1 .\" Id: roff.7,v 1.46 2013/12/26 02:43:18 schwarze Exp
3 .\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 .\" Copyright (c) 2010, 2011, 2013 Ingo Schwarze <schwarze@openbsd.org>
6 .\" Permission to use, copy, modify, and distribute this software for any
7 .\" purpose with or without fee is hereby granted, provided that the above
8 .\" copyright notice and this permission notice appear in all copies.
10 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 .Nd roff language reference for mandoc
27 language is a general purpose text formatting language.
28 Since traditional implementations of the
32 manual formatting languages are based on it,
33 many real-world manuals use small numbers of
35 requests and escape sequences intermixed with their
40 To properly format such manuals, the
42 utility supports a tiny subset of
45 Only these requests and escapes supported by
47 are documented in the present manual,
48 together with the basic language syntax shared by
59 Input lines beginning with the control character
61 are parsed for requests and macros.
67 Requests change the processing state and manipulate the formatting;
68 some macros also define the document structure and produce formatted
72 is accepted as an alternative control character,
78 Lines not beginning with control characters are called
80 They provide free-form text to be printed; the formatting of the text
81 depends on the respective processing context.
84 documents may contain only graphable 7-bit ASCII characters, the space
85 character, and, in certain circumstances, the tab character.
86 The backslash character
88 indicates the start of an escape sequence, used for example for
90 .Sx Special Characters ,
91 .Sx Predefined Strings ,
93 user-defined strings defined using the
96 For a listing of escape sequences, consult the
97 .Sx ESCAPE SEQUENCE REFERENCE
100 Text following an escaped double-quote
102 whether in a request, macro, or text line, is ignored to the end of the line.
103 A request line beginning with a control character and comment escape
106 Furthermore, request lines with only a control character and optional
107 trailing whitespace are stripped from input.
110 .Bd -literal -offset indent -compact
111 \&.\e\(dq This is a comment line.
112 \&.\e\(dq The next line is ignored:
114 \&.Sh EXAMPLES \e\(dq This is a comment, too.
115 \&example text \e\(dq And so is this.
117 .Ss Special Characters
118 Special characters are used to encode special glyphs and are rendered
119 differently across output media.
120 They may occur in request, macro, and text lines.
121 Sequences begin with the escape character
123 followed by either an open-parenthesis
125 for two-character sequences; an open-bracket
127 for n-character sequences (terminated at a close-bracket
129 or a single one character sequence.
132 .Bl -tag -width Ds -offset indent -compact
134 Two-letter em dash escape.
136 One-letter backslash escape.
143 Terms may be text-decorated using the
145 escape followed by an indicator: B (bold), I (italic), R (regular), or P
146 (revert to previous mode).
147 A numerical representation 3, 2, or 1 (bold, italic, and regular,
148 respectively) may be used instead.
149 The indicator or numerical representative may be preceded by C
150 (constant-width), which is ignored.
152 The two-character indicator
154 requests a font that is both bold and italic.
155 It may not be portable to old roff implementations.
158 .Bl -tag -width Ds -offset indent -compact
160 Write in \fBbold\fP, then switch to regular font mode.
161 .It Li \efIitalic\efP
162 Write in \fIitalic\fP, then return to previous font mode.
163 .It Li \ef(BIbold italic\efP
164 Write in \f(BIbold italic\fP, then return to previous font mode.
171 which encourages semantic annotation.
172 .Ss Predefined Strings
173 Predefined strings, like
174 .Sx Special Characters ,
175 mark special output glyphs.
176 Predefined strings are escaped with the slash-asterisk,
186 .Bl -tag -width Ds -offset indent -compact
188 Two-letter ampersand predefined string.
190 One-letter double-quote predefined string.
193 Predefined strings are not recommended for use,
194 as they differ across implementations.
199 Manuals using these predefined strings are almost certainly not portable.
201 Whitespace consists of the space character.
202 In text lines, whitespace is preserved within a line.
203 In request and macro lines, whitespace delimits arguments and is discarded.
205 Unescaped trailing spaces are stripped from text line input unless in a
207 In general, trailing whitespace on any input line is discouraged for
208 reasons of portability.
209 In the rare case that a blank character is needed at the end of an
210 input line, it may be forced by
213 Literal space characters can be produced in the output
214 using escape sequences.
215 In macro lines, they can also be included in arguments using quotation; see
219 Blank text lines, which may include whitespace, are only permitted
220 within literal contexts.
221 If the first character of a text line is a space, that line is printed
222 with a leading newline.
224 Many requests and macros support scaled widths for their arguments.
225 The syntax for a scaled width is
226 .Sq Li [+-]?[0-9]*.[0-9]*[:unit:] ,
227 where a decimal must be preceded or followed by at least one digit.
228 Negative numbers, while accepted, are truncated to zero.
230 The following scaling units are accepted:
232 .Bl -tag -width Ds -offset indent -compact
245 default vertical span
257 default horizontal span
262 Using anything other than
268 is necessarily non-portable across output media.
272 If a scaling unit is not provided, the numerical value is interpreted
273 under the default rules of
275 for vertical spaces and
280 .Bl -tag -width ".Bl -tag -width 2i" -offset indent -compact
281 .It Li \&.Bl -tag -width 2i
282 two-inch tagged list indentation in
285 two-inch tagged list indentation in
291 Each sentence should terminate at the end of an input line.
292 By doing this, a formatter will be able to apply the proper amount of
293 spacing after the end of sentence (unescaped) period, exclamation mark,
294 or question mark followed by zero or more non-sentence closing
303 The proper spacing is also intelligently preserved if a sentence ends at
304 the boundary of a macro line.
307 .Bd -literal -offset indent -compact
308 Do not end sentences mid-line like this. Instead,
309 end a sentence like this.
310 A macro would end like this:
314 A request or macro line consists of:
318 the control character
322 at the beginning of the line,
324 optionally an arbitrary amount of whitespace,
326 the name of the request or the macro, which is one word of arbitrary
327 length, terminated by whitespace,
329 and zero or more arguments delimited by whitespace.
332 Thus, the following request lines are all equivalent:
333 .Bd -literal -offset indent
339 Macros are provided by the
343 languages and can be defined by the
346 When called, they follow the same syntax as requests, except that
347 macro arguments may optionally be quoted by enclosing them
348 in double quote characters
350 Quoted text, even if it contains whitespace or would cause
351 a macro invocation when unquoted, is always considered literal text.
352 Inside quoted text, pairs of double quote characters
354 resolve to single double quote characters.
356 To be recognised as the beginning of a quoted argument, the opening
357 quote character must be preceded by a space character.
358 A quoted argument extends to the next double quote character that is not
359 part of a pair, or to the end of the input line, whichever comes earlier.
360 Leaving out the terminating double quote character at the end of the line
362 For clarity, if more arguments follow on the same input line,
363 it is recommended to follow the terminating double quote character
364 by a space character; in case the next character after the terminating
365 double quote character is anything else, it is regarded as the beginning
366 of the next, unquoted argument.
368 Both in quoted and unquoted arguments, pairs of backslashes
370 resolve to single backslashes.
371 In unquoted arguments, space characters can alternatively be included
372 by preceding them with a backslash
374 but quoting is usually better for clarity.
377 .Bl -tag -width Ds -offset indent -compact
378 .It Li .Fn strlen \(dqconst char *s\(dq
381 into one function argument.
387 would be considered separate arguments.
388 .It Li .Op \(dqFl a\(dq
391 as literal text instead of a flag macro.
393 .Sh REQUEST REFERENCE
397 parser recognises the following requests.
400 language defines many more requests not implemented in
403 Set line adjustment mode.
404 This line-scoped request is intended to have one argument to select
405 normal, left, right, or centre adjustment for subsequent text.
406 Currently, it is ignored including its arguments,
407 and the number of arguments is not checked.
409 Append to a macro definition.
410 The syntax of this request is the same as that of
412 It is currently ignored by
416 Append to a macro definition, specifying the macro name indirectly.
417 The syntax of this request is the same as that of
419 It is currently ignored by
423 Append to a macro definition, switching roff compatibility mode off
424 during macro execution.
425 The syntax of this request is the same as that of
427 It is currently ignored by
431 Changes the control character.
432 Its syntax is as follows:
433 .Bd -literal -offset indent
434 .Pf . Cm \&cc Op Ar c
439 is not specified, the control character is reset to
441 Trailing characters are ignored.
446 Its syntax can be either
447 .Bd -literal -offset indent
448 .Pf . Cm \&de Ar name
454 .Bd -literal -offset indent
455 .Pf . Cm \&de Ar name Ar end
460 Both forms define or redefine the macro
463 .Ar macro definition ,
464 which may consist of one or more input lines, including the newline
465 characters terminating each line, optionally containing calls to
469 macros or high-level macros like
473 macros, whichever applies to the document in question.
477 macro works in the same way as for
482 .Ar macro definition ,
483 and after that, it is also evaluated as a
487 macro, but not as a high-level macro.
489 The macro can be invoked later using the syntax
491 .D1 Pf . Ar name Op Ar argument Op Ar argument ...
493 Regarding argument parsing, see
497 The line invoking the macro will be replaced
498 in the input stream by the
499 .Ar macro definition ,
500 replacing all occurrences of
505 .Ar N Ns th Ar argument .
507 .Bd -literal -offset indent
509 \efI\e^\e\e$1\e^\efP\e\e$2
516 .D1 \efI\e^XtFree\e^\efP.
518 in the input stream, and thus in the output: \fI\^XtFree\^\fP.
520 Since macros and user-defined strings share a common string table,
523 clobbers the user-defined string
527 can also be printed using the
529 string interpolation syntax described below
531 but this is rarely useful because every macro definition contains at least
532 one explicit newline character.
534 In order to prevent endless recursion, both groff and
536 limit the stack depth for expanding macros and strings
537 to a large, but finite number.
538 Do not rely on the exact value of this limit.
542 macro, specifying the macro name indirectly.
543 The syntax of this request is the same as that of
545 It is currently ignored by
551 macro that will be executed with
553 compatibility mode switched off during macro execution.
554 This is a GNU extension not available in traditional
556 implementations and not even in older versions of groff.
561 compatibility mode at all, it handles this request as an alias for
564 Define a user-defined string.
565 Its syntax is as follows:
567 .D1 Pf . Cm \&ds Ar name Oo \(dq Oc Ns Ar string
573 arguments are space-separated.
576 begins with a double-quote character, that character will not be part
578 All remaining characters on the input line form the
580 including whitespace and double-quote characters, even trailing ones.
584 can be interpolated into subsequent text by using
585 .No \e* Ns Bq Ar name
588 of arbitrary length, or \e*(NN or \e*N if the length of
590 is two or one characters, respectively.
591 Interpolation can be prevented by escaping the leading backslash;
592 that is, an asterisk preceded by an even number of backslashes
593 does not trigger string interpolation.
595 Since user-defined strings and macros share a common string table,
602 used for defining a string can also be invoked as a macro,
603 in which case the following input line will be appended to the
605 forming a new input line passed to the
609 .Bd -literal -offset indent
620 Such abuse is of course strongly discouraged.
624 half of an if/else conditional.
625 Pops a result off the stack of conditional evaluations pushed by
627 and uses it as its conditional.
628 If no stack entries are present (e.g., due to no prior
631 then false is assumed.
632 The syntax of this request is similar to
634 except that the conditional is missing.
636 End an equation block.
640 Begin an equation block.
643 for a description of the equation language.
645 Change the font family.
646 This line-scoped request is intended to have one argument specifying
647 the font family to be selected.
648 It is a groff extension, and currently, it is ignored including its
649 arguments, and the number of arguments is not checked.
651 Specify hyphenation points in words.
652 This line-scoped request is currently ignored.
654 Set automatic hyphenation mode.
655 This line-scoped request is currently ignored.
659 half of an if/else conditional.
660 The result of the conditional is pushed into a stack used by subsequent
663 which may be separated by any intervening input (or not exist at all).
664 Its syntax is equivalent to
667 Begins a conditional.
668 Right now, the conditional evaluates to true
669 if and only if it starts with the letter
671 indicating processing in nroff style as opposed to troff style.
672 If a conditional is false, its children are not processed, but are
673 syntactically interpreted to preserve the integrity of the input
681 which may lead to interesting results, but
683 .D1 \&.if t .if t \e{\e
685 will continue to syntactically interpret to the block close of the final
687 Sub-conditionals, in this case, obviously inherit the truth value of
689 This request has the following syntax:
690 .Bd -literal -offset indent
695 .Bd -literal -offset indent
699 .Bd -literal -offset indent
704 .Bd -literal -offset indent
709 COND is a conditional statement.
710 roff allows for complicated conditionals; mandoc is much simpler.
711 At this time, mandoc supports only
720 All other invocations are read up to the next end of line or space and
723 If the BODY section is begun by an escaped brace
725 scope continues until a closing-brace escape sequence
727 If the BODY is not enclosed in braces, scope continues until
729 If the COND is followed by a BODY on the same line, whether after a
730 brace or not, then requests and macros
732 begin with a control character.
733 It is generally more intuitive, in this case, to write
734 .Bd -literal -offset indent
741 than having the request or macro follow as
743 .D1 \&.if COND \e{ .foo
745 The scope of a conditional is always parsed, but only executed if the
746 conditional evaluates to true.
750 is converted into a zero-width escape sequence if not passed as a
759 being considered an argument of the
764 Its syntax can be either
765 .Bd -literal -offset indent
772 .Bd -literal -offset indent
778 In the first case, input is ignored until a
780 request is encountered on its own line.
781 In the second case, input is ignored until the specified
783 macro is encountered.
784 Do not use the escape character
786 anywhere in the definition of
788 it would cause very strange behaviour.
792 macro is a roff request or a roff macro, like in
796 the subsequent invocation of
798 will first terminate the
800 then be invoked as usual.
801 Otherwise, it only terminates the
803 and arguments following it or the
805 request are discarded.
807 Declare the need for the specified minimum vertical space
808 before the next trap or the bottom of the page.
809 This line-scoped request is currently ignored.
811 Turn off automatic hyphenation mode.
812 This line-scoped request is currently ignored.
814 Remove a request, macro or string.
815 This request is intended to have one argument,
816 the name of the request, macro or string to be undefined.
817 Currently, it is ignored including its arguments,
818 and the number of arguments is not checked.
820 Define or change a register.
821 A register is an arbitrary string value that defines some sort of state,
822 which influences parsing and/or formatting.
823 Its syntax is as follows:
825 .D1 Pf \. Cm \&nr Ar name Oo +|- Oc Ns Ar value
829 may, at the moment, only be an integer.
830 If it is prefixed by a sign, the register will be
831 incremented or decremented instead of assigned to.
833 The following register
835 is handled specially:
838 If set to a positive integer value, certain
840 macros will behave in the same way as in the
843 If set to 0, these macros will behave in the same way as outside the
845 section, even when called within the
848 Note that starting a new
852 macro will reset this register.
855 Turn on no-space mode.
856 This line-scoped request is intended to take no arguments.
857 Currently, it is ignored including its arguments,
858 and the number of arguments is not checked.
861 This line-scoped request is intended to take one numerical argument.
862 Currently, it is ignored including its arguments,
863 and the number of arguments is not checked.
865 Include a source file.
866 Its syntax is as follows:
868 .D1 Pf \. Cm \&so Ar file
872 will be read and its contents processed as input in place of the
875 To avoid inadvertent inclusion of unrelated files,
877 only accepts relative paths not containing the strings
882 This request requires
884 to change to the right directory before calling
886 per convention to the root of the manual tree.
887 Typical usage looks like:
889 .Dl \&.so man3/Xcursor.3
891 As the whole concept is rather fragile, the use of
899 This line-scoped request can take an arbitrary number of arguments.
900 Currently, it is ignored including its arguments.
902 Output character translation.
903 Its syntax is as follows:
905 .D1 Pf \. Cm \&tr Ar [ab]+
909 characters are replaced
913 Replacement (or origin) characters may also be character escapes; thus,
917 replaces all invocations of \e(xx with \e(yy.
919 Re-start a table layout, retaining the options of the prior table
928 Begin a table, which formats input in aligned rows and columns.
931 for a description of the tbl language.
932 .Sh ESCAPE SEQUENCE REFERENCE
936 parser recognises the following escape sequences.
939 language defines more escape sequences not implemented in
945 documents, using escape sequences is discouraged except for those
950 A backslash followed by any character not listed here
951 simply prints that character itself.
953 A backslash at the end of an input line can be used to continue the
954 logical input line on the next physical input line, joining the text
955 on both lines together as if it were on a single input line.
957 The escape sequence backslash-space
959 is an unpaddable space-sized non-breaking space character; see
962 The rest of the input line is treated as
965 Hyphenation allowed at this point of the word; ignored by
968 Non-printing zero-width character; see
971 Acute accent special character; use
975 .Sx Special Characters
976 with two-letter names, see
978 .Ss \e*[ Ns Ar name ]
979 Interpolate the string with the
982 .Sx Predefined Strings
985 For short names, there are variants
991 .Dq mathematical minus sign .
993 .Sx Special Characters
994 with names of arbitrary length, see
997 One-twelfth em half-narrow space character, effectively zero-width in
1000 Grave accent special character; use
1004 Begin conditional input; see
1007 One-sixth em narrow space character, effectively zero-width in
1010 End conditional input; see
1013 Paddable non-breaking space character.
1015 Digit width space character.
1016 .Ss \eA\(aq Ns Ar string Ns \(aq
1017 Anchor definition; ignored by
1019 .Ss \eB\(aq Ns Ar string Ns \(aq
1022 is a numerical expession; ignored by
1024 .Ss \eb\(aq Ns Ar string Ns \(aq
1025 Bracket building function; ignored by
1027 .Ss \eC\(aq Ns Ar name Ns \(aq
1028 .Sx Special Characters
1029 with names of arbitrary length.
1031 Interrupt text processing to insert requests or macros; ignored by
1033 .Ss \eD\(aq Ns Ar string Ns \(aq
1034 Draw graphics function; ignored by
1037 Move down by half a line; ignored by
1040 Backslash special character.
1041 .Ss \eF[ Ns Ar name ]
1042 Switch font family (groff extension); ignored by
1044 For short names, there are variants
1048 .Ss \ef[ Ns Ar name ]
1052 .Sx Text Decoration .
1053 For short names, there are variants
1057 .Ss \eg[ Ns Ar name ]
1058 Interpolate the format of a number register; ignored by
1060 For short names, there are variants
1064 .Ss \eH\(aq Ns Oo +|- Oc Ns Ar number Ns \(aq
1065 Set the height of the current font; ignored by
1067 .Ss \eh\(aq Ns Ar number Ns \(aq
1068 Horizontal motion; ignored by
1070 .Ss \ek[ Ns Ar name ]
1071 Mark horizontal input place in register; ignored by
1073 For short names, there are variants
1077 .Ss \eL\(aq Ns Ar number Ns Oo Ar c Oc Ns \(aq
1078 Vertical line drawing function; ignored by
1080 .Ss \el\(aq Ns Ar number Ns Oo Ar c Oc Ns \(aq
1081 Horizontal line drawing function; ignored by
1083 .Ss \eM[ Ns Ar name ]
1084 Set fill (background) color (groff extension); ignored by
1086 For short names, there are variants
1090 .Ss \em[ Ns Ar name ]
1091 Set glyph drawing color (groff extension); ignored by
1093 For short names, there are variants
1097 .Ss \eN\(aq Ns Ar number Ns \(aq
1100 on the current font.
1101 .Ss \en[ Ns Ar name ]
1102 Interpolate the number register
1104 For short names, there are variants
1108 .Ss \eo\(aq Ns Ar string Ns \(aq
1113 .Ss \eR\(aq Ns Ar name Oo +|- Oc Ns Ar number Ns \(aq
1114 Set number register; ignored by
1116 .Ss \eS\(aq Ns Ar number Ns \(aq
1117 Slant output; ignored by
1119 .Ss \es\(aq Ns Oo +|- Oc Ns Ar number Ns \(aq
1120 Change point size; ignored by
1123 .No \es Ns Oo +|- Oc Ns Ar n ,
1124 .No \es Ns Oo +|- Oc Ns \(aq Ns Ar number Ns \(aq ,
1125 .No \es Ns [ Oo +|- Oc Ns Ar number ] ,
1127 .No \es Ns Oo +|- Oc Ns [ Ar number Ns ]
1128 are also parsed and ignored.
1130 Horizontal tab; ignored by
1133 Move up by half a line; ignored by
1135 .Ss \eV[ Ns Ar name ]
1136 Interpolate an environment variable; ignored by
1138 For short names, there are variants
1142 .Ss \ev\(aq Ns Ar number Ns \(aq
1143 Vertical motion; ignored by
1145 .Ss \ew\(aq Ns Ar string Ns \(aq
1146 Interpolate the width of the
1150 .Ss \eX\(aq Ns Ar string Ns \(aq
1153 as device control function; ignored in nroff mode and by
1155 .Ss \ex\(aq Ns Ar number Ns \(aq
1156 Extra line space function; ignored by
1158 .Ss \eY[ Ns Ar name ]
1159 Output a string as a device control function; ignored in nroff mode and by
1161 For short names, there are variants
1165 .Ss \eZ\(aq Ns Ar string Ns \(aq
1168 with zero width and height; ignored by
1171 Output the next character without advancing the cursor position;
1174 by simply skipping the next character.
1176 This section documents compatibility between mandoc and other
1178 implementations, at this time limited to GNU troff
1182 refers to groff version 1.15.
1192 macros are considered regular macros.
1195 implementations, these are special macros that must be specified without
1196 spacing between the control character (which must be a period) and the
1201 register is only compatible with OpenBSD's groff-1.15.
1203 Historic groff did not accept white-space before a custom
1211 and family would print funny white-spaces with historic groff when
1212 using the next-line syntax.
1222 .%A Joseph F. Ossanna
1223 .%A Brian W. Kernighan
1224 .%I AT&T Bell Laboratories
1225 .%T Troff User's Manual
1226 .%R Computing Science Technical Report
1228 .%C Murray Hill, New Jersey
1230 .%U http://www.kohala.com/start/troff/cstr54.ps
1233 .%A Joseph F. Ossanna
1234 .%A Brian W. Kernighan
1236 .%T Heirloom Documentation Tools Nroff/Troff User's Manual
1237 .%D September 17, 2007
1238 .%U http://heirloom.sourceforge.net/doctools/troff.pdf
1241 The RUNOFF typesetting system, whose input forms the basis for
1243 was written in MAD and FAP for the CTSS operating system by Jerome E.
1245 Doug McIlroy rewrote it in BCPL in 1969, renaming it
1247 Dennis M. Ritchie rewrote McIlroy's
1249 in PDP-11 assembly for
1251 Joseph F. Ossanna improved roff and renamed it nroff
1254 then ported nroff to C as troff, which Brian W. Kernighan released with
1256 In 1989, James Clarke re-implemented troff in C++, naming it groff.
1261 reference was written by
1262 .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
1264 .An Ingo Schwarze Aq Mt schwarze@openbsd.org .