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.

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?

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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}
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
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
show 3 more comments

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.