Skip to content

Will Xu's Blog

Katex Formula Crash Course

Katex1 min read

How to input math formulas using KaTeX plugin.

Common constructs

superscript
1a^2 + b^2 = c^2
a2+b2=c2a^2 + b^2 = c^2
1e^{i\pi} + 1 = 0
eiπ+1=0e^{i\pi} + 1 = 0
subscript
1s = a_1 + a_2 + \cdots + a_n
s=a1+a2++ans = a_1 + a_2 + \cdots + a_n
1A_0 = W_{0,0} + W_{0,1} + W_{0,2} + \cdots + W_{0,n}
A0=W0,0+W0,1+W0,2++W0,nA_0 = W_{0,0} + W_{0,1} + W_{0,2} + \cdots + W_{0,n}
square root
1y = \sqrt{x}
y=xy = \sqrt{x}
1y = \sqrt[n]{x}
y=xny = \sqrt[n]{x}
fraction
1z = \frac{x}{y}
z=xyz = \frac{x}{y}
1z = \frac{x}{1+\frac{y}{8}}
z=x1+y8z = \frac{x}{1+\frac{y}{8}}

Greek Letters

Example
1\alpha, \Alpha
α,A\alpha, \Alpha
All Greek letters
α,A\alpha, \Alpha\rightarrow\alpha, \Alpha
β,B\beta, \Beta\rightarrow\beta, \Beta
γ,Γ\gamma, \Gamma\rightarrow\gamma, \Gamma
δ,Δ\delta, \Delta\rightarrow\delta, \Delta
ϵ,E,ε\epsilon, \Epsilon, \varepsilon\rightarrow\epsilon, \Epsilon, \varepsilon
ζ,Z\zeta, \Zeta\rightarrow\zeta, \Zeta
η,H\eta, \Eta\rightarrow\eta, \Eta
θ,Θ,ϑ\theta, \Theta, \vartheta\rightarrow\theta, \Theta, \vartheta
ι,I\iota, \Iota\rightarrow\iota, \Iota
κ,K\kappa, \Kappa\rightarrow\kappa, \Kappa
λ,Λ\lambda, \Lambda\rightarrow\lambda, \Lambda
μ,M\mu, \Mu\rightarrow\mu, \Mu
ν,N\nu, \Nu\rightarrow\nu, \Nu
ξ,Ξ\xi, \Xi\rightarrow\xi, \Xi
o,Oo, O\rightarrowo, O
π,Π,ϖ\pi, \Pi, \varpi\rightarrow\pi, \Pi, \varpi
ρ,P,ϱ\rho, \Rho, \varrho\rightarrow\rho, \Rho, \varrho
σ,Σ,ς\sigma, \Sigma, \varsigma\rightarrow\sigma, \Sigma, \varsigma
τ,T\tau, \Tau\rightarrow\tau, \Tau
υ,Υ\upsilon, \Upsilon\rightarrow\upsilon, \Upsilon
ϕ,Φ,φ\phi, \Phi, \varphi\rightarrow\phi, \Phi, \varphi
χ,X\chi, \Chi\rightarrow\chi, \Chi
ψ,Ψ\psi, \Psi\rightarrow\psi, \Psi
ω,Ω\omega, \Omega\rightarrow\omega, \Omega

Parenthesis and Brackets

(x+y)(x+y)\rightarrow(x+y)
[x+y][x+y]\rightarrow[x+y]
{x+y}\{x+y\}\rightarrow\{x+y\}
x+y\langle x+y \rangle\rightarrow\langle x+y \rangle
x+y\|x+y\|\rightarrow\|x+y\|

To make the parenthesis resize dynamically, put \left and \right before parenthesis.

  • with \left and \right:
1F = G \left( \frac{m_1 m_2}{r^2} \right)
F=G(m1m2r2)F = G \left( \frac{m_1 m_2}{r^2} \right)
  • without \left and \right:
1F = G ( \frac{m_1 m_2}{r^2} )
F=G(m1m2r2)F = G ( \frac{m_1 m_2}{r^2} )

To manually control parenthesis size, use \big, \Big, \bigg, \Bigg.

1\big( \Big( \bigg( \Bigg(,
2\big[ \Big[ \bigg[ \Bigg[
((((,[[[[\big( \Big( \bigg( \Bigg(, \big[ \Big[ \bigg[ \Bigg[

Sum and Product

1\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
i=1ni=n(n+1)2\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
1\prod_{i=1}^{n} i = n!
i=1ni=n!\prod_{i=1}^{n} i = n!

Modulo

  • Binary modulo \bmod
1c = a \bmod b
c=amodbc = a \bmod b
  • Parenthesis modulo \pmod
1a^p \equiv a \pmod{p}
apa(modp)a^p \equiv a \pmod{p}

Decorations

ff'\rightarrowf'
ff''\rightarrowf''
x˙\dot{x}\rightarrow\dot{x}
x¨\ddot{x}\rightarrow\ddot{x}
x^\hat{x}\rightarrow\hat{x}
x~\tilde{x}\rightarrow\tilde{x}
xˉ\bar{x}\rightarrow\bar{x}
x\vec{x}\rightarrow\vec{x}
1\overline{x + y + z}
x+y+z\overline{x + y + z}
1\underline{x + y + z}
x+y+z\underline{x + y + z}
1\overbrace{x + y + z}^{|A|}
x+y+zA\overbrace{x + y + z}^{|A|}
1\underbrace{x + y + z}_{|A|}
x+y+zA\underbrace{x + y + z}_{|A|}

Dots

  • low dots
1\{0, 1, 2, \ldots\}
{0,1,2,}\{0, 1, 2, \ldots\}
  • center dots
11 + 2 + \cdots + n
1+2++n1 + 2 + \cdots + n
  • cdot vs cdots
1x_1 \cdot x_2 \cdot x_3 \cdots x_n
x1x2x3xnx_1 \cdot x_2 \cdot x_3 \cdots x_n

Sets

N\mathbb{N}\rightarrow\mathbb{N}
Q\mathbb{Q}\rightarrow\mathbb{Q}
R\mathbb{R}\rightarrow\mathbb{R}
Z\mathbb{Z}\rightarrow\mathbb{Z}
C\mathbb{C}\rightarrow\mathbb{C}
\emptyset\rightarrow\emptyset
\cup\rightarrow\cup
\cap\rightarrow\cap
\setminus\rightarrow\setminus
\subset\rightarrow\subset
\subseteq\rightarrow\subseteq
\supset\rightarrow\supset
\supseteq\rightarrow\supseteq
\in\rightarrow\in
\ni\rightarrow\ni
\notin\rightarrow\notin
\forall\rightarrow\forall
\exists\rightarrow\exists
\nexists\rightarrow\nexists
\equiv\rightarrow\equiv
¬\neg\rightarrow\neg
\lor\rightarrow\lor
\land\rightarrow\land

Geometry

AB\overline{AB}\rightarrow\overline{AB}
AB\overrightarrow{AB}\rightarrow\overrightarrow{AB}
A\angle A\rightarrow\angle A
ABC\triangle ABC\rightarrow\triangle ABC
ABCD\square{ABCD}\rightarrow\square{ABCD}
\cong\rightarrow\cong
\sim\rightarrow\sim
\|\rightarrow\|
\perp\rightarrow\perp
4545^{\circ}\rightarrow45^{\circ}
sin(θ)\sin(\theta)\rightarrow\sin(\theta)
cos(θ)\cos(\theta)\rightarrow\cos(\theta)
tan(θ)\tan(\theta)\rightarrow\tan(\theta)

Calculus

  • Derivative
1v = \frac{ds}{dt}, a = \frac{dv}{dt} = \frac{d^2 s}{dt^2}
v=dsdt,a=dvdt=d2sdt2v = \frac{ds}{dt}, a = \frac{dv}{dt} = \frac{d^2 s}{dt^2}
  • Partial
1\frac{\partial^2u}{\partial t^2} = c^2 \frac{\partial^2 u}{\partial x^2}
2ut2=c22ux2\frac{\partial^2u}{\partial t^2} = c^2 \frac{\partial^2 u}{\partial x^2}
  • Integral
1\int udv = uv - \int v du
udv=uvvdu\int udv = uv - \int v du

Matrix

  • bmatrix for bracket, and pmatrix for parenthesis.
1M(\theta) =
2\begin{bmatrix}
3 \cos(\theta) & -\sin(\theta) & 0 \\
4 \sin(\theta) & \cos(\theta) & 0 \\
5 0 & 0 & 1 \\
6\end{bmatrix}
M(θ)=[cos(θ)sin(θ)0sin(θ)cos(θ)0001]M(\theta) = \begin{bmatrix} \cos(\theta) & -\sin(\theta) & 0 \\ \sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}

Cases

1f(x) =
2\begin{cases}
3 1, & x < 0 \\
4 x + 1, & x >= 0
5\end{cases}
f(x)={1,x<0x+1,x>=0f(x) = \begin{cases} 1, & x < 0 \\ x + 1, & x >= 0 \end{cases}