markdownmathjax

MathJax \color declaration spills over and colors subsequent text


I tried \color and \textcolor in a markdown file and then in an html file. Only the latter scopes the color to its argument. With \color, the rest of the expression stays red.

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


$$\color{red}{red} black$$
$$\textcolor{red}{red} black$$

What's wrong?


Solution

  • The \color macro in MathJax version 2 was a non-standard one that took the material to be colors as an argument. The actual LaTeX \color macro is a switch that turns on coloring for the material that follows. In MathJax v3 (which you are using), the \color macro has been made compliant with the standard LaTeX one, which is the result you are seeing.

    This is described in the MathJax documentation for the color extension in the blue "note" box. You can configure MathJax to use the older \color macro, as described in the colorv2 extension page.