ROFF(7) | NetBSD Miscellaneous Information Manual | ROFF(7) |
Input lines beginning with the control characters ‘.' or ‘'' are parsed for requests and macros. These define the document structure, change the processing state and manipulate the formatting. Some requests and macros also produce formatted output, while others do not.
All other input lines provide free-form text to be printed; the formatting of free-form text depends on the respective processing context.
Thus, the following request lines are all equivalent:
.ig end .ig end . ig end
A quoted argument may contain whitespace, and pairs of double quote characters (‘“”') resolve to single double quote characters. A quoted argument extends to the next double quote character that is not part of a pair, or to the end of the input line, whichever comes earlier. Leaving out the terminating double quote character at the end of the line is discouraged. For clarity, if more arguments follow on the same input line, it is recommended to follow the terminating double quote character by a space character; in case the next character after the terminating double quote character is anything else, it is regarded as the beginning of the next, unquoted argument.
Both in quoted and unquoted arguments, pairs of backslashes (‘\\') resolve to single backslashes. In unquoted arguments, space characters can alternatively be included by preceding them with a backslash (‘\ '), but quoting is usually better for clarity.
.de name macro definition ..
or
.de name end macro definition .end
Both forms define or redefine the macro name to represent the macro definition, which may consist of one or more input lines, including the newline characters terminating each line, optionally containing calls to roff requests, roff macros or high-level macros like man(7) or mdoc(7) macros, whichever applies to the document in question.
Specifying a custom end macro works in the same way as for ig; namely, the call to ‘.end' first ends the macro definition, and after that, it is also evaluated as a roff request or roff macro, but not as a high-level macro.
The macro can be invoked later using the syntax
.name [argument [argument ...]]
Regarding argument parsing, see MACRO SYNTAX above.
The line invoking the macro will be replaced in the input stream by the macro definition, replacing all occurrences of \\$N, where N is a digit, by the Nth argument. For example,
.de ZN \fI\^\\$1\^\fP\\$2 .. .ZN XtFree .
produces
\fI\^XtFree\^\fP.
in the input stream, and thus in the output: XtFree.
Since macros and user-defined strings share a common string table, defining a macro name clobbers the user-defined string name, and the macro definition can also be printed using the ‘\*' string interpolation syntax described below ds, but this is rarely useful because every macro definition contains at least one explicit newline character.
In order to prevent endless recursion, both groff and mandoc(1) limit the stack depth for expanding macros and strings to a large, but finite number. Do not rely on the exact value of this limit.
.ds name ["]string
The name and string arguments are space-separated. If the string begins with a double-quote character, that character will not be part of the string. All remaining characters on the input line form the string, including whitespace and double-quote characters, even trailing ones.
The string can be interpolated into subsequent text by using \*[name] for a name of arbitrary length, or \*(NN or \*N if the length of name is two or one characters, respectively. Interpolation can be prevented by escaping the leading backslash; that is, an asterisk preceded by an even number of backslashes does not trigger string interpolation.
Since user-defined strings and macros share a common string table, defining a string name clobbers the macro name, and the name used for defining a string can also be invoked as a macro, in which case the following input line will be appended to the string, forming a new input line passed to the roff parser. For example,
.ds badidea .S .badidea H SYNOPSIS
invokes the SH macro when used in a man(7) document. Such abuse is of course strongly discouraged.
.if t .ig
will discard the ‘.ig', which may lead to interesting results, but
.if t .if t \{\
will continue to syntactically interpret to the block close of the final conditional. Sub-conditionals, in this case, obviously inherit the truth value of the parent. This request has the following syntax:
.if COND \{\ BODY... .\}
.if COND \{ BODY BODY... \}
.if COND \{ BODY BODY... .\}
.if COND \ BODY
COND is a conditional statement. roff allows for complicated conditionals; mandoc is much simpler. At this time, mandoc supports only ‘n', evaluating to true; and ‘t', ‘e', and ‘o', evaluating to false. All other invocations are read up to the next end of line or space and evaluate as false.
If the BODY section is begun by an escaped brace ‘\{', scope continues until a closing-brace escape sequence ‘.\}'. If the BODY is not enclosed in braces, scope continues until the end of the line. If the COND is followed by a BODY on the same line, whether after a brace or not, then requests and macros must begin with a control character. It is generally more intuitive, in this case, to write
.if COND \{\ .foo bar .\}
than having the request or macro follow as
.if COND \{ .foo
The scope of a conditional is always parsed, but only executed if the conditional evaluates to true.
Note that text following an ‘.\}' escape sequence is discarded. Furthermore, if an explicit closing sequence ‘\}' is specified in a free-form line, the entire line is accepted within the scope of the prior request, not only the text preceding the close, with the ‘\}' collapsing into a zero-width space.
.ig ignored text ..
or
.ig end ignored text .end
In the first case, input is ignored until a ‘..' request is encountered on its own line. In the second case, input is ignored until the specified ‘.end' macro is encountered. Do not use the escape character ‘\' anywhere in the definition of end; it would cause very strange behaviour.
When the end macro is a roff request or a roff macro, like in
.ig if
the subsequent invocation of if will first terminate the ignored text, then be invoked as usual. Otherwise, it only terminates the ignored text, and arguments following it or the ‘..' request are discarded.
.nr name value
The value may, at the moment, only be an integer. So far, only the following register name is recognised:
.so file
The file will be read and its contents processed as input in place of the ‘.so' request line. To avoid inadvertant inclusion of unrelated files, mandoc(1) only accepts relative paths not containing the strings “../” and “/..”.
Joseph F. Ossanna and Brian W. Kernighan, Troff User's Manual, AT&T Bell Laboratories, Computing Science Technical Report, 54, 1976 and 1992, Murray Hill, New Jersey, http://www.kohala.com/start/troff/cstr54.ps.
Joseph F. Ossanna, Brian W. Kernighan, and Gunnar Ritter, Heirloom Documentation Tools Nroff/Troff User's Manual, September 17, 2007, http://heirloom.sourceforge.net/doctools/troff.pdf.
February 9, 2011 | NetBSD 5.99 |