Skip to content

Instantly share code, notes, and snippets.

@yig
Created January 15, 2016 04:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yig/dc648aef95e7a44217be to your computer and use it in GitHub Desktop.
Save yig/dc648aef95e7a44217be to your computer and use it in GitHub Desktop.
Runs latexmk in continuous mode. Runs quickly (draft mode followed by batch mode). Plays a ding sound when finished. Also copies the PDF aside, so that PDF viewers don't get confused by the partially-written PDF files.
#!/bin/bash
## I used cfxr to create a coin sound. afplay is an OS X command line sound playback tool.
DING='afplay -v .01 /mixed\ media/music/cfxr\ coin.wav'
## Silence the ding.
# DING=''
## Simple continuous ding with draft mode followed by a batch mode run which actually generates the PDF.
## Copies the PDF with the suffix -copy.pdf, so that live-updating PDF viewers don't choke trying to load the PDF while it is still being written.
### We can't distinguish between the first time latexmk launches the viewer regardless of changes and later launches of the viewer with changes.
### If we could find a way to make latexmk think the viewer is always already running, we could make $pdf_preview just call open.
### Since we can't, the pdf_previewer and pdf_update_command should both actually run pdflatex:
### UPDATE: Added synctex. You will need to make a symlink from "paper.synctex.gz" to "paper-copy.synctex.gz".
### UPDATE: Move the PDF instead of copying it, which is faster, atomic, and uses less space. touch the original filename to keep latexmk happy.
echo "Don't forget to symlink paper.synctex.gz to paper-copy.synctex.gz:"
echo " " ln -s paper.synctex.gz paper-copy.synctex.gz
echo
latexmk -pdf -pvc -pdflatex='pdflatex -draftmode -interaction=nonstopmode %O %S && touch %D' -e '$pdf_update_command=$pdf_previewer=q|nostart pdflatex -interaction=batchmode -synctex=1 %R ; /bin/mv %S %R-copy.pdf ; touch %S ; '"${DING}"'|' -e '$pdf_update_method=4' "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment