LATEX is a free, open-source document typesetting system that is particularly strong for typesetting mathematics conveniently and everything beautifully, and for handling cross-references and bibliographies painlessly. LATEX source files are text, so it is well suited for collaboration, emailing, and version control, and all text-oriented tools can be used with it. Major journals and conferences provide LATEX class files that accomplish their formatting requirements painlessly. Pronounced la-Tek or Lay-tek, said Lamport. Not Lay-teks (shudder). Lamport's LATEX is a macro package based on Knuth's TEX, and Knuth said TEX was not spelled t-e-x but actually τ-ε-χ (tau epsilon chi).
The key references are:
This second edition covers the current version of LATEX.
This second edition covers far more than the first. The first edition listed Goossens's name first.
Every symbol you could possibly want, plus thousands you will never need.
LATEX provides the \textasciicircum, \textunderscore, \textasciitilde, and \textbackslash commands to produce text versions of those characters.
Tildes are most often needed in URLs, for which use the url package and enclose each URL in a \url{ } command. The \url command handles some other special characters, as if they were in a URL.
The underscore package redefines _ in text mode to be an underscore character.
` '
:
`X'
formats as ‘X’.
`` ''
:
``X''
formats as “X”.
-
makes a hyphen.
--
makes an en-dash.
Example: pages 3--5
formats as "pages 3–5".
---
makes an em-dash.
Example: Frogs---a kind of reptile---live in water
formats as
"Frogs—a kind of reptile—live in water".
Figure~\ref{fig:process}
formats as "Figure 1",
with never a line break between "Figure" and "1".
\mbox{
words}
.
\-
where a hyphenated break would be good:
hy\-phen\-ation
will only be broken and hyphenated at those two points,
and not at "hyphena-tion" as it otherwise might.
To encourage specific hyphenations at every occurrence of a word,
list it with dashes at hyphenation points
in a \hyphenation
command
in the file's preamble:
\hyphenation{hy-phen-ation per-co-late}
\textit{et al.}\
.
url
package
and put the URL in the argument of a \url
command,
thus:
\usepackage{url} % immediately after the \documentclass command … \url{URL}
\cite
commands.
This is not a good idea:
RW98a
and RW98b
,
and the a
's and b
's
change depending on what references are cited
in a particular document;
RW98b
(or often even AD94
)
is without looking it up.
The free TeXShop application for OSX (www.uoregon.edu/~koch/texshop) makes formatting LATEX very convenient. It can be used with its built-in editor or with your own favorite text editor.
tetex
seems to be the best latex
implementation at present.
It is free and available for OSX and Windows.
For OSX, I recommend installing fink
(www.finkproject.org)
and then tetex
.
Some tetex
installations (including fink's)
are set up to produce A4 (European) pdf files.
To produce 8.5"x11" pdfs,
you can put these commands
in your file's preamble:
\setlength{\pdfpagewidth}{8.5in} \setlength{\pdfpageheight}{11in}
I have some tools that you will find helpful: bibfile, bibKeys, latexCheck, latexCites.
The LATEX language is primarily about expressing structure, and only secondarily about presentation.
Structure your document first, then adjust the presentation only if something really doesn't look right. Remember that LATEX is usually a much better typesetter than you are.
A document typically consists of:
Each section may have subsections; each subsection may have subsubsections; and so forth.
Content (in the form of paragraphs, lists, block quotes, figures, etc.) goes in the sections, subsections, subsubsections, etc.
The main file consists of:
\documentclass{
C}
line,
where C is the document class.
The standard classes are
\usepackage{
package}
lines.
These load a package of commands and environments
that you can then use in your document.
\title{
title}
,
\author{
author}
,
and other commands for the title information,
any \newcommand
definitions
(see Lamport),
any \setlength
commands
(see Lamport),
and other definitions or redefinitions of things.
document
environment containing
all your text, commands, and other environments:
\begin{document}
\maketitle
if you are using a title
\input{
filename}
commands that include a file named
filename.tex
.
It must have the .tex
suffix
and this suffix can't appear in the command argument.
\end{document}
Everything is done with commands, environments, and text.
Text consists of letters, digits, spaces, and punctuation
.:;,?!`'()[]-/*@
.
It may have commands and environment mixed in with it as needed.
A command consists of the command name,
possibly optional arguments in [], and
possibly required arguments in {}.
Command names begin with a backslash \
,
like \section
.
Command arguments follow the command in curly braces {}
or square brackets []
:
braces for required arguments (most arguments are required)
and brackets for optional arguments.
\section{Heading for this section}
LATEX elides the whitespace following a command. If you need to retain whitespace after a command, either enclose the entire command (arguments and all) in braces { } or use the \ command (backslash followed by space).
An environment
is set off with
\begin
and \end
commands,
each with the environment name as an argument.
An environment named E consists of
\begin{E}
followed by the contents of the environment
and terminated with
\end{E}.
\begin{figure} … \end{figure}
The document itself is enclosed in a document
environment:
\begin{document} … \end{document}
.
Put text to emphasize in the argument
of an \emph
command:
\emph
{emphasized}
.
It will be handled appropriately in all contexts
(for example, in text that's already italicized).
\emph
{emphasized}
LATEX
supports character formatting
independent of structure;
it is preferable to use \emph
for emphasis
rather than any of these.
Some examples are:
\textit
{italic}
\textbf
{bold}
\textsc
{small-caps}
\textsf
{sans-serif}
LATEX has a vast range of accented character commands, with examples here using o, and other letter symbols:
ò | \`{o} |
ó | \'{o} |
ô | \^{o} |
ö | \"{o} |
õ | \~{o} |
ō | \={o} |
ȯ | \.{o} |
o̮ | \b{o} |
ȩ | \c{e} |
ọ | \d{o} |
ő | \H{o} |
o͡o | \t{oo} |
ŏ | \u{o} |
ǒ | \v{o} |
å, Å | {\aa}, {\AA} |
æ, Æ | {\ae}, {\AE} |
ç, Ç | \c{c}, \c{C} |
ł, Ł | {\l}, {\L} |
ø, Ø | {\o}, {\O} |
œ, Œ | {\oe}, {\OE} |
ß | {\ss} |
Some common text symbols are:
# | \# |
$ | \$ |
% | \% |
& | \& |
^ | {\textasciicircum} |
_ | {\textunderscore} |
~ | {\textasciitilde} |
\\ | {\textbackslash} |
{ | \{ |
} | \} |
… | {\dots} |
< | {\textless} |
> | {\textgreater} |
§ | {\S} |
¶ | {\P} |
© | {\copyright} |
… | {\ldots} |
(LATEX also has many, many mathematical symbols not discussed here.)
A blank line starts a new paragraph.
If you have to start a paragraph with a command, it's \par
—
that's the command a blank line executes.
An itemized list is an itemize
environment
with \item
commands, one per list item.
\begin{itemize} \item The first item. \item The second item. \end{itemize}
An enumerated list is an enumerate
environment
with \item
commands, one per list item.
\begin{enumerate} \item The first item. \item The second item. \end{enumerate}
Long quotes are traditionally typeset as a separate block of text,
with extra space on all four sides.
In LATEX
this is done by enclosing the quote
in a quote
or
quotation
environment.
quotation
is only for multi-paragraph quotes.
\begin{quote} A long quote … \end{quote}
formats as
A long quote …
Sections are marked by their headings, but not otherwise distinguished. There is no environment for a section, for example.
The text of a section (subsection, subsubsection) heading is the argument of a \section (\subsection, \subsubsection) command:
Figure 1. \section and \subsection
\section{The Section's Heading} Some text in the section. \subsection{Subsection heading} This is text in the subsection.
The result is shown in Figure 1.
For unnumbered headings, use \section* (\subsection*, \subsubsection*).
Each figure (table) is enclosed in a
figure
(table
)
environment.
Figures and tables are floated to an appropriate location by
LATEX.
The environments take an optional location argument
that influences where the figure (table) will end up,
consisting of any combination of
h
(here),
t
(top of a page),
b
(bottom of a page),
p
(on a separate page of figures and tables),
and
!
(tell LATEX
to try harder).
There are more extreme measures for controlling floats; see Lamport.
In two-column mode,
a double-column figure (table)
is enclosed in a
figure*
(table*
) environment.
You can put anything you like in a figure
or table
environment —
it doesn't have to be an actual figure or table.
Figures (tables) are not centered by default.
Put the \centering
command
immediately after the
\begin{figure}
(\begin{table}
) command to center
the contents of the environment.
A figure or table's caption
is given by the \caption
command
with the caption text as its argument:
\caption{Tex of the caption}
.
LATEX automatically numbers captioned figures and tables (separately) for you, and puts the number in the caption, so don't you do so too.
To reference a figure (table) number elsewhere,
use the \label
command
after the caption
to set an internal label
at the figure's (table's) location,
and the \ref
command
to refer to that label.
It has to be after the caption,
as LATEX
increments the figure (table) number
only when it sees the caption.
LATEX
has the tabular
environment
for making tables.
See Lamport for more details.
I don't recommend it.
Make your tables in HTML, OmniGraffle, or some other
more convenient tool,
save them as images,
and use the image as your table.
The best way to handle images
is to use the graphicx
package
and include the image using the
\includegraphics
command.
The name of the image file is a required argument,
and the size or various other possibilities
are optional arguments.
\usepackage{graphicx} % after the \documentclass command … \includegraphics[width=2in]{image.pdf}
PDF images work best (they are vector images and scale perfectly) if you are using pdflatex as the formatting engine. You can specify the width or height in inches, centimeters (cm), millimeters (mm), points (pt), or various other units.
The label command \label
defines a label for its location
whose name is given in its required argument,
and the ref command \ref
shows the value of the label in its required argument.
Figure~\ref{fig:process} shows our process diagram.
\begin{figure}\centering
\includegraphics[width=3cm]{Process.pdf}
\caption{The process diagram}
\label{fig:process}
\end{figure}
The convention is that figure labels begin with fig:
,
table labels with tbl:
,
section labels with sec:
,
and
equation labels with eq:
.
LATEX is great at typesetting mathematics. Mathematics typesetting is done in math mode, and LATEX uses $ to get in and out of math mode, so escape your dollar signs with backslashes if you just want to put a $ in your document.
The $'s are a shorthand for beginning and ending
the math
environment.
It is slightly less convenient,
but much safer,
to use \( \)
to surround inline mathematics to typeset.
There is also the displaymath
environment
for displayed mathematics
(in a separate centered paragraph),
and the \[ \]
shortcuts for it.
See Lamport for more information. There are lots of possibilities and they all work wonderfully, but it's too much to discuss here.
LATEX
collects the title, author names, etc.
(from
\title{title}
,
\author{author}
,
\date{date}
(or \date
{} for no date),
etc.
commands in the preamble).
The title material actually appears
later where the \maketitle
command appears.
Workshops, conferences, and journals
often redefine the \maketitle
command
to fit their special formats,
and sometimes add additional information commands
like \abstract
.
Basic LATEX has commands for dealing with these but they aren't very helpful.
The fancyhdr
package
does a much better job.
It has commands
\lhead{
left-header}
,
\chead{
center-header}
,
\rhead{
right-header}
,
\lfoot{
left-footer}
,
\cfoot{
center-footer}
,
and
\rfoot{
right-footer}
for specifying text to appear in those places.
Use the LATEX
\thepage
command
wherever you need the page number.
You may need to adjust the page layout parameters
to set up space for headers and footers —
this is not a trivial task.
See Goossens for more information.
LATEX and BibTEX together do a great job of handling citations and references.
In my experience the most accurate source is the ACM portal, which has relatively accurate BibTEX entries for many papers from the ACM and from other sources. The public CCSB has a vast collection of BibTEX entries (including all of mine), but you will need to verify them as the accuracy varies widely depending on where the entry came from. Most of the entries in my personal bibliography (online at CCSB) have been checked and verified against the source document and venue, and are accurate.
Each
BibTEX
entry has a key on its first line
by which you can reference it in a \cite
command
(not to be confused with the key =
field whose
value is used for sorting the references
and which need not match the entry key):
/* in the bib file */ @InProceedings(Winbladh+Alspaugh+2006-aagd, key = {Winbladh+Alspaugh+2006-aagd}, author = {Winbladh, Kristina and Alspaugh, Thomas A. and Ziv, Hadar and Richardson, Debra J.}, title = {An Automated Approach for Goal-driven, Specification-based Testing}, booktitle = {21th International Conference on Automated Software Engineering (ASE 2006)}, year = {2006}, pages = {289--292}, month = sep, )
% in the LATEX file \cite{Winbladh+Alspaugh+2006-aagd}.
Then LATEX and BibTEX collect and format the references into a bibliography for your document, using the right number or alphanumeric key for each citation.
Here's how to make this work:
\bibliography{
filename}
command in your LATEX file
where you want the References section to appear.
\bibliographystyle{
STYLE}
command in front of it,
to control the style of the references.
The standard styles are
abbrv | plain with first names, month names, and journal names abbreviated |
alpha | plain with Aut04 labels rather than numbers. |
plain | van Leunen format entries, numbered. |
unsrt | plain but entries appear in order of first citation rather than alphabetically |
latex
to put all the citation keys
in the .aux file.
latex
to get all the references from the .bbl file
and construct the References section.
latex
once again
to get all the citations in the text set up
(if this is necessary,
there will be a message about "Some references were undefined …"
in latex
's output).
There are several bib styles besides alpha; see Lamport.
It's also possible to include an uncited reference in the reference list: give its key in a \nocite command. \nocite{*} adds all the references in your \bibliography file(s) to the reference list.
It's all controlled in the class file, and then to a lesser extent in package style files, and then to a small extent in your document files. Changing the presentation in the class or package styles is nontrivial, and not discussed here. How to make a style or class file …