Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to use beamer overlay inside minted code? The obvious solution does not work:

\documentclass{beamer}
\usepackage{minted}

\begin{document}

\begin{frame}[fragile]

\frametitle{Foo}

\begin{minted}{lua}
\uncover<1>{print("foo")}
\uncover<2>{print("bar")}
\uncover<3>{print("baz")}
\end{minted}

\end{frame}

\end{document}
share|improve this question

4 Answers 4

up vote 5 down vote accepted

Unfortunately, there is no obvious way to make this work due to the way minted works internally. In fact, it is vital that the code is not parsed by TeX in the usual way.

There might be some trickery possible to circumvent this but for now I suggest that the easiest way to approximate the desired behaviour is to use multiple sequential minted environments:

\uncover<1>{\begin{minted}{lua}
print("foo")
\end{minted}}
\uncover<2>{begin{minted}{lua}
print("bar")
\end{minted}}
\uncover<3>{\begin{minted}{lua}
print("baz")
\end{minted}}

Though to be honest I’m not certain if this even works.

share|improve this answer
1  
Wouldn't it be \uncover<x>{\begin{minted}...\end{minted}}? –  Aaron Aug 31 '11 at 6:11
    
@Aaron Damn, of course. Which makes the whole thing much more difficult. I hope the above works at all. –  Konrad Rudolph Aug 31 '11 at 7:03
    
It does not work for me. –  rgrig Oct 6 at 9:21

After some trial and error the following is the only solution that works for me:

\begin{frame}

\begin{overprint}
\onslide<1>
\begin{minted}{c++}
   ...
\end{minted}

\onslide<2>
\begin{minted}{c++}
   ...
\end{minted}
\end{overprint}

\end{frame}
share|improve this answer

I used something similar to what Konrad Rudolph suggested, I used \onslide<n> before the minted block (actually #+begin_src in emacs' orgmode). It does not require curly brackets around the block.

share|improve this answer

The following worked for me: (I'm using Pygments 1.5 which is pre-release at the moment.)

\begin{frame}[fragile]
  \frametitle{...}

  \begin{minted}{haskell}
    data C a = ...
  \end{minted}

  \begin{minted}{c++}
    template<typename T> class C {...};
  \end{minted}

  \begin{minted}{scala}
    class C[T] {...};
  \end{minted}
\end{frame}

The fragile keyword is in fact what does the trick for me. (Note its use after \begin{frame}.)

share|improve this answer
7  
Don't see any overlays in your code. –  Alexander Gladysh Dec 14 '11 at 5:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.