-
Notifications
You must be signed in to change notification settings - Fork 207
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
[Node] Measuring svg output children #358
Comments
OK, my bad. |
I think there is another approach to this that doesn't require you to know anything about the bounding boxes of individual terms or their locations. You can put an event listener on the outermost SVG element itself, and that will get click events for any element that that it contains. You can use the event's The difficulty with this approach in SVG output is that, because the glyphs are rendered as filled paths rather than text, a click would only be registered only if it occurred on the "ink" of the letter (not the letter's background). This problem can be overcome by adding transparent "hit boxes" into the structure that are the size of the character bounding boxes. Here is one example of that:
Here, we we use the startup's Then a render action is added at priority 170 (so that it follows the typesetting at priority 150) that attaching the click handler to the typeset math. The click handler itself uses the click target to move up the tree to the closest container that represents an item in the math tree that we care about. In this case, the ones we care about are marked with an
I'm assuming that your editor using some sort of expression tree as its internal format and that you generate the LaTeX from that as the expression is edited. (LaTeX itself would be a horrible internal format for this sort of thing.) In that case, you can insert the |
Thanks for the thorough response! |
I'm doing a similar thing (for RN too). I iterated through the LiteAdaptor and looked at the See #190 |
@jacobp100 let's join efforts, what say you? |
I'm not sure quite what you mean by that. The LiteDOM is not a setting where there is a mouse or clicking. It's not a real DOM. But if you added an But I think you don't have to use the event handler on the MathJax element itself, but could use React Native support for touch events to do a similar thing. I don't have any experience with React Native, but some quick searching around suggests that TouchableOpacity might be the thing you need. For example, this post has some examples that might help. The TouchableOpacity I don't think you should need to make a new output jax for this. |
Indeed that is my approach. The only problem is understanding what symbol is being hit, which is the reason I opened this issue. |
@ShaMan123 sorry, I meant to get back to you. My use-case specifically handles three layers, and I flatten these layers into a single svg path data string to make it easier on react-native-svg You can see my hacked-together code here Note this probably doesn't handle MML generally, it only needs to handle the MML output from my input editor Also note it's gathering other data in addition to the path data |
@jacobp100 Thanks. I'll look into it |
Hi,
I've been working this past week on a better way to interact with math in
react-native
(#342 )react-native-math-view
.V3
has unlocked options that have been near to impossible to implement natively with proper responsiveness.One of them is editing math.
I've been struggling with this for a few days. I went through the files again and again and am near to giving up 😓 (for the near future).
I need a way to measure the layout of children relative to the root parent
svg
output node (in node runtime environment). Then I could compute the layout, intercept touches and change thetex
input accordingly (with a customtex
keyboard i.e.).You can see what I did in MathjaxAdaptor.toSVGArray
My approach was to walk up the svg tree and concat all transformations for each deep child, then apply the layout onto it.
I seem to be missing something because if there are lower/upper chars, fractions etc. my calculation are wrong. See below.
Is there any better way of achieving this?
Any help would be much appreciated.
Thanks,
The text was updated successfully, but these errors were encountered: