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

class='MJX-TeXAtom-ORD' in MathML crashes mathml2chtml #2822

Closed
NSoiffer opened this issue Jan 19, 2022 · 4 comments
Closed

class='MJX-TeXAtom-ORD' in MathML crashes mathml2chtml #2822

NSoiffer opened this issue Jan 19, 2022 · 4 comments

Comments

@NSoiffer
Copy link

Issue Summary

If class='MJX-TeXAtom-ORD' is present in MathML being converted by mathml2chtml, then the function crashes. This happens in both Firefox and Chrome

Steps to Reproduce:

  1. Open https://mathjax.github.io/MathJax-demos-web/input-mml2chtml.html
  2. Paste the following MathML into the input area:
 <math display='block' id='Mna33kyx-0'>
    <mn class='MJX-TeXAtom-ORD' id='Mna33kyx-9'>2</mn>
 </math>
  1. Click Render and open the debugger to see the message:
Uncaught Error: Unexpected text node "2"
    at t.error (cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js:1:205225)
    at t.addText (cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js:1:204033)
    at t.addChildren (cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js:1:203371)
    at t.makeNode (cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js:1:202222)
    at t.addChildren (cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js:1:203503)
    at t.makeNode (cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js:1:202222)
    at t.addChildren (cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js:1:203503)
    at t.makeNode (cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js:1:202222)
    at t.addChildren (cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js:1:203503)
    at t.makeNode (cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js:1:202222)

I know it might seem strange to have this internal class set, but the situation is that the math is being grabbed from the web, processed a little, and being sent back to MathJax for rendering. Since the original source (Wikipedia) used MathJax, that shows up.

Technical details:

  • MathJax V3.2.0
@dpvc
Copy link
Member

dpvc commented Jan 24, 2022

The classes that start with MJX- control different aspects of MathJax's parsing of the MathML, and if you use them incorrectly, it can lead to problems like this. The MJX-TeXAtom-* class is only applied to mrow elements by MathJax, and should not appear on any other type of node. If you remove the mrow, you should remove that class as well.

Also, this must be coming from MathJax v2 output, as v3 uses a data-mjx- attribute instead.

Although I can have MathJax ignore the class if it is not on an mrow, you really can't expect MathJax to perform correctly if you move its markers around indiscriminately.

@NSoiffer
Copy link
Author

The example came from https://en.wikipedia.org/wiki/Quadratic_formula, so I guess they are still stuck on v2.

The movement of the attr to the <mn> comes from there being a single mrow around the <mn>. The MathML spec says that mrow with a single child can be ignored unless they have attrs on them. I think the only MathML attr allowed on mrow is dir and since I'm not concerned about display in my app, I just coalesce any attrs on mrow into the child figuring that things like classes will still do what they were intended to do on the child. Apparently, that's not a good assumption. Normally this (bad) assumption won't be a problem for AT, but some AT may decide to display the math during navigation for sighted folks who are watching so display is potentially used (as it is in my demo for how navigation might work in AT).

Based on your reply, removing MJX-TeXAtom-* and data-mjx- should solve the problem in v2 and v3. Anything else that should be removed?

@dpvc
Copy link
Member

dpvc commented Jan 24, 2022

I guess they are still stuck on v2.

Yes, wikipedia is using v2.

I think the only MathML attr allowed on mrow is dir

I think that overlooks the attributes shared by all MathML elements, which includes class (and style, id, href and so on). There is also attributes shared by all presentation elements, which include mathcolor and mathbackground, and also apply to mrow. So it seems that you should not remove mrow when it has class set (or any of these other attributes). In fact, I'd argue that, in a setting like HTML pages where data attributes are allowed, you shouldn't remove <mrow> if it has a data-* attribute either (these are mentioned in the section on maction, so the spec does recognize these in the HTML setting, and they are allowed on any element, including mrow).

Anything else that should be removed?

If you are going to remove these attributes, then I'd recommend removing any class starting with MJX-, not just MJX-TeXAtom-*, as there are others used in v2 to capture MathJax data that isn't available in MathML directly (in v3 they should all be in data attributes).

@NSoiffer
Copy link
Author

Apologies for not being precise -- I meant the only mrow-specific attr is dir. My code merges any mrow attrs into the single child element which is why the mn ended up with class='MJX-TeXAtom-ORD' . I was trying to avoid removing attrs, although since I'm mainly targeting speech and braille, and any display will likely be in a different environment than the originally authored code, leaving the attrs may not be ideal. I'll learn more when the code gets used more.

I'll change my code to remove MJX-*. Again, thanks for letting me know how to fix the problem.

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

No branches or pull requests

2 participants