A question for the LaTeX gurus (2)

Tuesday, 4 March, 2008

So I’ve sort-of figured out how to do conditional blocks. The following LaTeX initially appears to work:


newboolean{cond1}
newboolean{cond2}

setboolean{cond1}{false}
setboolean{cond2}{true}

ifthenelse{boolean{cond1}}
{
A block of conditional text in here.
blah blah
}

ifthenelse{boolean{cond2}}
{
A separate block of conditional text in here.
blah blah
}

I say initially appears to work, because it works fine for the first 4 or 5 attempts, but then some combination of blocks (begin{verbatim} for example), causes it to break on the 6 attempt. If I include a verbatim block in that 6 attempt, latex outputs an obscure error message… something along the lines of:


Runaway argument?
some code here end {verbatim} end {listing}
! Paragraph ended before @xverbatim was complete.


Which is rather infuriating, considering that I’ve got verbatim blocks in the previous conditional sections (it doesn’t complain about those), and because I’ve almost got the answer to my problem.

3 Responses to “A question for the LaTeX gurus (2)”

  1. jrbriggs says:

    Addendum…

    Further reading indicates the problem is (rather obviously) using verbatim inside the scope of another command. Though as to why that’s a problem, or how to get around it — I’m not any closer to answering.

  2. jrbriggs says:

    Gah! Even more infuriating. Found one reference to using \relax after the ifthenelse. Which fixes the problem — but only if you use it on the ifthenelse that is actually firing (i.e. the one set to true). On the others, it breaks. Meaning it’s a no-solution solution.

  3. jrbriggs says:

    Eureka! Or some other exclamation.

    The winner is…

    versions.sty

    Which I overlooked before for some reason, and revisited, only to discover it’s exactly what I want, and works as advertised. With thanks to Uwe L”uck, for releasing it and relieving 4 days of frustration.

Leave a Reply