I'd like to create an environment solution that either displays its contents or nothing depending on whether the boolean solutions is set. Currently I'm trying:
\documentclass{article}
\usepackage{ifthenx}
\newboolean{solutions}
\setboolean{solutions}{true}
\usepackage{color}
\newenvironment{solution}%
{%
\ifsolutions%
\color{red}
\subsubsection*{Solution}%
}%
{%
\fi%
}
\begin{document}
Write some code:
\begin{solution}
\begin{verbatim}
a = 1;
a++;
\end{verbatim}
\end{solution}
\end{document}
This works great for \setboolean{solutions}{true} but fails for \setboolean{solutions}{false}. I get an error:
! Incomplete \iffalse; all text was ignored after line 21.
<inserted text>
\fi
<*> foo
?
https://tex.stackexchange.com/a/204450/13600 recommends using the environ package, but this is not a real environment so it fails if with an verbatim environment in the \BODY. In turn, https://tex.stackexchange.com/a/51256/13600 recommends some work arounds for environ like using special macros or external files.
Is there a cleaner way to do what I want?
commentpackage. – egreg Oct 19 '18 at 15:38comment. – egreg Oct 19 '18 at 15:40commenthas the same problems with verbatim. – Alec Jacobson Oct 19 '18 at 15:47