I'm writing a pretty complicated class to typeset a book based on memoir.

One of my commands draws a caption on the preceding verso page, draws content on the following recto and verso pages, and then needs to draw content on the following recto page. However, the following recto page is created by an environment that begins with \clearpage so that its TOC entry and footer definition end up on the right page.

The command already knows how to start on the verso page using


But I can't figure out how to add content past a following \clearpage. I'm trying to make this work with conditional statements, but it's not working the way I expect.

My understanding of LaTeX (and thus TeX) macros is that when we define a newcommand or a newenvironment, LaTeX substitutes the macro's content where the macro command is placed when it compiles the document.

So in theory,


    \foo test text

Would be interpreted by LaTeX as

\Huge test text

If this is correct, I should be able to add conditional switches that are toggled wherever the command is used, as though it was being interpreted straight through.

Are conditionals the wrong way to go about this, or am I using the wrong methodology?

Here is a MWE showing my use of conditionals to try to display or hide a black box on the page after the \complicated command, regardless of the fact that the exampleenvironment begins with \clearpage.



    \begin{tikz}[remember picture, overlay]
            [text width=1in,text height=1in,fill=black] 
            at (current page.center){};

    \noindent\textsf{This is the test Environment}\par%
    It needs to start with a clearpage, but has to accept the black box from the other environment.%

    \textbf{This command puts some content on the bottom of this page}%
    \textbf{And fills this page}%
    \textbf{And needs to draw a box on the next page}%


    foo bar baz bat


    This page should have a black box

% conditional "test" should now be false...

    This page should \emph{not} have a black box. 


My MWE outputs this document, which is correct except the black box on the last page should not be there. Typing \testfalse where the MWE says `% conditional "test" should now be false...' gives the desired behavior, but I would like the environment to toggle the conditional, not the user in the main TeX file.

enter image description here

  • (for searching) Also answer the question: How to execute something outside the environment group in environment defined by newenvironment?
    – user202729
    Commented Mar 26, 2022 at 7:53

1 Answer 1


When you perform \testtrue, it effectively does


The same goes for \testfalse (\let\iftest\iffalse). Since they both use \let, they're very similar in nature to that of macro definitions/assignments. And, macro definitions are local to the group within which they are made. As such, your issue of \testfalse inside the exampleenvironment doesn't survive past \end{exampleenvironment}.

Here is a toned-down version of your implementation:

enter image description here


%\testfalse% default is false

  {\testtrue}% \begin{exampleenvironment}
  {}% \end{exampleenvironment}


\verb|test| is \iftest true\else false\fi.

  Setting \verb|test| to true.

\verb|test| is \iftest true\else false\fi.


If you want such definitions to survive your environment, consider prepending it with a \global definition, as in \global\testtrue.Of course, this makes a global change to the conditional and therefore survives all (nested) groups. If you which for it to survive only the current group, you can use \aftergroup\testtrue. Note that \aftergroup takes only a single token. For extending this to multiple tokens, see \aftergroup a list of tokens.

You must log in to answer this question.

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