ulrik@kaizer.se/ hacks/
regenerate latex when changed

I wrote these two scripts, I hope they can help some latex writers.

They depend on the Debian package inotify-tools; using inotify you can watch when a file changes. This script watches a tex file and rebuilds it with pdflatex when it is changed on the disk.

~/bin/onchange

Helper script to run something when a file changes. This works fine with for example gedit. However it will need tweaking for vim or other editors that delete the file and move another in its place when saving.

#!/bin/sh
FILE="$1"
COMMAND="$2"

while inotifywait -e close_write "$FILE"; do
    sh -c "$COMMAND"
done

~/bin/textwatch

A script to watch a tex file. Run as it is. It shows a notification icon in the notification area to show that it is running. Clicking the notification simply terminates the watching script.

#!/bin/sh
FILE="$1"

if test -z $1
then
        FILE=`zenity --file-selection --filename=$HOME/Documents`
        echo $FILE
fi

DIR=`dirname "$FILE"`
FILE=`basename "$FILE"`
cd "$DIR"

TEX="$FILE"
PDF="`echo $FILE | rev | cut --complement -c -4 | rev`.pdf"

test ! -e "$FILE" && echo "No such file" && exit

~/bin/onchange "$TEX" "pdflatex -interaction nonstopmode $TEX; evince $PDF &" &
PID="$!"

zenity --notification --title "LaTeX running" --text "Watching $TEX"
kill $PID

I hope it works. It worked all fine and dandy last time I was writing reports, but I can't make sure since latex isn't even installed right now :)