Page MenuHomePhabricator

<math>\textrm{foobar}</math> results in "Math input error" with MathJax
Closed, ResolvedPublicBUG REPORT

Description

Enable "Client side MathJax rendering" in Special:Preferences → Apperance → Math. Then preview a page with the contents <math>\textrm{foobar}</math>.

I expect to see "foobar" but instead I see "Math input error". Right clicking on the error and selecting "Show Math As MathML code" reveals a more detailed error message Unexpected text node "foobar".

The MathML code generated by MediaWiki is the following:

<math class="mwe-math-element" xmlns="http://www.w3.org/1998/Math/MathML">
    <mrow data-mjx-texclass="ORD">
        <mstyle displaystyle="true" scriptlevel="0">
            <mrow data-mjx-texclass="ORD">
                <mtext>
                    <mrow data-mjx-texclass="ORD">foobar</mrow>
                </mtext>
            </mrow>
        </mstyle>
    </mrow>
</math>

Pasting this into https://mathjax.github.io/MathJax-demos-web/input-mml2svg.html reproduces the error message Unexpected text node "foobar".

Pasting the same into https://www-archive.mozilla.org/projects/mathml/demo/tester.html shows no errors in Firefox but does not render in Chrome.

Pasting the same into https://www.mathmlcentral.com/Tools/FromMathML.jsp shows an unexpected "mtext".

Pasting the same into https://validator.w3.org/nu/#textarea shows "Error: Element mrow not allowed as child of element mtext in this context."

All of these errors can be fixed by replacing line <mrow data-mjx-texclass="ORD">foobar</mrow> with just foobar.

Details

Related Changes in Gerrit:

Event Timeline

Pasting this into https://mathjax.github.io/MathJax-demos-web/input-mml2svg.html does not produce any output for me. The other links as reported.

Pasting this into https://mathjax.github.io/MathJax-demos-web/input-mml2svg.html does not produce any output for me. The other links as reported.

same here

If one uses <math>\textrm{foobar}</math> this exands to <math class="mwe-math-element" xmlns="http://www.w3.org/1998/Math/MathML"><mrow data-mjx-texclass="ORD"><mstyle displaystyle="true" scriptlevel="0"><mrow data-mjx-texclass="ORD"><mtext>foobar</mtext></mrow></mstyle></mrow></math> in contrast <math>\texttt{foobar}</math> fails with the same error. The code guilty is \MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseParsing::hBox

What temml.org seems to be doing is to use mtext and translate each individual letter to another UTF-8 char.

Try

\texttt{foobar}

\textrm{foobar}

on temml.org.

image.png (193×897 px, 20 KB)

LaTeXML does not use any math specific elements but plain span elements.

Screenshot 2025-03-06 at 14.34.18.png (113×1 px, 17 KB)

(I think the temml.org rendering looks even better, @Dginev )

Mathoid produces

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block" alttext="{\texttt {foobar}}{\textrm {foobar}}">
  <semantics>
    <mrow>
      <mrow class="MJX-TeXAtom-ORD">
        <mrow class="MJX-TeXAtom-ORD">
          <mtext mathvariant="monospace">foobar</mtext>
        </mrow>
      </mrow>
      <mrow class="MJX-TeXAtom-ORD">
        <mrow class="MJX-TeXAtom-ORD">
          <mtext>foobar</mtext>
        </mrow>
      </mrow>
    </mrow>
    <annotation encoding="application/x-tex">{\texttt {foobar}}{\textrm {foobar}}</annotation>
  </semantics>
</math>

Screenshot 2025-03-06 at 14.37.49.png (464×605 px, 32 KB)

Also fails in Client Side MathJax mode.

This is quite high priority as over 2580 instances in 688 articles on en.wikipedia.

The \textrm syntax is not listed in Help:Formula so we could say that its not a supported syntax. We could probably add some rule so that \textrm is treated as \mathrm or possibly as \text. Either that or we treat it as an error and list it at Category:Articles with Maths Errors.

Physikerwelt triaged this task as High priority.

Change #1148925 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/extensions/Math@master] Fix MathJax textrm rendering

https://gerrit.wikimedia.org/r/1148925

Change #1148925 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Fix MathJax textrm rendering

https://gerrit.wikimedia.org/r/1148925