My program produces multiple outputs: I have a .tex file compiled, and some of them are produced in the command-line. The compilation info of pdf-latex is useless to me and I would like to hide it to make my command-line output readable.

I have seen this site mention some box-thicking should do it, but I haven't found a command-line equivalent.

4 Answers 4


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 ...
  • 6
    the quiet-option would be perfect, but "pdflatex: unrecognized option '-quiet'"
    – Haxelaar
    Mar 19, 2014 at 8:19
  • 2
    @Haxelaar Hmm, it seems to be present for the MiKTeX 2.9 pdflatex version, but the Arch Linux TeXLive version does not have it indeed. Then redirecting output is your only option. You can leave out the 2>&1 bit if you still want to show errors (and maybe warnings, depending on how pdflatex outputs them).
    – rubenvb
    Mar 19, 2014 at 8:36
  • 15
    Using pdflatex --interaction=batchmode ... hides almost all of the output
    – user30471
    Mar 2, 2017 at 1:51

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.


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.

  • 1
    Welcome to TeX.SX! Very nice contribution!
    – egreg
    Nov 11, 2018 at 15:09
  • Thank you :) I've further improved the proposed answer so that it has disabled stdin when running pdflatex with : command, because it would seem to hang up when it prompts for input (grep doesn't print characters until newline is printed, so you can't possibly know what it's waiting for). Oh and I've found out that pdflatex always prints ! at the start of the line describing problem, so I've also updated the grep expression and added colored output so that you see exactly what have failed. And finally, I've added final pdf/div filename to be printed in the bash script on success.
    – jirislav
    Nov 11, 2018 at 16:34
  • Would you like to submit it to CTAN?
    – egreg
    Nov 11, 2018 at 16:46
  • I've never submitted anything there until now :) .. I've called it pdfla­tex-quiet
    – jirislav
    Nov 11, 2018 at 17:30
  • perhaps you could get in touch with Latexmk maintainer and suggest incorporation into it
    – user4686
    Nov 12, 2018 at 22:31

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

  • Perfect solution
    – Diaa
    Oct 9, 2020 at 22:53

Update 2023-02-05

I have switched to tectonic and no longer use the solution below.

tex-to-pdf compiler bash function

I ended up combining the answers from rubenvb, Andrew and jirislav and putting it as a function in my .bashrc.

Short version

All the output is redirected in a .txt file. The error messages of this file are displayed and the .txt file removed.

You can put the following function in your .bashrc:

function tex-pdf {
        pdflatex -halt-on-error -interaction=nonstopmode $1 > $1.txt
        grep '^!.*' --color=always $1.txt
        rm $1.txt
export -f tex-pdf

You can use it like

$ tex-pdf report

Long version

If you use BibTeX or want to remove files that are created during compilation, but you don't need, you can extend the function in the following way:

function tex-pdf {
    printf "Step 1/4 - pdflatex\n"
    pdflatex -halt-on-error -interaction=nonstopmode $1.tex > $1.txt
    grep '^!.*' --color=never $1.txt

    printf "Step 2/4 - bibtex\n"
    bibtex $1.aux > $1.txt
    grep '^!.*' --color=never $1.txt

    printf "Step 3/4 - pdflatex\n"
    pdflatex -halt-on-error -interaction=nonstopmode $1.tex > $1.txt
    grep '^!.*' --color=never $1.txt

    printf "Step 4/4 - pdflatex\n"
    pdflatex -halt-on-error -interaction=nonstopmode $1.tex > $1.txt
    grep '^!.*' --color=never $1.txt

    rm -f $1.txt $1.aux $1.bbl $1.blg $1.log $1.out $1.toc
export -f tex-pdf

If there are no errors in your code, the output will be:

$ tex-pdf report
Step 1/4 - pdflatex
Step 2/4 - bibtex
Step 3/4 - pdflatex
Step 4/4 - pdflatex

You must log in to answer this question.