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.

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?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

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}
share|improve this answer
    
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?? –  stalking is prohibited 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

 
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.