Chapter 2) version of troff , which, like every GNU program, does all the stuff the originals do and about 47 other things, too. Because groff is free, whereas nroff and troff are subject to expensive licenses from whoever owns the original UNIX licensing rights this year, groff is all you see these days.
All the “roff” programs are batch formatters. In these programs, you type your document with formatting codes into a text file and then run the text file through groff , which produces a beautifully typeset version of your document, give or take all your typos and coding errors. Then you fix the document, re- groff , and so on. These programs are the antithesis of WYSIWYG (What You See Is What You Get) formatting.People still use groff , partly because it’s free and partly because you can do fancy stuff with highly structured documents that’s difficult or impossible with WYSIWYG formatters. We don’t expect that you’ll write a great many groff documents yourself, but you’ll probably run into some on the Internet or in software packages.With a bit of effort, you can turn groff documents into something legible. Assuming that you have a PostScript printer available, type a command like this one:
groff filename
Replace filename with the name of the text file you want to print. The groff program interprets the typesetting codes in the text file and tells the printer how to print your document.As you probably figured out if you got this far in this book, principle yields to hideous complication after you add a few practical details. This section describes some of the details and the ensuing complications.
Macro mania
Formatting a document by using troff and its cousins requires rather low-level detailed instructions using incomprehensible two-letter codes in the documents — instructions so detailed that even UNIX weenies find them tedious (and that’s saying a great deal). To relieve the tedium, most troff documents take advantage of macro packages that define higher-level instructions, which people use rather than the low-level stuff. (These macro packages serve roughly the same function as style sheets in Microsoft Word.) The troff program has been around for more than 25 years, and many macro packages have come and gone, although a few have stood the test of time. Because lazy typists have written all of them, each has a cryptic two- or three-letter name, all starting with -m , the flag code that tells groff to use the macro package. Table 9-1 lists a few popular macro packages.
Name Description Origin | ||
-ms | Manuscript macros | Bell Labs |
-mm | Different manuscript macros | Another part of Bell Labs |
-me | Eric’s macros | Somebody’s Ph.D. thesis at Berkeley (must have been a good thesis because he’s now the head of Google) |
-man | Manual page macros | Same place as -ms |
To tell groff to format a document with the -ms macros, for example, you type
groff -ms filename
Telling a priori what macros are used in what document is difficult, unless the author took pity and gave you a clue by naming the file mobydick.ms or the like. Fortunately, the worst that happens if you use the wrong macro package is that the document looks ugly. (It’s not totally illegible: The text is still there, but it’s formatted incorrectly.) You can try different macro packages and see which one works least badly. As a general rule, documents from academia usually use the –me macro package, whereas those from industry usually use -mm or -ms . Documents about the UNIX system itself usually use -ms because -ms was written by some of the same guys who did the original UNIX work, and pages from the online manual (what the man command shows you) use -man .
Let’s sneak a peek
One of the nicest things about groff is that it’s device independent, which means that it can reformat your document for any of several output devices. To format your document and display it on a normal, text-only terminal, use the nroff command:
nroff -ms filename | more
(This command actually calls groff , but tells it to format for plain-text output. Change the -ms to one of the other macro packages if necessary.) The more command displays the result a screen at a time. Press the spacebar to move from screen to screen, or press Q when you see enough.
Back in the mid-1970s, the whole idea of computerized document formatting and typesetting was much less established than it is now. Within AT&T, however, troff and the UNIX system it ran on rapidly became the standard for document preparation. Why? Two words: line numbers. AT&T files a large number of patents, and patent applications must have every fifth line numbered. The troff program was the first text formatter that could do that. The patent typists embraced troff (patent applications are revised and retyped about a thousand times before they’re finally sent to the patent office), and the rest, as they say, is history.
If you’re running X Windows, you can tell groff to display a page at a time, beautifully typeset in an X window, by typing this command:
groff -TX75 -ms filename
In the window that groff creates, press the spacebar to move from screen to screen or press Q when you see enough. If the type is too small to read, use -TX100 rather than -TX75 to make the text bigger. (You can’t use any other numbers; X comes with one set of fonts for 75 dot-per-inch screens and another for 100 dot-per-inch screens, so that’s what groff uses.)