3

Dear LaTeX / beamer enthusiasts

For our courses, we have a large repository of LaTeX slides using the great beamer package. Some slides are only included in the handout, others are available in handout and in the beamer slide set. Handouts and overlays are generated from the same file by passing the options to the beamer class from a build script.

I am looking for a solution to mark slides in the handout that are actually only visible in the handout (and are not part of the overlays). Because we have a huge repository of slides that are used (imported) in various courses, I would like to automate this task without having to maintain some sort of "handout_required" switch.

I know how to find out about the current mode (handout/trans/beamer/...). If I could find out about which modes are currently required (because in an \only<handout> environment, for instance), I would know how to solve the problem.

[edited: in my original question I assumed that I could solve the problem if I could temporarily switch to a different mode, which turned out to be untrue]

I have consulted a lot of pages here and elsewhere and cannot find an answer to my problem.

Any help would be much appreciated.

Here is a usage scenario

\documentclass[handout]{beamer}

\begin{document}

% this command only finds out that we are in handout mode
% (but I want to find out about the currently required mode)
\newcommand\onlyhandoutmarker{\only<handout>{(handout)}} 

% this supports using the marker in the frametitle
\setbeamertemplate{frametitle}{
  \begin{beamercolorbox}[wd=\textwidth, ht=0.85cm, dp=0.4cm]{frametitle}
    \strut\insertframetitle\ \onlyhandoutmarker\strut
  \end{beamercolorbox}
}

\begin{frame}{General Slide}
This slide appears on overlay slides and in the handout. 

It should not be marked as handout in the handout slides.
\end{frame}

\begin{frame}<handout>{Handout Slide}
This slide only appears in a handout. 

This is the slide that I would like marked as handout in the handout slides.
\end{frame}

\end{document}

first slide

second slide

2
  • 1
    "If I could temporarily switch to a different mode": You can temporarily switch to different modes like this: tex.stackexchange.com/a/649910/36296 (however I don't really see how this would solve your problem....) Sep 24, 2023 at 13:07
  • Thank you, samcarter. Indeed, that was a misconception on my side. It is very useful to know how to do this but, as you say, it does not help me for this problem. My original idea was when switching to a different mode I would not enter the <handout> part in the first place, but since I am already in that part when checking for the mode, this does not work to detect the current requirements. Again I would need access to the currently required set of modes. Sorry for the confusion.
    – FelixF
    Sep 24, 2023 at 14:24

1 Answer 1

2

Adaptations

  • added two toggles, that are set to true, if handout mode was set in a frame or in an altenv (e.g. with onlyenv):
    \newtoggle{handoutmarkerframe}
    \newtoggle{handoutmarkeraltenv}
    
  • set handoutmarkerframe before every frame to false, with:
    \preto\frame{\global\togglefalse{handoutmarkerframe}}
    
  • change the definition of \beamer@@frameenvspec, to include the following additional lines:
    \ifstrequal{#1}{handout}{% <<< NEW
        \global\toggletrue{handoutmarkerframe}% <<< NEW
    }{}% <<< NEW
    
    • this will check, if frame was called with the option <handout> and sets the toggle handoutmarkerframe accordingly
  • analogously change definition of \beamer@@altenv and \endaltenv to set the toggle handoutmarkeraltenv
  • add \onlyhandoutmarker (" (handout)") to the frame title, if at least one toggle is true:
    \ifboolexpr{ togl {handoutmarkerframe} or togl {handoutmarkeraltenv} }{%
        \onlyhandoutmarker%
    }{}%
    
  • added package etoolbox for commands \preto, \ifstrequal and toggles
  • for test purposes, I added more slides to see that it still works properly afterwards

Code

\documentclass[handout]{beamer}

\usepackage{etoolbox}

\newtoggle{handoutmarkerframe}
\newtoggle{handoutmarkeraltenv}
\newcommand{\onlyhandoutmarker}{\ (handout)}

\preto\frame{\global\togglefalse{handoutmarkerframe}}

\makeatletter
\def\beamer@@frameenvspec<#1>{%
    \ifstrequal{#1}{handout}{% <<< NEW
        \global\toggletrue{handoutmarkerframe}% <<< NEW
    }{}% <<< NEW
    \expandafter\gdef\expandafter\beamer@frameoptions\expandafter{\beamer@frameoptions<#1>}%
    \beamer@copewithframeenv%
}

\long\def\beamer@@altenv#1#2#3#4#5{%
    \ifstrequal{#1}{<handout>}{% <<< NEW
        \global\toggletrue{handoutmarkeraltenv}% <<< NEW
    }{}% <<< NEW
    \alt#1{\long\def\beamer@eoenv{#3}#2}{\long\def\beamer@eoenv{#5}#4}%
}

\protected\def\endaltenv{%
    \global\togglefalse{handoutmarkeraltenv}% <<< NEW
    \beamer@eoenv%
}
\makeatother

% this supports using the marker in the frametitle
\setbeamertemplate{frametitle}{
  \begin{beamercolorbox}[wd=\textwidth, ht=0.85cm, dp=0.4cm]{frametitle}
    \strut\insertframetitle%
    \ifboolexpr{ togl {handoutmarkerframe} or togl {handoutmarkeraltenv} }{%
        \onlyhandoutmarker%
    }{}%
    \strut%
  \end{beamercolorbox}
}

\begin{document}

\begin{onlyenv}<handout>
    \begin{frame}{General Slide inside handout onlyenv}
        This slide only appears in a handout. 
        
        This is the slide that I would like marked as handout in the handout slides.
    \end{frame}
\end{onlyenv}

\begin{frame}<all>{All Slide}
    This slide appears on overlay slides and in the handout. 
    
    It should not be marked as handout in the handout slides.
\end{frame}

\begin{frame}<handout>{Handout Slide}
    This slide only appears in a handout. 
    
    This is the slide that I would like marked as handout in the handout slides.
\end{frame}

\begin{frame}{General Slide}
    This slide appears on overlay slides and in the handout. 
    
    It should not be marked as handout in the handout slides.
\end{frame}

\end{document}

Result

enter image description here

4
  • 1
    That is already very helpful. Thank you very much for your answer. However, in our scenario, we also import slides and make them handout as in \begin{onlyenv}<handout> ... \end{onlyenv} where your solution does not seem to work. Is there a more general way to catch the <handout>?
    – FelixF
    Sep 24, 2023 at 14:52
  • I don't know, if there is a more general way, but you could of course change the definition of onlyenv similarly to what I did with frame.
    – dexteritas
    Sep 24, 2023 at 15:02
  • I made an edit to my answer, so it now also work with \begin{onlyenv}<handout> ... \end{onlyenv}.
    – dexteritas
    Sep 24, 2023 at 15:29
  • 1
    That's absolutely fantastic, dexteritas. With your help and template (and having looked at the source of beamerbaseoverlay.sty) I could extend it now even such that it also works with \only<handout>{ ... } which we also use sometimes. This shows that this solution is generic enough for my purposes. Thanks a lot for this. You helped me tremendously. I mark this answer as the solution.
    – FelixF
    Sep 24, 2023 at 16:29

You must log in to answer this question.

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