Thursday 30 May 2013

Conditional inclusion in Python LaTeX template

I have been using a very simple templating technique in python

page = template % dotted

dotted is a dictionary whose keys are a dotted path to every property in an object eg child.carer.email

To conditionally include text in LaTeX you can use the etoolbox package:

\usepackage{etoolbox}

\newcommand\toggleTrue{\toggletrue}
\newcommand\toggleFalse{\togglefalse}

\newtoggle{elephants}
\toggleFalse{elephants}
\iftoggle{elephants}{
elephants
}{
not elephants
}

A boolean object property, say member.isAdult can now be used to control inclusion:

\usepackage{etoolbox}

\newcommand\toggleTrue{\toggletrue}
\newcommand\toggleFalse{\togglefalse}

\newtoggle{isAdult}
\toggle%(member.isAdult)s{isAdult}
\iftoggle{isAdult}{
payment date
}{
date of birth 
}

No comments:

Post a Comment