8

It seems that the following code does not work as expected (ie. printing the \end{frame} as a verbatim colored code. Instead, the \end{frame} is interpreted by LaTeX:

\documentclass[10pt,a4paper]{beamer}
\usepackage{minted}
\begin{document}
\begin{frame}[fragile]{Test}
\begin{minted}{latex}
\begin{frame}{Title exemple}
This is an exemple.
\end{frame}
\end{minted}
This is never shown !
\end{frame}
\end{document}

There is a bunch of errors at compilation time :

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

What should be done for this sample to compile nicely ?

1
  • Welcome to TeX.SX. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}) or hit Ctrl+K. Jan 14, 2014 at 11:58

3 Answers 3

14

This is due to the way that beamer's fragile option works--it breaks with both minted and verbments (and anything similar). The fragile option causes the contents of the frame to be written to a temp file, so that beamer can deal with verbatim content. The problem is that beamer assumes that the current frame has ended as soon as it encounters a line beginning with \end{frame}. It doesn't have a way to detect that the \end{frame} is actually inside a minted environment, and thus isn't to be taken literally. Because of thise, both minted and verbments will fail with the example given.

There are a few ways to work around this.

  • The simplest is to use fragile=singleslide. This disables overlays, allowing beamer to avoid the use of temp files and the associated issues.
  • Another solution is the approach in the answer provided by Jubobs: just indent the environment (whether it's minted or pyglist). Since the \end{frame} in the minted environment is now preceded by space characters, beamer will no longer interpret it as the end of the frame. Unfortunately, if you take this approach, your code will be indented by one or more spaces, which may not be desirable. You could use minted's gobble option to work around this. For example, if you indent by 4 spaces, then gobble=4. You could also use the autogobble option that automatically strips off leading space characters.
2
  • The first way works for me.
    – kalakay
    May 20, 2020 at 15:30
  • Same here, using fragile=singleslide works well, adding space does not. I suspect that something within package minted has changed since the answer.
    – BanDoP
    Oct 9, 2022 at 14:06
2

An alternative solution (credits to Thomas F. Sturm) with tcolorbox commands tcboutputlisting and tcbinputlisting.

\documentclass{beamer}
\usepackage[minted]{tcolorbox}

\begin{document}

\begin{tcboutputlisting}
\begin{frame}{equation}
$a =  b$
\end{frame}
\end{tcboutputlisting}

\begin{frame}[fragile]{Example}
\tcbinputlisting{listing only}
\end{frame}

\end{document}

enter image description here

1

The method with the indentation did not work for me, and I wanted to use multiple slides. So, another possible solution is to use the escapeinside option of minted to trick Beamer into not detecting \end{frame}. The advantage is that you do not have to use fragile=singleslide.

\begin{frame}[fragile]{How to make a Beamer slide}
  \begin{minted}[escapeinside=||]{latex}
\begin{frame}{Title}{Subtitle}
  Body
\end{frame||}
  \end{minted}
\end{frame}

You can use \end{frame||} to end your snippet: this will escape to LaTeX but do nothing.

enter image description here

You must log in to answer this question.

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