Writing Math — Every Notation Available in KaTeX
A comprehensive guide to Folio's math environments. Covers inline math, equation, align, gather, cases, matrix, and \newcommand — every KaTeX-based math notation explained.
1. Inline and Display Math
1.1. Inline Math
To embed math within text, enclose it in $...$:
The function $f(x) = x^2 + 1$ is always positive.
Result: The function is always positive.
1.2. Display Math
To display math on its own line, use $$...$$:
$$\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}$$
Result:
2. Numbered Equation Environments
2.1. equation Environment
Assigns a number to a single equation:
\begin{equation}
e^{i\pi} + 1 = 0
\end{equation}
Result:
To suppress the number, use equation*:
\begin{equation*}
\sum_{k=0}^{n} \binom{n}{k} = 2^n
\end{equation*}
Result:
2.2. align Environment
Displays multiple equations with alignment. Use & to mark alignment points and \\ for line breaks:
\begin{align}
(a + b)^2 &= a^2 + 2ab + b^2 \\
(a - b)^2 &= a^2 - 2ab + b^2 \\
(a + b)(a - b) &= a^2 - b^2
\end{align}
Result:
2.3. gather Environment
Lists equations centered without alignment:
\begin{gather}
x^2 + y^2 = r^2 \\
x = r \cos\theta \\
y = r \sin\theta
\end{gather}
Result:
2.4. multline Environment
Splits a long equation across multiple lines. The first line is left-aligned and the last line is right-aligned:
\begin{multline}
(x_1 + x_2 + x_3 + x_4 + x_5)^2 \\
= x_1^2 + x_2^2 + ... + x_5^2 \\
\quad + 2(x_1 x_2 + x_1 x_3 + ...)
\end{multline}
Result:
3. Piecewise Definitions and Matrices
3.1. cases Environment
Write piecewise definitions:
$$
|x| = \begin{cases}
x & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}
$$
Result:
Another example (the Fibonacci sequence):
$$
f(n) = \begin{cases}
1 & n = 0 \\
1 & n = 1 \\
f(n-1) + f(n-2) & n \geq 2
\end{cases}
$$
Result:
3.2. Matrix Environments
Choose the environment based on the bracket style:
| Environment | Brackets |
matrix |
None |
pmatrix |
Parentheses |
bmatrix |
Square brackets |
Bmatrix |
Curly braces |
vmatrix |
Vertical bars |
Vmatrix |
Double bars |
$$
A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, \quad
\det A = \begin{vmatrix} 1 & 2 \\ 3 & 4 \end{vmatrix} = -2
$$
Result:
Use smallmatrix for inline matrices:
The matrix $\left(\begin{smallmatrix} a & b \\ c & d \end{smallmatrix}\right)$ like so.
Result: The matrix like so.
4. Math Symbols and Commands
4.1. Greek Letters
Uppercase:
4.2. Operators and Relations
4.3. Big Operators
4.4. Superscripts, Subscripts, and Decorations
4.5. Fractions and Roots
4.6. Delimiter Sizing
\left and \right auto-size delimiters:
4.7. Math Fonts
5. Custom Commands
You can define custom commands with \newcommand. Writing them at the top of an article makes them available within that article, but registering them in the Settings preamble editor makes them available across all articles automatically.
\newcommand{\R}{\mathbb{R}}
\newcommand{\norm}[1]{\left\| #1 \right\|}
\newcommand{\inner}[2]{\left\langle #1, #2 \right\rangle}
With the above definitions, \R expands to , \norm{v} to , and \inner{u}{v} to .
\DeclareMathOperator can be used to define math operators:
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\rank}{rank}
This gives proper spacing: , .
6. Summary
On Folio, standard LaTeX math syntax works almost exactly as expected. All commands and environments supported by KaTeX are available. Next, we'll look at theorem environments in detail.
Mathematics "between the lines" — exploring the intuition textbooks leave out, written in LaTeX on Folio.