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
1
  • 1
    \global\footrue
    – egreg
    Jun 3, 2016 at 23:01

1 Answer 1

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
3
  • So, local boolean changes!!! How I didn't think about it! Thanks so much.
    – Sigur
    Jun 3, 2016 at 23:03
  • 1
    @Sigur as shown in the answer you reference \footrue is just \let\something\somethingelse and \let is always local to the current group unless prefixed by \global Jun 3, 2016 at 23:04
  • I didn't know that \let is local. Good to know.
    – Sigur
    Jun 3, 2016 at 23:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .