# Macros with \fi for showing and hiding proofs [duplicate]

I would like to be able to globally showing and hiding proofs on a document, and be able to use macros to open and close the proof environments. Here is my current MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\newif\ifshowproof
\newcommand{\bp}{\ifshowproof\begin{proof}}
\newcommand{\ep}{\end{proof}}
\showprooffalse

\begin{document}
Goodbye.
\bp
Hello.
\ep\fi
Test.
\end{document}


As explored here: newcommand does not work with \fi, I cannot simply add \fi to the definition of \ep, however, I would like to have a "catch-all" macro so to say, that is, ideally something that would execute as \end{proof}\fi. Is there an easy way to do this?

## marked as duplicate by egreg, Malipivo, Heiko Oberdiek, Claudio Fiandrino, RubenApr 25 '14 at 10:17

I would just use a \NewEnviron to define a Proof environment that does what you want:

## Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{environ}

\newif\ifshowproof
\showprooffalse

\NewEnviron{Proof}{%
\ifshowproof%
\begin{proof}%
\BODY
\end{proof}%
\fi%
}%

\begin{document}

Goodbye.
\begin{Proof}
Hello.
\end{Proof}
Test.

\showprooftrue
Goodbye.
\begin{Proof}
Hello.
\end{Proof}
Test.

\end{document}

• I've seen them before, but out of curiosity, what do the % at the end of each line for the Proof definition do? – Abe Schulte Apr 25 '14 at 4:05
• @AbeSchulte: Well ever since Tex Capacity Exceeded (if remove % after use of macro) I have gotten into the habit of adding % at the end of a line, even when it is not absolutely necessary. There are a few cases where this is a problem but I have not run into them. See When is it harmful to add percent character at end of lines in a \newcommand, or similar. – Peter Grill Apr 25 '14 at 4:08
• @AbeSchulte: I have a feeling that the environ package needs to see the \end{Proof} directly, and not a macro that means \end{Proof}`. – Peter Grill Apr 25 '14 at 4:29
• In that case, do you happen to know of another solution that does allow for macros? – Abe Schulte Apr 25 '14 at 4:32