I am trying to highlight code lines in the listings package for a presentation. The following working example shows how I have been able to hack my way to a solution, however I am now at the point where I need some advice.
Let me draw your attention to the image at the end of this question. It shows how one frame changes. I want you to notice how only "vector" is uncovered while I walk through explaining different lines of the code. The layout is as follows:
_______________
* vector | |
* matrix | Code examples |
* list |_______________|
The problem is that I am not able to change the example code when I want to continue the presentation talking about matrices, i.e. I want to uncover a new code block.
Question: Can I ´\uncover´ listings code blocks?
The following code shows a minimal working example:
\documentclass[14pt]{beamer}
%
% author: Sigve Karolius
% summary: Minimal example of listings code highlighting
% typeset: pdflatex <filename>.tex
\usetheme[secheader]{Boadilla}
\usepackage{listings}
\lstnewenvironment{beamerR}{%
\lstset{%
language=R,%
identifierstyle=\color{blue}\scriptsize\ttfamily,%
keywordstyle=\scriptsize\ttfamily,%
commentstyle=\scriptsize\ttfamily,%
numberstyle=\tiny\ttfamily,%
stringstyle=\scriptsize\ttfamily,%
basicstyle=\scriptsize\ttfamily,%
emphstyle=\scriptsize\bfseries\ttfamily,%
moredelim=**[is][\only<+>{\lstset{style=highlight}}]{@}{@},%
escapechar={|},%
}%
}{%
}
\newcommand{\GreenHilight}[1]{% color listings line, necessary strategy for practical reasons.
\makebox[0pt][l]{\color{green!30!white}\rule[-0.316em]{#1}{1.06em}}%Color - |***-------------|
\makebox[0pt][r]{\color{green!30!white}\rule[-0.316em]{0.876em}{1.06em}}% |---*************|
}
\begin{document}
% ------------------------------------------------------------------------------
%%
%%%
%%
% ------------------------------------------------------------------------------
\begin{frame}[fragile]{Datastructures}
%
\begin{columns}
%
\begin{column}{0.28\textwidth}
\setbeamercovered{transparent}
\begin{itemize}
\item<1-7> vector
\item<8-8> matrix
\item<9-9> array
\item<10-10> data frame
\item<11-11> list
\end{itemize}
\end{column}
\begin{column}{0.68\textwidth}
\begin{beamerR}
|\uncover<1-2>{\GreenHilight{\linewidth}}|> c(1,2,3,4); 1:4
|\uncover<2-2>{\GreenHilight{\linewidth}}|[1] 1 2 3 4
|\uncover<3-7>{\GreenHilight{\linewidth}}|> lst <- rnorm(1000,mean=0,sd=1)
|\uncover<4-5>{\GreenHilight{\linewidth}}|> lst[-c( (1:990), (992:1000) )]
|\uncover<5-5>{\GreenHilight{\linewidth}}|[1] -0.2585032
|\uncover<6-6>{\GreenHilight{\linewidth}}|> summary( lst )
|\uncover<7-7>{\GreenHilight{\linewidth}}| Min. 1st Qu. Median
|\uncover<7-7>{\GreenHilight{\linewidth}}|-3.878000 -0.694100 -0.002885
|\uncover<7-7>{\GreenHilight{\linewidth}}| Mean 3rd Qu. Max.
|\uncover<7-7>{\GreenHilight{\linewidth}}|-0.013390 0.672200 2.919000
\end{beamerR}
\end{column}
%
\end{columns}
\end{frame}
%
\end{document}