Latex Primer 2
Latex Primer 2
This document is created by Thomas Wong and was originally used as a resource for students
in MATH110-001 at UBC. It is now a free for all resource for anyone interested in learning
LATEX. I don’t own LATEX or any of the packages or websites mentioned here. This is by no
means an exhaustive document. Please bother your instructor for any LATEX related issues.
However, please feel free to email me at thomas[dot]wong[at]unimelb[dot]edu[dot]au with any
comments, suggestions, feedback or if you spot any typos in this primer. Enjoy :)
If you want . . .
1 Some Online TEX Editors 1
2 A Quick Introduction 1
3 The Structure of LATEX 2
4 Normal Text 3
5 Math As Part Of A Sentence. 4
6 One line of Math, (Equation). 5
7 Multiple lines of Math, (Align). 7
8 Tables (Tabular). 8
9 Lists, Piecewise functions. 8
10 Pictures, Plots, Graphs, etc. 10
11 Miscellaneous and Other Cool Stuff. 10
12 Common Mathematical Commands and Symbols. 13
1. https://www.overleaf.com/
It is possible to the website without registering, but you won’t be able to save it online. Re-
member to make a copy of everything you do on your own computer.
2 A Quick Introduction
One of the biggest advantages of LATEXis that we (as the user) don’t have to worry too much
about the layout of the document. Latex will deal will most of the formatting issues. Latex
does contain a relatively steep learning curve but I have found through my own experiences
that the best way to learn is to begin with a template and then look up the bits I need to do
the task I have to do.
The document is not meant to be read from start to finish in a single sitting. When you
encounter problems with Latex, simply jump to the relevant section and look up the syntax.
LATEX Primer Thomas Wong
I have tried to include plenty of sample codes, so feel free to copy and paste the relevant bits
into Latex and edit as necessary.
Before, we get into it, there are some symbols that are special to Latex. Most commands
begin with a backslash ‘\’, and if a particular command requires input, this will be accomplished
using the curly brackets {}. Other symbols that will be of importance are $, % and &.
Some tips to do well with Latex:
3.1 Commenting
If we were to compile the above document, we notice that the lines starting with % do not
show up. This is known as commenting. It allows us to write comments in the document for
our own reference without it showing up in the final product. We can accomplish this by using
the % symbol. Every line that begins with a % in the code will be ignored by the compiler and
not displayed in the final document.
4 Normal Text
Text works normally as we would expect. Simply type what you want and Latex will take care
of the line breaks and spacing. With that said, to manually introduce a new line, we can do it
as follows:
While in text mode, we can also adjust the spacing quite easily. Some common spacing
commands:
LATEX Primer Thomas Wong
2. ‘\noindent’ at the beginning of a paragraph will remove the indent found at the start of
a paragraph.
1. Quotation marks can be written using the grave accent and the apostrophe symbols ‘ ’.
5. A series of dots such as . . . or · · · can be written using $\ldots$ and $\cdots$ respec-
tively.
Example 5. If you want to write a comment in the code to remind yourself how awesome
math is, you can write:
% Mathematics is amazing.
will be displayed
We can use $ to enclose variables to distinguish them for simple text. For example, look at
the difference between (a,a) or (x,x) with the first of each pair enclosed in $.
An important note: Curly brackets {} are used as invisible brackets to group text to-
gether.
Example 8. Environments:
\begin{environment we want}
Stuff we want to to
\end{environment we want}
\begin{equation}
f(x) = \frac{1}{1+\frac{1}{1+\frac{1}{1+\frac{1}{1+x}}}}
\end{equation}
Example 10. Important Note: When using the equation environment, or the align envi-
ronment below, we do not need any $ symbols. If you tried something like
LATEX Primer Thomas Wong
\begin{equation}
$f(x) = \frac{1}{1+\frac{1}{1+\frac{1}{1+\frac{1}{1+x}}}}$
\end{equation}
It won’t compile and spit out errors like it was the end of the world.
Notice that Latex automatically labels each equation in the document. If you do not want
an equation label, use the asterisk symbol when using the equation environment. Ie.
\begin{equation*}
f(x) = \frac{1}{1+\frac{1}{1+\frac{1}{1+\frac{1}{1+x}}}}
\end{equation*}
Everything that we can do in math mode can be done in the equation environment. We
can think of the equation environment as a extended version of the $ enclosure. As as example
of why the equation environment is sometime better, suppose we write the previous equation
using $, it would look like f (x) = 1+ 1 1 , which would be a little strange as part of a
1+ 1
1
1+ 1+x
paragraph.
As a final comment, sometimes we will want to bracket parts of our equation, if we do it
naively, we might right something that looks like:
\begin{equation}
g(t) = (\frac{t+2}{t-3})(\frac{1}{t})
\end{equation}
\begin{equation}
g(t) = \left(\frac{t+2}{t-3}\right)\left(\frac{1}{t}\right)
\end{equation}
Notice the difference between the text in the second and third row, the {\rm } in a align
or equation environment will tell Latex that this is normal text and not math text. Although
not necessary, empty curly brackets {} can be used as place holders to keep track of the which
bits you want empty.
8 Tables (Tabular).
If we want to insert a table of some sort into our document, the tabular environment will take
care of that. When creating the table, we have to tell Latex how many columns the table has.
Each column can be justified left(l) right(r) or center(c). Borders are handled in two different
ways. The vertical borders are defined when creating the environment using (|), horizontal
borders are added in the environment using the command \hline
Example 15. Tables:
\begin{tabular}{||l|l|c||r|}
\hline
\hline
Left Justified& Left Justified& Center Justified& Right Justified\\
Cell & Cell & Cell & Cell\\
\hline
$x$ & {}& $\frac{1}{t}$& {}\\
\hline
\hline
\end{tabular}
1. if we want to create a numbered list (such as this one), we will need to use
\begin{enumerate}
\item The first thing goes here.
\item The second thing goes here.
\end{enumerate}
2. To get an unnumbered list (ie one with bullet points), we simply replace enumerate with
itemize.
LATEX Primer Thomas Wong
\begin{itemize}
\item This is not numbered.
\item This won’t be numbered either.
\end{itemize}
3. The cases environment is useful when we want to insert piecewise functions. See Exam-
ple 17 to see how its used. It contains elements that are similar to the array environment.
4. This one is really included for completeness. The array environment is rarely used by
itself, but it will be a necessary part for the next example. It is (loosely speaking) similar
to the align environment with some tabular qualities.
As a final note on environments, we can embed one environment within another (possibly
the same). For example, to write a piecewise function, we can write:
Example 16. Piece-wise Function:
\begin{equation}
f(t) = \left\{
\begin{array}{cl}
f_1(t) & x < 10\\
x^4-x +2 & x \geq 10\\
\frac{5}{t} & {\rm otherwise}
\end{array}
\right.
\end{equation}
which will be displayed as:
f1 (t) x < 10
4
f (t) = x − x + 2 x ≥ 10 (8)
5
otherwise
t
Example 17. Piece-wise Function (again): An alternative (and possibly easier) way to
code up a piecewise function (Thanks Maxim).
\begin{equation}
f(x) = \begin{cases}
2x+c\sin(x) & \mbox{if } x\geq\pi \\
cx^3-x & \mbox{if } x<\pi
\end{cases}
\end{equation}
which will be displayed as:
(
2x + c sin(x) if x ≥ π
f (x) = (9)
cx3 − x if x < π
LATEX Primer Thomas Wong
\begin{figure}[htbp]
\centering
\includegraphics[width=1.00\textwidth]{picture.jpg}
\end{figure}
2. We can choose to have the picture at the current spot (here, h), top of the page (t),
bottom of the page (b) or separate page for pictures (p). Some, or all, of the letters may
be present. Latex will process them in order h,t,b then p.
4. width=1.00\textwidth adjusts the width of the picture as a fraction of the width of the
text.
2. http://www.meta-calculator.com/online/
3. http://fooplot.com/
11.1 Style
Latex has various media ‘styles’ built into it for articles, books, reports, letters, and slides. All
it takes is changing one word in the header. Standard sections such as cover/title pages, table
of contents, list of figures, list of tables, appendices are handled automatically.
\newcommand{ddx}[1]{\frac{d^{#1}}{dx^{#1}}}
in the pre-amble and write \ddx{2} for the second derivative (and replace 2 with 3 etc
to get higher order derivatives).
\newcommand{dd}[1]{\frac{d}{d #1}}
\newcommand{dd}[2]{\frac{d^{#2}}{d #1^{#2}}}
in the pre-amble and write \dd{t}{2} for the second order derivative with respect to t.
11.3 Numbering
As you may have noticed with the equations of this document, the numbering is done automat-
ically. I simply have to tell Latex what I want numbered. The same goes for the sections of this
document. Although not present, the same goes for Tables, Pictures, Theorems, Definitions,
References, Bibliography and pretty much anything else you want numbered.
11.4 Labelling
If there are particular sections or equations are important, it is possible to label them and
then link to them from elsewhere within the document. For example, I can link to Section 12
through very little effort. Again, the numbering is taken care of by Latex.
LATEX Primer Thomas Wong
11.5 Referencing
This is not only true for links within the document. If I have a list of references/bibliography,
Latex arranges and numbers the entries into the any style of your choosing (APA, MLA, AMA,
Chicago etc). The same goes for URL links as shown at the start of the document. Referencing
these entries within the document can also be done quite easily.
11.6 Customisation
EVERYTHING in Latex can be customised: font style, size, colour, spacing, margins, blank
spaces, hyperlinks, etc. There is a vast range of packages on the internet for everything that
you could ever think of changing in Latex. There is no reason to stop at the default settings.
Google is your friend!
LATEX Primer Thomas Wong