# Use latexmk to filter the log file

I am usually using latexmk in a split shell with my code on the left and latexmk in -pvc mode on the right.

When using some packages which themselves load a lot of other packages (think beamer) the log file contains tens or even hundreds of lines of messages from the packages being loaded (also spelling files, fonts, etc.).

I would like to prune the output to just the warnings, the errors, and latexmk’s own messages so these do not get lost.

Any ideas?

-
I think this is a very important question — something that bothers me every time I am using Latex. I am offering a bounty to draw more attention to this question, and in particular to see if anyone is aware of more recent developments regarding Latex log file filters. – Jukka Suomela Aug 20 '12 at 7:40
@JukkaSuomela I thougt that this question has been answered by Neil tex.stackexchange.com/a/18088/4736 , see below. What's the obstacle to use the silcence package? – Keks Dose Aug 20 '12 at 11:33
@KeksDose: I do not see how I should use the silence package so that I automatically get just the relevant warnings and errors, and nothing else (cf. what rubber-info tries to do). If you have a fully working example how to set it up, please post an answer! – Jukka Suomela Aug 20 '12 at 11:38
Also of interest is the logreq package. – Martin Schröder Aug 20 '12 at 21:51
@NickolayKolev The silence package needs some information about packages you use. Could you make a short working example and I will try get the silence of the logs, just as a proof of concept. – Keks Dose Aug 21 '12 at 9:26

You can use pplatex to filter errors, warnings and badboxes: http://www.stefant.org/web/projects/software/pplatex.html

(the compilation of http://dl.dropbox.com/u/12697903/pplatex/pplatex-1.0-rc1-src.tar.gz needs an additional #include in src/outputfilter.cpp)

If you then have ppdflatex in the path, you can create a ~/.latexmkrc file like the following to have a great workflow (with KDE, but it should be easily adaptable):

$pdf_mode = 1;$pdflatex = 'ppdflatex -- -interaction=nonstopmode -shell-escape -synctex=1';
$pdf_previewer = "start okular";$pdf_update_method = 0;
$recorder = 1;$preview_continuous_mode = 1;
$sleep_time = 1;  - pplatex does not seem to be actively maintained; the current version is from 2010. – Jukka Suomela Aug 20 '12 at 7:59 The last release is some time ago. I am in contact with it's author from time to time fixing something. He planned to put the source code on github, to open up development. – Patrick Häcker Sep 1 '12 at 19:00 Stefan Hepp has created the github project (github.com/stefanhepp/pplatex) and wants to keep improving the project. – Patrick Häcker Sep 5 '12 at 18:05 pplatex can be installed via brew install homebrew/tex/pplatex (osx homebrew or linuxbrew). Unfortunately currently the formula does not work. – Hotschke Aug 3 at 12:44 I just remembered that rubber has log filtering. It turns out there is a program in the rubber package called rubber-info which is solely for parsing the log file. Because latexmk acts as tee (writing the to the logfile and printing to stdout and stderr, we can run rubber-info after latexmk is finished. So I put this in a shell script: #! /bin/bash latexmk --pdf$1 > /dev/null 2>&1
rubber-info --check $1 rubber-info --boxes$1


and set makeprg in vim to

:set makeprg=latexmake\ %:h


And now I have only the errors and warnings (including overfull boxes).

-
Unfortunately, rubber's output parser is not really fool-proof: it may occasionally produce an empty output even if there were errors. This kind of two-step approach makes it even more risky — if latexmk fails, and rubber-info produces no output, you may easily miss major issues. A common scenario is that pdflatex runs OK, but bibtex then fails, yet rubber-info does not find any problems in the bibtex log file. – Jukka Suomela Aug 20 '12 at 7:46
I can back the issues with rubber-info mentioned by Jukka. As a consequence I have stopped using it. – Daniel Aug 20 '12 at 8:06

Try the silence package, it can filter a variety of errors, warnings, and messages.

-
apparently no support for underfull or overfull messages – Hotschke Aug 3 at 12:41

If you don't edit your preamble very often, you can also precompile it, it will also make you gain time with each compilation.

You can find details in this page, but essentially, you have to

• separate the fixed preamble from the document, paste it into a file named preamble.tex
• run latex -ini -job-name="main" "&latex preamble.tex\dump" or if you prefer pdflatex run pdflatex -ini -job-name="main" "&latex preamble.tex\dump"

• add %&main.fmt at the beginning of your file and remove \input{preamble}

• add -parse-first-line to latex/pdflatex's flags.

I believe you can add a latexmk rule to recompile the preamble if you edit it, also.

-
Precompiling the preamble is essentially broken for LuaLaTeX with fontspec. – Martin Schröder Aug 20 '12 at 21:44

You need to write a small script which filters the log file. Either a Perl, Python or similar scripting language of you choice or a longer egrep line (if you under a *nix system) should do it.

Before I knew latexmk I wrote my own minimalistic version of it (actually of texify) which does such filtering. Here the filter code on its own as an example. It is a Perl script which still needs adjustments to include latexmk's own messages.

#!/usr/bin/env perl
use strict;
use warnings;
my $nobox = 0; # Should box warning be excluded my$nextlines = 0;
while (<>) {
if ($nextlines > 0) {$nextlines--; print STDERR $_; } elsif (/^(!\s+)?LaTeX (?:Warning|Error)/i) { print STDERR$_; }
elsif (/^! Undefined control sequence\./i) { chomp; print STDERR $_, ": ";$nextlines = 1; }
elsif (/^! Use of .* doesn't match its definition\./i) { print STDERR $_;$nextlines = 3; }
elsif (/^!/i) { print STDERR $_; } elsif (!$nobox && /(overfull|underfull|badbox)/i) { print STDERR \$_; }
}

-
Otherwise write to the latexmk author, he is usually very open for suggestions – daleif Mar 10 '11 at 11:45
@John Collins, the latexmk author, also is pretty active here on tex.se. So we probably will here from him soon :-) – Daniel Aug 20 '12 at 8:12

Though it would miss TeX warnings, showing only LaTeX ones, you could patch LaTeX's error and warning commands to write the warnings and errors additionally to another separate log file. This log file would then only contain errors and warnings. Latexmk could then cat this file at the end of the run.

I would be willing to have a go at this if anyone thinks it useful, but at the moment I think the missing of TeX's messages would be a deal-breaker. Perhaps if using LuaTeX, one can hook into TeX's messages too?

-