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?

  • I think that the best you can get (without filtering) is the -halt-on-error flag, which stops on first error. Also two LaTeX passes may not be enough in general. And what about warning messages? – Andrey Vihrov Sep 8 '11 at 16:52
  • Yeah I mean warnings as well as errors. The KDE latex editor Kile somehow manages to do it, it has a small log window which only displays errors and warnings, but I can't figure out how to do that in a script – Eddy Sep 8 '11 at 16:55
  • 2
    No. TeX does not distinguish between stdout and stderr. – egreg Sep 8 '11 at 17:03
  • Possible cross site duplicate of: stackoverflow.com/questions/1037927/run-pdflatex-quietly , except that here it is on topic =) – Ciro Santilli 郝海东冠状病六四事件法轮功 Mar 14 '14 at 11:31

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.

#determine aux name by stripping .tex suffix and adding .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:

#determine aux name by stripping .tex suffix and adding .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" 
| improve this answer | |
  • 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 8 '11 at 17:44

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

> texfot pdflatex eddy

where eddy.tex is


A purposely overfull line

And an error


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.

| improve this answer | |
  • I have been looking for something like this for so long. Latex generates so much output. Very nice. Thank also to Karl Berry. – Nasser Jun 28 '15 at 6:31

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.

| improve this answer | |
  • 5
    I think he wants to suppress everything but errors and warnings. This package seems to do just the opposite – Spike Jan 5 '12 at 21:53

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.


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.

| improve this answer | |

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.