roff(7) — Linux manual page

Name | Description | History | Using roff | roff Programming | File Name Extensions | Editing roff | Authors | See Also | COLOPHON

roff(7)               Miscellaneous Information Manual               roff(7)

Name         top

       roff - concepts and history of roff typesetting

Description         top

       The term roff describes a family of document formatting systems known
       by names like troff, nroff, ditroff, and groff.  A roff system
       consists of an extensible text formatting language and a set of
       programs for printing and converting to other text formats.  Unix-
       like operating systems distribute a roff system as a core package.

       The most common roff system today is GNU roff, groff(1).  groff
       retains the input conventions and functionality of its ancestors,
       with many extensions.  The ancestry of roff is described in section
       “History” below.  In this document, the term roff generally refers to
       this class of programs, with the exception of a roff(1) command
       provided in early Unix systems.  In spite of its age, roff remains in
       wide use today; for example, the manual pages on Unix systems
       (“man pages”), books about software and programming, and technical
       memoranda are written in roff.

       This document describes the history of the development of the “roff
       system”, typographical concepts that form the common background of
       all roff implementations, details on the roff pipeline which is
       usually hidden behind front-ends like groff(1), a general overview of
       the formatting language, some tips for editing roff files, and many
       suggestions for further reading.

History         top

       Computer-driven document formatting dates back to the 1960s.  The
       roff system itself is intimately connected with the Unix operating
       system, but its roots go back to the earlier operating systems CTSS
       and Multics.

   The predecessor RUNOFF
       roff's ancestor RUNOFF was written in the MAD language by Jerry
       Saltzer to prepare his Ph.D. thesis using the Compatible Time Sharing
       System (CTSS), a project of the Massachusetts Institute of Technology
       (MIT).  The program is generally referred to in full capitals, both
       to distinguish it from its many descendants, and because bits were
       expensive in those days; five- and six-bit character encodings were
       still in widespread usage, and mixed-case alphabetics seen as a
       luxury.  RUNOFF introduced a syntax of inlining formatting directives
       amid document text, by beginning a line with a period (an unlikely
       occurrence in human-readable material) followed by a “control word”.
       Control words with obvious meaning like “.line length n” were
       supported as well as an abbreviation system; the latter came to
       overwhelm the former in popular usage and later derivatives of the
       program.  A sample of control words from a RUNOFF manual of December
       1966 ⟨⟩
       was documented as follows with only a slight update to parameter syn‐
       tax.  They will be familiar to roff veterans.

                          Abbreviation   Control word
                                   .ad   .adjust
                                   .bp   .begin page
                                   .br   .break
                                   .ce   .center
                                   .in   .indent n
                                   .ll   .line length n
                                   .nf   .nofill
                                   .pl   .paper length n
                                   .sp   .space [n]

       In 1965, MIT's Project MAC teamed with Bell Telephone Laboratories
       and General Electric (GE) to inaugurate the Multics 
       ⟨⟩ project.  After a few years, Bell Labs
       discontinued its participation in Multics, famously prompting the
       development of Unix.  Meanwhile, Saltzer's RUNOFF proved influential,
       seeing many ports and derivations elsewhere.

       In 1969, Doug McIlroy wrote one such reimplementation of RUNOFF in
       the BCPL language for a GE 645 running GECOS at the Bell Labs loca‐
       tion in Murray Hill, New Jersey.  In its manual, the control commands
       were termed “requests”, their two-letter names were canonical, and
       the control character was configurable with a .cc request.  Other
       familiar requests emerged at this time; no-adjust (.na), need (.ne),
       page offset (.po), tab configuration (.ta, though it worked differ‐
       ently), temporary indent (.ti), character translation (.tr), and
       automatic underlining (.ul; on RUNOFF you had to backspace and under‐
       score in the input yourself).  .fi to turn on fill mode got the name
       it retains to this day.

       By 1971, McIlroy's runoff had been rewritten in DEC PDP-11 assembly
       language for the fledgling Unix operating system by Dennis Ritchie
       and seen its name shortened to roff (perhaps under the influence of
       Ken Thompson), but had added support for automatic hyphenation with
       .hc and .hy requests; a generalization of line spacing control with
       the .ls request; and what later roffs would call diversions, with
       “footnote” requests.  This roff indirectly funded operating systems
       research at Murray Hill, for it was used to prepare patent applica‐
       tions for AT&T to the U.S. government.  This enabled the group to
       acquire the aforementioned PDP-11; roff promptly proved equal to the
       task of typesetting the manual for “v1 Unix”, what would later become
       known as First Edition Research Unix, dated November 1971.

       Output from all of the foregoing programs was limited to line print‐
       ers and paper terminals such the IBM 2471 (based on the Selectric
       line of typewriters) and the Teletype Corporation Model 37.  Propor‐
       tionally-spaced type was unknown.

   New roff and Typesetter roff
       The first years of Unix were spent in rapid evolution.  The practi‐
       calities of preparing standardized documents like patent applications
       (and Unix manual pages), combined with McIlroy's enthusiasm for macro
       languages, perhaps created an irresistible pressure to make roff
       extensible.  Joe Ossanna's nroff, literally a “new roff”, was the
       outlet for this pressure.  By the time of Version 3 Unix (February
       1973)—and still in PDP-11 assembly language—it sported a swath of
       features now considered essential to roff systems; definition of
       macros (.de), diversion of text thence (.di), and removal thereof
       (.rm); trap planting (.wh; “when”) and relocation (.ch; “change”);
       conditional processing (.if); and environments (.ev).  Incremental
       improvements included assignment of the next page number (.pn); no-
       space mode (.ns) and restoration of vertical spacing (.rs); the sav‐
       ing (.sv) and output (.os) of vertical space; specification of
       replacement characters for tabs (.tc) and leaders (.lc); configura‐
       tion of the no-break control character (.c2); shorthand to disable
       automatic hyphenation (.nh); a condensation of what were formerly six
       different requests for configuration of page “titles” (headers and
       footers) into one (.tl) with a length controlled separately from the
       line length (.lt); automatic line numbering (.nm); interactive input
       (.rd), which necessitated buffer-flushing (.fl), and was made conve‐
       nient with early program cessation (.ex); source file inclusion in
       its modern form (.so; though RUNOFF had an “.append” control for a
       similar purpose) and early advance to the next file argument (.nx);
       ignorable content (.ig); and programmable abort (.ab).

       Third Edition Unix had also brought the pipe(2) system call, and the
       explosive growth of a componentized system based around it and a
       “filter model” that remains perceptible today.  Around this time tbl
       was developed.  Equally importantly, the Bell Labs site in Murray
       Hill acquired a Graphic Systems C/A/T phototypesetter, and with it
       came the necessity of expanding the capabilities of a roff system to
       cope with proportionally-spaced type, multiple point sizes and font
       styles.  Ossanna wrote a parallel implementation of nroff for the
       C/A/T, dubbing it troff (for “typesetter roff”).  Unfortunately, sur‐
       viving documentation does not illustrate what requests were imple‐
       mented at this time for C/A/T support; the troff(1) man pages in
       Fourth Edition Unix (November 1973)—and even Sixth (1975)—do not fea‐
       ture a request list, unlike nroff(1).  Apart from typesetter-driven
       features, version 4 Unix roffs added string definitions (.ds); made
       the escape character configurable (.ec); and enabled the user to
       write diagnostics to the standard error stream (.tm).  Around 1974,
       empowered with scalable fonts, italic type, and a symbol font spe‐
       cially commissioned by Bell Labs from Graphic Systems, Brian
       Kernighan and Lorinda Cherry implemented eqn for typesetting mathe‐
       matics.  In the same year, for Fifth Edition Unix, Ossanna combined
       and reimplemented the programs in C, using preprocessor conditions of
       that language to generate both from a single source tree.

       The syntax of the formatting language of the nroff/troff programs was
       documented in the famous Troff User's Manual [CSTR #54], first pub‐
       lished 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 specifica‐

       After Ossanna's death in 1977, Kernighan went on with developing
       troff.  In the late 1970s, Kernighan equipped 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” below.
       In 1979, these novelties were described in the paper [CSTR #97].
       This new troff version is the basis for all existing newer troff sys‐
       tems, including groff.  On some systems, this device-independent
       troff got a binary of its own called ditroff(7).  All modern troff
       implementations provide device-independent functionality.

       The source code of both the ancient Unix and classical troff weren't
       available for two decades.  Nowadays, it is accessible again (on-
       line) for non-commercial use; see SEE ALSO, below.

   groff — free GNU roff
       The most important free roff project was the GNU implementation of
       troff, written from scratch by James Clark and put under the GNU
       Public License ⟨⟩.  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.

   Free Heirloom roff
       An alternative is Gunnar Ritter's Heirloom roff project⟩ project, started in
       2005, which provides enhanced versions of the various roff tools
       found in the OpenSolaris and Plan 9 operating systems, now available
       under free licenses.  You can get this package with the shell com‐
              $ git clone

       Moreover, one finds there the Original Documenter's Workbench Release

Using roff         top

       Most people won't even notice that they are actually using roff.
       When you read a system manual page (man page) roff is working in the
       background.  But using roff explicitly isn't difficult either.

       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.

   The roff pipe
       Each roff system consists of preprocessors, roff formatter programs,
       and a set of device postprocessors.  This concept makes heavy use of
       the piping mechanism, that is, a series of programs is called one
       after the other, where the output of each program in the queue is
       taken as the input for the next program.

              cat file | ... | preproc | ... | troff options | postproc

       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

       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

       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.

       A roff preprocessor is any program that generates output that
       syntactically obeys the rules of the roff formatting language.  Each
       preprocessor defines a language of its own that is translated into
       roff code when run through the preprocessor program.  Parts written
       in these languages may be included within a roff document; they are
       identified by special roff requests or macros.  Each document that is
       enhanced by preprocessor code must be run through all corresponding
       preprocessors before it is fed into the actual roff formatter
       program, for the formatter just ignores all alien code.  The
       preprocessor programs extract and transform only the document parts
       that are determined for them.

       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

              tbl      for tables.
              eqn      for mathematical formulae.
              pic      for drawing diagrams.
              refer    for bibliographic references.
              soelim   for including macro files from standard locations.
              chem     for drawing chemical formulæ.

       Other known preprocessors that are not available on all systems

              grap   for constructing graphical elements.
              grn    for including gremlin(1) pictures.

   Formatter programs
       A roff formatter is a program that parses documents written in the
       roff formatting language or uses some of the roff macro packages.  It
       generates intermediate output, which is intended to be fed into a
       single device postprocessor that must be specified by a command-line
       option to the formatter program.  The documents must have been run
       through all necessary preprocessors before.

       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

   Devices and postprocessors
       Devices are hardware interfaces like printers, text or graphical
       terminals, etc., or software interfaces such as a conversion into a
       different text or graphical format.

       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 units per inch, 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.

roff Programming         top

       Documents using roff are normal text files decorated by roff
       formatting elements.  The roff formatting language is quite powerful;
       it is almost a full programming language and provides elements to
       enlarge the language.  With these, it became possible to develop
       macro packages that are tailored for special applications.  Such
       macro packages are much handier than plain roff.  So most people will
       choose a macro package without worrying about the internals of the
       roff language.

   Macro packages
       Macro packages are collections of macros that are suitable to format
       a special kind of documents in a convenient way.  This greatly eases
       the usage of roff.  The macro definitions of a package are kept in a
       file called name.tmac (classically  All tmac files are
       stored in one or more directories at standardized positions.  Details
       on the naming of macro packages and their placement is found in

       A macro package that is to be used in a document can be announced to
       the formatter by the command-line option -m, 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

   The roff formatting language
       The classical roff formatting language is documented in the Troff
       User's Manual [CSTR #54].  The roff language is a full programming
       language providing requests, definition of macros, escape sequences,
       string variables, number or size registers, and flow controls.

       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 start with a backslash, “\”.  They can appear almost
       anywhere, even in the midst of text on a line, and implement various
       features, including the insertion of special characters with “\(” or
       “\[]”, break suppression at input line endings with “\c”, font
       changes with “\f”, point size changes with “\s”, in-line comments
       with “\"”, and many others.

       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.

File Name Extensions         top

       Manual pages (man pages) take the section number as a file name
       extension, e.g., the filename for this document is roff.7, i.e., it
       is kept in section 7 of the man pages.

       The classical macro packages take the package name as an extension,
       e.g., for a document using the me macro package, for
       mm, for ms, file.pic for pic files, etc.

       But there is no general naming scheme for roff documents, though 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:

              LESSOPEN='|lesspipe %s'

       where lesspipe is either a system supplied command or a shell script
       of your own.

       More details for file name extensions can be found at

Editing roff         top

       All roff formatters provide automated line breaks and horizontal and
       vertical spacing.  In order to not disturb this, the following tips
       can be helpful.

       ·      Never include empty or blank lines in a roff document.
              Instead, use the empty request (a line consisting of a dot
              only) or a line comment .\" if a structuring element is

       ·      Never start a line with whitespace because this can lead to
              unexpected behavior.  Indented paragraphs can be constructed
              in a controlled way by roff requests.

       ·      Start each sentence on a line of its own, for the spacing
              after a dot is handled differently depending on whether it
              terminates an abbreviation or a sentence.  To distinguish both
              cases, do a line break after each sentence.

       ·      To additionally use the auto-fill mode in Emacs, it is best to
              insert an empty roff request (a line consisting of a dot only)
              after each sentence.

       The following example shows judicious line breaking in a roff input

              This is an example of a
              .I roff
              document that you can type into your text editor.
              This is the next sentence in the same paragraph.
              This is a longer sentence stretching over several input lines;
              abbreviations like cf. are easily identified because the dot is
              not followed by a line break.
              In the output, this sentence continues the same paragraph.

   Editing with Emacs
       The best program for editing a roff document is Emacs (or XEmacs);
       see emacs(1).  It provides an nroff mode that is suitable for all
       kinds of roff dialects.  This mode can be activated by the following

       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 press 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.

       ·      The most general method is to include the following 3 comment
              lines at the end of the file.

                     .\" Local Variables:
                     .\" mode: nroff
                     .\" End:

       ·      There is a set of file name extensions, e.g., the man pages
              that trigger the automatic activation of the nroff mode.

       ·      Theoretically, it is possible to write the sequence

                     .\" -*- nroff -*-

              as the first line of a file to have it started in nroff mode
              when loaded.  Unfortunately, some applications such as the man
              program are confused by this; so this is deprecated.

   Editing with Vim
       Besides Emacs, some other editors provide nroff style files too,
       e.g., vim(1), an extension of the vi(1) program.  Vim's highlighting
       can be made to recognize roff files by setting the filetype option in
       a Vim modeline.  For this feature to work, your copy of vim must be
       built with support for, and configured to enable, several features;
       consult the editor's online help topics “auto-setting”, “filetype”,
       and “syntax”.  Then put the following at the end of your roff files,
       after any Emacs configuration:

                     .\" vim: set filetype=groff:

       Replace “groff” in the above with “nroff” if you want highlighing
       that does not recognize many of the GNU extensions to roff, such as
       request, register, and string names longer than two characters.

Authors         top

       This document was written by Bernd Warken ⟨groff-bernd.warken-72@⟩.

See Also         top

       There is a lot of documentation on roff.  The original papers on
       classical troff are still available, and all aspects of groff are
       documented in great detail.

   Internet sites
       “History of Unix Manpages”
              An online article maintained by the mdocml project 
              ⟨⟩ provides an overview of
              roff development from Salzer's RUNOFF to 2008, with links to
              original documentation and recollections of the authors and
              their contemporaries.  Unfortunately, while invaluable, this
              page has contributed to the widespread misconception that
              original groff author James Clark's surname is spelled
              “Clarke”.  It is not.
              The historical troff site ⟨⟩ provides an
              overview and pointers to the historical aspects of roff.

              The Multics site ⟨⟩ contains a lot of
              information on the MIT projects, CTSS, Multics, early Unix,
              including runoff; especially useful are a glossary and the
              many links to ancient documents.

       Unix Archive
              The Ancient Unixes Archive ⟨⟩ pro‐
              vides the source code and some binaries of the ancient Unixes
              (including the source code of troff and its documentation)
              that were made public by Caldera since 2001, e.g., of the
              famous Unix version 7 for PDP-11 at the Unix V7 site 

       Developers at AT&T Bell Labs
              Bell Labs Computing and Mathematical Sciences Research 
              ⟨⟩ provides a search facility for
              tracking information on the early developers.

       Plan 9 The Plan 9 operating system ⟨⟩ by
              AT&T Bell Labs.

       runoff Jerry Saltzer's home page 
              ⟨⟩ stores
              some documents using the ancient RUNOFF formatting language.

       CSTR Papers
              The Bell Labs (now Alcatel) CSTR site 
              ⟨⟩ stores the
              original troff manuals (CSTR #54, #97, #114, #116, #122) and
              famous historical documents on programming.

       GNU roff
              The groff web site ⟨⟩ pro‐
              vides the free roff implementation groff, the actual standard

   Historical roff documentation
       Many classical troff documents are still available on-line.  The two
       main manuals of the troff language are

       [CSTR #54]
              J. F. Ossanna, Nroff/Troff User's Manual⟩; Bell Labs, 1976; revised by
              Brian Kernighan, 1992.

       [CSTR #97]
              Brian Kernighan, A Typesetter-independent TROFF⟩, Bell Labs, 1981,
              revised March 1982.

       The “little language” roff papers are

       [CSTR #114]
              Jon L. Bentley and Brian W. Kernighan, GRAP – A Language for
              Typesetting Graphs⟩; Bell Labs,
              August 1984.

       [CSTR #116]
              Brian W. Kernighan, PIC – A Graphics Language for Typesetting⟩; Bell Labs,
              December 1984.

       [CSTR #122]
              J. L. Bentley, L. W. Jelinski, and B. W. Kernighan, CHEM – A
              Program for Typesetting Chemical Structure Diagrams, Computers
              and Chemistry⟩;
              Bell Labs, April 1986.

       You can get an archive with most classical roff documentation as rea‐
       sonable PDF files at github using the shell command
              $ git clone

   Manual pages
       Due to its complex structure, a full roff system has many man pages,
       each describing a single aspect of roff.  Unfortunately, there is no
       general naming scheme for the documentation among the different roff

       In groff, the man page groff(1) contains a survey of all documenta‐
       tion available in groff.

       On other systems, you are on your own, but troff(1) might be a good
       starting point.

COLOPHON         top

       This page is part of the groff (GNU troff) project.  Information
       about the project can be found at 
       ⟨⟩.  If you have a bug report for
       this manual page, see ⟨⟩.  This
       page was obtained from the project's upstream Git repository
       ⟨⟩ on 2020-09-18.  (At that
       time, the date of the most recent commit that was found in the repos‐
       itory was 2020-09-19.)  If you discover any rendering problems in
       this HTML version of the page, or you believe there is a better or
       more up-to-date source for the page, or you have corrections or
       improvements to the information in this COLOPHON (which is not part
       of the original manual page), send a mail to

groff         18 September 2020                      roff(7)

Pages that refer to this page: groff(1)groffer(1)nroff(1)troff(1)groff_filenames(5)groff_out(5)groff_tmac(5)ditroff(7)groff(7)groff_diff(7)