1. Installing LaTeX
  2. The Absolute Basics
  3. Packages

Using $\mathrm{\LaTeX}$ is practically inevitable for anyone who wishes to graduate with a mathematics degree from ETH, and we recommend getting familiar with the syntax as soon as possible.

This is totally what coding in LaTeX looks like.

Therefore every lecture will be accompanied by a brief post dedicated to learning how to use $\mathrm{\LaTeX}$. Together these posts will constitute a somewhat opinionated and whimsical introduction to typesetting professional mathematics. No prior knowledge of the subject is assumed.

Installing LaTeX

Before you can begin playing with $\mathrm{\LaTeX}$, you need access to a $\mathrm{\TeX}$ distribution. There are essentially two ways to do this:

  1. Install a $\mathrm{\TeX}$ distribution on your computer.
  2. Use a browser-based solution.

There are advantages and disadvantages to both methods. You will probably eventually want a $\mathrm{\TeX}$ distribution installed on your computer, since even if you primarily work in your browser, it is useful to be able to open .tex files locally. To obtain a $\mathrm{\TeX}$ distribution, go here and follow the installation instructions for your operating system of choice.

$\LaTeX$ is free software. However there also exist commercial $\mathrm{\LaTeX}$ editors. Of these I like Texpad (which is Mac/iOS only), although I do most of my work using the free LaTeXTools plugin for Sublime Text.

In the short term, however, it is easier to use a browser-based solution, since this doesn't require installing any special software. There are several competing products:

All of these are free for basic use, but allow you to subscribe to a paid plan for more features. My personal favourite is Overleaf. Moreover ETH has purchased an institutional license for Overleaf, which means if you sign up using your ETH email address then you get the paid features for free.

For this reason, the rest of these tutorial lectures will assume that you are using Overleaf.

Aside: Overleaf also has a excellent online knowledge base for learning $\mathrm{\LaTeX}$. It is far more comprehensive than my notes will ever be!


The Absolute Basics

Consider the following very short file:

\documentclass{article}
\begin{document}
Hello Math World!
\end{document}

To turn these four lines into a $\mathrm{\TeX}$ file, simply save them to your computer with a .tex extension. If we feed this file to a $\mathrm{\LaTeX}$ compiler, it will produce for us a PDF. It looks like this:

Note that only one of the four lines actually got printed. Let us explain why. Every $\mathrm{\LaTeX}$ document consists of two parts:

  1. The preamble.
  2. The content.

The content of the document is everything between the  \begin{document} and \end{document} . This is what gets typeset (= printed).  

The preamble is everything that comes before the \begin{document} line. This is where we tell $\mathrm{\LaTeX}$ what type of document we'd like to create. In our simple example the preamble consisted of the single line \documentclass{article}. This line is not optional: $\mathrm{\LaTeX}$ will throw an error if we omit it. We chose the class article, which is the default option and will suffice for everything we do today.

Here is another thrilling $\mathrm{\LaTeX}$ file:

\documentclass{article}
\title{The Tragedy of Darth Plagueis the Wise}
\author{Supreme Chancellor Palpatine}
\date{A long time ago}
\begin{document}
\maketitle
The dark side of the Force is a pathway to many abilities some consider to be unnatural.
\end{document}

This produces:

This time the preamble had three extra lines. We specified the title, the author, and the date. Then we added an extra line to the document itself: \maketitle. This tells $\mathrm{\LaTeX}$ to typeset the information we gave it.

Pro Tip: If you want to just use today's date, you can write \date{\today}.

So how do I type maths?

Inserting maths is easy. We simply invoke math mode. There are two types of math mode, depending whether we want the maths to appear on the same line as the surrounding text, or whether we want it to appear on its own line. The former is called inline math mode, whereas the latter is called displayed math mode.

Inline math mode is entered via the \begin{math} command and exited via the \end{math} command. Meanwhile displayed math mode is entered via the \begin{displaymath} command and exited by the \end{displaymath} command.

Here is a more complicated document that illustrates this.

\documentclass{article}
\title{The Basel Problem}
\author{Leonhard Euler}
\date{December 1735}
\begin{document}
\maketitle
Given any complex number \begin{math}s\end{math} with real part greater than 1, consider the function \begin{math}\zeta(s)\end{math} given by 
\begin{displaymath}
\zeta(s) = \sum_{n=1}^{\infty} \frac{1}{n^s}.
\end{displaymath}
Then it holds that \begin{math}\zeta(2) = \frac{\pi^2}{6}\end{math}.
\end{document}

This gives us:

Let us go through the various math elements we introduced step-by-step.

  • Greek letters: To write a Greek letter, we type a backslash, followed by the name of the letter. Thus \alpha produces $ \alpha$.
  • To write an exponent, use a caret ^. Thus n^2 gives us $n^2$. If the exponent has more than one character, it needs to be wrapped in curly brackets. Thus n^{34} gives $n^{34}$.
  • The summation symbol: We wrote \sum to produce the summation symbol $\sum$. Moreover we use an underscore with curly brackets _{...} to specify the lower range of the summation and a caret with curly brackets ^{...} to specify the upper range of the summation.
  • Fractions: To create a fraction $\frac{a}{b}$ we write \frac{a}{b}. Note that both the summation symbol and the fraction have a slightly different appearance depending as to whether we are in inline mode or displayed mode.
  • The number infinity: The command for infinity is \infty.

As you can see, some commands are easier to guess than others. They will all eventually become second nature. You can find a comprehensive reference list here, although my advice is just to pick things up as you go along.

Typing out \begin{math} ... \end{math} and \begin{displaymath} ... \end{displaymath} every time we want to enter or exit math mode rapidly becomes tedious. So you will pleased to know there are shorter versions:

Short version Really short version
Inline \( ... \) $ ... $
Displayed \[ ... \] $$ ... $$

Warning: $\mathrm{\LaTeX}$ experts will tell you not to use the “really short version” $$ ... $$ for displayed math. This is because it is a deprecated command from the original plain $\mathrm{\TeX}$ syntax. As a result, using $$ ... $$ can cause errors in some weird edge cases (for instance, when used in tandem with \fleqn). For more information about this see here. Throughout the rest of these notes, we will use $ ...$  for inline maths, and \[ ... \] for displayed maths.


Packages

$\mathrm{\LaTeX}$ can be extended by enabling additional packages. This is done via the \usepackage command in the preamble. There are hundreds and hundreds of packages to choose from, but in practice you won't need that many.

There are however three key packages that you will probably end up using in every single document you write. They are designed to enable advanced mathematical typesetting, and were all developed by the American Mathematical Society. They are:

  • amsmath
  • amssymb
  • amsthm

The simplest to understand of these is the middle one, amssymb. This package gives $\mathrm{\LaTeX}$ access to certain common mathematical fonts and symbols.

For example, amssymb unlocks the “blackboard font” that is typically used to denote fields (eg. the real numbers $\mathbb{R}$, the rational numbers $\mathbb{Q}$, and the complex numbers $\mathbb{C}$). Let us see this in action:

\documentclass{article}
\usepackage{amssymb}
\title{\"Uber die Anzahl der Primzahlen unter einer gegebenen Gr\"o\ss e}
\author{Bernhard Riemann}
\date{November 1859}
\begin{document}
\maketitle
Let $s \in \mathbb{C}$ be such that $ \zeta(s) = 0$. Assume that $s$ is not of the form $s = -2n$ for some $n \in \mathbb{N}$. Then we conjecture that the real part of $s$ is equal to $ \frac{1}{2}$, that is,
\[
s = \frac{1}{2} + i t
\]
for some $t \in \mathbb{R}$.
\end{document}

This gives us:

To get the special font $\mathbb{C}$ we wrote \mathbb{C}  (inside math mode). The “bb” stands for “blackboard”. This only works because we invoked the amssymb package in the preamble. Other amssymb fonts can be accessed similarly:

Command Alphabet Appearance
\mathbb Blackboard $\mathbb{ABC}$
\mathcal Calligraphic $\mathcal{ABC}$
\mathfrak Fraktur $\mathfrak{ABC}$

Note also that the symbol $ \in $ is given by the command \in.

Moreover this time the title contained several letters with diacritics. Diacritics in $\mathrm{\LaTeX}$ are mostly easy to guess:

  • An umlaut is given by \". Thus Ü is \"U and ö is \"o.
  • An accent is given by \'. Thus é is \'e.
  • To get ß, one types \ss.

Finally, observe that in “Größe” we wrote Gr\"o\ss e , deliberately leaving a space after the \ss. If we omitted this space, $\mathrm{\LaTeX}$ would try and parse \sse as a command and throw an error. Nevertheless, $\mathrm{\LaTeX}$ does not print this extra space. We will discuss spacing more in the next tutorial.

Warning: If you are using an old (pre-2018) version of $\mathrm{\LaTeX}$, you will sometimes need to add the line \usepackage[utf8]{inputenc} to your preamble to handle certain accents correctly. This loads the package inputenc (which is short for “Input Encoding”) with the utf8 option. However in new versions of $\mathrm{\LaTeX}$ this is loaded automatically, so you don't need to bother.

That's it for today. In the next $\mathrm{\LaTeX}$ installment we'll discuss formatting and styling text, and the package amsmath. In the third installment we'll discuss the final key package amsthm, which allows us to add Theorems and Proofs and whatnot to our documents.

By Christmas you will all be typesetting gurus, ready to pour scorn upon your Microsoft Word-using friends.

-

Comments and questions?