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?

1 Answer 1

22

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}
3
  • 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
    Commented Jun 7, 2012 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?? Commented Jun 7, 2012 at 16:03
  • 1
    @Forgiver no; escaping to LaTeX doen't work as expected when \uncover or \onslide are involved. Commented Jun 7, 2012 at 16:49

You must log in to answer this question.

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