Search code examples
javascriptmathmarkdownmathjax

Prevent MathJax to manipulate dom on startup


I want MathJax to only manipulate certain elements on my page when I tell it to do so.

I've this code.

var converter = new Markdown.Converter();
converter.hooks.chain("preConversion", removeMath);
converter.hooks.chain("postConversion", replaceMath);

$(".exec-math").each(function(index, el){
  var str = converter.makeHtml($(el).html());
  $(el).html(str);
});

MathJax.Hub.Config({
 tex2jax: {
   inlineMath: [ ['$','$'] ],
   processEscapes: true
 }
});

MathJax.Hub.Queue(["Typeset",MathJax.Hub]);

// <span class="exec-math">**Markdown** and $a > b$</span>

It basically keeps the math away from the markdown engine.

The problem right now is that it looks like MathJax is being ran twice, like this.

  1. MathJax is loaded, manipulate dom
  2. Execute my code and schedule another run

So, is there a way to tell MathJax not to run on startup?


Solution

  • Yes. Set skipStartupTypeset to true in your configuration. See the core options documentation for details.