Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
I'd say \directlua{foo([[\unexpanded{#1}]])} –  egreg Oct 4 '12 at 11:13
add comment

2 Answers

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

\def\foo#1{%
  \directlua{foo([[\unexpanded{#1}]]}%
  }
share|improve this answer
add comment

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

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.