2

I'm trying to understand why the hook AtBeginEnvironment{frame} does not seem to apply in this MWE:

\documentclass{beamer}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usetheme{Madrid}

\usepackage[T1]{fontenc} \usepackage[french]{babel}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Redéfinition de l'environnement frame \AtBeginEnvironment{frame}{% \frametitle{\thesection - \insertsection}% \framesubtitle{\thesubsection - \insertsubsection} }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\section{section n°1} \subsection{sous-section 1-1}

\begin{frame} Texte du slide. \end{frame}

\end{document}

Normally, it should print a title and a subtitle in the frame, but for some reason that I don't understand it does not.

Thanks for helping.

2 Answers2

1

Setting the frametitle at the start of the frame environment is too early. As there are people - including pandoc users - who use the extremely annoying syntax \begin{frame}{frametitle}{framesubtitle}, beamer needs to jump through a lot of hoops to deal with this complicate syntax. You have to wait with \frametitle after beamer is done with this.

Instead of messing with the frame environment, disable beamer's checks for the existence of a frametitle and patch the frametitle to show the section/subsection if the frametitle is empty:

\documentclass{beamer}

\usepackage{xpatch} \makeatletter \patchcmd\beamer@@tmpl@frametitle{\insertframetitle}{% \ifx\insertframetitle@empty \thesection{} - \insertsection \ifx\insertframesubtitle@empty \ifnum\thesubsection>0 \def\insertframesubtitle{\thesubsection{} - \insertsubsection} \fi\fi \else \insertframetitle \fi }{}{} \makeatother

\makeatletter \CheckCommand\beamer@checkframetitle{@ifnextchar\bgroup\beamer@inlineframetitle{}} \renewcommand\beamer@checkframetitle{\global\let\beamer@frametitle\relax@ifnextchar\bgroup\beamer@inlineframetitle{}} \makeatother

\begin{document}

\section{section 1} \subsection{sub 1} \begin{frame} \end{frame}

\begin{frame} \frametitle{frametitle} \framesubtitle{framesub}

\end{frame} \end{document}

  • Thanks again SamCarter. This is indeed working a bit better in Pandoc. I'm trying to figure out how to add the current section in the subtitle. Replacing the occurrences of title with subtitle in your snippet does not seems to work... investigating. – Pol Dellaiera Oct 30 '22 at 06:36
  • And there is another issue, your snippet add a title on the \titlepage and \sectionpage – Pol Dellaiera Oct 30 '22 at 06:37
  • @PolDellaiera Sure it does add them to the title page etc. Your question does not ask to exclude any special frames, so why should an answer exclude them? However you can exclude them as shown in https://tex.stackexchange.com/questions/661314/beamer-include-subsection-in-frametitle-but-only-if-subsection-exists-i-e-no/661329#661329 – samcarter_is_at_topanswers.xyz Oct 30 '22 at 10:58
  • Thanks, I will see what I can do with all these information. – Pol Dellaiera Oct 30 '22 at 15:51
0

Here is a way:

\documentclass{beamer}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usetheme{Madrid}

\usepackage[T1]{fontenc} \usepackage[french]{babel}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Redéfinition de l'environnement frame \let\oldframe\frame \def\newframe{% \oldframe\frametitle{\thesection - \insertsection}% \framesubtitle{\thesubsection - \insertsubsection}% } \def\endnewframe{\endframe}

\renewenvironment{frame}{\newframe}{\endnewframe}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\section{section n°1} \subsection{sous-section 1-1}

\begin{frame} Texte du slide. \end{frame}

\end{document}

koleygr
  • 20,105
  • Thanks! Indeed, it works pretty fine in Overleaf.

    Sadly, this is failing when using Pandoc to convert a markdown file to beamer. That's extremely weird.

    – Pol Dellaiera Oct 29 '22 at 18:27
  • @PolDellaiera Not weird at all. Pandoc uses the extremly annoying syntax \begin{frame}{frametitle}{framesub} to set the frame title and subtitle and by redefining the frame environment you'll loose the ability to use this syntax as well as optional arguments. – samcarter_is_at_topanswers.xyz Oct 29 '22 at 21:08