Docs

Mathematics

Inline and display math with KaTeX — delimiters, common commands, and limits

Mathematics is rendered with KaTeX, which implements a large, fast subset of LaTeX math mode. If you write LaTeX, you already write this.

Inline math

Wrap in single dollars:

Result

The map is continuous if is open for every open .

Markdown
The map $f: X \to Y$ is continuous if $f^{-1}(U)$ is open for every open $U$.

The LaTeX delimiters \( ... \) work too, so sources pasted from a .tex file render without rewriting.

Display math

Wrap in double dollars on their own lines:

Result
Markdown
$$
\int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}
$$

\[ ... \] is equivalent. Display math that overflows a narrow screen scrolls horizontally instead of breaking the layout.

On one line or on its own lines

A display formula needs its delimiters on their own lines. $$x^2$$ written inside a line, or alone on one line, is still a formula in the line, and so is \[x^2\]. That matters beyond centring: an environment that only works in display mode, such as align*, or a \tag, fails in red when the formula is inline, which looks like a KaTeX error rather than the delimiter mistake it is. The editor always writes the multi-line form.

Every spelling, and what it gives:

Written Result Note
$x^2$ , inline Inline maths.
\(x^2\) , inline Inline maths, as in LaTeX.
$$x^2$$ , inline Still inline: on one line, double dollars do not make a display.
\[x^2\] , inline Also inline on one line: it is rewritten to double dollars first.
$$
x^2
$$
a display formula, centred on its own line Display maths: the delimiters on their own lines.
\[
x^2
\]
a display formula, centred on its own line Display maths, as in LaTeX, also on their own lines.

Multi-line and aligned equations

The standard alignment environments work inside display math:

Result
Markdown
$$
\begin{aligned}
(a+b)^2 &= a^2 + 2ab + b^2 \\
(a-b)^2 &= a^2 - 2ab + b^2
\end{aligned}
$$

Also available: cases, matrix / pmatrix / bmatrix / vmatrix, gathered, array. See the full list of supported environments.

Derivations

A proof laid out as numbered lines, with a justification and a line number on each row, is one display formula: a \begin{array}{lll} with a row per line and & between the three columns.

Result
Markdown
$$
\begin{array}{lll}
[\text{Hyp}] & \vdash p \supset q & (1)\\
[\text{Hyp}] & \vdash q \supset r & (2)\\
[(1), (2), \text{Syll}] & \vdash p \supset r & (3)
\end{array}
$$
  • l aligns a column left; use c or r for a column that should be centred or flush right.
  • Names of rules and abbreviations (Hyp, Syll, Df) go in \text{…} so they are set upright.
  • A reference inside the formula stays text: a formula cannot hold a link. If a line must link to the result it cites, say so in the prose around the formula.

There is no separate derivation block, and none is needed: the layout renders as written here and converts to LaTeX unchanged.

Common commands

You write You get
\frac{a}{b}, \tfrac{a}{b} ,
\sqrt{x}, \sqrt[3]{x} ,
x_i, x^2, x_i^2 , ,
\sum_{i=1}^{n}
\int_a^b, \oint ,
\lim_{x \to 0}
\alpha, \beta, \Gamma, \Omega
\mathbb{R}, \mathcal{L}, \mathfrak{g}
\leq, \geq, \neq, \approx, \equiv
\in, \subset, \cup, \cap, \setminus
\to, \mapsto, \implies, \iff
\infty, \partial, \nabla, \hbar
\langle x, y \rangle
\hat{x}, \bar{x}, \vec{v}, \dot{x}

The authoritative reference is KaTeX's supported functions page.

Limits and behavior

  • Errors render in place. A command KaTeX does not know renders the raw source in red rather than failing the page — you see exactly what to fix.
  • Math mode only. KaTeX renders math, not LaTeX documents: no \documentclass, no \section, no text-mode environments. Document structure is Markdown's job; only the mathematics goes in dollars.
  • Macros last one formula. A \newcommand or \def works inside the formula that defines it and nowhere else, so a definition at the top of a document does not reach the formulae below it. Write commands out in full.
  • A literal dollar sign is \$ in prose. Inside code spans and code blocks, $ is always literal and math is never rendered.
  • Diagrams. A rectangular commutative diagram with straight arrows works in a display with \begin{CD} (see Draw a commutative square). Anything else, tikzcd included, is not maths mode: use a TikZ block.