Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
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

2 Answers 2

up vote 6 down vote accepted

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}
share|improve this answer
    
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 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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.