4

Given a frame that has code rendered in a \begin{lstlisting}...\end{lstlisting} environment, is it possible to use beamer's incremental frame building feature to highlight code snippets?

Here is an example of what I would like to use:

\begin{frame}[fragile]{Test}
\begin{lstlisting}
x = y \alert<2->{// Assigns the value of y to x.}
\end{lstlisting}
\end{frame}
mavam
  • 427
  • Yes, of course; two examples: http://tex.stackexchange.com/questions/8384/how-to-make-overlay-still-work-inside-lstlisting-environment and http://tex.stackexchange.com/questions/100537/two-code-blocks-working-syncronously/100548#100548 – Claudio Fiandrino Apr 24 '13 at 19:42

1 Answers1

5

You can do this although you don't get the listings formatting inside the alert, but perhaps that's OK for comments..

enter image description here

\documentclass{beamer}
\usepackage{listings}
\begin{document}

\begin{frame}[fragile]{Test}
\begin{lstlisting}[escapeinside=`']
x = z // Assigns the value of y to x.
x = y `\alert<2->{// Assigns the value of y to x.}'
\end{lstlisting}
\end{frame}

\end{document}
David Carlisle
  • 757,742