Skip to content

Instantly share code, notes, and snippets.

@dingensundso
Created April 20, 2013 16:30
Show Gist options
  • Save dingensundso/5426526 to your computer and use it in GitHub Desktop.
Save dingensundso/5426526 to your computer and use it in GitHub Desktop.
These to scripts monitor the tex-File you're editing and compile it (and tell mupdf to reload) when you made changes. Just start mupdf with "mupdf-latex-launch file.tex" and start working on your masterpiece.
#!/bin/bash
# Licensed under GPL <http://www.gnu.org/licenses/>.
# Slightly edited version of the live-latex-update.sh from vim-live-latex-preview
# <https://aur.archlinux.org/packages/vim-live-latex-preview/>
file="$1"
mupid=$(cat /tmp/llmupdf.pid)
windowid=$(xdotool search --pid $mupid --class MuPDF | head -n1)
logfile="${file%.tex}.log"
auxfile="${file%.tex}.aux"
if head -n 5 "$file" | grep -i -q 'xelatex' > /dev/null 2>&1 ; then
execprog="xelatex"
echo "XeLaTeX document detected."
else
execprog="pdflatex"
echo "Using PDFLaTeX."
fi
if ${execprog} -interaction=nonstopmode -halt-on-error -file-line-error -synctex=1 "$file" ; then
if cat "$logfile" | grep -i -q "undefined citations\|undefined references" > /dev/null 2>&1 ; then
if bibtex "$auxfile" ; then
if ! ${execprog} -interaction=nonstopmode -halt-on-error -file-line-error -synctex=1 "$file" ; then
echo -n "failure" > "$HOME/.config/live-latex-preview/lastresult" 2>/dev/null
echo
echo "failure"
exit 1
fi
else
echo -n "bibfail" > "$HOME/.config/live-latex-preview/lastresult" 2>/dev/null
echo
echo "bibfail"
exit 2
fi
fi
if cat "$logfile" | grep -i -q 'rerun to get' > /dev/null 2>&1 ; then
if ! ${execprog} -interaction=nonstopmode -halt-on-error -file-line-error -synctex=1 "$file" ; then
echo -n "failure" > "$HOME/.config/live-latex-preview/lastresult" 2>/dev/null
echo
echo "failure"
exit 1
fi
fi
if [[ $windowid != "999999" ]] ; then
echo "Updating MuPDF window."
xdotool key --window $windowid r &> /dev/null
fi
echo -n "success" > "$HOME/.config/live-latex-preview/lastresult" 2>/dev/null
echo
echo "success"
else
echo -n "failure" > "$HOME/.config/live-latex-preview/lastresult" 2>/dev/null
echo
echo "failure"
exit 1
fi
exit 0
#!/bin/bash
# This script is beerware. HF
update="latex-mupdf-update"
texfile=$(basename "$1")
opwd=$PWD
cd "$(dirname "$1")"
# Initial compilation
$update $texfile
# Start mupdf
mupdf "${texfile%.tex}.pdf" &>/dev/null &
mupid="$!"
echo $mupid>/tmp/llmupdf.pid
# Get inputfiles so we can check if they've been edited
inputs(){
grep "\\input" $1 | sed 's/^.*\\input{\(.\+\)}.*$/\1.tex/g'
}
while test -d /proc/$mupid; do
# Wait for changes and update
inotifywait -e modify,move_self $texfile $(inputs $texfile) -t 5 2>/dev/null && $update "$texfile"
done
echo "MuPDF was closed."
cd "$opwd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment