Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-reload pdf viewer while editing latex files

I use the llpp pdf viewer when editing my LaTeX files. To have it automatically refreshing the pdf file when I compile, I use a wrapper to launch it (cf. this).

The part handling the waiting and refreshing is this one :

inotifywait -m -e close_write $1 | while read; do
    kill -HUP $pid_llpp
done &

My problem is the following : whenever an error occurs in the compilation of the tex file, no pdf output is procuded and llpp is closing. I tried something like that :

inotifywait -m -e close_write $1 | while read; do
    if [ -a $1 ]
    then
        kill -HUP $pid_llpp
    fi
done &

It works partially : when an error occurs during the compilation, llpp doesn't close but does not refresh anymore...

Could anyone help me to solve this problem ?

like image 515
Pece Avatar asked Nov 04 '22 02:11

Pece


1 Answers

Update: Since release v26 llpp ships the wrapper script in an polished version! You find it as misc/llpp.inotify in the llpp distribution.


I pushed a partial fix to your problem (full script here):

inotifywait -m -e close_write "$PWD" | while read dir ev file; do
if [ "$file" = "$pdf" ] && [ -e "$pdf" ]; then
    kill -HUP $pid_llpp
fi
done &

This checks whether the current pdf file is still available and only then fires the update event. This is similar to what you have done. However I can still be the case that llpp will close as the file might disappear directly after the check. I have no idea how to tackle this.

The problem of not refreshing after the error has been fixed is solved by watching the folder containing the pdf and filtering out the events for the pdf. If inotify is call directly on the file it seems to miss all events after delete.

If you are still interested in it, please let me know if it works for you.

(As a side note: The wrapper is now also able to pass flags to llpp)

like image 153
Pascal Wittmann Avatar answered Nov 08 '22 03:11

Pascal Wittmann