ROFF(7)

NAME
roff - roff language reference for mandoc

DESCRIPTION
The roff language is a general purpose text formatting language. In particular, it serves as the basis for the mdoc(7) and man(7) manual formatting macro languages. This manual describes the subset of the roff language accepted by the mandoc(1) utility.

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.

LANGUAGE SYNTAX
roff documents may contain only graphable 7-bit ASCII characters, the space character, and, in certain circumstances, the tab character. To produce other characters in the output, use the escape sequences documented in the mandoc_char(7) manual.

All manuals must have UNIX line terminators.

REQUEST SYNTAX
A request or macro line consists of:

1.  the control character ‘’. or ‘'’ at the beginning of the line,
2.  optionally an arbitrary amount of whitespace,
3.  the name of the request or the macro, which is one word of arbitrary length, terminated by whitespace,
4.  and zero or more arguments delimited by whitespace.

Thus, the following request lines are all equivalent:

    .ig end
    .ig    end
    .   ig end

REQUEST REFERENCE
The mandoc(1) roff parser recognizes the following requests. Note that the roff language defines many more requests not implemented in mandoc(1).

  ad
Set line adjustment mode. This line-scoped request is intended to have one argument to select normal, left, right, or center adjustment for subsequent text. Currently, it is ignored including its arguments, and the number of arguments is not checked.

  am
Append to a macro definition. The syntax of this request is the same as that of de. It is currently ignored by mandoc(1), as are its children.

  ami
Append to a macro definition, specifying the macro name indirectly. The syntax of this request is the same as that of dei. It is currently ignored by mandoc(1), as are its children.

  am1
Append to a macro definition, switching roff compatibility mode off during macro execution. The syntax of this request is the same as that of de1. It is currently ignored by mandoc(1), as are its children.

  de
Define a roff macro. Its syntax can be either

    .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 ...]]

Arguments are separated by blank characters and can be quoted using double-quotes (‘"’) to allow inclusion of blank characters into arguments. To include the double-quote character into a quoted argument, escape it from ending the argument by doubling it.

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.

  dei
Define a roff macro, specifying the macro name indirectly. The syntax of this request is the same as that of de. It is currently ignored by mandoc(1), as are its children.

  de1
Define a roff macro that will be executed with roff compatibility mode switched off during macro execution. This is a GNU extension not available in traditional roff implementations and not even in older versions of groff. Since mandoc(1) does not implement roff compatibility mode at all, it handles this request as an alias for de.

  ds
Define a user-defined string. Its syntax is as follows:

    .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.

  el
The "else" half of an if/else conditional. Pops a result off the stack of conditional evaluations pushed by ie and uses it as its conditional. If no stack entries are present (e.g., due to no prior ie calls) then false is assumed. The syntax of this request is similar to if except that the conditional is missing.

  hy
Set automatic hyphenation mode. This line-scoped request is currently ignored.

  ie
The "if" half of an if/else conditional. The result of the conditional is pushed into a stack used by subsequent invocations of el, which may be separated by any intervening input (or not exist at all). Its syntax is equivalent to if.

  if
Begins a conditional. Right now, the conditional evaluates to true if and only if it starts with the letter n, indicating processing in nroff style as opposed to troff style. If a conditional is false, its children are not processed, but are syntactically interpreted to preserve the integrity of the input document. Thus,

    .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
Ignore input. Its syntax can be either

    .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.

  ne
Declare the need for the specified minimum vertical space before the next trap or the bottom of the page. This line-scoped request is currently ignored.

  nh
Turn off automatic hyphenation mode. This line-scoped request is currently ignored.

  rm
Remove a request, macro or string. This request is intended to have one argument, the name of the request, macro or string to be undefined. Currently, it is ignored including its arguments, and the number of arguments is not checked.

  nr
Define a register. A register is an arbitrary string value that defines some sort of state, which influences parsing and/or formatting. Its syntax is as follows:

    .nr name value

The value may, at the moment, only be an integer. So far, only the following register name is recognised:

nS  If set to a positive integer value, certain mdoc(7) macros will behave in the same way as in the SYNOPSIS section. If set to 0, these macros will behave in the same way as outside the SYNOPSIS section, even when called within the SYNOPSIS section itself. Note that starting a new mdoc(7) section with the Sh macro will reset this register.

  so
Include a source file. Its syntax is as follows:

    .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 "/..".

  tr
Output character translation. This request is intended to have one argument, consisting of an even number of characters. Currently, it is ignored including its arguments, and the number of arguments is not checked.

  T&
Re-start a table layout, retaining the options of the prior table invocation. See TS.

  TE
End a table context. See TS.

  TS
Begin a table, which formats input in aligned rows and columns. See tbl(7) for a description of the tbl language.

COMPATIBILITY
This section documents compatibility between mandoc and other other roff implementations, at this time limited to GNU troff ("groff"). The term "historic groff" refers to groff version 1.15.

-   The nS register is only compatible with OpenBSD's groff-1.15.
-   Historic groff did not accept white-space before a custom end macro for the ig request.
-   The if and family would print funny white-spaces with historic groff when using the next-line syntax.

SEE ALSO
mandoc(1), man(7), mandoc_char(7), mdoc(7), tbl(7) Joseph F. Ossanna, Brian W. Kernighan, AT&T Bell Laboratories, Troff User's Manual, Computing Science Technical Report, 54, Murray Hill, New Jersey, 1976 and 1992, http://www.kohala.com/start/troff/cstr54.ps. Joseph F. Ossanna, Brian W. Kernighan, Gunnar Ritter, Heirloom Documentation Tools Nroff/Troff User's Manual, September 17, 2007, http://heirloom.sourceforge.net/doctools/troff.pdf.

HISTORY
The RUNOFF typesetting system was written in PL/1 for the CTSS operating system by Jerome ("Jerry") E. Saltzer in 1961. It was first used as the main documentation tool by Multics since 1963. Robert ("Bob") H. Morris ported it to the GE-635 and called it roff, Doug McIlroy rewrote it in BCPL in 1969, Joseph F. Ossanna rewrote it in PDP-11 assembly in 1973, and Brian W. Kernighan rewrote it in C in 1975.

AUTHORS
-nosplit This partial roff reference was written by Kristaps Dzonsons <kristaps@bsd.lv> and Ingo Schwarze <schwarze@openbsd.org>.