# Creating new environment with ifthenelse

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.

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}


Instead of solving your problem, I suggest to you using the package multiaudience.

Suppose I am a teacher and I want to show the proofs only to me and not to my students.

I define two audiences, teachers and students:

\SetNewAudience{teachers}
\SetNewAudience{students}


and I say some parts of the document should be shown only to teachers:

\begin{shownto}{teachers}
...
\end{shownto}


If I set

\DefCurrentAudience{teachers}


this part will be shown.
If I set

\DefCurrentAudience{students}


it will not. You may set this parameter also outside the document itself, when you compile it, see the package documentation.

For example, this code:

\documentclass{article}
\usepackage{multiaudience}
\usepackage{amsmath, amsthm}
\SetNewAudience{teachers}
\SetNewAudience{students}
\begin{document}
\DefCurrentAudience{teachers}
Here I say that $1+1=2$.
\begin{shownto}{teachers}
\begin{proof}
Here I put the proof that $1+1=2$.
\end{proof}
\end{shownto}
\end{document}


produces this output:

Whereas this code:

\documentclass{article}
\usepackage{multiaudience}
\usepackage{amsmath, amsthm}
\SetNewAudience{teachers}
\SetNewAudience{students}
\begin{document}
\DefCurrentAudience{students}
Here I say that $1+1=2$.
\begin{shownto}{teachers}
\begin{proof}
Here I put the proof that $1+1=2$.
\end{proof}
\end{shownto}
\end{document}


produces this output:

As you can see, in the second case the proof is not shown.

• Thank you for the alternative approach! Oct 4, 2021 at 6:09
• @ShivashriganeshMahato You're welcome! Thank you for accepting my answer. Oct 4, 2021 at 6:15
• I am defining a new environment as indicated in my updated question, but I'm running into errors with matching begins and ends. Is this the correct way to use the package with proofs in creating a new environment? Oct 4, 2021 at 6:15
• @ShivashriganeshMahato See the other answers. Please accept one of them. Oct 4, 2021 at 9:00
• Thank you nonetheless, multiaudience is useful for future reference. Oct 4, 2021 at 13:49

With a recent LaTeX release you can use hooks.

\documentclass{article}
\usepackage{amsthm} % for proof environment
\usepackage{etoolbox}

\newtoggle{showproofs}
\newsavebox{\hideproof}

\iftoggle{showproofs}{}{\par\setbox\hideproofs=\vbox\bgroup}%
}
\iftoggle{showproofs}{}{\egroup}%
}

\begin{document}

This proof is not shown.

\begin{proof}
The proof is obvious.
\end{proof}

\toggletrue{showproofs}

This proof will be shown.

\begin{proof}
The proof is obvious.
\end{proof}

\end{document}


When the toggle is set to false, the proof is typeset, but the contents will be discarded.