Failed to execute 'splitText' on 'Text' when mixing TeX and asciimathml together with <br /> tag
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é $]-\infty;-2[U]-2;+\infty[$.<br />- Pour noter un ensemble de valeurs discrètes, utilise le symbole [...; ...] du clavier. Par exemple : ${2}$ sera noté $[2;2]$ et `{2;3}` sera noté $[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:
If I remove the <br /> tag from the html, the problem does not occur.
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();
}
}
}
Great, thanks! I can confirm that the proposed fix works for the case presented above.
Fixed in v4.0.