13

I am preparing a beamer presentation and using the lstlisting environment in order to put in code. However, I would like to use the \pause command within lstlisting. By definition that is not possible. I am numbering the lines so it is bad if I just end and begin the environment again in order to insert \pause. Any tips?

18

You can escape to LaTeX (Section 4.14 Escaping to LaTeX of the listings documentation) and use \pause:

\documentclass{beamer}
\usepackage{listings}
\usepackage{bera}

\lstset{basicstyle=\small\ttfamily,
numbers=left,
escapeinside=||
}
\begin{document}

\begin{frame}[fragile]
\begin{lstlisting}
line1 |\pause|
line2 |\pause|
line3
\end{lstlisting}
\end{frame}

\end{document}
  • Oh, I have to admit that I didn't look into the documentation. Mia culpa! Newbie mistake. Thank you any way, Gonzalo. You are bailing me out here (also on the other question, thanks!) – MCB Jun 7 '12 at 14:53
  • Can we use your answer for \uncover as what had been discussed in How to make overlay still work inside lstlisting environment?? – kiss my armpit Jun 7 '12 at 16:03
  • 1
    @Forgiver no; escaping to LaTeX doen't work as expected when \uncover or \onslide are involved. – Gonzalo Medina Jun 7 '12 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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