[Tex/LaTex] Problem with \setbox

boxesplain-tex

I wrote the following box, which contains my name displayed vertically:

\setbox0\vbox{\hbox{M}\hbox{a}\hbox{t}\hbox{t}\hbox{e}\hbox{o}}

I'd like to dysplay it twice in a line, so I wrote:

\line{\hss \box0 \hss \box0 \hss}

But there is a problem: \box0 appears only once! I see only one copy of my name!

Instead, if I write

\line{\hss \vbox{\hbox{M}\hbox{a}\hbox{t}\hbox{t}\hbox{e}\hbox{o}} \hss \vbox{\hbox{M}\hbox{a}\hbox{t}\hbox{t}\hbox{e}\hbox{o}}\hss}

I get the desired output.

What's wrong with the use of \setbox0 or \box0?

(All is done under plain TeX.)

Best Answer

\box also clears the box register. Use \copy instead.

\line{\hss \copy0 \hss \copy0 \hss}

I would use \hfill instead of \hss. Then TeX will throw an overfull \hbox warning, if the place is not sufficient.

A centered version can be achieved via \halign:

\setbox0\vbox{\halign{\hfil#\hfil\cr M\cr a\cr t\cr t\cr e\cr o\cr}}
\line{\hfill \copy0 \hfill \copy0 \hfill}
\bye

Result

Smaller space between letters

The following example uses different methods to reduce the space between the letters. The first boxes 0, 2, 4 (even numbered boxes smaller than ten are scratch boxes for local assignments) keep the distance between the baselines constant. Box 0 is the unmodified version. Box 2 shrinks the \baselineskip according to egreg's comment. The extreme is in box 4, where the maximum letter height is measured with the result that the two "t"s are in touch.

The boxes 6 and 8 keep the distance between the letters constant. Because of \baselineskip=0pt, TeX switches to set \lineskip instead. It's default value is 1pt. Box 8 finally does not leave any space between the letters.

\def\test{\halign{\hfil##\hfil\cr M\cr a\cr t\cr t\cr e\cr o\cr}}

\setbox0\vbox{\test}
\setbox2\vbox{%
  \advance\baselineskip-2pt\relax
  \test
}
\setbox4\hbox{atteo}
\setbox4\vbox{%
  \baselineskip=\ht4
  \lineskiplimit=0pt
  \test
}
\setbox6\vbox{%
  \baselineskip=0pt
  \test
}
\setbox8\vbox{%
  \baselineskip=0pt
  \lineskip=0pt
  \test
}

\line{\hfill\copy0 \hfill\copy2 \hfill\copy4 \hfill\copy6 \hfill\copy8 \hfill}
\bye

Result

Related Question