groff_man_style(7) | Miscellaneous Information Manual | groff_man_style(7) |
groff_man_style - GNU roff man page tutorial and style guide
groff -man |
[option ...] [file ...] |
groff -m man |
[option ...] [file ...] |
The GNU implementation of the man macro package is part of the groff document formatting system. It is used to produce manual pages (“man pages”) like the one you are reading.
This document presents the macros thematically; for those needing only a quick reference, the following table lists them alphabetically, with cross references to appropriate subsections below.
Macro | Meaning | Subsection |
.B | Bold | Font style macros |
.BI | Bold, italic alternating | Font style macros |
.BR | Bold, roman alternating | Font style macros |
.EE | Example end | Document structure macros |
.EX | Example begin | Document structure macros |
.I | Italic | Font style macros |
.IB | Italic, bold alternating | Font style macros |
.IP | Indented paragraph | Paragraphing macros |
.IR | Italic, roman alternating | Font style macros |
.LP | Begin paragraph | Paragraphing macros |
.ME | Mail-to end | Hyperlink macros |
.MR | Man page cross reference | Hyperlink macros |
.MT | Mail-to start | Hyperlink macros |
.P | Begin paragraph | Paragraphing macros |
.PP | Begin paragraph | Paragraphing macros |
.RB | Roman, bold alternating | Font style macros |
.RE | Relative inset end | Document structure macros |
.RI | Roman, italic alternating | Font style macros |
.RS | Relative inset start | Document structure macros |
.SB | Small bold | Font style macros |
.SH | Section heading | Document structure macros |
.SM | Small | Font style macros |
.SS | Subsection heading | Document structure macros |
.SY | Synopsis start | Command synopsis macros |
.TH | Title heading | Document structure macros |
.TP | Tagged paragraph | Paragraphing macros |
.TQ | Supplemental paragraph tag | Paragraphing macros |
.UE | URI end | Hyperlink macros |
.UR | URI start | Hyperlink macros |
.YS | Synopsis end | Command synopsis macros |
We discuss other macros (.AT, .DT, .HP, .OP, .PD, and .UC) in subsection “Deprecated features” below.
Throughout Unix documentation, a manual entry is referred to simply as a “man page”, regardless of its length, without gendered implication, and irrespective of the macro package selected for its composition.
Man pages should be encoded using Unicode basic Latin code points exclusively, and employ the Unix line-ending convention (U+000A only).
groff is a programming system for typesetting: we thus often use the verb “to set” in the sense “to typeset”. The formatter troff(1) collects words from the input and fills output lines with as many as will fit. Words are separated by spaces and newlines. A transition to a new output line is called a break. When formatted, a word may be broken at hyphens, at \% or \: escape sequences (see subsection “Portability” below), or at predetermined locations if automatic hyphenation is enabled (see the -rHY option in section “Options” below). An output line may be supplemented with inter-sentence space, and then optionally adjusted with more space to a consistent line length (see the -dAD option). roff(7) details these processes.
An input line that starts with a dot (.) or neutral apostrophe (') is a control line. To call a macro, put its name after a dot on a control line. We refer to macros in this document using this leading dot. Some macros interpret arguments, words that follow the macro name. A newline, unless escaped (see subsection “Portability” below), marks the end of the macro call. An input line consisting of a dot followed by a newline is called the empty request; it does nothing. Text lines are input lines that are not control lines.
We describe below several man macros that plant one-line
input traps: the next input line that directly produces formatted
output is treated specially. For man documents that follow the advice
in section “Portability” below, this means that control lines
using the empty request and uncommented input lines ending with an escaped
newline do not spring the trap; anything else does (but see the .TP
macro description).
A tagged paragraph describes each macro. We present coupled pairs
together, as with .EX and .EE.
Optional macro arguments are indicated by surrounding them with square brackets. If a macro accepts multiple arguments, those containing space characters must be double-quoted to be interpreted correctly. An empty macro argument can be specified with a pair of double-quotes (""), but the man package is designed such that this should seldom be necessary. See section “Notes” below for examples of cases where better alternatives to empty arguments in macro calls are available. Most macro arguments will be formatted as text in the output; exceptions are noted.
Document structure macros organize a man page's content. All of them break the output line. .TH (title heading) identifies the document as a man page and configures the page headers and footers. Section headings (.SH), one of which is mandatory and many of which are conventionally expected, facilitate location of material by the reader and aid the man page writer to discuss all essential aspects of the topic. Subsection headings (.SS) are optional and permit sections that grow long to develop in a controlled way. Many technical discussions benefit from examples; lengthy ones, especially those reflecting multiple lines of input to or output from the system, are usefully bracketed by .EX and .EE. When none of the foregoing meets a structural demand, use .RS/.RE to inset a region within a (sub)section.
An ordinary paragraph (.P) like this one is set without a
first-line indentation at the current left margin. In man pages and other
technical literature, definition lists are frequently encountered; these can
be set as “tagged paragraphs”, which have one (.TP) or
more (.TQ) leading tags followed by a paragraph that has an
additional indentation. The indented paragraph (.IP) macro is useful
to continue the indented content of a narrative started with .TP, or
to present an itemized or ordered list. All of these macros break the output
line. If another paragraph macro has occurred since the previous .SH
or .SS, they (except for .TQ) follow the break with a default
amount of vertical space, which can be changed by the deprecated .PD
macro; see subsection “Horizontal and vertical spacing” below.
They also reset the type size and font style to defaults (.TQ again
excepted); see subsection “Font style macros” below.
.SY and .YS aid you to construct a command synopsis that has the classical Unix appearance. They break the output line.
These macros are GNU extensions not defined on systems running AT&T, Plan 9, or Solaris troff; see an-ext.tmac in section “Files” below.
Multiple .SY/.YS blocks can be specified, for instance to distinguish differing modes of operation of a complex command like tar(1); each will be vertically separated as paragraphs are.
.SY can be repeated before .YS to indicate
synonymous ways of invoking a particular mode of operation.
groff's own command-line interface serves to illustrate most of the specimens of synopsis syntax one is likely to encounter.
.SY groff .RB [ \-abcCeEgGijklNpRsStUVXzZ ] .RB [ \-d\~\c .IR cs ] .RB [ \-d\~\c .IB name =\c .IR string ] .RB [ \-D\~\c .IR enc ](and so on similarly)
.RI [ file\~ .\|.\|.] .YS . . .SY groff .B \-h . .SY groff .B \-\-help .YS . . .SY groff .B \-v .RI [ option\~ .\|.\|.\&] .RI [ file\~ .\|.\|.] . .SY groff .B \-\-version .RI [ option\~ .\|.\|.\&] .RI [ file\~ .\|.\|.] .YS
produces the following output.
groff |
[-abcCeEgGijklNpRsStUVXzZ] [-d cs] [-d name=string] [-D enc] [-f fam] [-F dir] [-I dir] [-K enc] [-L arg] [-m name] [-M dir] [-n num] [-o list] [-P arg] [-r cn] [-r reg=expr] [-T dev] [-w name] [-W name] [file ...] |
groff |
-h |
groff |
--help |
groff |
-v [option ...] [file ...] |
groff |
--version [option ...] [file ...] |
Several features of the above example are of note.
Man page cross references like ls(1) are best presented with .MR. Text may be hyperlinked to email addresses with .MT/.ME or other URIs with .UR/.UE. Hyperlinked text is supported on HTML and terminal output devices; terminals and pager programs must support ECMA-48 OSC 8 escape sequences (see grotty(1)). When device support is unavailable or disabled with the U register (see section “Options” below), .MT and .UR URIs are rendered between angle brackets after the linked text.
.MT, .ME, .UR, and .UE are GNU extensions not defined on systems running AT&T, Plan 9, or Solaris troff; see an-ext.tmac in section “Files” below. Plan 9 from User Space's troff implements .MR.
The arguments to .MR, .MT, and .UR should be prepared for typesetting since they can appear in the output. Use special character escape sequences to encode Unicode basic Latin characters where necessary, particularly the hyphen-minus. (See section “Portability” below.) URIs can be lengthy; rendering them can result in jarring adjustment or variations in line length, or troff warnings when a hyperlink is longer than an output line. The application of non-printing break point escape sequences \: after each slash (or series thereof), and before each dot (or series thereof) is recommended as a rule of thumb. The former practice avoids forcing a trailing slash in a URI onto a separate output line, and the latter helps the reader to avoid mistakenly interpreting a dot at the end of a line as a period (or multiple dots as an ellipsis). Thus,
.UR http://\:example\:.com/\:fb8afcfbaebc74e\:.cc
The output driver .MR grops 1 produces PostScript from .I troff output. . The Ghostscript program (\c .MR gs 1 ) interprets PostScript and PDF.
Contact .MT fred\:.foonly@\:fubar\:.net Fred Foonly .ME for more information.
The GNU Project of the Free Software Foundation hosts the .UR https://\:www\:.gnu\:.org/\:software/\:groff/ .I groff home page .UE .
The hyperlinking of .TP paragraph tags with .UR/.UE and .MT/.ME is not yet supported; if attempted, the hyperlink will be typeset at the beginning of the indented paragraph even on hyperlink-supporting devices.
The man macro package is limited in its font styling options, offering only bold (.B), italic (.I), and roman. Italic text is usually set underscored instead on terminal devices. The .SM and .SB macros set text in roman or bold, respectively, at a smaller type size; these differ visually from regular-sized roman or bold text only on typesetting devices. It is often necessary to set text in different styles without intervening space. The macros .BI, .BR, .IB, .IR, .RB, and .RI, where “B”, “I”, and “R” indicate bold, italic, and roman, respectively, set their odd- and even-numbered arguments in alternating styles, with no space separating them.
Because font styles are presentational rather than semantic,
conflicting traditions have arisen regarding which font styles should be
used to mark file or path names, environment variables, and inlined
literals.
The default type size and family for typesetting devices is 10-point Times, except on the X75-12 and X100-12 devices where the type size is 12 points. The default style is roman.
Observe what is not prescribed for setting in bold or italics above: elements of “synopsis language” such as ellipses and brackets around options; proper names and adjectives; titles of anything other than major works of literature; identifiers for standards documents or technical reports such as CSTR #54, RFC 1918, Unicode 13.0, or POSIX.1-2017; acronyms; and occurrences after the first of a technical term.
Be frugal with italics for emphasis, and particularly with bold. Article titles and brief runs of literal text, such as references to individual characters or short strings, including section and subsection headings of man pages, are suitable objects for quotation; see the \(lq, \(rq, \(oq, and \(cq escape sequences in subsection “Portability” below.
Unlike the above font style macros, the font style alternation macros below set no input traps; they must be given arguments to have effect. Italic corrections are applied as appropriate. If a space is required within an argument, first consider whether the same result could be achieved with as much clarity by using single-style macros on separate input lines. When it cannot, double-quote an argument containing embedded space characters. Setting all three different styles within a word presents challenges; it is possible with the \c and/or \f escape sequences. See subsection “Portability” below for approaches.
.BI -r register = numeric-expression
After .B .NH is called,
In places where .IB n th is allowed,
Use GNU .IR pic 's .B figname command to change the name of the vbox.
if .I file is .RB \[lq] \- \[rq], the standard input stream is read.
.RI ( tpic was a fork of AT&T .I pic by Tim Morgan of the University of California at Irvine
The indentation argument accepted by .IP, .TP, and the deprecated .HP is a number plus an optional scaling unit, as is .RS's inset-amount. If no scaling unit is given, the man package assumes “n”; that is, the width of a letter “n” in the font current when the macro is called (see section “Measurements” in groff(7)). An indentation specified in a call to .IP, .TP, or the deprecated .HP persists until (1) another of these macros is called with an indentation argument, or (2) .SH, .SS, or .P or its synonyms is called; these clear the indentation entirely.
The left margin used by ordinary paragraphs set with .P (and its synonyms) not within an .RS/.RE relative inset is 7.2n for typesetting devices and 7n for terminal devices (but see the -rIN option). Headers, footers (both set with .TH), and section headings (.SH) are set at the page offset (see groff(7)) and subsection headings (.SS) indented from it by 3n (but see the -rSN option).
It may be helpful to think of the left margin and indentation as related but distinct concepts; groff's implementation of the man macro package tracks them separately. The left margin is manipulated by .RS and .RE (and by .SH and .SS, which reset it to the default). Indentation is controlled by the paragraphing macros (though, again, .SH and .SS reset it); it is imposed by the .TP, .IP, and deprecated .HP macros, and cancelled by .P and its synonyms. An extensive example follows.
This ordinary (.P) paragraph is not in a relative inset nor does it possess an indentation.
Now we have created a relative inset (in other words, moved the left margin) with .RS and started another ordinary paragraph with .P.
This table is affected both by |
the left margin and indentation. |
This ordinary (.P) paragraph resets the indentation, but the left margin is still inset.
This table is affected only |
by the left margin. |
Finally, we have ended the relative inset by using .RE, which (because we used only one .RS/.RE pair) has reset the left margin to the default. This is an ordinary .P paragraph.
Resist the temptation to mock up tabular or multi-column output with tab characters or the indentation arguments to .IP, .TP, .RS, or the deprecated .HP; the result may not render comprehensibly on an output device you fail to check, or which is developed in the future. The table preprocessor tbl(1) can likely meet your needs.
Several macros insert vertical space: .SH, .SS, .TP, .P (and its synonyms), .IP, and the deprecated .HP. The default inter-section and inter-paragraph spacing is is 1v for terminal devices and 0.4v for typesetting devices (“v” is a unit of vertical distance, where 1v is the distance between adjacent text baselines in a single-spaced document). (The deprecated macro .PD can change this vertical spacing, but its use is discouraged.) Between .EX and .EE calls, the inter-paragraph spacing is 1v regardless of output device.
Registers are described in section “Options” below. They can be set not only on the command line but in the site man.local file as well; see section “Files” below.
The following strings are defined for use in man pages. Others are supported for configuration of rendering parameters; see section “Options” below.
None of the above is necessary in a contemporary man page. \*S is superfluous, since type size changes are invisible on terminal devices and macros that change it restore its original value afterward. Better alternatives exist for the rest; simply use the \(rg, \(lq, \(rq, and \(tm special character escape sequences directly. Unless a man page author is aiming for a pathological level of portability, such as the composition of pages for consumption on simulators of 1980s Unix systems (or Solaris troff, though even it supports \(rg), the above strings should be avoided.
It is wise to quote multi-word section and subsection headings; the .SH and .SS macros of man(7) implementations descended from Seventh Edition Unix supported six arguments at most. A similar restriction applied to the .B, .I, .SM, and font style alternation macros.
The two major syntactical categories for formatting control in the
roff language are requests and escape sequences. Since the man
macros are implemented in terms of groff requests and escape
sequences, one can, in principle, supplement the functionality of man
with these lower-level elements where necessary.
However, using raw groff requests (apart from the empty request “.”) is likely to make your page render poorly when processed by other tools; many of these attempt to interpret page sources directly for conversion to HTML. Some requests make implicit assumptions about things like character and page sizes that may not hold in an HTML environment; also, many of these viewers don't interpret the full groff vocabulary, a problem that can lead to portions of your text being omitted or presented incomprehensibly.
For portability to modern viewers, it is best to write your page solely with the macros described in this page (except for the ones identified as deprecated, which should be avoided). The macros we have described as extensions (.EX/.EE, .SY/.YS, .TQ, .UR/.UE, .MT/.ME, .MR, and .SB) should be used with caution, as they may not be built in to some viewer that is important to your audience. See an-ext.tmac in section “Files” below.
Similar caveats apply to escape sequences. Some escape sequences
are however required for correct typesetting even in man pages and usually
do not cause portability problems. Several of these render glyphs
corresponding to punctuation code points in the Unicode basic Latin range
(U+0000–U+007F) that are handled specially in roff input; the
escape sequences below must be used to render them correctly and portably
when documenting material that uses them syntactically—namely, any of
the set ' - \ ^ ` ~ (apostrophe, dash or minus, backslash, caret,
grave accent, tilde).
Before starting the motor, set the output speed to\~1. There are 1,024\~bytes in 1\~KiB. CSTR\~#8 documents the B\~language.
.RB [ \-\-stylesheet=\c .IR name ]
.EX $ \c .B groff \-T utf8 \-Z \c .I file \c .B | grotty \-i .EE
.RB [ \-\-reference\-dictionary=\fI\,name\/\fP ]
.RB [ \-\-reference\-dictionary=\c .IR name ]
Several special characters are also widely portable. Except for \-, \(em, and \(ga, AT&T troff did not consistently define the characters listed below, but its descendants, like Plan 9 or Solaris troff, can be made to support them by defining them in font description files, making them aliases of existing glyphs if necessary; see groff_font(5).
.TP .BI "split \(dq" text \(dq
For maximum portability, escape sequences and special characters not listed above are better avoided in man pages.
Two macros, both GNU extensions, are called internally by the groff man package to format page headers and footers and can be redefined by the administrator in a site's man.local file (see section “Files” below). The presentation of .TH above describes the default headers and footers. Because these macros are hooks for groff man internals, man pages have no reason to call them. Such hook definitions will likely consist of “.sp” and “.tl” requests. They must also increase the page length with “.pl” requests in continuous rendering mode; .PT furthermore has the responsibility of emitting a PDF bookmark after writing the first page header in a document. Consult the existing implementations in an.tmac when drafting replacements.
To remove a page header or footer entirely, define the appropriate macro as empty rather than deleting it.
Use of the following in man pages for public distribution is discouraged.
M. Douglas McIlroy designed, implemented, and documented the AT&T man macros for Unix Version 7 (1979) and employed them to edit the first volume of its Programmer's Manual, a compilation of all man pages supplied by the system. That man supported the macros listed in this page not described as extensions, except .P and the deprecated .AT and .UC. The only strings defined were R and S; no registers were documented.
.UC appeared in 3BSD (1980). Unix System III (1980) introduced .P and exposed the registers IN and LL, which had been internal to Seventh Edition Unix man. PWB/UNIX 2.0 (1980) added the Tm string. 4BSD (1980) added lq and rq strings. SunOS 2.0 (1985) recognized C, D, P, and X registers. 4.3BSD (1986) added .AT and .P. Ninth Edition Research Unix (1986) introduced .EX and .EE. SunOS 4.0 (1988) added .SB.
The foregoing features were what James Clark implemented in early
versions of groff. Later, groff 1.20 (2009) originated
.SY/.YS, .TQ, .MT/.ME, and
.UR/.UE. Plan 9 from User Space's troff
introduced .MR in 2020.
The following groff options set registers (with -r) and strings (with -d) recognized and used by the man macro package. To ensure rendering consistent with output device capabilities and reader preferences, man pages should never manipulate them.
.\" Use narrower indentation on terminals and similar. .if n .nr IN 4n .\" Put only one space after the end of a sentence. .ss 12 0 \" See groff(7). .\" Keep pages narrow even on wide terminals. .if n .if \n[LL]>78n .nr LL 78n .\" Ensure hyperlinks are enabled for terminals. .nr U 1
.soquiet \V[XDG_CONFIG_HOME]/man.local .soquiet \V[HOME]/.man.local
Some tips on troubleshooting your man pages follow.
To get a “literal”... | ...should be input. |
' | \(aq |
- | \- |
\ | \(rs |
^ | \(ha |
` | \(ga |
~ | \(ti |
Instead of... | ...should be considered. |
.TP "" | .TP |
.BI "" italic-text bold-text | .IB italic-text bold-text |
.TH foo 1 "" "foo 1.2.3" | .TH foo 1 yyyy-mm-dd "foo 1.2.3" |
.IP "" 4n | .IP |
.IP "" 4n | .RS 4n |
paragraph | .P |
... | paragraph |
... | .RE |
.B one two "" three | .B one two three |
Instead of... | ...should be considered. |
.IP \(bu 4n | .IP \(bu 4n |
paragraph | paragraph |
.IP \(bu 4n | .IP \(bu |
another-paragraph | another-paragraph |
Instead of... | ...do this. |
.ds EL \&.\|.\|. | Arguments are |
Arguments are | .IR src-file\~ .\|.\|.\& |
.IR src-file\~ \*(EL\& | .IR dest-dir . |
.IR dest-dir . |
The initial GNU implementation of the man macro package was
written by James Clark. Later, Werner
Lemberg supplied the S, LT, and cR registers, the
last a 4.3BSD-Reno mdoc(7) feature.
Larry Kollar added the
FT, HY, and SN registers; the HF string; and the
PT and BT macros.
G. Branden
Robinson implemented the AD and MF strings; CS,
CT, and U registers; and the MR macro. Except for
.SB, the extension macros were written by Lemberg,
Eric S. Raymond, and
Robinson.
This document was originally written for the Debian GNU/Linux system by Susan G. Kleinmann. It was corrected and updated by Lemberg and Robinson. The extension macros were documented by Raymond and Robinson. Raymond also originated the portability section, to which Ingo Schwarze contributed most of the material on escape sequences.
tbl(1), eqn(1), and refer(1) are preprocessors used with man pages. man(1) describes the man page librarian on your system. groff_mdoc(7) details the groff version of the BSD-originated alternative macro package for man pages.
groff_man(7), groff(7), groff_char(7), man(7)
26 December 2024 | groff 1.23.0 |