UNIX Has Its Way with Words
The four kinds of UNIX programs that handle text areText editors
Text formatters
Word processors
Desktop publishing programs
Before describing the most commonly used text editors in gory detail, we thought that you would want to know the differences among these four kinds of programs, in case you plan to impersonate a geek at the next meeting of your local UNIX users’ group.
Just the text, ma’am
A text editor enables you to
Create a file full of text
Edit the text
You can print a file by using the lp or lpr programs, as described in Chapter 9, although text editors can’t do boldface, headers or footers, italics, or all that other fancy stuff you need in order to produce modern, overformatted, professional-quality memos.You may want to use a text editor to write letters and reports. You certainly will use one to send electronic mail, as described in Chapter 17.The most commonly used text editors in the land of UNIX are vi , emacs , and pico . We have strong opinions about these editors, which becomes abundantly clear in the later sections in this chapter, where we tell you how to use each of them.
Text formatters aren’t really editors
Text formatters are programs that read text files and create nice-looking formatted output. You use a text editor to make a text file that contains special little commands only the formatter understands; the .IT command, for example, makes something italic. When you run the text formatter, it reads the text file, reads the special little commands, and creates a formatted file you can then print. You use lp or lpr to print the output of the text formatter.The most common UNIX text formatter is TeX , pronounced "teccccch" (like yeccccch), an arcane language popular among mathematicians and physicists because of its capability to format large, complex equations, and because it produces more aesthetically pleasing results than any of its competitors. A companion program, LaTeX , is designed to make TeX easier to use (relatively speaking, of course). (See the nearby sidebar, "Howdy, TeX !" for more info about TeX and LaTeX and where to get them.) Another common text formatter is troff . Some people use nroff (an older version of troff ), or groff , a newer GNU version of the program. With luck, you never have to use any of them. If your luck has run out, you may want to check out the section about troff , nroff , and groff in Chapter 9.
Donald E. Knuth created the popular TeX text formatter way back in the late 1970s. According to Knuth himself, TeX is a "typesetting system . . . intended for the creation of beautiful books — and especially for books that contain a lot of mathematics." Like troff and its cousins nroff and groff , TeX uses macros (prewritten bits of formatting code) to shield you (theoretically) from painful, low-level programming chores. In practice, TeX is hard to handle because it can do many, many things in a variety of ways, all proudly anti- intuitive. For people overwhelmed by the sheer complexity of TeX , Knuth created something called plain TeX , which is a slim and trim, stripped-down version of TeX . Because TeX overwhelms almost everyone, almost everyone uses plain TeX rather than TeX itself.Over the years, various intrepid UNIX hackers have taken it upon themselves to write their own sets of macros that work with TeX . The best known is probably LaTeX (the La part comes from the last name of its creator, Leslie Lamport). To make a long story short, LaTeX simplifies TeX by letting you describe the structure of a document without making you worry about the way the document looks (sort of like using the built-in styles in a word processor, such as Microsoft Word). Other macro packages for TeX include Eplain , Lollipop , pdfTeX (for creating books in Adobe Acrobat), and HyperTeX (for creating hypertext documents, such as Web pages, with TeX ).Like many things UNIX, TeX and the TeX source code and documentation are available for free; you can download them from various FTP and Web sites on the Internet. Also, you can buy one of a number of commercial versions of TeX; you get technical support and, in some cases, additional features in exchange for your money.The best source of information about TeX , LaTeX , and related subjects is The TeX Users Group home page on the World Wide Web (at www.tug.org/ ) or one of the many TeX Usenet newsgroups, such as comp. text.tex .
Cuisinarts for text: Word processors
Word processors combine the capabilities of text editors and text formatters. Most word processors are (or try to be) WYSIWYG (an acronym for What You See Is What You Get), which enables you to see on-screen how the document (that’s what they call their files) will look when you print them.Several surprisingly good, free word processors are available for UNIX. KWord, which comes with the KDE desktop package, is a simple but quite usable word processor. AbiWord is quite similar to Microsoft Word, and OpenOffice.org contains equivalents to most of the Microsoft Office. When writing this original version of this book in 1993, we used troff , but for the current edition we used OpenOffice.org Writer, which produced files that, to our editor’s relief, work fine in Microsoft Word.
Most UNIX users think that word processors are for wimps (what you see is all you’ve got) because they like the unintelligible and unmemorable commands used by text formatters and prefer to imagine what their text will look like when it is printed rather than be able to see it on-screen. Text formatters can do more complex things than word processors can, such as format complicated mathematical expressions, lay out multi-page tables, and neatly organize sections and headers of huge, book-length documents. But that’s probably not your problem.
Desktop publishing does it all
A desktop publishing (DTP) program resembles a fancy word processor. It can do everything a word processor can, plus things you need only if you are printing a book, newsletter, or something else that looks fancy. DTPs have facilities for creating tables of contents and indexes, maintaining cross- references — you name it. For writing an occasional memo, a desktop publishing program is definitely overkill.The most popular desktop publishing program for UNIX is Adobe FrameMaker (available for PCs and Macintoshes also).TeX and some versions of troff are available for free, which explains why they remain so popular (big surprise, eh?). All desktop publishers are commercial products that cost extra. Lots extra.
vi and emacs and pico are your friends
The rest of this chapter explains how to use each of the Big Three text editors (vi , emacs , and pico ), along with some words about how to use the prehistoric but not yet extinct ed (who, as you will see, is not your friend). Even if you use a word processor or desktop publishing program, you may need to use a text editor to do some things, such as these tasks:
Write electronic mail (see Chapter 17).
Create or edit text files called shell scripts, which enable you to create your own UNIX commands (see Chapter 12).
Create or edit special text files that control the way your UNIX setup works (see Chapter 7).
Write C programs (just kidding!).