# How to define a proof environment which can be displayed/hidden? [combining two TeX solutions] [duplicate]

This question already has an answer here:

I once asked for a solution to suppress vertical space right after the beginning of a proof environment; see the link (1) below. I use this quite heavily, it works very well.

I recently asked how to hide/display solutions in an exercise; see the link (2) below. It also works very well.

I now would like to construct a proof environment which allows for the hide/show feature. So exactly combining the two solutions of the above problems. I tried my best but I'm not a TeX expert... see below (I obtain: ./mini.tex:55: LaTeX Error: \env@proof@save@env undefined.)

\documentclass{scrartcl}

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{environ}
\usepackage{ifthen}

\newboolean{showProof}% for showing proofs
\setboolean{showProof}{true}% setting the switch

\newboolean{sol}% for solution environment
\setboolean{sol}{true}% setting the switch

% proof environment which suppresses vertical space
% see (1) http://tex.stackexchange.com/questions/66739/how-to-suppress-vertical-space-between-proof-environment-heads-and-itemize-envir
\makeatletter
\renewenvironment{proof}[1][Proof]{\par
\pushQED{\qed}%
\normalfont\topsep2\p@\@plus2\p@\relax
\trivlist
\item[\hskip\labelsep
\sffamily\bfseries #1]\mbox{}\hfill\\*\ignorespaces
}{%
\popQED\endtrivlist\@endpefalse
}
\makeatother

% solution environment which allows to show/hide of content
% see (2) http://tex.stackexchange.com/questions/172404/solution-environment-via-true-false-switch?noredirect=1#172408
\makeatletter
\NewEnviron{solution}[1][sol]{
\gdef\@tmp{#1}
\ifthenelse{\boolean{#1}}{\par\noindent{\sffamily\bfseries Solution}\par\noindent\BODY}{\ignorespaces}
}[\ifthenelse{\boolean{\@tmp}}{}{\ignorespacesafterend}]
\makeatother

% trial to define proof environment with the feature that content can be
% shown/hidden (mix of the above two solutions)
\makeatletter
\RenewEnviron{proof}[1][showProof]{
\gdef\@tmp{#1}
\ifthenelse{\boolean{#1}}{%
\par\pushQED{\qed}%
\normalfont\topsep2\p@\@plus2\p@\relax
\trivlist\item[\hskip\labelsep
\sffamily\bfseries #1]\gdef\mycurrenvir{proof}\global\starttheoremtrue\mbox{}\hfill\\*\ignorespaces
\BODY}{\ignorespaces}
}[\ifthenelse{\boolean{\@tmp}}{%
\gdef\mycurrenvir{\relax}
\popQED\endtrivlist\@endpefalse
}{\ignorespacesafterend}]
\makeatother

\begin{document}
This is some statement we would like to prove: $\exp(i\pi)=-1$
\begin{proof}
This should be displayed if and only if showProof is set to true.
\end{proof}
\end{document}


## marked as duplicate by Werner, Adam Liter, Heiko Oberdiek, cmhughes, Svend TveskægApr 23 '14 at 0:36

• This is very similar in nature to How to ignore everything in the document environment? where I got around the problem by defining the required commands so as to make environ happy. More specifically, just add \makeatletter \providecommand{\env@proof@save@env}{} \providecommand{\env@proof@process}{} \makeatother somewhere before using \RenewEnviron. – Werner Apr 22 '14 at 22:08
• If you replace in the solution below the head by \RenewEnviron{proof}[2][showProof] and use #2 instead of the hard-coded name Proof, then it does not work anymore (I get Undefined control sequence ...  with many more symbols that tex.stackexchange fails to put in a comment). Do you know why/how to fix it? – Marius Hofert Apr 22 '14 at 22:59
• solution was defined using \NewEnviron, while proof was redefined using \RenewEnviron. I think the definition via environ works as expected... it's just a redefinition that needs a little help. – Werner Apr 22 '14 at 23:01
• Yes, because with \RenewEnviron{proof}[2][showProof] your input needs to be \begin{proof}[<opt>]{<man>} where <opt> is optional (defaults to showProof) and <man> is mandatory. So you would need \begin{proof}{SHoWPRooF} in order for #2 to be properly recognized as a "alternative" to Proof. – Werner Apr 22 '14 at 23:04