1 .\" $OpenBSD: roff.7,v 1.20 2013/04/27 17:15:01 jmc Exp $
3 .\" Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 .\" Copyright (c) 2010, 2011 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.
18 .Dd $Mdocdate: April 27 2013 $
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 intermixed with their
40 To properly format such manuals, the
42 utility supports a tiny subset of
45 Only these requests 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 for
90 .Sx Special Characters ,
91 .Sx Predefined Strings ,
93 user-defined strings defined using the
97 Text following an escaped double-quote
99 whether in a request, macro, or text line, is ignored to the end of the line.
100 A request line beginning with a control character and comment escape
103 Furthermore, request lines with only a control character and optional
104 trailing whitespace are stripped from input.
107 .Bd -literal -offset indent -compact
108 \&.\e\(dq This is a comment line.
109 \&.\e\(dq The next line is ignored:
111 \&.Sh EXAMPLES \e\(dq This is a comment, too.
112 \&example text \e\(dq And so is this.
114 .Ss Special Characters
115 Special characters are used to encode special glyphs and are rendered
116 differently across output media.
117 They may occur in request, macro, and text lines.
118 Sequences begin with the escape character
120 followed by either an open-parenthesis
122 for two-character sequences; an open-bracket
124 for n-character sequences (terminated at a close-bracket
126 or a single one character sequence.
129 .Bl -tag -width Ds -offset indent -compact
131 Two-letter em dash escape.
133 One-letter backslash escape.
140 Terms may be text-decorated using the
142 escape followed by an indicator: B (bold), I (italic), R (regular), or P
143 (revert to previous mode).
144 A numerical representation 3, 2, or 1 (bold, italic, and regular,
145 respectively) may be used instead.
148 .Bl -tag -width Ds -offset indent -compact
150 Write in bold, then switch to regular font mode.
151 .It Li \efIitalic\efP
152 Write in italic, then return to previous font mode.
159 which encourages semantic annotation.
160 .Ss Predefined Strings
161 Predefined strings, like
162 .Sx Special Characters ,
163 mark special output glyphs.
164 Predefined strings are escaped with the slash-asterisk,
174 .Bl -tag -width Ds -offset indent -compact
176 Two-letter ampersand predefined string.
178 One-letter double-quote predefined string.
181 Predefined strings are not recommended for use,
182 as they differ across implementations.
187 Manuals using these predefined strings are almost certainly not portable.
189 Whitespace consists of the space character.
190 In text lines, whitespace is preserved within a line.
191 In request and macro lines, whitespace delimits arguments and is discarded.
193 Unescaped trailing spaces are stripped from text line input unless in a
195 In general, trailing whitespace on any input line is discouraged for
196 reasons of portability.
197 In the rare case that a blank character is needed at the end of an
198 input line, it may be forced by
201 Literal space characters can be produced in the output
202 using escape sequences.
203 In macro lines, they can also be included in arguments using quotation; see
207 Blank text lines, which may include whitespace, are only permitted
208 within literal contexts.
209 If the first character of a text line is a space, that line is printed
210 with a leading newline.
212 Many requests and macros support scaled widths for their arguments.
213 The syntax for a scaled width is
214 .Sq Li [+-]?[0-9]*.[0-9]*[:unit:] ,
215 where a decimal must be preceded or followed by at least one digit.
216 Negative numbers, while accepted, are truncated to zero.
218 The following scaling units are accepted:
220 .Bl -tag -width Ds -offset indent -compact
233 default vertical span
245 default horizontal span
250 Using anything other than
256 is necessarily non-portable across output media.
260 If a scaling unit is not provided, the numerical value is interpreted
261 under the default rules of
263 for vertical spaces and
268 .Bl -tag -width ".Bl -tag -width 2i" -offset indent -compact
269 .It Li \&.Bl -tag -width 2i
270 two-inch tagged list indentation in
273 two-inch tagged list indentation in
279 Each sentence should terminate at the end of an input line.
280 By doing this, a formatter will be able to apply the proper amount of
281 spacing after the end of sentence (unescaped) period, exclamation mark,
282 or question mark followed by zero or more non-sentence closing
291 The proper spacing is also intelligently preserved if a sentence ends at
292 the boundary of a macro line.
295 .Bd -literal -offset indent -compact
296 Do not end sentences mid-line like this. Instead,
297 end a sentence like this.
298 A macro would end like this:
302 A request or macro line consists of:
306 the control character
310 at the beginning of the line,
312 optionally an arbitrary amount of whitespace,
314 the name of the request or the macro, which is one word of arbitrary
315 length, terminated by whitespace,
317 and zero or more arguments delimited by whitespace.
320 Thus, the following request lines are all equivalent:
321 .Bd -literal -offset indent
327 Macros are provided by the
331 languages and can be defined by the
334 When called, they follow the same syntax as requests, except that
335 macro arguments may optionally be quoted by enclosing them
336 in double quote characters
338 Quoted text, even if it contains whitespace or would cause
339 a macro invocation when unquoted, is always considered literal text.
340 Inside quoted text, pairs of double quote characters
342 resolve to single double quote characters.
344 To be recognised as the beginning of a quoted argument, the opening
345 quote character must be preceded by a space character.
346 A quoted argument extends to the next double quote character that is not
347 part of a pair, or to the end of the input line, whichever comes earlier.
348 Leaving out the terminating double quote character at the end of the line
350 For clarity, if more arguments follow on the same input line,
351 it is recommended to follow the terminating double quote character
352 by a space character; in case the next character after the terminating
353 double quote character is anything else, it is regarded as the beginning
354 of the next, unquoted argument.
356 Both in quoted and unquoted arguments, pairs of backslashes
358 resolve to single backslashes.
359 In unquoted arguments, space characters can alternatively be included
360 by preceding them with a backslash
362 but quoting is usually better for clarity.
365 .Bl -tag -width Ds -offset indent -compact
366 .It Li .Fn strlen \(dqconst char *s\(dq
369 into one function argument.
375 would be considered separate arguments.
376 .It Li .Op \(dqFl a\(dq
379 as literal text instead of a flag macro.
381 .Sh REQUEST REFERENCE
385 parser recognises the following requests.
388 language defines many more requests not implemented in
391 Set line adjustment mode.
392 This line-scoped request is intended to have one argument to select
393 normal, left, right, or centre adjustment for subsequent text.
394 Currently, it is ignored including its arguments,
395 and the number of arguments is not checked.
397 Append to a macro definition.
398 The syntax of this request is the same as that of
400 It is currently ignored by
404 Append to a macro definition, specifying the macro name indirectly.
405 The syntax of this request is the same as that of
407 It is currently ignored by
411 Append to a macro definition, switching roff compatibility mode off
412 during macro execution.
413 The syntax of this request is the same as that of
415 It is currently ignored by
419 Changes the control character.
420 Its syntax is as follows:
421 .Bd -literal -offset indent
422 .Pf . Cm \&cc Op Ar c
427 is not specified, the control character is reset to
429 Trailing characters are ignored.
434 Its syntax can be either
435 .Bd -literal -offset indent
436 .Pf . Cm \&de Ar name
442 .Bd -literal -offset indent
443 .Pf . Cm \&de Ar name Ar end
448 Both forms define or redefine the macro
451 .Ar macro definition ,
452 which may consist of one or more input lines, including the newline
453 characters terminating each line, optionally containing calls to
457 macros or high-level macros like
461 macros, whichever applies to the document in question.
465 macro works in the same way as for
470 .Ar macro definition ,
471 and after that, it is also evaluated as a
475 macro, but not as a high-level macro.
477 The macro can be invoked later using the syntax
479 .D1 Pf . Ar name Op Ar argument Op Ar argument ...
481 Regarding argument parsing, see
485 The line invoking the macro will be replaced
486 in the input stream by the
487 .Ar macro definition ,
488 replacing all occurrences of
493 .Ar N Ns th Ar argument .
495 .Bd -literal -offset indent
497 \efI\e^\e\e$1\e^\efP\e\e$2
504 .D1 \efI\e^XtFree\e^\efP.
506 in the input stream, and thus in the output: \fI\^XtFree\^\fP.
508 Since macros and user-defined strings share a common string table,
511 clobbers the user-defined string
515 can also be printed using the
517 string interpolation syntax described below
519 but this is rarely useful because every macro definition contains at least
520 one explicit newline character.
522 In order to prevent endless recursion, both groff and
524 limit the stack depth for expanding macros and strings
525 to a large, but finite number.
526 Do not rely on the exact value of this limit.
530 macro, specifying the macro name indirectly.
531 The syntax of this request is the same as that of
533 It is currently ignored by
539 macro that will be executed with
541 compatibility mode switched off during macro execution.
542 This is a GNU extension not available in traditional
544 implementations and not even in older versions of groff.
549 compatibility mode at all, it handles this request as an alias for
552 Define a user-defined string.
553 Its syntax is as follows:
555 .D1 Pf . Cm \&ds Ar name Oo \(dq Oc Ns Ar string
561 arguments are space-separated.
564 begins with a double-quote character, that character will not be part
566 All remaining characters on the input line form the
568 including whitespace and double-quote characters, even trailing ones.
572 can be interpolated into subsequent text by using
573 .No \e* Ns Bq Ar name
576 of arbitrary length, or \e*(NN or \e*N if the length of
578 is two or one characters, respectively.
579 Interpolation can be prevented by escaping the leading backslash;
580 that is, an asterisk preceded by an even number of backslashes
581 does not trigger string interpolation.
583 Since user-defined strings and macros share a common string table,
590 used for defining a string can also be invoked as a macro,
591 in which case the following input line will be appended to the
593 forming a new input line passed to the
597 .Bd -literal -offset indent
608 Such abuse is of course strongly discouraged.
612 half of an if/else conditional.
613 Pops a result off the stack of conditional evaluations pushed by
615 and uses it as its conditional.
616 If no stack entries are present (e.g., due to no prior
619 then false is assumed.
620 The syntax of this request is similar to
622 except that the conditional is missing.
624 End an equation block.
628 Begin an equation block.
631 for a description of the equation language.
634 Its syntax is as follows:
636 .D1 Pf . Cm \&ft Op Ar font
640 arguments are supported:
641 .Bl -tag -width 4n -offset indent
642 .It Cm B , BI , 3 , 4
651 switches to normal font
652 .It Cm P No "or no argument"
653 switches back to the previous font
656 This request takes effect only locally, may be overridden by macros
657 and escape sequences, and is only supported in
661 Set automatic hyphenation mode.
662 This line-scoped request is currently ignored.
666 half of an if/else conditional.
667 The result of the conditional is pushed into a stack used by subsequent
670 which may be separated by any intervening input (or not exist at all).
671 Its syntax is equivalent to
674 Begins a conditional.
675 Right now, the conditional evaluates to true
676 if and only if it starts with the letter
678 indicating processing in nroff style as opposed to troff style.
679 If a conditional is false, its children are not processed, but are
680 syntactically interpreted to preserve the integrity of the input
688 which may lead to interesting results, but
690 .D1 \&.if t .if t \e{\e
692 will continue to syntactically interpret to the block close of the final
694 Sub-conditionals, in this case, obviously inherit the truth value of
696 This request has the following syntax:
697 .Bd -literal -offset indent
702 .Bd -literal -offset indent
706 .Bd -literal -offset indent
711 .Bd -literal -offset indent
716 COND is a conditional statement.
717 roff allows for complicated conditionals; mandoc is much simpler.
718 At this time, mandoc supports only
727 All other invocations are read up to the next end of line or space and
730 If the BODY section is begun by an escaped brace
732 scope continues until a closing-brace escape sequence
734 If the BODY is not enclosed in braces, scope continues until
736 If the COND is followed by a BODY on the same line, whether after a
737 brace or not, then requests and macros
739 begin with a control character.
740 It is generally more intuitive, in this case, to write
741 .Bd -literal -offset indent
748 than having the request or macro follow as
750 .D1 \&.if COND \e{ .foo
752 The scope of a conditional is always parsed, but only executed if the
753 conditional evaluates to true.
757 is converted into a zero-width escape sequence if not passed as a
766 being considered an argument of the
771 Its syntax can be either
772 .Bd -literal -offset indent
779 .Bd -literal -offset indent
785 In the first case, input is ignored until a
787 request is encountered on its own line.
788 In the second case, input is ignored until the specified
790 macro is encountered.
791 Do not use the escape character
793 anywhere in the definition of
795 it would cause very strange behaviour.
799 macro is a roff request or a roff macro, like in
803 the subsequent invocation of
805 will first terminate the
807 then be invoked as usual.
808 Otherwise, it only terminates the
810 and arguments following it or the
812 request are discarded.
814 Declare the need for the specified minimum vertical space
815 before the next trap or the bottom of the page.
816 This line-scoped request is currently ignored.
818 Turn off automatic hyphenation mode.
819 This line-scoped request is currently ignored.
821 Remove a request, macro or string.
822 This request is intended to have one argument,
823 the name of the request, macro or string to be undefined.
824 Currently, it is ignored including its arguments,
825 and the number of arguments is not checked.
828 A register is an arbitrary string value that defines some sort of state,
829 which influences parsing and/or formatting.
830 Its syntax is as follows:
832 .D1 Pf \. Cm \&nr Ar name Ar value
836 may, at the moment, only be an integer.
837 So far, only the following register
842 If set to a positive integer value, certain
844 macros will behave in the same way as in the
847 If set to 0, these macros will behave in the same way as outside the
849 section, even when called within the
852 Note that starting a new
856 macro will reset this register.
859 Turn on no-space mode.
860 This line-scoped request is intended to take no arguments.
861 Currently, it is ignored including its arguments,
862 and the number of arguments is not checked.
865 This line-scoped request is intended to take one numerical argument.
866 Currently, it is ignored including its arguments,
867 and the number of arguments is not checked.
869 Include a source file.
870 Its syntax is as follows:
872 .D1 Pf \. Cm \&so Ar file
876 will be read and its contents processed as input in place of the
879 To avoid inadvertent inclusion of unrelated files,
881 only accepts relative paths not containing the strings
886 This request requires
888 to change to the right directory before calling
890 per convention to the root of the manual tree.
891 Typical usage looks like:
893 .Dl \&.so man3/Xcursor.3
895 As the whole concept is rather fragile, the use of
903 This line-scoped request can take an arbitrary number of arguments.
904 Currently, it is ignored including its arguments.
906 Output character translation.
907 Its syntax is as follows:
909 .D1 Pf \. Cm \&tr Ar [ab]+
913 characters are replaced
917 Replacement (or origin) characters may also be character escapes; thus,
921 replaces all invocations of \e(xx with \e(yy.
923 Re-start a table layout, retaining the options of the prior table
932 Begin a table, which formats input in aligned rows and columns.
935 for a description of the tbl language.
937 This section documents compatibility between mandoc and other
939 implementations, at this time limited to GNU troff
943 refers to groff version 1.15.
953 macros are considered regular macros.
956 implementations, these are special macros that must be specified without
957 spacing between the control character (which must be a period) and the
962 register is only compatible with OpenBSD's groff-1.15.
964 Historic groff did not accept white-space before a custom
972 and family would print funny white-spaces with historic groff when
973 using the next-line syntax.
983 .%A Joseph F. Ossanna
984 .%A Brian W. Kernighan
985 .%I AT&T Bell Laboratories
986 .%T Troff User's Manual
987 .%R Computing Science Technical Report
989 .%C Murray Hill, New Jersey
991 .%U http://www.kohala.com/start/troff/cstr54.ps
994 .%A Joseph F. Ossanna
995 .%A Brian W. Kernighan
997 .%T Heirloom Documentation Tools Nroff/Troff User's Manual
998 .%D September 17, 2007
999 .%U http://heirloom.sourceforge.net/doctools/troff.pdf
1002 The RUNOFF typesetting system, whose input forms the basis for
1004 was written in MAD and FAP for the CTSS operating system by Jerome E.
1006 Doug McIlroy rewrote it in BCPL in 1969, renaming it
1008 Dennis M. Ritchie rewrote McIlroy's
1010 in PDP-11 assembly for
1012 Joseph F. Ossanna improved roff and renamed it nroff
1015 then ported nroff to C as troff, which Brian W. Kernighan released with
1017 In 1989, James Clarke re-implemented troff in C++, naming it groff.
1022 reference was written by
1023 .An Kristaps Dzonsons ,
1024 .Mt kristaps@bsd.lv ;
1027 .Mt schwarze@openbsd.org .