# suppress expansion in macro call

What I would like is to suppress the expansion of the group as a parameter to a macro so that it can be expanded later. For example we want to pass the paramater unmodified as a string to lua or to a file.

Let us suppose we have a macro \foo which accepts a parameter.

\def\foo#1{%
\directlua{foo([[#1]]}%
}


if we call it as: \foo{\bar{abc}} the \bar gets expanded before \foo gets to see it. Of course we can manually suppress the expansion with \foo{\noexpand\bar{abc}}, but can it be done automatically?

-
I'd say \directlua{foo([[\unexpanded{#1}]])} –  egreg Oct 4 '12 at 11:13

if we call it as: \foo{\bar{abc}} the \bar gets expanded before \foo gets to see it.

The argument to \foo is not expanded before \foo gets to see it. It is expanded inside \foo. Consider the following

\documentclass{article}
\def\foo#1{\def\bar{a}#1}
\begin{document}
\def\bar{x}
\foo{\bar}
\end{document}


If you want to expand \bar before \foo get to see it you need an \expandafter: \expandafter\foo\expandafter{\bar{abc}}

-
You actually want two of them: \expandafter\foo\expandafter{\bar{abc}}. What you wrote only expands the {, which has no effect. –  Ryan Reich Oct 4 '12 at 13:58
@RyanReich thank you, I fixed it. –  StrongBad Oct 4 '12 at 14:03

Without a full example to test this is untested but I would assume that you could go

\def\foo#1{%
\directlua{foo([[\unexpanded{#1}]]}%
}

-