4

Inspired by the discussion on https://github.com/josephwright/beamer/issues/388

There are many questions on this site like "I use theme X but I'd like to have the footer/header/whatever from theme Y", just one example: Mix Warsaw and Madrid beamer theme

To make this easier, how could one just load a specific template from a theme, for example just the footline?


Test cases

Test 1: simple case

\useoutertheme{infolines}
\setbeamertemplate{footline}[infolines theme] 

Test 2: test if it works with parent theme

\usetheme{Boadilla} 
\setbeamertemplate{footline}[infolines theme] 

Test 3: test if it works with options

\usetheme[height=3cm]{Rochester}
\setbeamertemplate{headline}[sidebar theme]
2
  • (definitely samcarter will know the answer) (wait... op is samcarter)
    – Symbol 1
    Apr 21, 2017 at 17:15
  • @Symbol1 Problem: I don't know a good answer :) Apr 21, 2017 at 17:16

3 Answers 3

3
+100

Test 1

This seems to work.

\documentclass{beamer}
    \usecolortheme{whale}
    \useoutertheme{split}
\makeatletter
    \let\beamer@@@@sbto@old=\beamer@@@@sbto
    \def\text@footline{footline}
    \long\def\beamer@@@@sbto#1#2[#3]#4[#5]#6{
        \def\text@element{#1}
        \ifx\text@footline\text@element
            \beamer@@@@sbto@old{#1}{#2}[#3]{#4}[#5]{#6}
        \fi
    }
    \useoutertheme{infolines}
    \let\beamer@@@@sbto=\beamer@@@@sbto@old
\makeatother

\begin{document}
    \begin{frame}
        Test
    \end{frame}
\end{document}

Test 2

If you want to gain the control over colors, do the same trick on \beamer@clearbeamercolor and \beamer@setbeamercolor.

(The same for \setbeamerfont and \setbeamersize)

\documentclass{beamer}
    \usecolortheme{whale}
    \useoutertheme{split}
\makeatletter
    \let\beamer@@@@sbto@old=\beamer@@@@sbto
    \def\text@footline{footline}
    \long\def\beamer@@@@sbto#1#2[#3]#4[#5]#6{
        \def\text@element{#1}
        \ifx\text@footline\text@element
            \beamer@@@@sbto@old{#1}{#2}[#3]{#4}[#5]{#6}
        \fi
    }
    \let\beamer@clearbeamercolor@old=\beamer@clearbeamercolor
    \let\beamer@setbeamercolor@old=\beamer@setbeamercolor
    \def\beamer@clearbeamercolor#1#2{}
    \def\beamer@setbeamercolor#1#2{}
    \usetheme{Boadilla}
    \setbeamertemplate{footline}[infolines theme]
    \let\beamer@@@@sbto=\beamer@@@@sbto@old
    \let\beamer@clearbeamercolor=\beamer@clearbeamercolor@old
    \let\beamer@setbeamercolor=\beamer@setbeamercolor@old
\makeatother

\begin{document}
    \begin{frame}
        Test
    \end{frame}
\end{document}

Test 3

In this test, it is essential that \beamer@@@@sbto is a long macro.

\documentclass{beamer}
    \usecolortheme{whale}
    \useoutertheme{split}
\makeatletter
    \let\beamer@@@@sbto@old=\beamer@@@@sbto
    \def\text@headline{headline}
    \long\def\beamer@@@@sbto#1#2[#3]#4[#5]#6{
        \def\text@element{#1}
        \ifx\text@headline\text@element
            \beamer@@@@sbto@old{#1}{#2}[#3]{#4}[#5]{#6}
        \fi
    }
    \usetheme[height=3cm]{Rochester}
    \setbeamertemplate{headline}[sidebar theme]
    \let\beamer@@@@sbto=\beamer@@@@sbto@old
\makeatother

\begin{document}
    \section{TEST}
    \begin{frame}
        Test
    \end{frame}
\end{document}
4
  • Thank you very much! On the first look this seems indeed to work very well! I will test it a bit and report back. Apr 21, 2017 at 17:50
  • OK, I thought a bit about possible test cases and came up with 3 ones (see edit to my question) which should cover a broad spectrum of possible use cases. 1) you passed with flying colours :) 2) loading the parent theme also works, slight disadvantage is that things like colours will be overwritten by the theme. 3) for a theme with options I get an error Paragraph ended before \beamer@@@@sbto was complete., but maybe I did not modify your solution correctly to now select a headline instead of a footline, as in the previous test. Apr 24, 2017 at 12:27
  • Bonus point: with your approach one does not need to know the exact name of the template, e.g. all ones needs is footline and not that the footline in infolines is called infolines theme . Apr 24, 2017 at 12:40
  • 1
    @samcarter It seems \beamer@@@@sbto is a long macro. I will update my answer accordingly.
    – Symbol 1
    Apr 28, 2017 at 14:40
1

A clumsy workaround: Using the catchfilebetweentags package. However this needs some additional comments in the .sty files.

\documentclass{beamer}

\usecolortheme{whale}
\useoutertheme{split}

\usepackage{catchfilebetweentags}
\newcommand\fromtheme[2]{\ExecuteMetaData[beamertheme#1.sty]{#2}}
\newcommand\fromcolortheme[2]{\ExecuteMetaData[beamercolortheme#1.sty]{#2}}  
\newcommand\fromfonttheme[2]{\ExecuteMetaData[beamerfonttheme#1.sty]{#2}}  
\newcommand\fromoutertheme[2]{\ExecuteMetaData[beameroutertheme#1.sty]{#2}}
\newcommand\frominnertheme[2]{\ExecuteMetaData[beamerinnertheme#1.sty]{#2}}  

\fromoutertheme{infolines}{footline:infolines}

\begin{document}
    \begin{frame}
        Test
    \end{frame}
\end{document}  

The .sty files would need comments like:

%<*footline:infolines>
\defbeamertemplate*{footline}{infolines theme}
{
  \leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{author in head/foot}\insertshortauthor\expandafter\beamer@ifempty\expandafter{\beamer@shortinstitute}{}{~~(\insertshortinstitute)}
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
    \usebeamerfont{title in head/foot}\insertshorttitle
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
    \usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
    \insertframenumber{} / \inserttotalframenumber\hspace*{2ex} 
  \end{beamercolorbox}}%
  \vskip0pt%
}
%</footline:infolines>

%<*headline:infolines>
\defbeamertemplate*{headline}{infolines theme}
{
  \leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,right]{section in head/foot}%
    \usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.65ex,dp=1.5ex,left]{subsection in head/foot}%
    \usebeamerfont{subsection in head/foot}\hspace*{2ex}\insertsubsectionhead
  \end{beamercolorbox}}%
  \vskip0pt%
}
%</headline:infolines>

Problems of the above Ansatz:

  • comments of the form %<*footline:infolines> , %</footline:infolines> would have to be inserted in the code, custom made themes would probably not do this and user would be confused for which templates it would work and for which ones not.

  • I know just loading a specific template will break as soon as the template tries to use something defined within the theme, but outside the template, for example things like \pgfdeclareverticalshading{beamer@topshade}{...} would have to be inside the <*tag>...</tag>

  • of course it would be more convenient if one would not have to know in which sub-theme the template is defined, but could just insert the general theme and this command would recursivly search the loaded sub-themes for a given tag.

  • I have not yet thought about how optional arguments of themes would fit into this...

  • ....


Results of the test cases:

Test 1: simple case

works

Test 2: test if it works with parent theme

fail

Test 3: test if it works with options

fail

1

The following code is from louisstuart96 in an answer I received at https://github.com/josephwright/beamer/issues/388#issuecomment-296338235

[in case he decides to add an answer himself, I will delete this CM]

\documentclass{beamer}

\usecolortheme{whale}
\useoutertheme{split}

\makeatletter
\let\beamer@original@defbeamertemplate\beamer@defbeamertemplate
\def\beamer@defbeamertemplate{\beamer@sbtfalse\@ifstar{\beamer@sbtoo}{\beamer@sbtoo}}
\useoutertheme{infolines}
\setbeamertemplate{footline}[infolines theme] 
% This \set must be done manually, 
% since generally theme names have nothing to do with file names
\let\beamer@defbeamertemplate\beamer@original@defbeamertemplate
\makeatother

\begin{document}
    \begin{frame}
        Test
    \end{frame}
\end{document}

Results of the test cases:

Test 1: simple case

works

Test 2: test if it works with parent theme

works [with the slight disadvantage is that things like colours will be overwritten by the theme]

Test 3: test if it works with options

works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.