asnunes / mathml-to-latex

A JavaScript tool to convert mathml string to LaTeX equation string.
MIT License
51 stars 14 forks source link

Why will the extra parentheses be parsed when there are subscripts #8

Closed zbh876325764 closed 3 years ago

zbh876325764 commented 3 years ago

example: <math display="block" xmlns="http://www.w3.org/1998/Math/MathML"> <msub> <mi>𝑎</mi> <mn>0</mn> </msub> </math>

result:'\left(𝑎\right)_{0}'

but i want '𝑎_{0}'

asnunes commented 3 years ago

Hello, @zbh876325764. Sorry for taking too long to respond. I missed this issue. This is just the way the library is implemented. It does not distingue between one or many characters, so for one char in LaTeX, parentheses are optional, but they must be applied for many chars cases, so they are always applied to accomplish the most restrive case.

nguyentuan12b6 commented 1 month ago

hello @asnunes , I also have this problem, when I use <mrow> tag after <msub> tag,

example: <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>F</mi><mi>e</mi><msub><mrow><mo>(</mo><mi>O</mi><mi>H</mi><mo>)</mo></mrow><mn>3</mn></msub></math>

result: F e \left(\left(\right. O H \left.\right)\right)_{3}

but i want: F e \left(\right. O H \left.\right)_{3}

I have this idea: check the starting characters, if it starts with { or [ or (, then wrap ( ) can be omitted (see photo below) Screenshot 2024-08-01 112306 ( The file containing the function in the image is src\data\helpers\wrappers\parenthesis.ts ) Have a nice day, asnunes