-->
Previous Table of Contents Next


Chapter 19
TeX and LaTeX

by Peter MacKinnon

In This Chapter
•   Typesetting versus writing
•   TeX
•   LaTeX: An enhancement of TeX
•   VirTeX and IniTeX

TeX (pronounced tech) is a text formatting system invented by Donald Knuth. It lets you produce professionally typeset documents by embedding TeX commands within a normal ASCII text file. This text file can then be converted to what is known as a dvi (device-independent file), which can be either previewed onscreen using an X Window program called xdvi or converted to a PostScript file for printing.

TeX is a powerful program in that it enables you to define specific typesetting commands (such as font size, page size, or space between lines). It also works as a programming language that enables you to create macros for defining more abstract units of text such as documents, headings, and paragraphs. The benefit of these high-level macros is that they enable you to concentrate on the writing of a document, not the typesetting. The key appeal of TeX for engineers and scientists is that it supports the typesetting of complex mathematical formulas.

Typesetting Versus Writing

The usefulness of a document can be limited by its appearance. Consider two documents: one that is well-organized with clearly defined units of text such as chapters, headings, and paragraphs, and another that has no paragraph breaks and no space between lines. The first document is much more appealing to the reader, whereas the second document is downright painful to read. So, despite the best efforts of an author to create a magnum opus, or even a recipe for strawberry jam, the meaning behind the words may get lost in a typographical abyss.

In book publishing, authors aren’t usually responsible for anything beyond the genius of their words. They usually leave the design and crafting of the book to a book designer. This person then hands the design template to page layout technicians. TeX performs this book design and typesetting role for you, enabling you, the author, to be your own publisher. It gives you control over the publication of your own material while still allowing you to concentrate on what you’re supposed to be writing about!

TeX

A TeX file can be created with any Linux text editor such as vi or emacs. You can enter text into a file called arkana.tex like this:


Do you suppose that Alfred Hitchcock would have had as successful a

directing

career if he did not have the considerable talents of actors Cary Grant

and

James Stewart in his most popular films? That’s a tough one to answer…

\bye

After you save your file, use the TeX program to convert it to a dvi file using this command:


$ tex arkana

The resulting arkana.dvi file that is created contains your text. This file can be used by different output devices (hence the name) for viewing or printing. For example, if you want to print your dvi file to a PostScript printer, convert it to a ps format, and print it using the dvi2ps utility:


$ dvi2ps arkana.ps | lp

This assumes that the default printer is PostScript-capable. If you want to just preview how the text looks, use the X application xdvi:


$ xdvi arkana.dvi &

The tex command also produces a log file entitled arkana.log, containing any error and warning messages, and other information such as the number of pages of output. The beauty of all this indirect representation of TeX output is that the TeX source file and its resulting dvi are very portable, particularly from Linux to its ancestor UNIX.

Simple Text Formatting

Most of the work in creating a TeX document is putting in the words that discuss whatever you’re writing about. As shown earlier, it is fairly simple to create an unadorned TeX file: The only special command you used was \bye. This command tells the TeX program that it has reached the end of the document. The \bye command uses one of several characters that TeX treats with special interest, specifically the backslash or escape character. Here is the set of special characters that TeX recognizes: \, {, }, ~, #, $, %, ^, &, and the space character. The meaning behind these characters will be discussed as you progress.

One of the main conveniences of TeX is the intelligent way it deals with text. Words are any sequence of characters separated by whitespace characters. The number of whitespace characters between words is immaterial because TeX treats them as one character. Sentences are recognized by the last word preceding a ., ?, !, or :. Paragraphs are distinguished by a blank line following a sentence. Much like the spaces between words, TeX treats excess blank lines as redundant and ignores them. Thus, the text


How do you compare

these two terrific leading men? James Stewart had that good-natured,

All-American       charm      mixed

with a surprising element of vulnerability, uncommon

among     other major Hollywood actors.



Cary Grant, on the other

hand, was versatile     enough to play the villain as well as the suave

hero in many films.

is formatted by TeX as follows:


How do you compare these two terrific leading men? James Stewart had that

good-natured, All-American charm mixed with a surprising element of

vulnerability, uncommon among other major Hollywood actors.



Cary Grant, on the other hand, was versatile enough to play the villain as

well as the suave hero in many Hitchcock films.

You can also insert comments into your TeX file using the % character. Text following a % character is treated as a comment and not made part of the TeX output. The text


From her% Nothing to do with Hitchcock

% …nothing at all

e to there

is formatted as


From here to there


Previous Table of Contents Next