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.

Quick Start
In AutEng, wrap your math expressions in $...$ 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=b±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}x=2ab±b24ac is used to solve quadratic equations.

For a more prominent display:

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

Superscripts and Subscripts

Use ^ for superscripts and _ for subscripts. Wrap multi-character superscripts/subscripts in curly braces.

Superscripts and Subscripts

Powers, indices, and notation

Basic: x2x^2x2, xix_ixi, x10x^{10}x10, xmaxx_{max}xmax

Combined: xi2x_i^2xi2, xi,j(k)x_{i,j}^{(k)}xi,j(k)

Nested: ex2e^{x^2}ex2, xyzx_{y_z}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:

ab\frac{a}{b}ba

Inline fraction: 12\frac{1}{2}21 or 12\tfrac{1}{2}21 or 1/21/21/2

Nested fractions:

11+12\frac{1}{1 + \frac{1}{2}}1+211

Complex fractions:

x2+2x+1x21\frac{x^2 + 2x + 1}{x^2 - 1}x21x2+2x+1

Roots

Use \sqrt for square roots and \sqrt[n] for nth roots.

Roots

Square roots and nth roots

Square root: x\sqrt{x}x, x2+y2\sqrt{x^2 + y^2}x2+y2

Cube root: x3\sqrt[3]{x}3x

nth root: xn\sqrt[n]{x}nx

Nested: 1+x\sqrt{1 + \sqrt{x}}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: α\alphaα, β\betaβ, γ\gammaγ, δ\deltaδ, ϵ\epsilonϵ, θ\thetaθ, λ\lambdaλ, μ\muμ, π\piπ, σ\sigmaσ, ϕ\phiϕ, ω\omegaω

Uppercase: Γ\GammaΓ, Δ\DeltaΔ, Θ\ThetaΘ, Λ\LambdaΛ, Σ\SigmaΣ, Φ\PhiΦ, Ω\OmegaΩ

Variants: ε\varepsilonε, ϑ\varthetaϑ, φ\varphiφ

In equations:

θ=arctan(yx)\theta = \arctan\left(\frac{y}{x}\right)θ=arctan(xy)

Operators and Symbols

Basic Operators

Arithmetic and Comparison

Common mathematical operators

Arithmetic: +++, -, ×\times×, ÷\div÷, ±\pm±, \mp

Comparison: ===, \neq=, <<<, >>>, \leq, \geq, \approx, \equiv

Set operations: \in, \notin/, \subset, \subseteq, \cup, \cap, \emptyset

Logic: \land, \lor, ¬\neg¬,     \implies,     \iff

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=1ni=n(n+1)2\sum_{i=1}^{n} i = \frac{n(n+1)}{2}i=1ni=2n(n+1)

Product:

i=1ni=n!\prod_{i=1}^{n} i = n!i=1ni=n!

Integral:

0exdx=1\int_{0}^{\infty} e^{-x} dx = 10exdx=1

Multiple integrals:

Df(x,y)dA\iint_D f(x,y) \, dADf(x,y)dA

Limits:

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

Brackets 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:

(xy)(\frac{x}{y})(yx)

With auto-sizing:

(xy)\left(\frac{x}{y}\right)(yx)

Different delimiters:

  • Parentheses: (x)\left(x\right)(x)
  • Brackets: [x]\left[x\right][x]
  • Braces: {x}\left\{x\right\}{x}
  • Absolute value: x\left|x\right|x
  • Norms: x\left\|x\right\|x
  • Angle brackets: x\left\langle x \right\ranglex

Mixed:

[x2y+(ab)2]\left[\frac{x^2}{y} + \left(\frac{a}{b}\right)^2\right][yx2+(ba)2]

Matrices and Arrays

Use \begin{matrix} environments for matrices. Use & to separate columns and \\ for new rows.

Delimiters Required
Matrix environments must be wrapped in $$...$$ delimiters to render correctly. Place the $$ on separate lines before and after the matrix environment.

Matrices

Different matrix styles

Basic matrix:

abcd\begin{matrix} a & b \\ c & d \end{matrix}acbd

With parentheses:

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

With brackets:

[123456789]\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}147258369

Determinant:

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

Calculus Notation

Derivatives

Derivative Notation

Different ways to express derivatives

Prime notation: f(x)f'(x)f(x), f(x)f''(x)f′′(x), f(x)f'''(x)f′′′(x)

Leibniz notation: dfdx\frac{df}{dx}dxdf, d2fdx2\frac{d^2f}{dx^2}dx2d2f

Partial derivatives: fx\frac{\partial f}{\partial x}xf, 2fxy\frac{\partial^2 f}{\partial x \partial y}xy2f

Dot notation: x˙\dot{x}x˙, x¨\ddot{x}x¨

Example:

ddx(x2)=2x\frac{d}{dx}\left(x^2\right) = 2xdxd(x2)=2x

Integrals

Integral Notation

Definite and indefinite integrals

Indefinite: f(x)dx\int f(x) \, dxf(x)dx

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

Multiple: Vf(x,y,z)dV\iiint_V f(x,y,z) \, dVVf(x,y,z)dV

Contour: Cf(z)dz\oint_C f(z) \, dzCf(z)dz

Example:

0πsin(x)dx=2\int_{0}^{\pi} \sin(x) \, dx = 20πsin(x)dx=2

Special Functions

Common mathematical functions have special formatting to distinguish them from variables.

Function Names

Properly formatted function names

Trigonometric: sin(x)\sin(x)sin(x), cos(x)\cos(x)cos(x), tan(x)\tan(x)tan(x), sec(x)\sec(x)sec(x), csc(x)\csc(x)csc(x), cot(x)\cot(x)cot(x)

Inverse trig: arcsin(x)\arcsin(x)arcsin(x), arccos(x)\arccos(x)arccos(x), arctan(x)\arctan(x)arctan(x)

Hyperbolic: sinh(x)\sinh(x)sinh(x), cosh(x)\cosh(x)cosh(x), tanh(x)\tanh(x)tanh(x)

Logarithms: log(x)\log(x)log(x), ln(x)\ln(x)ln(x), log10(x)\log_{10}(x)log10(x)

Other: exp(x)\exp(x)exp(x), max(x,y)\max(x,y)max(x,y), min(x,y)\min(x,y)min(x,y), gcd(a,b)\gcd(a,b)gcd(a,b)

Example:

sin2(x)+cos2(x)=1\sin^2(x) + \cos^2(x) = 1sin2(x)+cos2(x)=1

Accents and Decorations

Add accents and decorations to variables for additional notation.

Accents

Various accent marks and decorations

Hat: x^\hat{x}x^, xyz^\widehat{xyz}xyz

Bar: xˉ\bar{x}xˉ, xyz\overline{xyz}xyz

Tilde: x~\tilde{x}x~, xyz~\widetilde{xyz}xyz

Dot: x˙\dot{x}x˙, x¨\ddot{x}x¨

Vector: v\vec{v}v, AB\overrightarrow{AB}AB

Underline: x\underline{x}x

Example:

F=ma\vec{F} = m\vec{a}F=ma

Text 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/sv = 50 \text{ m/s}v=50 m/s

With labels:

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

With explanations: P(AB)=P(BA)P(A)P(B) (Bayes’ Theorem)P(A|B) = \frac{P(B|A)P(A)}{P(B)} \text{ (Bayes' Theorem)}P(AB)=P(B)P(BA)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: aba\,bab (,)

Medium space: aba\:bab (:)

Thick space: a  ba\;bab (;)

Quad space: aba\quad bab (\quad)

Double quad: aba\qquad bab (\qquad)

Negative space: a ⁣ba\!bab (!)

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

x=a+b=c+d=e+f\begin{aligned} x &= a + b \\ &= c + d \\ &= e + f \end{aligned}x=a+b=c+d=e+f

With explanations:

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

Common Patterns

Piecewise Functions

Piecewise Functions

Functions defined by cases

f(x)={x2if x0x2if x<0f(x) = \begin{cases} x^2 & \text{if } x \geq 0 \\ -x^2 & \text{if } x < 0 \end{cases}f(x)={x2x2if x0if x<0 x={xif x0xif x<0|x| = \begin{cases} x & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases}x={xxif x0if x<0

Binomial Coefficients

Binomial Coefficients

Combinations and binomial notation

Binomial coefficient: (nk)\binom{n}{k}(kn)

In equations:

(x+y)n=k=0n(nk)xnkyk(x + y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k(x+y)n=k=0n(kn)xnkyk

Alternative notation: C(n,k)=(nk)=n!k!(nk)!C(n,k) = \binom{n}{k} = \frac{n!}{k!(n-k)!}C(n,k)=(kn)=k!(nk)!n!

Set Notation

Set Notation

Sets and set operations

Set definition: S={xR:x>0}S = \{x \in \mathbb{R} : x > 0\}S={xR:x>0}

Set operations: ABA \cup BAB, ABA \cap BAB, ABA \setminus BAB

Special sets: N\mathbb{N}N, Z\mathbb{Z}Z, Q\mathbb{Q}Q, R\mathbb{R}R, C\mathbb{C}C

Cardinality: S|S|S or #S\#S#S

Example:

N={1,2,3,}\mathbb{N} = \{1, 2, 3, \ldots\}N={1,2,3,}

Best Practices

Use Display Math for Complex Equations
Complex equations are easier to read when displayed on their own line. Use $$...$$ for equations that are the focus of discussion.
Add Spacing Around Operators
Use \, to add thin spaces around differentials and between function arguments for better readability: $\int f(x) \, dx$
Use \text for Units and Labels
Always wrap units and text labels in \text{...} to ensure proper formatting and spacing.
Consistent Notation
Be consistent with your notation throughout your document. If you use $\vec{v}$ for vectors, use it everywhere.
Avoid Overuse of Inline Math
Too much inline math can make text hard to read. Consider using display math or breaking up dense mathematical content.

Common Mistakes

Forgetting Curly Braces
$x^10$ renders as $x^10$ (wrong), while $x^{10}$ renders correctly as $x^{10}$. Always use braces for multi-character superscripts/subscripts.
Missing \left and \right
Brackets don't auto-size without \left and \right. Compare $(\frac{x}{y}$ vs $\left(\frac{x}{y}\right)$.
Incorrect Function Names
Use \sin, not sin. The backslash ensures proper formatting and spacing.
Forgetting Spacing in Integrals
Always add \, before dx in integrals: $\int f(x) \, dx$
Missing Math Delimiters
All math content must be wrapped in $...$ 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

CategorySyntaxExample
Superscriptx^2$x^2$
Subscriptx_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

Ready to Start?

Start creating beautiful technical documentation with AutEng.

Get Started with AutEng