I have a script written in perl which harvest data from an sql database, then produces a printed report in latex.
I was looking to put an IF loop in the latex part of the script to print one set of text if the data existed in the sql database, and a different set of text if it does not.
Looks like etoolbox is promising here, but can it take a variable (which I can set to be anything - 1,0,T,F etc)?
I found this example on the site which shows how to set up the loop but without a variable (LaTeX conditional expression).
\newtoggle{paper}
which is set with either
\toggletrue{paper}
\togglefalse{paper}
And to use it:
\iftoggle{paper}{%
% using paper
}{%
% electronic
}
EDIT: What I am wondering is if I can use a variable from earlier in my script (e.g. $myo_text) in the eftoolbox toggle.
e.g.
\newtoggle{$myo_text}
Or is there another way of doing this? Is it even possible to carry a variable into the latex part of the script from the sql query and use it in a conditional loop?
EDIT 2: Here is a trimmed latex chunk from my script. Just now it prints out these perl variables just fine ($myo_test, $myo_reporter1 etc).
print FH <<END;
\\textbf{EXERCISE TOLERANCE TEST} \\newline
\\begin{small}
\\textbf{Stress Test:} $myo_test \\newline
\\textbf{Rest ECG:} $myx_rest_ecg \\newline
\\textbf{Stress ECG:} $myx_stress_ecg \\newline
\\textbf{Performed by:} $myx_performed1 \\newline
\\end{small}
\\textbf{Reported By:} $myo_reporter1 \\hspace{2em} \\textbf{Signature:}
\\end{document}
END
I would like to put a loop in this latex chunk that does not print this part of the report if $myo_text is blank/empty.
paper. – egreg Feb 04 '14 at 10:01\ifstrequal{\myo_text}{true}{True case}{False case}or some of the other test commands. – Andrew Swann Feb 04 '14 at 10:35$myo_textrather than the string$myo_textgets written to the text file to be processed by latex. How you do that depends on the structure of your perl, something likeprint "\\newtoggle{" . $myo_text . "}"– David Carlisle Feb 04 '14 at 11:40$myo_testinto the latex file although if you just want a simple if test you could do it in the latex, I'll add something – David Carlisle Feb 04 '14 at 11:59XYZ_unique_name_XYZ, and then have you perl script replace all placeholders, and remove the empty ones. – daleif Feb 04 '14 at 12:16