mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.14k stars 1.16k forks source link

<mtext>A&nbsp;</mtext> renders well in FF but fails in Chromium #3287

Closed physikerwelt closed 1 day ago

physikerwelt commented 1 week ago

Replace the text below with the details of the issue you are facing.
DO NOT simply erase the form and type a free-form response.

Issue Summary

As described in https://phabricator.wikimedia.org/T375241 LaTeX input like $\text{A }$ creates the following rendering error in Chromium but renders fine in Firefox.

With a preprocessing script the LaTeX input is converted into MathML of this form

<mtext>A&nbsp;</mtext>

Is this the MathML representation the MathJax team recommends?

"TypeError: Cannot read properties of null (reading 'getElementsByTagName')\n    at e.tags (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:9238)\n    at e.transform (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/input/mml/extensions/mml3.js:1:2952)\n    at e.mmlFilter (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/input/mml/extensions/mml3.js:1:3057)\n    at e.execute (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:731579)\n    at t.executeFilters (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:36695)\n    at e.compile (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/input/mml.js:1:2287)\n    at t.compile (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:49304)\n    at t.compileMath (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:44016)\n    at t.compile (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:43529)\n    at Object.renderDoc (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:39265)"

Steps to Reproduce:

  1. Login to https://www.mediawiki.org/
  2. Select Client Side Math rendering in the preferences https://www.mediawiki.org/wiki/Special:Preferences#mw-prefsection-rendering-math
  3. Goto https://www.mediawiki.org/wiki/Extension:Math/T375241

See that it works with FF but fails with Chrome.

Technical details:

I am using the following MathJax configuration:

https://github.com/wikimedia/mediawiki-extensions-Math/blob/db81c960623d346ca8f43fb91ca3da92f868ea29/modules/ext.math.mathjax.js#L7

( function () {
    'use strict';
    const extensionAssetsPath = mw.config.get( 'wgExtensionAssetsPath' );
    window.MathJax = {
        loader: {
            // see https://docs.mathjax.org/en/latest/input/mathml.html
            load: [ '[mml]/mml3' ],
            // see https://docs.mathjax.org/en/latest/options/startup/loader.html
            paths: {
                mathjax: extensionAssetsPath + '/Math/modules/mathjax/es5'
            }
        }
    };
}() );

and loading MathJax via

<script src="/w/extensions/Math/modules/mathjax/es5/input/mml.js" charset="UTF-8"></script>
<script src="/w/extensions/Math/modules/mathjax/es5/input/mml/extensions/mml3.js" charset="UTF-8"></script>

Supporting information:

"TypeError: Cannot read properties of null (reading 'getElementsByTagName')\n    at e.tags (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:9238)\n    at e.transform (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/input/mml/extensions/mml3.js:1:2952)\n    at e.mmlFilter (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/input/mml/extensions/mml3.js:1:3057)\n    at e.execute (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:731579)\n    at t.executeFilters (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:36695)\n    at e.compile (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/input/mml.js:1:2287)\n    at t.compile (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:49304)\n    at t.compileMath (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:44016)\n    at t.compile (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:43529)\n    at Object.renderDoc (https://www.mediawiki.org/w/extensions/Math/modules/mathjax/es5/tex-chtml.js?1d4e3:1:39265)"
dpvc commented 1 week ago

This is a duplicate of #3030. WebKit and Blink seem to have difficulty processing the XSLT stylesheet used for the mml3 extension when the MathML contains &nbsp; entities. The code example given there should resolve the issue for you, though you might need to change inputJax[0] to inputJax[1] depending on how MathJax is loaded.

dpvc commented 1 week ago

PS, this is already fixed in v4 (now out in beta release).

physikerwelt commented 1 day ago

Thank you. With your fix, we could fix the upstream but https://phabricator.wikimedia.org/T375241 in little time. This was very helpful.