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.

In latex beamer I want to do the following:

  1. repeat a frame (from some slides before)
  2. repeat it again, but make some words grey (or better opaqueness 50%) others red
  3. repeat it again but without the grey words from the previous slide

Is there an elegant way to this except of a copy and paste solution?

share|improve this question

3 Answers 3

up vote 13 down vote accepted

beamer redefines virtually every environment (and many macros) from the standard document classes to accommodate its use of overlay specification. As such, what you are after forms part of the basic functionality of beamer. You could use a mixture of standard overlay specifications (associated with existing commands, like \item from the enumerate or itemize environments) or by using commands like \only, \uncover, \visible or \onslide. The following minimal example, taken from the documentation with slight modifications, tries to highlight this. The code for a single frame produces 3 slides, depending on the overlay specification:

\documentclass{beamer}% http://ctan.org/pkg/beamer
\usetheme{warsaw}%
\setbeamercovered{transparent}% Allow for shaded (transparent) covered items
\begin{document}
\begin{frame}
  \frametitle{There Is No Largest Prime Number}
  \framesubtitle{The proof uses \textit{reductio ad absurdum}.}
  \begin{theorem}
    There is no largest prime number.
  \end{theorem}
  \begin{proof}
    \begin{enumerate}
      \item<1-| alert@1> Suppose $p$ were the largest prime number.
      \item<2-> Let $q$ be the \alt<3>{\alert{product}}{product} of the \uncover<3->{first} $p$ numbers.
      \item<3-> Then $q+1$ is not divisible by any of them.
      \item<1-> But $q + 1$ is \visible<2->{greater than} $1$, thus divisible by some prime
        number not in the first $p$ numbers.\qedhere
    \end{enumerate}
  \end{proof}
\end{frame}
\end{document}

Beamer overlay specification example

For more information, read the beamer documentation. On a side note - see how the overlay specification is nested with the transparency of the first \item. The word first is set to some transparent opacity twice. As it uncovers, the transparency is lost in a stepwise fashion.

In your specific case, it sounds like the frame you want to reuse is somewhere at the start of your presentation. Although \againframe seems pertinent, it could be that you duplicate the previous frame code but this time add some overlay specification.

One possible alternative to duplicating code of an existing frame (for ease of changes to the source frame being changed automatically) is to use a combination of \againframe and some macros. Here's a (very) minimal example:

\documentclass{beamer}% http://ctan.org/pkg/beamer
% Original macro \mymacro essentially does nothing
\newcommand{\mymacro}[1]{#1}% \mymacro{..}
\begin{document}
\begin{frame}[label=example]% This is frame 'example'
  Here is some \mymacro{content}.
\end{frame}

% Redefining \mymacro to change its argument into an \alert{..}
\renewcommand{\mymacro}[1]{\alert{#1}}%
\againframe{example}% Re-use frame 'example'
\end{document}

Using \againframe

However, LaTeX complains about multiply-defined labels since you're using \againframe.

share|improve this answer
    
Thanks. Yes as you pointed out, the frame I want to reuse is somewhere at the start of my presentation. But I don't want to copy the code (because then I have to make changes twice and I want a solution which applies also for similar cases in the future). \againframe however don't let me modify things, doesn't it? –  student Oct 9 '11 at 17:09
    
@user4011: The only way you can have access to the original frame content is if you use @cmhughes' answer and define macros that you redefine, or if you copy some part of the previous code. \againframe doesn't allow modification of code, nor would capturing the entire frame content in (say) \BODY when using the environ package. I'll edit my answer to highlight this to some degree. –  Werner Oct 9 '11 at 17:26
    
@Werner: \againframe sort of let's you modify things. Take a look at my answer. –  Loop Space Nov 29 '11 at 10:19

\againframe is your friend here. Both the frame environment and \againframe are themselves overlay-aware. This means that you can supply an overlay specification to both which says "Only show the frames matching this specification even if there's code for more". So if you have a very complicated frame but put \begin{frame}<1>[label=repeated] at the start then only the first slide is shown irrespective of all the other information. But all that information is kept, so you can later on say \againframe<2-3>{repeated} to get the next bit.

I recommend making sure that the overlay specifications don't overlap, which can mean a bit of juggling with the numbers if you want something actually repeated as it is. Then you have to ensure that, say, slide 2 is an exact copy of slide 1.

Here's an example:

\documentclass{beamer}% http://ctan.org/pkg/beamer
%\url{http://tex.stackexchange.com/q/31031/86}
\begin{document}
\begin{frame}<1>[label=again]
  \frametitle{The Infamous Disappearing Text}

Here is a frame, it's a bit \alert<2-3>{boring}.

It's so boring, we'll see it \only<-3>{{\color<2-3>{gray}twice}}.

\only<3>{But the second time, we'll try to make it more interesting by making some of those words change colour.}

\only<5>{The third time, we'll wave a magic wand to make all the gray words disappear.}

\end{frame}

\begin{frame}
\frametitle{Some Comments}
This frame is perhaps even more so.
\end{frame}

\againframe<2-3>{again}

\begin{frame}
\frametitle{Some Comments}
Will this tedium ever end?
\end{frame}

\againframe<4-5>{again}

\end{document}

(I shan't post the screenshots. They're every bit as tedious as the text suggests.)

I used this in a seminar that I gave a year or so back. You can see the PDFs here (sorry, the source isn't available there). The slides to look at are 59-61, 75-76, 81-82, 87-88, 95-97 of the beamer version. These are all a single frame, but shown at different stages. It won't compile, but the code for that actual frame is:

\begin{frame}<1-3 |trans: 1|handout: 1>[label=definition]
\frametitle{\only<1-4|trans: 1|handout: 1>{First}\only<5-6|trans: 2| handout: 2>{Second}\only<7-8|trans: 3|handout: 3>{Third}\only<9-10| trans: 4|handout: 4>{Fourth}\only<11-12|trans: 5-6|handout: 5-6>{Fifth} Candidate\visible<12|trans: 6|handout: 6>{: Fr\"olicher Space}}

\begin{definition}[{\only<1-4|trans: 1|handout: 1>{First}\only<5-6|trans: 2|handout: 2>{Second}\only<7-8|trans: 3|handout: 3|handout: 3>{Third}\only<9-10|trans: 4|handout: 4|handout: 4>{Fourth}\only<11|trans: 5|handout: 5>{Fifth}\only<1-11|trans: 1-5|handout: 1-5|handout: 1-5>{ Attempt}\only<12|trans: 6|handout: 6>{Fr\"olicher Space}}]
A \alert{\alt<1-11|trans: 1-5|handout: 1-5| handout: 1-5>{smooth}{Fr\"olicher} space} is a triple \((X,\m{\alt<1-11|trans: 1-5|handout: 1-5| handout: 1-5>{I}{C}},\m{\alt<1-11|trans: 1-5| handout: 1-5>{O}{F}})\) where:
%
\begin{itemize}
\item \(X\) is a \alt<1-10|trans: 1-4|handout: 1-4>{\alert<1-3>{topological space}}{\alert<11>{set}}
\item \(\m{\alt<1-11|trans: 1-5|handout: 1-5>{I}{C}}\only<1-8|trans: 1-3| handout: 1-3>{(U)} \subseteq \Hom{\alt<1-10|trans: 1-4|handout: 1-4>{\TopCat}{\Set}}{\alt<1-8|trans: 1-3|handout: 1-3>{U}{\R}}{X}\),\only<1-8|trans: 1-3|handout: 1-3>{ \(U \subseteq \R^m\) open,}
\item \(\m{\alt<1-11|trans: 1-5|handout: 1-5>{O}{F}}\only<1-10|trans: 1-4| handout: 1-4>{(V\only<1-8|trans: 1-3|handout: 1-3>{;\R^m})} \subseteq \Hom{\alt<1-10|trans: 1-4|handout: 1-4>{\TopCat}{\Set}}{\alt<1-10|trans: 1-4|handout: 1-4>{V}{X}}{\alt<1-8|trans: 1-3|handout: 1-3>{\R^m}{\R}}\)\only<1-10|trans: 1-4|handout: 1-4>{, \(V \subseteq X\) open}.
\end{itemize}

\only<1-4|trans: 1|handout: 1>{\medskip}
\pause[2]

\only<5-11|trans: 2-5|handout: 2-5>{
such that

\begin{itemize}
\item \(\m{I}\) and \(\m{O}\) are \alert<5>{compatible},
\item \(\alt<5-6|trans: 2|handout: 2>{\overline{\m{I}}}{\m{I}}\) and \(\alt<5-6|trans: 2|handout: 2>{\overline{\m{O}}}{\m{O}}\) are  \only<5-6|trans: 2|handout: 2>{\alert<5>{also compatible}}\only<7-|trans: 3-| handout: 3->{\alert<7>{saturated}: \(\m{I} = \overline{\m{I}}\), \(\m{O} = \overline{\m{O}}\)}.
\end{itemize}
}
\only<12|trans: 6|handout: 6>{
such that

\begin{itemize}
\item \(\m{C} = \{\psi \colon \R \to X : \phi\psi \in \Ci(\R,\R), \phi \in \m{F}\}\)
\item \(\m{F} = \{\phi \colon X \to \R : \phi\psi \in \Ci(\R,\R), \psi \in \m{C}\}\)
\end{itemize}
}

A \alert{morphism} is a \only<1-10|trans: 1-4|handout: 1-4>{continuous }map \(f \colon X \to Y\) such
that
%
\[
  \phi f \psi \alt<1-2|trans: 1|handout: 1>{\text{ is }}{\in} \Ci \text{ for } \psi \in \m{\alt<1-11|trans: 1-5|handout: 1-5>{I}{C}}\only<1-2|trans:1|handout: 1>{(U)}, \phi \in \m{\alt<1-11|trans:1-5|handout: 1-5>{O}{F}}\only<1-2|trans: 1|handout: 1>{(V;\R^m)}
\]
\end{definition}

\only<3|trans: 1|handout: 1>{
Notation:
\begin{itemize}
\item smooth map = morphism
\item \(\psi \in \m{I}\), \(\phi \in \m{O}\), \(\theta \in \Ci\)
\end{itemize}
}
\end{frame}

and the reinvocations are things like:

\againframe<6-7|trans: 3|handout: 3>{definition}

(looking at it, then it might compile in a normal beamer document if you add \newcommand\m[1]{\mathcal{#1}} and \newcommand{\Ci}{C^\infty} in your preamble. There might be things I've missed, though.)

share|improve this answer
    
Dead useful, I was looking for a way to insert a small digression into a slide, and this looks like the way to go. –  Vincent Fourmond Apr 30 '13 at 7:13

You could use something like this:

\documentclass{beamer}

\usepackage{xcolor}

\begin{document}

\def\mytext#1{Here {\color{#1}is some} text} 
\begin{frame}
 \mytext{black}
\end{frame}
\begin{frame}
 \mytext{red}
\end{frame}
\begin{frame}
 \mytext{black}
\end{frame}

\end{document}

If you wanted to, you could even use

\def\mytext#1{\begin{frame}Here {\color{#1}is some} text\end{frame}} 

and then you wouldn't have to \begin{frame}...\end{frame}, simply

\mytext{blue}
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.