A brief introduction to LaTeX

examples | overview of commands | hints

getting started | a simple document | previewing | equations | figures | page formatting

LaTeX is a powerful document preparation system which is in widespread use in science and mathematics communities. It is a "mark-up language" and hence you control all document formatting and other properties by writing explicit commands right in the file with the text that is to be published.

Its nicer features include very polished output, reference and cross-reference schemes, and sophisticated equation layouts. It can be cumbersome to do simple things with it, on the other hand, it can be relatively easy to do quite complicated things (especially related to mathematical typesetting). Above all, it is nearly ubiquitous among scientific journals as the preferred submission format (at least in physics).

If you are wondering, the "TeX" in "LaTeX" is pronounced "teck". As for the "La", it seems to be up for grabs. Since "latex", as in the synthetic material, sets a precedence of sorts, maybe its not unreasonable to go with the long "a". The incarnation of LaTeX which we consider in here is LaTeX2e.

Getting started.

Before beginning, PLEASE check to make sure your shell is getting set up to access local TeX and LaTeX resources. Type
printenv TEXINPUTS
If this gives no output than please contact the instructor before proceeding.

Creating a simple LaTeX document.

A very stripped-down LaTeX document might look like this:
Hello world!
The effect is to first define the kind of document, here, an "article" (other options: book, letter, report), then to put the text in a "document" environment which tells the system that this is the material to be published.

These commands would be written up in a text file (using emacs, for example); let's call the tile file.tex, where the extension .tex is standard for both LaTeX and its precursor, TeX. The next step is to generate postscript by typing

latex2e file
dvips file
The effect of these statements is to invoke the LaTeX processor which spits out a file called file.dvi, a "device independent" form of the document which can be readily converted to a postscript file or output for display on X. The command dvips does the conversion to postscript.

Note: bear in mind that if you have any cross-referencing (not to worry what that means) then LaTeX needs to make two passes at the file. You must, in this case, call the

latex2e file
two times before invoking the dvips command.

Note Jr.: if you use the .tex extension, you don't need to type it in when "latex-ing" the file. Same goes for dvips.

That's all there is to it. The result, file.ps, is printable postscript.

Previewing the LaTeX document.

To see what you've done, try either
xdvi file.dvi
ghostview file.ps
If you use xdvi, you needn't have run dvips as above. This utility displays file.dvi which came directly from latex.

If your intent is to ultimately print the file, maybe use ghostview (or the convenient alias, gv) instead of xdvi, since you can print the file from within gv after inspecting it.

A slightly more complicated example.

If you tried the above example, you'd find that the printed document would show a pretty small ("10 point" or "10pt") roman font. Maybe this is not desired. You can change this by introducing a "class" file in the \documentclass declaration. In this next example, we'll switch to a more legible 11pt fontset, as well as demonstrate other features of LaTeX:
% This is a comment! LaTeX ignores things to the right of a %-symbol


% the line break and extraneous spaces here are ignored.
% "Hello again." will appear as a sentence.
% But blank lines separate paragraphs:

This begins a new paragraph (with only one sentence in it).

We can muck with many features of the text. \\
For example, font types can be easily changed: {\it this is in italics.}

% The "\\" is a new-line character which forces a line break
% "\it" is a LaTeX command causing italics to be printed.
% the curly braces limit the scope \it to be just the words
% enclosed. It is equivalent to:

For example, font types can be easily changed: \it this is in italics. \rm

% In the above, the switch from italics to the default (roman)
% is made using the \rm command.

latex will ignore this, because it is beyond the "end of the document."

Adding in math symbols and equations.

LaTeX has a "mathmode" which interprets special characters for mathematical typesetting. The $-sign toggles mathmode and normal mode. For example, if you want a math symbol or symbols in normal text, use

The circumference is $2 \pi r$ where $r$ is the radius.
Note that $-signs always appear in pairs, bracketing mathmode text. Also note that the character \pi for the greek symbol is known only in mathmode. Typing it outside of a $...$ pair will cause latex to generate an error.

Latex can also make equations which, in the usual manner, appear on their own separate lines embedded in normal text.

Here is an equation: \begin{equation}
f(x) = a_0 + a_1 z + a_2 z^2
Note that Eq. \ref{eq:quad} is quadratic.
This construct will cause an equation number to appear with the formula; the (optional) label gets assigned the equation number ("2", for example); then the sentence following the equation (it could have preceeded it) will read "Note that Eq. 2 is quadratic."

The \label{tag}--\ref{tag} usage here is an example of referencing which might require the LaTeX to be run twice.

LaTeX has a slough of math symbols, most of which have obvious, clear names (like the letters of the greek alphabet--\lambda and \Lambda are lowercase and uppercase examples). There are a few which may be harder to guess, for example \pm for the plus-over-minus sign used when giving error ranges. > Try this link for a list of LaTeX math symbols and features.

You'll probably find that most every symbol you'd ever need is defined in LaTeX. However there are two which you may have to define yourself. They are the greater-than-almost-equal-to and less-than-... symbols. A workaround (which may not be necessary in new or future LaTeX versions) is to put the following lines in your LaTeX file above the begin{document} command:

\def\gae{\lower 2pt \hbox{$\, \buildrel {\scriptstyle >}\over {\scriptstyle \sim}\,$}}
\def\lae{\lower 2pt \hbox{$\, \buildrel {\scriptstyle <}\over {\scriptstyle \sim}\,$}}
Then in your equations you can use \gae or \lae to produce the symbols.

Adding in figures.

Figures are somewhat special in LaTeX, since it is a primarily a typesetting language. It is possible to include figures, but the standard way is to first generate them elsewhere in postscript format. Then, a particular style file epsf can be used to help merge the LaTeX and figure postscript. It works like this, for example:

\caption{This is the figure caption.}

The \epsfxsize scales the (encapsulates) postscript file figure.ps so that its horizontal (x) dimension is 6.5 inches. (Other units of length are cm, pt=points).The \epsfbox sets the name of the postscript file to read in, and \centerline (a "native" LaTeX command, not specific to the epsf style) centers the figure.

The [tbhp] is optional; if is is included, it guides LaTeX in placing the figure on a page. The first choice is t=top, second is b=bottom, h=here and p=page-of-its-own. Here we've made the figure 6.5 inches wide--it the figure is roughly square, then LaTeX won't be able to put it anywhere except on its own page.

Formatting the page.

LaTeX allows you to play with the page layout. For example, on an 8.5"x11" page, the default side margins are 1.5" wide. You can change this to 1" by putting

\evensidemargin 0.0in
\oddsidemargin 0.0in
\textwidth 6.5in
after the \documentstyle command but before the \begin{document} statement. Odd and even refer to page numbers, and the margin always refers to the left side of the page. LaTeX defines the margin to be 1" plus the value of the sidemargin variables. We must also reset the text width variable if we want the right margin to be 1" also. (Clearly we want the sum of L+R margins and the text width to be the page width.)

See the file ~p5720/examples/latex-cv-template.tex for more possibilities.


Please let the instructor kmow of any difficulties you may be having. This section will be updated as problems arise. For now, the best hint is to play with the LaTeX files in the ~p5720/examples directory.

bcb 18-Sep-98.