I have an environment which should only be shown, if a certain flag is set. Currently I do
\ifenv
\begin{env} Text \end{env}
\fi
but it would be nice to include the \ifenv and \fi into the environment. Here is my naive approach, but it did not work.
\newif\ifenv
\envtrue
\newenvironment{env}{\ifenv}{\fi}
\begin{env} Test \end{env}
This compiles fine, but setting \envfalse instead of \envtrue produces an error. My guess is that \ifenv is evaluated immediately when read by LaTeX, and not after the environment is expanded with its content.
How can I achieve this? Any help would be appreciated :)