An important reason for using LaTeX is that it is fairly easy to typeset mathematical expressions. This lesson we will discuss some of the most used commands for typesetting mathematics.

For basic mathematics, no packages are needed. We will use mathtools, an extension of amsmath, since we will typeset more complex expressions:


Please consent the main reference Wikibooks/LaTeX/Mathematics, whenever you are in doubt. For more details you can look at this Short Math Guide for LaTeX, or the documentation of amsmath or mathtools.

Mathematical environments

Mathematics within text like $1+1=2$ is called inline mathematics. A line that consists of a single mathematical expression like \[ 1+1=2 \] is called a display. Inline mathematics can be typeset between $s.

We know that $1+1=2$.
We know that $1+1=2$.

Mathematics can be typeset in a display by putting it between \[ and \].

Examine the curve given by \[ y = x^2 + 2. \] Does it attain a minimum?
Examine the curve given by
y = x^2 + 2.
Does it attain a minimum?

Recall that an empty line creates a new paragraph. Therefore there are no empty lines before or after the display in this example.

To number displays automatically one uses the equation environment. We will see later how to reference displays.

Since both $a$ and $b$ are odd we have \begin{equation} a + b = 2x \end{equation} and \begin{equation} a-b = 2y \end{equation} for some $x$ and $y$.
Since both $a$ and $b$ are odd we have
a + b = 2x
a-b = 2y
for some $x$ and $y$.

LaTeX switches to math mode in every mathematical environment. The most important differences compared to text mode are:

In the rest of this lesson we will assume that you are working in math mode.

Powers and indices

Powers and indices can be inserted using the hat ^ and the underscore _. For example $

\[ a^2\quad a_i\quad a_i^2 \]
a^2 a_i a_i^2

The _ and ^ bind themselves to the next group. Recall that groups can be made with { and }. Hence

\[ a^{n+1}\quad a^n+1\quad a_{i/2} \]
a^{n+1} a^n+1 a_{i/2}

Exercise 1

Typeset the powers

\[ (a^b)^c,\quad a^{b^c} \]

Common expressions

A fraction can be created using \frac{2}{3}. It is possible to create fractions inside fractions.

\[ \frac{\frac{1}{x}+\frac{1}{y}}{y-z} \]

We can use \tfrac for small fractions, it is up to the user to decide when to use this.

Roots can be inserted as \sqrt{2} or \sqrt[n]{2} for $\sqrt[n]{2}$.

A sum or integral is given by \sum or \int, use ^ and _ to specify the boundaries. For example

\[ \sum_{i=1}^{10} t_i\quad \int_0^\infty e^{-x}\, dx \]
\sum_{i=1}^{10} t_i
\int_0^\infty e^{-x}\, dx

There are more operators that use ^ and _ for specifying boundaries, for example \prod $\prod$ and \bigcup $\bigcup$. A more detailed list is shown at the end of this page.

You can scale brackets and delimiters, e.g. | or (, automatically using \left and \right.

\[ \left| \sum_{n=1}^\infty a_n \right| \leq \sum_{n=1}^\infty \left| a_n \right| \]
\left| \sum_{n=1}^\infty a_n \right| \leq \sum_{n=1}^\infty
\left| a_n \right|

With \ldots $\ldots$ and \cdots $\cdots$ one makes dots. The context determines which dots to use. For example, we write 1,2,\ldots,n $1,2,\ldots,n$ and 1\cdot 2 \cdots n $1\cdot 2\cdots n$. In general we try to choose the dots in such a way that they are at the same height as the surrounding operators. The command \dots tries to accomplish this.

Exercise 2

Typeset the display.

\[ \left | \sum_{i=1}^n a_ib_i \right| \leq \left( \sum_{i=1}^n a_i^2 \right)^{\frac{1}{2}} \cdot \sqrt{\sum_{i=1}^n b^2_i} \]

Horizontal whitespace

In math mode all spaces and line breaks are ignored; whitespace is determined by the operators or commands used. However, sometimes it is necessary to create some horizontal whitespace. The command \quad inserts whitespace the size of the font type, so 10pt for a 10pt font. A \qquad inserts twice as much whitespace. These commands also work in text mode. In math mode we have the following specific commands:

command length
\, 3/18 quad                     
\: 4/18 quad
\; 5/18 quad
\! $-$3/18 quad
\[ \int y\, dx \]
\int y\, dx


With the following commands we can choose different fonts. For the last two the package amssymb is required.

command example   usage
\mathrm $\mathrm{ABCDEF}$ $\mathrm{abcdef}$  
\mathit $\mathit{ABCDEF}$ $\mathit{abcdef}$  
\mathbf $\mathbf{ABCDEF}$ $\mathbf{abcdef}$ sets, vectors
\mathcal $\mathcal{ABCDEF}$ $\mathcal{abcde}$ categories, big-oh notation
\mathbb $\mathbb{ABCDEF}$   sets

We prefer not to use these commands directly in the code, but in a new command to seperate the content and layout. For example:

The complex numbers $\mathbb{C}$.


The complex numbers $\CC$.

Exercise 3

Typeset the display.

\[ \forall \epsilon > 0 \quad \exists \delta \quad \text{such that} \quad \forall x,y \in \mathbb{R}: |x-y|< \delta \implies | f(x+\delta) - f(x)| < \epsilon. \]

Hint: text inside math mode must be inserted using \text{...}. You can use Wikibooks/LaTeX for a list of symbols and LaTeX commands.


An operator is a function written as a word, like $\sin$ and $\log$. LaTeX has many predefined operators, but sometimes it is necessary to define one yourself. We create operators using \DeclareMathOperator in the preamble.

The next two exercises are about typesetting theorems.

Exercise 4

  1. Create a new LaTeX file containing the following code:
    \begin{theorem}[Cauchy-Schwarz inequality]
  2. Typeset the following definition:

    Definition 1. If $P(X\in S)=1$ for a finite $S$ then the expectation \[ \mathbb{E}X=\sum_{x\in S} xP(X=x). \]

  3. Typeset the following theorem. You may or may not use \DeclareMathOperator, whatever you find convenient.

    Theorem 2 (Cauchy-Schwarz inequality) . If $X$ and $Y$ are random variables with $\mathbb{E}X^2 \lt \infty$ and $\mathbb{E}Y^2 \lt \infty$, then \[ \DeclareMathOperator{\Var}{Var} \DeclareMathOperator{\Cov}{Cov} |\Cov(X,Y)|\le\sqrt{\Var(X)}\sqrt{\Var (Y)}. \]

Exercise 5

  1. Choose one of the following statements:
    • There are infinitely many prime numbers.
    • The number $\sqrt2$ is not rational.
  2. Create a new LaTeX file containing:
  3. Typeset your chosen statement using the theorem environment defined in the preamble.
  4. Prove the theorem and write your proof down in a proof environment.


You don’t need to remember all LaTeX commands. There are lot of references on the internet:


  • What is a math environment? What rules apply in math mode?
  • How to insert special characters?
  • What do $, [ ], _, ^, \alpha, \sin, \log, \frac, \binom, \sqrt[n], \sum, \int, (), [], \{ \} and | | do?
  • How to create your own operator?
  • How to insert horizontal whitespace?