# Equations in normal LaTeX to MathJax formatting

To use the align environment in a document one does something like:

\begin{align*}
x &= \sqrt{4^2-1^2} \\
&= \sqrt{15}.
\end{align*}put


However, to achieve the same desired output on a webpage which uses MathJax to render math, as math.se does:

\begin{align*} x &= \sqrt{4^2-1^2} \\ &= \sqrt{15}. \end{align*}


must be done.

I want to save in some tex files the contents of some possible post for webpages which use MathJax, so the post would be whatever is between \begin{document} and \end{document}. But also, I want these documents to be compilable using pdflatex.

In order to achieve that, either the  or the align (and the like) environment must be redefined.

How to do so?

-
You do not need the $ and $ for MathJax to recognize this. You have not give your MathJax configuration, but as long as processEnvironments is true in the tex2jax section of your configuration, then it should pick up the \begin directly. –  Davide Cervone Sep 10 '13 at 1:12
@DavideCervone I've realized that after I posted this. If you put your comment as an answer I'll accept it. –  leo Sep 10 '13 at 3:58

## 3 Answers

You do not need the $ and $ for MathJax to recognize this. You have not given your MathJax configuration, but as long as processEnvironments is true in the tex2jax section of your configuration, then it should pick up the \begin directly. See the tex2jax section of the configuration documentation.

-

One idea is to have a conditional test; if the conditional is true (mathjax document), then nothing is done; if it is false (pdflatex document), then $ and $ are \let to \relax:

\documentclass{article}
\usepackage{amsmath}

\newif\ifmathjax
\ifmathjax\relax
\else
\let$\relax\let$\relax
\fi
\mathjaxfalse% for pdflatex
%\mathjaxtrue% for mathjax

\begin{document}

\begin{align*} x &= \sqrt{4^2-1^2} \\ &= \sqrt{15}. \end{align*}

\end{document}


Of course, this implies that in your document you can't simply write

$expression$


you'll need \begin{equation*} expression \end{equation*}.

-
That can be a problem. Is it possible to redefine the align environment instead? The only thing which is needed is to allow the syntax \begin{align*} ... \end{align*} –  leo Sep 9 '13 at 4:40
Just checked. It seems that there's no problem with using the align environment without the . My question is useless. –  leo Sep 9 '13 at 5:06

Did you read the mathjax documentation. align* should work just fine. But it is not supported by mathjax by default. If I call it as

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


then things like align* works just fine.

-