Section A.1 Introduction to LaTeX
Objectives
- Use Overleaf and LaTeX to typeset mathematics.
The overwhelming majority of mathematics articles and texts are typeset using LaTeX [7], a document preparation system developed specifically for producing scientific and technical documents. As students in the mathematics programs you are expected to know how to use LaTeX. The availability of free, online editors like Overleaf provides a low barrier to entry.
In LaTeX the primary focus is on the content and not the format of your document. So you will be working on a plaintext file, typing commands that tell LaTeX what to do when your document is compiled (similar to programming).
Example A.1.1. LaTeX example.
In LaTeX, the following code generates the text below. Can you guess what the commands mean by looking at the output?
Code:
Let's prove that \[ \sum_{i=1}^n i = \dfrac{n(n+1)}{2}\] using mathematical induction. The base case for $n = 1$ is clearly true, since $1 = \frac{1(2)}{2}$. Now assume that the claim is true for $n = k$; that is, \[ \sum_{i=1}^k i = 1 + 2 + \cdots + k = \dfrac{k(k+1)}{2}.\]
Output:
Let's prove that
using mathematical induction.
The base case for \(n = 1\) is clearly true, since \(1 = \frac{1(2)}{2}\text{.}\)
Now assume that the claim is true for \(n = k\text{;}\) that is,
Try this out yourself! Go to https://overleaf.com and create an account. Then start a new blank project, give it the name First Project, and copy and paste the code above, just below the \section{introduction}
line.
Press CTRL + Enter
to compile the document. The output should appear on the right.
You may have noticed that there is some extra text that tells LaTeX what kind of document you are preparing (article), what the title is (First Project), author's name, and so on. Everything above the \begin{document}
line is said to be the preamble of the document—here you will usually issue commands to LaTeX about global formatting options, packages you want installed, and so on.
In fact if you look at your First Project document, in line 14 there is an error message, denoted by the red X. Hover your cursor over it to see the message: Undefined control sequence
. The issue here is that the command \dfrac{ }{ }
that we used to generate
is not in LaTeX by default. So the fractions don't actually appear in the output.
To remedy this we need to tell LaTeX to load the amsmath
package so we have access to all its commands, including \dfrac{ }{ }
. Just add the line \usepackage{amsmath}
to the preamble. It can be anywhere, but it is generally good practice to place all \usepackage
commands together, so type it in line 3. Now compile again by pressing CTRL + Enter
and the error message should disappear. The output on the right should be correct as well.
Most mathematics documents start by loading the packages
-
amsmath
for general mathematical features -
amsthm
for theorem-like environments -
amssymb
for even more symbols
so you can just load all of them at the beginning of each document you create.
You also probably noticed that placing dollar signs $ $
around text renders that text as mathematics. Placing \[ \]
around text (or double dollar signs $$ $$
)renders that as display mathematics, centered in its own line. Have a look at this website for a list of commonly-used math symbols and try using Overleaf to typeset a number of results from these notes or another math textbook. Have fun and explore! This is where your LaTeX journey begins.
Next Steps and Resources.
This video is a very nice introduction to LaTeX by David Richeson and I highly recommend you take the time to watch it (35 minutes).
Here are some other helpful resources:
- David Richeson also has a PDF quick guide to LaTeX available on his website.
- Overleaf also has an introductory guide.
- Detexify for searching commands for symbols.
- TeXworks, if you would like to install LaTeX on your computer. (optional! only if you really want to...)