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
Disadvantages:
Advantages:
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.
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 TeXLive for Linux. 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.
Although not strictly necessary, it is a good idea to use a spell checker. Two free spell checkers are Aspell and Ispell.
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.
\
, for example, \&
to print &.\
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!
The best learning is 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}
pdflatex demo.tex
(alternative: latex demo.tex
followed by dvipdf demo.dvi
).As demonstrated above with \textbf
, text is written in another face by using a command with the text enclosed in curly braces { }
.
\textbf{...}
Bold face
\texttt{...}
Typewriter
\textit{...}
Italics
\textsl{...}
Slanted
\underline{...}
Underlined
Font commands may be nested, for example, \textbf{super \textit{stylish}}
yields super stylish.
LaTeX ignores single line breaks in the code. To indicate a paragraph break, use two line breaks. To force a line break within a paragraph, use two backslashes \\
.
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
.
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.
Many math symbols are intuitively represented in the formula text. For example, $|f(x)| > 2M$
produces the formula |f(x)| > 2M.
+ - / = < > : | ( ) [ ]
work directly.$ x + y $
and $x+y$
have the same output.\{
and \}
.Superscripts and subscripts are made using ^
and _
. For example, $x^2 + y^2$
yields x² + y². A symbol can have both a superscript and a subscript: $A_n^k$
yields Ank.
{ }
. For example, $Y_{2n}$
to produce Y2n.{ }
, it can itself have superscripts and subscripts.Graphical fractions are made with \frac{ numerator }{ denominator }
. The formula \[ \frac{1}{x^2 + y^2} \]
produces
Sums, products, limits, and integrals are produced with commands \sum
, \prod
, \lim
, and \int
. They usually have upper and lower limits, which are added like superscripts and subscripts. For example, \[ \sum_{k=0}^N \]
for
LaTeX commands \exp
, \log
, \cos
, \sin
, \arccos
, \min
, \max
, \inf
, \sup
, and others write common functions, which are typeset in Roman font instead of italics.
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{functionname}
.
The formula text \[ \exp( -\frac{x^2}{2} ) \]
has output
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
\left
and \right
must appear in pairs.\left\{ ... \right|
is legal.\left.
or \right.
.LaTeX provides an extensive set of math symbols. Symbols are represented with \
followed by the symbol name:
\alpha
α
\beta
β
\gamma
γ
\delta
δ
\epsilon
ϵ
\le
≤
\ge
≥
\ne
≠
\approx
≈
\pm
±
\infty
∞
\rightarrow
→
\Rightarrow
⇒
\partial
∂
\exists
∃
\forall
∀
\in
∈
\not\in
∉
And there are many more if you need them.
Sometimes formulas need manual adjustments to space symbols properly. A “quad” is the length equal to the font size, 1 quad = 11 pt with 11 pt font size. These commands add horizontal spacing:
\,
3/18 quad space
\:
4/18 quad space
\;
5/18 quad space
\quad
1 quad space
\qquad
2 quad space
\!
−3/18 quad negative space
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
.
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
It is sometimes useful for notation to use another font than the standard one, for example, writing vectors in boldface. The following commands change the font of the math they enclose
\mathrm{...}
Roman
\mathbf{...}
Bold
\mathtt{...}
Typewriter
\mathsf{...}
Sans serif
\mathit{...}
Italic
\mathcal{...}
Calligraphic
The normal math font is forced with \mathnormal{...}
.
When a differential precedes or follows other symbols, insert a small space with \,
. For example, $\int \phi(x) \,dx$
to produce ∫ f(x) dx rather than ∫ f(x)dx.
See if you can reproduce the following formula:
LaTeX offers commands for creating title pages, numbered sections, bibliography, and other features necessary in a structured document.
To create a title page, write the following commands at the beginning of the body text:
\title{title text}
\author{author \\ institute \\ address}
\maketitle
Write an abstract with
\begin{abstract} abstract text \end{abstract}
Sections headings are defined and automatically numbered with the commands
\part \chapter \section \subsection \subsubsection
Use for instance \section{Methodology}
to create a section with heading text "Methodology". Use \section*{title}
to omit numbering. For example, a research article might be structured as
\section{Introduction}
...
\subsection{Previous Work}
...
\section{Background}
...
\section{Theory}
...
\subsection{Main Theorem}
...
\subsection{Implications}
...
\section{Experiments}
...
\section{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.
A bibliography is structured like
\begin{thebibliography}{samplelabel}
\bibitem{key1}entry text 1
\bibitem{key2}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.
For example, the bibliography code
\begin{thebibliography}{9}
\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}
produces
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].
You now have the foundation to begin writing documents with LaTeX. This guide is only a quick introduction to some of the most useful features of LaTeX. Beyond this guide, other LaTeX features and package features you may want are