diff options
| -rwxr-xr-x | bin/latexmk | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/bin/latexmk b/bin/latexmk index 61b68f5..79d497e 100755 --- a/bin/latexmk +++ b/bin/latexmk @@ -3,38 +3,49 @@ set -e [ -n "$DEBUG" ] && set -x +ENGINE=${ENGINE:-tectonic} +ENGINE_ARGS=${ENGINE_ARGS:-} +VIEWER=${VIEWER:-zathura} + reexec= +nocolor= while getopts 1Rnh opt; do case "$opt" in - 1) entr_args='-z' ;; - R) reexec=1 ;; - n) nocolor=1 ;; - h|?) printf "usage: %s [-h]\n" "$(basename "$0")" - printf "\n" - printf " -1 \t oneshot mode\n" - printf " -n \t no color\n" - printf "\n" - exit 2 ;; + 1) entr_args='-z' ;; + R) reexec=1 ;; + n) nocolor=1 ;; + h | ?) + printf "usage: %s [-h]\n" "$(basename "$0")" + printf "\n" + printf " -1 \t only run once\n" + printf " -n \t no color\n" + printf "\n" + exit 2 + ;; esac done shift $((OPTIND - 1)) if [ -n "${reexec}" ]; then - pdf=$(readlink -f -- $(printf $1 | sed 's/\.tex/\.pdf/')); + pdf=$(realpath "$(printf "%s" "$1" | sed 's/\.tex/\.pdf/')") log() { if [ -n "${nocolor}" ]; then - printf "$(tput setaf 2)!>>>$(tput sgr0) $1\n" + printf "%s!==>%s %s\n" "$(tput setaf 2)" "$(tput sgr0)" "$1" else - printf "=> $1\n" + printf "==> %s\n" "$1" fi } - log "running tectonic" - tectonic --chatter=minimal "$1" - if ! pgrep -fx "zathura $pdf" >/dev/null; then - log "running zathura" - swaymsg exec zathura "$pdf" >/dev/null + + # compile the document + log "running ${ENGINE}" + ${ENGINE} ${ENGINE_ARGS} "$1" + + if ! pgrep -fx "${VIEWER} $pdf" >/dev/null; then + # spawn the viewer + log "running ${VIEWER}" + (${VIEWER} "$pdf" >/dev/null 2>&1) & fi - printf -- '!! ' + exit 0 fi |