5

I would like to define a command \mycover that is dual to Beamer's \uncover. In beamerbaseoverlay.sty the \uncover command is defined as

\newcommand{\uncover}{\alt{\beamer@fakeinvisible}{\beamer@makecovered}}

Therefore, my first attempt at \mycover simply switches the \alt branches:

\newcommand{\mycover}{\alt{\beamer@makecovered}{\beamer@fakeinvisible}}

Unfortunately, the first slide in \mycover's overlay specification is always shown as completely invisible, even if I \setbeamercovered{transparent}. Here is an example:

\documentclass{beamer}

\makeatletter
\newcommand{\mycover}{\alt{\beamer@makecovered}{\beamer@fakeinvisible}}
\def\c@slideinframe{\beamer@slideinframe}
\makeatother

\setbeamercovered{transparent}

\begin{document}
\begin{frame}{}
  \structure{Slide \arabic{slideinframe}}

  \uncover<1,4>{Testing} \mycover<2-3>{my cover} \uncover<1,4>{command.}
\end{frame}
\end{document}

The words "my cover" should be covered on exactly the same slides as the words "Testing" and "command", namely slides 2 and 3. What actually happens, however, is that "my cover" is completely invisible on slide 2 and is properly covered on slide 3.

enter image description here

What is the problem with \mycover and how can I fix it?

  • What is wrong with \uncover for the complement? That is presumably why beamer doesn't have a \cover in the first place... – vonbrand Apr 13 '14 at 21:41
  • 2
    @vonbrand It's a good suggestion, but for complex overlays I found it conceptually cumbersome to have to complement the overlay specification each time I want to "\cover". (Also, Beamer does include both \visible and \invisible, one of which is "redundant".) – Henry DeYoung Apr 13 '14 at 21:50
  • @GonzaloMedina I just cropped it manually in GIMP (select, then crop to selection) and built the gif from that. I'm not sure what would be the easiest way to automate that. – Henry DeYoung Apr 14 '14 at 17:15

1 Answers1

3

The following definition seems to produce the desired result:

\documentclass{beamer}

\makeatletter
\def\beamer@startmycovered{%
  \def\opaqueness<##1>##2{%
    \only<##1>{%
      \beamer@actions{%
        \expandafter\xdef\csname beamer@oldcolorhook%
        \the\beamer@coveringdepth\endcsname{\beamer@colorhook}%
        \expandafter\xdef\csname beamer@oldpgfextension%
        \the\beamer@coveringdepth\endcsname{\beamer@pgfextension}%
        {\globalcolorstrue\colorlet{beamer@freeze\the\beamer@coveringdepth}{bg}}%
        \xdef\beamer@colorhook{!##2!beamer@freeze%
          \the\beamer@coveringdepth\beamer@colorhook}%
        \gdef\beamer@pgfextension{!##2opaque}%
        \color{.}%
      }%
      {%
        \xdef\beamer@colorhook{\csname beamer@oldcolorhook%
          \the\beamer@coveringdepth\endcsname}%
        \xdef\beamer@pgfextension{\csname beamer@oldpgfextension%
          \the\beamer@coveringdepth\endcsname}%
        \color{.}%
      }}}%
  \ifnum\beamer@slideinframe<\beamer@minimum%ok, at beginning
  {%
    \beamer@saveanother%
    \advance\beamer@minimum by-\beamer@slideinframe%
    \beamer@slideinframe=\beamer@minimum%
    \beamer@uncoverbeforeactions%
    \beamer@restoreanother%
  }%
  \else%
  {%
    \beamer@saveanother%
    \advance\beamer@slideinframe by-\beamer@minimum%
    \beamer@uncoverafteractions%
    \beamer@restoreanother%
  }%
  \fi%
  \beamer@do%
%  }%
}

\long\def\beamer@makemycovered#1{\beamer@startmycovered#1\beamer@endcovered}
\def\mycover{%
\alt{\beamer@makemycovered}{\beamer@fakeinvisible}}
\def\c@slideinframe{\beamer@slideinframe}
\makeatother

\setbeamercovered{transparent}

\begin{document}

\begin{frame}
\frametitle{Test frame 1}
\structure{Slide \arabic{slideinframe}}

\uncover<1,5>{Testing} \mycover<2-4>{my cover} \uncover<1,5>{command.}
\end{frame}

\begin{frame}
\frametitle{Test frame 2}
\structure{Slide \arabic{slideinframe}}

Testing \mycover<2,4,6>{my cover} command.
\end{frame}

\begin{frame}
\frametitle{Test frame 3}
\structure{Slide \arabic{slideinframe}}

\mycover<2,6>{Testing} \mycover<1-3,5-7>{my cover} command.
\end{frame}

\end{document}

enter image description here

I used your original idea, but using a variation of the original \beamer@startcovered used in \beamer@makecovered.

Although I don't use much overlay specifications in my presentations (\pause, \only and \onslide are enough for me) I like your idea a lot; I think this command could be a part of the official beamer class.

Gonzalo Medina
  • 505,128
  • Thanks, this does seem to do what I want! Could you explain a little bit why my first attempt failed and how your fix works? I'd like to understand more so that I can better solve these problems on my own. Comparing your definition of \beamer@startmycovered with \beamer@startcovered from beamerbaseoverlay.sty, it looks like you removed a \beamer@actions and a \beamer@smuggle from around the entire definition. What do these do? Thanks again! – Henry DeYoung Apr 15 '14 at 16:51
  • That command doesn't seem to work for figures. Only for text. – Droplet Jun 14 '16 at 10:13
  • @Droplet, the \uncover beamer command can not work for graphics in "transparent" mode, so no surprise this one also doesn't (It's implemented as a fake transparent in beamer, just by changing text and background colors). – PlasmaBinturong Feb 13 '18 at 13:35