Katex Formula Crash Course

09/01/2019 — In Katex

How to input math formulas using KaTeX plugin.

Common constructs

superscript
a^2 + b^2 = c^2
a2+b2=c2a^2 + b^2 = c^2
e^{i\pi} + 1 = 0
eiπ+1=0e^{i\pi} + 1 = 0
subscript
s = a_1 + a_2 + \cdots + a_n
s=a1+a2++ans = a_1 + a_2 + \cdots + a_n
A_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
y = \sqrt{x}
y=xy = \sqrt{x}
y = \sqrt[n]{x}
y=xny = \sqrt[n]{x}
fraction
z = \frac{x}{y}
z=xyz = \frac{x}{y}
z = \frac{x}{1+\frac{y}{8}}
z=x1+y8z = \frac{x}{1+\frac{y}{8}}

Greek Letters

Example
\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:
F = 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:
F = 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.

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

Sum and Product

\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}
\prod_{i=1}^{n} i = n!
i=1ni=n!\prod_{i=1}^{n} i = n!

Modulo

  • Binary modulo \bmod
c = a \bmod b
c=amodbc = a \bmod b
  • Parenthesis modulo \pmod
a^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}
\overline{x + y + z}
x+y+z\overline{x + y + z}
\underline{x + y + z}
x+y+z\underline{x + y + z}
\overbrace{x + y + z}^{|A|}
x+y+zA\overbrace{x + y + z}^{|A|}
\underbrace{x + y + z}_{|A|}
x+y+zA\underbrace{x + y + z}_{|A|}

Dots

  • low dots
\{0, 1, 2, \ldots\}
{0,1,2,}\{0, 1, 2, \ldots\}
  • center dots
1 + 2 + \cdots + n
1+2++n1 + 2 + \cdots + n
  • cdot vs cdots
x_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
v = \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
\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
\int udv = uv - \int v du
udv=uvvdu\int udv = uv - \int v du

Matrix

  • bmatrix for bracket, and pmatrix for parenthesis.
M(\theta) =
\begin{bmatrix}
\cos(\theta) & -\sin(\theta) & 0 \\
\sin(\theta) & \cos(\theta) & 0 \\
0 & 0 & 1 \\
\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

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