oreilly.comSafari Books Online.Conferences.


Living Linux

Processing TeX and LaTeX Files


As I mentioned a few weeks ago, one of the more popular and capable typesetting tools for Linux is TeX. It comes with all of the major Linux distributions. The TeX system itself, a large collection of files and data, is packaged in distributions; TeTeX is the TeX distribution designed for Linux, and you can find it on the Web at

Donald Knuth, the world's foremost authority on algorithms, wrote TeX in 1984 as a way to typeset his books, because he wasn't satisfied with the quality of available systems. Since then, many extensions to the TeX formatting language have been made -- the most notable being Leslie Lamport's LaTeX, which is designed to facilitate the typesetting of structured documents. (LaTeX probably gets more day-to-day use than the plain TeX format, but in my experience, both systems are useful for different kinds of documents.)

While not everyone wants needs to write documents with TeX or LaTeX, these formats are widely used, especially on Linux systems. So every Linux user has the potential to encounter one of these files. This column tells you how to deal with them.

Getting sample input

When someone writes a document with TeX, they compose an input file, which is a plain text file that contains the text of the document, with the TeX formatting commands interspersed in it.

So first, we'll need to get some sample input files to process.

For the following examples, we'll use some tutorial files written on the subject of learning TeX and LaTeX itself -- Michael Doob's A Gentle Introduction to TeX and Tobias Oetiker's The Not So Short Introduction to LaTeX. These tutorials are available on the Net in the respective formats they describe. You can download them here:

The TeX input for A Gentle Introduction to TeX is one file, called gentle.tex.

The Not So Short Introduction to LaTeX is a somewhat larger document, and its chapters have been put in separate files. So the LaTeX input is a collection of several files in a .zip archive -- after you download it, use the unzip tool to extract all of the files:

$ unzip

This command makes a new subdirectory, called src, which contains all of the LaTeX input for this document.

To view or print a TeX or LaTeX document, you process its input file.

Is it a TeX or LaTeX file?

TeX and LaTeX files are processed with different commands. So, the first step is figuring out which format a file is in.

By convention, TeX files always have a .tex file name extension.

LaTeX input files sometimes have a .latex or .ltx file name extension instead -- but not always. One way to tell if a .tex file is actually in the LaTeX format is to use grep to search the file for the text "\document", which every LaTeX (and not TeX) document will have. (The regular expresion to use with grep is '\\document', since slash characters must be specified with two slashes.)

For example, to determine whether the file "gentle.tex" is a plain TeX or LaTeX document, type:

$ grep '\\document' gentle.tex RET

In this example, grep returned to the shell prompt without matching and printing any lines at all, so you can safely assume that the file gentle.tex is a plain TeX document.

Pages: 1, 2

Next Pagearrow

Linux Online Certification

Linux/Unix System Administration Certificate Series
Linux/Unix System Administration Certificate Series — This course series targets both beginning and intermediate Linux/Unix users who want to acquire advanced system administration skills, and to back those skills up with a Certificate from the University of Illinois Office of Continuing Education.

Enroll today!

Linux Resources
  • Linux Online
  • The Linux FAQ
  • Linux Kernel Archives
  • Kernel Traffic

  • Sponsored by: