\writecontentsline の謎を解く

\writecontentsline の謎を解く

次のようなマクロをプログラムしようとしています\adcontentsline\immediate\write例えば、に適用すると、

\frameEntry{\insertframenumber}{\inserframetitle \}{\thepage} 

間違ったページ番号を記録します。逆に、\writeページが発送されるまで延期された場合は、間違った\insertpagenumberと間違ったが\insertpagetitle記録されます。

より詳しい背景: 私は、数百枚のスライドのセットを生成する目的で、目次用の独自のマクロ セットを作成中ですarticle。課題は、各スライドの直後に、目次のスタイルでフレームのリストを作成することです\subsection

minitocやなどのパッケージはtitletoc動作しませんでした。前者は目次を生成しないため、後者は とうまく連携しないためですhyperref

答え1

パッケージエトッククラスと互換性がありませんbeamer

ただし、モード、つまりクラスとパッケージbeamerで使用される場合は、が適用されます。articlearticlebeamerarticleetoc

\documentclass{article}
\usepackage{beamerarticle}
\usepackage{etoc}
% section=1, subsection=2, subsubsection=3
\etocsetlevel {beamerframe}{6}% dummy, a priori invisible, level
\etocsettocdepth {all}

% Earlier provisory code by jfbu
% \let\oldframetitle \frametitle
% \renewcommand\frametitle [1]{%
%              \etoctoccontentsline{beamerframe}{#1}%
%              \oldframetitle {#1}%
% }
%%%%

% Better code by Yossi Gil
% Override action when frame title is encountered:
\setbeamertemplate{frametitle}{%
   \paragraph{\insertframenumber.~\insertframetitle}\\
   \noindent\emph{\insertframesubtitle}\par
   \etoctoccontentsline{beamerframe}{\insertframenumber.~\insertframetitle}%
} 
%%%%

% Command to list frames in a sub-section:
\newcommand\listofframesinsubsection {\begingroup
  % we are going to list one frame per line, with dots up to the page number,
  % this is the default etoc design for subsections, we thus need to set the
  % level of a beamerframe to 2. But then we need to artificially move up the
  % leve of subsection so that \localtableofcontents does see the beamerframes
  % as sub levels of a subsection
    \etocsetlevel {subsection}{1}% artificially pretending subsections are
                                % sections  one up the level
    \etocsetlevel {beamerframe}{2}% pretending beamerframes are subsections
    \etoctoclines % use the styles defined by \etocsetstyle, or here, as we
                  % didn't make any use of \etocsetstyle, just defaults
                  % to the package default styles (which are convenient for
                  % us here.)
    \etocsettocstyle {\noindent Frames in this subsection:\par}{}%
    \etocsetnexttocdepth {beamerframe}%
    \localtableofcontents
\endgroup % clean up all our mess for the next \localtableofcontents  not to
          % be affected and proceed in compatibility mode with the same
          % default design as in article class
}

\begin{document}

\etocsetnexttocdepth {subsection}
\tableofcontents

  \section{Some frames}

%\etocsettocstyle{\subsection*{Local contents:}}{}
\etocsettocstyle {}{}
\etocsetnexttocdepth {subsection}
 \localtableofcontents 

\subsection {first subsection}
\listofframesinsubsection

\begin{frame}\frametitle{AHK}
  Ah Ah 
\end{frame}

\begin{frame}\frametitle{AHJ}
  Oh Oh
\end{frame}

\subsection {second subsection}
\listofframesinsubsection

\begin{frame}\frametitle{HBZ}
  Ah Ah 
\end{frame}

\begin{frame}\frametitle{HBW}
  Oh Oh
\end{frame}

  \section{More frames}

%\etocsettocstyle{\subsection*{Local contents:}}{}
\etocsettocstyle {}{}
\etocsetnexttocdepth {subsection}
 \localtableofcontents 


\subsection {third subsection}
\listofframesinsubsection

\begin{frame}\frametitle{BHK}
  Ah Ah 
\end{frame}

\begin{frame}\frametitle{BHJ}
  Oh Oh
\end{frame}

\subsection {fourth subsection}
\listofframesinsubsection


\begin{frame}\frametitle{BBZ}
  Ah Ah 
\end{frame}

\begin{frame}\frametitle{BBW}
  Oh Oh
\end{frame}

\end{document}

(画像は、更新されたコードに追加されたフレーム番号の挿入を反映するように再生成されています)

注: 上記のコードでは、フレームが段落を宣言しています。サブセクションで遭遇する段落のみがフレームに関連付けられている場合は、プリアンブルを簡略化することができ、beamerframeのセクション レベルを定義する必要はありませんetoc。以下は、そのような簡素化されたプリアンブルです (ドキュメントが以前のプリアンブルで既にコンパイルされている場合は、補助ファイルを破棄するか、最初のコンパイル時のエラーを無視して 2 回コンパイルする必要があります)。

\documentclass{article}
\usepackage{beamerarticle}
\usepackage{etoc}
% section=1, subsection=2, subsubsection=3
\etocsettocdepth {all}

\setbeamertemplate{frametitle}{%
   \paragraph{\insertframenumber.~\insertframetitle}\\
   \noindent\emph{\insertframesubtitle}\par
} 

% Command to list frames in a sub-section:
\newcommand\listofframesinsubsection {\begingroup
    \etocsetlevel {subsection}{1}% pretending subsections are sections
    \etocsetlevel {paragraph}{2}% pretending paragraphs are subsections
    \etoctoclines % allows to use the package default styles for subsections
    \etocsettocstyle {\noindent Frames in this subsection:\par}{}%
    \etocsetnexttocdepth {paragraph}%
    \localtableofcontents
\endgroup 
}

etoc with beamer記事ページ 1 etoc with beamer記事ページ2


[YG:]

上記のコマンドは、 以外のモードでは機能しません。このため、上記のプリアンブルの大部分articleで上記を保護するのがおそらく最善です。\mode{}

もう 1 つのベスト プラクティスは、記事とスライド モード用に 2 つの別個のファイルを使用することです。この 2 つのファイルは、\input実際のフレームが含まれているファイルである必要があります。この方法を使用する場合は、このような保護は必要ありません。

関連情報