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.

When there is \directlua{x = 25} one can say \edef\rgf{\directlua{tex.sprint(x)}}, but when x was never created by \directlua{x = 25}, \directlua{tex.sprint(x)} will fail. Thus something like \@ifundefined{x}{x undefined}{x defined} would be nice. How does one "say this in Lua", please?

share|improve this question
3  
May be you 'd try reading some general lua programming documentation first. –  Khaled Hosny Nov 3 '11 at 14:28
    
@KhaledHosny: I tried but did not find it there. Any suggestion for better lua-documentation? –  Stephen Nov 3 '11 at 17:56

1 Answer 1

up vote 12 down vote accepted

You can do this:

\directlua{tex.sprint( x or 42 ) }

or perhaps

\directlua{
  if x then
    tex.sprint(x)
  % else
    % do something else
  end
}
share|improve this answer
1  
But see also the question about using luacode and \directlua{} –  topskip Nov 3 '11 at 12:31
    
Thanks, it works! (Upvoted & accepted.) Also your answer to the other question is enlightening, but unfortunately with that question title one does not find it without being told that it is there. –  Stephen Nov 3 '11 at 17:52

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.