Skip to content

Instantly share code, notes, and snippets.

@saethlin
Created January 17, 2019 04:47
Show Gist options
  • Select an option

  • Save saethlin/9d7570a66fc127ef22692a3fc0b914b1 to your computer and use it in GitHub Desktop.

Select an option

Save saethlin/9d7570a66fc127ef22692a3fc0b914b1 to your computer and use it in GitHub Desktop.
Basically overleaf
#!/usr/bin/env bash
trap "kill 0" SIGINT
HOST=$(cut -d':' -f1 <<<$1)
TEX_PATH=$(cut -d':' -f2 <<<$1)
DIR=`dirname $TEX_PATH`
FILE=`basename $TEX_PATH`
PDF="${FILE/tex/pdf}"
# Script that compiles the LaTeX file on change
SCRIPT=$(<<'EOF'
cd "$DIR"
CHECKSUM=$(cksum "$FILE");
while true;
do if [ \"$(cksum $FILE )\" != \"CHECKSUM\" ]; then
pdflatex -interaction -nonstopmode -file-line-error "$FILE" > /dev/null;
CHECKSUM=$(cksum "$FILE");
else sleep 0.1;
fi;
done;
EOF
)
# Execute the script on the target machine
( ssh $HOST $SCRIPT ) &
# Copy back the compiled pdf
( while true; do rsync -cz "$HOST:$DIR/$PDF" . 2> /dev/null; sleep 0.5; done ) &
ssh $HOST
kill 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment