Parens in LaTeX not converted to MathML properly
Author: petewu100Created Jan 26, 2026Updated Sep 22, 2026
Labelsbug
When converting LaTeX to MathML, KaTeX is not handling parenthesized expressions properly.
- Go to the KaTeX homepage, https://katex.org.
- In the "Type an expression:" box, type (x)^2
- Open the Elements tab of DevTools to inspect the MathML that KaTeX has added to the DOM.
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<semantics>
<mrow>
<mo stretchy="false">(</mo>
<mi>x</mi>
<msup>
<mo stretchy="false">)</mo>
<mn>2</mn>
</msup>
</mrow>
<annotation encoding="application/x-tex">(x)^2</annotation>
</semantics>
</math>=> Note: in the <msup> the base is <mo stretchy="false">)</mo> So the exponent applies to just the close paren.
Expected: the base in the <msup> to be the whole parenthesized expression wrapped in an <mrow>:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<msup>
<mrow>
<mo stretchy="false">(</mo>
<mi>x</mi>
<mo stretchy="false">)</mo>
</mrow>
<mn>2</mn>
</msup>
</math>It is important for the MathML to have the proper semantic structure for compatibility with other apps.
Environment
- KaTeX Version: 0.16.28
- Device: Desktop PC
- OS: Windows 11 25H2
- Browser: Edge
- Version: 144.0.3719.82
Source: KaTeX/KaTeX