Search code examples
javascriptmathjax

How to modify TeX before it is processed by MathJax v3?


I am attempting to do something similar to this MathJax v2 startup hook, that modifies the TeX command before it is processed (every time before typesetting).

MathJax v3 does not have that Augment logic. Instead, there are startup actions:

window.MathJax = {

  // configuration...

  startup: {
    ready () {

      // MathJax is loaded, but not yet initialized
      // Get TeX here

      window.MathJax.startup.defaultReady();

      // MathJax is ready
    }
  }
}

But I didn't found anywhere in the documentation how to get the TeX command there, before it is processed. How can it be done?


Solution

  • Here is a configuration for MathJax v3 that should do the trick, provided you are loading a component that has only one input processor.

    MathJax = {
      startup: {
        ready() {
          MathJax.startup.defaultReady();
          MathJax.startup.document.inputJax[0].preFilters.add(
            ({math}) => {
              if (math.display === false) {
                math.math = '\\displaystyle{' + math.math + '}';
              }
            }
          );
        }
      }
    };