<span class="mw-page-title-main">MathJax</span>
Fabrice P. Lauss𝕪s erzajlk Web

MathJax

MathJax is an open source Ajax-based framework to display mathematical notations in web browsers. It renders the input, entered as LaTeX or MathML expressions, as high-quality display in MathML or HTML with CSS and integrates well with text-based content, both in display mode and inline.

We are using Mathjax on laussy.org. Here are possible reasons why it sometimes stop working, according to Grok.

Examples

A result from Ramanujan:

$$ \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\ldots} } } }\,. $$

A result from Elena:

$$\begin{multline}\label{eq:elena} S_\mathrm{inc}(\omega)=\Big(\frac{2P_\sigma}{\kappa_\sigma+\Gamma_\sigma}-\frac{\Gamma_\sigma}{\kappa_\sigma}\Big) \delta(\omega)+\frac{\frac{1}{2\pi}\frac{\Gamma_\sigma}{2}}{\big(\frac{\Gamma_\sigma}{2}\big)^2+\omega^2}+\\ \frac{(P_\sigma-\gamma_\sigma)\Big(3\Gamma_\sigma^3-(P_\sigma-5\gamma_\sigma)\Gamma_\sigma\kappa_\sigma+2\gamma_\sigma \kappa_\sigma^2\Big)-\Big(\Gamma_\sigma^2-(3P_\sigma-\gamma_\sigma)\kappa_\sigma\Big)\omega^2}{\pi(\kappa_\sigma+\Gamma_\sigma)\Big(9\Gamma_\sigma^2\omega^2+[2\omega^2-\kappa_\sigma(P_\sigma-\gamma_\sigma)]^2\Big)}\,, \end{multline}$$

A result from Fabrice:

\begin{equation}\label{eq:fabrice} p(n_0,\Sigma) =\frac{(1-\theta_0)(1-\theta)^M\theta^{n_0+\Sigma}{M+n_0+\Sigma-1\choose M-1}{}_2F_1(1,-n_0+\Sigma,-M-n_0+\Sigma+1,\frac{\theta_0}{\theta})}{\left(\frac{\xi}{\xi-1}\right)^M-\frac1{\xi^{n_0+1}}{M+\Sigma+n_0\choose M-1}{}_2F_1(1,M+\Sigma+n_0+1,\Sigma+n_0+2,\frac{1}{\xi})}\,.\end{equation}

You may have noticed I could not resist the temptation to label them with our wz tooltips.

The beauty of it beyond perfect typesetting and integration in the flow of the text is that you can even label them. Equation \eqref{eq:elena} is the lineshape for the incoherent Mollow triplet, that is, the luminescence spectrum of a two-level emitter in strong-coupling with a cavity which it brought into lasing [1]. Equation \eqref{eq:fabrice} is the exact solution of quantum Boltzmann master equation which provides an analytical description of Bose-Einstein condensation.

And just when you thought you could not be impressed further, you have to get a look at inline display, like, Euler's formula $e^{i\pi}+1=0$, displayed idiotically to feature all the fundamental numbers, $e$, $i$, $\pi$, $0$ and $1$. See the Knuthian quality of the insert of math in the text? I'm doing that merely putting $\TeX$'s dollar signs around, I'm feeling at home on the web! What an age we live in!

Wikitext keeps its hands off the maths

An equation is not prose, but until 30 August (2026) the wiki parser had no way of knowing that. A <math> tag is a tag extension: MediaWiki lifts its contents out into a strip marker before anything else runs and puts them back verbatim at the end, so nothing it does can reach inside. Maths written the way this wiki actually writes it—$$…$$, or a bare \begin{align}—had none of that protection, because those delimiters are handed to MathJax to find in the finished page, client-side, and no parser hook ever saw them. Three habits of $\mathrm{\LaTeX}$ then walked straight into three rules of wikitext: an indented continuation line begins with a space, and a leading space is a <pre> block, which tears the body of the equation out of its paragraph and strands \begin and \end on either side of it, where MathJax can no longer pair them; a double prime, \vartheta'', is two apostrophes, and two apostrophes are italics, so <i> tags get spliced into the middle of the $\mathrm{\TeX}$; and a blank line inside a long equation closes the paragraph, with the same stranding as the first. The equation came out as its own source code, and nothing said why.

Since SimpleMathJax 0.8.4-laussy5 a parser hook lifts the maths out too, and all three go away at once—along with every other collision of the same kind, because the equation stops being text the parser can see. InternalParseBeforeLinks is the seam that works: it runs after templates have expanded and after the contents of <syntaxhighlight>, <pre> and <nowiki> have already become strip markers—so a listing full of dollar signs cannot be mistaken for an equation—and before the passes that make tables, italics and indented blocks, which are exactly the three that did the damage. What it takes are $$…$$, \(…\) and the AMS environments that stand on their own: align, alignat, flalign, gather, multline, equation, eqnarray and subequations, starred or not, each \end matched to its own \begin so that a subequations wrapping an align is one piece and not two.

One thing is deliberately not protected: single-dollar inline maths. $…$ cannot be told apart from prose—a sentence naming $wgServer and $wgScriptPath would pair the two dollars and everything between them would vanish—and by that point in the parse a <code> is no shelter. Inline maths lives on one line and so meets neither the leading-space nor the blank-line rule; the only one it is still exposed to is the apostrophe, so a double prime inline wants x^{\prime\prime} rather than two quotes. MathJax mis-pairs stray dollars client-side already, and that has not changed.

There is a guard against the same accident on the display delimiter. One stray $$ in prose puts every later pair on the page out of phase, and a runaway match that happened to span a table would take the table with it—structure lost, rather than merely a badly typeset stretch. So a match is refused if any line inside it opens or closes a table or is a heading: no equation begins a line with a pipe-brace or an equals sign, and one that does is a runaway by definition. Refusing leaves the text exactly as it was before, which is the worst that can happen.

A welcome side effect: a | inside a display equation no longer splits a table cell, since the equation is out of the wikitext before the table is built. P(a|b) can be written as itself.

Colors in MathJaX

<span style="color: red;">$$ax^2+bx+c$$</span>

$$\color{red}{ax^2}+bx+c$$

yields:

$$ax^2+bx+c$$

but if the color is standard, then

\color{red}{ax^2}+bx+c

also works.

See also

Links