suppress output

1,962

Reading the documentation leads to some good information. For example, using the standard (pdf|lua)latex options, we immediately come up with the following:

pdflatex -interaction="batchmode" myfile.tex

This produces a very minimal message stating the name of the program, the version, the enablement of restricted \write18, and the fact that it's entering extended mode. It suppresses all other output. The latexmk documentation gives the option -silent, which suppresses a good deal of output, but not all.

None of these options let errors come through, however, and unfortunately TeX was not written for a system which distinguishes between stderr and stdout, so standard output redirection options don't work here. You're probably stuck filtering your output to make this happen. Fortunately, it's not too hard. Assuming you're on some vaguely bash-like shell:

pdflatex -halt-on-error file.tex | grep -A3 '^!'

will do the trick. It's completely silent unless it hits an error (a line that starts with "!"), at which point it dies loudly, spitting out the line declaring the error and the following three lines, as well.

I'm not really familiar with latexmk, and a little fiddling with it revealed that it seems to produce a great deal of output besides the output of the programs it calls. Redirecting latexmk's output catches all the output of latex, including the error messages, so you lose them before you can filter them out with grep. latexmk appears to have options to quiet the programs it calls, such as latex and makeindex, but none for quieting latexmk itself. So you may want to write a script which, in a way not unlike the pdflatex command above, quiets the programs you're actually calling individually. Something like:

#!/bin/bash
pdflatex -halt-on-error file.tex | grep -A3 '^!'
makeindex file.idx &> /dev/null
pdflatex -halt-on-error file.tex | grep -A3 '^!'

(makeindex sends all its messages to stderr, so you need the ampersand (or a "2") for this to work.)

Share:
1,962

Related videos on Youtube

mnr
Author by

mnr

Updated on August 11, 2022

Comments

  • mnr
    mnr over 1 year

    Would it be possible to make a wrapper script, or does there exist a sequence of flags -XYZ for latexmk (looking at the manual, it appears not), so that the command behaves in the following way:

    ~/latexmk -XYZ bla.tex
    ~/
    

    if there are no errors in the file. (So latexmk gives exactly NO response), and

    ~/latexmk -XYZ bla.tex
    Error on line 54 in file bla.tex
    ~/
    

    if there are errors.

    It would be great to not see output that is useless.

  • dgoodmaniii
    dgoodmaniii about 9 years
    Did this answer work for you? Did you come up with another solution?