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.

Possible Duplicate:
\pause won't generate extra slides in a containsverbatim frame

I use lstlisting environments in my beamer frames, but I would also like to have blocks with showing/hidden options like <2>, <1-3>, etc. With the following code, only the first version of the frame is displayed (with only the first block). Is there a way to make the hidden/shown block options work when the [containsverbatim] option is active?

\begin{frame}[containsverbatim]

  \begin{block}{}
    \begin{lstlisting}
blah blah blah
    \end{lstlisting}
  \end{block}

  \begin{block}<2>{}
    \begin{lstlisting}
blah blah blah
    \end{lstlisting}
  \end{block}

\end{frame}
share|improve this question

migrated from stackoverflow.com Aug 28 '12 at 18:44

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Daniel, Tom Bombadil, Marco Daniel, percusse, cgnieder Aug 29 '12 at 16:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Please do not use containsverbatim: it is a historical overhang and is not in the documentation for a reason. The correct option is fragile. –  Joseph Wright Aug 28 '12 at 19:09
add comment

2 Answers

up vote 2 down vote accepted

Of course you can combine verbatim material and overlay specifications in your frames; only some precautions must be taken: to use verbatim material in a frame, you have to add the option [fragile] to the frame environment (with verbatim material, the \frame command will not do); the \end{frame} line must be alone on a single line:

\documentclass{beamer}
\usepackage{listings}

\begin{document}

\begin{frame}[fragile]
\begin{block}{}
\begin{lstlisting}
blah blah blah
\end{lstlisting}
\end{block}

\begin{block}<2>{}
\begin{lstlisting}
blah blah blah
\end{lstlisting}
\end{block}
\end{frame}

\end{document}
share|improve this answer
    
Thanks for the info about containsverbatim vs fragile. But how come I can't even indent \end{frame} when using fragile? I've always indented my LaTeX code (like any other code) and it would be hard for me to live without indentation... How can I do that? –  Eusebius Aug 29 '12 at 7:15
    
I'll choose this answer, but IMO the situation is bugged, if "fragile" works only if no space or tabulation is used on a given LaTeX line. –  Eusebius Sep 1 '12 at 7:09
add comment

You can combine lstlisting and beamer's uncover features. However you should not use containsverbatim. Instead there is an option to place the verbatim part before the \begin{frame} where it will not confuse the beamer features. You can find it in the documentation of the beamer class.

share|improve this answer
    
It would be great if you can make a minimal example using the OP's snippet to demonstrate how your answer works. –  percusse Aug 28 '12 at 18:56
add comment

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