This seems to be one for tex.web
to me. The alignment code is made more complex than simple boxing operations by the need to handle \span
correctly. However, the general flow is pretty clear. TeX works through the rows, typesetting everything to natural width but in unset boxes (i.e. the glue is not set at this stage). At each stage, the width of the current box is compared to that in the preamble. If the current box is wider, then this value is stored in the preamble for further use. All of the unset boxes are themselves stored in one box per row.
Once TeX gets to the end of the alignment, it goes through each row and sets the glue. The key routine seems to be
@ @<Make the unset node |r| into an |hlist_node| of width |w|...@>=
begin height(r):=height(q); depth(r):=depth(q);
if t=width(r) then
begin glue_sign(r):=normal; glue_order(r):=normal;
set_glue_ratio_zero(glue_set(r));
end
else if t>width(r) then
begin glue_sign(r):=stretching;
if glue_stretch(r)=0 then set_glue_ratio_zero(glue_set(r))
else glue_set(r):=unfloat((t-width(r))/glue_stretch(r));
@^real division@>
end
else begin glue_order(r):=glue_sign(r); glue_sign(r):=shrinking;
if glue_shrink(r)=0 then set_glue_ratio_zero(glue_set(r))
else if (glue_order(r)=normal)and(width(r)-t>glue_shrink(r)) then
set_glue_ratio_one(glue_set(r))
else glue_set(r):=unfloat((width(r)-t)/glue_shrink(r));
end;
width(r):=w; type(r):=hlist_node;
end
The important point for the current question is that this is coded just for alignments, even though the concept is pretty much the same as for \hbox to <dim>
. Thus the code used in an alignment does not include a check for underfull boxes.
You can see that the overall effect of the \halign
code is the same as \hbox to <dim>
by using \tracingall
and looking at the boxes, for example
\tracingall
\halign{#\cr abcdefg\cr a b\cr ab\cr}
\newbox\testbox
\setbox\testbox=\hbox{abcdefg}
\setbox\testbox=\hbox to \wd\testbox{a b}
\box\testbox
\bye
You'll see that the glue situation is identical in the two a b
cases: it's just that the warning is omitted in the \halign
case.
\hbox to width{...}
. As for absence of glue, what would you do if you discovered that an hbox has glue?\hfill
by yourself?\hfill
myself, that would make the second line of my example intoab-----
(with-
replaced by spaces), which is incorrect. A solution may be to put\hskip 0pt plus 1sp
, but even that is not quite right.