7

I realise similar questions have been asked before, but no solution worked for me so far.


Consider this document:

\documentclass{beamer}

\usepackage{minted}

\begin{document}

\begin{frame}[fragile]
\only<2>{
\begin{minted}{agda}
test
\end{minted}
}
\end{frame}

\end{document}

It gives the following error:

! FancyVerb Error:
  Extraneous input ` test \end {minted} ' between \begin{minted}[<key=value>] a
nd line end
.
\FV@Error ... {FancyVerb Error:
\space \space #1
}

l.5 }

This input will be discarded. Hit <return> to continue.

)
Runaway argument?
! File ended while scanning use of \FancyVerbGetLine.
<inserted text> 
                \par 
l.13 \end{frame}

I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.

! FancyVerb Error:
  Couldn't find `\end{minted}' to end a verbatim environment on input line 5.
.
\FV@Error ... {FancyVerb Error:
\space \space #1
}

l.13 \end{frame}

Probably you mistyped the environment name or included an extraneous 
space, or are using an improperly defined verbatim environment. 
Hit return and I will try to terminate this job.


[...]

Things are pretty mixed up, but I think the worst is over.

(That last line was beautiful, I needed to include it.)

What's the matter? How do I fix it? Note that \mintinline works fine.

Turion
  • 4,622

1 Answers1

17

The problem with using \only{...} is, that you cannot have such fragile content as argument for a macro (see e.g. https://tex.stackexchange.com/a/30006/36296 for more explanation).

Luckily you can use the onlyenv environment instead:

\documentclass{beamer}

\usepackage{minted}

\begin{document}

\begin{frame}[fragile]
\begin{onlyenv}<2>
\begin{minted}{agda}
test
\end{minted}
\end{onlyenv}
\end{frame}

\end{document}