[Tex/LaTex] Why does \hss fail

boxestex-core

Please why does the following fail?

% \hss -> \hskip 0pt plus 1fil minus 1fil
\setbox0=\hbox{a}%
\setbox0\hbox to 10mm{\hss\unhbox0\hss}
\unhbox0

And what makes LaTeX's

\def\bm@c{\hss\unhbox\@tempboxa\hss}

different?

EDIT

The following schemes work

\newbox\boxa
\newbox\boxb
\setbox\boxa=\hbox{a}%
% Case 1
\setbox\boxb\hbox to 10mm{\hss\unhbox\boxa\hss}
x \box\boxb y

and

% Case 2
\setbox\boxb\hbox to 10mm{\hss\box\boxa\hss}
x \unhbox\boxb y

I just wonder why \unhbox\boxb gives an error in case 1. When precisely is \hss evaluated? Inside or outside the box?

TeX by Topic (Section 18.3.1) says that

\leftskip=0cm plus 0.5fil \rightskip=0cm minus 0.5fil

gives the error "infinite shrinkage…" But this doesn't seem to have a direct link with the issue in question.

Best Answer

What's happening in your sample code is that first, you create a box of 10mm width having some glue at both ends and a letter in the middle. The glue is set, within the box, so that the whole space is filled. Then you unbox it. The contents are emptied into the main horizontal list, and the glue is reset in that context. The error you are getting is

! Infinite glue shrinkage found in a paragraph.

which comes about when TeX starts trying to reset the infinitely-shrinkable \hss (this despite the fact that it only needs to expand, and you can see in the output that the letter a is indeed centered on its line).

The situation with your new example is exactly the same. If you place a whole box into a paragraph, then regardless of the glue in it, there will be no infinite shrinkage because the glue is already set in the box. If you unbox it, then the glue loses its dimensions and has to be reset, and its infinite shrink component gives an error.

Perhaps it is best to think of the situation as follows. Let . denote glue and let - denote set glue; i.e. actual space. I'll write an actual box with bars |. Then you have the following correspondence:

\hbox to 10cm {\hss a\hss} ---> \hbox to 10cm {.a.} ---> |---a---|

First the \hbox examines the horizontal list inside, which includes glue, and sets the length of that glue so that it fills the box, resulting in the last picture. Suppose that's the box stored in \box0. Then your example is:

\unhbox0 ---> \unhbox |---a---| ---> .a. ---> -----------a------------

You see, when the bars are removed, the -'s revert to .'s and have to be reinterpreted, leading to some different lengths, as shown at right. The problem is that even though those lengths are stretched, the glue itself has an infinite shrink component, and this is not allowed in a computation outside an \hbox.

Related Question