6

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:

boxes smashed together

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?

  1. 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.

  2. 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?

  3. 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 a vbox put you into vertical mode, and an hbox into horizontal mode? Or is something else going on here?

  4. 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 or plus 1fill reverts the output to the previous state.

Edit bonus question:

  1. 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!

6
  • Did you try your "not smashed" together code? There is (or should be!) a difference --- but not because of the \hfil.
    – jon
    Commented Jun 18, 2015 at 2:41
  • No, I meant, what is the difference? It sounds like \parindent is one difference, it should be generated between the "paragraphs" in the second version, yes? Is anything else different? Commented Jun 18, 2015 at 4:57
  • A short, unelaborated answer: \hboxes 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 \hboxes. See §. 6.3 of TeXbyTopic.
    – jon
    Commented Jun 18, 2015 at 5:05
  • 2
    You wrote: "I'm wondering why this does not work ... code". But your code perfectly works. It does what did you write. You didn't explain what did you expect. And second note: your second multi-line code differs because there are spaces at the start of outer \hbox and between \vbox{} and \hfil.
    – wipet
    Commented Jun 18, 2015 at 6:09
  • 1
    It seems you are missing a key point about glue: it stretches to fill the space required. A simple \hbox has no required width so fills any glue does not stretch at all.
    – Joseph Wright
    Commented Jun 18, 2015 at 7:36

1 Answer 1

8

Ad 1. (From TeXbyTopic). \hfil is a "horizontal command": a "Horizontal skip equivalent to \hskip 0cm plus 1fil. The "one-liner" you provide is a horizontal box of no specified width. What is there to fill? Consider this line:

\hbox{This \hfill question is really a continuation of my previous question. Basically, I'm wondering why this does not work: 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: }

Should that line "stretch"? What should \hfill do here?

Ad 1a. This is unclear. Where are you adding \hfill and to which of your examples? They are not the same....

Ad 2. This sounds like a "design" question; would you rather every \hbox to fill an entire "line" unless explicitly told not to? More practically, you could (in this case) do:

\hbox to \the\hsize{% <-- this is important here
  \vbox{%
    \hbox{This is}
    \hbox{A line}}
%  \hfill
  \vbox{%
    \hbox{And so}
    \hbox{Is this}}
%  \hfill
  \vbox{%
    \hbox{Also this}
    \hbox{Is another}}}

But maybe you are setting the textblock explicitly.

Ad 3. I don't really understand what you are asking. But note that \vbox, which follows the same specification as for \hbox, constructs "a vertical box with reference point on the last item" (from TeXbyTopic). So in your "compressed" example, you are literally asking for the second \vbox to be built right next to the first \vbox with an \hfil of at least 0cm to fill up an \hbox comprised of three "natural width" boxes. TeX sees no need to use more than 0cm for the \hfil.

Note also that your "uncompressed" example includes signficant whitespace in the following places:

\hbox{ %              <-- here; this one is important still
  \vbox{
    \hbox{This is}
    \hbox{A line}} %  <-- here
  %\hfil
  \vbox{
    \hbox{And so}
    \hbox{Is this}} % <-- here
  %\hfil
  \vbox{
    \hbox{Also this}
    \hbox{Is another}}}

Ad 4. (In response to edit of question.) Again, you are setting something to 0pt plus 1fil -- so the minimum amount may well be 0pt in such a case. I hope the above comments help explain why you need to decide whether you want a "\spaceskip" or not.

2
  • 1
    Thanks for your assistance. This is actually helping quite a bit. I think the problem is that I am importing foreign concepts from CSS and even though my questions are not always clear the answers are helping me figure it out. Commented Jun 18, 2015 at 4:39
  • 1
    I feel your pain the other way: I remember trying once to (learn how to) get things to "float" horizontally in CSS. It was a key element of a frustrating evening....
    – jon
    Commented Jun 18, 2015 at 4:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .