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 Δ=b24ac\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 f1(g1(x))f^{-1}(g^{-1}(x)) composes inverse functions, and primes work as f=f=ff' = 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 limx0sinxx=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±b24ac2ax = \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ϵ0EtE=ρϵ0×E=BtB=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=σ(yx)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=[1001],{abcd},P(t)={0,t<0t,0t12t,1<t20,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=adbc\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 x2=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=1nj=1mxij0ex2dx=π2Df(x,y)dxdyγf(z)dzi=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:

limx0ex1x=1,lim supnanlim infnbn,limn(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+abnfxx=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

θ^vxˉ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} ABa+b+cthe sum of the termsxxxthe 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 xdom(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}ddxx=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!(nk)!(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: aba \le b, aba \ge b, aba \ne b, aba \approx b, aba \equiv b, aba \sim b, aba \simeq b, aba \cong b, aba \propto b, aba \ll b, aba \gg b, aba \leqslant b.

Operators: a+ba + b, a±ba \pm b, aba \mp b, a×ba \times b, aba \cdot b, aba \circ b, aba \bullet b, a÷ba \div b, amodba \bmod b, a(modb)a \pmod{b}, aba \mid b, aba \nmid b.

Arrows: aba \to b, aba \mapsto b, aba \rightarrow b, aba \Rightarrow b, aba \Leftarrow b, a    ba \iff b, alabelba \xrightarrow{\text{label}} b, aba \hookrightarrow b, aba \twoheadrightarrow b.

Sets and logic: aSa \in S, aSa \notin S, STS \subset T, STS \subseteq T, ABA \cup B, ABA \cap B, ABA \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, aba \perp b, aba \parallel b, \hbar, \ell, z\Re z, z\Im z, 0\aleph_0.

Color, boxes, and cancellation permalink

xf(x)aba colored boxb±b24ac2a\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, xyx \bcancel{-} y, zwz \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=01n!(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.