KaTeX Syntax Quick Reference — Math Equations in Markdown
Complete reference for KaTeX mathematical notation including common formulas, symbols, and usage patterns for technical documentation.
Introduction
KaTeX is a fast, easy-to-use JavaScript library for rendering mathematical notation in web browsers. It supports a large subset of LaTeX syntax and is perfect for technical documentation, research papers, and educational content.
This comprehensive reference covers the most commonly used KaTeX syntax patterns, from basic arithmetic to advanced mathematical notation. Whether you're documenting algorithms, writing research papers, or creating educational content, this guide will help you express mathematical concepts clearly and beautifully.
$...$ for inline math or $$...$$ for display (block) math. The rendering happens automatically in real-time. All math content must be wrapped in these delimiters to render correctly. For display math, place the $$ delimiters on their own lines.Basic Syntax
Inline vs Display Math
Use single dollar signs $...$ for inline math that flows with text, and double dollar signs $$...$$ for display math that appears on its own line.
Inline and Display Math
Compare inline math within text versus display math on its own line
The quadratic formula x=2a−b±b2−4ac is used to solve quadratic equations.
For a more prominent display:
x=2a−b±b2−4acSuperscripts and Subscripts
Use ^ for superscripts and _ for subscripts. Wrap multi-character superscripts/subscripts in curly braces.
Superscripts and Subscripts
Powers, indices, and notation
Basic: x2, xi, x10, xmax
Combined: xi2, xi,j(k)
Nested: ex2, xyz
Fractions and Roots
Fractions
Use \frac{numerator}{denominator} for fractions. For inline fractions, consider using \tfrac (text-style) or the slash notation.
Fractions
Different fraction styles
Display fraction:
baInline fraction: 21 or 21 or 1/2
Nested fractions:
1+211Complex fractions:
x2−1x2+2x+1Roots
Use \sqrt for square roots and \sqrt[n] for nth roots.
Roots
Square roots and nth roots
Square root: x, x2+y2
Cube root: 3x
nth root: nx
Nested: 1+x
Greek Letters
Greek letters are essential in mathematics. Use backslash followed by the letter name. Capitalize for uppercase Greek letters.
Common Greek Letters
Lowercase and uppercase Greek letters
Lowercase: α, β, γ, δ, ϵ, θ, λ, μ, π, σ, ϕ, ω
Uppercase: Γ, Δ, Θ, Λ, Σ, Φ, Ω
Variants: ε, ϑ, φ
In equations:
θ=arctan(xy)Operators and Symbols
Basic Operators
Arithmetic and Comparison
Common mathematical operators
Arithmetic: +, −, ×, ÷, ±, ∓
Comparison: =, =, <, >, ≤, ≥, ≈, ≡
Set operations: ∈, ∈/, ⊂, ⊆, ∪, ∩, ∅
Logic: ∧, ∨, ¬, ⟹, ⟺
Large Operators
Large operators like sums, products, and integrals automatically adjust their size in display mode.
Sums, Products, and Integrals
Large operators with limits
Summation:
i=1∑ni=2n(n+1)Product:
i=1∏ni=n!Integral:
∫0∞e−xdx=1Multiple integrals:
∬Df(x,y)dALimits:
x→∞limx1=0Brackets and Delimiters
Use \left and \right to make brackets automatically size to their contents. This works with parentheses, brackets, braces, and absolute value bars.
Auto-Sizing Delimiters
Brackets that scale with content
Without auto-sizing:
(yx)With auto-sizing:
(yx)Different delimiters:
- Parentheses: (x)
- Brackets: [x]
- Braces: {x}
- Absolute value: ∣x∣
- Norms: ∥x∥
- Angle brackets: ⟨x⟩
Mixed:
[yx2+(ba)2]Matrices and Arrays
Use \begin{matrix} environments for matrices. Use & to separate columns and \\ for new rows.
$$...$$ delimiters to render correctly. Place the $$ on separate lines before and after the matrix environment.Matrices
Different matrix styles
Basic matrix:
acbdWith parentheses:
(acbd)With brackets:
147258369Determinant:
acbd=ad−bcCalculus Notation
Derivatives
Derivative Notation
Different ways to express derivatives
Prime notation: f′(x), f′′(x), f′′′(x)
Leibniz notation: dxdf, dx2d2f
Partial derivatives: ∂x∂f, ∂x∂y∂2f
Dot notation: x˙, x¨
Example:
dxd(x2)=2xIntegrals
Integral Notation
Definite and indefinite integrals
Indefinite: ∫f(x)dx
Definite: ∫abf(x)dx
Multiple: ∭Vf(x,y,z)dV
Contour: ∮Cf(z)dz
Example:
∫0πsin(x)dx=2Special Functions
Common mathematical functions have special formatting to distinguish them from variables.
Function Names
Properly formatted function names
Trigonometric: sin(x), cos(x), tan(x), sec(x), csc(x), cot(x)
Inverse trig: arcsin(x), arccos(x), arctan(x)
Hyperbolic: sinh(x), cosh(x), tanh(x)
Logarithms: log(x), ln(x), log10(x)
Other: exp(x), max(x,y), min(x,y), gcd(a,b)
Example:
sin2(x)+cos2(x)=1Accents and Decorations
Add accents and decorations to variables for additional notation.
Accents
Various accent marks and decorations
Hat: x^, xyz
Bar: xˉ, xyz
Tilde: x~, xyz
Dot: x˙, x¨
Vector: v, AB
Underline: x
Example:
F=maText in Math Mode
Use \text{...} to include regular text within math expressions. This is essential for units, labels, and explanations.
Text in Equations
Mixing text and math
With units: v=50 m/s
With labels:
f(x)={x2−x2if x≥0if x<0With explanations: P(A∣B)=P(B)P(B∣A)P(A) (Bayes’ Theorem)
Spacing and Alignment
Manual Spacing
Sometimes you need to adjust spacing manually. KaTeX provides several spacing commands.
Spacing Commands
Fine-tune spacing in equations
Thin space: ab (,)
Medium space: ab (:)
Thick space: ab (;)
Quad space: ab (\quad)
Double quad: ab (\qquad)
Negative space: ab (!)
Aligned Equations
Use the aligned environment to align multiple equations at specific points (usually the equals sign). Like matrix environments, aligned must be wrapped in $$...$$ delimiters on separate lines.
Aligned Equations
Multi-line equations with alignment
With explanations:
(x+y)2=(x+y)(x+y)=x2+xy+yx+y2=x2+2xy+y2Common Patterns
Piecewise Functions
Piecewise Functions
Functions defined by cases
Binomial Coefficients
Binomial Coefficients
Combinations and binomial notation
Binomial coefficient: (kn)
In equations:
(x+y)n=k=0∑n(kn)xn−kykAlternative notation: C(n,k)=(kn)=k!(n−k)!n!
Set Notation
Set Notation
Sets and set operations
Set definition: S={x∈R:x>0}
Set operations: A∪B, A∩B, A∖B
Special sets: N, Z, Q, R, C
Cardinality: ∣S∣ or #S
Example:
N={1,2,3,…}Best Practices
$$...$$ for equations that are the focus of discussion.\, to add thin spaces around differentials and between function arguments for better readability: $\int f(x) \, dx$\text{...} to ensure proper formatting and spacing.$\vec{v}$ for vectors, use it everywhere.Common Mistakes
$x^10$ renders as $x^10$ (wrong), while $x^{10}$ renders correctly as $x^{10}$. Always use braces for multi-character superscripts/subscripts.\left and \right. Compare $(\frac{x}{y}$ vs $\left(\frac{x}{y}\right)$.\sin, not sin. The backslash ensures proper formatting and spacing.\, before dx in integrals: $\int f(x) \, dx$$...$ or $$...$$ delimiters. Environments like \begin{matrix}, \begin{aligned}, and \begin{cases} will not render without these delimiters. For display math, place $$ on separate lines.Quick Reference Table
| Category | Syntax | Example |
|---|---|---|
| Superscript | x^2 | $x^2$ |
| Subscript | x_i | $x_i$ |
| Fraction | \frac{a}{b} | $\frac{a}{b}$ |
| Square root | \sqrt{x} | $\sqrt{x}$ |
| Sum | \sum_{i=1}^{n} | $\sum_{i=1}^{n}$ |
| Integral | \int_{a}^{b} | $\int_{a}^{b}$ |
| Limit | \lim_{x \to \infty} | $\lim_{x \to \infty}$ |
| Greek letter | \alpha, \beta, \gamma | $\alpha, \beta, \gamma$ |
Related Content
Using KaTeX in AutEng
Practical guide to integrating mathematical equations in your documentation
Markdown, Mermaid & KaTeX Syntax
Complete syntax reference for Markdown, Mermaid diagrams, and KaTeX math equations
Getting Started
Learn the basics of AutEng and create your first document
Ready to Start?
Start creating beautiful technical documentation with AutEng.
Get Started with AutEng