# How to generalize a solution with \NewEnviron to \RenewEnviron (error: \env@proof@save@env undefined)

This question is a follow-up from Solution environment via true/false switch where Ian helped me to define a solution environment which can be hidden. I tried it as well for a proof environment, but proof is already defined. I tried to work with \RenewEnviron and followed How to ignore everything in the document environment? to get past the first error, but now I get LaTeX Error: \env@proof@save@env undefined. I am looking for a fix (rather than a suggestion to stick with the already defined environment or to use a different name).

\documentclass{scrartcl}

\usepackage[american]{babel}
\usepackage{environ}
\usepackage{amsthm}
\usepackage{amsmath}

\newif\ifshowproof
\showprooftrue

% proof environment
\makeatletter
\providecommand{\env@document@save@env}{}%
\providecommand{\env@document@process}{}%
\RenewEnviron{proof}[1][showproof]{%
\csname if#1\endcsname
\trivlist
\item\relax{\sffamily\bfseries Proof}\par\noindent
\BODY
\endtrivlist
\fi
}
\makeatother

\begin{document}
Proof with hide feature:
\begin{proof}[false]
This should not appear
\end{proof}

Proof without hide feature:
\begin{proof}
This should appear
\end{proof}
\end{document}

-
I suggest \let\proof\relax\let\endproof\relax and to remove the useless \providecommand instructions. – egreg Apr 26 '14 at 19:13
Hi Enrico, where do you put the \let\proof... statement at? instead of the \providecommand or inside? I tried various versions but they give me errors. – Marius Hofert Apr 26 '14 at 19:20
Now \RenewEnviron should become \NewEnviron. – egreg Apr 26 '14 at 19:22
Ahh, great, thanks! (do you want to post it so that I can accept it?) – Marius Hofert Apr 26 '14 at 19:25
This will be fixed in v0.3 of environ, just submitted to CTAN. Sorry for the inconvenience. – Will Robertson May 4 '14 at 8:37

In my experience, \RenewEnviron has never worked. The only way I know to make it work is to undefine the previous commands and use \NewEnviron:

\documentclass{scrartcl}

\usepackage[american]{babel}
\usepackage{environ}
\usepackage{amsthm}
\usepackage{amsmath}

\newif\ifshowproof
\showprooftrue

% proof environment
% remove the meaning of \proof and \endproof
\let\proof\relax
\let\endproof\relax
% now we can redefine proof
\NewEnviron{proof}[1][showproof]{%
\csname if#1\endcsname
\trivlist
\item\relax{\sffamily\bfseries Proof}\par\noindent
\BODY
\endtrivlist
\fi
}

\begin{document}
Proof with hide feature:
\begin{proof}[false]
This should not appear
\end{proof}

Proof without hide feature:
\begin{proof}
This should appear
\end{proof}
\end{document}


However, I would retain the original proof environment, so the QED mechanism remains in place.

\documentclass{scrartcl}

\usepackage[american]{babel}
\usepackage{environ,letltxmacro}
\usepackage{amsthm}
\usepackage{amsmath}

\newif\ifshowproof
\showprooftrue

% proof environment
\makeatletter
\LetLtxMacro\amsthmproof\proof
\LetLtxMacro\amsthmendproof\endproof
\let\proof\relax
\let\endproof\relax
\NewEnviron{proof}[1][showproof]{%
\csname if#1\endcsname
\amsthmproof[\normalfont\bfseries Proof\spacefactor3000 ]
\BODY
\amsthmendproof
\fi
}
\makeatother

\begin{document}
Proof with hide feature:
\begin{proof}[false]
This should not appear
\end{proof}

Proof without hide feature:
\begin{proof}
This should appear
\end{proof}
\end{document}


Remove the \spacefactor3000 bit (don't forget the space, otherwise) if you want the full stop after Proof.

If you really want a line break after Proof (but you shouldn't), add \mbox{}\par\noindent after the closing bracket.

-
As you know, I'm not an expert here. But I think with \pushQED{\qed} before \csname and \popQED before \endtrivlist, one can get the qedsymbol as well. – Marius Hofert Apr 26 '14 at 19:34
I posted a follow-up question which shows that a \label{} introduces an additional horizontal space (tex.stackexchange.com/questions/173664/…) – Marius Hofert Apr 26 '14 at 20:15
@MariusHofert Yes, of course. That's because you want a new line after Proof, which you don't want, do you? ;-) – egreg Apr 26 '14 at 20:16
ahh... of course... my hope was that a label does not change the spacing, but apparently it does. hmmm... I would like the new line after the label in case there is one :-) – Marius Hofert Apr 26 '14 at 20:18
@MariusHofert Besides, what does a \label do there? – egreg Apr 26 '14 at 20:20