I want to save the content of a macro (which may contain text and other macros) for later use and without full expansion.
\def\mcr{a}
\def\textandmacro{sampletext \mcr} % this content i want to recall later with unexpanded \mcr
\def\save{\textandmacro} % so i save it
\def\mcr{b} % the macro may change
\def\textandmacro{xy} % this macro may change, too
%
\save % use '\save' here as if to type 'sampletext \mcr'
After that, when i use \save
i want to get sampletext b
, which is sampletext
and the current meaning of \mcr
.
But what i get is xy
of course, because \textandmacro
has changed.
When i \edef
the macro \save
, i will get sampletext a
, because \mcr
is fully expanded while edef-ing. This is not what i want.
What i want is some kind of an expansion for one level, not more. I don't want to save \textandmacro
but sampletext \mcr
.
Any ideas?
I'm working in TeX (LuaTeX), so Latex will not help me.
Best regards, Peter
Edit: the accepted answer is cool. I solved my problem with the \toks version. The other answers with the \let seem to be also right and simpler. I did't test it yet, but they are cool answers, too!
So: thank you all!
\edef\save{\unexpanded\expandafter{\textandmacro}}
does what you need\let\save\textandmacro
or with LaTeX\NewCommandCopy{\save}{\textandmacro}
.