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 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:
Fractions
$\frac{numerator}{denominator}$
$
\frac{x^2 + 1}{x - 1}
$
Renders as:
$
\cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{x}}}
$
Renders as:
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:
Square Roots
$\sqrt{x}$ <!-- square root -->
$\sqrt[3]{x}$ <!-- cube root -->
$\sqrt[n]{x}$ <!-- nth root -->
Renders as:
Greek Letters
| Lowercase | Code | Uppercase | Code |
|---|---|---|---|
| α | \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:
Integrals
$
\int_{a}^{b} f(x) \, dx
$
$
\iint_{D} f(x,y) \, dA
$
$
\oint_{C} \vec{F} \cdot d\vec{r}
$
Renders as:
Limits
$
\lim_{x \to \infty} \frac{1}{x} = 0
$
$
\lim_{n \to \infty} \left(1 + \frac{1}{n}\right)^n = e
$
Renders as:
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:
Piecewise Functions
$
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}
$
Renders as:
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:
Operators and Relations
| Symbol | Code | Description |
|---|---|---|
| ± | \pm | Plus or minus |
| × | \times | Multiplication |
| ÷ | \div | Division |
| ≠ | \neq | Not equal |
| ≤ | \leq | Less or equal |
| ≥ | \geq | Greater or equal |
| ≈ | \approx | Approximately |
| ∈ | \in | Element of |
| ⊂ | \subset | Subset |
| ∪ | \cup | Union |
| ∩ | \cap | Intersection |
| → | \to or \rightarrow | Arrow |
| ⇒ | \Rightarrow | Implies |
| ∀ | \forall | For all |
| ∃ | \exists | There exists |
| ∞ | \infty | Infinity |
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:
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:
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:
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:
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:
1. Use Spacing Commands
KaTeX doesn’t automatically add spacing between elements. Use these commands:
| Command | Width | Example |
|---|---|---|
\, | 3/18 em | Thin space |
\: | 4/18 em | Medium space |
\; | 5/18 em | Thick space |
\quad | 1 em | Quad space |
\qquad | 2 em | Double 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:
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:
4. Color Equations
Highlight parts of equations with color:
$
x = \frac{-b \pm \sqrt{\textcolor{red}{b^2 - 4ac}}}{2a}
$
Renders as:
Render Math Beautifully on Android
MerMD renders KaTeX math equations natively — inline, display, and complex notation. Free on Google Play.
Download MerMD