When defining macros using \edef
(which by default expands every macro within the definition as much as possible), I can declare some macro within that definition to not expand by using \noexpand
before that macro. So \noexpand
could be seen as declaring an exception to the default behavior of expanding everything.
However, sometimes I only want very few commands to be expanded. Now when I define a macro using \def
, the default behavior is to not expand anything within the definition (at the point of the definition - it may of course later be expanded after the new macro has been expanded somewhere). Is there a command for manually expanding a macro (fully or just one step) at the point of definition when defining it using \def
or any other definition command such that normally macros are not expanded (in analogy to declaring an exception as with \noexpand
within \edef
)? If so, what is the command and its exact effect?
To illustrate the question by an example, I can have the following code using \edef
:
\documentclass{article}
\newcounter{mycount}
\edef\foo{\noexpand\textit{\arabic{mycount}}}
\stepcounter{mycount}
\begin{document}
Before: \foo
After: \arabic{mycount}
\end{document}
The output is:
Before: 0
After: 1
My question is whether there is a command \doexpand
(or whether such a command could be defined) such that the following code would yield the same result:
\documentclass{article}
\newcounter{mycount}
\def\foo{\textit{\doexpand\arabic{mycount}}}
\stepcounter{mycount}
\begin{document}
Before: \foo
After: \arabic{mycount}
\end{document}
EDIT: Some alteration of the last code would be ok. My restriction is not to use \def
but to have any way of defining a macro such that macros within that definition are normally not expanded as long as they are not "marked" somehow to be expanded.
\def
it performs no expansion.\doexpand
would also be not-expanded. Only if it was first expanded would TeX know that the following command should also be expanded. But that would mean you would need to ensure that\doexpand
was expanded, so you'd need\doexpand\doexpand
. But now the problem is that TeX can only know that\doexpand
means to expand the next thing if it first expands\doexpand
. So we need to ensure that\doexpand
is expanded, too. That is, we need\doexpand\doexpand\doexpand
...\doexpand
in front of the counter use instead of writing\noexpand
everywhere else.