MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

Typesetting the same content results in nested assistive content

Open fast-reflexes opened this issue 3 years ago • 3 comments

Issue Summary

Every time the same content is typeset anew with MathJax.typesetPromise(), the assistive math tag gets a nested version of the math content itself.

Steps to Reproduce:

Go to https://codesandbox.io/s/better-react-mathjax-20-m8uf2c

  1. Let the page load, check the assistive mml subelement of the content typeset on startup.
  2. Click TYPESET and observe what change occurs in the assistive math element (it gets a nested version of the math element itself)
  3. Do it again to observe a further nesting in the assistive element.

No matter if typesetClear is used or not, this is the resulting behaviour.

I would expect the assistive element to look the same after typesetting anew.

Technical details:

  • MathJax Version: 3.2.1
  • Client OS: MacOS Catalina 10.15.7
  • Browser: Chrome Version 103.0.5060.53 (Official Build) (x86_64)

I am using the following MathJax configuration:

DEFAULT (e.g. typesetting on startup)

and loading MathJax via

<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

fast-reflexes avatar Jul 03 '22 16:07 fast-reflexes

Thanks for the report. The problem is due to the fact that the MathML input jax is picking up the assistive MathML that was inserted during the initial typesetting pass, and is typesetting that again. A check need to be added to not typeset the assistive MathML.

For now, you can use the following configuration

MathJax = {
  mml: {},
  startup: {
    ready() {
      const {FindMathML} = MathJax._.input.mathml.FindMathML;
      class myFindMathML extends FindMathML {
        processMath(set) {
          const adaptor = this.adaptor;
          for (const mml of Array.from(set)) {
            if (adaptor.kind(adaptor.parent(mml)) === 'mjx-assistive-mml') {
              set.delete(mml);
            }
          }
          return super.processMath(set);
        }
      }
      MathJax.config.mml.FindMathML = new myFindMathML();
      MathJax.startup.defaultReady();
    }
  }
};

to work around the issue.

I'll make a pull request to fix this in the next release.

dpvc avatar Jul 05 '22 13:07 dpvc

Alternatively, if you are not using MathML input yourself, then using tex-chtml.js instead of tex-mml-chtml.js would also resolve the problem (and give you a smaller file for your users to download).

dpvc avatar Jul 05 '22 13:07 dpvc

Thanks a lot for your detailed answer! Will take it into account!

fast-reflexes avatar Jul 28 '22 17:07 fast-reflexes