the equation tree

17 views
Skip to first unread message

Robert Harris

unread,
May 30, 2016, 6:18:26 PM5/30/16
to MathJax Users
my goal is to build a mathjax based equation manipulator.  a simple toy example would be to transform:

  a = bc

to:

  b = a/c

with "button press" ease.  this might become increasingly useful with large, complex equations and a long list of possible transformations.

to achieve this goal, i will need to be able to manipulate the equation data structure as a tree.  i assume that this tree structure exists someplace inside mathjax, but i am having a hard time figuring out where.

Q: does anyone know how i would get the tree form an equation?

Q: is this the right sort of place to start?

  var math = MathJax.Hub.getAllJax("#elementId")[0];

i've seen references to "Presentation MathML", which looks like the WRONG thing, in that it has stripped out the hierarchical structure and thus is not a plausible candidate for manipulation.

thanks,

  -trebor

Davide P. Cervone

unread,
May 31, 2016, 7:53:03 AM5/31/16
to mathja...@googlegroups.com
i assume that this tree structure exists someplace inside mathjax,

No, MathJax does not have that sort of a tree.  It has a Presentation MathML representation of the expression, which (as you point out) is not suited to computational work, in general.  Indeed, there is nothing that says the mathematics represented by MathJax needs to be well formed, or meaningful in a computational way, and many expressions represented in TeX and MathML do not carry enough semantic information to form the computational tree that you are looking for without additional contextual information.  For example, is "(1,3)" an open interval on the real line, a point in the plane, or an inner product?

Q: does anyone know how i would get the tree form an equation?

If you are planning to do the kinds of manipulation that you indicate, then you should not use MathJax's internal format for that.  You should represent the expressions you are managing using your own tree structure, and use that tree to generate the input needed by MathJax to display your expression.  Then you can manipulate your tree as you see fit, and send the new result to MathJax to display.

Q: is this the right sort of place to start?

  var math = MathJax.Hub.getAllJax("#elementId")[0];

No, for several reasons.  First, the internal structure used by MathJax isn't going to help you (as discussed above), but second, the element ID passed to getAllJax() is not a CSS selector, but an actual ID.  So you would use MathJax.Hub.getAllJax("elementId") without the "#".

Davide

Robert Harris

unread,
May 31, 2016, 2:05:38 PM5/31/16
to MathJax Users, dp...@union.edu
davide, thanks for the insight here, you have saved me a lot of time.  i'm looking at MathLib.js next to see if that can do the job for me. 

  -trebor

Peter Krautzberger

unread,
May 31, 2016, 2:12:20 PM5/31/16
to mathja...@googlegroups.com, Davide P. Cervone
Hi trebor,

MathLib.js is inactive -- see https://github.com/alawatthe/MathLib/issues/5

From the OSS tools for computation out there, I would suggest MathJS (http://mathjs.org/) as the most actively maintained project. They also have a TeX output for visual rendering that works well with MathJax.

Regards,
Peter.

--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages