mathjax / MathJax-node

MathJax for Node
Apache License 2.0
609 stars 96 forks source link

When latex contains double braces "{{}}", the conversion of MathML is incorrect #446

Closed lyxabymxlc closed 4 years ago

lyxabymxlc commented 5 years ago

For example: $${\text{{A}}_{2}}$$ The code for converting to MathML is as follows: <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\text{{A}}_{2}}"> <mrow class="MJX-TeXAtom-ORD"> <msub> <mtext>{A}</mtext> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msub> </mrow> </math> But it's wrong, It should not be'{A}'. The brackets '{}' on both sides of 'A' are redundant. How can I repair it? Thank you.

dpvc commented 5 years ago

MathJax does not process macros or special characters inside \text{} or other text-mode macros, except for math delimiters and a few escaped characters like \$ and \{. All other characters are shown verbatim. This is because MathJax doesn't process text-mode, only math mode. You are correct that this is not consistent with LaTeX, but it is how MathJax is currently implemented.

There is a pull request that adds a new MathJax extension that supports more text-mode macros and special characters. It would handle this situation for you. You could download the extension file from the pull request and use the technique given in this comment for loading the extension into MathJax node.

lyxabymxlc commented 5 years ago

@dpvc Thank you. I'll try it.

lyxabymxlc commented 5 years ago

@dpvc It solved my problem perfectly. Thank you very much.

lyxabymxlc commented 5 years ago

@dpvc After using the new plug-in'text-macros', there is a new problem. For example: {{P}_\text{L{\text{max}}}}={{U}_\text{L}}{{I}_\text{L}}=3\text{V}\times 0.3\text{A}=0.9\text{W} Error reporting when converting mathml: TeX parse error: '\text' is only supported in math mode How can I repair it? Thank you.

dpvc commented 5 years ago

@lyxabymxlc, add

      text: ['Macro', ''],

to the textMacros object that begins at line 108. Anywhere in the object is OK, but I would recommend adding it after the texttt definition at line 169.

lyxabymxlc commented 5 years ago

@lyxabymxlc, add

      text: ['Macro', ''],

to the textMacros object that begins at line 108. Anywhere in the object is OK, but I would recommend adding it after the texttt definition at line 169.

You're right. Perfect.