This is a tangential followup to my question here: How do things like ToC and label work to save information between compiles?
Edit: Question solved but the original was ill formed. I have edited the question to reflect the solution.
I am fairly familiar with a lot of expansion aspects of latex, but I only know how to avoid a particular macro from expanding, or skipping macros during expansion using \expandafter. But is there a way to immediately define a macro when it is defined, but without expanding any commands in that macro? Let me give an example.
Suppose I know I will be handed some mystery macros \text, \texttwo, \textthree. All I know is that they contain text and some number of commands, but I have no idea what those commands are.
I want to write a macro that transfers the content of the mystery macro to a new name I have, so I can renew the previous mystery macro. But I need it to do so immediately so that, as I renew the mystery macro, I can use transfer on it several times, renewing it between uses, and not end up with a bunch of duplicate macros at the end. So, some pseudo code would be;
\documentclass{article}
\newcommand{\text}{Mysterious content here}
\newcommand{\texttwo}{Mysterious content here again}
\newcommand{\textthree}{Mysterious content here again and again}
\newcommand{\transfer}[2]{%
\expandafter\let\csname#2\endcsname#1% \let works better than \edef
}%
\begin{document}
\transfer{\text}{newcomone}
\renewcommand{\text}{New Text Take two, but now include \texttwo}
\transfer{\text}{newcomtwo}
\renewcommand{\text}{New Text Take three, but with \textthree}
\transfer{\text}{newcomthree}
\text
\newcomone
\newcomtwo
\newcomthree
\end{document}
Ideally I'd want the output to look like;
New Text Take three, but with Mysterious content here again and again
Mysterious content here
New Text Take two, but now include Mysterious content here again
New Text Take three, but with Mysterious content here again and again
In the above example I (originally) used edef, but I don't want to use edef directly as that would expand the commands inside \newcomtwo and \newcomthree. But I believe if I used \def it would result in all three being the same.
Now, if I knew the commands coming in I could use \noexpand or \protect in front of the relevant commands (ie write something like \renewcommand{\text}{New Text Take two, but now include \protect\texttwo} ) But is there a way to do it without needing access to the mystery command? i.e. do it at the level of how I defined the \transfer command?
\let\origmacro\macro \renewcommand\macro{...}
?Mysterious Text!
is nowhere in your file at all, how is that supposed to be produced exactly?