0% found this document useful (0 votes)
67 views23 pages

LaTeX Guide

This document provides an introduction to LaTeX, including what it is, how it differs from word processors, how to get LaTeX, useful web editors, and resources for help. It covers the basics of creating documents in LaTeX such as structure, text formatting, equations, figures, and references.

Uploaded by

jcmelchorp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views23 pages

LaTeX Guide

This document provides an introduction to LaTeX, including what it is, how it differs from word processors, how to get LaTeX, useful web editors, and resources for help. It covers the basics of creating documents in LaTeX such as structure, text formatting, equations, figures, and references.

Uploaded by

jcmelchorp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

A Beginner’s Guide to LATEX

Jon Shiach, Tony Scallan & Killian O’Brien


May 22, 2017

Contents
1 Introduction 2
1.1 What is LATEX? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 How LATEX differs to traditional word processors . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Getting LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Web based LATEX editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.5 Getting help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.6 Some useful and interesting web links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Getting started 4
2.1 LATEX editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Commands and Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 The structure of a tex file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4 The top matter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.5 Entering text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.6 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.7 Program code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.8 Sectioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.9 Table of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3 Typesetting equations 11
3.1 Aligned equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.3 Superscripts and subscripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.4 Fractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.5 Brackets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.6 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.7 Greek characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.8 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.9 Piecewise functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.10 Text in equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4 Figures & tables 16


4.1 Importing graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.2 Captions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.3 Constructing tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

5 Referencing 19
5.1 Referencing sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.2 Cross referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

A Article template 23

1
A Beginner’s Guide to LATEX

1 Introduction
1.1 What is LATEX?
LATEX (pronounced ‘lay-tech’) is a document preparation system that is widely used by mathematicians
because it is easy to produce professional standard documents with beautifully typeset mathematics.
LATEX is based upon TEX (pronounced ‘tech’), a low level typesetting language written by Donald Knuth
in 1982.

1.2 How LATEX differs to traditional word processors


With a word processor like Microsoft Word the user is presented with a representation of the physical page
and enters their content directly onto the page. This can prompt the user to think about various aspects
of how their content will appear on the page, such as where the line-breaks in a paragraph are; where the
page-breaks are; how the font looks and so on. Arguably these considerations can be a distraction from
the writing process itself.
Writing a document with LATEX is quite different. Here the user enters their content in a plain text
format and makes use of embedded commands to produce chapter and section breaks, mathematical
symbols, formatted tables and so on. But the user should normally be focused on just the content of
their writing at this stage and not concerned with how it will look on the final printed, or screen-viewed
page. The formatting of the user’s content onto the page is handled separately by the LATEX system using
pre-defined settings. These settings can all be fully customised by using special LATEX commands but the
philosophy is that the normal work-flow enables the user to focus solely on the content of their writing
and leave the work of preparing the content for the page to the computer.

1.3 Getting LATEX


LATEX is free software and available on Mac OS X, Microsoft Windows and Linux platforms. LATEX is
distributed as a collection of packages and programs that will contain everything you need to be able
to create documents (and lots of things that you will never use). Use the links below to download the
appropriate package corresponding to your computer. These are very large files (approximately 1.5GB)
and may take a long time to download if you are on a slow connection.

• Mac OS X (MacTeX) – http://www.tug.org/mactex/

• Microsoft Windows (proTeXt) – http://www.tug.org/protext/

• Linux (TeX Live) – http://www.tug.org/texlive/

1.4 Web based LATEX editors


An alternative way to produce LATEX documents is to use a web based LATEX editor where documents can
be created without needing to download and install the LATEX packages to your computer. Two such
examples are:

• overleaf (formally writelatex) – http://www.overleaf.com

• sharelatex – http://www.sharelatex.com

1.5 Getting help


Due to the thousands of LATEX commands and environments available, there are bound to be times when
a LATEX user cannot remember the correct syntax or simply does not know how to solve a problem. The
simple answer to this is to perform a web search with the term ‘latex’ prefixing your search. For example,
searching for ‘latex tables’ will return lots of web pages showing you how to insert a table into your
document. There isn’t a day that goes by when even experienced LATEX users need to lookup something
or other. Thankfully, LATEX is such a widely used program that there are plenty of resources available
and searching the web for ‘latex’ is ‘safe for work’.

Division of Mathematics & Computation 2 Manchester Metropolitan University


1.6 Some useful and interesting web links A Beginner’s Guide to LATEX

1.6 Some useful and interesting web links


There is a large amount of information relating to TEXand LATEX on the web. Here are some selected
highlights.

• http://www-cs-faculty.stanford.edu/~uno/ – This is the webpage of Donald Knuth, a computer


scientist from Stanford University who wrote TEX.
• http://latex-project.org/ – The home of the LATEX project (and future LATEX3 version).
• http://www.ctan.org/ – The Comprehensive TEX Archive Network is a central repository for TEX
packages and other material.

• http://tobi.oetiker.ch/lshort/lshort.pdf – The Not So Short Introduction to LATEX, by


Tobias Oetiker et al, a more in-depth introduction than this guide.
• http://tex.stackexchange.com/ – This Stack Exchange is a question and answer site for users
of TEX, LATEX and related typesetting systems. Mostly used for technical queries relating to the use
of these systems.

• http://xetex.sourceforge.net/ – XETEX is an extension to TEX which allows the use of Unicode


and modern font technologies to support (most of) the world’s fonts.

Division of Mathematics & Computation 3 Manchester Metropolitan University


A Beginner’s Guide to LATEX

2 Getting started
A LATEX document consists of a plain text file that contains the commands that are used to create the
typeset document (known as the ‘tex file’). This plain text file can be created using any text editor you
want but it must have the extension .tex appended to the end of the filename. The tex file is then
compiled where it is parsed to the LATEX program and provided there are no errors, an output file will be
produced that will contain the typeset document.

2.1 LATEX editors


The traditional way to create a LATEX document was to use any text editor to create the tex file and then
compile it using the command prompt. Fortunately, modern LATEX packages contain dedicated editors
that include tools for compiling the tex file and viewing the typeset PDF file, examples include TeXshop
(Mac) and TeXstudio (Windows and Linux).

2.2 Commands and Environments


LATEX is a typesetting language that uses specific commands and environments to control the appearance
of a document. To distinguish them from text, all LATEX commands are preceded by a backslash \ . A
command name consists only of letters and is ended by a space or a punctuation mark, i.e.,

\command

For example, the command \LaTeX\ produces the LATEX logo. If a command requires an argument then
it is placed within curly brackets { }, i.e.,

\command{argument}

For example, the command \emph{emphasised text} produces emphasised text.


LATEX controls the appearance of sections of text using what are called environments. Environments
are controlled by a command at the start and end of the text that is being affected, i.e.,

\begin{environment name}
...
\end{environment name}

For example, the center environment centres all text that appears in between the \begin{center} and
\end{center} commands.

2.2.1 Comments
Like with any markup or programming language, comments in the source file are useful for helping
understand what is going on. In LATEX any text following a \% symbol is treated as a command and is
ignored.

2.2.2 Measurements
Some commands require a length to be specified. In these cases LATEX recognises the following units:

pt printer’s point (1/72th of an inch)


cm centimetre
mm millimetre
in inch
em width of an ‘m’ character in the current font
ex height of an ‘x’ character in the current font

2.2.3 User defined commands


It is possible for a user to define or alter existing commands and environments by using the following
commands

Division of Mathematics & Computation 4 Manchester Metropolitan University


2.3 The structure of a tex file A Beginner’s Guide to LATEX

\newcommand
\renewcommand
\newenvironment
\renewenvironment
The use of these commands is outside the scope of this document, but for more information on using
these, click on the following link: Wikibooks: LaTeX/Macros.

2.3 The structure of a tex file


The basic structure of a tex file is as follows

\documentclass{...}
\usepackage{...}
\begin{document}
...
\end{document}

The area between \documentclass{...} and \begin{document} is known as the preamble and is used
to tell LATEX which packages are required (see section 2.3.2) and contains commands that affect the entire
document. After the preamble, the text of the document is contained within the \begin{document} and
\end{document} commands.

2.3.1 Document classes


The documentclass command specifies the type of document that is going to be created. Three of the
most useful document classes are given in the table below:
Class Description
article A standard scientific journal article, short report, assignment etc.
book A large document divided into chapters, e.g., project report, PhD thesis etc.
beamer Presentation slides
The options used in the documentclass command are given below:
Option Description
10pt, 11pt, 12pt Base font size
a4paper, letterpaper Paper size
Specifies whether the document is printed on double or
twoside, oneside
single sided paper
fleqn Typesets displayed equations left aligned instead of centred
Places the equation numbers on the left hand side instead
leqno
of the right
Specifies whether a new page should be started after the
titlepage, notitlepage
document title or not (used for the article class)
onecolumn, twocolumn Specifies the number of columns used in the document
For example, if you want an article to use 11pt type on A4 paper and printed on both sides of the paper
you would use:
\documentclass[11pt,a4paper,twoside]{article}

2.3.2 Packages
Packages are enhancements that allows authors to use commands to perform actions that would be very
complicated using basic LATEX. Packages are activated using usepackage command
\usepackage[options]{package}
where package is the name of the package and options is a list of keywords that trigger special features
in the package. There are hundreds of available packages and different documents will require different
packages. Below is a list of common packages that you may find useful

Division of Mathematics & Computation 5 Manchester Metropolitan University


A Beginner’s Guide to LATEX 2.4 The top matter

Package Description
geometry An easy way to set the page margins
amsmath, amssymb, American Mathematics Society (AMS) packages that provide en-
amsthm chancements to the typesetting of mathematics in LATEX documents
biblatex Enhanced referencing package that allows Harvard style referencing
graphicx Include image files in a document
fancyhdr Fancy header and footers
listings Insert code into a document with syntax highlighting
tikz A vector drawing package
automatically appends fig., table., eq. etc. to the cross-reference
cleveref
based on the type of environment being referenced
Automatically add hyperlinks for references and easy cross-
hyperref
referencing

For example, to include these packages in your preamble the following would appear in the preamble

\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[backend=bibtex,citestyle=authoryear,bibstyle=authoryear,natbib]{biblatex}
\addbibresource{references}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{listings}
\usepackage{cleveref}
\usepackage{hyperref}

2.4 The top matter


The top matter of a document contains the title, author name and the date. This information is specified
using \title{...}, \author{...} and \date{...} commands and displayed in the title of the document
using the \maketitle command. For example,

\documentclass[11pt,a4paper,twoside]{article}

\title{A \LaTeX\ Document}


\author{Joe Bloggs}
\date{September 2013}

\begin{document}
\maketitle
\end{document}

The \title{...} and \author{...} fields are compulsory and LATEX will return an error if these aren’t
specified. The \date{...} field is optional, if it is left blank then LATEX will not use the date in the
title; if no \date command is specified then LATEX will use the date that the document is compiled. If an
affiliate institution is required, this can be written in the \author field, for example,

\documentclass[11pt,a4paper,twoside]{article}

\title{A \LaTeX\ Document}


\author{Joe Bloggs \\
School of Computing, Mathematics and Digital Technology \\
Manchester Metropolitan University}
\date{September 2013}

\begin{document}
\maketitle
\end{document}

Division of Mathematics & Computation 6 Manchester Metropolitan University


2.5 Entering text A Beginner’s Guide to LATEX

If we compile the above tex file we get the output shown below

A LATEX Document
Joe Bloggs
School of Computing, Mathematics and Digital Technology
Manchester Metropolitan University

September 2013

2.4.1 Abstract

LATEX provides an environment for including an abstract in an article document class. To add an
abstract in your document, include the following in the preamble:

\begin{abstract}
...
\end{abstract}

2.5 Entering text


Text is entered into a tex file in the same way as any other word processing program. To start a new
paragraph, leave an empty line between the previous paragraph and the next (LATEX ignores multiple
blank lines in the input file). By default, the first line of a paragraph is indented in the compiled document.
If it is preferred to have a blank line separating paragraphs with no indentation then place the following
commands in the preamble:

\setlength{\parindent}{0pt}
\setlength{\parskip}{11pt}

2.5.1 Special characters

Since certain characters have special meaning in LATEX then in order to use these same characters in a
document we need to use commands to do this. Below is a list of the special characters in LATEX and the
command used to enter these into a document

LATEX command (for inserting


Special character Special LATEXmeaning
into document)
\ (backslash) \(\backslash\) Used to begin a command
% (percent) \% Used to start a comment
$ (dollar) \$ Used to start and end math mode
& (ampersand) \& Used to align tables and equations
{ } (curly brackets) {...} Used to enclose a group or argument
(underscore) \_{...} Used in math mode for subscripts
ˆ (caret) \^{...} Used in math mode for superscripts

2.5.2 Appearance of text

The appearance and size of text can be changed using the following commands:

Division of Mathematics & Computation 7 Manchester Metropolitan University


A Beginner’s Guide to LATEX 2.6 Lists

Command Description
\textbf{...} bold text
\emph{...} emphasised text
\underline{...} underlined text
\texttt{...} typewriter font
{\tiny ...} tiny

{\scriptsize ...} script size


{\small ...} small
{\normalsize ...} normal size
{\large ...} large
{\Large ...} Large
{\LARGE ...} LARGE
{\huge ...} huge
{\Huge ...}
Huge
2.5.3 Text alignment
The text is justified by default but can be alined to the left, centre or right hand side using the flushleft,
center or flushright environments. For example, the source

\begin{center}
This text is centred on the page
\end{center}

will produce the following output

This text is centred on the page

2.6 Lists
LATEX provides environments to handle bulleted and numbered lists. For a simple bulleted list, use the
itemize environment, for example, the source

\begin{itemize}
\item First item
\item Second item
\end{itemize}

produces

• First item
• Second item

Numbered lists can be produced using the enumerate environment, for example.

\begin{enumerate}
\item First item
\item Second item
\end{enumerate}

produces

Division of Mathematics & Computation 8 Manchester Metropolitan University


2.7 Program code A Beginner’s Guide to LATEX

1. First item
2. Second item

Lists and numbered lists can be nested. For example,


\begin{enumerate}
\item First level item
\begin{enumerate}
\item Second level item
\begin{enumerate}[(i)]
\item Third level item
\end{enumerate}
\end{enumerate}
\end{enumerate}
produces

1. First level item


(a) Second level item
(i) Third level item

2.7 Program code


A widely used convention, and one that is recommended, is that program code be typeset using a
monospaced font when included in a document so it can be easily distinguished from the rest of the text.
This can be easily done using using the package listings.
\begin{lstlisting}
...
\end{lstlisting}
For example
\begin{lstlisting}[language=matlab,basicstyle=\ttfamily,frame=single]
for i = 1 : 10
x(i) = i;
end
\end{lstlisting}
produces
for i = 1 : 10
x(i) = i;
end

If you have a file containing the code you want to include in your document then this can be included in
your document using
\lstinputlisting{myfile.m}
This is particularly useful if you are still making changes to the code.

2.8 Sectioning
LATEX provides an easy way to structure a document using sections/chapters. A typical document will
have at most three levels of sectioning with sections, subsections and subsubsections being nested within
each other. A new section can be started using the command

Division of Mathematics & Computation 9 Manchester Metropolitan University


A Beginner’s Guide to LATEX 2.9 Table of contents

\section[short name]{section name}


where section name is the section heading that appears in the document and short name is an optional
field that can be used to provide a shortened section heading for use in the table of contents (see
section 2.9). If a document uses the book class then new chapters can be started using the command

\chapter[short name]{chapter name}


For example,

\section{Section heading}
This section’s content ...

\subsection{Subsection heading}
This subsection’s content ...

\subsubsection{Subsubsection heading}
This subsubsection’s content ...

produces

1 Section heading
This section’s content ...

1.1 Subsection heading


This subsection’s content ...

1.1.1 Subsubsection heading


This subsubsection’s content ...

Note that the section numbering is automatically included in the output. If you do not want the section
numbering to appear in the document, replace the section command with section*.

2.9 Table of contents


A table of contents can be included in a document using the command \tableofcontents at the point
where you want it to appear (usually after the abstract). The table of contents will include all automatically
numbered headings specified using the sectioning commands.
For example, generating a table of contents using the sections defined in section 2.8 will give the
output shown below:

1 Section heading 1
1.1 Subsection heading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.1 Subsubsection heading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Similar commands exist for generating list of figures and lists of tables, these are: \listoffigures and
\listoftables respectively.

Division of Mathematics & Computation 10 Manchester Metropolitan University


A Beginner’s Guide to LATEX

3 Typesetting equations
There are two main types of equations in LATEX: inline equations that appear along side normal text and
display equations that appear on their own line centered on the page. To write an inline equation, we
enclose the equation between \( and \). For example,
The roots of a quadratic polynomial of the form \( 0 = ax^2 + bx + c \) can be
calculated using the quadratic formula.
produces

The roots of a quadratic polynomial of the form 0 = ax2 + bx + c can be calculated using the
quadratic formula.

To write a display equation, we enclose the equation between \[ and \]. For example, the source:
The quadratic formula is \[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \]
produces

The quadratic formula is √


−b ± b2 − 4ac
x=
2a

To write a numbered equation, we use the equation environment. For example


The quadratic formula is
\begin{equation}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.
\end{equation}
produces

The quadratic formula is √


−b ± b2 − 4ac
x= . (1)
2a

Note that the equation number has been added to the right of the equation as is standard practice (or
to the left if the fleqno option was used in the \documentclass command). LATEX will automatically
increment the equation numbers when you include more equations in your document.

3.1 Aligned equations


To typeset multiline equations we can use the align environment which is available as part of the amsmath
package. As with matrices and tables, a double backslash \\ is used to specify a line break and an
ampersand & is used to set the point at which the lines should be aligned, for example,
\begin{align}
f(x) &= (x+a)(x+b) \\
&= x^2 + (a+b)x + ab
\end{align}
produces

f (x) = (x + a)(x + b) (2)


2
= x + (a + b)x + ab (3)

Note that each line of the multiline equation has an equation number appended to the right. To suppress
this for an individual line we can use the \notag command on the line that we do not want the equation
number to appear, for example,

Division of Mathematics & Computation 11 Manchester Metropolitan University


A Beginner’s Guide to LATEX 3.2 Symbols

\begin{align}
\notag f(x) &= (x+a)(x+b) \\
&= x^2 + (a+b)x + ab
\end{align}

produces

f (x) = (x + a)(x + b)
= x2 + (a + b)x + ab (4)

To suppress all equation numbers, use the align* environment, for example,

\begin{align*}
f(x) &= (x+a)(x+b) \\
&= x^2 + (a+b)x + ab
\end{align*}

produces

f (x) = (x + a)(x + b)
= x2 + (a + b)x + ab

3.2 Symbols
Mathematical symbols are entered either directly from the keyboard (only +, −, =, !, /, (, ), [, ], <, >, |,
0
and : can be accessed in this way) or by using the appropriate LATEX command. A list of some of the
more common mathematical symbols is given below

× \times ÷ \div ± \pm · \cdot


◦ \circ 0 \prime ∞ \infty ¬ \neg
∧ \wedge ∨ \vee ∪ \cup ∩ \cap
∀ \forall ∃ \exists ∈ \in ∈
/ \notin
⊂ \subset ⊃ \supset → \rightarrow ← \leftarrow
↔ \leftrightarrow ⇒ \Rightarrow ⇐ \Leftarrow ⇔ \Leftrightarrow
ȧ \dot{a} â \hat{a} ā \bar{a} ã \tilde{a}
6= \neq ≥ \geq ≤ \leq ∼ \sim
.. ..
... \ldots ··· \cdots . \vdots . \ddots

For example

\[ (\forall p, \exists q)[ \neg (p \rightarrow q)] \]

produces

(∀p, ∃q)[¬(p → q)]

3.3 Superscripts and subscripts


Superscripts and subscripts are produced by the special characters ^ (a caret) and _ (an underscore)
respectively. If more than one character is required in the super/subscript, they should be grouped using
curly brackets. For example,

Division of Mathematics & Computation 12 Manchester Metropolitan University


3.4 Fractions A Beginner’s Guide to LATEX

\[ z_{n+1} = z_n^2 + c \]

produces

zn+1 = zn2 + c

3.4 Fractions
A fraction can be specified using the \frac{numerator}{denominator} command. The size of the
fraction will depend on whether it appears in an inline or display equation. For example

The fraction \( \frac{a}{b} \) appears in an inline equation and is smaller whilst the
following fraction appears in a display equation and is larger \[ \frac{a}{b}. \]

produces

The fraction ab appears in an inline equation and is smaller whilst the following fraction appears in
a display equation and is larger
a
.
b

If you want to control whether an inline or display fraction is used, the commands \tfrac and \dfrac
specify and inline or display fraction respectively.

3.5 Brackets
Brackets can be entered directly from the keyboard with the exception of curly brackets that use the
commands \{ and \}. Brackets surrounding an expression can be automatically sized to match the
vertical height of the expression using \left and \right commands immediately preceding the bracket
command. For example

\[ \left( \frac{a}{b} \right) \]

produces
a
b

Note that both \left and \right must be used else LATEX will return an error. If you only require a
bracket on one side of an expression, an empty bracket can be specified using a full-stop symbol. For
example

\[ \left. \frac{dy}{dx} \right|_{x=1} \]

produces

dy
dx x=1

3.6 Operators
Mathematical operators can be entered using the appropriate command. Some operators require an
argument that is placed in curly brackets. For certain operators such as summations and limits, the
superscript and subscripts are placed underneath and above the operators respectively. Below is a list of
some common operators:

Division of Mathematics & Computation 13 Manchester Metropolitan University


A Beginner’s Guide to LATEX 3.7 Greek characters

√ √
a \sqrt{a} n
a \sqrt[n]{a} exp \exp log \log

ln \ln sin \sin cos \cos tan \tan


b
X b
Y Z b
lim \lim_{a} \sum_{a}^{b} \prod_{a}^{b} \int_{a}^{b}
a a
ZZ Ia a

\iint \oint ∂ \partial ∇ \nabla

3.7 Greek characters


Greek characters can be added to an equation by writing the character name after a \. If the first letter
of the character name is lowercase, then LATEX will use a lowercase Greek character, else if the first letter
is uppercase then the uppercase character is produced. Remember that some uppercase Greek characters
are the same as their latin equivalents (e.g., uppercase α is A) and can be entered directly from the
keyboard. For example,
\( \alpha, A, \beta, B, \gamma, \Gamma, \delta, \Delta \)
produces

α, A, β, B, γ, Γ, δ, ∆

3.8 Matrices
To typeset a matrix, use either the matrix, pmatrix, bmatrix or vmatrix environments depending on
the type of parenthesis required (none, rounded brackets, square brackets and vertical lines respectively).
As with tables, \\ specifies a line break and & specifies a column break, e.g.,
\[ A = \begin{pmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{pmatrix} \]
produces
 
1 2 3
A = 4 5 6
7 8 9

3.9 Piecewise functions


A piecewise function where the output of a function depends on certain criteria can be specified using the
cases environment. This effectively defines a 2 × 2 matrix with a stretchy opening curly bracket. For
example
\[ f(x) =
\begin{cases}
\sin(x) & x \leq \frac{\pi}{2}, \\
\cos(x) & \text{otherwise}
\end{cases} \]
produces
(
sin(x) x ≤ π2 ,
f (x) =
cos(x) otherwise

Division of Mathematics & Computation 14 Manchester Metropolitan University


3.10 Text in equations A Beginner’s Guide to LATEX

3.10 Text in equations


Text in equations can be specified using the \text{...} command. Text added in this way will be
treated as standard text by LATEX and will not be italicised. For example

\[ E_{\text{kinectic}} = \frac{1}{2}mv^2 \text{ Joules} \]


produces

1
Ekinectic = mv 2 Joules
2

Division of Mathematics & Computation 15 Manchester Metropolitan University


A Beginner’s Guide to LATEX

4 Figures & tables


Figures and tables are specified using the figure and table environments respectively. Figures and
tables are separate from normal text and do not necessarily appear where they are defined in the source
file and float around the document. If there is not enough room for the figure or table on the current
page, LATEX will position them in the next available page. Therefore, it is important that figures and
tables are captioned and cross-referenced in the text (see section 5.2).
To insert a figure or table into a document the commands are
\begin{figure}[placement]
...
\end{figure}
or
\begin{table}[placement]
...
\end{table}
The placement option seen above gives the author a degree of control over where the figure is placed in
the document. Placement options include:
Positions the figure ‘here’ or at approximately the location corre-
h
sponding closest to the source text
t Positions the figure at the ‘top’ of the page
b Positions the figure at the ‘bottom’ of the page
p Positions the figure on a special ‘page’ for figures and tables only
For example, using the placement option [htb], LATEX will first attempt to place the figure where it
appears in the source text, if this is not possible it will attempt to place it at the top of the page, if this
is not possible it will attempt to place it at the bottom of the page, if it is not possible to place it on the
current page it will place it on the next available page.

4.1 Importing graphics


The majority of figures will involve importing an image file into a LATEX document. This is achieved using
the includegraphics command that requires the graphicx package to be installed in the preamble.
\includegraphics[options]{filename}
The options available are:
width=x Specify the width of the imported image to x
height=y Specify the height of the imported image to y
scale=x Scales the image by the scaling factor x
angle=x Rotates the image anti-clockwise by x degrees
The filename should include folder names if the image file is not in the same directory as the text file.
For example, if the image file myimage.png is contained within the directory Images then the filename
would be Images/myimage.png.

4.1.1 Supported image files


LATEX supports JPEQ, PNG, PDF and EPS file formats. JPEG (*.jpg) are the best form to use if the
image is a photograph or a picture. If the image is a diagram, computer generated plot (e.g., a MATLAB
plot) or a screenshot, the PNG (*.png) format is the best format to use.
To export a MATLAB plot as a PNG file do the following:
1. Click on the MATLAB figure window
2. Select ‘File’ and ‘Save As’ from the menu
3. Choose ‘Portable Network Graphics file *.png’ from the ‘Save file as:’ drop down menu
4. Enter a filename in the ‘Save As’ field and click ‘ok’

Division of Mathematics & Computation 16 Manchester Metropolitan University


4.2 Captions A Beginner’s Guide to LATEX

4.2 Captions
Figure and table captions should can be specified using the \caption{...} command. The caption will
appear above or below the figure/table depending on where the caption command is used relative to the
commands used to construct the figure/table. Figure captions should appear below the figure, therefore
the caption command should be used after the \includegraphics command. Table captions usually
appear above a table and therefore the command should be used before the tabular environment (see
section 4.3). For example the source

\begin{figure}[htb]
\centering
\includegraphics[width=0.6\textwidth]{Images/mandelbrot.png}
\caption{The Mandelbrot set}
\label{fig:mandelbrot set}
\end{figure}

produces

Figure 1: The Mandelbrot set

Note that the figure has been centred on the page using the \centering command. The image file
mandelbrot.png is contained within the Images directory and has been scaled so that its width is 0.6
times that of the width used for the text in the document. LATEX automatically appends a figure number
to the caption depending on how many figures have been defined previously. The figure caption will also
appear in the list of figures if the \listoffigures command has been used.

4.3 Constructing tables


A table can be constructed using the tabular environment.

\begin{tabular}{columns}
...
\end{tabular}

where the columns argument is used to specify the number of columns and the horizontal alignment of
each of the columns using the following:

l left-justified column
c centred column
r right-justified column
| vertical line
|| double vertical line

Division of Mathematics & Computation 17 Manchester Metropolitan University


A Beginner’s Guide to LATEX 4.3 Constructing tables

Text in the rows and columns of a table are separated by & and \\ respectively. Horizontal lines that
span the width of the table can be inserted using the \hline command. For example, the source
\begin{table}[htb]
\centering
\caption{A simple table}
\label{tab:simple table}
\begin{tabular}{| l | c | r |}
\hline \hline
\(x\) & \(x^2\) & \(x^3\) \\
\hline
2 & 4 & 8 \\
4 & 16 & 64 \\
6 & 36 & 216 \\
8 & 64 & 512 \\
10 & 100 & 1000 \\
\hline \hline
\end{tabular}
\end{table}
produces

Table 1: A simple table


x x2 x3
2 4 8
4 16 64
6 36 216
8 64 512
10 100 1000

Division of Mathematics & Computation 18 Manchester Metropolitan University


A Beginner’s Guide to LATEX

5 Referencing
One of the main benefits of using LATEX over other word processing programs is that it is very easy to
insert references citing a source and use cross-referencing within a document.

5.1 Referencing sources


To reference a source, LATEX requires you to do three things:
• produce a database containing all of the information for the sources cited in the document (see
section 5.1.2);
• insert a citation to the source in the document (see section 5.1.5);
• insert a bibliography and provide LATEX with the filename of the bib file (see section 5.1.6)
LATEX uses a tool called Bibtex to handle the citation of sources and to produce the list of references in
the bibliography. BibTeX can be called from the command line, however, most dedicated LATEX editors
will have a built in macro to call BibTeX. Compiling a LATEX document with BibTeX is requires multiple
passes to generate the references in your document. Each pass will perform a particular task until it has
managed to resolve all of the citation references:
1. Run LATEX on the tex file – this will typeset most of the document and produce an auxiliary
file with the extension *.aux. This auxiliary file contains information on all of the citations and
cross-references in the document.
2. Run BibTeX on the tex file – this will link the citations in the AUX file with the source list in the
bib file
3. Run LATEX again on the tex file – this will insert the citations and references into the document.
4. Run LATEX one last time – this will resolve the cross references.
Note that online editors such as overleaf and sharelatex will perform the multiple passes of LATEX and
BibTeX necessary to insert the references automatically.

5.1.1 The biblatex package


The biblatex package provides many features that allow authors to customise the way that references are
displayed in their document. To use the Harvard method of referencing (this is the university’s preferred
method), the following should be added to the preamble

\usepackage[backend=bibtex,citestyle=authoryear,bibstyle=authoryear,natbib]{biblatex}
\addbibresource{references}

Note that this assumes that the bib file (section 5.1.2) has the filename references.bib.

5.1.2 The bib file


To insert a reference you need to provide LATEX with the citation information regarding the source (author,
title, year etc.). This is done using another text file with the extension *.bib hereafter known as a ‘bib
file’. The bib file is a database that contains information on all of the sources cited in the tex file and
should be saved in the same directory as the tex file. Each source listed in the bib file is given a type of
source and mandatory information about the source. Depending on the type of source, an entry in the
bib file takes the form
@type{refkey,
author = "author name",
title = "title",
year = "year",
...
}
The keywords used here are explained below:

Division of Mathematics & Computation 19 Manchester Metropolitan University


A Beginner’s Guide to LATEX 5.1 Referencing sources

type Specifies the type of the source being cited (see section 5.1.3 for
information about the various types of sources.
@refkey A unique text string used by LATEX to identify the source. A
common method of generating the refkey is to combine the first
author’s name with the year of publication, e.g., bloggs:2013.
author name The names of the author’s are listed here using the keyword and to
separate each author. Author’s names should take the form other,
a.n. where the surname is given first followed by a comma with
the initials separated by a fullstop.
title The title of the source.
year The year the source was first published.

5.1.3 Standard templates


Some of the standard bib file templates are listed below

• @article – a journal or magazine article

– Required fields: author, title, journal, year


– Optional fields: volume, number, pages, month, note

• @book – a published book

– Required fields: author/editor, title, publisher, year


– Optional fields: volume/number, series, address, edition, month, note

• @online – webpage

– Required fields: author, title, year, url


– Optional fields: subtitle, language, version, note, organization, date, month, year, urldate

• @thesis – a thesis written to satisfy the requirements of a degree

– Required fields: author, title, type, institution, year/date


– Optional fields: subtitle, location, chapter, pages

• @inproceedings – an article in a conference proceedings

– Required fields: author, title, booktitle, year


– Optional fields: editor, volume/number, series, pages, address, month, organization, publisher,
note

Examples of bib file entries are given below

@book{higham:1994,
author = {Higham, N.},
title = {Handbook of Writing for the Mathematical Sciences},
publisher = {SIAM},
year = {1994}
}

@article{shiach:2005,
author = {Shiach, J.B. and Mingham, C.G.},
title = {A temporally second-order accurate Godunov-type scheme for solving the
extended Boussinesq equations},
journal = {Coastal Engineering},
year = {2009},
volume = {56},
pages = {32 -- 45}
}

Division of Mathematics & Computation 20 Manchester Metropolitan University


5.1 Referencing sources A Beginner’s Guide to LATEX

5.1.4 Web pages


Referencing web pages can be done using the @online template. In addition to the standard citation
information, it is necessary to provide the URL for the webpage and the date that it was accessed. This is
because webpages can be altered subsequent to you reading them and in providing a date that you access
the webpage you are showing that the information was accurate at the time of reading. An example of a
bib file entry using the @online template is given below.
@online{wikibooks:2013,
author = {Wikibooks},
title = {\LaTeX --- Wikibooks{,} The Free Textbook Project},
year = {2013},
url = {https://en.wikibooks.org/wiki/LaTeX},
note = {[Online; accessed 10 September 2013]}
}

5.1.5 Citations
Where you want a citation to be inserted, use a variation of the \cite command depending on the type
of citation given in the list below.
Citation command Format
\citet{refkey} name (year)
\citep{refkey} (name, year)
\citeauthor{refkey} name
\citeyear{refkey} year
\citeyearpar{refkey} (year)
For example, the source
An excellent guide for writing mathematical documents was written by
\citet{higham:1994}.
produces (provided the bib file entry from section 5.1.3 was included in the bib file)

An excellent guide for writing mathematical documents was written by Higham (1994).

If you don’t want the author’s name to be included in the sentence use the \citep{...} command. For
example,
An excellent guide for writing mathematical documents is ‘Handbook of writing for the
mathematical sciences’ \citep{higham:1994}.
produces

An excellent guide for writing mathematical documents is ‘Handbook of writing for the mathematical
sciences’ (Higham, 1994).

5.1.6 Bibliography
In order for sources to be cited in a LATEX document it is necessary to insert a bibliography using the
following commands
\setlength\bibitemsep{2\itemsep}
\printbibliography
These commands will insert a new section titled ‘References’ that contains a list of all of the references
cited in the document using a Harvard style format, for example

References
N.J. Higham. (1994). Handbook of writing for the mathematical sciences. SIAM.

Division of Mathematics & Computation 21 Manchester Metropolitan University


A Beginner’s Guide to LATEX 5.2 Cross referencing

5.2 Cross referencing


To cross-reference any numbered item in a document, e.g., equations, figures, tables, sections etc., you
must first mark it with a label using the \label command:

\label{marker}
where marker is a unique text string for the item. Once a numbered item has been marked, cross-
referencing is achieved using the \ref command:
\ref{marker}

This will insert the item number into the document. The page where the item appears in the document
can be determined using the \pageref command:
\pageref{marker}
For example, the source

The image in fig.~\ref{fig:mandlebrot set} on page~\pageref{fig:mandelbrot set}


is of the Mandelbrot set.
produces

The image in fig. 1 on page 17 is of the Mandelbrot set.

A useful package for cross-referencing is the cleveref package which can automatically append the
type of item that is being cross-referenced to the item number (e.g., fig., table., section etc.). First include
the package in your preamble using
\usepackage{cleveref}

and then use \cref to cross-reference. For example,


The image in \cref{fig:mandlebrot set} on page~\pageref{fig:mandelbrot set}
is of the Mandelbrot set.

The image in fig. 1 on page 17 is of the Mandelbrot set.

5.2.1 Markers
There is no restriction to the text used for the marker in the label command as long as it does not
contain special LATEX characters. However, since documents can contain hundreds of markers, it is good
practice to have a marking convention in order to avoid duplication. A common convention is to use a
shorthand prefix, for example
chap: chapter
sec: section
fig: figure
tab: table
eq: equation
itm: enumerated list item
For example, the image of the Mandelbrot set in fig. 1 had the marker fig:mandelbrot set.

Division of Mathematics & Computation 22 Manchester Metropolitan University


References A Beginner’s Guide to LATEX

References
Higham, N. (1994). Handbook of Writing for the Mathematical Sciences. SIAM.
Unknown (2013). Text formatting with LATEX. [Online; accessed 10 September 2013]. Economics Graduate
Student Association, University of North Carolina. url: http://www.unc.edu/depts/econ/egsa/
LaTeX.pdf.

Wikibooks (2013). LATEX— Wikibooks, The Free Textbook Project. [Online; accessed 10 September 2013].
url: https://en.wikibooks.org/wiki/LaTeX.

A Article template
Below is a template for an article using some common packages. You can copy and paste this into a new
tex file to begin creating a LATEX document.
\documentclass[a4paper,twoside,11pt]{article}

% packages
\usepackage[margin=2.54cm]{geometry}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[backend=bibtex,citestyle=authoryear,bibstyle=authoryear,natbib]{biblatex}
\addbibresource{references}
\usepackage{tikz}
\usetikzlibrary{arrows,patterns,calc,matrix}
\usepackage{caption}
\captionsetup[table]{skip=2pt}
\usepackage{placeins}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[protrusion=true,expansion=true]{microtype}
\usepackage{cleveref}
\usepackage{hyperref}

% top matter
\title{Your title}
\author{Your name}

% document
\begin{document}

% title
\maketitle

% document text
...

% bibliography
\setlength\bibitemsep{2\itemsep}
\printbibliography

\end{document}

Division of Mathematics & Computation 23 Manchester Metropolitan University

You might also like