mProjectsCode / mProjectsCode/obsidian-meta-bind-plugin

Need examples of using MathJS within a button definition

Open Beginner friendly
#669 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
TypeScript
Stars
1k
Forks
86
PR merge metrics
No merged PRs in 30d

Description

Page

https://www.moritzjung.dev/obsidian-meta-bind-plugin-docs/reference/viewfields/math/

Issue or Enhancement

While I have referenced the Math View page, I think that there needs to be probably another page under the button pages that also explains and provides some examples of how mathjs works with meta-bind.

First with some experimenting I was able to get a View to use mathjs correctly. Somewhere I found a reference to using a math namespace for mathjs functions. Yes, the mathjs pages specifically use this namespace but I thought I found a reference that was Obsidian specific (possibly using the meta-bind plugin) that used math, Math or mathjs. I can not find the reference now. It may also have been an AI hallucination. In any event, I tried the following with error of the namespace not being defined in JavaScript.

`VIEW[math.pickRandom\["Option A", "Option B", "Option C"\])]`
`VIEW[Math.pickRandom\["Option A", "Option B", "Option C"\])]`
`VIEW[mathjs.pickRandom\["Option A", "Option B", "Option C"\])]`

Finally trying without a namespace worked within the View.

`VIEW[pickRandom(\["Option A", "Option B", "Option C"\])]`

So I would request that the View Math page be updated with a couple of examples that show calling mathjs functions so that others do not run into the same problems and get frustrated.

What really triggered this divergence of being productive was that I have a Button that I built a while back and thought it was working at that time. Now I get failures in the console. That Button is defined as follows:

```meta-bind-button
style: default
label: Initialize test parameters
icon: test-tube-diagonal
id: initialize-testing
action:
  type: updateMetadata
  bindTarget: dev_test_years
  evaluate: true
  value: mathjs.pickRandom("2007-2008,2008-2009,2009-2010,2010-2011,2011-2012,2012-2013,2013-2014,2014-2015,2015-2016,2016-2017,2017-2018,2018-2019,2019-2020,2020-2021,2021-2022,2022-2023".split(","))

I think it would be worth a couple mins of time to create a new page on how to access the mathjs functions in a Button context.

Also, I found a reference to creating a Button using the InlineJS action and experimented with this also, but I had the same problem of not being able to access the the mathjs namespace.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Math View page and the button documentation, then compare the reported VIEW expressions with the shown updateMetadata button definition. Add button-focused examples explaining how mathjs functions are called, including the InlineJS context, and make the namespace behavior clear enough to prevent the reported errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.