Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
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
1  
No. TeX does not distinguish between stdout and stderr. – egreg Sep 8 '11 at 17:03

2 Answers

up vote 6 down vote accepted

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" 
share|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 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.

share|improve this answer
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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