22
$\begingroup$

I was trying to use the align environment on the main site. Here were the things I tried without success:

\begin{align*} A &= B \ &= C \ &= D \end{align*}

\begin{align*} A &= B \ &= C \ &= D \end{align*}

\begin{align*} A &= B \ &= C \ &= D \end{align*}

\begin{align*} A &= B \ &= C \ &= D \end{align*}

(incidentally, I'm also not sure how to display some code on this site, so if someone could go in an edit it so everyone else can see the code used for each of these attempts, that would be awesome)

Added by Rasmus:

\begin{align*} A &= B \\ &= C \\ &= D \end{align*}

$\endgroup$
3
  • $\begingroup$ Looks fine to me. $\endgroup$
    – Rasmus
    Commented Jan 22, 2012 at 15:18
  • $\begingroup$ That's because I failed to communicate properly that the C and D were supposed to be on separate lines. I figured it out already, though. $\endgroup$ Commented Jan 22, 2012 at 15:23
  • 3
    $\begingroup$ Using \\\ or \newline instead of \\ should work (see my edit). $\endgroup$
    – Rasmus
    Commented Jan 22, 2012 at 16:19

2 Answers 2

29
$\begingroup$

Dustan already discovered a workaround, but let me explain a little bit behind why that works:

The particular implementation/configuration of MathJax on this site allows for the use of \begin{align} and \end{align} environments to indicate the start and end of displayed material with syntax using the environments introduced in AMSTeX of the same name. That is, you can use \begin{align} and \end{align} in place of the $$ signs to trigger the activation of the Math environment. That is how things work on the MathJax side.

However, for rendering the user content, in the text boxes we use the MarkDown (or an extension thereof) syntax, where underscores _ translates to italics and double asterisks ** gives bold. As part of the MarkDown syntax, the backslash character \ is co-opted as an escape character, so you can type \* when you actually want to display the asterisk * without having it interpreted as part of the "mark up". It is now necessary then to also escape backslash itself, since it has acquired a functional meaning. That is, to display the backslash, you need to type \\ to get \.

Now you begin to see a little bit of conflict brewing on the horizon.

MarkDown wants to change \\s to \s. In the context of an align environment, when you use \\ for line breaks, MarkDown substitutes in \ and when MathJax processes, it sees just \ followed by a blank-space character, so it interprets it just as a space, not as a line break.

The reason that enclosing things in dollar signs can fix this is that SE has modified their MarkDown engine to explicitly ignore things inside special environments. For example, if you enclose things in back-ticks `, you enter the "code" environment and things will be displayed verbatim, without MarkDown mucking about and interpreting stuff. One of the special environments is the math environments when delimited by dollar signs.


To illustrate:

\begin{align} A & = B \\ & = C \end{align}

gives

\begin{align} A & = B \ & = C \end{align}

while

\begin{align} A & = B \\\\ & = C \end{align}

gives

\begin{align} A & = B \\ & = C \end{align}

and

$$ \begin{align} A & = B \\ & = C \end{align} $$

gives

$$ \begin{align} A & = B \\ & = C \end{align} $$

In the middle case MarkDown changes the four consecutive backslashes \\\\ to \\, which when parsed by MathJax gives the intended output.


One last remark: while the middle syntax works, it is exploiting the fact that the current implementation of MarkDown processes content before MathJax, and that it does not ignore non-dollar-sign-enclosed math environments. It can easily break if any of the conditions are changed. So I suggest taking the final syntax, that is, enclose everything in dollar signs, to make what you type more "future-proof".

$\endgroup$
3
$\begingroup$

I figured it out; unlike in regular TeX, it seems that the \$$ is necessary to render the align environment on this website.

$$\begin{align*}A &= B \\ &= C \\ &=D\end{align*}$$

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .