LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Print Subscribe to Linux Subscribe to Newsletters
Linux & Unix > Excerpts >
Living Linux

Processing TeX and LaTeX Files

04/12/2000

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 http://www.tug.org/teTeX/.

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:

  • A Gentle Introduction to TeX (TeX format)
  • The Not So Short Introduction to LaTeX (.zip)

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 src.zip

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




Tagged Articles

Be the first to post this article to del.icio.us

Recommended for You

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

Sign up today to receive special discounts,
product alerts, and news from O'Reilly.
Privacy Policy >
View Sample Newsletter >
  • Youtube
  • http://www.youtube.com/OreillyMedia
  • Twitter
  • Subscribe
  • View All RSS Feeds >
O'Reilly Media

800-889-8969 or 707-827-7019
Monday-Friday 7:30am-5pm PT
©2011, O'Reilly Media, Inc.
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
  • About O'Reilly
  • Academic Solutions
  • Contacts
  • Customer Service
  • Careers
  • Press Room
  • Privacy Policy
  • Terms of Service
  • Writing for O'Reilly
  • Community
  • Authors
  • Forums
  • Membership
  • Newsletters
  • RSS Feeds
  • User Groups
  • More O'Reilly Sites
  • igniteshow.com
  • makerfaire.com
  • makezine.com
  • craftzine.com
  • labs.oreilly.com
  • Partner Sites
  • PayPal Developer Zone
  • O'Reilly Insights on Forbes.com