\insertsectionnumber と \inserttocsectionnumber の違い

\insertsectionnumber と \inserttocsectionnumber の違い

次のビーマーコード

\documentclass{beamer}

\setbeamertemplate{section in toc}[sections numbered]

\begin{document}

\frame{\tableofcontents}

\section{section one}
\frame{\insertsectionnumber\quad\insertsection}

\section*{section two}
\frame{\insertsectionnumber\quad\insertsection}

\section{section three}
\frame{\insertsectionnumber\quad\insertsection}

\end{document}

次の結果が得られます。

ここに画像の説明を入力してください

\tableofcontentsコマンドを呼び出すことは知っています。いくつかのコマンド\inserttocsectionnumberがあり、異なる結果を返す場合:\section*\inserttocsectionnumber\insertsectionnumber2 セクション3そして3 セクション3。 なぜ?

答え1

これは からのコードbeamerbasesection.styで、注釈が付いています。

などの標準クラスとは異なり、カウンタのステップに関して\sectionとの間には区別がありません。そのため、カウンタはコマンドによっても増加します。\section*sectionarticlesection\section*

これはバグですか?いいえ、私はそうする方が、さまざまな洗練された機能をすべて記録するのに簡単だと思いますbeamer

\newcommand<>{\section}{\alt#1{\@ifnextchar[\beamer@section\beamer@@section}{\beamer@secgobble}}

\def\beamer@@section{\@ifnextchar*\beamer@@ssection\beamer@@@section}
\long\def\beamer@@ssection*#1{\beamer@section[{#1}]{}}  %% starred section
\long\def\beamer@@@section#1{\beamer@section[{#1}]{#1}}
\long\def\beamer@section[#1]#2{%
  \beamer@savemode%
  \mode<all>%
  \ifbeamer@inlecture
    \refstepcounter{section}%  used in any case of \section or \section* 
    \beamer@ifempty{#2}%
    {\long\def\secname{#1}\long\def\lastsection{#1}}%
    {\global\advance\beamer@tocsectionnumber by 1\relax%
      \long\def\secname{#2}%
      \long\def\lastsection{#1}%
      \addtocontents{toc}{\protect\beamer@sectionintoc{\the\c@section}{#2}{\the\c@page}{\the\c@part}%
        {\the\beamer@tocsectionnumber}}}%
    {\let\\=\relax\xdef\sectionlink{{Navigation\the\c@page}{\noexpand\secname}}}%
    \beamer@tempcount=\c@page\advance\beamer@tempcount by -1%
    \beamer@ifempty{#1}{}{%
      \addtocontents{nav}{\protect\headcommand{\protect\sectionentry{\the\c@section}{#1}{\the\c@page}{\secname}{\the\c@part}}}%
      \addtocontents{nav}{\protect\headcommand{\protect\beamer@sectionpages{\the\beamer@sectionstartpage}{\the\beamer@tempcount}}}%
      \addtocontents{nav}{\protect\headcommand{\protect\beamer@subsectionpages{\the\beamer@subsectionstartpage}{\the\beamer@tempcount}}}%
    }%
    \beamer@sectionstartpage=\c@page%
    \beamer@subsectionstartpage=\c@page%
    \def\insertsection{\expandafter\hyperlink\sectionlink}%
    \def\insertsubsection{}%
    \def\insertsubsubsection{}%
    \def\insertsectionhead{\hyperlink{Navigation\the\c@page}{#1}}%
    \def\insertsubsectionhead{}%
    \def\insertsubsubsectionhead{}%
    \def\lastsubsection{}%
    \Hy@writebookmark{\the\c@section}{\secname}{Outline\the\c@part.\the\c@section}{2}{toc}%
    \hyper@anchorstart{Outline\the\c@part.\the\c@section}\hyper@anchorend%
    \beamer@ifempty{#2}{\beamer@atbeginsections}{\beamer@atbeginsection}%
  \fi%
  \beamer@resumemode}%

編集:

使用された\refstepcounter場合、動作しないようにするためのパッチ\section*

\documentclass{beamer}

\usepackage{xpatch}

\makeatletter
\newif\ifisstarred%   new if command
\isstarredfalse%      % No starred section by default

\xpretocmd{\beamer@@ssection}{\isstarredtrue}{}{}  % enable `*` mode
\xpatchcmd{\beamer@@ssection}{\beamer@section[{#1}]{}}{\beamer@section[{#1}]{}\isstarredfalse}{\typeout{Patch success beamer@@ssection}}{\typeout{Patch failure}}
\xpatchcmd{\beamer@section}{%
  \refstepcounter{section}%
}{%
  \ifisstarred% 
  % Do nothing in here
  \else
  \refstepcounter{section}%
  \fi
}{\typeout{Patch success beamer@section}}{}
\makeatother


\setbeamertemplate{section in toc}[sections numbered]

\begin{document}

\frame{\tableofcontents}

\section{section one}
\frame{\insertsectionnumber\quad\insertsection}

%\inserttocsectionnumber


\section*{section two}
\typeout{Starred section}
\frame{\insertsectionnumber\quad\insertsection}

\section{section three}
\frame{\insertsectionnumber\quad\insertsection}

\end{document}

ここに画像の説明を入力してください

関連情報