Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sowiso opened this issue Oct 23, 2024 · 2 comments
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around v3 v4
Milestone

Comments

@sowiso
Copy link

sowiso commented Oct 23, 2024

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.

@dpvc
Copy link
Member

dpvc commented Oct 24, 2024

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 dpvc added Accepted Issue has been reproduced by MathJax team v3 Code Example Contains an illustrative code example, solution, or work-around v4 labels Oct 24, 2024
@dpvc dpvc added this to the v4.0 milestone Oct 24, 2024
dpvc added a commit to mathjax/MathJax-src that referenced this issue Oct 24, 2024
dpvc added a commit to mathjax/MathJax-src that referenced this issue Oct 24, 2024
@sowiso
Copy link
Author

sowiso commented Oct 24, 2024

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

dpvc added a commit to mathjax/MathJax-src that referenced this issue Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around v3 v4
Projects
None yet
Development

No branches or pull requests

3 participants
@dpvc @sowiso and others