18

I'm using MathJax to display math in a webpage. My MathJax code looks like this:

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

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

    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ],
         processEscapes: true
        }
      });
</script>

MathJax seems to work great, however I simply can't figure out how on earth to write multi-line equations. For example, this multi-line equation doesn't render properly. The entire equation is on one line instead of 3:

$$
\begin{eqnarray} 
y &=& x^4 + 4      \nonumber \\
  &=& (x^2+2)^2 -4x^2 \nonumber \\
  &\le&(x^2+2)^2    \nonumber
\end{eqnarray} 
$$
turtle
  • 7,533
  • 18
  • 68
  • 97
  • the default block markup is `\[` to open and `\]` to close, does it work with those? – Mike 'Pomax' Kamermans Sep 17 '13 at 22:13
  • Unfortunately, no. It doesn't work with the default delimiters. – turtle Sep 17 '13 at 22:15
  • 1
    just noticed your config is after you load in mathjax - have you tried swapping the order, so the config gets bound first? Not sure whether you can set config options after loading mathjax.js – Mike 'Pomax' Kamermans Sep 17 '13 at 22:57
  • 3
    Mike is right, the config should come before loading MathJax, but that is not the source of the problem here. You are probably using a blog or wiki software that processes backslashes in some way when it creates the HTML page. I suspect `\\​` is being turned into `\​`. Use the MathJax contextual menu to view the TeX source of your equation and see if the double backslashes are really there. I'll bet they are single ones. You may also lose all the other backslashes, too. So it may be that you have to double them all. – Davide Cervone Sep 19 '13 at 09:55
  • You may run into problems with other characters, like `_` or `*`, if they have special meaning in your wiki. – Davide Cervone Sep 19 '13 at 09:56
  • 7
    Turns out I had to add 6 escapes to each line: `\nonumber \\\\\\`, then it worked. – turtle Sep 20 '13 at 15:13
  • Note from the future: cdn.mathjax.org is nearing its end-of-life, check https://www.mathjax.org/cdn-shutting-down for migration tips (and perhaps update your post for future readers). – Peter Krautzberger Apr 21 '17 at 07:36

2 Answers2

13

The $$ wants to be touching the math in order to be recognized as delimiters. To make your sample work, remove the newlines after/before the opening/closing $$:

$$\begin{eqnarray} 
y &=& x^4 + 4      \nonumber \\
&=& (x^2+2)^2 -4x^2 \nonumber \\
&\le&(x^2+2)^2    \nonumber
\end{eqnarray}$$

(This works for me using Marked2 in MathJax mode):

smallberries
  • 188
  • 2
  • 5
  • 1
    Thank you for this answer! But... should use `align` instead of `eqnarray` (https://tex.stackexchange.com/a/197/78991) – samlaf Jul 16 '22 at 06:52
1
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: false,
    }
})
tarikakyol
  • 513
  • 7
  • 13