mathlive icon indicating copy to clipboard operation
mathlive copied to clipboard

Incorrect LaTeX Output When Generating LaTeX from Visually Entered Equations in MathField

Open hpvcodeDev opened this issue 8 months ago • 1 comments

When I enter mathematical equations visually in MathField (using the virtual keyboard or interacting with the editor in math mode), the generated LaTeX code (for example, when using getValue("latex") or copying as LaTeX) is not syntactically correct. Specifically, nested fractions within square roots lose the necessary braces, resulting in invalid LaTeX. For example, a fraction like \frac{2}{5} inside a square root is generated as \sqrt{\frac25} instead of \sqrt{\frac{2}{5}}.

Image

Generated (incorrect): \int_{B}^{A}\frac{X^2}{\frac{X-2}{\sqrt{\frac25}}}+5\,dX
Expected (correct): \int_{B}^{A}\frac{X^2}{\frac{X-2}{\sqrt{\frac{2}{5}}}}+5\,dX

As with this example, I have encountered more instances like this. This issue occurs when the equation becomes more complex with nested structures.

Note: This happens when we manually type equations using the keyboard. However, if we paste a LaTeX equation directly, it generates the correct code. But the idea is not to paste LaTeX equations — it's to write them

hpvcodeDev avatar Apr 16 '25 08:04 hpvcodeDev

\frac25 is valid LaTeX. When the arguments are a single digit, the braces are optional. Try it here: https://editor.codecogs.com/

arnog avatar Apr 16 '25 13:04 arnog