Does anyone know how to invert a boolean in LaTeX? It looks like once you are inside a logical test, resetting the logical value has no effect. Using the etoolbox package, I tried
\foreach \n in {1,2,3,4,5,5,6,7,8,9,e}{ \iftoggle{pauper}{ True \togglefalse{pauper} }{ False \toggletrue{pauper} } } It should produce True False True False True False True False True False, but produces only a string of ten True. How can I make it come out True False True False ....
If this problem is solved, I can solve a far larger problem. It might be that the larger problem has a more elegant solution I have not though of, so I state it as well:
The context is a textbook, where I write the assignment and the answer together, and then call the assignment file twice. The first time, the boolean value assignment is true, the second time it is false.
\begin{enumerate} \item \ifthenelse{assignment}{$2+2$}{$4$} ... \end{enumerate} Now, I would like for the answers section to have answers to only the odd numbered problems, except for a teacher's version which would have all. So the \item should ideally be something like this
% if assignment=false, then ... % if item counter is odd: \item \ifthenelse{assignment}{$2+2$}{$4$} % but if item counter is odd: \stepcounter{enumi} % if assignment=true, then, regardless of counter: \item \ifthenelse{assignment}{$2+2$}{$4$} I have tried
\ifthenelse{\boolean{assignment}}{$2+2$}{ \ifthenelse{\boolean{oddItem}}{ \item $4$ \setboolean{oddItem}{false} }{ \stepcounter{enumi} \setboolean{oddItem}{true} } } But the boolean stays the same value. I have tried several combinations, and also setting it outside the inner ifthenelse like this,
\setboolean{oddItem}{\not\boolean{oddItem}} but to no avail. Same with toggle instead of boolean.