-
Notifications
You must be signed in to change notification settings - Fork 205
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
Get Bounding Boxes of Nodes #190
Comments
The output jax have a
will output the bounding box information. The I'm not sure what you have in mind for If you are trying to get the sizes of individual subexpressions, that could be done, but would require a little more work. mathJax does not currently have a subexpression API for this. |
Thanks for your reply! My use-case is a math editor, and I want to display a cursor over a rendered equation. I only need the x/y relative to the origin of the SVG. I'm using I had some crazy code to iterate the SVG and add the I'm trying to get this to work in react-native (via react-native-svg), so can't use browser measurement functions |
Have you considered putting your cursor into the expression itself? I have had some luck with that in the past. You could use something like
and then put |
Hmm - adding the \llap seems to affect the layout. I'm also noticing that I can't attach a I'm going from my own ast to latex, and then mathjax is going from latex to its own format. I think it might be better to fork this repo to let me construct the mathjax ast myself. Then I'd be able to keep track of all elements and layout. Unless there's a way to do this without forking 😄 |
It can. For example, if you have Also, you may need to set the TeX class of the cursor depending on its location in order to preserve the spacing. In TeX, the spacing between two items is determined by their TeX classes, so the presence of an ORD element (what an For some situations, like Unfortunately, there is no easy way around these spacing issues.
That's correct. The way that TeX handles these, there is no way to isolate them. But you can do it in MathML. If your editor is keeping its own abstract syntax tree internally (which I expect you do, as that is the best way to do this sort of thing), and translating that into LaTeX notation for output, you could instead translate to MathML for MathJax (and could have a LaTeX option for copying-and-pasting). The MathML construct for In order to do this sort of thing in TeX, you would have to write a custom macro (implemented in javascript) that generates the corresponding MathML with ids. That can certainly be done. |
I'll definitely look at going to MathML. I've not really looked at it before, but it seems like that's your canonical representation in this codebase. I'll let you know how it goes! |
So one thing I'm looking at is adding to the SVG wrapper the property public place(x: number, y: number) {
this.origin.x += x;
this.origin.y += y;
...
} This seems to mostly work! However, I was just wondering what your thoughts on this approach were! Would this be something you'd be interested in getting a PR for? For my use-case, I'm only interested in the path data, position, and scale of path elements. If I can get it working, I should be able to almost completely replace the adapter with a no-op, which would remove the parser and make my bundle smaller! |
Are you looking only for an offset of a child from its parent (MathML) element? If so, then this should work for that; if you want an offset from the location of the outermost math element, then you would need to update all the child node positions as well.
These are the only two that are probably relevant to your usage. The ones in So that leaves The mtable wrapper has three uses of Finally, the other usage is in
Probably not. One of the places where we looked for speed improvements was the bounding box computations, since in v2 they can contribute about 10% of the output time. Maintaining any extra values like this that are only used by a tiny fraction of the use-cases is not something I would want to include in the core. It would be possible to make an extension that handles these computations (rather than editing the core code directly), and that would be the recommended path for making something like this available, I would think.
Well, since the individual characters don't have wrappers, I'm not sure how this does it for you. While most token elements will only contain one character, that is not always the case. In particular,
I'm not sure I understand what you are saying. MathJax's DOMadaptor plays a central role in the construction of the SVG (and CommonHTML) output, so I don't see how you can get away without it. Perhaps I misunderstand what you are saying, here. |
I've got something working enough. I'll close this, as there's not much more MathJax can do. Thanks for your help though! :D |
You're welcome, and good luck with your project! |
I'm using this in using the node example here.
I realise that there are some ways to access the tree structure. E.g.
math.root.walkTree
.If I have a math node, is there a way to get the bounding box that was used when typesetting? I need the x, y baseline, and width of the node
The text was updated successfully, but these errors were encountered: