Like I suggested in my answer to your other question, you can hook into the \section
macro. The issue is that \section
is not a simple macro. Its expansion involves an auxiliary macro \@startsection
, which in turn expands \@sect
with eight arguments. You can read Section 61.2 of source2e for the gory details, but the first argument is the "level" of section (section
, subsection
, etc.), and the eighth is the name of the section.
You need a TeX executable with the e-TeX primitives to use the etoolbox
package. But you probably do without knowing it. The code below adds to the \@sect
command the logging directive. It essentially does what David and Werner suggested in their comments, but automatically after each sectioning command.
\documentclass{article}
\usepackage{lipsum}
\usepackage{etoolbox}
\makeatletter
\apptocmd{\@sect}{
\typeout{You are now parsing #1 \expandafter\csname the#1\endcsname, ``#8''}
}
{%
\typeout{Patch of \string\@sect\space succeeded}
}
{%
\typeout{Patch of \string\@sect\space failed}
}
\makeatother
\begin{document}
\section{First}
\lipsum[1-2]
\subsection{A subsection}
\lipsum[3-7]
\section{Second}
\lipsum
\section{Third}
\lipsum
\end{document}
Here is a snippet from the console output:
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2012/texmf-dist/tex/latex/lipsum/lipsum.sty)
(/usr/local/texlive/2012/texmf-dist/tex/latex/etoolbox/etoolbox.sty
(/usr/local/texlive/2012/texmf-dist/tex/latex/etex-pkg/etex.sty))
Patch of \@sect succeeded
(./Pete.aux)
You are now parsing section 1, ``First''
You are now parsing subsection 1.1, ``A subsection''
[1{/usr/local/texlive/2012/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
You are now parsing section 2, ``Second''
[2]
You are now parsing section 3, ``Third''
[3] [4] [5] (./Pete.aux) )</usr/local/texlive/2012/texmf-dist/fonts/type1/publi
c/amsfonts/cm/cmbx12.pfb></usr/local/texlive/2012/texmf-dist/fonts/type1/public
/amsfonts/cm/cmr10.pfb>
Output written on Pete.pdf (5 pages, 41359 bytes).
Transcript written on Pete.log.
\wlog{this is section \thesection}
\typeout{You are now parsing section \thesection}
typeout
because it will send the content into the standard output as well which my process is attached to it. So now i can play with logging with error messages :):-)
]