Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
I suggest \let\proof\relax\let\endproof\relax and to remove the useless \providecommand instructions. –  egreg Apr 26 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 at 19:20
    
Now \RenewEnviron should become \NewEnviron. –  egreg Apr 26 at 19:22
    
Ahh, great, thanks! (do you want to post it so that I can accept it?) –  Marius Hofert Apr 26 at 19:25
    
This will be fixed in v0.3 of environ, just submitted to CTAN. Sorry for the inconvenience. –  Will Robertson May 4 at 8:37

1 Answer 1

up vote 6 down vote accepted

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.

enter image description here

share|improve this answer
    
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 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 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 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 at 20:18
    
@MariusHofert Besides, what does a \label do there? –  egreg Apr 26 at 20:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.