| groff(1) | User Commands | groff(1) |
groff - front end to the GNU roff document formatting system
groff |
[-abcCeEgGijklNpRsStUVXzZ] [-d ctext] [-d string=text] [-D fallback-encoding] [-f font-family] [-F font-directory] [-I inclusion-directory] [-K input-encoding] [-L spooler-argument] [-m macro-package] [-M macro-directory] [-n page-number] [-o page-list] [-P postprocessor-argument] [-r cnumeric-expression] [-r register=numeric-expression] [-T output-device] [-w warning-category] [-W warning-category] [file ...] |
groff |
-h |
groff |
--help |
groff |
-v [option ...] [file ...] |
groff |
--version [option ...] [file ...] |
groff is the primary front end to the GNU roff document formatting system. GNU roff is a typesetting system that reads plain text input that includes formatting commands to produce output in PostScript, PDF, HTML, or other formats, or for display to a terminal. Formatting commands can be low-level typesetting primitives, macros from a supplied package, or user-defined macros. All three approaches can be combined. If no file operands are specified, or if file is “-”, groff reads the standard input stream.
A reimplementation and extension of troff and other programs from AT&T Unix, groff is widely available on POSIX and other systems owing to its long association with Unix manuals, including man pages. It and its predecessor have produced several best-selling software engineering texts. groff can create typographically sophisticated documents while consuming minimal system resources.
Like its predecessor “troff”, the term “groff” affords two popular pronunciations: as one syllable (like the surname), rhyming with “trough”, or as “jee-roff”, in analogy to the Bell Labs pronunciation “tee-roff”. Little risk of confusion exists; use whichever suits you.
The groff command orchestrates the execution of preprocessors, the transformation of input documents into a device-independent page description language, and the production of output from that language.
-h and --help display a usage message and exit.
Because groff is intended to subsume most users' direct invocations of the gtroff(1) formatter, the two programs share a set of options. However, groff has some options that gtroff does not share, and others which groff interprets differently. At the same time, not all valid gtroff options can be given to groff.
The following options either do not exist in GNU troff or are interpreted differently by groff.
The following options are passed as-is to the formatter program gtroff(1) and described in more detail in its man page.
The architecture of the GNU roff system follows that of other device-independent roff implementations, comprising preprocessors, macro packages, output drivers (or “postprocessors”), and a suite of utilities, with the formatter program gtroff(1) at its heart. See roff(7) for a survey of how a roff system works.
The front end programs available in the GNU roff system make it easier to use than traditional roffs that required the construction of pipelines or use of temporary files to carry a source document from maintainable form to device-ready output. The discussion below summarizes the constituent parts of the GNU roff system. It complements roff(7) with groff-specific information.
Those who prefer to learn by experimenting or are desirous of rapid feedback from the system may wish to start with a “Hello, world!” document.
$ echo "Hello, world!" | groff -Tascii | sed '/^$/d' Hello, world!
We used a sed(1) command only to eliminate the 65 blank lines that would otherwise flood the terminal screen. (roff systems were developed in the days of paper-based terminals with 66 lines to a page.)
Today's users may prefer output to a UTF-8-capable terminal.
$ echo "Hello, world!" | groff -Tutf8 | sed '/^$/d'
Producing PDF, HTML, or TeX's DVI is also straightforward. The hard part may be selecting a viewer program for the output.
$ echo "Hello, world!" | groff -Tpdf > hello.pdf $ evince hello.pdf $ echo "Hello, world!" | groff -Thtml > hello.html $ firefox hello.html $ echo "Hello, world!" | groff -Tdvi > hello.dvi $ xdvi hello.dvi
Those with a programmer's bent may be pleased to know that they can use groff in a read-evaluate-print loop (REPL). Doing so can be handy to verify one's understanding of the formatter's behavior and/or the syntax it accepts. Turning on all warnings with -ww can aid this goal.
$ groff -ww -Tutf8 \# This is a comment. Let's define a register. .nr a 1 \# Do integer arithmetic with operators evaluated left-to-right. .nr b \n[a]+5/2 \# Let's get the result on the standard error stream. .tm \n[b] 3 \# Now we'll define a string. .ds name Leslie\" This is another form of comment. .nr b (\n[a] + (7/2)) \# Center the next two text input lines. .ce 2 Hi, \*[name]. Your secret number is \n[b]. \# We will see that the division rounded toward zero. It is \# Here's an if-else control structure. .ie (\n[b] % 2) odd. .el even. \# This trick sets the page length to the current vertical \# position, so that blank lines don't spew when we're done. .pl \n[nl]u <Control-D>
Hi, Leslie.
Your secret number is 4. It is even.
The formatter reads the device description file DESC for the selected output device when it starts; page dimensions declared there are used if present. groff's build process configures a default page format and writes it to typesetters' DESC files. This installation defaults to “letter”. If the DESC file lacks this information, the formatter and output driver use a page length of “11i” (eleven inches) for compatibility with AT&T troff. See groff_font(5).
In the formatter, the pl request changes the page length, but macro packages often do not support alteration of the paper format within a document. One might, for instance, want to switch between portrait and landscape orientations. Macro packages lack a consistent approach to configuration of parameters dependent on the paper format; some, like ms, benefit from a preamble in the document prior to the first macro call, while others, like mm, instead require the specification of registers on the command line, or otherwise before its macro file is interpreted, to configure page dimensions.
Output drivers for typesetters also recognize command-line options -p to override the default page dimensions and -l to use landscape orientation. The output driver's man page, such as grops(1), may be helpful.
groff's “-d paper” command-line option is a convenient means of setting the paper format; see groff_tmac(5). Combine it with appropriate -P options for the output driver, overriding its defaults. The following command formats for PostScript on A4 paper in landscape orientation.
$ groff -T ps -d paper=a4l -P -pa4 -P -l -ms my.ms >my.ps
The groff program wraps gtroff(1), allowing one to specify preprocessors via command-line options and running the appropriate output driver for the selected output device. This convenience avoids the manual construction of pipelines or management of temporary files required of users of traditional roff(7) systems. Use grog(1) to infer an appropriate groff command line to format a document.
Input to a roff system is in plain text interleaved with control lines and escape sequences. The combination constitutes a document in one of a family of languages we also call roff; see roff(7) for background. An overview of GNU roff language syntax and features, including lists of all supported escape sequences, requests, and predefined registers, can be found in groff(7). GNU roff extensions to the AT&T troff language, a common subset of roff dialects extant today, are detailed in groff_diff(7).
A preprocessor interprets a domain-specific language that produces
roff language output. Frequently, such input is confined to sections
or regions of roff input (bracketed with macro calls specific to each
preprocessor), which it replaces. Preprocessors therefore often interpret a
subset of roff syntax along with their own language. GNU roff
provides reimplementations of most preprocessors familiar to users of
AT&T troff; these routinely have extended features and/or require
GNU troff to format their output.
| gtbl | lays out tables; |
| geqn | typesets mathematics; |
| gpic | draws diagrams; |
| grefer | processes bibliographic references; |
| gsoelim | preprocesses “sourced” input files; |
| ggrn | renders diagrams; |
| gchem | draws chemical structural formulæ using pic ; |
| gperl | populates groff registers and strings using |
| glilypond | embeds LilyPond sheet music; and |
| gpinyin | eases Mandarin Chinese input using Hanyu Pinyin. |
A preprocessor unique to GNU roff is preconv(1), which converts various input encodings to something GNU troff can understand. When used, it is run before any other preprocessors.
Most preprocessors enclose content between a pair of characteristic tokens. Such a token must occur at the beginning of an input line and use the dot control character. Spaces and tabs must not follow the control character or precede the end of the input line. Deviating from these rules defeats a token's recognition by the preprocessor. Tokens are generally preserved in preprocessor output and interpreted as macro calls subsequently by gtroff. The gideal preprocessor is not yet available in groff.
| preprocessor | starting token | ending token |
| gchem | .cstart | .cend |
| geqn | .EQ | .EN |
| grap | .G1 | .G2 |
| ggrn | .GS | .GE |
| gideal | .IS | .IE |
| .IF | ||
| gpic | .PS | .PE |
| .PF | ||
| .PY | ||
| grefer | .R1 | .R2 |
| gtbl | .TS | .TE |
| glilypond | .lilypond start | .lilypond stop |
| gperl | .Perl start | .Perl stop |
| gpinyin | .pinyin start | .pinyin stop |
Macro files are roff input files designed to produce no
output themselves but instead ease the preparation of other roff
documents. When a macro file is installed at a standard location and
suitable for use by a general audience, it is termed a macro package.
The -m option loads a macro package prior to any roff input documents, and after performing any string and register assignments directed by -d and -r options. The GNU roff system implements most well-known macro packages for AT&T troff in a compatible way and extends them. These have one- or two-letter names arising from intense practices of naming economy in early Unix culture, a laconic approach that led to many of the packages being identified in general usage with the nroff and troff option letter used to invoke them, sometimes to punning effect, as with “man” (short for “manual”), and even with the option dash, as in the case of the s package, much better known as ms or even -ms.
Macro packages serve a variety of purposes. Some are “full-service” packages, adopting responsibility for page layout among other fundamental tasks, and defining their own lexicon of macros for document composition; each such package stands alone and a given document can use at most one.
Others are supplemental. For instance, andoc is a wrapper package specific to GNU roff that recognizes whether a document uses man or mdoc format and loads the corresponding macro package. It can be specified on the command line as -mandoc. A man(1) librarian may use this macro file to delegate loading of the correct macro package; it is thus unnecessary for man itself to scan the contents of a document to decide the issue.
Many macro files augment the function of the full-service packages, or of roff documents that do not employ such a package—the latter are sometimes characterized as “raw”. These auxiliary packages are described, along with details of macro file naming and placement, in groff_tmac(5).
The formatter, the program that interprets roff language input, is gtroff(1). It provides the features of the AT&T troff and nroff programs as well as many extensions. The command-line option -C switches gtroff into compatibility mode, which tries to emulate AT&T troff as closely as is practical to enable the formatting of documents written for the older system.
A shell script, gnroff(1), emulates the behavior of AT&T nroff. It attempts to correctly encode the output based on the locale, relieving the user of the need to specify an output device with the -T option and is therefore convenient for use with terminal output devices, described in the next subsection.
GNU troff generates output in a device-independent, but not device-agnostic, page description language detailed in groff_out(5).
gtroff output is formatted for a particular output device, typically specified by the -T option to the formatter or a front end. If neither this option nor the GROFF_TYPESETTER environment variable is used, the default output device is ps. An output device may be any of the following.
Any program that interprets the output of GNU troff is a postprocessor. The postprocessors provided by GNU roff are output drivers, which prepare a document for viewing or printing. Postprocessors for other purposes, such as page resequencing or statistical measurement of a document, are conceivable.
An output driver supports one or more output devices, each with its own device description file. A device determines its postprocessor with the postpro directive in its device description file; see groff_font(5). The -X option overrides this selection, causing gxditview to serve as the output driver.
GNU roff includes a suite of utilities.
Several utilities prepare descriptions of fonts, enabling the formatter to use them when producing output for a given device.
A trio of tools transform material constructed using roff preprocessor languages into graphical image files.
Another set of programs works with the bibliographic data files used by the grefer(1) preprocessor.
groff exits successfully (with status 0) if either of the options -h or --help is specified, status 2 if the program cannot interpret its command-line arguments, and status 1 if it encounters an error during operation. Otherwise, groff runs a pipeline to process its input; if all commands within the pipeline exit successfully, groff does likewise. If not, groff's exit status encodes a summary of problems encountered, setting bit 2 if a command exited with a failure status, bit 3 if a command was terminated with a signal, and bit 4 if a command could not be executed. (Thus, if all three misfortunes befall one's pipeline, groff exits with status 2^2 + 2^3 + 2^4 = 4+8+16 = 28.) To troubleshoot pipeline problems, re-run the groff command with the -V option and break the reported pipeline down into separate stages, inspecting the exit status of, and diagnostic messages emitted by, each command.
Environment variables in the host system affect the behavior of programs supplied by groff as follows. Normally, the path separator in environment variables ending with PATH is the colon; this may vary depending on the operating system. For example, Windows uses a semicolon instead.
roff systems are best known for formatting man pages. A man(1) librarian program, having located a page, might render it with a groff command.
groff -t -man -Tutf8 /usr/share/man/man1/groff.1
To process a roff input file using the preprocessors gtbl and gpic and the me macro package in the way to which AT&T troff users were accustomed, one would type (or script) a pipeline.
gpic foo.me | gtbl | gtroff -me -Tutf8 | grotty
Shorten this pipeline to an equivalent command using groff.
groff -p -t -me -T utf8 foo.me
An even easier way to do this is to use grog(1) to guess the preprocessor and macro options and execute the result by using the command substitution feature of the shell.
$(grog -Tutf8 foo.me)
Each command-line option to a postprocessor must be specified with any required leading dashes “-” because groff passes the arguments as-is to the postprocessor; this permits arbitrary arguments to be transmitted. For example, to pass a title to the gxditview postprocessor, the shell commands
groff -X -P -title -P 'trial run' mydoc.t
groff -X -Z mydoc.t | gxditview -title 'trial run' -
When paging output for the ascii, latin1, and utf8 devices, programs like more(1) and less(1) may require command-line options to correctly handle some terminal escape sequences; see grotty(1).
GNU roff installs files in varying locations depending on its compile-time configuration. On this installation, the following locations are used.
Most macro files supplied with GNU roff are stored in /usr/share/groff/1.24.1/tmac for the installation corresponding to this document. As a rule, multiple directories are searched for macro files; see gtroff(1). For a catalog of macro files GNU roff provides, see groff_tmac(5).
Device and font description files supplied with GNU roff are stored in /usr/share/groff/1.24.1/font for the installation corresponding to this document. As a rule, multiple directories are searched for device and font description files; see gtroff(1). For the formats of these files, see groff_font(5).
Obtain links to groff releases for download, its source repository, discussion mailing lists, a support ticket tracker, and further information from the groff page of the GNU website.
A free implementation of the grap preprocessor, written by Ted Faber, can be found at the grap website. groff supports only this grap.
groff (both the front-end command and the overall system) was primarily written by James Clark. Contributors to this document include Clark, Trent A. Fisher, Werner Lemberg, Bernd Warken, and G. Branden Robinson.
Groff: The GNU Implementation of troff, by Trent A. Fisher and Werner Lemberg, is the primary groff manual. You can browse it interactively with “info groff”.
A list of all groff man pages follows. A few (grohtml, gropdf, gxditview, and xtotroff) will be unavailable if their corresponding programs were disabled during compilation.
| 2026-03-14 | groff 1.24.1 |