This question is really a continuation of my previous question. Basically, I'm wondering why this does not work:
\hbox{\vbox{\hbox{This is}\hbox{A line}}\hfil\vbox{\hbox{And so}\hbox{Is this}}\hfil\vbox{\hbox{Also this}\hbox{Is another}}}
\bye
Formatted (I don't think this changes the meaning, but in case it does, it's smashed together like that in my original) it looks like this:
\hbox{
\vbox{
\hbox{This is}
\hbox{A line}}
\hfil
\vbox{
\hbox{And so}
\hbox{Is this}}
\hfil
\vbox{
\hbox{Also this}
\hbox{Is another}}}
\bye
My naïve expectation is that this should work (in fact I feel like it should work even without explicit \hfil
) because “TeX works by placing boxes and glue” and all I'm doing is creating some boxes.
I think there's something wrong my intuition because the output I get looks like this:
So the previous question showed me how to solve the problem, but it didn't fix the real problem of my defective intuition. What is wrong in my thought process?
Does TeX not automatically insert glue in this case? If not, why does adding
\hfil
not remedy the problem?I notice adding
\hfill
changes the output—I get the first box on the left, the middle on the extreme right, and presumably the last one is off in space to the right of the page somewhere.I suppose based on the previous answer that I need to set some box sizes. Why is that? It seems like the boxes ought to grow to take up the space that exists on that line—at least when there is stretchable glue involved. If I wanted to not set up explicit sizes, what would I need to do?
I notice I get different behavior when I put
\hfil
inside and outside a\vbox
: when I use\vbox{...}\hfill\vbox{...}
it has no effect, but when I use\vbox{...}\vbox{\hfill}\vbox{...}
it does have an effect. But it has the wrong effect. Is\hfill
not a horizontal command? Doesn't starting avbox
put you into vertical mode, and anhbox
into horizontal mode? Or is something else going on here?Running the formatted one adds space between the boxes. I assume this is
\spaceskip
, but changing its value to things like\spaceskip=0pt plus 1fil
orplus 1fill
reverts the output to the previous state.
Edit bonus question:
What is the difference between this:
\vbox{ \hbox{This is} \hbox{A line}}
and:
\vbox{ This is\par A line}
I really appreciate the patience of everyone on here helping me to learn TeX!
\hfil
.\parindent
is one difference, it should be generated between the "paragraphs" in the second version, yes? Is anything else different?\hbox
es are in "restricted horizontal mode": text is constructed only on the current line (e.g., try putting a\par
inside your\hbox
). In the\vobx
, you are in unrestricted horizontal mode, which allows paragraph building. Inside a\vbox
, you are also in internal vertical mode, which allows your "stacking" of\hbox
es. See §. 6.3 of TeXbyTopic.\hbox
has no required width so fills any glue does not stretch at all.