An important reason for using LaTeX is that it is fairly easy to typeset mathematical expressions. For basic mathematics, no packages are needed. We will use mathtools, an extension of amsmath, since we will typeset more complex expressions:

\usepackage{mathtools}

This lesson we will discuss some of the most used commands for typesetting mathematics. For more details you can look at this Short Math Guide for LaTeX and the documentation of amsmath or mathtools.

Our main reference, however, is Wikibooks/LaTeX/Mathematics.

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
\begin{equation}
a + b = 2x
\end{equation}
and
\begin{equation}
a-b = 2y
\end{equation}
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.

Characters

The symbols

\ + - = ! / ( ) [ ] < > | ' :

can be inserted directly in math mode. For other symbols and accents there exist commands. We will encounter many symbols in this lesson. If you don’t know the code for a symbol you can use detexify. There also exist overviews of LaTeX symbols.

The following accents are used frequently:

command output
a', a'', a''' $a’$, $a’’$, $a’’’$
\hat{a}, \widehat{aa} $\hat{a}$, $\widehat{aa}$
\bar{a}, \underline{a}, \overline{aa} $\bar{a}$, $\underline{a}$, $\overline{aa}$
\dot{a}, \ddot{a}, \dddot{a} $\dot{a}$, $\ddot{a}$, $\dddot{a}$
\not= $\not=$
\vec{a}, \overrightarrow{aa}, \overleftarrow{aa} $\vec{a}$, $\overrightarrow{aa}$, $\overleftarrow{aa}$
\tilde{a}, \widetilde{aa} $\tilde{a}$, $\widetilde{aa}$

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} \]

Operators

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.

\[ \DeclareMathOperator{\tr}{tr} \DeclareMathOperator{\ord}{ord} \DeclareMathOperator{\Poisson}{Poisson} \tr A,\quad \ord_p{a} = 2,\quad \Poisson(\lambda) \]
\documentclass[a4paper]{article}
\usepackage{mathtools}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\ord}{ord}
\DeclareMathOperator{\Poisson}{Poisson}

\begin{document}
\[
\tr A, \ord_p a = 2, \Poisson(\lambda)
\]
\end{document}

Common expressions

A fraction can be created using \frac{2}{3}. A binomial coefficient is made with \binom{n}{k}. It is possible to create fractions inside fractions.

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

We can use \tfrac and \tbinom for small fractions and binomial coefficients. It is up to the user to decide when to use \tfrac.

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.

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.

Brackets

Brackets and other delimiters are typeset in the following way:

\[ ( a )\quad [ b ]\quad \{ c \}\quad \mid d \mid \quad \| e \|\quad \langle f \rangle\quad \lfloor g \rfloor\quad \lceil h \rceil\quad \ulcorner i \urcorner \]
( a ) [ b ] \{ c \} | d | \| e \|
\langle f \rangle
\lfloor g \rfloor
\lceil h \rceil
\ulcorner i \urcorner

You can scale these delimiters automatically using \left, \right en \middle.

\[ \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|

You can scale them manually using \bigl, \bigr; \Bigl, \Bigr; \biggl, \biggr; \Biggl, \Biggr. You should only do this if necessary.

\[ ( \bigl( \Bigl( \biggl( \Biggl( \quad\quad \biggl(\frac{x^2}{y^3}\biggr) \quad\quad P\biggl(A=2 \biggm| \frac{A^2}{B}>4\biggr) \]
( \bigl( \Bigl( \biggl( \Biggl(
\biggl(\frac{x^2}{y^3}\biggr)
P\biggl(A=2 \biggm| \frac{A^2}{B}>4\biggr)

Exercise 2

Typeset the display

\[ \biggl(\sum_{i=1}^n a_i\biggr)^2 \]

Experiment with the size of the brackets to find the right size.

Horizontal whitespace

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

Layout

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
\mathsf $\mathsf{ABCDEF}$ $\mathsf{abcdef}$  
\mathtt $\mathtt{ABCDEF}$ $\mathtt{abcdef}$  
\mathcal $\mathcal{ABCDEF}$ $\mathcal{abcde}$ categories, big-oh notation
\mathfrak $\mathfrak{ABCDEF}$ $\mathfrak{abcdef}$ Lie-algebras, ideals
\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}$.
\documentclass[a4paper]{article}
\usepackage[dutch]{babel}
\usepackage{mathtools}
\usepackage{amssymb}

\newcommand{\field}[1]{\mathbb{#1}}
\newcommand{\CC}{\field{C}}

\begin{document}
The complex numbers $\CC$.
\end{document}

List of symbols

Sets, logic, functions
         
\exists $\exists$      \rightarrow $\rightarrow$
\nexists $\nexists$      \leftarrow $\leftarrow$
\forall $\forall$      \mapsto $\mapsto$
\neg $\neg$      \implies $\implies$
\subset $\subset$      \Rightarrow $\Rightarrow$
\supset $\supset$      \leftrightarrow $\leftrightarrow$
\in $\in$      \iff $\iff$
\notin $\notin$      \Leftrightarrow $\Leftrightarrow$
\ni $\ni$      \top $\top$
\vee $\vee$      \bot $\bot$
\wedge $\wedge$      \emptyset $\emptyset$
Binary relations
       
< $ <$      > $ >$
= $=$      : $:$
\in $\in$      \ni $\ni$
\leq $\leq$      \geq $\geq$
\ll $\ll$      \gg $\gg$
\prec $\prec$      \succ $\succ$
\preceq $\preceq$      \succeq $\succeq$
\sim $\sim$      \approx $\approx$
\simeq $\simeq$      \cong $\cong$
\equiv $\equiv$      \doteq $\doteq$
\subset $\subset$      \supset $\supset$
\subseteq $\subseteq$      \supseteq $\supseteq$
\sqsubseteq $\sqsubseteq$      \sqsupseteq $\sqsupseteq$
\smile $\smile$      \frown $\frown$
\perp $\perp$      \models $\models$
\mid $\mid$      \parallel $\parallel$
\vdash $\vdash$      \dashv $\dashv$
\propto $\propto$      \asymp $\asymp$
\bowtie $\bowtie$         
\sqsubset $\sqsubset$      \sqsupset $\sqsupset$
\Join $\Join$         
Greek letters (lowercase)
           
\alpha $\alpha$      \iota $\iota$      \sigma $\sigma$
\beta $\beta$      \kappa $\kappa$      \tau $\tau$
\gamma $\gamma$      \lambda $\lambda$      \upsilon $\upsilon$
\delta $\delta$      \mu $\mu$      \phi $\phi$
\epsilon $\epsilon$      \nu $\nu$      \chi $\chi$
\zeta $\zeta$      \xi $\xi$      \psi $\psi$
\eta $\eta$      \pi $\pi$      \omega $\omega$
\theta $\theta$      \rho $\rho$         
\varepsilon $\varepsilon$      \varpi $\varpi$      \varsigma $\varsigma$
\vartheta $\vartheta$      \varrho $\varrho$      \varphi $\varphi$
Greek letters (uppercase)
       
\Gamma $\Gamma$      \Phi $\Phi$
\Delta $\Delta$      \Psi $\Psi$
\Theta $\Theta$      \Omega $\Omega$
\Lambda $\Lambda$         
\varGamma $\varGamma$      \varPhi $\varPhi$
\varDelta $\varDelta$      \varPsi $\varPsi$
\varTheta $\varTheta$      \varOmega $\varOmega$
\varLambda $\varLambda$    
Operators without ‘limits’
                 
\arccos $\arccos$      \cot $\cot$      \hom $\hom$      \sin $\sin$  
\arcsin $\arcsin$      \coth $\coth$      \ker $\ker$      \sinh $\sinh$  
\arctan $\arctan$      \csc $\csc$      \lg $\lg$      \tan $\tan$  
\arg $\arg$      \deg $\deg$      \ln $\ln$      \tanh $\tanh$  
\cos $\cos$      \dim $\dim$      \log $\log$      
\cosh $\cosh$      \exp $\exp$      \sec $\sec$      
Operators with ‘limits’
       
\det $\det$      \limsup $\limsup$
\gcd $\gcd$      \max $\max$
\inf $\inf$      \min $\min$
\lim $\lim$      \Pr $\Pr$
\liminf $\liminf$      \sup $\sup$
\injlim $\injlim$      \projlim $\projlim$
\varliminf $\varliminf$      \varlimsup $\varlimsup$
\varinjlim $\varinjlim$      \varprojlim $\varprojlim$
Binary operators
       
+ $+$      - $-$
\pm $\pm$      \mp $\mp$
\times $\times$      \cdot $\cdot$
\circ $\circ$      \bigcirc $\bigcirc$
\div $\div$      \bmod $\bmod$
\cap $\cap$      \cup $\cup$
\sqcap $\sqcap$      \sqcup $\sqcup$
\wedge or \land $\wedge$      \vee or \lor $\vee$
\triangleleft $\triangleleft$      \triangleright $\triangleright$
\bigtriangleup $\bigtriangleup$      \bigtriangledown $\bigtriangledown$
\oplus $\oplus$      \ominus $\ominus$
\otimes $\otimes$      \oslash $\oslash$
\odot $\odot$      \bullet $\bullet$
\dagger $\dagger$      \ddagger $\ddagger$
\setminus $\setminus$      \smallsetminus $\smallsetminus$
\wr $\wr$      \amalg $\amalg$
\ast $\ast$      \star $\star$
\diamond $\diamond$         
\lhd $\lhd$      \rhd $\rhd$
\unlhd $\unlhd$      \unrhd $\unrhd$
\dotplus $\dotplus$      \centerdot $\centerdot$
\ltimes $\ltimes$      \rtimes $\rtimes$
\leftthreetimes $\leftthreetimes$      \rightthreetimes $\rightthreetimes$
\circleddash $\circleddash$      \uplus $\uplus$
\barwedge $\barwedge$      \doublebarwedge $\doublebarwedge$
\curlywedge $\curlywedge$      \curlyvee $\curlyvee$
\veebar $\veebar$      \intercal $\intercal$
\doublecap or \Cap $\doublecap$      \doublecup or \Cup $\doublecup$
\circledast $\circledast$      \circledcirc $\circledcirc$
\boxminus $\boxminus$      \boxtimes $\boxtimes$
\boxdot $\boxdot$      \boxplus $\boxplus$
\divideontimes $\divideontimes$      \vartriangle $\vartriangle$
\And $\And$    
Large operators
             
\sum $\sum$      \prod $\prod$      \coprod $\coprod$  
\bigoplus $\bigoplus$ \bigotimes $\bigotimes$ \bigodot $\bigodot$  
\bigcup $\bigcup$ \bigcap $\bigcap$ \biguplus $\biguplus$  
\bigsqcup $\bigsqcup$ \bigvee $\bigvee$ \bigwedge $\bigwedge$  
\int $\int$ \oint $\oint$ \iint $\iint$  
\iiint $\iiint$ \iiiint $\iiiint$ \idotsint $\idotsint$  
Miscellaneous
   
\partial $\partial$
\eth $\eth$
\hbar $\hbar$
\imath $\imath$
\jmath $\jmath$
\ell $\ell$
\Re $\Re$
\Im $\Im$
\wp $\wp$
\nabla $\nabla$
\Box $\Box$
\infty $\infty$
\aleph $\aleph$
\beth $\beth$
\gimel $\gimel$
\angle $\angle$
\natural $\natural$

The next two exercises are about typesetting theorems.

Exercise 3

  1. Create a new LaTeX file containing the following code:
    \documentclass[a4paper,12pt]{article}
    \usepackage[english]{babel}
    \usepackage{mathtools}
    \usepackage{amssymb}
    \usepackage{amsthm}
    
    \theoremstyle{plain}
    \newtheorem{theorem}{Theorem}
    \theoremstyle{definition}
    \newtheorem{definition}[theorem]{Definition}
    
    \begin{document}
    
    \begin{definition}
    \end{definition}
    
    \begin{theorem}[Cauchy-Schwarz inequality]
    \end{theorem}
    
    \end{document}
    
  2. Typeset the following definition:

    Definition 1. If $P(X\in S)=1$ for a finite $S$ then the expectation \[ EX=\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 $EX^2 \lt \infty$ and $EY^2 \lt \infty$, then \[ \DeclareMathOperator{\Var}{Var} \DeclareMathOperator{\Cov}{Cov} |\Cov(X,Y)|\le\sqrt{\Var(X)}\sqrt{\Var (Y)}. \]

Exercise 4

  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:
    \documentclass[a4paper,12pt]{article}
    \usepackage[dutch]{babel}
    
    \usepackage{mathtools}
    \usepackage{amssymb}
    \usepackage{amsthm}
    
    \theoremstyle{plain}
    \newtheorem{theorem}{Theorem}
    
    \begin{document}
    
    \end{document}
    
  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.

Resources

You don’t need to remember all LaTeX commands. On the internet there are lots of references.

LaTeX Cheat Sheet
A comprehensive document with a lot of commands. Save it and print it.

Remember

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