1

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?

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

2 Answers 2

4

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

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

It doesn't really answer your question, but I think you are thinking about expansion wrong.

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}}

1
  • You actually want two of them: \expandafter\foo\expandafter{\bar{abc}}. What you wrote only expands the {, which has no effect.
    – Ryan Reich
    Commented Oct 4, 2012 at 13:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .