[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] Divert into string variable
From: |
Tadziu Hoffmann |
Subject: |
Re: [Groff] Divert into string variable |
Date: |
Sat, 29 Nov 2014 00:15:58 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
> is it safe to divert into a string variable?
In a way, roff doesn't really distinguish between "strings",
"macros", and "diversions". They all share the same namespace
and can be accessed both via ".xx" at the beginning of an input
line and as "\*[xx]". The results, however, will depend on what
the "variable" currently contains.
> That means instead of:
>
> .br
> .di A
> ...text...
> .br
> .di
> .A
>
> use something like:
>
> .br
> .di A
> ...text...
> .br
> .di
> ...\*A...
*Diverting* text means that you store *formatted* material in
the variable. During formatting, for example, spaces become
fixed. Formatted material is not intended to be reprocessed
again, e.g., in fill mode. Although it is possible, if you
do so you're likely to get uneven spacing. For single words
it might be okay (except if the diversion was formatted with
a nonzero indent).
If you intend to reprocess saved text, you should normally
save that text unprocessed as a macro:
.br
.de A
...text...
..
.A
more text
or a string:
.br
.ds A ...text...
.A
\" remember: A has no newline, so this is stupid
more text
The difference between ".de" and ".ds" is that ".ds" does not
store a terminating newline in A, which is why stuff defined
with ".ds" should really be accessed as \*A. This also helps
to preserve the structure of the input with regard to lines.
E.g., if you have an "emboldening" macro,
regular text
.B bold text
regular text
and a *macro* A containing multiple lines, then
regular text
.B \*A
regular text
will give you only the first line of A in bold, and
the rest in regular (and an empty line afterwards).