Skip to content

Using LaTeX and MathJax

Joram Soch edited this page Nov 1, 2024 · 7 revisions

The source code for proofs and definitions in "The Book of Statistical Proofs" uses a combination of Markdown, MathJax and LaTeX. On this page, we collect a set of rules and recommendations for applying LaTeX markup to typeset formulas. For more information, see the suggested notation for the StatProofBook.

Basic rules

  1. Use $...$ for in-line math, e.g.
Let $X$ be an $n \times 1$ random vector.
  1. Use $$...$$ for stand-alone equations, e.g.
$$
y = Ax + b \sim \mathcal{N}(A\mu + b, A \Sigma A^\mathrm{T}) \; .
$$
  1. Use $$ \begin{split} ...&... \\ ...&... \end{split} $$ to write multi-line equations, e.g.
$$
\begin{split}
M_y(t) &= \exp \left[ t^\mathrm{T} b \right] \cdot M_x(At) \\
&= \exp \left[ t^\mathrm{T} b \right] \cdot \exp \left[ t^\mathrm{T} A \mu + \frac{1}{2} t^\mathrm{T} A \Sigma A^\mathrm{T} t \right] \\
&= \exp \left[ t^\mathrm{T} \left( A \mu + b \right) + \frac{1}{2} t^\mathrm{T} A \Sigma A^\mathrm{T} t \right] \; .
\end{split}
$$
  1. Label each stand-alone equation (also splitted ones) using \label{eq:XYZ}, e.g.
$$ \label{eq:mvn-pdf}
f_X(x) = \frac{1}{\sqrt{(2 \pi)^n |\Sigma|}} \cdot \exp \left[ -\frac{1}{2} (x-\mu)^\mathrm{T} \Sigma^{-1} (x-\mu) \right] \; .
$$
  1. You can then reference them in in-line math or other equations using \eqref{eq:XYZ}, e.g.
$$ \label{eq:y-mgf-s2}
\begin{split}
M_y(t) &\overset{\eqref{eq:y-mgf-s1}}{=} \exp \left[ t^\mathrm{T} b \right] \cdot M_x(At) \\
&\overset{\eqref{eq:mvn-mgf}}{=} \exp \left[ t^\mathrm{T} b \right] \cdot \exp \left[ t^\mathrm{T} A \mu + \frac{1}{2} t^\mathrm{T} A \Sigma A^\mathrm{T} t \right] \\
&= \exp \left[ t^\mathrm{T} \left( A \mu + b \right) + \frac{1}{2} t^\mathrm{T} A \Sigma A^\mathrm{T} t \right] \; .
\end{split}
$$

Things to avoid

  1. Do not use a vertical bar (|) in in-line math, because it will be interpreted as indicating a table (Markdown).

    Solution: Use \vert, \lvert, \rvert or \mid, depending on your specific formula and context.

  2. Do not use double blackslash (\\) in in-line math, because it will be converted to a single backslash (HTML).

    Solution: Use \\\\ or \atop, depending on your specific expression and requirements.

  3. Do not use two consecutive curly opening braces ({{) in any equation, because it will cause a build error (Jekyll).

    Solution: Put a space between the two braces in order to avoid the build error: { {.

  4. Do not put anything after $$ ending a stand-alone equation, because the equation will be displayed incorrectly.

    Solution: Always leave an empty line after $$. Put \; ,, \; ; or \; . into the equation.

  5. Sometimes, in-line equations containing }_ fail to render due to interactions of Markdown and MathJax.

    Solution: Replace _ by \_. For more information, see this Stackoverflow post.

Clone this wiki locally