8

I've tried reading the excellent Beamer user guide, but failed to understand.

I understand the basic idea: there's a counter beamerpauses that is advanced by a + inside an overlay specification. You can for example write \item<+> and you'll get an item that only shows for the slide with the current value of beamerpauses. Also, beamerpauses gets increased by one.

So far so nice.

One can write \item<.>. This has the effect of turning on the item for the previous (-1) value of beamerpauses, and it does not increase the counter.

Great.

Now what happens here (edited so that it does something interesting:)

\only<.(2)-+(6)>{\alert<+->{foo}\alert<+->{bar}} \only<-.(2)>\alert<-+>{BAR}\alert<-+(1)>{FOO}}
      (1)          (2)            (3)                (4)                         (5)

is it equivalent to

 \only<3-7>{\alert<2->{foo}\alert<3->{bar}}\only<-6>\alert<-5>{BAR}\alert<-7>{FOO}}

?

In particular: When does the increment at (1) happen? Before both the arguments are processed or after? Do the increments at (2) and (3) affect the counter when (4) and (5) are evaluated?

How does the counter change in this case? what is its value at every point? How can I find out? I tried writing \thebeamerpauses but this counter does not seem to change with the slides. Is there a counter that holds the slide number?

4
  • even \alt<-+>{foo}{bar} doesn't behave as expected. Is this a typo?
    – Seamus
    Commented Dec 2, 2010 at 11:14
  • It's not clear what the code above is expected to do. Could you add the same example with explicit slide specifications, so we see what it is you expected...
    – Seamus
    Commented Dec 2, 2010 at 11:17
  • I edited the code, making it a little more interesting...I think. Commented Dec 2, 2010 at 14:39
  • I would like to close this question and open a new one which would be more focused....is that a reasonable thing to do? Commented Dec 3, 2010 at 10:41

2 Answers 2

9

The rules for the incremental overlay specification are given as:

  1. \beamerpauses is initially set to 1
  2. If + is encountered in an overlay specification, all occurrences of + are replaced by \beamerpauses, then \beamerpauses is incremented
  3. If . is encountered in an overlay specification, all occurrences of . are replaced by \beamerpauses-1; \beamerpauses is not changed

It might be easier to understand if you pretend this, which as far as I can see is equivalent:

  1. \beamerpauses is initially set to 0
  2. If + is encountered in an overlay specification, \beamerpauses is incremented and all occurrences of + are replaced by \beamerpauses
  3. If . is encountered in an overlay specification, all occurrences of . are replaced by \beamerpauses; \beamerpauses is not changed

If you assume as well that \alt is smart and gobbles the inactive argument rather than expands it, you would guess that

\alt<-+>{\alert<+>{foo}\alert<+>{bar}}{\alert<.>{bar}\alert<.>{foo}}

is the same as

\alt<-1>{\alert<+>{foo}\alert<+>{bar}}{\alert<.>{bar}\alert<.>{foo}}

On slide 1, the first argument \alert<+>{foo}\alert<+>{bar} is expanded, resulting in

\alert<2>{foo}\alert<2>{bar}

After slide 1, the second argument \alert<.>{bar}\alert<.>{foo} is instead expanded, resulting in

\alert<1>{bar}\alert<1>{foo}

So in total the combination is equivalent to

\alt<-1>{\alert<2>{foo}\alert<2>{bar}}{\alert<1>{bar}\alert<1>{foo}}

Put these in the same frame and you'll see they do the same thing.

The - indicates an interval, so <2-4> means "on slides 2 through 4." Without explicit endpoints the first and last slide are substituted. So the first <-+> specification is equivalent to <1-1>, which in turn is equivalent to <1>.

Slide by slide we get:

  1. the \alt expands \alert<2>{foo}\alert<2>{bar}, which since \beamerpauses is 1 is the same as {foo}{bar}

  2. the \alt expands \alert<1>{bar}\alert<1>{foo}, which since \beamerpauses is 2 is the same as {bar}{foo}.

Advanced incremental-overlay-specification-fu involves offsetting \beamerpauses with numbers in parentheses such as \alert<.(2)->{foo}\alert<+->{bar}, which will alert first bar then both foo and bar. This is how you can have parts of a frame (for instance, parts of tikzpictures) change dynamically without having them all in the same order as they are typeset on the frame or hard-coding their slide numbers.

Edit Yossi asked if \alt really is "smart". If you look in the source code for beamerbaseoverlay.sty you find:

%
% \alt and \altenv
%
\def\alt{\@ifnextchar<{\beamer@alt}{\beamer@alttwo}}
\long\def\beamer@alttwo#1#2{\beamer@ifnextcharospec{\beamer@altget{#1}{#2}}{#1}}
\long\def\beamer@altget#1#2<#3>{%
  \def\beamer@doifnotinframe{#2}\def\beamer@doifinframe{#1}%
  {\beamer@masterdecode{#3}}\beamer@donow}
\long\def\beamer@alt<#1>#2#3{%
  \def\beamer@doifnotinframe{#3}\def\beamer@doifinframe{#2}%
  {\beamer@masterdecode{#1}}\beamer@donow}

To me it looks the like the effect of \alt<#1>{#2}{#3} is that #2 and #3 are saved in macros which are expanded depending on whether #1 applies to the current frame. I don't understand expansion completely but I believe that when \def is scanning for parameter text it doesn't expand that text until the point of replacement (as opposed to \edef, which expands the parameter text before assigning it to #n). So yes, \alt is "smart" in the sense that conditionally included text is not expanded until it's included. I guess you could do a \tracingall to know for sure.

dangerous bend Late Edit

Couldn't help but paste in this frame I'm working on right now.

\begin{frame}[label=integral-of-x]{Example: Integral of $x$}
\begin{example}<+->
Find $\int_0^3 x\,dx$
\end{example}
\begin{solution}<+->
\action<.->{For any $n$ we have $\alert<.(5)>{\Delta x = \frac{3}{n}}$ and for each $i$ between $0$ and $n$, $\alert<.(4)>{x_i = \frac{3i}{n}}$.}
\action<+->{For each $i$, take $x_i$ to represent the function on the $i$th interval.}
\action<+->{So}
\begin{align*}
    \action<.->{\int_0^3 x\,dx = \lim_{n\to\infty} R_n }
        \action<+->{&= \lim_{n\to\infty} \sum_{i=1}^n \alert<.(1)>{f(x_i)}\,\alert<.(2)>{\Delta x}}
        \action<+->{ = \lim_{n\to\infty}\sum_{i=1}^n 
            \alert<.>{\left(\frac{\alert<.(2)>{3}i}{\alert<.(2)>{n}}\right)}
            \alert<+>{\left(\frac{\alert<.(1)>{3}}{\alert<.(1)>{n}}\right) }\\}
        \action<+->{&= \lim_{n\to\infty}\alert<.>{\frac{9}{n^2}} \alert<.(1)>{\sum_{i=1}^n i}}
        \action<+->{ = \alert<.(1)>{\lim_{n\to\infty}}\frac{9}{\alert<.(1)>{n^2}} 
            \cdot \alert<.>{\frac{\alert<.(1)>{n(n+1)}}{2}}}
        \action<+->{= \frac{9}{2}\alert<.>{\cdot 1}}
\end{align*}
\end{solution}
\end{frame}

sample code output

7
  • The final example alerts first bar then both. An extra "-" slipped in there maybe?
    – Seamus
    Commented Dec 2, 2010 at 13:31
  • @Seamus: that's what I meant. When I said "then foo" I didn't add "and no longer bar". But I'll edit it to be more clear. Commented Dec 2, 2010 at 13:42
  • Your comment about \alt being smart, is at the heart of what I am asking...it is smart? does it gobble up the inactive term? what is the value of the counter after the alt is done? which terms incremented it? Commented Dec 2, 2010 at 15:00
  • @Yossi: see edit. (1,2) yes (3) 3 on slide 1 and 2 on slide 2 (4) any + that's encountered for the first time between angle brackets. Commented Dec 2, 2010 at 15:34
  • 1
    @Dr.ManuelKuehner seven years later I finally know how to quickly convert a PDF file to an animated GIF. So yes, see my edit. Commented Jun 20, 2017 at 20:05
0

From the following simple example, it looks like the \alert inside the \alt is deciding what the second slide should be, and this overwrites whatever the second argument in \alt thinks it should be.

\alt<+->{%
  \alert<+>{foo} bar%
}
{barfoo}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .