# Definition of \strut explained

Can anyone explain me the fine details of the \strut macro. Why is the box \copyied in mathmode but \unhcopyied otherwise?

% latex.ltx, line 484, but identical in plainTeX
\def\strut{\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}


The TeXBook states (e.g. page 120) that the unboxing macros unset any glue in the box's outer level, but there is no glue in the \strutbox, is it?

I understand that \strutbox is an actually empty box with a font size dependent height (.7\baselineskip, where \baselineskip is about 1.2x font size) and depth (.3\baselineskip) but zero width:

% latex.ltx, line 2357, inside the \set@fontsize macro
\setbox\strutbox\hbox{%
\vrule\@height.7\baselineskip
\@depth.3\baselineskip
\@width\z@}%


I assume it is more efficient to use a box instead of repeatably use \vrule. Also you can use \ht\strutbox and \dp\strutbox to access the height and depth as dimensions. This allows you to write .5\ht\strutbox while .5*.7\baselineskip would require eTeX's \dimexpr or a temporal assignment.

I really like to understand the fine nuances of TeX better.

-

You can't \unhcopy an hbox in math mode, that's simple! Indeed

$\unhcopy\strutbox$


gives

! Incompatible list can't be unboxed.
<*> $\unhcopy\strutbox$


The command \unhcopy is used outside of math mode because of two facts:

1. it starts horizontal mode;
2. it removes one level of boxing, avoiding "too deep" nesting.

A similar definition is that of \leavevmode:

\def\leavevmode{\unhbox\voidb@x}


where \voidb@x is a box register that should always remain void. The difference between \unhbox and \unhcopy is that the former destroys the contents of the box register, while the latter produces only a copy of it and leaves the register intact.

Among the duties of \fontsize is to provide a convenient \strut; the strut's height and depth are always 7/10 and 3/10 of the baselineskip, which is set by the second argument to \fontsize. So when a command such as \large is executed, also the strut is changed; it will restored when the group ends or another \fontsize command (possibly implicit) is executed.

(For the rest you're right.)

## Note.

The register \voidb@x can be used to ensure that a box register is void, by saying \setbox\mybox=\box\voidb@x, which destroys the contents of \mybox and is more efficient than the equivalent {\setbox0=\box\mybox}.

-
I see, both things make perfect sense: Unboxing a non-math hbox in mathmode wouldn't be right and removing one unnecessary boxing level is of course more efficient. Nice answer! (As usual, I'm waiting a little bit before accepting it) –  Martin Scharrer Jun 28 '11 at 18:07