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.
grep -i warning *.logto the end of that pipeline :-) – David Carlisle Jul 04 '14 at 22:31\expandafter(the one just before the{) is doing? I don't understand why it is needed. (Is the{parsed as just another token, like\renewcommand? so we have to skip over it too?) (ii) Is there some translation of this solution using\edefinstead? If there is, that would help me understand better how\edefand\expandafterstand to each other. – dubiousjim Jul 04 '14 at 22:51{is just a token at that point, it's not so easy to use\edefas\edeffully expands things (and breaks any fragile command) but you just want to expand\textdaggeronce. – David Carlisle Jul 04 '14 at 23:14\bullet. I guess because it's not expandable? What I did in those cases was to saytexdef -tlatex bulleton my command line and get the expansion, and then just manually include that into any\renewcommand...– dubiousjim Jul 05 '14 at 21:53