This lesson we will introduce some important new constructions for typesetting mathematics. See also Wikibooks/LaTeX/Advanced Mathematics.
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}
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}
\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 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.
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:
% Wrong:
P \coloneqq \{ \text{natural numbers} p \text{such that} p \text{is prime} \}
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}
To place several lines under a sum you can use \substack
and \\
:
\sum_{\substack{
0 < i < m \\
0 < j < n
}}
P (i,j)
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}
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.
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.
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).)
Typeset the following mathematical expressions. For some parts there is a hint: scroll over the whitespace beneath the display to see it.
Hint: Use the cases environment.
Hint: The $\mathbb{Q}$ is made in the style blackboard bold.
Hint: use the substack command.
align
and align*
environment.