Next: , Previous: Tabs and Fields, Up: gtroff Reference


5.11 Character Translations

The control character (‘.’) and the no-break control character (‘'’) can be changed with the cc and c2 requests, respectively.

— Request: .cc [c]

Set the control character to c. With no argument the default control character ‘.’ is restored. The value of the control character is associated with the current environment (see Environments).

— Request: .c2 [c]

Set the no-break control character to c. With no argument the default control character ‘'’ is restored. The value of the no-break control character is associated with the current environment (see Environments).

See Requests.

— Request: .eo

Disable the escape mechanism completely. After executing this request, the backslash character ‘\’ no longer starts an escape sequence.

This request can be very helpful in writing macros since it is not necessary then to double the escape character. Here an example:

          
          .\" This is a simplified version of the
          .\" .BR request from the man 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]
          .  ft R
          ..
          .ec
— Request: .ec [c]

Set the escape character to c. With no argument the default escape character ‘\’ is restored. It can be also used to re-enable the escape mechanism after an eo request.

Note that changing the escape character globally likely breaks macro packages since gtroff has no mechanism to `intern' macros, i.e., to convert a macro definition into an internal form which is independent of its representation (TeX has this mechanism). If a macro is called, it is executed literally.

— Request: .ecs
— Request: .ecr

The ecs request saves the current escape character in an internal register. Use this request in combination with the ec request to temporarily change the escape character.

The ecr request restores the escape character saved with ecs. Without a previous call to ecs, this request sets the escape character to \.

— Escape: \\
— Escape: \e
— Escape: \E

Print the current escape character (which is the backslash character ‘\’ by default).

\\ is a `delayed' backslash; more precisely, it is the default escape character followed by a backslash, which no longer has special meaning due to the leading escape character. It is not an escape sequence in the usual sense! In any unknown escape sequence \X the escape character is ignored and X is printed. But if X is equal to the current escape character, no warning is emitted.

As a consequence, only at top-level or in a diversion a backslash glyph is printed; in copy-in mode, it expands to a single backslash which then combines with the following character to an escape sequence.

The \E escape differs from \e by printing an escape character that is not interpreted in copy mode. Use this to define strings with escapes that work when used in copy mode (for example, as a macro argument). The following example defines strings to begin and end a superscript:

          
          .ds { \v'-.3m'\s'\En[.s]*60/100'
          .ds } \s0\v'.3m'

Another example to demonstrate the differences between the various escape sequences, using a strange escape character, ‘-’.

          
          .ec -
          .de xxx
          --A'123'
          ..
          .xxx
              ⇒ -A'foo'

The result is surprising for most users, expecting ‘1’ since ‘foo’ is a valid identifier. What has happened? As mentioned above, the leading escape character makes the following character ordinary. Written with the default escape character the sequence ‘--’ becomes ‘\-’ – this is the minus sign.

If the escape character followed by itself is a valid escape sequence, only \E yields the expected result:

          
          .ec -
          .de xxx
          -EA'123'
          ..
          .xxx
              ⇒ 1
— Escape: \.

Similar to \\, the sequence \. isn't a real escape sequence. As before, a warning message is suppressed if the escape character is followed by a dot, and the dot itself is printed.

          
          .de foo
          .  nop foo
          .
          .  de bar
          .    nop bar
          \\..
          .
          ..
          .foo
          .bar
              ⇒ foo bar

The first backslash is consumed while the macro is read, and the second is swallowed while executing macro foo.

A translation is a mapping of an input character to an output glyph. The mapping occurs at output time, i.e., the input character gets assigned the metric information of the mapped output character right before input tokens are converted to nodes (see Gtroff Internals, for more on this process).

— Request: .tr abcd...
— Request: .trin abcd...

Translate character a to glyph b, character c to glyph d, etc. If there is an odd number of arguments, the last one is translated to an unstretchable space (‘).

The trin request is identical to tr, but when you unformat a diversion with asciify it ignores the translation. See Diversions, for details about the asciify request.

Some notes:

— Request: .trnt abcd...

trnt is the same as the tr request except that the translations do not apply to text that is transparently throughput into a diversion with \!. See Diversions, for more information.

For example,

          
          .tr ab
          .di x
          \!.tm a
          .di
          .x

prints ‘b’ to the standard error stream; if trnt is used instead of tr it prints ‘a’.