beamer icon indicating copy to clipboard operation
beamer copied to clipboard

Is it possible to cancel acurrently running frame?

Open keinstein opened this issue 5 years ago • 4 comments

Hi, when implementing corporate designs I had to implement special frame layouts for title pages and table of contents and so on. This means that the corresponding commands must be called outside of any frame. On the other hand beamer seems to prefer to call maketitle inside the frame.

In order to be consistent with this practise I need either a way to cancel a started frame, or – which would be probably the better solution – a way to change the overlay specification from inside the frame body together with a way to inject code at the very end of the frame environment. I think the latter would be possible with defining some global macro that is passed from \endframe to the environment code.

Example:

\def\maketitle{%
  \replaceoverlayspcification\saveoverlayspecification<0>
  \afterframe{%
    \setbeamertemplate{backgrond}{my new background}
    \setbeamertemplate{headline}[my predefined fancy headline]
    \expandafter\againframe\saveoverlayspecification{\lastframe}%
  }%
}
\begin{frame}
  \maketitle
\end{frame}

keinstein avatar Nov 27 '19 08:11 keinstein

It's weird to typeset anything outside a frame. For a frame with special layout, you may try plain option to a frame. beamer cannot change themes freely within a document because the sizes of headlines, footlines and sidebars are all calculated at the beginning. Then if you use plain option, you have to set layouts on your own.

louisstuart96 avatar Nov 27 '19 09:11 louisstuart96

There is a neat trick to automatically change the layout for titlepage etc without chanceling running frames or hooking into the end of the frame.

Small caveat: as @louisstuart96 already mentioned, elements might be misaligned if the heights of the headlines differ too much. If this becomes a problem, you will have to force a rerun of the geometry calculations.

\documentclass{beamer}

\setbeamertemplate{headline}{normal headline}

\makeatletter

\def\ps@navigation@titlepage{%
  \usebackgroundtemplate{\includegraphics[width=\paperwidth]{example-image-duck}}
  \setbeamertemplate{headline}{title headline}
  \@nameuse{ps@navigation}}
\addtobeamertemplate{title page}{\thispagestyle{navigation@titlepage}}{}

\def\ps@navigation@toc{%
  \usebackgroundtemplate{\includegraphics[width=\paperwidth,page=2]{example-image-duck}}
  \setbeamertemplate{headline}{toc headline}
  \@nameuse{ps@navigation}}
\apptocmd{\beamer@tableofcontents}{\thispagestyle{navigation@toc}}{}{}

\makeatother

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\begin{frame}
  \tableofcontents
\end{frame}

\section{section name}
\begin{frame}
  content...
\end{frame}

\end{document}

samcarter avatar Nov 27 '19 12:11 samcarter

@louisstuart96 In the standard way

\begin{frame}
\maketitle
\end{frame}

the macro \maketitle has no way to change the frame option~~page style~~ to plain. The only way I can think of this is finishing the frame, throwing away the box that contains the page contents and restart the whole page with a new frame. That is what I think of as cancelling a started frame. I think it is theoretically possible, but I don't know how.

The other way round it would work: Typeset the frame material as usual, change the page style and use againframe. This works when triggered outside the frame.

\documentclass{beamer}

\title{Titleline\\\vskip 1 filll end}
\begin{document}
\setbeamertemplate{headline}{\rule{\paperwidth}{5cm}}%
\makeatletter
\beamer@calculateheadfoot
\makeatother
\begin{frame}
  a\vfill b
\end{frame}

\begin{frame}<0>[label=titelseite]
  a\vfill b
\end{frame}

\setbeamertemplate{headline}{x}%
\makeatletter
\beamer@calculateheadfoot
\makeatother
\againframe<1>{titelseite}

\begin{frame}
  a\vfill b
\end{frame}

\end{document}

As you can see, the secound frame is typeset in the style that is active at the time of calling \againframe, not in the style that has been used for the frame environment.

BTW. the option label= stores the frame environment in a macro, not the typeset box. So yes, it is possible to change everything after the frame has been „typeset“. My question is: How can I trigger that from inside the frame body? So I change my question how can I realize this macro:

\newcommand\putinotherframesetup{%
    \addframelabelfrominside{myframelabel}%
    \setframeoverlayspecificationfrominside{<0>}%
  \end{frame}
  \begin{frame}{relabel=myframelabel}%
}

I'm shure that this is possible to implement at least for non-verbatim and non-fragile frames. What is already done? What must be done?

keinstein avatar Nov 27 '19 14:11 keinstein

@samcarter Nice solution. Though it is still a hack, it should be safe in the sense that it does not depend on the beamer version. Yes, setting up the dimensions correctly, is an exercise with reading the source of \beamer@calculateheadfoot and playing around with \global. Actually if you do this, one page style \ps@beamer@tmp should be sufficient, as it must be redefined in each frame or another macro that restores the original settings. Actually, it should be also safe (with respect to upward/downward compatibility) to overwrite the whole page style (i.e. copy and paste and delete everything unnecessary) as the page style navigation uses either high-level beamer code or basic TeX code (except from some geometry stuff).

keinstein avatar Nov 27 '19 20:11 keinstein