I have a handful of existing macros that I want to wrap in some custom processing. Here's an example of the kind of thing I'm aiming to do:
\makeatletter
\let\olddag\textdagger
\renewcommand\textdagger{\@inmatherr\textdagger \olddag}
\makeatother
Then if were to try to use $\textdagger$
, I'd get a error, rather than the existing behavior of typesetting nothing appropriate. However, \textdagger
in regular text mode will fall through to its existing definition.
My question is, how can I achieve the same effect but without making the assignment to the intermediate command \olddag
? I suspect there would be some voodoo using \edef
and/or \expandafter
that would enable me to expand:
{\@inmatherr\textdagger \textdagger}
or perhaps:
{\noexpand\@inmatherr\noexpand\textdagger \textdagger}
at definition time, so that when I invoke \textdagger
in the body of my document, I don't get a TeX stack overflow. But I haven't yet been able to find what it is.
These other questions (and answers) may be relevant:
- A: How do I reuse a command name two or more times?
- How to use \noexpand in an \edef?
- When to use \edef, \noexpand, and \expandafter?
- What is the difference between \let and \edef?
- How to control whether and when a macro gets expanded during another definition?
- Problem with nested \noexpand and \edef
But I haven't yet been able to piece together a solution from them. I guess it's no news that LaTeX's order-of-evaluation rules aren't that transparent.