MathJax-src icon indicating copy to clipboard operation
MathJax-src copied to clipboard

algebra manipulation tool

Open trebor opened this issue 1 year ago • 3 comments

a while back, i worked on an algebra manipulation tool, algebranch that used older MathJax. sadly the prototype is now way out of date and broken, but it gives you some idea of what i'm shooting for. i'd like to take another crack at it, and strongly suspect that MathJax has done a lot of the work to make this easier for me, but i can't seem to find my way to getting underway on the project. the API doc is a bit thin. :(

image

what i need to be able to do is:

  1. parse text like x = 2 * y into an math expression tree, maybe an MmlTree?
  2. manipulate the tree
  3. render the tree onto a web page.

my questions:

  • which of the above is possible with MathJax?
  • what would minimal code to parse text into tree look like?
  • what would minimal code to render the tree look like?

thanks for any help getting started here.

trebor avatar Apr 07 '24 21:04 trebor

You might want to check out https://github.com/josdejong/mathjs/ for parsing and manipulation/computation. Then you can "pretty print" via toTeX and display the result with MathJax. See for example https://mathjs.org/docs/expressions/parsing.html and https://mathjs.org/examples/browser/pretty_printing_with_mathjax.html.html

pkra avatar Apr 08 '24 08:04 pkra

oh thank you for getting back to me!

i had tried something like that originally, but i could not find a way to map the MathJax expression elements in the browser to the math expression tree in mathjs.

i was able to catch mouse events from the MathJax expression on the web page, which is expressed is a tree in the dom, but that "dom tree" is not isomorphic to the tree in mathjs tree.

my workaround was to break the expression out into all the sub-elements, but that does not feel like a great UI. :(

now that i am writing this, i realize i asked the wrong question, i think the better question would be:

can i map mouse events in the dom to nodes, to nodes the math expression tree, be that mathjs or maybe MmlTree?

trebor avatar Apr 08 '24 18:04 trebor

i had tried something like that originally, but i could not find a way to map the MathJax expression elements in the browser to the math expression tree in mathjs. i was able to catch mouse events from the MathJax expression on the web page, which is expressed is a tree in the dom, but that "dom tree" is not isomorphic to the tree in mathjs tree.

Ah ok, now I understand why you were asking about SRE's annotation - it overlays a similarly "orthogonal" informational structure on top of the visual format. I don't usually think of SRE's tree as suitable for computational work but if you have enough control over the input, then maybe you can use SRE's tree (which is exposed as data attributes) to reconstruct enough information.

can i map mouse events in the dom to nodes, to nodes the math expression tree, be that mathjs or maybe MmlTree?

The MathJax team will know best but I don't think that's doable without preparing the input yourself, e.g., adding data attributes (which MathJax will then preserve in its output).

Maybe the mathjs people have an idea on how to generate something suitable; their docs on customizations include several toTeX related customizations, https://mathjs.org/docs/expressions/customization.html

pkra avatar Apr 09 '24 07:04 pkra