5

Is it possible to add data into the .log file?

For example, I create a LaTeX file and at some point, i want to put a command that will add data into the .log file.

I don't want something hardcoded into the LaTeX file. I want to add a message like, "You are now parsing section 1". Then somewhere else in the document, I want to add "You are now parsing section 2".

Is it possible, if yes, how can I achieve this?

6
  • 2
    \wlog{this is section \thesection} Apr 1, 2013 at 16:46
  • 1
    \typeout{You are now parsing section \thesection}
    – Werner
    Apr 1, 2013 at 16:59
  • Both works, thanks. However, i'll use 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 :)
    – Pete
    Apr 1, 2013 at 18:12
  • A more descriptive title might make this question more findable. For instance, "How can I automatically add document sectioning information to the log file?" [The typical hacker's answer to "Is it possible...?" is "Yes, if you work hard enough." But you want to know how. :-)] Apr 1, 2013 at 18:49
  • I would change the title of this question, but i don't have the rights to do so. Also, the title seems to be part of the url, so i imagine it cannot be changed.
    – Pete
    Apr 1, 2013 at 19:05

1 Answer 1

5

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.
1
  • 1
    Your check and upvote are thanks enough. :-) Apr 1, 2013 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.