Tutorials‎ > ‎

Introduction

What is LaTeX?
LaTeX, pronounced “la-tek,” is a text formatter. Unlike word processors like Microsoft Word, LaTeX is not a “what you see is what you get” editor. Instead, the user writes LaTeX code representing the content and desired formatting. LaTeX then compiles this code to produce a formatted document. The typical writing and editing cycle with LaTeX is

1. Write LaTeX code
2. Compile
3. View output
4. Return to Step 1 for editing

Why should I use it?

 Disadvantages: Less intuitive than word processors Many commands to learn Time lost to debugging LaTeX code Advantages: Automatic numbering of sections, citations, etc. Beautiful math formulas with fine control Fine control over spacing Packages and user-defined macros

LaTeX is a professional typesetting tool providing great control, particularly with math formulas. However, it does take patience to learn. If none of this is appealing, LaTeX is not for you.

What tools does this require?
LaTeX code is plain text, so any text editor will suffice. To compile LaTeX code, a TeX system with LaTeX is necessary. Two free TeX systems available for download are MikTeX for Windows and teTeX for UNIX. Third, a viewer program is necessary to view the output. LaTeX typically outputs DVI, PS, or PDF format files. Adobe Reader can view PDF files and the Ghostscript + Ghostview system can view all three formats.

Note: There is more than one version of LaTeX. This guide is specifically for LaTeX 2ε, however, most features should also apply to other versions.

Although not strictly necessary, it is a good idea to use a spell checker. Two free spell checkers are Aspell and Ispell.

LaTeX Basics

The structure of a LaTeX document is a preamble followed by a body:

\documentclass[options]{class}
Preamble: Global commands, settings, and macro definitions
\begin{document}
Body: Text and local commands
\end{document}

The \documentclass line specifies the general options like paper size and default font size and the type or “class” of document. The preamble is used to include packages, set global parameters like margin widths, and define macros. The body is mostly plain text with occasional commands for special symbols, changing fonts, or other formatting.

• All characters may be used directly except # $& ~ _ ^ % { } \, which have special meaning. • The special characters #$ & ~ _ ^ % { } may be printed by prefixing \, for example, \& to print &.
• All commands are \ followed by a sequence of letters, for example, \textbf for writing in bold face.

For example, the body text

You can get this \textbf{amazing product} for only \$49.99! compiles to You can get this amazing product for only$49.99!

Hello, LaTeX World!
LaTeX is best learned through experience. Get started with this exercise:

demo.tex

\documentclass[12pt]{article}
\begin{document}

The \#1 story is that this article was compiled today (\today) with
\LaTeX. To try some commands, it includes \textit{a few fancy}
\textbf{fonts}.

\end{document}
1. Copy the code above into a text editor and save it as demo.tex.
2. Compile it with LaTeX. With teTeX or MikTeX, the command latex demo.tex produces a DVI file, which can then be converted to PS with dvips demo.dvi or to PDF with dvipdf demo.dvi.
3. View the output PS or PDF file.

Fonts
As demonstrated with \textbf, text is written in another face by using a command with the text enclosed in curly braces { }.

 Bold face \textbf{...} Typewriter \texttt{...} Italics \textit{...} Underlined \underline{...} Slanted \textsl{...}

Font commands may be nested, for example, \textbf{super \textit{stylish}} yields super stylish.

Line, Paragraph, and Page Breaks
LaTeX ignores single line breaks in the code. To force a line break within a paragraph, use two backslashes \\. To indicate a paragraph break, use two line breaks:

Code:
In 1812, Bessel was elected to the Berlin Academy and won an award from the academy a few years later for estimations of precession and aberration constants. In 1825, he was elected as a Fellow of the Royal Society.

In 1830, Bessel published his calculations for the positions of 38 stars over the years 1750--1850. In 1838, he determined that the star Sirius has a companion star, Cygni, and calculated its position. The star was later observed in 1862, verifying his conjecture.
Output:
In 1812, Bessel was elected to the Berlin Academy and won an award from the academy a few years later for estimations of precession and aberration constants. In 1825, he was elected as a Fellow of the Royal Society.
In 1830, Bessel published his calculations for the positions of 38 stars over the years 1750–1850. In 1838, he determined that the star Sirius has a companion star, Cygni, and calculated its position. The star was later observed in 1862, verifying his conjecture.

To add a blank line between two paragraphs, use \bigskip:

Code:
In 1812, Bessel was elected to the Berlin Academy and won an award from the academy a few years later for estimations of precession and aberration constants. In 1825, he was elected as a Fellow of the Royal Society.

\bigskip

In 1830, Bessel published his calculations for the positions of 38 stars over the years 1750--1850. In 1838, he determined that the star Sirius has a companion star, Cygni, and calculated its position. The star was later observed in 1862, verifying his conjecture.
Output:
In 1812, Bessel was elected to the Berlin Academy and won an award from the academy a few years later for estimations of precession and aberration constants. In 1825, he was elected as a Fellow of the Royal Society.

In 1830, Bessel published his calculations for the positions of 38 stars over the years 1750–1850. In 1838, he determined that the star Sirius has a companion star, Cygni, and calculated its position. The star was later observed in 1862, verifying his conjecture.

LaTeX determines intelligent page breaking automatically (avoiding problems like orphan lines), but it is occasionally necessary to manually indicate page breaks. To force a page break, use the command \pagebreak. To prevent a page break, use \nopagebreak.

Math in LaTeX

A math formula can be written within a line of text (text style), or apart on its own line (display style). Text style math is enclosed with dollar signs: $...$. Display style math is enclosed with either $...$ or double dollar signs $$...$$. The enclosed code is called the formula text.

Basic Symbols
Many math symbols are intuitively represented in the formula text. For example, $|f(x)| > 2M$ produces the formula |f(x)| > 2M.

• Letters, numbers, and the symbols + - / = < > : | ( ) [ ] work directly.
• Spaces between these symbols has no effect. $x + y$ and $x+y$ have the same output.
• To produce curly braces { }, use \{ and \}.

Superscripts and Subscripts
Superscripts and subscripts are made using ^ and _. For example, $x^2 + y^2$ yields x2 + y2. A symbol can have both a superscript and a subscript: $A_n^k$ yields Ank.

• If a superscript or subscript has multiple symbols, it must be enclosed with { }, for example, $Y_{2n}$ to produce Y2n.
• If a superscript or subscript is enclosed with { }, it can itself have superscripts and subscripts.

Fractions
Graphical fractions are made with \frac{ numerator }{ denominator }. The formula $\frac{1}{x^2 + y^2}$ produces

 1 x2 + y2

Sums, Products, and Integrals
The commands \sum, \prod, and \int produce these three features. They usually have upper and lower limits, which are added like superscripts and subscripts. For example, $\sum_{k=0}^N$ to produce

 N ∑ k=0

Functions
The standard style in math typesetting is to use italics on variables and Roman font on function names. LaTeX provides commands to display some common functions in Roman font, including

 \arccos \cos \exp \log \sin \arcsin \cot \inf \max \sup \arctan \csc \lim \min \tan

For example, $sin(x)$ generates sin(x) while $\sin(x)$ generates sin(x). For other functions not in this list, force Roman font with \mathrm{function name}.

Parenthesis
The formula text $\exp( -\frac{x^2}{2} )$ has output

exp(−
 x2 2
)

To generate parenthesis with the correct size, use the \left and \right commands. The \left command is placed in front of the opening parenthesis and the \right command is placed with the matching closing parenthesis. Correcting the example formula, $\exp\left( -\frac{x^2}{2} \right)$ has output

exp (
 x2 2
)
• \left and \right must appear in pairs.
• They may also be used with other bracket symbols, including [ ] { } |.
• The bracket symbols need not match, \left\{ ... \right| is legal.
• To produce a single opening or closing bracket, make the other bracket invisible with \left. or \right..

Greek and Special Symbols
LaTeX provides an extensive set of math symbols. Symbols are represented with \ followed by the symbol name:

 α \alpha κ \kappa υ \upsilon Ξ \Xi β \beta λ \lambda φ \phi Π \Pi γ \gamma μ \mu χ \chi Σ \Sigma δ \delta ν \nu ψ \psi Υ \Upsilon ε \epsilon ξ \xi ω \omega Ψ \Psi ζ \zeta π \pi Γ \Gamma Φ \Phi η \eta ρ \rho Δ \Delta Ω \Omega θ \theta σ \sigma Θ \Theta ι \iota τ \tau Λ \Lambda ± \pm → \rightarrow ≠ \ne ∃ \exists ∞ \infty ⇒ \Rightarrow ≡ \equiv ∀ \forall ≤ \le ⇔ \Leftrightarrow ≈ \approx ∈ \in ≥ \ge ∴ \therefore ∼ \sim ∉ \not\in

There are many more if you need them.

Spacing
Sometimes formulas need manual adjustments to space symbols properly. A “quad” is the length equal to the font size, for example, 1 quad = 11 pt with 11 pt font size. These commands add horizontal spacing:

Use the small space command \, to adjust where symbols are a little too close. Use the negative space command \! to squeeze together symbols that are otherwise too far apart. Multiple negative spaces \!\!\! can be used to squeeze further. For larger spaces, use \quad and \qquad.

Normal Text within a Formula
It is frequently necessary to write normal text within a math formula, particularly single words and short phrases like “if” and “such that.” This can be done with \mbox{ normal text }. For example,
$f(x_0) = f(x_1) \qquad \mbox{if and only if} \qquad x_0 = x_1$
produces

f(x0) = f(x1)     if and only if      x0 = x1

Math Fonts
It is sometimes useful for notation to use another font than the standard, for example, writing vectors in boldface. The following commands change the font of the math they enclose

 Roman \mathrm{...} Bold \mathbf{...} Typewriter \mathtt{...} Sans serif \mathsf{...} Italic \mathit{...} Calligraphic \mathcal{...}

The normal math font is forced with \mathnormal{...}.

Typesetting differentials
When a differential precedes or follows other symbols, insert a small space with \,. For example, $\int \phi(x) \,dx$ to produce  ∫ f(xdx  rather than ∫ f(x)dx.

Exercise
See if you can reproduce the following formula:

Document Structure

LaTeX offers commands for creating title pages, numbered sections, bibliography, and other features necessary in a structured document.

Title Page
To create a title page, write the following commands at the beginning of the body text:

\title{title text}
\author{author \\ institute \\ address}
\maketitle

Depending on settings, it may be necessary to include these commands to begin page numbering after the title page:

\thispagestyle{empty}
\newpage
\setcounter{page}{1}

Abstract
Write an abstract with

\begin{abstract} abstract text \end{abstract}

Sections
Sections are labeled and automatically numbered with the commands

\part     \chapter     \section     \subsection     \subsubsection

Use the command \sectioncommand{title} to create a section with heading text title. Use \sectioncommand*{title} to omit numbering. For example, a research article could be structured

 Code: \section{Introduction}     ... \subsection{Previous Work} ... \section{Background} ... \section{Theory} ... \subsection{Main Theorem} ... \subsection{Implications} ... \section{Experiments} ... \section{Conclusion} ... Outline: Introduction Previous Work Background Theory Main Theorem Implications Experiments Conclusion

The command \tableofcontents produces a table of contents based on the section commands. When sections are added, change order, or if a section heading appears on a different page, the LaTeX code must be compiled twice to create the table of contents correctly.

Bibliography and Citations
A bibliography is structured

 \begin{thebibliography}{samplelabel}      \bibitem{key 1}entry text 1      \bibitem{key 2}entry text 2      ... \end{thebibliography}

Each \bibitem command represents an entry in the bibliography. The entry text is the actual bibliographic information (author, title, publication, etc.). The key argument is a keyword for referring to the entry. To cite the entry within the text, use the command \cite{key}. The samplelabel argument is simply to indicate the number of digits in the largest label. If there are between 10 and 99 entries, use 99.

An example bibliography:

Code:
\begin{thebibliography}{99}
\bibitem{Heijmans} H. Heijmans and J. Goutsias. Nonlinear Multiresolution Signal Decomposition Schemes--Part II: Morphological Wavelets.'' \textsl{IEEE Transactions on Image Processing}, 2000.

\bibitem{Do} M. Do, \textsl{Directional Multiresolution Image Representations}, Ph.D. Thesis, Department of Communication Systems, Swiss Federal Institute of Technology Lausanne, 2001.

...

\end{thebibliography}
Output:
References
 [1] H. Heijmans and J. Goutsias. “Nonlinear Multiresolution Signal Decomposition Schemes–Part II: Morphological Wavelets.” IEEE Transactions on Image Processing, 2000. [2] M. Do, Directional Multiresolution Image Representations, Ph.D. Thesis, Department of Communication Systems, Swiss Federal Institute of Technology Lausanne, 2001. ...

The text

For background on contourlets, see \cite{Do}.

produces

For background on contourlets, see [2].

Closing

You now have the knowledge to begin using LaTeX. Be aware that this guide is only a quick introduction to the most useful features of LaTeX. Beyond this guide, other LaTeX features and package features you may want are

 • Tables, lists, footnotes, figures • Defining your own macros • AmS-LaTeX math extensions (amsmath) • Color, drawings, import graphics (color, tikz, graphicx, ...) • Multi-column page layout (multicol) • Presentation slides (beamer and others) • Listing code with syntax highlighting (listings) • Hyperlinks (hyperref) • Strikeout and various underlining styles (ulem)