26

I have a bash script which I use to compile a file with pdflatex twice (to make sure it sorts out references properly, etc.). This is the 'latexbuild' script I use:

module load ctan
pdflatex --shell-escape --interaction=nonstopmode $1
bibtex $1
pdflatex --shell-escape --interaction=nonstopmode --interaction=batchmode $1

I would then call this script with latexbuild test.tex. It produces a lot of output which I would like to supress, except for the error messages which I'd like to see. Is there any way to only allow error messages to be displayed?

Eddy
  • 1,875

4 Answers4

31

The texfot Perl script by Karl Berry has been recently added to TeX Live; the command line

> texfot pdflatex eddy

where eddy.tex is

\documentclass{article}
\begin{document}

A purposely overfull line \makebox[1.1\textwidth]{x}

And an error \abcdefghi

\end{document}

will produce the following output on the terminal:

/usr/texbin/texfot: invoking: pdflatex eddy
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
Overfull \hbox (156.0012pt too wide) in paragraph at lines 4--6
! Undefined control sequence.
l.8 \abcdefghi
! Emergency stop.
l.8 \abcdefghi
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on eddy.log.

Although the documentation asserts that the --interactive option allows for stopping at errors, this doesn't seem to work (maybe this will be fixed in a next release).

The “real” terminal output is available in $TMPDIR/fot or /tmp/fot if the TMPDIR environment variable is not set.

egreg
  • 1,121,712
15

You could use the -file-line-error option and then grep the output for something of that form filename:##:error code (Below I just use the regex .*:[0-9]*:.*. Works decently well on a few tests.

Note, bibtex is run on the .aux file not the .tex file. For it, using the -terse option is probably sufficient.

Lastly I have no idea what your module load ctan does (--I have no such program--), so I excluded it.

#!/bin/bash
ARGUMENT="$1"
#determine aux name by stripping .tex suffix and adding .aux
AUXNAME="${ARGUMENT%.tex}.aux"
pdflatex -shell-escape -interaction=nonstopmode -file-line-error "$ARGUMENT" | grep ".*:[0-9]*:.*" 
bibtex -terse "$AUXNAME"  
pdflatex -shell-escape -interaction=nonstopmode -file-line-error "$ARGUMENT" | grep ".*:[0-9]*:.*" 

You might want to play around with the -A and -B options to grep if you want some context surrounding the error messages, rather than just a single line.

I'd also play around with using if constructs or checking exit status to determine whether the last two steps should be done. (E.g., if an error is found in the first run, don't bother with the second, etc.) I can give more details if need be.

EDIT: Just saw your comment about warnings. The above will only catch true errors. I'm not sure there is a standard to warning messages, but grepping for the word "warning" might be good enough. so then it's something like:

#!/bin/bash
ARGUMENT="$1"
#determine aux name by stripping .tex suffix and adding .aux
AUXNAME="${ARGUMENT%.tex}.aux"
pdflatex -shell-escape -interaction=nonstopmode -file-line-error "$ARGUMENT" | grep -i ".*:[0-9]*:.*\|warning" 
bibtex -terse "$AUXNAME"  
pdflatex -shell-escape -interaction=nonstopmode -file-line-error "$ARGUMENT" | grep -i ".*:[0-9]*:.*\|warning" 
Torbjørn T.
  • 206,688
frabjous
  • 41,473
  • Thanks, that worked well. I changed grep ".*:[0-9]*:.*" to egrep ".*:[0-9]*:.*|LaTeX Warning:" so that it looks for warnings as well as errors. – Eddy Sep 08 '11 at 17:44
4

The silence package provides a means for suppressing LaTeX package and class warnings and errors. For example, the command

\WarningFilter{latex}{Marginpar on page}

would suppress all warnings produced by latex that start with "Marginpar on page...". It is not always perfect, but it seems like something that might help in your case. You could also suppress all warnings (or errors) using \WarningsOff (or \ErrorsOff). Consider reading the package documentation for more of the filtering options.

Werner
  • 603,163
  • 5
    I think he wants to suppress everything but errors and warnings. This package seems to do just the opposite – Spike Jan 05 '12 at 21:53
1

Newb attempt that seems to be working on a few simple examples:

pdflatex a.tex | perl -0777 -ne 'print m/\n! .*?\nl\.\d.*?\n.*?(?=\n)/gs'

supposes that all errors are of form:

! Cryptic explanation
<maybe more cryptic explanations>
l.123 Undefined \asdfqwer
                          very very very very long line.

Please correct away.

EDIT

As answered by egreg after I posted, texfot seems to be a super advanced version of this attempt also based on "heuristic" regex filtering. Not in TeX Live 2013 ISO, but prefer that if you can use it.