3

I run a sequence of latex commands from a bash script. Since the latex output polutes the scripts own output I would like to suppress it. But sending the output to /dev/null will make the latex process inaccesible for the user. Hence it could be killed only manually in case there is a compilation error. How can I control latex from within the script. I.e. suppress the output and exit the process in case of error.

7
  • 1
    Did you try pdflatex --interaction=batchmode?
    – egreg
    Commented Jul 16, 2012 at 15:27
  • Try this: pdflatex -halt-on-error file.tex 1> /dev/null [[ $? -eq 1 ]] && echo "msg in case of erros" && exit With this, in case of errors, the msg will appear. Otherwise, the output will be send to null.
    – Sigur
    Commented Jul 16, 2012 at 16:45
  • @Thiago this appears to work, but hangs if the file.tex doesn't exist (which is one possible error). Commented Jul 17, 2012 at 16:08
  • So you can try to check first if the file exists. The variable $? has the result of any command. Usually it could be zero or not. You can test it.
    – Sigur
    Commented Jul 17, 2012 at 19:58
  • 1
    @Sigur Can you turn your comments into an answer, please?
    – egreg
    Commented Nov 3, 2012 at 22:12

1 Answer 1

4

As asked above by egreg, I'm turning my comments into answer.

I'm using this command om my script and I'm satisfied with it.

pdflatex -halt-on-error file.tex 1> /dev/null 
[[ $? -eq 1 ]] && echo "msg in case of erros" && exit

In case of errors, the msg will appear. Otherwise, the output will be send to null.

Now, you can try to improve with a command to search for your file before running pdflatex.

2
  • 1
    Not the best bash I've seen in my life... 1> is funny, so is the && exit. Also, [[ $? -eq 1 ]] is not the best idea, just in case pdflatex returns another (non-zero) code. How about (( $? )) && echo "msg in case of errors" instead ? Commented Nov 4, 2012 at 0:00
  • I don't know. For me, it works! But if there are better solutions, thanks for helping.
    – Sigur
    Commented Nov 4, 2012 at 0:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .