troff (), short for "typesetter roff", is the major component of a
document processing system developed by
Bell Labs
Nokia Bell Labs, commonly referred to as ''Bell Labs'', is an American industrial research and development company owned by Finnish technology company Nokia. With headquarters located in Murray Hill, New Jersey, Murray Hill, New Jersey, the compa ...
for the
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
operating system. troff and the related
nroff were both developed from the original
roff.
While nroff was intended to produce output on terminals and line printers, troff was intended to produce output on
typesetting
Typesetting is the composition of text for publication, display, or distribution by means of arranging physical ''type'' (or ''sort'') in mechanical systems or '' glyphs'' in digital systems representing '' characters'' (letters and other ...
systems, specifically the
Graphic Systems CAT, which had been introduced in 1972. Both used the same underlying
markup language
A markup language is a Encoding, text-encoding system which specifies the structure and formatting of a document and potentially the relationships among its parts. Markup can control the display of a document or enrich its content to facilitate au ...
, and a single source file could normally be used by nroff or troff without change.
''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 and 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
A man page (short for manual page) is a form of software documentation found on Unix and Unix-like operating systems. Topics covered include programs, system libraries, system calls, and sometimes local system details. The local host administ ...
, mv macros for creating mountable
transparencies
A transparency, also known variously as a viewfoil or foil (from the French word "feuille" or sheet), or viewgraph, is a thin sheet of transparent flexible material, typically polyester (historically cellulose acetate), onto which figures can be ...
, and the ms and mm macros for letters, books, technical memoranda, and reports.
History
''troffs origins can be traced to a
text-formatting program called
RUNOFF, which was written by
Jerome H. Saltzer for
MIT
The Massachusetts Institute of Technology (MIT) is a private research university in Cambridge, Massachusetts, United States. Established in 1861, MIT has played a significant role in the development of many areas of modern technology and sc ...
's
CTSS operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
in the mid-1960s. (The name allegedly came from the phrase ''I'll run off a document''.)
Bob Morris ported it to the
GE 635 architecture and called the program
roff (an abbreviation of ''runoff''). It was rewritten as
rf for the
PDP-7
The PDP-7 is an 18-bit computing, 18-bit minicomputer produced by Digital Equipment Corporation as part of the Programmed Data Processor, PDP series. Introduced in 1964, shipped since 1965, it was the first to use their Flip-Chip module, Flip- ...
, and at the same time (1969),
Doug McIlroy
Malcolm Douglas McIlroy (born 1932) is an American mathematician, engineer, and programmer. As of 2019 he is an Adjunct Professor of Computer Science at Dartmouth College.
McIlroy is best known for having originally proposed Unix pipelines and de ...
rewrote an extended and simplified version of ''roff'' in the
BCPL
BCPL ("Basic Combined Programming Language") is a procedural, imperative, and structured programming language. Originally intended for writing compilers for other languages, BCPL is no longer in common use. However, its influence is still f ...
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
.
The first version of
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
was developed on a PDP-7 which was sitting around
Bell Labs
Nokia Bell Labs, commonly referred to as ''Bell Labs'', is an American industrial research and development company owned by Finnish technology company Nokia. With headquarters located in Murray Hill, New Jersey, Murray Hill, New Jersey, the compa ...
. In 1971 the developers wanted to get a
PDP-11
The PDP–11 is a series of 16-bit minicomputers originally sold by Digital Equipment Corporation (DEC) from 1970 into the late 1990s, one of a set of products in the Programmed Data Processor (PDP) series. In total, around 600,000 PDP-11s of a ...
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 (''newer "roff"'') 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 review
Peer review is the evaluation of work by one or more people with similar competencies as the producers of the work (:wiktionary:peer#Etymology 2, peers). It functions as a form of self-regulation by qualified members of a profession within the ...
ers, who thought that manuscripts using ''troff'' had been published before.
As such, the name ''troff'' is pronounced rather than *.
With ''troff'' came ''nroff'' (they were actually almost the same program), which was for producing output for
line printer
A line printer Printer (computing), prints one entire line of text before advancing to another line. Most early line printers were
printer (computing)#Impact printers, impact printers.
Line printers are mostly associated with unit record eq ...
s and character
terminals. It understood everything ''troff'' did, and ignored the commands which were not applicable, e.g.,
font
In metal typesetting, a font is a particular size, weight and style of a ''typeface'', defined as the set of fonts that share an overall design.
For instance, the typeface Bauer Bodoni (shown in the figure) includes fonts " Roman" (or "regul ...
changes.
Ossanna's ''troff'' was written in
PDP-11
The PDP–11 is a series of 16-bit minicomputers originally sold by Digital Equipment Corporation (DEC) from 1970 into the late 1990s, one of a set of products in the Programmed Data Processor (PDP) series. In total, around 600,000 PDP-11s of a ...
assembly language
In computing, assembly language (alternatively assembler language or symbolic machine code), often referred to simply as assembly and commonly abbreviated as ASM or asm, is any low-level programming language with a very strong correspondence bet ...
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
Brian Wilson Kernighan (; born January 30, 1942) is a Canadian computer scientist.
He worked at Bell Labs and contributed to the development of Unix alongside Unix creators Ken Thompson and Dennis Ritchie. Kernighan's name became widely known ...
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'' (often called ditroff for ''device independent 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.
In 1983, ''troff'' was one of several UNIX tools available for Charles River Data Systems'
UNOS operating system under
Bell Laboratories
Nokia Bell Labs, commonly referred to as ''Bell Labs'', is an American industrial research and development company owned by Finnish technology company Nokia. With headquarters located in Murray Hill, New Jersey, the company operates several lab ...
license.
The ''troff'' collection of tools (including
pre- and post-processors) was eventually called
Documenter's WorkBench (DWB), and was under continuous development in Bell Labs and later at the spin-off
Unix System Laboratories
Unix System Laboratories (USL), sometimes written UNIX System Laboratories to follow relevant trademark guidelines of the time, was an American software laboratory and product development company that existed from 1989 through 1993. At first wh ...
(USL) 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:
* the SoftQuad DWB, based on USL DWB 2.0 from 1994;
* the DWB 3.4 from
Lucent
Lucent Technologies, Inc. was an American multinational telecommunications equipment company headquartered in Murray Hill, New Jersey. It was established on September 30, 1996, through the divestiture of the former AT&T Technologies busines ...
Software Solutions (formerly USL);
* troff,
Plan 9 edition.
While ''troff'' has been supplanted by other programs such as
Interleaf
Interleaf, Inc. was a company that created computer software products for the technical publishing creation and distribution process. Founded in 1981, its initial product was the first commercial document processor that integrated text and graphi ...
,
FrameMaker
Adobe FrameMaker is a document processor designed for writing and editing large or complex documents, including structured documents. It was originally developed by Frame Technology Corporation, which was bought by Adobe.
Overview
FrameMake ...
, and
LaTeX
Latex is an emulsion (stable dispersion) of polymer microparticles in water. Latices are found in nature, but synthetic latices are common as well.
In nature, latex is found as a wikt:milky, milky fluid, which is present in 10% of all floweri ...
, 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
Ancient history is a time period from the beginning of writing and recorded human history through late antiquity. The span of recorded history is roughly 5,000 years, beginning with the development of Sumerian cuneiform script. Ancient hi ...
systems, as well as modern successors such as the ditroff-based open-sourced versions found on
OpenSolaris
OpenSolaris () is a discontinued open-source computer operating system for SPARC and x86 based systems, created by Sun Microsystems and based on Solaris. Its development began in the mid 2000s and ended in 2010.
OpenSolaris was developed as ...
and
Plan 9 from Bell Labs
Plan 9 from Bell Labs is a distributed operating system which originated from the Computing Science Research Center (CSRC) at Bell Labs in the mid-1980s and built on UNIX concepts first developed there in the late 1960s. Since 2000, Plan 9 has ...
, there are several versions of AT&T troff (CAT and ditroff-based) available under various open-source licenses.
Macros
In general, one was not encouraged to use troff directly, but rather go through some easier-to-use interface.
Troff includes macros that are run before starting to process the document. These macros include setting up page headers and footers, defining new commands, and influencing how the output will be formatted. The
command-line argument
A command-line interface (CLI) is a means of interacting with software via command (computing), commands each formatted as a line of text. Command-line interfaces emerged in the mid-1960s, on computer terminals, as an interactive and more user ...
for including a macro set is ''-m''name, 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:
* man for creating
manual pages
* mdoc for semantically-annotated
manual pages, which are better adapted to
mandoc conversion to other formats.
mandoc
is a fusion that supports both sets of manual commands.
[
* me for creating research papers
* mm for creating ]memorandum
A memorandum (: memorandums or memoranda; from the Latin ''memorandum'', "(that) which is to be remembered"), also known as a briefing note, is a Writing, written message that is typically used in a professional setting. Commonly abbreviation, ...
s
* ms for creating books, reports, and technical documentation
The ms macros were the first of these, developed at AT&T, before they were supplanted by the mm macros. One goal of the mm macros was that they be usable by the typing pool at Bell Labs and, over time, this happened and the mm macros became a standard at Bell Labs. AT&T made the mm macros commercially available for System V Unix. In contrast, the me macros were developed at Berkeley.
An example of a simple business letter prepared with the mm macros would be:
.TL
.ND "January 10, 1993"
.AU "Ms. Jane Smith"
.AT "Upcoming appointment"
.MT 5
Reference #A12345
.sp 4
Mr. Samuel Jones
.sp 0
Field director, Bureau of Inspections
.sp 0
1010 Government Plaza
.sp 0
Capitoltown, ST
.sp 3
Dear Mr. Jones,
.sp 2
.P
Making reference to the noted obligation to submit for state inspection our newly created production process, we request that you consider the possible inappropriateness of subjecting the innovative technologies of tomorrow to the largely antiquated requirements of yesterday. If our great state is to prosper in the twenty-first century, we must take steps
.B now ,
in
.I this
year of
.I this
decade, to prepare our industrial base for the interstate and international competition that is sure to appear. Our new process does precisely that. Please do not let it be undone by a regulatory environment that is no longer apt.
.P
Thank you for your consideration of our position.
.FC Sincerely
.SG
A comprehensive list of macros available is usually listed in a tmac(5)
manual page
A man page (short for manual page) is a form of software documentation found on Unix and Unix-like operating systems. Topics covered include programs, system libraries, system calls, and sometimes local system details. The local host administra ...
.
Preprocessors
As ''troff'' evolved, since there are several things which cannot be done easily in ''troff'', several preprocessor
In computer science, a preprocessor (or precompiler) is a Computer program, program that processes its input data to produce output that is used as input in another program. The output is said to be a preprocessed form of the input data, which i ...
s 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 (see pipes and filters). 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.
* eqn preprocessor allows mathematical formulae to be specified in simple and intuitive manner.
* tbl is a preprocessor for formatting tables.
* refer (and the similar program ''bib'') processes citations in a document according to a bibliographic database.
Three preprocessors provide ''troff'' with drawing capabilities by defining a domain-specific language
A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. There are a wide variety of DSLs, ranging ...
for describing the picture.
* '' pic'' is a procedural programming language
Procedural programming is a programming paradigm, classified as imperative programming, that involves implementing the behavior of a computer program as procedures (a.k.a. functions, subroutines) that call each other. The resulting program is a ...
providing various drawing functions like ''circle'' and ''box''.
* ''ideal'' allows the drawing of pictures declaratively, deriving the picture by solving a system of simultaneous equations
In mathematics, a set of simultaneous equations, also known as a system of equations or an equation system, is a finite set of equations for which common solutions are sought. An equation system is usually classified in the same manner as single e ...
based on vectors and transformations described by its input.
* ''grn'' describes the pictures through graphical elements drawn at absolute coordinates, based on the '' gremlin file format'' defined by an early graphics workstation.
In addition, there is a command soelim that removes .so
inclusion directives from the input text.
A typical structure of the pipeline might be:
soelim file , refer , ideal , pic , tbl , eqn , troff
Yet more preprocessors allow the drawing of more complex pictures by generating output for ''pic''.
* ''grap'' draws chart
A chart (sometimes known as a graph) is a graphics, graphical representation for data visualization, in which "the data is represented by symbols, such as bars in a bar chart, lines in a line chart, or slices in a pie chart". A chart can repres ...
s, like scatter plots and histograms
A histogram is a visual representation of the distribution of quantitative data. To construct a histogram, the first step is to "bin" (or "bucket") the range of values— divide the entire range of values into a series of intervals—and then ...
.
* ''chem'' draws chemical structure diagrams.
* ''dformat'' draws record-based data structures
In computer science, a data structure is a data organization and storage format that is usually chosen for efficient access to data. More precisely, a data structure is a collection of data values, the relationships among them, and the functi ...
.[J. L. Bentley. ''DFORMAT — A Program for Typesetting Data Formats''. CSTR #142, Bell Labs, April 1988.]
Other front-ends
Several other front-ends have been developed that are intended to be friendlier interfaces to troff.
One of them is Sanscribe, originally developed at Berkeley and then enhanced during the 1980s by several users including Intel
Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California, and Delaware General Corporation Law, incorporated in Delaware. Intel designs, manufactures, and sells computer compo ...
and InterACT. Used for writing memos, reports, documents, Sanscribe is built upon basic troff commands as well as the me macros and various pre- and post-processors such as soelim, eqn, tbl, grap, and pic. However it is a main program binary, not a preprocessor. The conditional inclusion capability renders it especially useful for maintaining multi-platform reference manuals. However, Sanscribe is fragile and prone to giving cryptic errors or producing weirdly formatted results.
A special-purpose front-end is vgrind, which generates nicely formatted source program listings, with such features as putting comments in italics, keywords in bold, and function names highlighted in margins. It can run either as a filter or as a main program with its output being passed to troff. It has support for the languages in use at Bell Labs facilities, including not just Fortran, C, and C++ but also domain-specific tools such as Bourne shell
The Bourne shell (sh) is a shell command-line interpreter for computer operating systems. It first appeared on Version 7 Unix, as its default shell. Unix-like systems continue to have /bin/sh—which will be the Bourne shell, or a symbolic lin ...
and yacc
Yacc (Yet Another Compiler-Compiler) is a computer program for the Unix operating system developed by Stephen C. Johnson. It is a lookahead left-to-right rightmost derivation (LALR) parser generator, generating a LALR parser (the part of a co ...
as well as those further afield such as Emacs Lisp
Emacs Lisp is a Lisp dialect made for Emacs.
It is used for implementing most of the editing functionality built into Emacs, the remainder being written in C, as is the Lisp interpreter.
Emacs Lisp code is used to modify, extend and customi ...
and Icon
An icon () is a religious work of art, most commonly a painting, in the cultures of the Eastern Orthodox, Oriental Orthodox, Catholic Church, Catholic, and Lutheranism, Lutheran churches. The most common subjects include Jesus, Mary, mother of ...
.
A different approach is employed by the CADiZ suite of tools for the Z notation
The Z notation is a formal specification language used for describing and modelling computing systems. It is targeted at the clear specification of computer programs and computer-based systems in general.
History
In 1974, Jean-Raymond Abria ...
. Rather than the cadiz
program being a preprocessor in the front of the pipeline, it interacts multiple times with troff
as both input and output, using saved files rather than a pipe. CADiZ also contains its own set of macros, called .ZA
to .ZZ
.
See also
*Desktop publishing
Desktop publishing (DTP) is the creation of documents using dedicated software on a personal ("desktop") computer. It was first used almost exclusively for print publications, but now it also assists in the creation of various forms of online co ...
*DocBook
DocBook is a Semantics (computer science), semantic markup language for technical documentation. It was originally intended for writing technical documents related to computer hardware and software, but it can be used for any other sort of docume ...
* groff GNU troff/nroff replacement
* nroff
*SGML
The Standard Generalized Markup Language (SGML; International Organization for Standardization, ISO 8879:1986) is a standard for defining generalized markup languages for documents. ISO 8879 Annex A.1 states that generalized markup is "based on t ...
*TeX
Tex, TeX, TEX, may refer to:
People and fictional characters
* Tex (nickname), a list of people and fictional characters with the nickname
* Tex Earnhardt (1930–2020), U.S. businessman
* Joe Tex (1933–1982), stage name of American soul singer ...
* Scribe (markup language)
References
External links
The Text Processor for Typesetters
Free troff implementation
User manual for the Plan 9 edition of troff
(In PostScript format)
section 3 describes the history of roff, nroff, troff, ditroff, tbl, eqn, and more.
* The original source code of nroff, troff and the preprocessors from AT&T Bell Labs in form of th
Documenter's Workbench (DWB) Release 3.3
(ported to current UNIX systems from http://www2.research.att.com/sw/download)
{{Plan 9 commands
Free typesetting software
Page description languages
History of software
Plan 9 commands
Unix text processing utilities