Whereas requests must occur on control lines, escape sequences can occur
intermixed with text and may appear in arguments to requests, macros,
and other escape sequences.
An escape sequence is introduced by the escape character, a backslash
\
(but see the ec
request below). The next character
selects the escape’s function.
Escape sequences vary in length. Some take an argument, and of those,
some have different syntactical forms for a one-character,
two-character, or arbitrary-length argument. Others accept only
an arbitrary-length argument. In the former scheme, a one-character
argument follows the function character immediately, an opening
parenthesis ‘(’ introduces a two-character argument (no closing
parenthesis is used), and an argument of arbitrary length is enclosed in
brackets ‘[]’. In the latter scheme, the user selects a delimiter
character. A few escape sequences are idiosyncratic, and support both
of the foregoing conventions (\s
), designate their own
termination sequence (\?
), consume input until the next newline
(\!
, \"
, \#
), or support an additional modifier
character (\s
again, and \n
). As with requests, use of
some escape sequences in source documents may interact poorly with a
macro package you use; consult its documentation to learn of “safe”
sequences or alternative facilities it provides to achieve the desired
result.
If an escape character is followed by a character that does not identify a defined operation, the escape character is ignored (producing a diagnostic of the ‘escape’ warning category, which is not enabled by default) and the following character is processed normally.
$ groff -Tps -ww .nr N 12 .ds co white .ds animal elephant I have \fI\nN \*(co \*[animal]s,\f[] said \P.\&\~Pseudo Pachyderm. error→ warning: escape character ignored before 'P' ⇒ I have 12 white elephants, said P. Pseudo Pachyderm.
Escape sequence interpolation is of higher precedence than escape sequence argument interpretation. This rule affords flexibility in using escape sequences to construct parameters to other escape sequences.
.ds family C\" Courier .ds style I\" oblique Choice a typeface \f(\*[family]\*[style]wisely. ⇒ Choose a typeface wisely.
In the above, the syntax form ‘\f(’ accepts only two characters for
an argument; the example works because the subsequent escape sequences
are interpolated before the selection escape sequence argument is
processed, and strings family
and style
interpolate one
character each.42
The escape character is nearly always interpreted when encountered; it is therefore desirable to have a way to interpolate it.
\e
¶Interpolate the escape character.
To format a backslash glyph on the output, use the \[rs]
special
character escape sequence. In macro and string definitions, two further
input sequences \\
and \E
come into play, permitting
deferred interpretation of escape sequences. See Copy Mode.
Outside of copy mode, escape sequence interpretation can be switched off and back on. This procedure can obviate the need to double the escape character inside macro definitions. See Writing Macros. (This approach is not available if your macro needs to interpolate values at the time it is defined—but many do not.)
.eo
¶Disable the escape mechanism except in copy mode. Once this request is invoked, no input character is recognized as starting an escape sequence in interpretation mode.
.ec
[c] ¶Recognize c as the escape character. If c is absent or invalid, the default escape character ‘\’ is selected.
Changing the escape character globally likely breaks macro packages,
since GNU troff
has no mechanism to “intern” macros, that is,
to convert a macro definition into an internal form independent of its
representation.43 When a
macro is called, its contents are interpreted literally.
.\" This is a simplified version of the `BR` macro from .\" the man(7) macro package. .eo .de BR . ds result \& . while (\n[.$] >= 2) \{\ . as result \fB\$1\fR\$2\" . shift 2 . \} . if \n[.$] .as result \fB\$1\" \*[result] . rm result . ft R .. .ec