MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

Failed to execute 'splitText' on 'Text' when mixing TeX and asciimathml together with <br /> tag

Open xma81 opened this issue 1 year ago • 2 comments

Issue Summary

With the example text, math does not get rendered and a splitText error is thrown

Steps to Reproduce:

Use this html to typeset:

- This exercise type allow for multiple open input fields with a related evaluation. Par exemple, $\mathbb{R} \left\{-2\right\}$ sera not&eacute; $]-\infty;-2[U]-2;+\infty[$.<br />- Pour noter un ensemble de valeurs discr&egrave;tes, utilise le symbole [...; ...] du clavier. Par exemple : ${2}$ sera not&eacute; $[2;2]$ et `{2;3}` sera not&eacute; $[2;2]U[3;3]$.

Technical details:

  • MathJax Version: 3.2
  • Browser: Chrome 130.0.6723.58

Supporting information:

It happens on the live demo with the above html:

image

If I remove the <br /> tag from the html, the problem does not occur.

xma81 avatar Oct 23 '24 15:10 xma81

Thanks for the report. It turns out that there is a problem with merging the math lists produced by the TeX and AsciiMath input jax, and so the positions of the math within the text strings are not being properly handled, leading to this error. I will make a PR to fix the problem.

As a work-around, you can incorporate the following into your MathJax configuration to fix the issue:

MathJax = {
  startup: {
    ready() {
      const {HTMLDocument} = MathJax._.handlers.html.HTMLDocument;
      HTMLDocument.prototype.findPosition = function (N, index, delim, nodes) {
        const adaptor = this.adaptor;
        const inc = 1 / (nodes[N].length || 1);
        let i = N;
        for (const [node, n] of nodes[N]) {
          if (index <= n && adaptor.kind(node) === '#text') {
            return { i, node, n: Math.max(index, 0), delim };
          }
          index -= n;
          i += inc;
        }
        return { node: null, n: 0, delim };
      };
      MathJax.startup.defaultReady();
    }
  }
}

dpvc avatar Oct 24 '24 13:10 dpvc

Great, thanks! I can confirm that the proposed fix works for the case presented above.

xma81 avatar Oct 24 '24 13:10 xma81

Fixed in v4.0.

dpvc avatar Aug 13 '25 14:08 dpvc