揭開 \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 與 beamer文章第 1 頁 etoc 與 beamer文章第 2 頁


[YG:]

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

另一個最佳實踐是為文章和幻燈片模式使用兩個單獨的包含檔案。這兩個檔案都應該\input是實際幀所在的檔案。如果這就是您所做的,那麼就不需要這樣的保護。

相關內容