Creating new environment with ifthenelse

environmentsifthenelseproof-package

I want to make it so all proofs in my document are conditional using the ifthen package. So far I have

\usepackage{ifthen}

\newboolean{proofs}
\setboolean{proofs}{true}
...
\ifthenelse{\boolean{proofs}}{\begin{proof}
    ...any proof...
\end{proof}}{ }

but of course I have to keep putting the ifthenelse statement every time I create a proof. I wish to encapsulate this in an environment, say fproof. How can I do this, since the ifthenelse statement is incorporated into both the begin and end of the proof environment?

For example, I would like any proof to be as simple as:

\begin{fproof}
   ...any proof...
\end{fproof}

Then toggling proofs would just hide all the fproof's. Any ideas?

Update: attempt using multiaudience package:

\newenvironment{fproof}
{\begin{shownto}{showProofs}\begin{proof}}{\end{proof}\end{shownto}}

Running into errors matching begins and ends.

Best Answer

All environments which should grab their content without processing (e.g. it to throw it away) need to find the end of the environment without expanding commands, so it must be explicitly in the source code.

There are a number of packages around for such conditional text, see https://ctan.org/topic/cond-comp for a list.

With a current LaTeX you can use the built-in +b argument of \NewDocumentEnvironment to grab the content. See the documentation of xparse for more infos.

\documentclass[12pt]{article}
\usepackage{etoolbox}
\usepackage{amsmath, amsthm}
\newbool{proofs}
\NewDocumentEnvironment{myproofs}{+b}
 {\ifbool{proofs}{\begin{proof}#1\end{proof}}{--proof left out--}}{}
\begin{document}

\begin{myproofs}
Here I put the proof that $1+1=2$.
\end{myproofs}

\booltrue{proofs}

\begin{myproofs}
Here I put the proof that $2+2=4$.
\end{myproofs}

\end{document}

enter image description here

Related Question