Making Math Pretty – or How to Use LaTeX - Iowa State University

Making Math Look Pretty
– or How to Use LaTeX
Kristi Meyer
Iowa State University
[email protected]
Basics of LaTeX
пЃ®
пЃ®
пЃ®
пЃ®
A computer program for typesetting text and
mathematical formulas
Uses commands to create mathematical
symbols
Not a WYSIWYG program
Need to compile the file in order to see the
finished product
Basics of LaTeX – Commands
пЃ®
пЃ®
пЃ®
пЃ®
Always begin with a backslash \
Case sensitive
Consist of letters only
Some have parameters
пЃ®
пЃ®
Square brackets [ ] after the command name are
for optional parameters
Curly braces { } after the command name are for
required parameters
Getting Started
пЃ®
пЃ®
пЃ®
Can use lots of different programs to create a
LaTeX file
All computers here use WinEdt
Need to begin by creating a new file
Input File Structure
пЃ®
Begins with a preamble
пЃ®
\documentclass[options]{class}
пЃ®
class specifies the type of document to be created
пЃ®
пЃ®
пЃ®
Usually use article or amsart
Can also use slides or siamltex
options customizes the document class you are
using
пЃ®
пЃ®
Can be used to set font size (10, 11, or 12 pt), set
paper size, use one or two columns, etc.
See Getting Started with LaTeX, pgs. 12 – 13, for
more information
Input File Structure
пЃ®
Begins with a preamble
пЃ®
\usepackage{package}
пЃ®
пЃ®
пЃ®
Packages add new features and commands to LaTeX
Common packages: amsmath, amssymb, graphics
Can also define new commands in the preamble,
specify page numbering, etc.
Input File Structure
пЃ®
пЃ®
Now we’re ready to begin the body of the text
\begin{document}
пЃ®
пЃ®
пЃ®
\begin{…} commands always need to be followed
(eventually) by \end{…} commands
Enter the actual content here
\end{document}
Typesetting Your Document
пЃ®
пЃ®
Click the “LaTeX” or “PDF LaTeX” button
on the top right
To view your file, click “DVI” or the Adobe
Acrobat symbol
пЃ®
пЃ®
пЃ®
DVI stands for “device independent” – it’s
basically a generic viewer
Can change between DVI, PDF, or PS files
Document is automatically saved when you
typeset it
Types of LaTeX Files
пЃ®
пЃ®
пЃ®
пЃ®
.tex – input file, needs to be compiled
.dvi – DVI file, shows what your file looks
like
.tex.bak – backup LaTeX file, is changed
when document is typeset
.log – log file, tells what happened the last
time you compiled your document
пЃ®
Helpful to look at if there are errors and you don’t
know why
Sections of a Paper
пЃ®
\title[label]{actual title}
пЃ®
пЃ®
пЃ®
\author{authors}
пЃ®
пЃ®
If you label your title, you’ll be able to reference it
later
Can also label theorems, equations, figures, tables,
etc.
Need to put \maketitle after title and authors
\today
пЃ®
пЃ®
Gives the current date
Usually want this centered
Sections of a Paper
пЃ®
\thanks{…}
пЃ®
пЃ®
пЃ®
Abstract
пЃ®
пЃ®
Creates a footnote with whatever is in the braces
Usually used after authors’ names for academic
information
Use \begin{abstract} and \end{abstract}
Keywords
пЃ®
пЃ®
Use \begin{keywords} and \end{keywords}
OR use \keywords{…}
Sections of a Paper
пЃ®
пЃ®
Papers should be divided into sections,
subsections, etc.
Important commands:
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
\section{Title of section}
\subsection{…}
\subsubsection{…}
\paragraph{…}
\subparagraph{…}
Sections of a Paper
пЃ®
Bibliography
пЃ®
\begin{thebibliography}{number} and
\end{thebibliography}
пЃ®
пЃ®
пЃ®
number is 9, 99, 999, etc.
Tells LaTeX how if you will be using only single-digit
numbers, double-digit numbers, etc.
Use \bibitem{label} to create a new reference
пЃ®
label lets you reference that item elsewhere in the paper
Referencing Using Labels
пЃ®
пЃ®
May want to reference a section, theorem,
figure, example, etc. somewhere else in the
document
To label a section:
пЃ®
пЃ®
\section{Title}\label{Label for section}
To reference a section:
пЃ®
пЃ®
\ref{Label for section}
Only gives the section number – you’ll need to
type Section separately
Theorems and Definitions
пЃ®
пЃ®
Can decide what style you want your
theorems, definitions, corollaries, etc.
Two possibilities for numbering:
пЃ®
Theorem 1, Example 1, Theorem 2, Lemma 1, etc.
пЃ®
\theoremstyle{…}
пЃ® \newtheorem{short name}{long name}
пЃ® Short name is what you type
пЃ® Long name is what is displayed on the page
Theorems and Definitions
пЃ®
Two possibilities for numbering:
пЃ®
Theorem 1, Example 2, Lemma 3, Example 4, etc.
пЃ®
пЃ®
For unnumbered theorems, use either
command with \newtheorem*
пЃ®
пЃ®
\newtheorem{shortname}[style]{longname}
* can be used in many environments for
unnumbered items
May need to include the package amsthm in
order to properly display theorems
Environments
пЃ®
пЃ®
пЃ®
Many environments available in TeX
Used to help format parts of your document
Always need \begin{environment name} and
\end{environment name}
Environments
пЃ®
Itemize environment
пЃ®
пЃ®
пЃ®
пЃ®
\begin{itemize} and \end{itemize}
Creates an outline using bullet points
Items within the section are created by \item
Can nest itemize environments within one another
Environments
пЃ®
Enumerate environment
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
\begin{enumerate} and \end{enumerate}
Creates an outline using numbers and letters
Items within the section are created by \item
Can nest enumerate environments within one
another
Centered environment
пЃ®
пЃ®
\begin{center} and \end{center}
To end a line, use \\
Typesetting Math
пЃ®
пЃ®
Mathematical text is placed between $
Math mode is normally displayed inline
пЃ®
пЃ®
To display math mode in a larger font, use
\displaystyle
пЃ®
пЃ®
пЃ®
Can make some expressions look funny
Makes all symbols within $ larger
For text within math mode, use \text{…}
Math mode uses italics and no spaces between
words
Useful Mathematical Commands
пЃ®
Greek letters
пЃ®
пЃ®
пЃ®
$\pi$ for lowercase, $\Pi$ for uppercase
No command for $\Alpha$ - just use A
Fractions
пЃ®
пЃ®
$\frac{numerator}{denominator}$
For a larger fraction, use \displaystyle
Useful Mathematical Commands
пЃ®
Superscripts and Subscripts
пЃ®
пЃ®
пЃ®
$x^2$
$x_2$
Use curly braces to group items together
пЃ®
пЃ®
$x_{i_2}$ or $x_{min}$
Can have a superscript and a subscript on the same
character
пЃ®
$x_i^3$
Useful Mathematical Commands
пЃ®
Limits and Integrals
пЃ®
пЃ®
пЃ®
Probably want to use \displaystyle, otherwise
they’ll look funny
$\displaystyle \lim_{x \to \infty} 3x$
$\displaystyle \int_0^2 x\ dx$
пЃ®
пЃ®
The \ gives a space between x and dx
Lots more commands on pgs. 58 – 65 of
Getting Started with LaTeX
Other Important Characters
пЃ®
Quote marks
пЃ®
пЃ®
пЃ®
For left-hand quote marks, use ``
For right-hand quote marks, use ” or ’’
Comments
пЃ®
Can comment out sections of file
пЃ®
пЃ®
Allows you to not display text without deleting it
Use % at the beginning of any lines you want to
comment out
Defining New Commands
пЃ®
пЃ®
пЃ®
пЃ®
Typing some long commands over and over is
not fun
Can define a new command that’s easier to
type
Goes in preamble
\newcommand{newname}{oldname}
пЃ®
newname cannot be the name of an existing
command
Mathematical Environments
пЃ®
Equation environment
пЃ®
\begin{equation} and \end{equation}
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
Automatically numbers equations
For no numbers, use equation*
Can label equations by \label{name}
Centers equation on page
Do not need $ within equation environment
Mathematical Environments
пЃ®
Align environment
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
пЃ®
\begin{align} and \end{align}
For no numbers, use align*
Put & in front of the symbol in each line that you
want aligned
End each line (except the last one) with \\
Do not need $ within align environment
Proof environment
пЃ®
\begin{proof} and \end{proof}
Arrays
пЃ®
пЃ®
Especially used for matrices
Begin with left symbol for matrix
пЃ®
пЃ®
$\left[
Next, begin array environment
пЃ®
\begin{array}{lrc}
пЃ®
Tells how many columns you have and their alignment
Arrays
пЃ®
Specify the entries of the matrix
пЃ®
пЃ®
пЃ®
End the array
пЃ®
пЃ®
Separate the entries by &
End each row (except the last one) by \\
\end{array}
Create the right side symbol for the matrix
пЃ®
\right]$
Arrays
пЃ®
пЃ®
Can also have lines within arrays
Horizontal lines
пЃ®
пЃ®
пЃ®
Use \hline after each row that you want a line
under
x^2 & 4x & 3 \\ \hline
Vertical lines
пЃ®
пЃ®
Put | between the columns that you want lines
between
\begin{array}{lr|c}
Tables
пЃ®
пЃ®
пЃ®
Basically the same as arrays
\begin{tabular}{lrc} and \end{tabular}
Can add lines in the same way that you do for
arrays
Figures
пЃ®
пЃ®
пЃ®
пЃ®
Often used to import some other type of file
(usually a .ps file) into your document
Can generate graphics in LaTeX, but this is
harder to do
Any imported file needs to be in the same
directory as your main file
Also need to include the package graphicx in
your preamble
Figures
пЃ®
Begin the figure environment by
\begin{figure}[placement]
пЃ®
пЃ®
пЃ®
placement is an optional argument that tells LaTeX
where on the page you want the figure
Can be h (here), t (top), b (bottom), or p (on a
separate page)
Put an ! before the placement if you really want the
figure at that page location
Figures
пЃ®
Include the file that you want
пЃ®
пЃ®
пЃ®
\includegraphics[display]{filename}
display is an optional parameter which allows you
to change the appearance of your graphic
Can use the following parameters:
пЃ®
пЃ®
width, height, angle (rotates the graphic
counterclockwise), scale (number between 0 and 1)
Changing width or height will preserve the aspect ratio
Figures
пЃ®
Can create a caption for your figure
пЃ®
\caption[shortname]{longname}
пЃ®
пЃ®
пЃ®
пЃ®
shortname is displayed in the Table of Contents (if you
create one)
longname is displayed below the figure
Captioning also automatically labels your figures
Can label your figure
пЃ®
пЃ®
\label{reference}
Allows you to refer to your figure later by using
\ref{reference}
Figures
пЃ®
End the figure environment
пЃ®
пЃ®
\end{figure}
May sometimes need to create a PostScript file
instead of a PDF file in order to get graphics to
display properly