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.

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

How can I test for a TeX boolean in Lua?

This kind of code doesn't work:



   -- some lua code

      -- some more lua code
      -- another lua code

   -- again some lua code

Is there a way to achieve this?

share|improve this question
up vote 5 down vote accepted

Tex expansion happens before control is passed to lua. The following minimal example works.



% \luaflagtrue

  print("before flag")
    print("lua flag true")
    print("lua flag false")

share|improve this answer
I don't see a thing. This only outputs "test" in the PDF, using lualatex from TeXLive 2011. – ℝaphink Sep 14 '11 at 17:47
Ah sorry, saw it in the output. – ℝaphink Sep 14 '11 at 17:49
OK found the issue: @ is redefined to other inside the luacode environment for some reason, so booleans using @ in their names won't work. – ℝaphink Sep 14 '11 at 17:52
@Raphink: You can still access them with \csname … \endcsname. – Andrey Vihrov Sep 15 '11 at 6:37
@Andrey: Good to know. I've switched to names without @ though, and it helped ;-) – ℝaphink Sep 15 '11 at 7:14

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.