3

Still hammering away at a database problem. Mostly done, but stumped by:

\documentclass{article}

\begin{document}

\newcommand{\testmacro}{U01}

The macro testmacro equals ``U01''

\directlua{
if \testmacro == ("U01") then tex.print ("testmacro equals U01")
    elseif \testmacro == ("U02") then tex.print ("testmacro not equal")
else tex.print ("Nothing matched")end}

\end{document}

Output is:

The macro testmacro equals ``U01''

Nothing matched

I've got a similar thing using a counter working properly, so kind of mystified here.

5

\directlua does expansion, so you are doing

if U01 == ("U01")

that clearly returns false. You have to quote the string:

\documentclass{article}

\begin{document}

\newcommand{\testmacro}{U01}

\directlua{
if "\testmacro" == "U01" then tex.print ("testmacro equals U01")
    elseif "\testmacro" == "U02" then tex.print ("testmacro not equal")
else tex.print ("Nothing matched")end}

\renewcommand{\testmacro}{U02}

\directlua{
if "\testmacro" == "U01" then tex.print ("testmacro equals U01")
    elseif "\testmacro" == "U02" then tex.print ("testmacro not equal")
else tex.print ("Nothing matched")end}

\renewcommand{\testmacro}{U03}

\directlua{
if "\testmacro" == "U01" then tex.print ("testmacro equals U01")
    elseif "\testmacro" == "U02" then tex.print ("testmacro not equal")
else tex.print ("Nothing matched")end}

\end{document}

enter image description here

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.