0% found this document useful (0 votes)
47 views14 pages

Latex Primer 2

This document is a LaTeX primer created by Thomas Wong to teach LaTeX. It covers the basic structure of a LaTeX document, including the preamble, packages, and document sections. It also provides examples and explanations of common text formatting, mathematical notation, equations, tables, lists and other elements in LaTeX. The primer is intended as a reference for anyone wanting to learn LaTeX.
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)
47 views14 pages

Latex Primer 2

This document is a LaTeX primer created by Thomas Wong to teach LaTeX. It covers the basic structure of a LaTeX document, including the preamble, packages, and document sections. It also provides examples and explanations of common text formatting, mathematical notation, equations, tables, lists and other elements in LaTeX. The primer is intended as a reference for anyone wanting to learn LaTeX.
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/ 14

LATEX Primer Thomas Wong

Last Updated: April 19, 2017.

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 Some Online TEX Editors


There are many online TEX editors available, the one I use is:

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:

1. Save often. Compile often.

2. Proof read often.

3. When stuck, check examples (here and on the web).

4. Talk to other people about it.

3 The Structure of LATEX


I guess a good starting point for understanding LATEX is to understand what a document looks
like.

Example 1. Sample Document


The start of this primer might look something like:

\documentclass[12pt]{article} %All documents start with this

% This is called the preamble. It sets up the format of the document.


% It includes author information, dates, formatting etc.
% If we require any additional formatting etc, we can import ‘packages’.
% This will give us more customability.

% For exmaple: ams* packages gives us a range of symbols etc.


\usepackage{amsmath, amsthm,amsfonts,amssymb}

% fancyhdr is a package that deals with headers and footers.


\usepackage{fancyhdr}
\setlength{\headheight}{15pt}
\pagestyle{fancyplain}

% Header and Footer content


\lhead{\today}
\chead{\LaTeX{} Primer}
\rhead{Thomas Wong}
\lfoot{}
\cfoot{}
\rfoot{}

% Preamble ends here


\begin{document}
% This is where the content starts, after this line.
LATEX Primer Thomas Wong

This is the start of a \LaTeX primer....


% Write all the content here, before this line.
\end{document}

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:

Example 2. New lines:


What you type: What you see:
Line break here.\\New line. Line break here.
New line.
We may also want to use Bold or Italics or alter the font size. Note the use of curly brackets,
these will be very useful in Latex.

Example 3. Bold and Italics:


What you type: What you see:
{\bf Bold stuff} Bold stuff.
{\it More stuff} More stuff.
Example 4. Font size:
What you type: What you see:
{\huge Some text}. Some text.
{\Large Some text}. Some text.
{\large Some text}. Some text.
Some text. Some text.
{\small Some text}. Some text.
{\footnotesize Some text}. Some text.
{\scriptsize Some text}. Some text.

While in text mode, we can also adjust the spacing quite easily. Some common spacing
commands:
LATEX Primer Thomas Wong

1. ‘\vspace{5cm}’ will leave a vertical gap of 5cm on the page.

2. ‘\noindent’ at the beginning of a paragraph will remove the indent found at the start of
a paragraph.

3. ’\newpage’ will begin a new page.

In addition, there are some changes to punctuating in Latex.

1. Quotation marks can be written using the grave accent and the apostrophe symbols ‘ ’.

2. Double quotation marks can be written using the above ‘‘ ’’

3. Dollar signs can be written using \$

4. Backslashes can be written using $\backslash$

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.

It will not show up in the document when you compile.

5 Math As Part Of A Sentence.


One of the biggest advantages of Latex is that it handles mathematical writing very well. As
you may have noticed at the end of the previous section, some commands are enclosed by $.
The dollar sign is used to enclose commands used in mathematics mode. If you want to include
a small snippet of mathematics in your writing, we can enclose it with $. For example:

Example 6. Writing Math:

We want to find the limit of $f(x)$ as $x$ approaches $3$.

will be displayed

We want to find the limit of f (x) as x approaches 3.

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 7. Curly Brackets:


LATEX Primer Thomas Wong

What you type: What you see:


x^23 x2 3.
x^(23) x( 23).
x^{23} x23
x^{(23)} x(23) .
Some common formatting in math mode include:

1. Subscripts are written as x_i and displayed as xi .

2. Superscripts are written as x^2 and displayed as x2 .


f (x)
3. Fractions are written as \frac{f(x)}{g(x)} and displayed as g(x)
.

4. Curly brackets are written as \{ \}.

5. Greater/Less than or equal to symbols: \geq and \leq respectively

For a list of common mathematics commands, refer to Section 12

6 One line of Math, (Equation).


We will frequently want to write an equation that might be more complicated. For this case,
we will need something known as an environment. Think of an environment as defining a space
where we can do more specialised tasks. Environments are always called using the following
code

Example 8. Environments:

\begin{environment we want}
Stuff we want to to
\end{environment we want}

In our case, we want the equation environment.

Example 9. Equation Environment:

\begin{equation}
f(x) = \frac{1}{1+\frac{1}{1+\frac{1}{1+\frac{1}{1+x}}}}
\end{equation}

will be displayed as:


1
f (x) = 1 (1)
1+ 1+ 1
1
1+ 1+x

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.

Example 11. No Numbering:

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

which will look a little strange.


t+2 1
g(t) = ()( ) (2)
t−3 t
We can get around that using \left and \right with our brackets. Note that each \left
has to be paired with a \right.

Example 12. Bracketing:

\begin{equation}
g(t) = \left(\frac{t+2}{t-3}\right)\left(\frac{1}{t}\right)
\end{equation}

which will look like:   


t+2 1
g(t) = (3)
t−3 t
LATEX Primer Thomas Wong

7 Multiple lines of Math, (Align).


In many cases, we want to write a series of equations one after another. We can accomplish
this nicely using the align environment. Like the equation environment, everything that works
in math mode will work in the align environment. Before we start, be aware of Example 10.
Example 13. Align Environment:
\begin{align}
f(x) &= \frac{x^3-2x^2-11x+12}{x^2-5x+4} \\
&= \frac{(x-1)(x^2-x-12)}{(x-1)(x-4)} \\
&= \frac{(x-1)(x+3)(x-4)}{(x-1)(x-4)} \\
&= x+3
\end{align}
will be displayed as:
x3 − 2x2 − 11x + 12
f (x) = (4)
x2 − 5x + 4
(x − 1)(x2 − x − 12)
= (5)
(x − 1)(x − 4)
(x − 1)(x + 3)(x − 4)
= (6)
(x − 1)(x − 4)
=x+3 (7)
Important note: the ampersand symbol (&), is used in align as a “tab” and keeps the
rows aligned. The double backslash (\\) works just like in normal text to denote a new line.
We can get fancy with the align environment by adding a second ampersand symbol to
comment on the various lines. The asterisks can also be used to omit the equation numbering.
Example 14. Text in Math Mode:
\begin{align*}
f(x) &= \frac{x^3-2x^2-11x+12}{x^2-5x+4} & {}\\
&= \frac{(x-1)(x^2-x-12)}{(x-1)(x-4)} & {Factoring}\\
&= \frac{(x-1)(x+3)(x-4)}{(x-1)(x-4)} & {\rm Factoring} \\
&= x+3 &{}
\end{align*}
will be displayed as:
x3 − 2x2 − 11x + 12
f (x) =
x2 − 5x + 4
(x − 1)(x2 − x − 12)
= F actoring
(x − 1)(x − 4)
(x − 1)(x + 3)(x − 4)
= Factoring
(x − 1)(x − 4)
=x+3
LATEX Primer Thomas Wong

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}

will give us:


Left Justified Left Justified Center Justified Right Justified
Cell Cell Cell Cell
1
x t

9 Lists, Piecewise functions.


There is a incredible large number of environments contained in Latex to do various things.
Here I will cover just a couple that will probably come up the most:

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

10 Pictures, Plots, Graphs, etc.


Inserting pictures and diagrams in Latex is relatively easy if you have registered with any of
the above sites. This is because we need the picture file to the in the same folder as the Latex
file you are writing.
Suppose you want to include a picture with the name picture.jpg. First, copy the picture
into the same folder as your Latex file. Then copy the following code into your Latex.

Example 18. Pictures:

\begin{figure}[htbp]
\centering
\includegraphics[width=1.00\textwidth]{picture.jpg}
\end{figure}

What the various bits mean:

1. figure is the name of the environment.

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.

3. \centering will make the picture center justified.

4. width=1.00\textwidth adjusts the width of the picture as a fraction of the width of the
text.

10.1 Online Graphing Calculators


If we have to deal with graphs and plots in Latex, we can always draw them by hand on the
final print out or scan them and then insert them as pictures. An alternative is to use an online
graphing calculator to do the plots and then import those pictures (either save or as a screen
shot). These are a couple of online graphing websites I have used in the past, but I’m sure
many others exist

1. https://www.desmos.com/ (Has amazing animations as well)

2. http://www.meta-calculator.com/online/

3. http://fooplot.com/

11 Miscellaneous and Other Cool Stuff.


There are other advantages of using Latex that might not be directly relevant to what we will
be doing or using in our course. But I feel that it would be cool to include it nonetheless.
LATEX Primer Thomas Wong

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.

11.2 Short hands


Suppose that you have a question that requires the use of a lot of derivatives. We could write
\frac{d}{dx} every time, but that would be time consuming and quite silly. We could be
smart and define a shorthand in the form of \newcommand{ddx}{\frac{d}{dx}} in the pre-
amble (the mess at the start of the document). After that, we can simply write \ddx in the
document to get our derivative. Now suppose we want to get really fancy and want to do
second derivatives, or derivatives with different variables. This is also easily accomplished:
1. To get higher order derivatives, put

\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).

2. To get derivatives with other variables, put

\newcommand{dd}[1]{\frac{d}{d #1}}

in the pre-amble and write \dd{t} for a derivative with respect to t.

3. Combining the above two, put

\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

12 Common Mathematical Commands and Symbols.


In this section, I have just put together a list of the more common mathematical notations
that we will be using throughout the course. This list is by no mean exhaustive. Most of these
commands will require math mode. Ie. $, or equation, or align.

12.1 Symbols and Formatting


What you want: What you should write: What you see:
Integers, Natural numbers \mathbb{Z}, \mathbb{N} Z, N
Rational, Real numbers \mathbb{Q}, \mathbb{R} Q, R
“is in” \in ∈
Infinity \infty ∞
Greek letters \alpha, \beta, \gamma α, β, γ
More Greek \Delta, \pi ∆, π
Subscripts,Indices x_i xi
Superscripts,Powers x^k xk
x
Fractions \frac{x}{y} y
Not equals \neq 6=
Greater than or equal to \geq ≥
Less than or equal to \leq ≤
Plus/Minus \pm ±
n
Binomials \binom{n}{k} b
LATEX Primer Thomas Wong

12.2 Functions and Calculus


What you want: What you should write: What you see:
A function f(x) f (x)
Compositions (f \circ g)(x) (f ◦ g)(x)

Square roots \sqrt{x} x

n-th roots \sqrt[n]{x} n
x
Sine \sin(x) sin(x)
Cosine \cos(x) cos(x)
Tangent \tan(x) tan(x)
Exponents \exp(x) exp(x)
Logs \log_a(x) or \ln(x) loga (x) or ln(x).
Right arrow \rightarrow →
Double right arrow \Rightarrow ⇒
Function maps \mapsto 7→
Limits \lim_{x\rightarrow 5} lim
x→5
\lim_{x\rightarrow\infty} lim
x→∞
d
Derivatives \frac{{\rm d}}{{\rm d}x} dx
d2
(Higher Orders) \frac{{\rm d}^2}{{\rm d}x^2} dx2
X n
Summation \sum_{i=0}^{n}
Zi=02
Integration \int_{-3}^{2}
−3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy