I am trying to write some code that will clean up some future notes for me. In essence I want to be able to "turn on" or "turn off" an environment (proofs of results) via a simple command. I managed this with the environ package easily enough, but without the proof environments the theorems are all too close together and get cluttered. Thus I wanted to inject some space and a hrule to separate them, just for a nice visual. Again, accomplishing this was trivial, just adding the relevent code at the end of my new environment code, but this would put space and a hrule after every theorem... including the last one. Is there a way to know if the given environment is the "last" environment to be typeset, and then not put the line there? I was thinking about trying to do some kind of stepcounter system where it would expand at the end and thus know that the one that had "counter 17" is the last one and expand a macro only there (or everywhere but there).
Here is my MWE that has the undesired hrule at the end:
\documentclass{article}
% Packages
\usepackage{amsmath}
\usepackage{environ}% Used to hide proofs for condensed version of what we want to see.
\newcommand{\hideproofs}{%
\RenewEnviron{proof}{%
\vspace{1cm}
\hrule%
\vspace{1cm}
}%
}%
\begin{document}
\hideproofs% Comment this out to show proofs.
\begin{theorem}
This is theorem 1!
\end{theorem}
\begin{proof}
This is the first proof! It should be hidden when the hideproof command is on
and instead have the spacing and the hrule,
but it should show when hideproof is commented out.
\end{proof}
\begin{theorem}
This is theorem 2!
\end{theorem}
\begin{proof}
This is the second proof! It should also be hidden when the hideproof command is on
and instead have the spacing and the hrule,
but it should show when hideproof is commented out.
\end{proof}
\begin{theorem}
This is theorem 3! The last thoerem!
\end{theorem}
\begin{proof}
This is the third proof! It should be hidden when the hideproof command is on
and instead NOT have the spacing OR the hrule,
but it should still show when hideproof is commented out.
\end{proof}
\end{document}
.aux
file for that since an environment at the time it is processed can not know if it is the last one or not. Maybetotcount
can help you (it does the.aux
writing for you).