Kjell-Magne Øierud

Software developer

Autocompile LaTeX documents 28 Oct 2014

A small shell snippet that will automatically run pdflatex when the source file is changed. It will display a nice Notification Center message (OS X only :-/ ) if the compile fails.

while true; do
  if [ something.tex -nt something.pdf ]; then
    pdflatex --interaction=nonstopmode cv.tex || \
      osascript -e 'display notification "Latex compilation failed" with title "ERROR"'
      sleep 1
  fi
done

And here is a version using fswatch:

fswatch -i 'something.tex' -e '.*' . | \
  xargs -t -n1 -I % \
    bash -c "pdflatex % || osascript -e 'display notification \"Latex compilation failed\" with title \"ERROR\"'"

Copyright © 2008–2017 Kjell-Magne Øierud.