ROFF(7) | Miscellaneous Information Manual | ROFF(7) |
The most common roff system today is the free software implementation GNU roff, groff(1). The pre-groff implementations are referred to as classical (dating back as long as 1973). groff implements the look-and-feel and functionality of its classical ancestors, but has many extensions. As groff is the only roff system that is available for every (or almost every) computer system it is the de-facto roff standard today.
In some ancient Unix systems, there was a binary called roff that implemented the even more ancient runoff of the Multics operating system, cf. section HISTORY. The functionality of this program was very restricted even in comparison to ancient troff; it is not supported any longer. Consequently, in this document, the term roff always refers to the general meaning of roff system, not to the ancient roff binary.
In spite of its age, roff is in wide use today, for example, the manual pages on UNIX systems (man pages/), many software books, system documentation, standards, and corporate documents are written in roff. The roff output for text devices is still unmatched, and its graphical output has the same quality as other free type-setting programs and is better than some of the commercial systems.
The most popular application of roff is the concept of manual pages or shortly man pages; this is the standard documentation system on many operating systems.
This document describes the historical facts around the development of the roff system; some usage aspects common to all roff versions, details on the roff pipeline, which is usually hidden behind front-ends like groff(1); an general overview of the formatting language; some tips for editing roff files; and many pointers to further readings.
The possibilities of the runoff language were quite limited as compared to modern roff. Only text output was possible in the 1960s. This could be implemented by a set of requests of length 2, many of which are still identically used in roff. The language was modelled according to the habits of typesetting in the pre-computer age, where lines starting with a dot were used in manuscripts to denote formatting requests to the person who would perform the typesetting manually later on.
The runoff program was written in the PL/1 language first, later on in BCPL, the grandmother of the C programming language. In the Multics operating system, the help system was handled by runoff, similar to roff's task to manage the Unix manual pages. There are still documents written in the runoff language; for examples see Saltzer's home page, cf. section SEE ALSO.
The name runoff was shortened to roff. The greatly enlarged language of Osanna's concept included already all elements of a full roff system. All modern roff systems try to implement compatibility to this system. So Joe Osanna can be called the father of all roff systems.
This first roff system had three formatter programs.
Osanna first version was written in the PDP-11 assembly language and released in 1973. Brian Kernighan joined the roff development by rewriting it in the C programming language. The C version was released in 1975.
The syntax of the formatting language of the nroff/troff programs was documented in the famous Troff User's Manual [CSTR #54], first published in 1976, with further revisions up to 1992 by Brian Kernighan. This document is the specification of the classical troff. All later roff systems tried to establish compatibility with this specification.
After Osanna had died in 1977 by a heart-attack at the age of about 50, Kernighan went on with developing troff. The next milestone was to equip troff with a general interface to support more devices, the intermediate output format and the postprocessor system. This completed the structure of a roff system as it is still in use today; see section USING ROFF. In 1979, these novelties were described in the paper [CSTR #97]. This new troff version is the basis for all existing newer troff systems, including groff. On some systems, this device independent troff got a binary of its own, called ditroff(7). All modern troff programs already provide the full ditroff capabilities automatically.
The source code of both the ancient Unix and classical troff weren't available for two decades. Fortunately, Caldera bought SCO UNIX in 2001. In the following, Caldera made the ancient source code accessible on-line for non-commercial use, cf. section SEE ALSO.
As a counter-measure to the galopping commercialization, AT&T Bell Labs tried to launch a rescue project with their Plan 9 operating system. It is freely available for non-commercial use, even the source code, but has a proprietary license that impedes the free development. This concept is outdated, so Plan 9 was not accepted as a platform to bundle the main-stream development.
The only remedy came from the emerging free operatings systems (386BSD, GNU/:Linux, etc.) and software projects during the 1980s and 1990s. These implemented the ancient Unix features and many extensions, such that the old experience is not lost. In the 21st century, Unix-like systems are again a major factor in computer industry — thanks to free software.
The most important free roff project was the GNU port of troff, created by James Clark and put under the It was called groff (GNU roff). See groff(1) for an overview.
The groff system is still actively developed. It is compatible to the classical troff, but many extensions were added. It is the first roff system that is available on almost all operating systems — and it is free. This makes groff the de-facto roff standard today.
Some roff implementations provide wrapper programs that make it easy to use the roff system on the shell command line. For example, the GNU roff implementation groff(1) provides command line options to avoid the long command pipes of classical troff; a program grog(1) tries to guess from the document which arguments should be used for a run of groff; people who do not like specifying command line options should try the groffer(1) program for graphically displaying groff files and man pages.
The preprocessors generate roff code that is fed into a roff formatter (e.g. troff), which in turn generates intermediate output that is fed into a device postprocessor program for printing or final output.
All of these parts use programming languages of their own; each language is totally unrelated to the other parts. Moreover, roff macro packages that were tailored for special purposes can be included.
Most roff documents use the macros of some package, intermixed with code for one or more preprocessors, spiced with some elements from the plain roff language. The full power of the roff formatting language is seldom needed by users; only programmers of macro packages need to know about the gory details.
There are a lot of free and commercial roff preprocessors. Some of them aren't available on each system, but there is a small set of preprocessors that are considered as an integral part of each roff system. The classical preprocessors are
Other known preprocessors that are not available on all systems include
The output produced by a roff formatter is represented in yet another language, the intermediate output format or troff output. This language was first specified in [CSTR #97]; its GNU extension is documented in groff_out(5). The intermediate output language is a kind of assembly language compared to the high-level roff language. The generated intermediate output is optimized for a special device, but the language is the same for every device.
The roff formatter is the heart of the roff system. The traditional roff had two formatters, nroff for text devices and troff for graphical devices.
Often, the name troff is used as a general term to refer to both formatters.
A roff postprocessor is a program that transforms troff output into a form suitable for a special device. The roff postprocessors are like device drivers for the output target.
For each device there is a postprocessor program that fits the device optimally. The postprocessor parses the generated intermediate output and generates device-specific code that is sent directly to the device.
The names of the devices and the postprocessor programs are not fixed because they greatly depend on the software and hardware abilities of the actual computer. For example, the classical devices mentioned in [CSTR #54] have greatly changed since the classical times. The old hardware doesn't exist any longer and the old graphical conversions were quite imprecise when compared to their modern counterparts.
For example, the Postscript device post in classical troff had a resolution of 720, while groff's ps device has 72000, a refinement of factor 100.
Today the operating systems provide device drivers for most printer-like hardware, so it isn't necessary to write a special hardware postprocessor for each printer.
A macro package that is to be used in a document can be announced to the formatter by the command line option see troff(1), or it can be specified within a document using the file inclusion requests of the roff language, see groff(7).
Famous classical macro packages are man for traditional man pages, mdoc for BSD-style manual pages; the macro sets for books, articles, and letters are me (probably from the first name of its creator Eric Allman), ms (from Manuscript Macros/), and mm (from Memorandum Macros/).
Requests are the predefined basic formatting commands similar to the commands at the shell prompt. The user can define request-like elements using predefined roff elements. These are then called macros. A document writer will not note any difference in usage for requests or macros; both are written on a line on their own starting with a dot.
Escape sequences are roff elements starting with a backslash They can be inserted anywhere, also in the midst of text in a line. They are used to implement various features, including the insertion of non-ASCII characters with font changes with in-line comments with the escaping of special control characters like and many other features.
Strings are variables that can store a string. A string is stored by the .ds request. The stored string can be retrieved later by the \* escape sequence.
Registers store numbers and sizes. A register can be set with the request .nr and its value can be retrieved by the escape sequence \n.
The classical macro packages take the package name as an extension, e.g. file.me for a document using the me macro package, file.mm for mm, file.ms for ms, file.pic for pic files, etc.
But there is no general naming scheme for roff documents, though file.tr for troff file is seen now and then. Maybe there should be a standardization for the filename extensions of roff files.
File name extensions can be very handy in conjunction with the less(1) pager. It provides the possibility to feed all input into a command-line pipe that is specified in the shell environment variable LESSOPEN. This process is not well documented, so here an example:
When editing a file within Emacs the mode can be changed by typing `M-x nroff-mode', where M-x means to hold down the Meta key (or Alt) and hitting the x key at the same time.
But it is also possible to have the mode automatically selected when the file is loaded into the editor.
All roff formatters provide automated line breaks and horizontal and vertical spacing. In order to not disturb this, the following tips can be helpful.
The following example shows how optimal roff editing could look.
Besides Emacs, some other editors provide nroff style files too, e.g. vim(1), an extension of the vi(1) program.
The "little language" roff papers are
In groff, the man page groff(1) contains a survey of all documentation available in groff.
On other systems, you are on your own, but troff(1) might be a good starting point.
This document is distributed under the terms of the FDL (GNU Free Documentation License) version 1.1 or later. You should have received a copy of the FDL on your system, it is also available on-line at the
This document is part of groff, the GNU roff distribution. It was written by it is maintained by
February 6, 2006 | Groff Version 1.19.2 |