[texhax] Checking the length of paragraph last line [fun]

Uwe Lück uwe.lueck at web.de
Thu Nov 10 10:16:51 CET 2005

At 21:33 14.10.05, William F. Adams wrote:
>and Uwe Lück (uwe.lueck at web.de) had the following charming response which 
>you could query him on if need be:
>At 16:49 07.09.05, Florian Knorn wrote:
>>could anybody plz tell me a macro that returns the remaing space in the
>>current text line ? like \remainingspace would contain the length like
>>"3cm" if the remaining space to the end of the line is 3cm.
>I have a really miraculous algorithm for this general problem,
>yet the present e-mail is too short to hold it
>(cf. Simon Singh, Lueck's Last Algorithm, chap. 2.4 :-)
>-- Uwe
>p.s.: Place a "marker" phantom box (e.g. with a small random
>height); typeset the paragraph in a testing \vbox with same
>parameters as in the text, take line by line from the \vbox,
>take word by word from each line into a measuring \hbox
>-- until you find you find the "marker" box ...

Thanks, but:

I don't believe that Fermat had a valid proof for Fermat's Last
Theorem, and likewise there is a problem with my algorithm,
as has occurred to me these days: there is no analogue
for \lastbox to unbuild a line as you can unbuild a \vbox.
The words don't form \hbox'es, and the characters cannot
be removed. Will Robertson and Morten Høgholm have just
proposed to have \lastchar and \unchar in extended versions
of TeX. Without, the measurement would rather have to do
as follows: Use \showbox to write the contents of a line
into the .log, look for the marker in the .log, restore from
the .log a low-level version of code generating what is left
of the marker in the line box, typeset that code in an \hbox,
measure it (with LaTeX, just \settowidth...).

Happy TeXing,

More information about the texhax mailing list