Steinn Sigurðsson: Astro 475(W) LaTeX primer


Here is a short primer on how to write and use LaTeX, should you choose to do so for your papers.

TeX is a typesetting language, it was invented in 1983 by Donald Knuth for the express purpose of lay out for mathematical writing. It is effectively a mark up language, similar in many ways to HTML, though it predated HTML by a decade.

TeX is free, Knuth donated it to the American Mathematical Society, and can be obtained from the web for installation. It is available on the departmental machines.

URL PCTeX
or the CTAN tex-archive mirror
Install at own peril!

LaTeX is an extended version of TeX, it can be thought of as TeX with the addition of some powerful macros, it is to TeX somewhat like C++ is to C.

TeX/LaTeX is an interpreted language, and is used to mark up text for presentation. It is not a wordprocessor or an editor, nor is it a web layout language. (TeX is a general purpose language, essentially any algorithm can be implemented in it, just not very efficiently, unless you are laying out a page of mathematical text).

LaTeX is used extensively for publication of papers and preprints in the physical sciences. In astronomy, astrophysics, theoretical and modern physics, and mathematics, TeX or LaTeX are by far the dominant way of putting together papers, books and other documents.

As in HTML, TeX reserves some characters to indicate commands. The important ones are

You can define your own commands, and write macros with multiple arguments. This is particularly helpful if you are using the same set of symbols repeatedly (see sample file).

To use LaTeX you first create a text file using your favourite editor or word processor.

So you create some file "foo.tex".
You will be using LaTeX, so you start off by marking up the file

\documentstyle[12pt,epsf]{article}

 - this invokes the command "documentstyle", asking for use 12 point fonts
and the encapsulated-postscript-file  macro to load figures.
 - you then invoke the argument "article" to tell documentstyle what
kind of document this will be (as opposed to, say, "memo" or "book").

you then have

\begin{document}

%
%THE ENTIRE TEXT OF YOUR DOCUMENT GOES HERE - see sample
%
%lines that begin with a "%" sign are assumed to be comments and are not interpreted by TeX
%

\end{document}

A key feature of TeX is "math-mode". This is toggled on and off using the "$" symbol.
Any text bracketed by a pair of "$" symbols is assumed to be an equation or similar, and is laid out in a manner appropriate to mathematical notation rather than text.

For example, $1 + 1 = 2$, sets out an equation.

You now have a file, "foo.tex", containing some text, some equations, and maybe some figures and references.

(I implicitly assume below that you are using a Unix workstation, PCs do this slightly differently in a way that should be obvious :-) ).
In the Good Old Days...

To use TeX, you now type:

latex foo

Nowadays, you most likely will have a GUI interface to your TeX interpreter, use it, its use is intuitively obvious (see above). LaTeX will probably complain about a number of errors, including failure to close {} pairs, or $ ... $ pairs, or illegal commands.
Fix the errors and run latex again.
(I recommend running latex frequently as you create a tex file, so as to catch such errors as they happen, and not get multiple error message in one big pile).

latex will now likely complain that it can not match the citations with the references.
This is a feature, not a bug.
The first time latex is run it assembles the data base of references, the second time it is run it matches them to the citations.

So run latex again:

latex foo

If all goes well, there should now exist three new files: "latex.log", "latex.aux" and "latex.dvi".
Ignore the first two. latex.dvi is the "device-independent" file that now carries the layout information you have put into your document.

.dvi files can be "previewed" using tools like "xdvi" (on Unix workstations), or your GUI will pop it up automatically and generate your pdf for you.
So type:

xdvi foo

This should display a WYSIWYG (What You See Is What You Get) version of your document, ready for printing.
If you don't like what you see, go back and change it.


If nothing I said make sense, maybe someone else can explain it better.

Here is Brian Edmonds LaTeX guide

and here is David Wilkin's ``Getting Started with LaTeX'' guide on the web.

Here is yet another guide for beginners, the parent site may also be of use.


Last updated 08/11

Back to the top of my home page.