1 .\" $Id: roff.7,v 1.42 2013/08/08 20:07:47 schwarze 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: August 8 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.
146 The indicator or numerical representative may be preceded by C
147 (constant-width), which is ignored.
149 The two-character indicator
151 requests a font that is both bold and italic.
152 It may not be portable to old roff implementations.
155 .Bl -tag -width Ds -offset indent -compact
157 Write in \fBbold\fP, then switch to regular font mode.
158 .It Li \efIitalic\efP
159 Write in \fIitalic\fP, then return to previous font mode.
160 .It Li \ef(BIbold italic\efP
161 Write in \f(BIbold italic\fP, then return to previous font mode.
168 which encourages semantic annotation.
169 .Ss Predefined Strings
170 Predefined strings, like
171 .Sx Special Characters ,
172 mark special output glyphs.
173 Predefined strings are escaped with the slash-asterisk,
183 .Bl -tag -width Ds -offset indent -compact
185 Two-letter ampersand predefined string.
187 One-letter double-quote predefined string.
190 Predefined strings are not recommended for use,
191 as they differ across implementations.
196 Manuals using these predefined strings are almost certainly not portable.
198 Whitespace consists of the space character.
199 In text lines, whitespace is preserved within a line.
200 In request and macro lines, whitespace delimits arguments and is discarded.
202 Unescaped trailing spaces are stripped from text line input unless in a
204 In general, trailing whitespace on any input line is discouraged for
205 reasons of portability.
206 In the rare case that a blank character is needed at the end of an
207 input line, it may be forced by
210 Literal space characters can be produced in the output
211 using escape sequences.
212 In macro lines, they can also be included in arguments using quotation; see
216 Blank text lines, which may include whitespace, are only permitted
217 within literal contexts.
218 If the first character of a text line is a space, that line is printed
219 with a leading newline.
221 Many requests and macros support scaled widths for their arguments.
222 The syntax for a scaled width is
223 .Sq Li [+-]?[0-9]*.[0-9]*[:unit:] ,
224 where a decimal must be preceded or followed by at least one digit.
225 Negative numbers, while accepted, are truncated to zero.
227 The following scaling units are accepted:
229 .Bl -tag -width Ds -offset indent -compact
242 default vertical span
254 default horizontal span
259 Using anything other than
265 is necessarily non-portable across output media.
269 If a scaling unit is not provided, the numerical value is interpreted
270 under the default rules of
272 for vertical spaces and
277 .Bl -tag -width ".Bl -tag -width 2i" -offset indent -compact
278 .It Li \&.Bl -tag -width 2i
279 two-inch tagged list indentation in
282 two-inch tagged list indentation in
288 Each sentence should terminate at the end of an input line.
289 By doing this, a formatter will be able to apply the proper amount of
290 spacing after the end of sentence (unescaped) period, exclamation mark,
291 or question mark followed by zero or more non-sentence closing
300 The proper spacing is also intelligently preserved if a sentence ends at
301 the boundary of a macro line.
304 .Bd -literal -offset indent -compact
305 Do not end sentences mid-line like this. Instead,
306 end a sentence like this.
307 A macro would end like this:
311 A request or macro line consists of:
315 the control character
319 at the beginning of the line,
321 optionally an arbitrary amount of whitespace,
323 the name of the request or the macro, which is one word of arbitrary
324 length, terminated by whitespace,
326 and zero or more arguments delimited by whitespace.
329 Thus, the following request lines are all equivalent:
330 .Bd -literal -offset indent
336 Macros are provided by the
340 languages and can be defined by the
343 When called, they follow the same syntax as requests, except that
344 macro arguments may optionally be quoted by enclosing them
345 in double quote characters
347 Quoted text, even if it contains whitespace or would cause
348 a macro invocation when unquoted, is always considered literal text.
349 Inside quoted text, pairs of double quote characters
351 resolve to single double quote characters.
353 To be recognised as the beginning of a quoted argument, the opening
354 quote character must be preceded by a space character.
355 A quoted argument extends to the next double quote character that is not
356 part of a pair, or to the end of the input line, whichever comes earlier.
357 Leaving out the terminating double quote character at the end of the line
359 For clarity, if more arguments follow on the same input line,
360 it is recommended to follow the terminating double quote character
361 by a space character; in case the next character after the terminating
362 double quote character is anything else, it is regarded as the beginning
363 of the next, unquoted argument.
365 Both in quoted and unquoted arguments, pairs of backslashes
367 resolve to single backslashes.
368 In unquoted arguments, space characters can alternatively be included
369 by preceding them with a backslash
371 but quoting is usually better for clarity.
374 .Bl -tag -width Ds -offset indent -compact
375 .It Li .Fn strlen \(dqconst char *s\(dq
378 into one function argument.
384 would be considered separate arguments.
385 .It Li .Op \(dqFl a\(dq
388 as literal text instead of a flag macro.
390 .Sh REQUEST REFERENCE
394 parser recognises the following requests.
397 language defines many more requests not implemented in
400 Set line adjustment mode.
401 This line-scoped request is intended to have one argument to select
402 normal, left, right, or centre adjustment for subsequent text.
403 Currently, it is ignored including its arguments,
404 and the number of arguments is not checked.
406 Append to a macro definition.
407 The syntax of this request is the same as that of
409 It is currently ignored by
413 Append to a macro definition, specifying the macro name indirectly.
414 The syntax of this request is the same as that of
416 It is currently ignored by
420 Append to a macro definition, switching roff compatibility mode off
421 during macro execution.
422 The syntax of this request is the same as that of
424 It is currently ignored by
428 Changes the control character.
429 Its syntax is as follows:
430 .Bd -literal -offset indent
431 .Pf . Cm \&cc Op Ar c
436 is not specified, the control character is reset to
438 Trailing characters are ignored.
443 Its syntax can be either
444 .Bd -literal -offset indent
445 .Pf . Cm \&de Ar name
451 .Bd -literal -offset indent
452 .Pf . Cm \&de Ar name Ar end
457 Both forms define or redefine the macro
460 .Ar macro definition ,
461 which may consist of one or more input lines, including the newline
462 characters terminating each line, optionally containing calls to
466 macros or high-level macros like
470 macros, whichever applies to the document in question.
474 macro works in the same way as for
479 .Ar macro definition ,
480 and after that, it is also evaluated as a
484 macro, but not as a high-level macro.
486 The macro can be invoked later using the syntax
488 .D1 Pf . Ar name Op Ar argument Op Ar argument ...
490 Regarding argument parsing, see
494 The line invoking the macro will be replaced
495 in the input stream by the
496 .Ar macro definition ,
497 replacing all occurrences of
502 .Ar N Ns th Ar argument .
504 .Bd -literal -offset indent
506 \efI\e^\e\e$1\e^\efP\e\e$2
513 .D1 \efI\e^XtFree\e^\efP.
515 in the input stream, and thus in the output: \fI\^XtFree\^\fP.
517 Since macros and user-defined strings share a common string table,
520 clobbers the user-defined string
524 can also be printed using the
526 string interpolation syntax described below
528 but this is rarely useful because every macro definition contains at least
529 one explicit newline character.
531 In order to prevent endless recursion, both groff and
533 limit the stack depth for expanding macros and strings
534 to a large, but finite number.
535 Do not rely on the exact value of this limit.
539 macro, specifying the macro name indirectly.
540 The syntax of this request is the same as that of
542 It is currently ignored by
548 macro that will be executed with
550 compatibility mode switched off during macro execution.
551 This is a GNU extension not available in traditional
553 implementations and not even in older versions of groff.
558 compatibility mode at all, it handles this request as an alias for
561 Define a user-defined string.
562 Its syntax is as follows:
564 .D1 Pf . Cm \&ds Ar name Oo \(dq Oc Ns Ar string
570 arguments are space-separated.
573 begins with a double-quote character, that character will not be part
575 All remaining characters on the input line form the
577 including whitespace and double-quote characters, even trailing ones.
581 can be interpolated into subsequent text by using
582 .No \e* Ns Bq Ar name
585 of arbitrary length, or \e*(NN or \e*N if the length of
587 is two or one characters, respectively.
588 Interpolation can be prevented by escaping the leading backslash;
589 that is, an asterisk preceded by an even number of backslashes
590 does not trigger string interpolation.
592 Since user-defined strings and macros share a common string table,
599 used for defining a string can also be invoked as a macro,
600 in which case the following input line will be appended to the
602 forming a new input line passed to the
606 .Bd -literal -offset indent
617 Such abuse is of course strongly discouraged.
621 half of an if/else conditional.
622 Pops a result off the stack of conditional evaluations pushed by
624 and uses it as its conditional.
625 If no stack entries are present (e.g., due to no prior
628 then false is assumed.
629 The syntax of this request is similar to
631 except that the conditional is missing.
633 End an equation block.
637 Begin an equation block.
640 for a description of the equation language.
642 Set automatic hyphenation mode.
643 This line-scoped request is currently ignored.
647 half of an if/else conditional.
648 The result of the conditional is pushed into a stack used by subsequent
651 which may be separated by any intervening input (or not exist at all).
652 Its syntax is equivalent to
655 Begins a conditional.
656 Right now, the conditional evaluates to true
657 if and only if it starts with the letter
659 indicating processing in nroff style as opposed to troff style.
660 If a conditional is false, its children are not processed, but are
661 syntactically interpreted to preserve the integrity of the input
669 which may lead to interesting results, but
671 .D1 \&.if t .if t \e{\e
673 will continue to syntactically interpret to the block close of the final
675 Sub-conditionals, in this case, obviously inherit the truth value of
677 This request has the following syntax:
678 .Bd -literal -offset indent
683 .Bd -literal -offset indent
687 .Bd -literal -offset indent
692 .Bd -literal -offset indent
697 COND is a conditional statement.
698 roff allows for complicated conditionals; mandoc is much simpler.
699 At this time, mandoc supports only
708 All other invocations are read up to the next end of line or space and
711 If the BODY section is begun by an escaped brace
713 scope continues until a closing-brace escape sequence
715 If the BODY is not enclosed in braces, scope continues until
717 If the COND is followed by a BODY on the same line, whether after a
718 brace or not, then requests and macros
720 begin with a control character.
721 It is generally more intuitive, in this case, to write
722 .Bd -literal -offset indent
729 than having the request or macro follow as
731 .D1 \&.if COND \e{ .foo
733 The scope of a conditional is always parsed, but only executed if the
734 conditional evaluates to true.
738 is converted into a zero-width escape sequence if not passed as a
747 being considered an argument of the
752 Its syntax can be either
753 .Bd -literal -offset indent
760 .Bd -literal -offset indent
766 In the first case, input is ignored until a
768 request is encountered on its own line.
769 In the second case, input is ignored until the specified
771 macro is encountered.
772 Do not use the escape character
774 anywhere in the definition of
776 it would cause very strange behaviour.
780 macro is a roff request or a roff macro, like in
784 the subsequent invocation of
786 will first terminate the
788 then be invoked as usual.
789 Otherwise, it only terminates the
791 and arguments following it or the
793 request are discarded.
795 Declare the need for the specified minimum vertical space
796 before the next trap or the bottom of the page.
797 This line-scoped request is currently ignored.
799 Turn off automatic hyphenation mode.
800 This line-scoped request is currently ignored.
802 Remove a request, macro or string.
803 This request is intended to have one argument,
804 the name of the request, macro or string to be undefined.
805 Currently, it is ignored including its arguments,
806 and the number of arguments is not checked.
809 A register is an arbitrary string value that defines some sort of state,
810 which influences parsing and/or formatting.
811 Its syntax is as follows:
813 .D1 Pf \. Cm \&nr Ar name Ar value
817 may, at the moment, only be an integer.
818 So far, only the following register
823 If set to a positive integer value, certain
825 macros will behave in the same way as in the
828 If set to 0, these macros will behave in the same way as outside the
830 section, even when called within the
833 Note that starting a new
837 macro will reset this register.
840 Turn on no-space mode.
841 This line-scoped request is intended to take no arguments.
842 Currently, it is ignored including its arguments,
843 and the number of arguments is not checked.
846 This line-scoped request is intended to take one numerical argument.
847 Currently, it is ignored including its arguments,
848 and the number of arguments is not checked.
850 Include a source file.
851 Its syntax is as follows:
853 .D1 Pf \. Cm \&so Ar file
857 will be read and its contents processed as input in place of the
860 To avoid inadvertent inclusion of unrelated files,
862 only accepts relative paths not containing the strings
867 This request requires
869 to change to the right directory before calling
871 per convention to the root of the manual tree.
872 Typical usage looks like:
874 .Dl \&.so man3/Xcursor.3
876 As the whole concept is rather fragile, the use of
884 This line-scoped request can take an arbitrary number of arguments.
885 Currently, it is ignored including its arguments.
887 Output character translation.
888 Its syntax is as follows:
890 .D1 Pf \. Cm \&tr Ar [ab]+
894 characters are replaced
898 Replacement (or origin) characters may also be character escapes; thus,
902 replaces all invocations of \e(xx with \e(yy.
904 Re-start a table layout, retaining the options of the prior table
913 Begin a table, which formats input in aligned rows and columns.
916 for a description of the tbl language.
918 This section documents compatibility between mandoc and other
920 implementations, at this time limited to GNU troff
924 refers to groff version 1.15.
934 macros are considered regular macros.
937 implementations, these are special macros that must be specified without
938 spacing between the control character (which must be a period) and the
943 register is only compatible with OpenBSD's groff-1.15.
945 Historic groff did not accept white-space before a custom
953 and family would print funny white-spaces with historic groff when
954 using the next-line syntax.
964 .%A Joseph F. Ossanna
965 .%A Brian W. Kernighan
966 .%I AT&T Bell Laboratories
967 .%T Troff User's Manual
968 .%R Computing Science Technical Report
970 .%C Murray Hill, New Jersey
972 .%U http://www.kohala.com/start/troff/cstr54.ps
975 .%A Joseph F. Ossanna
976 .%A Brian W. Kernighan
978 .%T Heirloom Documentation Tools Nroff/Troff User's Manual
979 .%D September 17, 2007
980 .%U http://heirloom.sourceforge.net/doctools/troff.pdf
983 The RUNOFF typesetting system, whose input forms the basis for
985 was written in MAD and FAP for the CTSS operating system by Jerome E.
987 Doug McIlroy rewrote it in BCPL in 1969, renaming it
989 Dennis M. Ritchie rewrote McIlroy's
991 in PDP-11 assembly for
993 Joseph F. Ossanna improved roff and renamed it nroff
996 then ported nroff to C as troff, which Brian W. Kernighan released with
998 In 1989, James Clarke re-implemented troff in C++, naming it groff.
1003 reference was written by
1004 .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
1006 .An Ingo Schwarze Aq Mt schwarze@openbsd.org .