Using overlays for source code listings in LaTeX Beamer
The standard way of including source code listings in Beamer is to use the semiverbatim
environment. Needless to say, it does not provide all the syntax highlighting and line-numbering love of the listings
package. Combine the two and you have something pretty as well as extremely helpful in delivering presentations which have code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | \documentclass{beamer} \setbeamercovered{transparent} \usepackage{pxfonts} \usepackage{listings} \begin{document} \lstset{language=python, numbers=left, numberstyle=\tiny, showstringspaces=false, aboveskip=-40pt, frame=leftline } \begin{frame}[fragile] \frametitle{\texttt{parrot.py}} \begin{semiverbatim} \pause \begin{lstlisting} if __name__ == "__main": \end{lstlisting} \pause \begin{lstlisting}[firstnumber=last] print "Oh yes, the, uh, the Norwegian Blue..." print "What's, uh... What's wrong with it? " \end{lstlisting} \pause \begin{lstlisting}[firstnumber=last] print "I'll tell you what's wrong with it, my lad." print "'E's dead, that's what's wrong with it!" \end{lstlisting} \end{semiverbatim} \end{frame} \end{document} |