# verbatim and overlays

I am trying to display a verbatim environment in an overlay. I have the following code but it is giving errors:

\only<2->{
\begin{verbatim}
Select T3.Subject
From  T as T1, T as T2, T as T3
Where T1.Predict=“BornOnDate” and
T1.Object=“1809-02-12” and
T2.Predict=“DiedOnDate” and
T2.Object=“1865-04-15” and
T3. Predict=“hasName” and
T1.Subject = T2.Subject and
T2. Subject= T3.subject
\end{verbatim}
}


Could anyone point what I am doing wrong?

-
Which table do you mean? To use overlay specification in beamer you need the semiverbatim environment. –  Marco Daniel Oct 23 '11 at 18:56
You are talking about a tabular, but your code shows verbatim. What is it now? –  Martin Scharrer Oct 23 '11 at 19:23

Verbatim material isn't allowed in macro argument, because the full argument is read before verbatim is processed. By then all text is already converted internally, i.e. all \abcd are already macros, all %text is already stripped etc.

Because frame is actually a pseudo-environment which reads its content like a macro you need to use its fragile option to take special care for verbatim and similar content. However, you are still not allowed to use it inside a macro's argument. I would store it in a box register and use that inside \only. For some reason this doesn't work with the verbatim environment but well with lstlisting from the listing package. You can and should also box the material outside of a frame, then you don't need the fragile option.

\documentclass{beamer}
\newsavebox{\mysavebox}
\usepackage{listings}

\begin{document}

\begin{lrbox}{\mysavebox}
\begin{lstlisting}
Select T3.Subject
From  T as T1, T as T2, T as T3
Where T1.Predict="BornOnDate" and
T1.Object="1809-02-12" and
T2.Predict="DiedOnDate" and
T2.Object="1865-04-15" and
T3. Predict="hasName" and
T1.Subject = T2.Subject and
T2. Subject= T3.subject
\end{lstlisting}
\end{lrbox}

\begin{frame}{Some title}
\only<2->{\usebox{\mysavebox}}
\end{frame}

\end{document}

-
Thank you very much. –  ozsu Oct 23 '11 at 19:23
Just to note that this also seems to center the listing (which is good considering all the issues with centering them). –  Alexey B. Jul 18 '14 at 1:17

verbatim is only possible with the macro \defverbatim. However, instead of verbatim you should use the package listings. Can be done in the same way. If you need it colored then use \defverbatim[colored]{...}

\documentclass{beamer}
\begin{document}

\defverbatim{\foo}{%
\begin{verbatim}
Select T3.Subject
From  T as T1, T as T2, T as T3
Where T1.Predict=“BornOnDate” and
T1.Object=“1809-02-12” and
T2.Predict=“DiedOnDate” and
T2.Object=“1865-04-15” and
T3. Predict=“hasName” and
T1.Subject = T2.Subject and
T2. Subject= T3.subject
\end{verbatim}
}

\begin{frame}{Some title}
\only<2->{\foo}
\end{frame}
\end{document}

-