Desvende o mistério do \writecontentsline

Desvende o mistério do \writecontentsline

Tentando programar uma macro semelhante a \adcontentsline: Aplicar \immediate\writea, digamos,

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

registra o número de página errado. Por outro lado, se o \writefor adiado para o momento em que a página é enviada, o errado \insertpagenumbere o errado \insertpagetitleserão registrados.

Mais contexto: trabalho escrevendo meu próprio pequeno conjunto de macros para sumário, com o objetivo de gerar uma edição de conjunto de algumas centenas de slides em articlemodo. O desafio é produzir uma lista de frames no estilo de sumário, logo após cada arquivo \subsection.

Pacotes como minitoce titletocnão funcionaram. O primeiro porque se recusa a produzir um índice e o segundo porque não funciona bem com hyperref.

Responder1

Pacoteetocé incompatível com a beamerclasse.

Porém, se beamerfor usado em um articlemodo, ou seja, com a articleclasse e o beamerarticlepacote, então etocé aplicável:

\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}

(as imagens foram geradas novamente para refletir a inserção do número do quadro adicionado no código atualizado)

Nota: no código acima, os frames declaram um parágrafo; se os únicos parágrafos encontrados nas subseções estiverem associados de tal forma a frames, é possível simplificar o preâmbulo, não há necessidade de definir um beamerframenível de seccionamento para etoc. Aqui está um preâmbulo simplificado (se o documento já foi compilado com o preâmbulo anterior, deve-se descartar os arquivos auxiliares ou apenas compilar duas vezes, ignorando o erro na primeira compilação).

\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 com beamerartigo página 1 etoc com beamerartigo página 2


[YG:]

Os comandos acima não funcionarão em nenhum modo diferente de article. Por esta razão, é provavelmente melhor proteger o que foi dito acima na \mode{maior parte do preâmbulo acima }.

Outra prática recomendada é usar dois arquivos separados, para o artigo e o modo de slides. Ambos os arquivos devem ser \inputos arquivos onde estão os quadros reais. Se é isso que você faz, então não há necessidade de tal proteção.

informação relacionada