\def is sometimes used as an abbreviation of a box construction, then its output is sometimes the same as the output with a \box register instead of \def.
Here is the question. When should I use a \box register rather than \def? Is there any specific situation one is better than the other one?
EDITED (09/12/09 UTC 2:45)
Edited question
Is there any cases that \setbox and its output commands pair (not only \box0, but also \copy0, \unhbox0, and so on) can be replaced a macro definition which is eventually expanded as a box?
If there was such a case, is there any specific situation one is better than the other one?
Examples I thought
Case 1:
\def\excuse{I should have made my question more clearer before the post.}
\setbox0=\hbox{I should have made my question more clearer before the post.}
I think the above case is the same as long as I call the box register with \unhcopy0. However, I wonder whether first one is better than second one because it can save memory.
Case2:
\def\excuse{\hbox{I should have made my question more clearer before the post.}}
\setbox0=\hbox{I should have made my question more clearer before the post.}
I think the above case is also the same as long as I call the box register with \copy0.
Case3:
\def\myhrulefill{\line{\leaders\hrule\hfill}}
\setbox0=\line{\leaders\hrule\hfill}
in this case, \hbox contains commands and which I suspected whether I can say those are the same or not.
Unfortunatelly, I cannot show you a sufficientlly complex example which contains some commands. Parhaps, if above examples contained conditional syntax like \if, repetion syntax like \loop...\repeat, one cannot be an alternative of the other one. I especially like to know such a case.



\defexpands to input, whereas a\boxstores typeset output. – Henri Menke Dec 08 '19 at 04:14