Text Formattingbeamer, listings | Overlays with Code Listings

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
turok
Posts: 7
Joined: Wed Oct 17, 2012 2:26 pm

beamer, listings | Overlays with Code Listings

Post by turok »

I have a problem with the following code:

Code: Select all

\documentclass{beamer}
\usepackage{listings}
\begin{document}
\begin{frame}[fragile]
\color<2>[rgb]{1,0,0}{% works
\begin{lstlisting}
COLOR
\end{lstlisting}
}
\only<1>{% don't work
\begin{lstlisting}
ONLY
\end{lstlisting}
}
\end{frame}
\end{document}

Code: Select all

Package Listings Warning: Text dropped after begin of listing on input line 11.


)
! Missing } inserted.
<inserted text>
                }
l.17 \end{frame}

?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

beamer, listings | Overlays with Code Listings

Post by CrazyHorse »

turok wrote:I have a problem with the following code:

Code: Select all

\documentclass{beamer}
\usepackage{listings}
\begin{document}
\begin{frame}[fragile]
\color<2>[rgb]{1,0,0}{% works
\begin{lstlisting}
COLOR
\end{lstlisting}
}
\only<1>{% don't work
\begin{lstlisting}
ONLY
\end{lstlisting}
}
\end{frame}
\end{document}
define the environment before the frame:

Code: Select all

\documentclass{beamer}
\usepackage{listings}
\begin{document}
\defverbatim{\Lst}{%
\begin{lstlisting}
ONLY
\end{lstlisting}}

\begin{frame}[fragile]
\color<2>[rgb]{1,0,0}{% works
\begin{lstlisting}
COLOR
\end{lstlisting}
}
\only<1>{\Lst}% works

\end{frame}
\end{document}
Post Reply