# LaTeX concepts

## Environments and commands

LATEX is a macro-package for TEX which has many preset environments where much of the setting up that TEX users have to do explicitly is done for you. An environment has the form

\begin{environment name}
...
\end{environment name}

LATEX also has commands which affect the formatting of the document. Their arguments are given in braces. For example,

  \textit{This is much more important} than this.


produces as output This is much more important than this.

The related \itshape command doesn't take an argument. It affects all the subsequent text in the environment where it's used.

LATEX tries to enforce the idea that the visual appearance of the document (use of fonts, indentation, etc) should derive from the logical structure of the document (i.e. rather than manually putting the section titles into bold, you should let the \section command do it). Resisting this philosophy can lead to extra (usually unnecessary) work.

LATEX is expandable. Many macros can be loaded in to provide added features. You can also create your own commands and environments. Commands can take arguments that modify their action

• Some commands have a *-form, a variant on the standard command that you get by adding a * to the command name.
• Mandatory arguments are enclosed in {} braces
• Optional arguments are enclosed in [ ] brackets.

## Classes and packages

At the top of your file you will have a line something like

\documentclass[12pt]{article}


which determines the font size and document class - the type of document you're writing. Each class has an associated *.cls file in the system directories which is read in at start-up time. Other options accepted by article include 10pt, 11pt and twocolumn.

Then you'll probably need to load in extra macros with the \usepackage command. Each package has an associated *.sty file in the system directories. The packages inherit the options from the \documentclass line and can be given others of their own. E.g.

\usepackage[dvips]{graphicx}
\usepackage[dvips]{color}


tells LATEX that you want to use the extra graphicx and color macros, and that you are going to use dvips to convert the resulting file to postscript. You can shorten this to

\usepackage[dvips]{graphicx,color}


## Errors

Errors can be reported either from the LATEX phase (in which case it is reported as such) or the lower level TEX phase. Don't be too put off by the half-digested text displayed. A line number is reported which usually helps to detect the error. Typing h' sometimes produces helpful diagnostics. The most common errors reported are

• a command misspelt
• a mismatched brace
• improper use of special characters
• forgetting to have the appropriate \usepackage{...} lines.
• an error like this
Overfull \hbox (15.42563pt too wide) in paragraph at lines
285--288 \OT1/ppl/m/n/10 You can cre-ate ver-tical space
between lines or ho-ri-zontal space   between

means that lines 285 to 288 are producing a text line about 15 pts (about 5mm) too wide. \OT1/ppl/m/n/10 is the specification of the font used. When TEX does right and left alignment, it works out how much space it needs to leave between words and where to hypenate words if necessary. But the amount of space it's prepared to leave has to fall within a certain range and it will only split words in certain places (shown in the error message by a hyphen). If these restrictions mean that LATEX can't produce a satisfactory line, it will produce as much of the line as it can. A re-phrasing of the offending sentence will usually solve the problem. Another thing you might try is to control the way a troublesome word is hyphenated using something like
\hypenation{furthermore fur-ther-more}

at the top of your file. If all else fails, use {\sloppy...} to enclose the offending text.
• LATEX issues a *.
This means LATEX needs more input. It probably means you've missed out an \end{document}, but if not you may be able to get LATEX to continue processing as best it can by typing <Return>.
• ! Argument of \label has an extra }
If you're sure you haven't left out a left brace, then maybe you need to protect the inmost (fragile) command. For example, in some older versions of LATEX \label is fragile which causes a problem in sequences like
\caption{Picture\label{margin}},
so the safer construction
\caption{Picture\protect\label{margin}}
has to be used.

## Files created

More than just the *.dvi file may be produced. Don't worry about them - except perhaps for the log file you won't need to look at them.

• *.aux - cross references, etc
• *.toc - created by \tableofcontents
• *.lof - created by \listoffigures
• *.lot - created by \listoftables
• *.log - a copy of the diagnostic output that usually comes out on the screen.

Some common errors can be found using the lacheck program on the LATEX file.

## How to use LATEX at CUED

• From the command line - Edit the latex source code using any editor you want, then run pdflatex at least twice, you should be able to preview your *.pdf` document. If you use evince as your previewer, the preview will be refreshed each time you regenerate the PDF file.
• Using a front-end - We have several latex-based programs ranging from xlatex (which just has buttons to replace command-line operations) to Kile (which includes an editor and many extra facilities).
• © Cambridge University, Engineering Department, Trumpington Street, Cambridge CB2 1PZ, UK (map)
Tel: +44 1223 332600, Fax: +44 1223 332662
Contact: helpdesk