Latex:在另一个环境中重新定义 Beamer 的框架环境

Latex:在另一个环境中重新定义 Beamer 的框架环境

我必须定期使用 Beamer 进行演示,并且我倾向于制作可以在以后的演示中重复使用的幻灯片。不使用幻灯片时,我喜欢保留它们“隐”在我的演讲结束时,它们可以用于进一步的解释(它们出现在 PDF 的末尾),并且总是只是一个复制粘贴当我再次需要它们时

另一件值得指出的事情是,我使用部分小节作为框架标题和框架副标题,以利用自动目录构建和 PDF 书签。

现在,我最近考虑在 beamer 文件末尾创建一个新环境(我称之为Extra),以“保留和隐藏”额外的幻灯片。这个想法是为了能够复制/粘贴章节、小节和框架,到那个Extra环境,但是防止章节出现在目录和书签中,并防止投影机计算额外的帧\inserttotalframenumber

编辑:我仍然希望将框架包含在 PDF 文件的末尾。

到目前为止,我的操作如下(MWE):

% arara: xelatex: { shell: yes }
% arara: xelatex: { shell: yes }

\documentclass[aspectratio=169, usenames, dvipsnames, hyperref={bookmarks=true}]{beamer}

%% Requirements usually in my theme file
\RequirePackage{etoolbox}% % used for conditions, etc.
\RequirePackage[utf8]{inputenc}


%% Navigation
\setbeamertemplate{navigation symbols}{}  %% replace the navigation symbols


%% Footline, with the ability to "fake" the page number in the Extra section
\setbeamertemplate{footline}{
    \hfill\begin{beamercolorbox}[wd=20mm, rightskip=5mm, ht=10mm]{page number in head/foot}
        %% Other sections except Title, TOC, Thanks and Extra
        \ifboolexpr{ ( not test {\ifcsstring{secname}{Title}} ) and ( not test {\ifcsstring{secname}{TOC}} ) and ( not test {\ifcsstring{secname}{Thanks}} ) and ( not test {\ifcsstring{secname}{Extra}} ) }{
            %% page number on main frames
            \hfill\footnotesize\insertframenumber/\inserttotalframenumber
            \vskip3mm
        }{
            %% specified number on the Extra pages
            %% allows me to have links to the extra pages to answer questions, 
            %% while virtually "staying on the same page"
            \ifboolexpr{ test {\ifcsstring{secname}{Extra}} }{
                \hfill\footnotesize\insertrefpage/\inserttotalframenumber
                \vskip3mm
            }{} %% no else statement
        }
    \end{beamercolorbox}%
}


%% For Extra slides
\newcommand{\refpage}[1]{
    %\hypertarget{extra:#1}{}
    \def\insertrefpage{#1}
}
\newcommand{\extrasection}[1]{
    \def\insertextrasection{#1}
}
\newcommand{\extrasubsection}[1]{
    \def\insertextrasubsection{#1}
}

\makeatletter
\newenvironment{Extra}{
    \refpage{\inserttotalframenumber}
    %% deactivate sections, subsections
    \renewcommand{\section}{\extrasection}
    \renewcommand{\subsection}{\extrasubsection}
    \renewcommand{\insertsection}{\insertextrasection}
    \renewcommand{\insertsubsection}{\insertextrasubsection}
    
    %% This is the part I accidentally came up with
    \renewenvironment{frame}{
        \beamer@frameenv
    }{
        \endframe
    }
    %% explanations or alternatives would be welcome
    
}{}
\makeatother


%%% Main title %%%
\title{My awesome presentation}
\subtitle{A nice subtitle}
\date{\today}
\author[YO]{Y O }



\begin{document}
    
    %% Title page
    \section*{Title}
    \begin{frame}[noframenumbering]
        \titlepage
    \end{frame}
    
    %% TOC
    %% Note: no need for a TOC if only one section
    \section*{TOC}
    \begin{frame}[noframenumbering]
        \frametitle{Table of Contents}
            \tableofcontents[
            currentsection,
            sectionstyle=show, 
            subsectionstyle=hide,
            ]
    \end{frame}
    

    %%% Main frames %%%
    \section{Section 1}
    \subsection{This example works}
    \begin{frame}{\insertsection}{\insertsubsection}
        %
        Some awesome stuff
        %
    \end{frame}
    
    
    \section{Section 2}
    \subsection{But I don't understand why}
    \begin{frame}{\insertsection}{\insertsubsection}
        %
        Some awesome stuff
        %
    \end{frame}

    
    %%% I keep this page as a closure %%%
    \section*{Thanks}
    \begin{frame}[noframenumbering]{Thank you for your attention}{} 
        \Large\textbf{Thanks}
    \end{frame}
    
    
    %% Here I just copy paste things that I want to 
    %% "hide" at the end of the pdf
    \section*{Extra}
    
    \begin{Extra}
        
        %% this command lets me fake the page number
        \refpage{2}

        %% Here I don't want the section to appear in the TOC or bookmarks
        %% But for saving time I would rather not modify it
        %% (this is a copy/paste of former main frames)
        \section{Reminder: Things from last week 1}
        \subsection{And a subtitle}
        \begin{frame}{\insertsection}{\insertsubsection}
            %
            Some awesome stuff
            %
        \end{frame}
    
        
        \refpage{\inserttotalframenumber}   
        \section{Reminder: Things from last week 2}
        \subsection{And a subtitle}
        \begin{frame}{\insertsection}{\insertsubsection}
            %
            Some awesome stuff
            %
        \end{frame}
        
        
    \end{Extra}
    
\end{document}

关于修改环境的部分frame在我测试其他东西时或多或少是偶然发生的,但我不明白为什么它会产生预期的效果,也不明白是否存在更好的替代方案。我说的是:

%% Adapted from beamer's definition of frame
%% added to the opening definition of Extra
\makeatletter
    \renewenvironment{frame}{
        \beamer@frameenv
    }{
        \endframe
    }
\makeatother

如果有人愿意分享一些关于为什么这似乎有效以及如何做得更好的见解,我会很高兴知道。

PS:我正在将 XeLaTeX 与 Beamer 类一起使用。

答案1

您可以将额外的帧放在附录中,并使用\insertmainframenumber而不是 ,而不必弄乱框架环境\inserttotalframenumber。这样,帧是否被计算就无关紧要了。

\documentclass[aspectratio=169, usenames, dvipsnames, hyperref={bookmarks=true}]{beamer}

%\usetheme{mytheme}

\title{Presentation title}
\subtitle{Such a nice presentation}
\date{\today}
\author[Y.O.]{Y.O.}

\makeatletter

\renewcommand<>\appendix{%
  \beamer@inappendixtrue%
  \only#1{%
%  \part{\appendixname}%
  \beamer@appendixwrite%
  \beamer@resetappendix%
  }%
}

%% Footline, with the ability to "fake" the page number in the Extra section
\setbeamertemplate{footline}{
    \hfill\begin{beamercolorbox}[wd=20mm, rightskip=5mm, ht=10mm]{page number in head/foot}
        %% Other sections except Title, TOC, Thanks and Extra
        \ifboolexpr{ ( not test {\ifcsstring{secname}{Title}} ) and ( not test {\ifcsstring{secname}{TOC}} ) and ( not test {\ifcsstring{secname}{Thanks}} )}{
            %% page number on main frames
            \hfill\footnotesize
              \ifbeamer@inappendix%
                \insertmainframenumber/\insertmainframenumber~
              \else%
                \insertframenumber/\insertmainframenumber~
              \fi%
            \vskip3mm
        }{}
    \end{beamercolorbox}%
}
\makeatother

%% new commands to be substituted with \section, \subsection, etc. 
\newcommand{\extrasection}[1]{
    \def\insertextrasection{#1}
}
\newcommand{\extrasubsection}[1]{
    \def\insertextrasubsection{#1}
}

\apptocmd{\appendix}{
    % substitute sections, subsections
    \renewcommand{\section}{\extrasection}
    \renewcommand{\subsection}{\extrasubsection}
    \renewcommand{\insertsection}{\insertextrasection}
    \renewcommand{\insertsubsection}{\insertextrasubsection}
}{}{}

\begin{document}
    
    %% Title page
    \section*{Title}
    \begin{frame}[noframenumbering]
        \titlepage
    \end{frame}

    %% TOC
    \section*{TOC}
    \begin{frame}[noframenumbering]
        \frametitle{Table of Contents}
        \tableofcontents[
                    currentsection, 
                    sectionstyle=show, 
                    subsectionstyle=hide,
        ]
    \end{frame}

    %% A random frame
    \section{Section 1}
    \subsection{The subsection title, usually describing a specific slide}
    \begin{frame}{\insertsection}{\insertsubsection}
        %% frame body
        Some very interesting text here
    \end{frame}

    %% A random frame
    \section{Section 2}
    \subsection{The subsection title, usually describing a specific slide}
    \begin{frame}{\insertsection}{\insertsubsection}
        %% frame body
        Some very interesting text here
    \end{frame}
    
    \appendix
        
        %% A random frame, copy/pasted from the rest of the document
        \section{Section 3}
        \subsection{The subsection title, usually describing a specific slide}
        \begin{frame}{\insertsection}{\insertsubsection}
            %% frame body
            Some very interesting text here
        \end{frame}


\end{document}

相关内容