If you write technical documentation, academic notes, or scientific papers in Markdown, you’ll eventually need to include mathematical equations. KaTeX is the fastest and most reliable way to render math in Markdown — and it works beautifully on Android with MerMD.

This guide covers everything you need to know about writing KaTeX math in Markdown, from basic inline expressions to complex multi-line equations.

What is KaTeX?

KaTeX (pronounced “KA-tech”) is a fast math typesetting library originally developed by Khan Academy. It renders LaTeX-style math notation into beautifully formatted equations. Unlike MathJax, KaTeX renders synchronously and produces identical output on every device.

Key advantages of KaTeX:

  • Blazing fast — renders in milliseconds, even on mobile devices
  • High quality — publication-grade typesetting
  • Wide support — 300+ LaTeX functions supported
  • Consistent — same rendering across all platforms

Inline Math vs. Display Math

There are two ways to include math in Markdown:

Inline Math

Inline math appears within a line of text. Wrap your expression in single dollar signs:

The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ and it solves any quadratic equation.

Renders as:

The quadratic formula is x=b±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} and it solves any quadratic equation.

Display Math

Display math is centered on its own line. Wrap expressions in double dollar signs:

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

Renders as:

0ex2dx=π2\int_{0}^{\infty} e^{-x^2} \, dx = \frac{\sqrt{\pi}}{2}

Fractions

$\frac{numerator}{denominator}$

$
\frac{x^2 + 1}{x - 1}
$

Renders as:

numeratordenominator\frac{numerator}{denominator}

x2+1x1\frac{x^2 + 1}{x - 1}

$
\cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{x}}}
$

Renders as:

11+11+1x\cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{x}}}

Exponents and Subscripts

$x^2$           <!-- superscript -->
$x_i$           <!-- subscript -->
$x_i^2$         <!-- both -->
$x^{n+1}$       <!-- grouped superscript -->
$a_{i,j}$       <!-- grouped subscript -->

Renders as:

x2x^2 xix_i xi2x_i^2 xn+1x^{n+1} ai,ja_{i,j}

Square Roots

$\sqrt{x}$          <!-- square root -->
$\sqrt[3]{x}$       <!-- cube root -->
$\sqrt[n]{x}$       <!-- nth root -->

Renders as:

x\sqrt{x} x3\sqrt[3]{x} xn\sqrt[n]{x}

Greek Letters

LowercaseCodeUppercaseCode
α\alphaΑA
β\betaΒB
γ\gammaΓ\Gamma
δ\deltaΔ\Delta
ε\epsilonΕE
θ\thetaΘ\Theta
λ\lambdaΛ\Lambda
μ\muΜM
π\piΠ\Pi
σ\sigmaΣ\Sigma
φ\phiΦ\Phi
ω\omegaΩ\Omega

Summation and Products

$
\sum_{i=1}^{n} x_i
$

$
\prod_{i=1}^{n} x_i
$

$
\sum_{k=0}^{\infty} \frac{x^k}{k!}
$

Renders as:

i=1nxi\sum_{i=1}^{n} x_i

i=1nxi\prod_{i=1}^{n} x_i

k=0xkk!\sum_{k=0}^{\infty} \frac{x^k}{k!}

Integrals

$
\int_{a}^{b} f(x) \, dx
$

$
\iint_{D} f(x,y) \, dA
$

$
\oint_{C} \vec{F} \cdot d\vec{r}
$

Renders as:

abf(x)dx\int_{a}^{b} f(x) \, dx

Df(x,y)dA\iint_{D} f(x,y) \, dA

CFdr\oint_{C} \vec{F} \cdot d\vec{r}

Limits

$
\lim_{x \to \infty} \frac{1}{x} = 0
$

$
\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n = e
$

Renders as:

limx1x=0\lim_{x \to \infty} \frac{1}{x} = 0

limn(1+1n)n=e\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n = e

Matrices

$
\begin{pmatrix} a & b \\ c & d \end{pmatrix}
$

$
\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}
$

$
\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc
$

Renders as:

(abcd)\begin{pmatrix} a & b \\ c & d \end{pmatrix}

[100010001]\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

abcd=adbc\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc

Piecewise Functions

$
f(x) = \begin{cases}
  x^2 & \text{if } x \geq 0 \\
  -x & \text{if } x < 0
\end{cases}
$

Renders as:

f(x)={x2if x0xif x<0f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases}

Aligned Equations

$
\begin{aligned}
  (x + y)^2 &= x^2 + 2xy + y^2 \\
  (x - y)^2 &= x^2 - 2xy + y^2 \\
  (x + y)(x - y) &= x^2 - y^2
\end{aligned}
$

Renders as:

(x+y)2=x2+2xy+y2(xy)2=x22xy+y2(x+y)(xy)=x2y2\begin{aligned} (x + y)^2 &= x^2 + 2xy + y^2 \\ (x - y)^2 &= x^2 - 2xy + y^2 \\ (x + y)(x - y) &= x^2 - y^2 \end{aligned}

Operators and Relations

SymbolCodeDescription
±\pmPlus or minus
×\timesMultiplication
÷\divDivision
\neqNot equal
\leqLess or equal
\geqGreater or equal
\approxApproximately
\inElement of
\subsetSubset
\cupUnion
\capIntersection
\to or \rightarrowArrow
\RightarrowImplies
\forallFor all
\existsThere exists
\inftyInfinity

Decorations and Accents

$\hat{x}$        <!-- hat -->
$\bar{x}$        <!-- bar -->
$\vec{v}$        <!-- vector arrow -->
$\dot{x}$        <!-- single dot (time derivative) -->
$\ddot{x}$       <!-- double dot -->
$\tilde{x}$      <!-- tilde -->
$\overline{AB}$   <!-- overline -->

Renders as:

x^\hat{x} xˉ\bar{x} v\vec{v} x˙\dot{x} x¨\ddot{x} x~\tilde{x} AB\overline{AB}

Physics

<!-- Newton's Second Law -->
$
F = ma
$

<!-- Kinetic Energy -->
$
E_k = \frac{1}{2}mv^2
$

<!-- Schrödinger Equation -->
$
i\hbar\frac{\partial}{\partial t}\Psi = \hat{H}\Psi
$

<!-- Maxwell's Equations -->
$
\nabla \cdot \vec{E} = \frac{\rho}{\epsilon_0}
$

Renders as:

F=maF = ma

Ek=12mv2E_k = \frac{1}{2}mv^2

itΨ=H^Ψi\hbar\frac{\partial}{\partial t}\Psi = \hat{H}\Psi

E=ρϵ0\nabla \cdot \vec{E} = \frac{\rho}{\epsilon_0}

Statistics

<!-- Normal Distribution -->
$
f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}
$

<!-- Bayes' Theorem -->
$
P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}
$

<!-- Standard Deviation -->
$
\sigma = \sqrt{\frac{1}{N}\sum_{i=1}^{N}(x_i - \mu)^2}
$

Renders as:

f(x)=1σ2πe(xμ)22σ2f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}

P(AB)=P(BA)P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}

σ=1Ni=1N(xiμ)2\sigma = \sqrt{\frac{1}{N}\sum_{i=1}^{N}(x_i - \mu)^2}

Linear Algebra

<!-- Dot Product -->
$
\vec{a} \cdot \vec{b} = \sum_{i=1}^{n} a_i b_i
$

<!-- Eigenvalue Equation -->
$
A\vec{v} = \lambda\vec{v}
$

<!-- Matrix Multiplication -->
$
C_{ij} = \sum_{k=1}^{n} A_{ik} B_{kj}
$

Renders as:

ab=i=1naibi\vec{a} \cdot \vec{b} = \sum_{i=1}^{n} a_i b_i

Av=λvA\vec{v} = \lambda\vec{v}

Cij=k=1nAikBkjC_{ij} = \sum_{k=1}^{n} A_{ik} B_{kj}

Calculus

<!-- Taylor Series -->
$
f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n
$

<!-- Chain Rule -->
$
\frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx}
$

<!-- Fundamental Theorem of Calculus -->
$
\int_{a}^{b} f'(x) \, dx = f(b) - f(a)
$

Renders as:

f(x)=n=0f(n)(a)n!(xa)nf(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x-a)^n

dydx=dydududx\frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx}

abf(x)dx=f(b)f(a)\int_{a}^{b} f'(x) \, dx = f(b) - f(a)

1. Use Spacing Commands

KaTeX doesn’t automatically add spacing between elements. Use these commands:

CommandWidthExample
\,3/18 emThin space
\:4/18 emMedium space
\;5/18 emThick space
\quad1 emQuad space
\qquad2 emDouble quad
$
\int f(x) \, dx$$    <!-- thin space before dx -->

Renders as:

$ \int f(x) , dx$$

2. Use \text{} for Words

When you need regular text inside an equation:

$
\text{Distance} = \text{Speed} \times \text{Time}
$

$
P(\text{heads}) = 0.5
$

Renders as:

Distance=Speed×Time\text{Distance} = \text{Speed} \times \text{Time}

P(heads)=0.5P(\text{heads}) = 0.5

3. Size Delimiters Automatically

Use \left and \right for auto-sizing brackets:

$
\left(\frac{x^2}{y^3}\right)
$

$
\left[\sum_{i=1}^{n} x_i\right]^2
$

Renders as:

(x2y3)\left(\frac{x^2}{y^3}\right)

[i=1nxi]2\left[\sum_{i=1}^{n} x_i\right]^2

4. Color Equations

Highlight parts of equations with color:

$
x = \frac{-b \pm \sqrt{\textcolor{red}{b^2 - 4ac}}}{2a}
$

Renders as:

x=b±b24ac2ax = \frac{-b \pm \sqrt{\textcolor{red}{b^2 - 4ac}}}{2a}

Render Math Beautifully on Android

MerMD renders KaTeX math equations natively — inline, display, and complex notation. Free on Google Play.

Download MerMD