3

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?

cgnieder
  • 66,645
Pr0gm4n
  • 31
  • 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

3 Answers3

2

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 '21 at 12:40
1

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}
luki
  • 1,796
  • 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
0

I know that this is a very old question, but as it has not been solved yet, maybe the solution I found for my problem could help those who will read at this question now as happened to me.

I had the same problem in hiding a section with minted content, based on a variable to set at the top of the document. I was able to solve the problem with a mix of \newif and the version package.

Here is my code:

\documentclass{article}

\usepackage{minted}

%-- Block for content hiding --------------------------- \newif\ifxml % define the if command to use to show/hide the content \usepackage{version} \newenvironment{xmlsection}{}{} % create the environment that will contain the document part to show/hide

\xmltrue % set \xmlfalse to hide the XML part

\ifxml \else \excludeversion{xmlsection} \fi % the ifelse clause to show/hide the section "xmlsection" %-- Block end -------------------------------------------

\date{} \title{My Title} \begin{document} \maketitle A sentence with \ifxml something to be shown only with xmltrue and \fi some text.

\begin{xmlsection} % the part of the document that will be shown/hidden
\section{Section with XML code}
Some text.\\

\begin{minted}[tabsize=2, fontsize=\footnotesize, breaklines, breakanywhere=false, autogobble, samepage]{XML}
    <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
    <channel>
        <!-- ... some XML tags -->
    </channel>
    </rss>
\end{minted}

\newpage
\end{xmlsection}

Other document sections\ldots

\end{document}

Hope this helps :)

Ma3x
  • 101