Skip to content

Mathematics and equations

Prerequisite: fundamentals. Goal: choose appropriate math environments and write readable notation.

Choose an environment

Purpose In a .tex source
Inline expression \(f(x)=x^2\)
Unnumbered display \[f(x)=x^2\]
Numbered display \begin{equation}...\end{equation}
Aligned derivation \begin{align}...\end{align}

In this Markdown website, dollar delimiters are processed by MathJax. For example, \(\int_0^1 x^2\,\mathrm{d}x=\frac{1}{3}\). The .tex sources use LaTeX's own environments; MathJax is not the PDF compiler.

Complete example

Source folder.

examples/mathematics/main.tex
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,amssymb}
\usepackage{siunitx}

\begin{document}
\section{A model and its rate of change}
The inline model is \(f(x)=x^2+2x+1\). Its derivative is
\begin{equation}
  f'(x)=2x+2.
  \label{eq:derivative}
\end{equation}
Equation~\ref{eq:derivative} gives \(f'(1)=4\).

\begin{align}
  \int_0^1 x^2\,\mathrm{d}x
    &= \left[\frac{x^3}{3}\right]_0^1 \\
    &= \frac{1}{3}.
\end{align}

For \(\mathbf{x}\in\mathbb{R}^2\), a linear transformation can use
\[
  A=\begin{bmatrix}1&2\\0&1\end{bmatrix},
  \qquad
  g(x)=
  \begin{cases}
    x^2, & x\geq 0,\\
    -x, & x<0.
  \end{cases}
\]
An example speed is \(\qty{2.0}{\metre\per\second}\).
\end{document}

amsmath provides align, bmatrix, and cases; amssymb supplies additional symbols such as \mathbb. In align, & marks the alignment point, not a visible symbol. \\ ends an alignment row.

The command \mathrm{d} typesets an upright differential. The spacing command \, separates it from the integrand. siunitx keeps quantities and units consistent; the example uses the version 3 command \qty.

Compile and expected output

cd examples/mathematics
latexmk -pdf -outdir=build main.tex

Run this from the repository root. Open build/main.pdf. Expect a numbered derivative, an aligned two-line integral evaluation, a two-by-two matrix, a piecewise function, and a speed with formatted units. The displayed integral equals \(1/3\); \(f'(1)=4\).

Do not nest display environments

Do not put an equation environment inside \[...\] or wrap align in another math environment. Use aligned inside an existing display if you need a grouped alignment.

Practice

Replace the model with \(f(x)=x^3\) and update its derivative to \(3x^2\). Add a label to one aligned row and refer to it in a sentence. Use \notag on a row you do not want numbered.

Check: the mathematics remains correct, the reference resolves, and the alignment uses & rather than a run of spaces.

Next: tables and figures.

Total repository views

Refresh Date: 2026-11-18