A KaTeX Rendering Tour

An evaluation post: the LaTeX features this site renders via KaTeX.

— 54 minute read

This is an evaluation post. Its only job is to show how the math rules in src/utils/markdown.js render to the page, so the KaTeX integration can be reviewed. Delete it when you are done.

Delimiters: inline math is $...$, display math is $$...$$ (single-line or multi-line). Two conventions: no space directly inside the delimiters, and a $ that immediately follows a word character is never treated as an opener. Red text means KaTeX refused to render the formula (see the last sections).

Inline math permalink

Euler's identity eiπ+1=0e^{i\pi}+1=0 is often called the most beautiful equation in mathematics. A single sentence can carry several formulas: the area of a circle is A=πr2A=\pi r^2, the slope of y=mx+by=mx+b is mm, and the discriminant Δ=b2−4ac\Delta=b^2-4ac decides whether the roots of ax2+bx+c=0ax^2+bx+c=0 are real.

Sub- and superscripts chain: xi(2)x_i^{(2)} is the second iterate of the ii-th component, while f−1(g−1(x))f^{-1}(g^{-1}(x)) composes inverse functions, and primes work as f′=f′′=f′′′f' = f'' = f'''.

Inline big operators tuck their limits in: ∑i=1ni=n(n+1)2\sum_{i=1}^{n} i = \tfrac{n(n+1)}{2} and lim⁡x→0sin⁡xx=1\lim_{x\to 0} \frac{\sin x}{x} = 1. Force limits above and below with ∑i=1n\sum\limits_{i=1}^{n} and ∏k=0∞\prod\limits_{k=0}^{\infty}.

Prices stay literal — a 5$ resistor and a 10$ capacitor, or a $5 part and a $10 board: no math mode is entered, because the delimiters here never satisfy the opener rules.

Display blocks permalink

The quadratic formula, single-line block:

x=−b±b2−4ac2ax = \frac{-b \pm \sqrt{b^2-4ac}}{2a}

Multi-line blocks continue until a line ending in $$ — Maxwell's equations in differential form:

∇×B=μ0J+μ0ϵ0∂E∂t∇⋅E=ρϵ0∇×E=−∂B∂t∇⋅B=0\begin{aligned} \nabla \times \mathbf{B} &= \mu_0 \mathbf{J} + \mu_0 \epsilon_0 \frac{\partial \mathbf{E}}{\partial t} \\ \nabla \cdot \mathbf{E} &= \frac{\rho}{\epsilon_0} \\ \nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \\ \nabla \cdot \mathbf{B} &= 0 \end{aligned}

align lines up at the & positions — the Lorenz system:

x′=σ(y−x)y′=x(ρ−z)−yz′=xy−βz\begin{align} x' &= \sigma (y - x) \\ y' &= x (\rho - z) - y \\ z' &= xy - \beta z \end{align}

And align*:

a2+b2=c2tan⁡θ=ba\begin{align*} a^2 + b^2 &= c^2 \\ \tan\theta &= \frac{b}{a} \end{align*}

equation wraps a single formula (it does not get an automatic number in this build — see "Numbering and tags"):

eiπ+1=0\begin{equation} e^{i\pi} + 1 = 0 \end{equation}

gathered centers every line:

(x+y+z)2=x2+y2+z2+2xy+2xz+2yz\begin{gathered} (x+y+z)^2 = x^2 + y^2 + z^2 \\ + 2xy + 2xz + 2yz \end{gathered}

Matrices permalink

(abcd)=(ax+bycx+dy)\begin{pmatrix} a & b \\ c & d \end{pmatrix} = \begin{pmatrix} ax + by \\ cx + dy \end{pmatrix}

Round, square, and vertical bars; cases for piecewise functions:

u=[100−1],{abcd},P(t)={0,t<0t,0≤t≤12−t,1<t≤20,t>2\mathbf{u} = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}, \qquad \begin{Bmatrix} a & b \\ c & d \end{Bmatrix}, \qquad P(t) = \begin{cases} 0, & t < 0 \\ t, & 0 \le t \le 1 \\ 2 - t, & 1 < t \le 2 \\ 0, & t > 2 \end{cases}

Inline matrices stay at text scale: ∣abcd∣=ad−bc\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc, cos⁡θ−sin⁡θsin⁡θcos⁡θ\begin{smallmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{smallmatrix}, and the Euclidean norm is ∥x∥2=x12+⋯+xn2\lVert \mathbf{x} \rVert_2 = \sqrt{x_1^2 + \cdots + x_n^2}.

Big operators and limits permalink

Display mode puts limits above and below:

∑i=1n∏j=1mxij∫0∞e−x2 dx=π2∬Df(x,y) dx dy∮γf(z) dz⋃i=1nAi\sum_{i=1}^{n} \prod_{j=1}^{m} x_{ij} \qquad \int_{0}^{\infty} e^{-x^2}\,dx = \frac{\sqrt{\pi}}{2} \qquad \iint_{D} f(x,y)\,dx\,dy \qquad \oint_{\gamma} f(z)\,dz \qquad \bigcup_{i=1}^{n} A_i

Limits that read as limits:

lim⁡x→0ex−1x=1,lim sup⁡n→∞an≤lim inf⁡n→∞bn,lim⁡n→∞(1+1n)n=e\lim_{x\to 0} \frac{e^x - 1}{x} = 1, \qquad \limsup_{n\to\infty} a_n \le \liminf_{n\to\infty} b_n, \qquad \lim_{n\to\infty} \left(1 + \frac{1}{n}\right)^n = e

Fractions, radicals, continued fractions permalink

Nested fractions and indexed roots:

11+23+452+23+abn∂f∂x∣x=0\frac{1}{1 + \frac{2}{3 + \frac{4}{5}}} \qquad \sqrt{2} + \sqrt[3]{2} + \sqrt[n]{\frac{a}{b}} \qquad \frac{\partial f}{\partial x} \bigg|_{x=0}

A continued fraction, the kind of thing that would be painful to lay out by hand:

12+13+14+15\cfrac{1}{2 + \cfrac{1}{3 + \cfrac{1}{4 + \cfrac{1}{5}}}}

Accents, bars, and brackets permalink

θ^v⃗xˉf~xyz^xyz~x˙x¨\hat{\theta} \qquad \vec{v} \qquad \bar{x} \qquad \tilde{f} \qquad \widehat{xyz} \qquad \widetilde{xyz} \qquad \dot{x} \qquad \ddot{x} AB‾∑‾a+b+c⏞the sum of the termsx⋅x⋅x⏟the cubea=defblim⁡γ−+\overline{AB} \qquad \underline{\sum} \qquad \overbrace{a + b + c}^{\text{the sum of the terms}} \qquad \underbrace{x \cdot x \cdot x}_{\text{the cube}} \qquad a \stackrel{\text{def}}{=} b \qquad \underset{\gamma}{\lim} \qquad \overset{+}{-}

Fonts and text permalink

xAxxdxLRgxx\mathbf{x} \qquad \bm{A} \qquad \pmb{x} \qquad \mathit{x} \qquad \mathrm{d}x \qquad \mathcal{L} \qquad \mathbb{R} \qquad \mathfrak{g} \qquad \mathsf{x} \qquad \mathtt{x}

Text inside math: for x∈dom(f)\text{for } x \in \text{dom}(f), bold text\textbf{bold text}, italic text\textit{italic text}, and erf⁡(x)\operatorname{erf}(x) for a roman operator.

Delimiters, sizing, and spacing permalink

Auto-sizing delimiters scale to their content; \big through \Bigg do it manually; \left. and \right| size invisible anchors:

(ab)[abcd]{ab}ddx∣x=0(ab)(ab)\left( \frac{a}{b} \right) \qquad \left[ \begin{array}{cc} a & b \\ c & d \end{array} \right] \qquad \left\{ \frac{a}{b} \right\} \qquad \left. \frac{d}{dx} \right|_{x=0} \qquad \bigg( \frac{a}{b} \bigg) \quad \Bigg( \frac{a}{b} \Bigg)

Custom fraction delimiters with \genfrac, and the binomial coefficient:

[ab](nk)=n!k!(n−k)!(nk)\genfrac{[}{]}{0pt}{}{a}{b} \qquad \binom{n}{k} = \frac{n!}{k!(n-k)!} \qquad {n \choose k}

Spacing: thin $a\,b$, thick $a\;b$, negative $a\!b$, word $a\quad b$, and double-word $a\qquad b$.

Symbols permalink

Relations: a≤ba \le b, a≥ba \ge b, a≠ba \ne b, a≈ba \approx b, a≡ba \equiv b, a∼ba \sim b, a≃ba \simeq b, a≅ba \cong b, a∝ba \propto b, a≪ba \ll b, a≫ba \gg b, a⩽ba \leqslant b.

Operators: a+ba + b, a±ba \pm b, a∓ba \mp b, a×ba \times b, a⋅ba \cdot b, a∘ba \circ b, a∙ba \bullet b, a÷ba \div b, a mod ba \bmod b, a(modb)a \pmod{b}, a∣ba \mid b, a∤ba \nmid b.

Arrows: a→ba \to b, a↦ba \mapsto b, a→ba \rightarrow b, a⇒ba \Rightarrow b, a⇐ba \Leftarrow b, a  ⟺  ba \iff b, a→labelba \xrightarrow{\text{label}} b, a↪ba \hookrightarrow b, a↠ba \twoheadrightarrow b.

Sets and logic: a∈Sa \in S, a∉Sa \notin S, S⊂TS \subset T, S⊆TS \subseteq T, A∪BA \cup B, A∩BA \cap B, A∖BA \setminus B, ∅\emptyset, ∀x\forall x, ∃y\exists y, ∄z\nexists z, ∴\therefore, ∵\because.

Greek and geometry: α β γ δ ε ζ η θ ϑ ι κ λ μ ν ξ π ρ σ τ υ ϕ φ χ ψ ω\alpha\,\beta\,\gamma\,\delta\,\varepsilon\,\zeta\,\eta\,\theta\,\vartheta\,\iota\,\kappa\,\lambda\,\mu\,\nu\,\xi\,\pi\,\rho\,\sigma\,\tau\,\upsilon\,\phi\,\varphi\,\chi\,\psi\,\omega and capitals Γ Δ Θ Λ Ξ Π Σ Φ Ψ Ω\Gamma\,\Delta\,\Theta\,\Lambda\,\Xi\,\Pi\,\Sigma\,\Phi\,\Psi\,\Omega, plus ∠ABC\angle ABC, △ABC\triangle ABC, a⊥ba \perp b, a∥ba \parallel b, ℏ\hbar, ℓ\ell, ℜz\Re z, ℑz\Im z, ℵ0\aleph_0.

Color, boxes, and cancellation permalink

xf(x)aba colored box−b±b2−4ac2a\textcolor{red}{\mathbf{x}} \qquad \textcolor{blue}{f(x)} \qquad \textcolor{#e67e22}{\frac{a}{b}} \qquad \colorbox{yellow}{\text{a colored box}} \qquad \boxed{\frac{-b \pm \sqrt{b^2-4ac}}{2a}}

Cancellation, in three flavors: a+ba \cancel{+} b, x−yx \bcancel{-} y, z∗wz \xcancel{*} w.

Numbering and tags permalink

This KaTeX build does not number equation or align lines automatically, and \label/\eqref are unsupported. Explicit numbering works with \tag:

e=∑n=0∞1n!(2.71828)e = \sum_{n=0}^{\infty} \frac{1}{n!} \tag{2.71828}

Local macros permalink

\newcommand works, but only inside the formula that defines it — macros do not leak across formulas:

E[X]=μVar⁡(X)=E[(X−μ)2]\newcommand{\E}{\mathbb{E}} \qquad \newcommand{\Var}{\operatorname{Var}} \qquad \E[X] = \mu \qquad \Var(X) = \E[(X - \mu)^2]

Error handling permalink

KaTeX is called with throwOnError: false, so invalid math renders as readable red text at the failure point instead of breaking the build.

Unknown command:

\unknowncommandx\unknowncommand{x}

Unbalanced fraction:

\frac{1}

The \href command requires the trust option, which this site does not enable:

\href\href{https://example.org}{a link}

Known limitations permalink

  • Math does not wrap. This inline formula overflows the column instead of breaking: det⁡(a11a12a13a14a15a21a22a23a24a25a31a32a33a34a35a41a42a43a44a45a51a52a53a54a55)=∑σ∈S5sgn⁡(σ)∏i=15ai,σ(i)\det\begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} & a_{15} \\ a_{21} & a_{22} & a_{23} & a_{24} & a_{25} \\ a_{31} & a_{32} & a_{33} & a_{34} & a_{35} \\ a_{41} & a_{42} & a_{43} & a_{44} & a_{45} \\ a_{51} & a_{52} & a_{53} & a_{54} & a_{55} \end{pmatrix} = \sum_{\sigma \in S_5} \operatorname{sgn}(\sigma) \prod_{i=1}^{5} a_{i,\sigma(i)}
  • No automatic equation numbering: equation and align render without numbers, and \label/\eqref are unsupported — use \tag for explicit numbers.
  • \eqnarray, \multline, \widebar, \cancelto, \html, \href, \includegraphics, and \resizebox are unsupported in this KaTeX build (or disabled by default).
  • Inline math is one line only; a $ pair spanning a newline is literal text.