Thursday, October 18, 2007

Troff Text Processor for Typesetters

"The great strength of troff is the flexibility of the basic language and its programmability -- it can be made to do almost any formatting task."
-- Brian W. Kernighan, Rob Pike - The UNIX Programming Environment

Troff is a document processing system, and it's part of the default UNIX text processing tools.

  • troff - for output device that can handle variable-width fonts and different character sizes
  • nroff - produces output suitable for simple fixed-width terminals or line printers
  • groff - a GNU licensed implementation of the ditroff and all the troff preprocessors
  • unroff - a free flexible implementation of troff written in Scheme
Even though now it has been superseded by TEX and LATEX, troff is still quite common, as UNIX manual pages for the "man" command are written in troff, using the "man macros".

"Since bare troff is unusable by humans, a race of gods now gone created macro packages for mortals to use."
-- Brian Kernighan on the troff macro package.

On some systems manpages are stored in compressed formats, so, before we operate on such a manpage, we need to uncompress it.

Let's use groff and the man macros to convert a manpage to ps, and send it to the printer spooler.

% cat /usr/share/man/man7/bootparam.7.gz | gunzip | groff -man | lpr

We could also send it to ps2pdf to publish the manpage as pdf.

% cat /usr/share/man/man1/groff.1.gz | gunzip | groff -man > && ps2pdf && xpdf groff.pdf"

If you plan on doing anything serious with troff, you should take a look at Bell Labs Computing Science Technical Report #54, Troff User's Manual.