Skip to content

What to do if your CMS replaces & etc with other things

Davide P. Cervone edited this page May 28, 2013 · 5 revisions

Your content management system seems to be inserting <span class="amp">&</span> for all of the ampersands, and that is causing the tex2jax extension to skip the math, since it is not allowed to include any HTML tags. I'm not sure if that is a feature you can turn off, but if not, there are the possible approaches:

  1. add some javascript that removes the spans before MathJax runs (that could be handled as a MathJax preprocessor, or as custom code in a MathJax configuration block).
  2. modify the tex2jax preprocessor to handle the span elements (harder than option 1), or
  3. define another character to be used in place of & as the column separator in TeX arrays (easy to code, but harder for you who are entering the data).

I suspect (1) may be the easiest approach.

To do that, add

MathJax.Hub.Register.StartupHook("Begin Typeset",function () {
  var span = document.getElementsByTagName("span");
  for (var i = span.length-1; i >= 0; i--) {
    if (span[i].className === "amp") {
      span[i].parentNode.insertBefore(span[i].firstChild,span[i]);
      span[i].parentNode.removeChild(span[i]);
    }
  }
});

after your MathJax.Hub.Config() call.

Note however, that you have several problems with your setup. First, you load MathJax.js twice (there are two separate script tags that reference MathJax.js). While MathJax is smart enough to only run once, this can cause MathJax.js to be downloaded twice in some browsers. Second, your configuration script should come BEFORE the script that loads MathJax.js, and it should have type="text/x-mathjax-config" not type="text/javascript". MathJax will load and execute the script at the appropriate time. If you put it after the script that loads mathJax, it may not execute at the proper time during MathJax's configuration process. See the documentation on inline configuration for details.

Clone this wiki locally