I have defined an environment called answer
that displays the answer of a question of a test I'm supposed to prepare.
The idea is to compile a version where the answers are displays and one were they are not (in order to test the students).
Is there an elegant way to disable environments?
One can of course define a command \ifanswer
and then write \ifanswer{\begin{answer}foo\end{answer}}
. For each environment. The problem with this approach however is that one needs to remember and insert this command each time, and of course forgetting this one time would be embarrassing.
MWE:
\documentclass{article}
\newenvironment{answer}{\textit{Answer} }{\textit{the end.}}
\begin{document}
Question: Bla
\begin{answer}
Foo
\end{answer}
\end{document}
Best Answer
As told by David, you can use
comment
package:If you want to do it the hard way -