- Create the "source file" (the tex document).
- Compile the source file with tex or latex.
- View or print the compiled file.

**Editing:**Use a text editor to create a text file containing the "tex source", and give the file a name with a ".tex" extension, say "paper.tex". The two standard editors on Unix system are emacs and vi. Pico, the editor in pine, is easy to learn, but its capabilities are very limited, and I would recommend that you learn emacs. Both emacs and vi (in the enhanced version "vim") are available in Windows versions.**Compiling:**Assuming your tex file is "paper.tex", issue the command**latex paper**to run the file through the latex program. (You can leave off the extension ".tex" in "paper.tex".) (For plain tex or amstex documents, the corresponding commands would be "tex paper" and "amstex paper", though you will likely not need this.) Often there will be error messages, in which case you'll have to exit the compile stage (type "x" at the question mark prompt), re-edit the file, and try again. Once all bugs have been fixed, the latex program will complete its run without error messages and create a file named "paper.dvi" (and some auxiliary files). This is the file that can be viewed on the screen or sent to the printer.**Previewing:**To view the file on the screen, use**xdvi paper**. (Again the extension ".dvi" can be left off; be sure, however, not to use the name of the original file "paper.tex" - xdvi operates on the dvi file, not the tex file.)**Printing:**To send the file to the printer (which, by default, is ah130, unless you have changed it to something else), issue the command**dvips paper**. In order not to waste paper, you should do this only at the very end of the process, or if there are a large number of errors. Most of the time, you can check a file by previewing it on the screen with xdvi. As the name suggests, dvips converts a dvi file to a postscript (ps) file; by default, the postscript output produced by this program is immediately sent to the printer. If instead, you want to save the postscript onto a file, use dvi with the "-o" option: e.g.,**dvips paper -o paper.ps**saves the postscript output onto a file "paper.ps" (which you can view with "gv").**Generating a pdf file:**To create a pdf version of your document (e.g., in order to post it on a website), use**pdflatex**instead of**latex**to compile the TeX file:**pdflatex paper**will generate**paper.pdf**in a single step, without an intermediate dvi file.

\documentclass{article} \begin{document} Hello world. \end{document}The essential parts of this document are:

**A "\documentclass{...}" statement.**
This determines the general format
of the document (such as font sizes of headings, whether or not
to indent paragraphs, etc.).
There exist hundreds of possible
so-called "document classes", but the two standard ones (and the only
ones you'll probably need) are "article" and
"amsart". The latter is the AMS version of "article" and automatically
loads the AMS enhancements to LaTeX. With "article", you can still get
these enhancements, but you have to explicitly load them by adding a
line "\usepackage{amsmath}" after the
"\documentclass" line. Both "article" and "amsart" can be used
as general purpose document classes -
your document does not have to be an "article".

**A "\begin{document} ... \end{document} pair.** This is where
the body of the document goes (body meaning everything except "title
matter" (title, author, date, etc.).

Exercise 1.1:Create a short tex document similar to the above example, call it "paper.tex" (say), and compile and preview the file as explained above.

Exercise 1.2:See what happens when you delete (or accidentally forget) the "\begin{document}" part. However, instead of actually deleting this line, put a percentage sign in front of it, which has the same effect.

**Accents:** To get accents, precede the character with the accent
by an escape quote of the appropriate kind (left, right, or double):
For example, "Paul Erd\"os", "Andr\'e", "l'H\^opital's rule".

**Braces and parentheses:** Brackets and round parentheses can be
used as is and shouldn't be escaped,
but curly braces ("{","}") are used for grouping in TeX,
and don't get printed. To get curly braces in the output,
you must use the escaped versions, "\{", and "\}".

**Quotation marks:** The usual double quotation marks don't come out
correctly in TeX. To get correct double quotes, surround the quoted
phrase by a left and a right pair of single quotes (``TeX'').

Exercise 1.3:Replace "Hello World" by a couple of short paragraphs and rerun the file through latex, to see how TeX treats lines and paragraphs. Add some words with special symbols and accents for variety.

\documentclass{article} \author{Don Knuth} \title{The \TeX\ Book} \date{\today} \begin{document} \maketitle ...... \end{document}Note that the "title matter" material (author, title, etc.) goes

Exercise 1.4:Add a "title matter", similar to the one above, to your document, and rerun the file through latex. Also, see what happens if you "delete" (i.e., comment out) the "\maketitle" command.

\section{Special characters} \subsection{Accents} \subsection{Braces} \subsection{Dollar signs} .... \section{Sectioning} \section{Conclusion}

Exercise 1.5:Add sectioning commands like those above to your document and rerun the file through latex. Notice that LaTeX automatically numbers the sections. The numbering can be prevented by using "asterisk" versions of the sectioning commands: \section*{...}, \subsection*{...}, etc. Do that and rerun your program.

Exercise 1.6:Now replace "article" in "\documentclass{...}" first by "amsart" , and then by "book", and observe how the appearance of the document changes, depending on the documentclass chosen.

**Note on fonts in titles and section headings.**
In almost all cases, you should leave the choice
of fonts to TeX and not try to explicitly force a specific font, type
face, of type size. For example, you could make the section headings
larger than they normally would be by placing a command "\Huge" or
"\Large" in front of the title (as in "\section{\Huge Special
Characters}"). It does work (try it!),
**but this is very bad style and
should be avoided**,
since it defeats the point of having structuring
commands like "\section" (and has other undesirable "side effects").
Nonetheless, there are situations where you
might want to put something in boldface or italic, e.g., to highlight
a special term. You can do that with the command "\textbf{...}" (for
boldface), or "\textit{...}" (for italic). For example, you could start
an exercise as follows:

\textbf{Exercise 6.} \textit{Prove Fermat's Theorem.}

\begin{center} ... \end{center} \begin{quote} ... \end{quote} \begin{itemize} \item This is the first item \item This is the second item \item This is the last itme \end{itemize} \begin{equation} ... \end{equation} \begin{align} ... \end{align}The third example creates a bullet list. The last two examples are math environments for typesetting numbered equations and multiline numbered equations, respectively (see below).

**Text mode.** This is the normal, or default, mode of TeX. TeX
stays in that mode unless it encounters a special
instruction that causes it
to switch to one of the math modes, and it returns to text mode following
a corresponding instruction that indicates the end of math mode.

**Ordinary (inline) math mode.**
Mathematical material to be typeset
inline must be surrounded by single dollar signs: "$a^2 + b^2 =
c^2$". The dollar signs cause TeX to enter and exit (ordinary) math mode.

**Display math mode.**
Formulas that are to be displayed on a separate line should be
surrounded by a pair of escaped brackets ("\[" and "\]").
For example, to typeset the above equation as a displayed formula, use
the following:

\[ a^2 + b^2 = c^2 \]Note that the the two "display math symbols" have been put on lines by themselves. This is not necessary, as far as TeX is concerned (the above input is completely equivalent to the terse "\[a^2+b^2=c^2\]"), but it greatly improves the readability of the tex file, and it's a good habit to keep. (In contrast to conventions for c programs, there is no need for, or particular advantage to, indenting lines.)

**Note about the "double dollar sign" ($$) symbold:** In AmSTeX and
Plain TeX, material to be typeset in display math mode is enclosed in
a pair of double dollar signs.
While the double dollar sign does work in LaTeX, it is not part of the
"official" LaTeX command set (in fact, most books on LaTeX don't even
mention it) and its use is discouraged. The main advantage of the
bracket pair
"\[", "\]" over the old double dollar sign pair is that the bracket
pair differentiates between beginning and end of math mode, which in
turn facilitates error checking.

**Symbols in math mode.**
Some symbols take on special meanings inside math mode,
or are valid only in math mode. For example, the
caret (^) (denoting exponentiation) is not valid outside math mode, and
TeX will give an error message if it finds this symbol in text mode.

**Spacing in math mode.**
In math mode (both ordinary and display math),
TeX decides on spacings between symbols
in math mode, using rather sophisticated algorithms; in particular,
**any blank spaces inside math mode are ignored**,
For example, the formula "$a^2 + b^2 = c^2$ could have been typed as
"$a^2+b^2=c^2$", or even placed on two different lines, without any
difference in the output. Letting TeX figure out the spacings
almost always
results in very good looking output, and you should not put
explicit spaces into mathematical formulas. (There are a few situtations
where one might want to adjust the spacing, but those are extremely
rare, and for a beginner it is best to just let TeX do the work.)

**Equation numbering.**
There are a number of other "environments" that, just like the
escaped bracket pair, delimit display math mode. One of these is the
"\begin{equation} ...\end{equation}" pair which acts just like the
escaped bracket pair except that the formula gets automatically
numbered.

Exercise 1.7.Add a few equations to your documents, including some displayed equations. (Some examples of math formulas you can use as models or building blooks are: \sum_{k=1}^n k^2, \frac{a}{q}, \int_1^x\frac{1}{x}dx, \sin(x), \arcsin(x), e^{2 \pi i}. Typing math will be covered in detailed next time.) Typeset these with \begin{equation} ... \end{equation} and see how formulas get numbered. Now switch from the "article" document class to the "book" document class; what effect does this have on the numbering of equations?

* Last modified: Wed 18 Aug 2004 02:32:05 PM CDT
ajh@uiuc.edu
*