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
\strictpagecheck%
\checkoddpage\ifoddpage\hbox{}\newpage\fi
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,
\newcommand{foo}{\Huge}
\begin{document}
\foo test text
\end{document}
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.
\documentclass{memoir}
\usepackage{tikz}
\newif\iftest
\testfalse
\newcommand{\drawbox}{%
\begin{tikz}[remember picture, overlay]
\node
[text width=1in,text height=1in,fill=black]
at (current page.center){};
\end{tikz}%
}
\newenvironment{exampleenvironment}{%
\clearpage%
\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.%
\iftest\drawbox\fi%
\testfalse%
\\\par%
}{%
\par\noindent\rule{\linewidth}{.4pt}%
}
\newcommand{\complicated}{%
\vfill%
\textbf{This command puts some content on the bottom of this page}%
\clearpage%
\textbf{And fills this page}%
\clearpage%
\textbf{And needs to draw a box on the next page}%
\clearpage%
\testtrue%
}
\begin{document}
\begin{exampleenvironment}
foo bar baz bat
\end{exampleenvironment}
\complicated
\begin{exampleenvironment}
This page should have a black box
\end{exampleenvironment}
% conditional "test" should now be false...
\begin{exampleenvironment}
This page should \emph{not} have a black box.
\end{exampleenvironment}
\end{document}
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.

