I wonder how costly it is in terms of compilations speed and also other terms like memory etc., to store some content in a box and use this box then afterwards only once (or maybe twice). Is the difference meaningless or significant if used often in a document?
I'm talking about something like
{\sbox\mybox{<some content>}% or \setbox\mybox\hbox{..}
<calculated something depended on the box dimension>
\box\mybox
% or:
% \usebox\mybox
}
Also: how big is the difference between using \box and \usebox (which requires to copy the box)? In some scenarios I can't be sure that the box isn't required again and can't use \box in general.
I'm coding several macros similar to \raisebox which store their content into a box and allow the user to access the dimensions using the macros \height, \width and others. During the normal use these macros might often be cascaded and each of it would simply re-save the saved box of the inner macro (\sbox\mybox{\sbox\mybox{..} .. \usebox\mybox} .. \usebox\mybox). So I wonder if I should program these macros in a way so that they can reuse the box register of the inner macro in such cases or if this would be overkill?
\copy\xor\box\xcosts the same, the former is less efficient for memory because it doesn't free the register, which is cleared anyway when the group ends. One has to pay attention to a peculiarity of box registers:\setbox0=\hbox{x}{\box0}results in an empty box register 0, because\boxclears the contents of the most recent instance of the register, which in this case happens to live at an upper level. – egreg Jul 10 '11 at 20:19\setbox0=\copy0copies the existing box 0 to a local assigned box 0, so\box0clears the local assignment while the one in the parent scope is unchanged. This is nice if you want to\copythe box but e.g. with adjusted height and depth. – Martin Scharrer♦ Jul 10 '11 at 20:39