I wanted to use the script you posted in your final answer.
Unfortunately, it didn’t work with my setting (MacVim with vim-latexsuite, Skim as the viewer and XeTeX). I also use forward search (i.e. I use the feature that pressing \ls in Vim will jump to the corresponding point in the PDF document in the open viewer).
Furthermore, my document isn’t called thesis.tex
(big surprise; it’s not a thesis). I’ve therefore done some more configuration work that I’d like to share. Attention, my bash skills are horrible.
#!/bin/bash
set -x
ulimit -t 10 # sometimes pdflatex gets stuck
if [ "$1" = "" ]; then
echo "No target name specified"
exit 1
fi
TARGET=$1
SOURCE=$1.tex
TMPSOURCE=_$TARGET.tex
TMPTARGET=_$TARGET
while [ 1 ]; do
# Compile a different file ($TMPSOURCE.pdf) so that it doesn't reload mid-compile
cp $SOURCE $TMPSOURCE
# better than running pdflatex manually, as this wont rebuild if there's nothing there.
latexmk -pdf -silent $TMPTARGET > /dev/null
# For rubber-info
cp $TMPTARGET.log $TARGET.log
if [ -e $TMPTARGET.pdf ]; then # Check the compile succeeded first
# No output file yet.
[ ! -e $TARGET.pdf ]
HASNOPDF=$?
# ignore if it's unchanged.
# OS X diff doesn't consider binary files. Single-line output, return value 2
diff $TARGET.pdf $TMPTARGET.pdf
OUTPUTDIFFERS=$?
if [ $HASNOPDF -eq 0 -o $OUTPUTDIFFERS -ne 0 ]; then
# Do NOT RM since Skim cannot deal with this.
cp $TMPTARGET.pdf $TARGET.pdf
fi
fi
sleep 1 # give it time to be killed by a CTRL-C
done
This compiles a temporary file and copies it back to whatever name was given (instead of the other way round as your script does); usage of the script:
./scriptname project
Where project
is the name of the TeX file, without file extension.
I’ve also changed the rubber-info
line:
autocmd FileType tex exe "set makeprg=rubber-info\\ _" . expand("%:t:r") . ".log"
And I needed to patch my latexmk
to use XeTeX since the name of the executable was hard-coded.
Unfortunately, this still destroys the output PDF file when I’ve saved my document before completing a statement, since latexmk
seems to always produce a PDF file, even on error – and its return code is always 0, which sucks.
(To clarify this, say that I’ve just typed emph{
into my document and save it. The background script will promptly compile the document, and fail. But it will still produce a (largely empty) output file).
Additionally, forward search no longer works properly; it basically jumps to a wrong point in the document. I suspect that this has something to do with my copying the document before compilation.
So, this is still a completely unsatisfactory solution, even though I didn’t even enable continuous saving on typing in MacVim yet.