I have a macro that is repeatedly called in my document
\newcommand\foo[1]{Process #1}
\newcommand\var[2]{Do something with #1 and #2, and then call '\foo{#2}', and again '\foo{#2}', and once again '\foo{#2}'}
The macro foo
is expanded many times inside var
with the same argument, one may think that passing the argument is just redundant, and could be possibly avoided.
Question: Is it possible to have a version of foo
such that when var
is defined as
\newcommand\var[2]{Do something with #1 and #2, and then call '\foo', and again '\foo', and once again '\foo'}
would lead to the result of the first example?
MWE
\documentclass[]{article}
\newcommand\foo[1]{Process #1}
\newcommand\var[2]{Do something with #1 and #2, and then call '\foo{#2}', and again '\foo{#2}', and once again '\foo{#2}'}
\begin{document}
\var{x}{y}
\end{document}
I would like to have the same result, after defining var
as
\newcommand\var[2]{Do something with #1 and #2, and then call '\foo', and again '\foo', and once again '\foo'}
\newcommand\foo{Process \noexpand{#1}}
? It doesn't work, right? I've try a bunch of combinations ofedef
s and\expandafter
s but I cannot make it work\renewcommand\var[2]{\def\foo{Process #2}Do something with #1 and #2, and then call '\foo', and again '\foo', and once again '\foo'}