Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

algebra manipulation tool #1083

Open
trebor opened this issue Apr 7, 2024 · 3 comments
Open

algebra manipulation tool #1083

trebor opened this issue Apr 7, 2024 · 3 comments

Comments

@trebor
Copy link

trebor commented Apr 7, 2024

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.

@pkra
Copy link
Contributor

pkra commented Apr 8, 2024

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

@trebor
Copy link
Author

trebor commented Apr 8, 2024

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?

@pkra
Copy link
Contributor

pkra commented Apr 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants