22.B: Creating LaTeX Documents | 22: LaTeX | 22: LaTeX | Contents |
While it may seem odd to start by learning how to print a LaTeX file before learning how to create one, there is a method to our madness. Once you know how to convert your LaTeX files to postscript form, you can view your new creations on your computer terminal.
LaTeX files consist of a series of commands which instruct the compiler to take certain actions when typesetting your file. The first step towards printing a LaTeX file is to convert your file to a more machine-friendly form. This is done with the command latex (no surprise there).
Look at the practice file practice.tex (more is good for this). Notice that the file has the extension tex indicating it is a TeX or LaTeX file. Now use the latex command to compile the file
> latex practice.tex
LaTeXshould respond with:
This is TeX, Version 3.1415 (C version 6.1) (practice.tex LaTeX2e <1994/12/01> patch level 3 (/usr/local/lib/texmf/tex/latex2e/latex209.def Entering LaTeX 2.09 compatibility mode. (/usr/local/lib/texmf/tex/latex2e/tracefnt.sty) (/usr/local/lib/texmf/tex/latex2e/latexsym.sty)) (/usr/local/lib/texmf/tex/latex2e/article.cls Document Class: article 1995/01/31 v1.2y Standard LaTeX document class (/usr/local/lib/texmf/tex/latex2e/size10.clo)) (practice.aux) (/usr/local/lib/texmf/tex/latex2e/Ulasy.fd) (/usr/local/lib/texmf/tex/latex2e/OMScmr.fd) [1] (practice.aux) ) Output written on practice.dvi (1 page, 1472 bytes). Transcript written on practice.log.
This verbose yet cryptic response tells you that LaTeX has run successfully and has created the file practice.dvi (among others).
To view the typeset version of your file, you can preview the "device independent" or .dvi file with the X-Window previewer xdvi:
> xdvi practice.dvi
Since a .dvi file is device independent, a device like a printer cannot process it. Accordingly, you need to convert it to a postscript form so a postscript printer can print it. This is easy:
> xdvips practice.dvi
You should receive a remarkably short and clear response:
This is dvipsk 5.58f Copyright 1986, 1994 Radical Eye Software ' TeX output 1997.06.15:1552' -> practice.ps. [1]
In other words, you have just created the postscript version of your file practice.ps.
It is also possible to view a postscript file in an X Window:
> ghostview practice.ps
To print your file, use your standard postscript printer command lpr, but make sure that you send it to a postscript capable printer or printer queue:
> lpr -Pps practice.ps
Of course your documents will not always be easy for LaTeX to compile. You may get error messages while running latex, or you may get output you do not like. We will create an error to give you the opportunity to see an error message. (It saves money and trees to use xdvi and ghostview and thereby avoid printing draft documents.)
Bring up practice.tex in your favorite editor and remove the closing brace after the word document in the second line, that is, change \begin{document} to
\begin{document
Now save your file and LaTeX it again. (Consider this a quiz.)
Unix should respond with:
This is TeX, Version 3.1415 (C version 6.1) (practice.tex LaTeX2e <1994/12/01> patch level 3 (/usr/local/lib/texmf/tex/latex2e/latex209.def Entering LaTeX 2.09 compatibility mode. (/usr/local/lib/texmf/tex/latex2e/tracefnt.sty) (/usr/local/lib/texmf/tex/latex2e/latexsym.sty)) (/usr/local/lib/texmf/tex/latex2e/article.cls Document Class: article 1995/01/31 v1.2y Standard LaTeX document class (/usr/local/lib/texmf/tex/latex2e/size10.clo)) Runaway argument? {document ! Paragraph ended before \begin was complete.\par l.3 ?
The first lines should look familiar. Then LaTeX asks if you have a "Runaway argument?" Runaway argument explains the problem LaTeX is having, while the ? means it wants an answer or action from you. If you do not know what is wrong, you can request advice from LaTeX with the h command:
? h
Unix responds with the helpful and good-natured advice
I suspect you've forgotten a `}', causing me to apply this control sequence to too much text. How can we recover? My plan is to forget the whole thing and hope for the best. ?
Again it asks you what it should do. Since it recommends that we forget the whole thing and go ahead, just press <return> and stumble onward. It then gives you another error (a second confusion created by the first):
! LaTeX Error: Missing \begin{document}. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help.