3. Mathematics¶
3.1 Inline and displayed¶
Inline maths sits within a sentence, and displayed maths gets its own line. Load amsmath for anything beyond the basics.
The energy is $E = mc^2$ here.
\[ E = mc^2 \] % displayed, no number
\begin{equation} % displayed and numbered
E = mc^2
\label{eq:energy}
\end{equation}
In the file below, these forms and some of the building blocks come together. Only the numbered equations get a number at the right.
maths.tex
% The maths from this chapter in one document. Build: pdflatex maths
\documentclass[11pt]{article}
\usepackage{amsmath}
\begin{document}
The energy is $E = mc^2$ here.
\[ E = mc^2 \]
E = mc^2
\tag{?}
\begin{align*}
r &= \frac{s}{c + v} \\
&= \frac{e v}{c + v} \\
&= \frac{e}{1 + c/v}.
\end{align*}
Building blocks: $x_{i,j}$, $\sqrt{x}$, $\alpha$, $\Delta$, $\sum_{i=1}^{n} x_i$,
$\int_0^1 x \, dx$, $a \approx b$ and $\left( \frac{a}{b} \right)$.
\end{document}

What that file compiles to.
3.2 The building blocks¶
| You want | You write |
|---|---|
| Superscript and subscript | x^2, x_i, x_{i,j} |
| Fraction | \frac{a}{b} |
| Square root | \sqrt{x} |
| Greek letters | \alpha, \mu, \Delta |
| Sum and integral | \sum_{i=1}^{n}, \int_0^1 |
| Operators and relations | \times, \approx, \leq, \rightarrow |
| Words in maths | \text{hours} |
| Spacing | \, small, \quad wide |
| Brackets that grow | \left( \frac{a}{b} \right) |
Braces group things, so x^{10} raises the whole 10, while x^10 raises only the 1.
3.3 Aligned derivations¶
Long derivations read best one step per line. Use & to mark where lines align, and \\ to end a line.
\begin{align}
r &= \frac{s}{c + v} \\
&= \frac{e v}{c + v} \\
&= \frac{e}{1 + c/v}.
\end{align}
Each line gets a number, and align* removes all of them. \nonumber removes one.
3.4 Maths as your own commands¶
If a symbol means something in your project, name it once, and every use will follow.
\newcommand{\rate}{\ensuremath{r}}
3.5 Tips¶
-
Spell out what each symbol means in the text around the equation.
-
Treat an equation as part of a sentence, with punctuation.
-
Don't use
$or `
` skips LaTeX's spacing rules.