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.

I have a macro where I need to combine one of it's arguments with text to form a string that is used in lua.

\newcommand{\mymacro}[1]{\directlua{
    myfunc("#1 4")
}

if I call \mymacro{alpha} I need myfunc to receive alpha4 and not alpha 4

any ideas?

share|improve this question
    
It seems that one can do #14 and it will work. Seems a bit strange but I guess as long as one doesn't have more than 9 macro parameters it should be fine. Is there a better way? –  AbstractDissonance Jul 25 '12 at 0:32
1  
I don’t think TeX supports more than 9 macro parameters anyway. –  Khaled Hosny Jul 25 '12 at 0:44

1 Answer 1

up vote 1 down vote accepted

Your \mymacro is a standard TeX macro: it does not matter at all that it includes \directlua. As such, the standard rules for replacement of material apply. When you define \mymacro with "#1 4", you are telling it to substitute in #1, then a blank space, then a 4. So its entirely to be expected that the space appears in the output.

As was indicated in a comment, TeX only allows up to nine arguments to a macro (and indeed working with a macro with nine arguments is pretty awkward). As such, you should miss out the space here or write your definition such that you use additional lines to divide up concepts

\newcommand{\mymacro}[1]{%
  \directlua{%
    myfunc(
     "%
       #1%
       4%
     "
     )
  }%
}
share|improve this answer
    
#1\relax4 also works. –  Martin Schröder Jul 25 '12 at 15:38

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.