Processing TeX and LaTeX Files
Processing the input files
Use the tex command to process TeX files. It takes as an argument
the name of the TeX source file to process, and it writes an output
file in DVI ("Device Independent") format with the same base file name
as the source file, but with a .dvi extension.
To process the TeX file gentle.tex, type:
$ tex gentle.tex RET
That's all there is to it! The output is written to a DVI file
named gentle.dvi. (During processing, TeX makes other files, too --
for example, you'll find a gentle.log file, which will contain a log
of error messages, if any; you can safely ignore these files -- and
delete them if you wish.)
The latex command works just like tex, but you use it to process
LaTeX files.
The Oetiker text consists of several separate LaTeX files in the
src directory, with the file lshort.tex being the base file for the
document -- when you process this file, LaTeX will read and include
all of its subsidiary files.
To prepare the LaTeX file lshort.tex, type:
$ latex lshort.tex RET
This command outputs a DVI file, lshort.dvi.
 |
You may need to run latex on a file several times consecutively --
LaTeX documents sometimes have indices and cross references which,
because of the way that LaTeX works, take another run through latex to
fully process. |
So to make sure all of the cross references in this document have
been generated, run latex on it once again:
$ latex lshort.tex RET
The lshort.dvi file will be rewritten with an updated version
containing the proper page numbers in the cross reference and index
entries.
What to do with the output
Ok, so you've successfully made a DVI output file from your TeX or
LaTeX input. Now what?
Once you've produced a DVI output file, you can preview it on the
screen, print it out, or convert it to another file format.
Use the xdvi tool to preview it on the screen. It shows how the
document will look should you print it, and lets you view it at
different magnifications.
For example, to preview the DVI file lshort.dvi, type:
$ xdvi lshort.dvi RET
This command opens xdvi in a new window and displays the first page
of the document; on the xdvi toolbar you'll find buttons for enlarging
the view, moving through pages, and exiting the viewer.
If you have a printer installed on your system, you can print the
DVI file. The dvips tool will convert the DVI file to PostScript, and
spool it to the printer (most systems with non-PostScript printers are
set up with filters to convert the PostScript to a format the printer
understands).
To print the file gentle.dvi, type:
$ dvips gentle.dvi RET
Instead of sending the PostScript output to the printer, you can
write it to a file. Give the name of the file with the -o option.
To write a PostScript file lshort.ps from the file lshort.dvi,
type:
$ dvips -o lshort.ps lshort.dvi RET
This writes a new file in PostScript format, lshort.ps; it doesn't
alter the original DVI file.
The ps2pdf tool, part of the gs (Ghostscript) package, converts a
PostScript file to PDF. Give as arguments the name of the PostScript
file, and the name of the PDF file to write to. For example:
$ ps2pdf lshort.ps lshort.pdf RET
This writes a new file in PDF format called lshort.pdf. The
original file lshort.ps is not altered.
To convert the PostScript output to plain text, use ps2ascii, which
works just like ps2pdf but outputs a file in plain text:
$ ps2ascii lshort.ps lshort.txt RET
This command converts the PostScript file to plain text and writes
it to lshort.txt. (You can also use the gs tool to convert the
PostScript output to an output format suitable for another printer or
output device.)
Next week: for those who want to dive into the world of TeX, some
document templates to make it easier.
Michael Stutz
was one of the first reporters to cover Linux and the free software movement in the mainstream press.
Read more Living Linux columns.
Discuss this article in the O'Reilly Network Linux Forum.
Return to the Linux DevCenter.
Prev [1] [2]