There are numerous occasions in page layout when it is necessary to store some text
for a period of time without actually printing it.
Footnotes are the most obvious example:
the text of the footnote usually appears in the input well before the place
on the page where it is to be printed is reached.
the place where it is output normally depends on how big it is,
which implies that there must be a way
to process the footnote at least
enough to decide its size
provides a mechanism called a diversion
for doing this processing.
Any part of the output may be diverted into a macro instead
and then at some convenient time the macro may be put back into
begins a diversion _ all subsequent output is collected into the macro
with no arguments is encountered.
This terminates the diversion.
The processed text is available at any time thereafter, simply
The vertical size of the last finished diversion is contained in
the built-in number register
suppose we want to implement a `keep-release'
so that text between the commands
will not be split across a page boundary
(as for a figure or table).
is encountered, we have to begin diverting
the output so we can find out how big it is.
whether the diverted text will fit on the current page,
and print it either there if it fits, or at the top of the next page if it doesn't.
^ev 1 \e" collect in new environment
^fi \e" make it filled text
^br \e" get last partial line
^if \e\en(dn>=\e\en(.t .bp \e" bp if doesn't fit
^nf \e" bring it back in no-fill
^ev \e" return to normal environment
Recall that number register
Since output was being diverted, this remains
at its value when the diversion started.
is the amount of text in the diversion;
(another built-in register)
is the distance to the next trap,
which we assume is at the bottom margin of the page.
If the diversion is large enough to go past the trap,
In either case, the diverted output is then brought back with
It is essential to bring it back in no-fill mode so
will do no further processing on it.
This is not the most general keep-release,
nor is it robust in the face of all conceivable inputs,
but it would require more space than we have here to write it
This section is not intended
to teach everything about diversions,
but to sketch out enough that you can read
existing macro packages with some comprehension.