0

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 :)

red_trumpet
  • 995
  • 1
  • 6
  • 17
  • By the way if you want to learn what's going on under the hood when the error happens, I recommend the TeXbook or TeX by topic (... and also LaTeX's source2e or something-else to see how environment works internally) – user202729 Jun 14 '22 at 13:15
  • @user202729 Thanks for the suggestions! – red_trumpet Jun 14 '22 at 14:07

0 Answers0