Troff


troff is the major component of a document processing system developed by AT&T Corporation for the Unix operating system.
troff features commands to designate fonts, spacing, paragraphs, margins, footnotes and more. Unlike many other text formatters, troff can position characters arbitrarily on a page, even overlapping them, and has a fully programmable input language. Separate preprocessors are used for more convenient production of tables, diagrams, and mathematics. Inputs to troff are plain text files that can be created by any text editor.
Extensive [|macro packages] have been created for various document styles. A typical distribution of troff includes the me macros for formatting research papers, man and mdoc macros for creating Unix man pages, mv macros for creating mountable transparencies, and the ms and mm macros for letters, books, technical memoranda, and reports.

History

troff's origins can be traced to a text-formatting program called RUNOFF, which was written by Jerome H. Saltzer for MIT's CTSS operating system in the mid-1960s.
Bob Morris ported it to the GE 635 architecture and called the program roff. It was rewritten as rf for the PDP-7, and at the same time, Doug McIlroy rewrote an extended and simplified version of roff in the BCPL programming language.
The first version of Unix was developed on a PDP-7 which was sitting around Bell Labs. In 1971 the developers wanted to get a PDP-11 for further work on the operating system. In order to justify the cost for this system, they proposed that they would implement a document-formatting system for the Bell Labs patents department. This first formatting program was a reimplementation of McIllroy's roff, written by Joe F. Ossanna.
When they needed a more flexible language, a new version of roff called nroff was written, which provided the basis for all future versions. When they got a Graphic Systems CAT phototypesetter, Ossanna modified nroff to support multiple fonts and proportional spacing. Dubbed troff, for typesetter roff, its sophisticated output amazed the typesetter manufacturer and confused peer reviewers, who thought that manuscripts using troff had been published before. As such, the name troff is pronounced rather than *.
With troff came nroff, which was for producing output for line printers and character terminals. It understood everything troff did, and ignored the commands which were not applicable, e.g., font changes.
Ossanna's troff was written in PDP-11 assembly language and produced output specifically for the CAT phototypesetter. He rewrote it in C, although it was now 7000 lines of uncommented code and still dependent on the CAT. As the CAT became less common, and was no longer supported by the manufacturer, the need to make it support other devices became a priority. Ossanna died before this task was completed, so Brian Kernighan took on the task of rewriting troff. The newly rewritten version produced a device-independent code which was very easy for post-processors to read and translate to the appropriate printer codes. Also, this new version of troff had several extensions, which included drawing functions. The program's documentation defines the output format of ditroff, which is used by many modern troff clones like GNU groff.
The troff collection of tools was eventually called Documenter's WorkBench, and was under continuous development in Bell Labs and later at the spin-off Unix System Laboratories through 1994. At that time, SoftQuad took over the maintenance, although Brian Kernighan continued to improve troff on his own. Thus, there are at least the following variants of the original Bell Labs troff in use:
While troff has been supplanted by other programs such as Interleaf, FrameMaker, and LaTeX, it is still being used quite extensively. It remains the default formatter for the UNIX documentation.
The software was reimplemented as groff for the GNU system beginning in 1990. In addition, due to the open sourcing of Ancient UNIX systems, as well as modern successors such as the ditroff based open-sourced versions found on OpenSolaris and Plan 9 from Bell Labs, there are several versions of AT&T troff available under various open-source licenses.

Macros

Troff includes sets of commands called macros that are run before starting to process the document. These macros include setting up page headers and footers, defining new commands, and generally influencing how the output will be formatted. The command-line argument for including a macro set is -mname, which has led to many macro sets being known as the base filename with a leading m.
The standard macro sets, with leading m are:
A more comprehensive list of macros available is usually listed in a tmac manual page.

Preprocessors

As troff evolved, since there are several things which cannot be done easily in troff, several preprocessors were developed. These programs transform certain parts of a document into troff input, fitting naturally into the use of "pipelines" in Unix — sending the output of one program as the input to another. Typically, each preprocessor translates only sections of the input file that are specially marked, passing the rest of the file through unchanged. The embedded preprocessing instructions are written in a simple application-specific programming language, which provides a high degree of power and flexibility.
Three preprocessors provide troff with drawing capabilities by defining a domain-specific language for describing the picture.
Yet more preprocessors allow the drawing of more complex pictures by generating output for pic.