pdflatex commandline hide compilation output

You can either redirect all of the pdflatex output:

  • for sh: pdflatex ... > /dev/null 2>&1
  • for cmd: pdflatex ... > NUL 2>&1

Or you can use the -quiet option:

pdflatex -quiet ...

In my case, there is no -quiet mode. So I had to use -interaction=batchmode argument as suggeseted by Andrew's comment.

But then another problem arised - you will not see what went wrong and why, because errors are also suppressed with batchmode.

The result I end up using is to suppress all pdflatex's output by using grep to output only errors:

: | pdflatex -halt-on-error src.tex | grep '^!.*' -A200 --color=always 

I use -halt-on-error because you basically can't use interactive mode in case of error (grep disables dialog between program and user). Also, to make sure that pdflatex does never prompt for the input, let's pipe in command with no output (: command).

Let me also explain the grep arguments:

  • ^!.*
    • string to search for in the output from pdflatex
    • it matches all lines that start with !, which are considered error lines
  • -A200
    • output 200 lines after every match
    • this way I make sure to print also the relevant information followed after the matched error lines
  • --color=always
    • this provides us colored output so that we can clearly see what went wrong and why - the problem is bold red

Wrapper script

I've created a wrapper script to provide more convenient solution exactly for this purpose. It's usage is almost the same as pdflatex / pdftex itself. You can check it out as a CTAN package or as a GitLab repository.

Quickinstall

And here is how to install the latest version using this oneliner:

curl -s https://gitlab.com/jirislav/pdftex-quiet/raw/latest/pdftex-quiet | \
    sudo tee /usr/local/bin/pdftex-quiet >/dev/null \
    && sudo chmod +x /usr/local/bin/pdftex-quiet \
    && sudo ln -sf /usr/local/bin/pdftex-quiet /usr/local/bin/pdflatex-quiet

Here is an example of how you run the wrapper script:

pdftex-quiet compile-me.tex
# You may also provide additional attributes to `pdflatex`
pdflatex-quiet -output-format=dvi -output-directory=/tmp compile-me.tex

You can also show version or help of the pdflatex-quiet / pdftex-quiet script:

pdflatex-quiet -v  # or --version
pdflatex-quiet -h  # or --help

Also the difference between pdflatex-quiet and pdftex-quiet, as explained here is respected - thanks to Denis Bitouzé's comment.


FWIW, https://ctan.org/pkg/texfot was my attempt at solving this problem -- eliminating the verbose output from tex engines while still showing the interesting messages (the ones I actually want to do something about). --karl