from Wikipedia, the free encyclopedia

troff [ tiːrɒf ] is a typesetting system which by AT & T for the operating system Unix was developed. It allows professional and high-quality typesetting , including typographical features such as different fonts and fonts , spacing , paragraphs , margins , automatic word division at the end of a line, footnotes and table of contents , to name just a few. There are extensions to display tables , diagrams and mathematical formulas . troff is a markup language such as B. HTML and is therefore written as pure text with a text editor .

troff is used in almost all UNIX-like systems for formatting online documentation ( man pages ).

troff and TeX are related to each other in that both pursue the goal of enabling high-quality typesetting. However, the approaches are very different, not only in the syntax, but also in the handling of the program packages and fonts.


Troff has its origin in a word processor 's program called RUNOFF written by Jerome H. Saltzer for, CTSS - operating system of the MIT in the mid-1960s. (Apparently the name came from the phrase in use at the time, I'll run off a document .)

Photo imagesetters worked with templates of the individual characters. A light source exposed a film through an appropriate arrangement of lenses and drawing stencils, letter by letter, line by line. A different font could be achieved by semi-automatically exchanging the character templates, changing the font style and rotating them internally. A stencil set always consisted of a font with different font styles. The imagesetter could manage a number of these sets of stencils, and this restriction also resulted in the need to “load” fonts at the beginning of the document.

Bob Morris ported RUNOFF to the GE- 635 architecture and named the program roff (an abbreviation of runoff ). It was rewritten as rf for the PDP-7 , and at the same time (1969) Douglas McIlroy was writing an expanded and simplified version of roff in the BCPL programming language .

The first version for Unix was developed on a PDP-7 that was at Bell Labs . In 1971 the developers needed a PDP-11 to continue working on the operating system. To justify the cost of this system, they proposed developing a document formatting system for the AT&T patent division. This first formatter was a reimplementation of McIllroys roff written by Joe F. Ossanna .

nroff ( Newer 'roff' ), was developed with regard to the previously restricted commands. It had a much more complicated syntax but was the basis for all later versions. However, it could only format output for character-oriented devices such as line printers , type wheel printers , computer terminals , etc.

When the labs got a Graphic Systems C / A / T phototype setter , Ossanna wrote an adapted version of nroff in PDP-11 assembly language that could control it. This version was called troff ( typesetter roff ), although many speculated that it actually meant Times roff due to the use of the Times Roman font family in troff as the default font.

The decision to use the PDP-11 and the C / A / T turned out to be a limitation. Ossanna ported troff to C , although it had meanwhile grown to 7000 lines of C / A / T dependent, uncommented program code. As the C / A / T got older and the manufacturer discontinued support, the need for troff to control other devices became a priority. However, Ossanna died of a heart attack before this could be realized.

So Brian W. Kernighan came up with the task of programming troff in C. This completely redeveloped version produced device-independent code that could be read very easily by drivers and translated into appropriate printer-specific output languages. This new version of troff (ditroff, for device independent 'troff' ) also had some enhancements such as: B. Drawing functions .

troff then became Documenter's WorkBench and was continuously developed at Bell Labs (which were renamed Unix System Laboratories , USL) until 1994. Then SoftQuad took over the maintenance. Brian Kernighan continued to develop drunk on his own. Therefore, there are currently three variants of Bell Labs troff . The source code of ditroff from Documenter's WorkBench was published on June 14, 2005 together with Solaris by Sun and placed under the CDDL open source license .

Internal structure

Troff can be understood as a filter . A text document is created with an editor, which is translated into another format using troff , taking into account the instructions embedded in the document text .

In the past, the photo exposure was controlled directly with the troff output code. With the advent of other high-resolution printing methods (e.g. laser printer ), troff was rewritten in such a way that a kind of meta code was generated, so-called device independent troff , or ditroff for short . Further filter programs then generated the final, device-specific code for control from this intermediate format.


Since the troff control commands are sometimes complex and can occur several times within a document, the possibility of creating macros was provided from the start. Various troff commands, e.g. B. to reduce the font size while changing the left and right indentation to a macro. This increases the clarity of the document enormously and, similar to the CSS for HTML or style templates in the known graphic word processors, enables a centralized format structure that has to be changed once when making adjustments and thus avoids changes in many places in the document.

Extensive macro packages have been developed for a wide variety of document styles. A typical troff distribution contains e.g. For example, the me macros for formatting scientific papers, man macros for creating Unix man pages , and the ms macros for books, technical documentation and reports.


When troff evolved into DWB, work began on various preprocessor programs, as not everything could be easily implemented in troff . These programs transform - again as filters - certain parts of a document into troff input. These filter programs have their own syntax and recognize their code in the troff document by means of certain key commands (which comprise exactly one line) and translate the code in between into troff control commands ( requests ).

Preprocessor function
tbl Table set
eqn Formulas and math expressions
pic Simple illustrations and flow charts (part of Documenters Workbench / ditroff)
ideal Character functions similar to pic
grap Graph, but converts this code into pic code, not directly troff
refer Bibliographical reference and quotation management
bib See refer above
soelim Load external text files that have to be processed by a preprocessor

nroff generates output for character-oriented devices such as line printers , type wheel printers , computer terminals etc. Commands that cannot be used (such as font changes) are ignored.


  • troff , by Bill Joy , was shipped up to SunOS-4.x Sun ; Since SunOS-5.x, Sun has been delivering ditroff
  • The Heirloom Documentation Tools are a version of ditroff with some extensions; the freely available source code is based on the programs of the same name from OpenSolaris
  • The SoftQuad DWB, which is based on the USL DWB 2.0 from 1994
  • The DWB 3.4 from Lucent Software Solutions (USL)
  • groff , a GNU implementation for troff and nroff

Drunk today

The troff family lost its popularity in the 1990s , but it is still used quite extensively. Although troff can be replaced by other programs such as Interleaf, FrameMaker and LaTeX , it is still the standard format for UNIX documentation, the so-called man pages .

The ability to output formatted plain text is probably the most important function of troff nowadays: the display of a man page on many modern Unixoid systems starts a nroff process in the background , which formats the man pages in troff format and sends them to a text viewer (e.g. B. more or less ).


Web links