3

I have a problem with the minted package in combination with etoolbox's iftoggle. It should be related (or basically be the same error) to this beamer question: minted environment in frame causes error but the there stated solution (using a fragile frame) cannot be applied in this way to a standard document.

The following MWE gives an error when \toggletrue{test}:

\documentclass{report}%
\usepackage{etoolbox}
\newtoggle{test}
\toggletrue{test}
\usepackage{minted}
\begin{document}
\iftoggle{test}{
    \begin{minted}
    test
    \end{minted}
}{}
test
\end{document}

The error is

(./mwe.aux)
(/usr/local/texlive/2016/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
)
! Missing \endcsname inserted.
<to be read again>
                   \def
l.15 }
      {}

How can I fix this problem?

3
  • 1
    \iftoggle{<toggle>}{<true>}{<false>} expects a <toggle>, yet you supply it with something else. That's the problem. What is it that you're really after?
    – Werner
    Nov 8, 2018 at 22:13
  • 1
    This will not work because the \iftoggle grabs the verbatim environment as argument, which will make it not work. Nov 8, 2018 at 22:15
  • @Werner: sorry that was a typo in the mwe, I fixed it.
    – asante
    Nov 9, 2018 at 9:18

1 Answer 1

5

You can't have a minted environment in the argument to another command.

For this special case, you can do

\iftoggle{test}{\iftrue}{\iffalse}
\begin{minted}
test
\end{minted}
\fi

Full example

\documentclass{report}
\usepackage{minted}
\usepackage{etoolbox}
\newtoggle{test}
\toggletrue{test}

\begin{document}
\iftoggle{test}{\iftrue}{\iffalse}
\begin{minted}{text}
test
\end{minted}
\fi

test

\togglefalse{test}
\iftoggle{test}{\iftrue}{\iffalse}
\begin{minted}{text}
test
\end{minted}
\fi

test

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .