# Question about exercise 17.16 in TeXbook

The answer to the exercise is:

\def\sqr#1#2{{\vcenter{\vbox{
\hrule height.#2pt
\hbox{\vrule width.#2pt height#1pt \kern#1pt \vrule width.#2pt}
\hrule height.#2pt}}}}
\def\square{\mathchoice\sqr34\sqr34\sqr{2.1}3\sqr{1.5}3}


I wonder why extra \vbox is used. May its absence influence the outcome in any way?

• please note my updated answer (my first answer was wrong) – David Carlisle Jul 18 at 6:54

A \vcenter is handled as a \vbox except that a vcent atom is wrapped around the construct which finally means that the resulting box is adjusted so its height+depth are centred on the math axis. However as Udo pointed out in comments the finer points of appendix G in the TeXBook do mean that there are some differences in the way \scriptspace is handled.

\scriptspace=5pt % excessive ammount to make things clearer

\def\sqr#1#2{{\vcenter{\vbox{
\hrule height.#2pt
\hbox{\vrule width.#2pt height#1pt \kern#1pt \vrule width.#2pt}
\hrule height.#2pt}}}}
\def\square{\mathchoice\sqr34\sqr34\sqr{2.1}3\sqr{1.5}3}

\def\sqrb#1#2{{\vcenter{
\hrule height.#2pt
\hbox{\vrule width.#2pt height#1pt \kern#1pt \vrule width.#2pt}
\hrule height.#2pt}}}
\def\squareb{\mathchoice\sqrb34\sqrb34\sqrb{2.1}3\sqrb{1.5}3}

$|A_{ \square}|\, |A_{\squareb }|$

\bye


Udo highlights the relevant rules in appendix G as follows:

It is the nature of the \hrule which extends to the width of the enclosing box.

And here it is the width of the hbox plus \scriptspace. With the \vbox the width of the \hrule has just the width of the \hbox; \scriptspace is applied later.

(Appendix G: Rule 1 jumps over the hrule, the postprocessing in rule 18 applies the \scriptspace to the hbox or the vbox.)

In particular it is 18b, quoting from the TeXBook:

18b. If the superscript field is empty (so that there is a subscript only), set box x to the subscript in style C↓, and add \scriptspace to w(x)

Which means with only one box, the horizontal rules extend, but with nested boxes (of any type) the width of the inner list is unchanged.

• Your answer is correct for D and T styles. But look at the use case of the macro \sqr and observe that the \hrules have no width, i.e., it is *. So in $$A_{\square}$$ the \scriptspace is applied and destroys the square box if \vbox{ and one } are deleted. – Udo Wermuth Jul 17 at 19:35
• @UdoWermuth I can't delete an accepted answer, but if you post a right answer I'll get the OP to unaccept this and I'll delete, thanks. – David Carlisle Jul 17 at 20:01
• @UdoWermuth I can confirm you are right but just at the moment I don't see where the texbook statement that vcenter is treated as vbox lead me astray, I'll need to stare at appendix g again.... – David Carlisle Jul 17 at 20:10
• It is the nature of the \hrule which extends to the width of the enclosing box. And here it is the width of the hbox plus \scriptspace. With the \vbox the width of the \hrule has just the width of the \hbox; \scriptspace is applied later. Please, don't delete your answer, edit it. (Appendix G: Rule 1 jumps over the hrule, the postprocessing in rule 18 applies the \scriptspace to the hbox or the vbox.) – Udo Wermuth Jul 18 at 6:05
• @UdoWermuth done thanks:-) – David Carlisle Jul 18 at 6:53