# 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.

```markdown

The quadratic formula $x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$ is used to solve quadratic equations.

For a more prominent display:

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

```

### Superscripts and Subscripts

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

```markdown

Basic: $x^2$, $x_i$, $x^{10}$, $x_{max}$

Combined: $x_i^2$, $x_{i,j}^{(k)}$

Nested: $e^{x^2}$, $x_{y_z}$

```

## Fractions and Roots

### Fractions

Use `\frac{'{numerator}'} {'{denominator}'}` for fractions. For inline fractions, consider using `\tfrac` (text-style) or the slash notation.

```markdown

Display fraction:
$$
\\frac{a}{b}
$$

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

Nested fractions:
$$
\\frac{1}{1 + \\frac{1}{2}}
$$

Complex fractions:
$$
\\frac{x^2 + 2x + 1}{x^2 - 1}
$$

```

### Roots

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

```markdown

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

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

nth root: $\\sqrt[n]{x}$

Nested: $\\sqrt{1 + \\sqrt{x}}$

```

## Greek Letters

Greek letters are essential in mathematics. Use backslash followed by the letter name. Capitalize for uppercase Greek letters.

```markdown

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:
$$
\\theta = \\arctan\\left(\\frac{y}{x}\\right)
$$

```

## Operators and Symbols

### Basic Operators

```markdown

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.

```markdown

Summation:
$$
\\sum_{i=1}^{n} i = \\frac{n(n+1)}{2}
$$

Product:
$$
\\prod_{i=1}^{n} i = n!
$$

Integral:
$$
\\int_{0}^{\\infty} e^{-x} dx = 1
$$

Multiple integrals:
$$
\\iint_D f(x,y) \\, dA
$$

Limits:
$$
\\lim_{x \\to \\infty} \\frac{1}{x} = 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.

```markdown

Without auto-sizing:
$$
(\\frac{x}{y})
$$

With auto-sizing:
$$
\\left(\\frac{x}{y}\\right)
$$

Different delimiters:
- Parentheses: $\\left(x\\right)$
- Brackets: $\\left[x\\right]$
- Braces: $\\left\\{x\\right\\}$
- Absolute value: $\\left|x\\right|$
- Norms: $\\left\\|x\\right\\|$
- Angle brackets: $\\left\\langle x \\right\\rangle$

Mixed:
$$
\\left[\\frac{x^2}{y} + \\left(\\frac{a}{b}\\right)^2\\right]
$$

```

## 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.

```markdown

Basic matrix:
$$
\\begin{matrix}
a & b \\\\
c & d
\\end{matrix}
$$

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

With brackets:
$$
\\begin{bmatrix}
1 & 2 & 3 \\\\
4 & 5 & 6 \\\\
7 & 8 & 9
\\end{bmatrix}
$$

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

```

## Calculus Notation

### Derivatives

```markdown

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

Leibniz notation: $\\frac{df}{dx}$, $\\frac{d^2f}{dx^2}$

Partial derivatives: $\\frac{\\partial f}{\\partial x}$, $\\frac{\\partial^2 f}{\\partial x \\partial y}$

Dot notation: $\\dot{x}$, $\\ddot{x}$

Example:
$$
\\frac{d}{dx}\\left(x^2\\right) = 2x
$$

```

### Integrals

```markdown

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

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

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

Contour: $\\oint_C f(z) \\, dz$

Example:
$$
\\int_{0}^{\\pi} \\sin(x) \\, dx = 2
$$

```

## Special Functions

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

```markdown

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)$, $\\log_{10}(x)$

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

Example:
$$
\\sin^2(x) + \\cos^2(x) = 1
$$

```

## Accents and Decorations

Add accents and decorations to variables for additional notation.

```markdown

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

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

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

Dot: $\\dot{x}$, $\\ddot{x}$

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

Underline: $\\underline{x}$

Example:
$$
\\vec{F} = m\\vec{a}
$$

```

## Text in Math Mode

Use `\text{'{...}'}` to include regular text within math expressions. This is essential for units, labels, and explanations.

```markdown

With units: $v = 50 \\text{ m/s}$

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

With explanations: $P(A|B) = \\frac{P(B|A)P(A)}{P(B)} \\text{ (Bayes' Theorem)}$

```

## Spacing and Alignment

### Manual Spacing

Sometimes you need to adjust spacing manually. KaTeX provides several spacing commands.

```markdown

Thin space: $a\\,b$ (\\,)

Medium space: $a\\:b$ (\\:)

Thick space: $a\\;b$ (\\;)

Quad space: $a\\quad b$ (\\quad)

Double quad: $a\\qquad b$ (\\qquad)

Negative space: $a\\!b$ (\\!)

```

### 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.

```markdown

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

With explanations:
$$
\\begin{aligned}
(x + y)^2 &= (x + y)(x + y) \\\\
&= x^2 + xy + yx + y^2 \\\\
&= x^2 + 2xy + y^2
\\end{aligned}
$$

```

## Common Patterns

### Piecewise Functions

```markdown

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

$$
|x| = \\begin{cases}
x & \\text{if } x \\geq 0 \\\\
-x & \\text{if } x < 0
\\end{cases}
$$

```

### Binomial Coefficients

```markdown

Binomial coefficient: $\\binom{n}{k}$

In equations:
$$
(x + y)^n = \\sum_{k=0}^{n} \\binom{n}{k} x^{n-k} y^k
$$

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

```

### Set Notation

```markdown

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

Set operations: $A \\cup B$, $A \\cap B$, $A \\setminus B$

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

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

Example:
$$
\\mathbb{N} = \\{1, 2, 3, \\ldots\\}
$$

```

## 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

| 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$ |
