Katex: Error with subscript or superscript

Created on 2 Dec 2018  ยท  11Comments  ยท  Source: KaTeX/KaTeX

Typing \log_{10}\left(x\right) into the preview at katex.org results in the error
Invalid markup: Incorrect number of children for <msub/> tag.
Same with
\log^{10}\left(x\right)

I am using Firefox 63.0.3 on Windows. The error does not occur on Chrome or Edge.

MathML bug

All 11 comments

More related errors
\lim_{x\to\infty}
gives
Invalid markup: Incorrect number of children for <munder/> tag.

I tried reproducing these using the MacOS version of Firefox but wasn't able to. Could you paste the MathML markup that you're seeing when you get these errors?

For \log_{10}\left(x\right)

<span class="katex-mathml">
   <math>
      <semantics>
         <mrow>
            <msub>
               <mi>log</mi>
               <mo>โก</mo>
               <mn>10</mn>
            </msub>
            <mrow>
               <mo fence="true">(</mo>
               <mi>x</mi>
               <mo fence="true">)</mo>
            </mrow>
         </mrow>
         <annotation encoding="application/x-tex">\log_{10}\left(x\right)</annotation>
      </semantics>
   </math>
</span>

It seems to be caused by the empty mo tag.
I extracted it to a new page to get:

<!DOCTYPE html>
<html>
   <head>
      <meta charset="utf-8">
   </head>
   <body>
      Equation:
      <span class="katex-mathml">
         <math>
            <semantics>
               <mrow>
                  <msub>
                     <mi>log</mi>
                     <mo>โก</mo>
                     <mn>10</mn>
                  </msub>
                  <mrow>
                     <mo fence="true">(</mo>
                     <mi>x</mi>
                     <mo fence="true">)</mo>
                  </mrow>
               </mrow>
               <annotation encoding="application/x-tex">\log_{10}\left(x\right)</annotation>
            </semantics>
         </math>
      </span>
   </body>
</html>

With the mo tag I get invalid-markup, without it the log renders correctly.

I don't expect that the mo tag is actually empty. It should have an invisible character, U+2061 (&ApplyFunction;), inside it. This is intentional (though arguably it should be after the <msub>...).

However, I'm also unable to reproduce the error, using Firefox 63.0.3 on Windows. Could it be caused by a plugin? Can you try in a private window?

The error still occurs in private browsing with all extensions disabled. I also just tried it on another computer and the error did not show up. Seems like it has something to do with my setup.

The error shows up if you select CSS under filter output in the console. Is this an issue?

With that instruction, I can reproduce the error. It seems to happen with \log_5 x but not \log x.

Ah, I see the issue now. <msub> is supposed to have only two children, but in this example, it has 3. This is caused by op's MathML builder returning a document fragment: https://github.com/KaTeX/KaTeX/blob/f71f469d4b3ca97654702a0807e736d176f4c4c5/src/functions/op.js#L251-L263

I think we need to modify supsub's MathML builder to wrap a fragment in an mrow, in this line: https://github.com/KaTeX/KaTeX/blob/f71f469d4b3ca97654702a0807e736d176f4c4c5/src/functions/supsub.js#L204

Alternatively, we need to bring the &ApplyFunction; outside of the subscript...

We could also do some sanity checking out the MathML nodes we're outputting to make sure we're conforming to things like expected child count.

Alternatively, we need to bring the ⁡ outside of the subscript...

I think that'd probably be preferable if it isn't too tricky.

Closed via #1890.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

OisinMoran picture OisinMoran  ยท  4Comments

asmeurer picture asmeurer  ยท  3Comments

sophiebits picture sophiebits  ยท  3Comments

yawnoc picture yawnoc  ยท  3Comments

ylemkimon picture ylemkimon  ยท  3Comments