TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
up vote 12 down vote accepted

You can do this:

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

or perhaps

  if x then
  % else
    % do something else
share|improve this answer
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


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.