2

Based on this clear explanation by @David, I tried to define a command to test if a particular environment was used or not.

But I really don't know why the result is always false.

MWE

\documentclass{report}
\newif\iffoo
\newenvironment{foo}{begin}{\par end\footrue}
\newcommand{\testefoo}{\iffoo true \else false \fi}
\begin{document}
\testefoo

\begin{foo}\end{foo}

\testefoo
\end{document}

Output

false
begin
end
false
Sigur
  • 37,330

1 Answers1

3

The end code of an environment definition runs within the group set up by \begin.. \end so if it makes local assignments (as \footrue does) they are lost at the end of the group.

Depending what you want to do you (and making some (true) assumptions about the implementation of \footrue and \end) you could use

\global\footrue

or

\aftergroup\footrue
David Carlisle
  • 757,742