Skip to content

Need examples of using MathJS within a button definition #669

Open

Description

@hickey

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.

Activity

  1. mProjectsCode commented on Jun 18, 2026

    @mProjectsCode
    Owner

    Sure, I can add some more examples for view fields in the future, but note that buttons use JavaScript and not the mathjs language. (This is documented here: https://www.moritzjung.dev/obsidian-meta-bind-plugin-docs/reference/buttonactions/updatemetadata/)

  2. hickey commented on Jun 18, 2026

    @hickey
    Author

    Thanks for the quick response!

    OK, but this probably adds a good amount of confusion as mathjs is a JavaScript module and it is used elsewhere in the meta-bind plugin. So one would assume that mathjs would also be available for a Button. Especially to those of us that are semi-fluent in JavaScript but don't work in the JavaScript ecosystem all the time. Maybe there are technical difficulties that don't allow Buttons to use the mathjs module. I unfortunately don't have time to dig into the TypeScript code to understand how it operates. I certainly think it might be a good addition.

    You may consider a statement or two on https://www.moritzjung.dev/obsidian-meta-bind-plugin-docs/guides/buttons/ that clarifies the context in which the buttons run so that others don't make the same mistake that I have made.

    Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions