Search code examples
mathjax

MathJax tries to render \begin{itemize}


When MathJax sees \begin{itemize} ... \end{itemize}, it tries to render it as a math object. I want it to only interpret things within dollar signs as math. I can't find any obvious reason why it would interpret \begin{itemize} as some delimiter.

Minimal working example:

<script type="text/javascript" 
        src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">  

    MathJax.Hub.Config({
        jax: ["input/TeX", "output/HTML-CSS"], 
        tex2jax: {
            inlineMath: [ ['$','$'] ]
        }, 
        "HTML-CSS": { availableFonts: ["TeX"] }
    }); 

</script>

<body>
Here is some thing:

\begin{itemize}
\item mathjax shouldn't care about this latex environment but it does
\item this WON'T be rendered as math: $x+y+z$
\end{itemize}

but this WILL: $\sum_{i=0}^n 1/2^i$
</body>

Result:

enter image description here

Expected:

enter image description here

Other comments:

If I change it to \begin{asdf} .. \end{asdf} the unwanted behavior still occurs. So it is not specific to "itemize". But \begin{foo} .. \end{bar} results in my expected behavior (i.e., MathJax does nothing).


Solution

  • The tex2jax extension is the one that handles identification of math in the page, and because environments like \begin{align}...\end{align} are math environments that do not require delimiters, tex2jax looks for \begin{xxx}...\end{xxx} within the document. Since there is no other reason to have such strings in an HTML document other than in code snippets (which will be skipped if they are in <code> or <pre> blocks, and can be configured to be skipped otherwise), or if you are doing additional javascript-based processing of your page (in which case you can coordinate your efforts with those of MathJax), and because tex2jax doesn't know what environments may be defined within your document, this seemed a reasonable approach.

    In any case, you can prevent it by setting processEnvironments: false in the tex2jax block of your MathJax configuration (see the tex2jax documentation). If you do, however, then you will have to enclose \begin{align}...\end{align} and any other math environments in display-math delimiters.