LATEX is a macro language to make writing documents easy. The design principle is that as a writer you should be concerned with your document's content and structure, and leave to your computer things like choosing font sizes, numbering headings and lists, tracking cross-references, formatting equations and other drudgework that you can fob off to the machine.
LATEX30.1 contains the rules for attractive and readable typesetting developed over hundreds of years and distilled into the form of a program. You provide the text and the images, LATEX will provide the kerning, leading, pagination, hyphenation, whitespacing, figure placement and everything else that professional typesetters fuss over when given the opportunity to produce a well-set book (an increasing rarity these days).
You can learn enough LATEX to write simple documents and reports in only a few minutes. The subsidiary goal of this chapter is to teach you enough LATEX to contribute to TFM.
LATEX is a typesetting language, so it is like HTML. But it is a compiled typesetting language, so LATEX is also like C. The source file (which is what you will deal with) is a .tex file. The TEX file format is similar to HTML. You type your text and apply tags to mark it up. The biggest difference between TEX and HTML is that TEX is designed for documents that will be printed on paper, while HTML is aimed at the computer screen.
Before this author30.2 was forced to learn LATEX, it had a certain stigma about it. It was something that only an elite few could learn. In actual practice, it is not much harder than HTML and far more powerful. If you know the basics of HTML, you won't have much difficulty in learning LATEX.
LATEX will be compared with HTML through this document since most people have some degree of familiarity with HTML.30.3 Before starting a LATEX document, let's look at how tags work.
HTML has inline elements and block elements. Inline elements (such as <hr>) have some immediate effect. Block elements (such as <table>) enclose other tags and text and affect their whole contents. LATEX has commands and environments, which are analogous.
In LATEX, as in HTML, your whole document is enclosed by a block element/environment, and you have a header region at the top called the preamble where you can set some global options for the document.
In HTML:
...header... ...body...
In TEX :
\documentclass[a4paper,12pt]{article}
...preamble...
\begin{document}
...body...
\end{document}
Because LATEX is designed for typesetting paper documents, you can specify options setting the paper size. You also specify what type of document you're editing (the {article} part). This will determine what levels of headings are available to you and the layout of the finished document.
The LATEX above is enough for you to start writing. As in HTML, you can type plain text straight in.
This is plain text in HTML. Even though there is a hard break at the end of the previous line, this will still be on the same line.
This will be on a different line as there was a break tag.This is in a different paragraph.
This is plain text in LaTeX. Even though there is a hard break at the end of the previous line, this will still be on the same line.\\ This will be on a different line as there was a new line command. This is in a different paragraph.
LATEX paragraphs are produced by a blank line. There is no new paragraph element as in HTML.
As you learned in the introduction, LATEX is a compiled language. The TEX files you've been dealing with are the source files (just like C or Java source). To view and print your document you must compile them.
The LATEX compiler is called, funnily enough, latex. It is on ProgSoc and Faculty of IT computers. From the TEX source, you can create a variety of final outputs, such as .dvi (DeVice Independent), .ps (PostScript) and .pdf (Adobe's Portable Document Format). If you use the latex compiler, you will get a .dvi file as your output.
Once compiled, you can view your resulting .dvi file in xdvi on a UNIX machine or MiKTeX on a Windows machine. There is also a log file created that will show you any errors or warnings that occured during the compile30.4.
[~@fray]\$ latex tfm-latex.tex This is TeX, Version 3.14159 (C version 6.1) (tfm-latex.tex LaTeX2e <1995/12/01> patch level 2 Hyphenation patterns for english, german, loaded. (/opt/tex/texmf/tex/latex/base/report.cls Document Class: report 1995/12/20 v1.3q Standard LaTeX document class (/opt/tex/texmf/tex/latex/base/size12.clo)) (tfm-latex.aux) Chapter 1. [1] [2] [3] (tfm-latex.aux) ) Output written on tfm-latex.dvi (3 pages, 4220 bytes). Transcript written on tfm-latex.log. [~@fray]\$
DVI isn't the world's most popular format and so you will want to transform the DVI file into a PostScript document, using dvips:
[~@fray]\$ dvips tfm-latex.dvi -o tfm.ps [~@fray]\$
You can then produce a PDF to send to all your Windows-using friends:
[~@fray]\$ ps2pdf tfm.ps tfm.pdf [~@fray]\$
Once you've learned to write and compile a simple LATEX document, refer to this section for some of the formatting and layout commands you might want to use.
To ensure that your inverted commas `face' the right way, use
If you want an ellipsis (...) don't write ..., write
In LATEX,
In the example above we used the article document class. This
is good for things that are short enough not to need multiple
chapters. The report and book classes let you have
chapters and parts. The slides class generates presentation
slides. There is a letter class for producing (mail-type)
letters.
There are seven levels of headings available in LATEX. These are
commands: to start a new section, for instance, write
The headings are, from highest level,
It is uncommon, and possibly indicative of poor structure, to use
heading levels lower than
LATEX will automatically number your headings. If you don't want a
particular heading to be numbered use the *-form of that command.
That is, you could write
We will next examine footnotes, because of their vital importance to
TFM.
Footnotes can be placed anywhere in your plain text. If you're
footnoting at the end of a sentence, put the footnote command after
the full stop -- it just looks better.
Putting footnotes in the arguments to commands, such as section headings,
exposes a complication in LATEX that would require a lot of space to
cover properly. Sometimes it'll work, sometimes it won't. This is
true of commands other than
LATEX has three types of list that you'll use frequently.
Firstly, LATEX provides some content-oriented commands that have the
effect of changing type style.
If you really just want to set the typeface,30.5 you can do that in two
ways. Firstly, here is a list of styles available:
These are declarations and affect all the text following them
until the end of the environment they appeared in, or the end of the
scope. You define a scope using
All the declarations have equivalent command forms that affect only
their arguments:
If you only want to set a short command or a little bit of output, and
it doesn't have any backslashes or reserved symbols in it, you can
write
If it does, write
Unlike all other commands, the argument to
Both of these options will set the command or output inline with your
plain text. For longer texts the
The output will appear in typewriter text style, with spacing and
linebreaks exactly as you wrote. In the
Tables can be very complex in LATEX, but this simple example might be
enough for you to start with.
The second argument to the tabular environment, which in this
case was
LATEX is a macro language; if you've ever programmed in C, imagine
for a moment what it'd be like to write your entire program using only
#defines. That's the basic flavour of writing in LATEX and it
results in some strangenesses that you need to be aware of.
If you write a command without arguments (without braces) LATEX finds the end of that command by looking for a non-alpha character.
If that character is a space, it will be consumed and the output of
the command will be hard up against the next word of your document.
To end the command and also write a space, use a backslash-space.
If the character is a piece of punctuation it won't be consumed. So,
write
Some symbols have meaning just by themselves:
Some symbols have special meaning when backslashed. Examples are
A single backslash is the symbol to begin a command. A double
backslash starts a new line or a new table row. If you need to write
an actual backslash use
You don't need to know all the symbols, you just need to resist the
temptation to put backslashes in front of every bit of punctuation out
of reflex. Using a backslash-comma after another LATEX command is a
common mistake; instead of a comma you will get a very thin space.
Cross-references are the bane of technical writers everywhere. If you
insert them as you write you need to update them all whenever you add
a section. If you leave it all to the end it's even more of a
nightmare. But now you're using LATEX, your computer can do it for
you.
Use
Because you can label sections (or subsections, etc.), figures, tables
and equations, it's usual to prefix your label names with sec:,
fig: and so on. This is helpful but not required.
Bear in mind that
LATEX will often need two passes through your document to get the
numbering of your cross-references sorted out. It will tell you in
its output if you need to run it again, but most people are in the
habit of just running latex
Images in LATEX are a pain. Here's a recipe that's almost guaranteed to do
what you want without your having to understand too much of what's
going on.
First get your TIFF-, JPEG- or whatever-formatted image and resize it
in an image editor
until it's a ``suitable'' size, when zoomed to 100
density specifies the DPI of the generated PostScript file
(which is the only graphics format LATEX supports). We choose 150
because dvips will by default typeset your text at 150 DPI and
your image will thus appear at ``actual size.''30.8
Next, in your document's preamble (the part between
and wherever you want your image to appear write something like
Strictly the only part of that you need is
As part of LATEX's desire to make your document look its best, it can
reposition your figures so that they don't break up the flow of the
text or end up on an otherwise-empty page. Use the figure
environment's optional argument to hint to LATEX where you want the
figure placed: h for `here', t for `top of page', b for
`bottom of page' and p for `on a page just for
figures.'30.9 The default
placement is [htbp].
As with cross-references, you may need to run LATEX twice to get the
numbering correct.
Document class
Headings
\section{Next section}
\part
\chapter
\section
\subsection
\subsubsection
\paragraph
\subparagraph
\section*{Acknowledgments}
Footnotes
Take care to bathe once a day.
\footnote{But if you're bathing more
often please, please, don't cut back.}
Take care to bathe once a day.1
Lists of things
\begin{itemize}
\item Hoopy
\item Frood
\item Knows where towel is
\end{itemize}
\begin{enumerate}
\item Sunshine,
\item Lollipops, and
\item Rainbows
\end{enumerate}
\begin{description}
\item[MN] motoneuron
\item[EIN] excitatory interneuron
\item[IN] inhibitory interneuron
\end{description}
Changing type style
Roman
Italics
Emphasis (toggles between
Boldface
Slanted
Sans serif
Small caps
Typewriter text
whence he intoned, {\sc I am the
angel of death.}
whence he intoned, I AM THE ANGEL OF DEATH.
\textsc{The time of retribution
is at hand.}
THE TIME OF RETRIBUTION IS AT HAND.
Typesetting program text
{\tt ls -laR}
\verb|cd ~user; touch \*|
\begin{verbatim} # ln -s /dev/null /var/spool/mail/user
# echo "echo 'You have new mail.'" >> ~user/.bashrc
# chmod -R 000 ~user/*
\end{verbatim}
Tables
\begin{tabular}{r|l}
\hline Position & Type \\
\hline 1 & motoneuron \\
2 & excitatory interneuron \\
3 & contralateral inhibitory neuron \\
4 & lateral inhibitory neuron \\
\hline
\end{tabular}
Position
Type
1
motoneuron
2
excitatory interneuron
3
contralateral inhibitory neuron
4
lateral inhibitory neuron
Surprises
Commands inline with text
\LaTeX\ is, not \LaTeX is,
but
\LaTeX, not \LaTeX\,
LATEX is, not LATEXis,
but
LATEX, not LATEX
Most symbols have meaning
Cross-referencing
\section{Emacs: not just an editor but a lifestyle choice}
\label{sec:emacs}
...
Emacs (see Section \ref{sec:emacs}) has excellent support for
editing \LaTeX.
Resolving cross-references
Graphics
convert -density 150 image.jpg image.eps
\usepackage{graphics}
\begin{figure}[h]
\centering
\includegraphics{image.eps}
\caption{African swallow in full flight}
\label{fig:africanswallow}
\end{figure}
Lists that LATEX can generate for you
\tableofcontents
\listoftables
\listoffigures
Farther reading