LaTeX

1. Introduction

TeX is the document markup language and typesetting engine developed by Don Knuth.
LaTeX is a modern set
of TeX macro packages that make the parent language much more versatile and easier to use.
In essence, LaTeX (latex) takes source code in .tex format, and generates
an intermediate .dvi file, which is then processed by dvips to produce
printable .ps. In a nutshell, TeX generates output by gluing rectangles of typeset
material together. Several letters are glued together to form a word; several of these units
are glued together to form paragraphs; paragraph units are glued to figure units and tables
units, all of which are just rectangles, and these form the output page.

To compile your .tex files on the command line (see the man pages for

latex file.texdvips -t letter file -o

Or in a Makefile:

%.dvi: %.tex

 

 latex $& foo - bibtex$*%.ps: %.dvi dvips -t letter -o $@ -C$(NUM) -D$(DPI)$

The intermediate .dvi file is a device independent file which means that it
contains all of the typesetting information, but it is not ready to be sent to a rendering
device (printer). You may view these intermediate files with xdvi. For actual output by
a physical printing device, you will need to convert this using a tool designed to
generate the output you want: dvips makes PostScript files, dvipdf makes
Proprietary Data Formats, you get the point from the names. (It is also possible to
convert from .ps to .pdf, using ps2pdf.)

In the following sections, we will cover how to typeset a report and a letter.
We’ll cover how to create the finest looking math you have ever seen;
how to include tables, figures, and images in
your work; and how to cite references.

2. Basic LaTeX File

All basic LaTeX files have at a bare minimum a declaration of the class of the
document to be rendered, which may have options, and begin and end document tags.
If you LaTeX a document at this stage, you won’t get any errors, but you won’t
get any output. The further addition of LaTeX commands or plain text will be
compiled into your output code, as in this example, the (nearly) smallest LaTeX
that will compile. You will get a free page number at the bottom.

\documentclass{report}\begin{document}Hello, World!\end{document}

The class declaration determines what style the rendered document will take, one particular
document with no content change at all is rendered significantly differently simply by changing
its class from report to article. Options to the different classes include paper
size and orientation, font size, and more. They are specified as in
\documentclass[12pt,landscape]{book}. Optional arguments in LaTeX are indicated
by [ ] pairs, and required arguments by { }.

LaTeX source code is basically marked up plain text, so type in your full text, LaTeX it,
and then begin adding your special items of which there are many examples in this handout.
The first things to modify in your text are to signify a paragraph break with a double
character anywhere in a line (the rest of the line is a comment.) To comment a block of
code, you must comment every single line. There are certain specific command related characters
which must be escaped using a backslash to be represented after processing by LaTeX
(examples include: #, %, &, etc. which are coded as \#, \%, \&).

Certain useful macros are pre-defined by LaTeX. Macros available in most class files
include nicely formatted titles (\title{Title}), author name (\author{Your Name}),
and date (\date{\today}}). These are defined before the begin document tag, they are
invoked inside the document using \maketitle.
You may divide your source code into more manageable pieces by simply chopping it into many
.tex files and including them into a master .tex file using
\input{subfile.tex}. (These files do not require begin and end document tags, in
fact those will break the compilation process; input simply drops the block of text in place
of the input macro.) Every logical piece of a document is typically made into a section
(\section{Section Title}), we therefore like to put each section into its own LaTeX
file, which you can see in the source code for this handout.

More than you ever wanted to know about all of the available LaTeX commands can be found
in [2] and [3]. There are also LaTeX packages to do things like slides
(for Powerpoint-like slides, check out prosper:
http://sourceforge.net/projects/prosper/),
to format your work for journal
submissions, for music typesetting (MuSiXTeX), chemistry, and many other
things [1].

3. A Letter to Mom

There aren’t too many differences between a letter and a report in LaTeX. To begin
with, you define \documentclass{letter} and give yourself begin and end document
tags as before. Then you need to define your
addressing information (\address{}), name (\name{}), and signature line
(\signature{}) (also generally your name) outside of the document tags.

Inside the document tags, you can then define multiple letters using

\begin{letter}{Mom's address}Hello, Mom!\end{letter}

The begin letter tag takes a second argument, the recipient’s address. Then you supply
an \opening{Dear John:}, the letter body, and a \closing{Sincerely,}.
Enclosures (\encl{}) and carbon copies (\cc{}) can also be added. Then, end
your letter. No matter how many letters you put in the document tags, all will get their
information about you from the macros at the beginning of the file. Just run
latex and dvips as before.

This letter also gives two examples of lists, an enumerated list and an itemized list
(descriptive lists exist as well.)

4. IEEE Math

Mathematical equations are a specialty of LaTeX. There isn’t any equation out there that
isn’t easily described in the LaTeX language. You can put equations
like e=mc2 in the text
(using $e=mc^2$). The \$ denotes the start and end
of in-line math. Or you can do equations
outside the text, and they can be numbered or not. The names of the math macros are
generally quite logical as for \lim,
\sum, and \alpha.

5. Tables

Tables are a wonderful way to present certain types of information. In LaTeX we need
to first distinguish between two closely related environments with bearing on their
construction. The first is the obvious table. This environment wraps around a
conceptual table, a block of processed text, but does not itself create any content.
tabular is what actually sets blocks of text and line grids together to make a
readable table. In the tabular options r, l, c == right, left, center
column justifications, and the | (pipe) creates the vertical lines.
\hline makes the horizontal lines, & separates the columns, and \\ ends rows.
Go forth and tabulate!

Other things that apply globally and occur in this example include the \newcommand{}
directive, allowing you to write your own macros, and the \caption{} directive, which is
self-explanatory.

6. Figures

Figures are really quite simple, like the table environment, a figure is
simply a wrapper which signifies the block of imagery. Also, like the
table environment, it takes a \caption{}. The actual content of a figure
can be anything (even a tabular), but it is usually an image. The easiest way to
include an image is using the graphicsx package which you must include
(using \usepackage{}), which you
can then tell that you are using the dvips post-processor. So, we can simply code
\includegraphics[width=3in,height=6cm]{figure.eps} and produce a picture (where
width and height are optional).

7. Citing Sources

To include references to works that you have cited in you research, you need a helper
of LaTeX called bibTeX. bibTeX bibliography entries are stored in a .bib file.
The attached .bib file contains entries for all of the common reference types and
many obscure ones. To include a bibliography file in your document, you need to say
\bibliography{filename}. To cite the references within your document, you simply
use the command \cite{keyword}. Then to actually compile the bibliography into
typesettable citation references you run bibTeX as:

latex filebibtex filelatex filelatex filedvips -t letter file -o

We know this seems like of extra compilation. Because LaTeX can only typeset the text that is
available at
run-time, the first run of LaTeX will not generate any citations (or table, figure,
or section references). Running bibTeX generates two files, .bbl and .blg,
which contain the typesetting data we need. We must run LaTeX a second time (and
sometimes a third) for the citation numbers to register in the text. If we fail, we
will see [?].

9. Resources

1. Michel Goossens, Sebastian Rahtz, and Frank Mittelbach.
The LaTeX Graphics Companion: Illustrating Documents with
TeX and PostScript
.
2. Helmut Kopka and Patrick W. Daly.
A Guide to LaTeXe: Document Preparation for Beginners and
.
Addison-Wesley Publishing Company, Wokingham, England, second
edition, 1995.
3. Leslie Lamport.
LaTeX: A Document Preparation System User’s Guide and
Reference Manual
.