Hiding an environment that contains minted code

Task: I want to create a 'notes' command and an environment which can be hidden by a boolean flag.

Problem: These 'notes' can contain minted code blocks which mess up previous solutions found on the internet. Furthermore, we'd like to be able to enable / disable the flag locally.

Circumstances:

• we are creating a file containing multiple subfiles
• we'd like to be able to set the flag when building a subfile separately

Research:

Current solution: So far, I've come up with this bit which works well – except that I cannot overwrite the flag locally.

\ifthenelse{\boolean{shownotes}}{%
\newcommand{\notes}[1]{Notes: #1}%
\newenvironment{notesenv}{Notes:}{}
}{%
\newcommand{\notes}[1]{}
\usepackage{environ}
\NewEnviron{notesenv}{} % omitting the \BODY command creates a hidden environment
}


The flag cannot be overwritten locally as it needs to be set accordingly when making the definition. I guess I could copy the definition to every file, but is that really the only solution?

• Welcome to TeX.SE! Did you try \newif? – luki Mar 19 '20 at 10:25
• I did not before, but now that I do I get the same behaviour as previously. It properly hides normal text (like the ifthen package), but as soon as you plug in some code environment it all breaks. – Pr0gm4n Mar 19 '20 at 11:23

This solution does not work for your environment notesenv. But for the \notes macro, you could create a new conditional \ifincludenotes with \newif. Locally you can set it true or false.

\documentclass{standalone}

\newif\ifincludenotes
\includenotestrue

\newcommand{\notes}[1]{\ifincludenotes#1\fi}

\begin{document}

\notes{Note1}

{\includenotesfalse%
\notes{Note2}%
}

\notes{Note3}

\end{document}

• Thanks for your reply, but as stated above this does not resolve the standing problem that I want to hide code, i.e. verbatim environments generated with minted. – Pr0gm4n Mar 19 '20 at 13:33

As a workaround, you can use \inputminted with NewEnviron.

For example:

\RequirePackage{environ}
\NewEnviron{hidden}[0][]{\if@hidden\else\BODY\fi}

...

\begin{hidden}
\inputminted{c}{solution.c}
\end{hidden}

• I'm not sure this would actually work. Could you provide a full minimal document and a screenshot of the result to show that this solves the problem? – Marijn Feb 10 at 12:40