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).
.tr
abcd… ¶.trin
abcd… ¶Translate character a to glyph b, character c to glyph d, and so on. If there is an odd number of characters in the argument, the last one is translated to a fixed-width space (the same one obtained by the ‘\ ’ escape).
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:
\(xx
, \[xxx]
,
\C'xxx'
, \'
, \`
, \-
, \_
),
glyphs defined with the char
request, and numbered glyphs
(\N'xxx'
) can be translated also.
\e
escape can be translated also.
\%
and \~
escape
sequences (but \%
and \~
can’t be mapped onto another
glyph).
\a
), tab (and
\t
).
shc
request.
.tr a\& foo bar ⇒ foo br
It is even possible to map the space character to nothing:
.tr aa \& foo bar ⇒ foobar
As shown in the example, the space character can’t be the first
character/glyph pair as an argument of tr
. Additionally, it is
not possible to map the space character to any other glyph; requests
like ‘.tr aa x’ undo ‘.tr aa \&’ instead.
If justification is active, lines are justified in spite of the ‘empty’ space character (but there is no minimal distance, i.e., the space character, between words).
tr
.
tr
does not check whether the entities in its
argument do exist.
See gtroff
Internals.
troff
no longer has a hard-coded dependency on Latin-1; all
charXXX
entities have been removed from the font
description files. This has a notable consequence that shows up in
warnings like ‘can't find character with input code XXX’ if
the tr
request isn’t handled properly.
Consider the following translation:
.tr éÉ
This maps input character é
onto glyph É
, which is
identical to glyph char201
. But this glyph intentionally doesn’t
exist! Instead, \[char201]
is treated as an input character
entity and is by default mapped onto \['E]
, and gtroff
doesn’t handle translations of translations.
The right way to write the above translation is
.tr é\['E]
In other words, the first argument of tr
should be an input
character or entity, and the second one a glyph entity.
tr
request is ignored.
.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 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’.