解开 \writecontentsline 之谜

解开 \writecontentsline 之谜

尝试编写类似于以下内容的宏\adcontentsline:应用于 \immediate\write,例如,

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

记录错误的页码。相反,如果\write延迟到页面发货时,则记录错误\insertpagenumber和错误。\insertpagetitle

更多背景信息:我正在编写自己的目录宏集,目的是生成数百张幻灯片的版本article。挑战是生成目录样式的框架列表,紧接着每个框架\subsection

minitoc和等软件包titletoc均无法使用。前者是因为它拒绝生成目录,而后者是因为它无法与 很好地兼容hyperref

答案1

包裹埃托克与该类不兼容beamer

但是,如果beamer以某种方式使用article,即与article类和beamerarticle包一起使用,则etoc适用:

\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。 这是一个精简的序言(如果文档已经使用较早的序言进行了编译,则应丢弃辅助文件,或者只编译两次,忽略第一次编译时的错误)。

\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 与 beamerarticle 第 1 页 etoc 与 beamerarticle 第 2 页


[YG:]

上述命令在除 之外的任何模式下均不起作用article。因此,最好在\mode{上述大部分序言中保护上述内容}

另一个最佳实践是使用两个单独的包含文件,分别用于文章和幻灯片模式。这两个文件都应该是\input实际框架所在的文件。如果您这样做,则无需进行这样的保护。

相关内容