Marcel Kapfer

Bash script for LaTeX users

2015-01-06

77 words, ~1min reading time

tex bash latex

Here a little shell script for LaTeX users who dont use an LaTeX IDE and who often use the command pdflatex. With this script is it possible to do so in regulary times automatically. It is also possible to tell the script how often it should build the PDF-file and how much time should be between these builds. Before you can use this script you have to make it executable with the command chmod +x buildpdf.sh.

#!/bin/bash
# A script for automatically creating PDf files from a latex document
# You can set the amounts of builds and the time between these builds
# Usage: ./buildpdf.sh filename [build amount] [time between builds in s]
# Marcel Michael Kapfer
# 6th January 2015
# GNU GPL v3.0 -> Feel free to re-distribute it or fork it
if [[ -z "$1" ]]; then
    echo "Usage: ./buildpdf.sh filename [build amount] [time between builds in s]"
    exit 1
else
    filename=$1
fi
if [[ -z "$2" ]]; then
    builds=1
else
    builds=$2
fi
if [[ -z "$3" ]]; then
    sleeptime=120
else
    sleeptime=$3
fi
for ((i=1; i<=$builds; ++i)) ;
do
    pdflatex $filename
    echo "Build $i ready"
    if (( i < builds )); then
        echo "Waiting $sleeptime seconds - then build again"
        sleep $sleeptime
    fi
done

I would like to hear what you think about this post. Feel free to write me a mail!

Reply by mail