This lesson we will introduce some important new constructions for typesetting mathematics. See also Wikibooks/LaTeX/Advanced Mathematics.

Advanced environments

If you want to align the formulas you can use the align environment. The align environment is a mathematical environment itself, so it doesn’t have to be put inside \[ .. \] or $ .. $. LaTeX aligns the lines at & and a line is ended with \\. If you use align* the equation won’t be numbered.

\begin{align} f(x) &= x^2 + 1 \\ g(x) &= x^3 - 3 \end{align}
\begin{align}
f(x) &= x^2 + 1 \\
g(x) &= x^3 - 3
\end{align}

Matrices

Matrices can be made with the pmatrix environment. For different brackets you can use bmatrix or vmatrix.

\[ \begin{pmatrix} a & b & c \\ d & e & f \\ g & h & i \end{pmatrix} \qquad \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix} \qquad \begin{vmatrix} a & b & c \\ d & e & f \\ g & h & i \end{vmatrix} \]
\begin{pmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{pmatrix}
\begin{bmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{bmatrix}
\begin{vmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{vmatrix}

In generic matrices it is common to use dots. These can be inserted using \cdots $\cdots$, \vdots $\vdots$ en \ddots $\ddots$.

Text inside mathematics

Text in math mode can be inserted using \text or \textnormal. The command \text uses the font of the current environment, \textnormal uses roman. You have to be careful with whitespaces when using these commands. An illustrating example can be found below.

\begin{gather*} P := \{ \text{natural numbers $p$ such that $p$ is prime} \}\\[0.5em] P := \{ \text{natural numbers } p \text{ such that } p \text{ is prime} \}\\[0.5em] \end{gather*}
P \coloneqq \{ \text{natural numbers $p$ such that $p$ is prime} \}
P \coloneqq \{ \text{natural numbers } p \text{ such that } p \text{ is prime} \}

and an example where whitespace is left out:

\[ P := \{ \text{natural numbers} p \text{such that} p \text{is prime} \} \]
% Wrong:
P \coloneqq \{ \text{natural numbers} p \text{such that} p \text{is prime} \}

Cases

The following construction is used a lot when defining functions:

\[ f(x) = \begin{cases} x^2 & \text{if $x \geq 0$,}\\ 0 & \text{otherwise.} \end{cases} \]
f(x) =
\begin{cases}
 x^2 & \text{if $x \geq 0$},\\
 0 & \text{otherwise}.
\end{cases}

Multiline subscript

To place several lines under a sum you can use \substack and \\:

\[ \sum_{\substack{ 0 < i < m \\ 0 < j < n }} P (i,j) \]
\sum_{\substack{
 0 < i < m \\
 0 < j < n
}}
P (i,j)

References

We saw that environments like equation and align display numbers next to the formulas. We will show how to reference these formulas. Use \label to label your equations.

\begin{equation} \label{eq:polynomial} f(x) = x^2 + 1 \end{equation}
\begin{equation}
\label{eq:polynomial}
f(x) = x^2 + 1
\end{equation}

It is common, but not necessary, to start labels of equations with eq:. Subsequently you can reference this formula with \eqref.

The polynomial defined in \eqref{eq:polynomial} has degree 2.
The polynomial defined in \eqref{eq:polynomial} has degree 2.

If you use the package hyperref references become clickable. The document viewer then jumps to the label. The package hyperref also makes the table of contents clickable.

Exercise

  1. Typeset the next display and its references. Where do you put the labels? (You don’t have to recreate the exact numbers (4) and (5).)

    Define \begin{align} q &= 10 \label{eq:vba}\\ r &= 100. \label{eq:vbb} \end{align} We will use the values in \eqref{eq:vba} and \eqref{eq:vbb}.
  2. Typeset the following mathematical expressions. For some parts there is a hint: scroll over the whitespace beneath the display to see it.

    \[ \cos z = \frac{e^{iz} + e^{-iz}}{2}= \sum_{n=0}^{\infty} \frac{(-1)^nz^{2n}}{(2n)!}=1-\frac{z^2}{2}+\frac{z^4}{4!}+~~\dots \text{ with radius of convergence }\infty \]
    \[ g(z)= \begin{cases} f(\frac{1}{z}) & \text{if } $z\ne 0$;\\ f(\infty) & \text{if } z=0. \end{cases} \label{eq:cont_g} \]

    Hint: Use the cases environment.

    \[ \mathbb{Q}^* = \{x\in \mathbb{Q} : x\not = 0\} = \mathbb{Q} \setminus \{0\} \]

    Hint: The $\mathbb{Q}$ is made in the style blackboard bold.

    \[ \begin{pmatrix} a & b\\ c & d \end{pmatrix} \cdot \begin{pmatrix} e & f\\ g & h \end{pmatrix} = \begin{pmatrix} ae+bg & af+bh\\ ce+dg & cf + dh \end{pmatrix} \]
    \[ \partial A = \overline{A} \setminus A^\circ \]
    Hint: This slash means something like a minus sign for sets: $A\setminus B = \{x\in A\mid x \notin B\}$
    \[ \Phi_n(X) = \prod_{\substack{\zeta\in\mathbb{C}^*:\\ \text{ord}(\zeta)=n}}(X-\zeta) \]

    Hint: use the substack command.

    \[ M_R = \left( \frac4\pi \right)^s \frac{n!}{n^n} \sqrt{|\Delta{(R)}|} \]

Remember

  • align and align* environment.
  • How to make matrices or cases?
  • How do you insert text in mathematics?
  • How to refer to equations?