troff and Unix Text Processing

This page aims to be a catalog of all of the freely available information about the typesetting program troff and a guide to text processing using traditional Unix tools. The one notable exception is TeX and LaTeX, which are a world unto themselves.

What is troff?

troff, pronounced tee-roff and short for "typesetter roff", is a typesetting program that takes text mixed with a markup language and outputs a typeset version in one of several file formats, usually PostScript or its binary cousin PDF.

It has its origins in a program called RUNOFF, an archaism meaning "to make copies," written by Jerome H. Saltzer for the CTSS operating system in the 1960s. A number of increasingly sophisticated ports to other platforms were made over the next several years, resulting in roff and nroff ("newer roff"). Joe F. Ossanna of Bell Labs created the first version known as troff to utilize a Graphics Systems CAT phototypesetter. He also produced nroff, which is responsible for rendering man pages on Unix and Linux systems to the present day.

Ossanna died before a device-independent version could be written, so Brian Kernighan (co-creator of the C programming language and Unix itself) ported it from PDP-11 assembly language to C. This version was known as ditroff for "device independent troff" and is the canonical form of troff duplicated and extended by more recent implementations, of which there are several.

troff is an extremely powerful typesetting tool, but also very low level. (Kernighan likened it to an assembly language for typesetting.) As a result, a number of now-standard macro packages were written for it to make it easier for casual users. Additionally, there are standard set of preprocessors that translate high-level specifications of things like diagrams and tables into native troff instructions.

Today, troff and its more popular but vastly larger and slower competitor TeX are the only actively maintained full-featured freely available typesetting languages. Books and papers are still written for troff, and man pages are still output to terminal windows by nroff. There are five actively maintained open source implementations sporting various extensions of the original version.

Resources

Implementations

Documentation

General documentation for troff and its variants appears here. Some of this, especially the Bell Labs docs, go back decades but remain useful because current implementations are fully backward compatible.

Macro Packages

man

The man macro package is, perhaps unsurprisingly, for formatting manual pages ("man pages") on *nix systems.

mdoc

An enhancement and extension of man, mdoc is also intended for writing man pages.

me

The me macro package is designed for formatting technical research papers.

mm

The mm macro package was designed for writing technical memoranda at Bell Labs.

mom

The mom macros are Peter Schaffter's effort to provide a more modern and easier to use macro package for authors to use with groff.

ms

The ms macros are suitable for reports, letters, books, and technical documentation.

www (GNU groff)

The www macro package is a (currently alpha) attempt to provide HTML output for GNU groff.

Preprocessors

chem

dformat

eqn

grap

grn

ideal

pic

refer

tbl

External Tools