In a previous question I asked how to generate multiple saveboxes in a loop. The answer build around csname
and the part inside csname
is rather long and I need the name several times (create the box, fill the box, get properties and use it). Therefore I would like to shorten this. I tried
\makeatletter
...
\@namedef{saveBox}{<what was inbetween \csname \endcsname>}
...
\expandafter\newsavebox\@nameuse{saveBox}
...
\makeatother
which is not working for me. A short background information on the inner workings/general intended use would be a bonus.
The awnser leaves me with one issue, I can't get the \def
version to work with a direct version, see example for clarification:
\def\floatRow@currentSaveBox{floatRow@savebox\alph{floatRow@rowImageCount}}
%\expandafter\newsavebox\csname\floatRow@currentSaveBox\endcsname %works
\expandafter\newsavebox\csname{}floatRow@savebox\alph{floatRow@saveboxCount}\endcsname %gives mising number error
I assume that my separation of \commandName
and the string floatRow@savebox
is wrong. Here is a MWE:
\documentclass{report}
\begin{document}
\newcounter{c}
\def\currentSBox{prefix\alph{c}}
\expandafter\newsavebox\csname\currentSBox\endcsname
\expandafter\savebox\csname\currentSBox\endcsname{dummy}
\expandafter\usebox\csname\currentSBox\endcsname
\expandafter\usebox\csname{}prefix\alph{c}\endcsname
\end{document}
etoolbox
package. It provides a much cleaner and more complete interface for the construction of command sequences without using kernel primitives.\@nameuse{saveBox}
needs two expansions to give you the name\saveBox
(\expandafter\expandafter\expandafter\newsavebox\@nameuse{saveBox}
) but that won't work either:\newsavebox
will complain:! LaTeX Error: Command \saveBox already defined.
\@nameuse
require two expansions?