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?

Gonzalo Medina
  • 505,128
MCB
  • 509

1 Answers1

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}
Gonzalo Medina
  • 505,128