I thought I was finally understanding expansion, but then I wrote something along the following lines, and it has me a bit stumped.
\documentclass{article}
\usepackage{xcolor}
\usepackage{etoolbox}
\makeatletter
\def\ae@test#1{\textcolor{red}{\fbox{#1}}}
\edef\aetest#1{<a bunch of expandable material>\expandonce\ae@test{#1}<more expandable material>}
\makeatother
\begin{document}
\aetest{Hello}
\end{document}
I suspect the issue has something to do with the need to look ahead for the arguments, but I don't even know how to test that theory.
So, I have two questions:
- What's actually happening that the expansion isn't working as I would like to think it should?
How do I write my macro
\aetest
so that it does what I want? Namely,\aetest{<arg>}->\textcolor{red}{\fbox{<arg>}}
I suppose there might be some trick I could do using tokens (since tokens within an \edef
expand just once), but I'm a bit cloudy on that approach since I haven't played much with tokens.
Incidentally, I wrote \ae@test
as I did because I'm not interested in the following sort of scenario:
\def\ae@test#1{\textcolor{red}{#1}}
where with \aetest
the following would accomplish what I want
\edef\aetest#1{\expandafter\noexpand\ae@test{#1}}
The issue is that I want to expand a macro which may have several fragile elements within it.
I did try something along the following lines
\edef\aetest#1{\unexpanded\expandafter{\ae@test{#1}}}
thinking that \ae@test
would thus be able to grab its argument, but still the same issue.
pgfkeys
and see if I can get something to work. I'm quite interested in this myself. :-)