Difference between unrestricted and internal vertical mode

At any point in the processing of a document, TeX can be in one of seven modes: no mode (only in \write and similar commands, I think), math mode ($...$), display math mode ($$...$$), restricted horizontal mode (\hbox{...}), unrestricted horizontal (paragraphs), internal vertical mode (\vbox{...}) or on the main vertical list.

What are the differences between the two vertical modes?

Obviously, there can be no page breaks within a \vbox, so I'll refine my question into: assuming that TeX is currently on the main vertical list, what are the differences between doing

\setbox0\vbox{... material ...}\unvbox0


and putting ... material ... directly in the main vertical list?

-
Please feel free to correct my use of the various terms: I don't have the TeXbook at hand to check them. –  Bruno Le Floch Feb 2 '12 at 5:45
I don't have my copy of TB either, but what about glue? Isn't it set when \unvboxing? (I'm not sure, can't remember that.) –  mbork Feb 2 '12 at 6:12
@mbork: \setbox0\vbox{!\vfill!}\unvbox0\bye puts a ! at the top of the page, and another one midway (one \vfill between the two !, one for the end of the page). So no, the glue is not set. Another way to see that is to add \showbox0 before unboxing: I see the item .\glue 0.0 plus 1.0fill. –  Bruno Le Floch Feb 2 '12 at 6:49

As far as the typesetting is concerned there is no difference whatsoever to my knowledge (in contrast to the situation when you do

\setbox0\hbox{... material ...}\unhbox0


which handles language nodes somewhat differently if I recall correctly (without a TB)). But there is of course one difference in that any local assignment within "material" will be reverted if it happens inside a box but obviously not if entered in directly.

As pointed out one other difference is that on the main vertical list, removals such as \unkern, \unskip, \lastbox and\unpenalty are not allowed, while they can be used within the \vbox. So for manipulation while preparing the material the vbox can have some advantage.

-
\insert comes to mind as something that fails in inner vmode, doesn't it? –  Bruno Le Floch Feb 2 '12 at 7:58
@Bruno \insert should work, they stay in the vbox but migrate to the vertical list when \unvbox happens. However, you are right there might be a difference here, because TeX exercises the pagebuilder directly after the insert and that has no effect in vmode. That might need some checking/looking at the code. I doubt that the TB will be precise enough in such a detail. –  Frank Mittelbach Feb 2 '12 at 8:04
Ah, your reply raises one point, then: the page builder is of course only exercised after the whole \vbox is processed. I guess my confusion about \insert is that LaTeX figures refuse to be used in inner vmode. Why is that? (Perhaps worth a separate question?) –  Bruno Le Floch Feb 2 '12 at 8:14
@Bruno that's because they would not work if they where kept inside the box (but you unbox that level and then it is ok). –  Frank Mittelbach Feb 2 '12 at 9:12
Thank you for the explanation. –  Bruno Le Floch Feb 2 '12 at 11:34

(References are to the TeXbook)

The operation \lastbox is not allowed in unrestricted vertical mode (p. 222).

\end and \dump are not allowed in internal vertical mode.

Note also that marks issued in internal vertical mode don't migrate (p. 259), so they won't be seen unless the constructed \vbox or \vtop is unboxed.

-
Marks seem to migrate when you \unvbox: \setbox0\vbox{\mark{abc}}\unvbox0 X\par\vfill\break\show\botmark\bye shows \botmark:abc. Alternatively, just do \tracingall\showlists after \unvbox0. On the other hand, your point about \lastbox, \end and \dump is very right. –  Bruno Le Floch Feb 2 '12 at 8:18
@egreg the second sentence is a red herring I would say. In the question as framed there is nothing to migrate as the box is unboxed. This statement refers to a mark or insert being kept inside a box when the page is being build together. –  Frank Mittelbach Feb 2 '12 at 9:10
@BrunoLeFloch No, they don't migrate: if you unbox, they aren't inside a box any more. I'd compare this with the similar situation with restricted horizontal mode, where marks do migrate to the enclosing vertical mode. –  egreg Feb 2 '12 at 9:20
@egreg: the whole point of my question is that I'm \unvbox-ing the box after constructing it, so in my context, \marks do migrate. I think your answer has useful material for people browsing this, but is a little bit off the initial question, so I accepted Frank's as "more helpful". Hope you don't mind. –  Bruno Le Floch Feb 2 '12 at 11:33
@BrunoLeFloch I intend "migrate" in the sense that the object is taken out from the box in which it is, while the box remains unaltered under every other respect. This isn't the case when you \unvbox`. –  egreg Feb 2 '12 at 11:37