# e-TeX \hbox to size of glue

I have a piece of glue (\hskip 2.4in plus 2fil specifically) that's flexible, and I want to create an \hbox to the same length, but \hbox to 2.4in plus 2fil doesn't work. Is there a way to achieve a similar result?

The reason I want to use this is to make a 3-column format with boxed in columns more flexible (especially to differently sized columns). I'm using pdfTeX, so I can use e-TeX's extra features if that's helpful

• Boxes are not stretchable. – Henri Menke Aug 18 '19 at 0:16
• @HenriMenke Is there a way to get a similar result, or will I have to do the calculation "by hand?" – Holden Rohrer Aug 18 '19 at 0:30
• The final size of the fil glue will only be known, once the paragraph is built, i.e. you can set the width of the \hbox to the width of the glue, if they are in different paragraphs. (However, I don't know whether you can get the size of the glue within TeX, but it's definitely possible in Lua) – Henri Menke Aug 18 '19 at 0:42
• That said, if you are trying to balance columns, Appendix D of the TeXbook has an algorithm for column balancing, but it involves a loop that retypesets the columns at different width until an optimum is reached or the number of tries is exceeded. – Henri Menke Aug 18 '19 at 0:46

You can use pdftex features to record the position before and after a glue node, and then (on the second run) use that information to construct a box of the desired size.

Here paragraph 1 just has glue, paragraph 2 has a box with Z...Z set to the same size.

\newwrite\zz % easier in latex where this is set up already
\openin\zz=\jobname.aux
\ifeof\zz\else
\input \jobname.aux
\closein\zz
\fi
\immediate\openout\zz=\jobname.aux

1) zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z
zzzz%
\hskip 2.4in plus 2fil
zzz zzzz zzz
zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z
zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z

2) zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z
zzzz%
\ifx\zzA\undefined\else
\leavevmode\rlap{\hbox to \dimexpr \zzB sp -\zzA sp{Z\dotfill Z}}%
\pdfsavepos\write\zz{\gdef\string\zzA{\the\pdflastxpos}}%
\hskip 2.4in plus 2fil
\pdfsavepos\write\zz{\gdef\string\zzB{\the\pdflastxpos}}%
zzz zzzz zzz
zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z
zzz zz zz zz zz zz zz zz zzzz zz zz zz zz zz zz zz z

\bye

• @HoldenRohrer: It is not clear, in your question, if you are using plain teX, LaTeX, or if you are looking for a “generic” solution; if you happen to be using LaTeX, I suggest you also have a look to the savepos module of the zref package. – GuM Sep 14 '19 at 15:29
• @GuM the OP tagged it plain-tex so I went with that (although tagging isn't always to be believed, I agree:-) – David Carlisle Sep 14 '19 at 15:55
• Please believe that I was not criticizing your answer, but simply trying to be helpful to the OP. :-) – GuM Sep 19 '19 at 10:01