3
votes

Within my rails application I use mathjax (TEX-AMS_HTML) to render latex formulas.

When entering formulas in a comment I use the codecogs Equation Editor with TinyMCE.

My current mathjax config ontop of (TEX-AMS_HTML) is:

        "HTML-CSS": {linebreaks: { automatic: true, width: "container" }},
        displayAlign: "left",
        extensions: ["tex2jax.js","MathMenu.js","MathZoom.js"],
        jax: ["input/TeX","output/HTML-CSS"],
        TeX: { extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"] },
        tex2jax: { ignoreClass: "w1", processClass: "active|comments-content" }

My problem is that some formulas are not rendering out, consider the following:

\[ foo\textup{bar} \]

This renders foo \textup bar. I have also noticed some symbols rendering textually such as:

\[ \AE \SS \]

This would render \AE \SS instead of the appropriate symbols.

I have tried switching to SVG, adjusting inline/display settings and cannot solve this.

Anyone have some idea as to why this is happening?

EDIT: Here is a contained example

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <title>Mathjax</title>
        <script type="text/x-mathjax-config">
            MathJax.Hub.Config({
            "HTML-CSS": {linebreaks: { automatic: true, width: "container" }},
            displayAlign: "left",
            extensions: ["tex2jax.js","MathMenu.js","MathZoom.js"],
            jax: ["input/TeX","output/HTML-CSS"],
            TeX: { extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"] },
            tex2jax: { ignoreClass: "w1", processClass: "active|comments-content" }
            });
        </script>
        <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
    </head>
    <body>
        <div id="wrapper">
            <div id="main">
                <div class="w1">
                    <div class="comments-content">
                        <p>\[foo\textup{bar}\AE\SS\]</p>
                        <p>\[K_{E}=\frac{1}{2}m(\frac{80}{3.6})^{2}\]</p>
                    </div>
                </div>
            </div>
        </div>  
    </body>
</html>

Which renders as: http://i.imgur.com/bUJXZPX.png

Notice that whilst mathjax is working and correctly renders the 2nd line, the first line of latex is not escaped.

EDIT2 (22/06/2017):
"Note from the future: cdn.mathjax.org is nearing its end-of-life, check mathjax.org/cdn-shutting-down for migration tips (and perhaps update your answer for future readers)" - Thanks to user Peter Krautzberger Basically this means the cdn used in my code example will need to be replaced with a localised version of mathjax.

1
We need a self-contained test case to have any hope of helping.zwol
Ok zach i'll do my best - check back when you get the chanceAllan W Smith
Try adding this parameter to tex2jax: inlineMath: [["\[","\]"]gab06
Inline math is \( not \[ So I'm afraid that won't workAllan W Smith
Note from the future: cdn.mathjax.org is nearing its end-of-life, check mathjax.org/cdn-shutting-down for migration tips (and perhaps update your answer for future readers).Peter Krautzberger

1 Answers

2
votes

The macros \textup, \AE, and \SS are not part of the default MathJax TeX macros and are not defined in your inline configuration, which is why the rendering in the image has them marked in red.

You'll see a more specific error if you remove the noundefined and noerrors extensions from your configuration -- which are also in the combined configuration TeX-AMS_HTML, so you'll need to drop that as well; as you can see from the link, your inline configuration entails all of TeX-AMS_HTML. (In production, it's preferable to use a combined configuration file since they load as a single large file.)

For a list of all default MathJax macros, see http://docs.mathjax.org/en/latest/tex.html#supported-latex-commands.

For how to define macros in MathJax, see https://tex.stackexchange.com/questions/139699/equivalent-of-mathup-for-upright-text-in-math-mode. From there an example:

MathJax.Hub.Config({
  TeX: {
    Macros: {
      RR: "{\\bf R}",
      bold: ["{\\bf #1}",1]
    }
  }
});

i.e., add a Macros block to the TeX block in your configuration.

(A particular case is\textup, which is a LaTeX text mode macro and MathJax focuses on math mode. Depending on the use case, the math equivalent might be \text{}, \mathrm{}, or something else, see this TeX.SE questions. Of course you can define \textup to be whatever you like but you might run into trouble backporting content to real TeX).