When storing a box, why do so many folks use \@tempboxa? Why not \@foobar or \@MyGreatTemporaryBox or simply \@temporaryBox0? Is there anything special about this \@tempboxa? Knuth says simply \setbox0=\hbox{…junk…} (The TexBook, Ch. 11, 1996). Why not using box0 or any other box<number>, as Knuth does? It is shorter, after all.
- 757,742
1 Answers
Remember that in classic TeX without etex extensions there are only 256 box registers so simply using \@foobar, \@MyGreatTemporaryBox would use up two of the 256, if multiple packages did this you would soon run out. Predefining \@tempboxa gives a single scratch box register that can be re-used, and is part of a general naming scheme for such registers:
\newdimen\@tempdima
\newdimen\@tempdimb
\newdimen\@tempdimc
\newbox\@tempboxa
\newskip\@tempskipa
\newskip\@tempskipb
\newtoks\@temptokena
You could (and latex does) also use the numbered box registers less than ten so \box0 but accessing \box0 is slower than accessing \box\@tempboxa (as you have to scan for the integer), see similar considerations for \z@
For the other register types and more important than speed \toks0 takes up two tokens of token memory if used in a macro definition but \@temptokena is just one token. Token memory was a scarce resource in 1985. (this less the case for box registers as they need a \box or \copy prefix to be used in any case, \box0 and \box\@tempboxa)
- 757,742
\@tempboxais that it is defined in the kernel with\newbox\@tempboxa, so your code doesn't have to say\newbox\@MyGreatTemporaryBox:\@tempboxaalready exists. You can also be reasonably sure the name is not already taken or clashes with other stuff (or rather if other people's code clashes with yours, you are on the same side as the LaTeX kernel as long as you keep your usage local). And of course it might also just be habit... – moewe Aug 15 '21 at 18:52\newboxand then you use it. That is not to say that the LaTeX kernel only uses\setbox\@tempboxa. You can also find instances of\setbox\z@,\setbox0. But mainly I expect it to be personal preference and habit. – moewe Aug 15 '21 at 19:05