Stuck in the era of using latex, I could only use a few tricks to make it a bit less painful.

My setup is a bit special (or weird); I use mac as the GUI, mosh to my Linux server, and Dropbox for syncing. Therefore, I would edit tex file in my editor via mosh, and see updated pdf after Dropbox syncs it.

Preview could do auto refresh, but it jumps to the beginning of the current page; it’s quite annoying to scroll back to the intended region and re-focus. Skim was recommended in a few places while searching for a solution to this problem, so I gave it a try. Unfortunately, Skim doesn’t work so well with Dropbox synced files. The reason seems to be that Dropbox firstly removes the original and download the new one from their server, while Skim is tracking the file object, hence it wouldn’t work.

Fortunately, Skim provides ways for “manually” refreshing; see more at https://sourceforge.net/p/skim-app/wiki/TeX_and_PDF_Synchronization/#reload-updated-pdf-files

Since I build latex on another computer, the pdflatex part doesn’t apply. Here’s the script tailored to my personal requirement:

1
2
3
4
5
6
7
8
9
10
11
12
$ cat ~/pdf_mac.sh
pdffile=$1
/usr/bin/osascript << EOF
set theFile to POSIX file "${pdffile}" as alias
tell application "Skim"
# uncomment the folloing line if you want Skim to get the focus
# activate
set theDocs to get documents whose path is (get POSIX path of theFile)
if (count of theDocs) > 0 then revert theDocs
open theFile
end tell
EOF

This gives us the way to control the refresh in Skim from command line.

Now, we just need to get the notification when the file is changed by Dropbox. For that, fswatch does the job well.

Define a function in the shell:

1
mpdf() { fswatch $1 | while read file ; do ; ~/pdf_mac.sh $file; done }

Then, I would just use mpdf <file.pdf> to monitor pdf file.

All in all, we deserve something better than latex.