Another weird LaTeX problem. I have a piece of code on my slide and the result it gives. I want to change the code slightly and visualize the change in the result. Normally in LaTeX beamer slides, I would use overlays like this:
Query: \begin{verbatim} some code \alt<2>{slightly changed code on slide 2}{original code on slide 1} some more code \end{verbatim} Result: this item is the same in both \visible<1>{this one is only there for the original code} \visible<2>{this one is only there for the changed code}
So far, so good. The code is in a verbatim environment, so I have cannot put the overlay around the line I want to change, but that’s fine, let’s make it an alternative around the whole verbatim
part. But, unfortunately, the problem is that you cannot put a verbatim
environment inside of overlays (learn why). So you have to hack it. This is the code I want, the line with FILTER
is the one I only want to have on the second slide:
\begin{verbatim} SELECT ?book ?author ?releasedate WHERE { ?book dbo:author ?author . { ?book dbp:releaseDate ?releasedate . } UNION { ?book dbp:pubDate ?releasedate . } FILTER (?releasedate > 1950) } \end{verbatim}
Like in my post on using verbatim inside of verbatim, I have to end the verbatim environment prematurely, skip back over the space and then I can include the overlay inside of verb
.
\begin{verbatim} SELECT ?book ?author ?releasedate WHERE { ?book dbo:author ?author . { ?book dbp:releaseDate ?releasedate . } UNION { ?book dbp:pubDate ?releasedate . } \end{verbatim} \vspace{-0.5\baselineskip} \verb| |\visible<2>{\texttt{FILTER (?releasedate > 1950 )}}\\ \verb|}| \\
Not the most elegant way, but it works…