9

How can I test for a TeX boolean in Lua?

This kind of code doesn't work:

\newif\if@mypkg@someif

\begin{luacode}

   -- some lua code

   \if@mypkg@someif
      -- some more lua code
   \else
      -- another lua code
   \fi

   -- again some lua code
\end{luacode}

Is there a way to achieve this?

5

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

\documentclass{minimal}
\usepackage{luacode}

\newif\ifluaflag

% \luaflagtrue

\begin{luacode}
  print("before flag")
  \ifluaflag
    print("lua flag true")
  \else
    print("lua flag false")
  \fi
\end{luacode}


\begin{document}
test
\end{document}
  • 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
  • 1
    @Raphink: You can still access them with \csname … \endcsname. – Andrey Vihrov Sep 15 '11 at 6:37
  • 1
    @Andrey: Good to know. I've switched to names without @ though, and it helped ;-) – ℝaphink Sep 15 '11 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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