From 4f7ccffecdfa36c5e531654b8eec44199935d497 Mon Sep 17 00:00:00 2001 From: davidpkj Date: Wed, 24 Aug 2022 20:30:48 +0200 Subject: added box scripts --- scripts/compile | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 scripts/compile (limited to 'scripts/compile') diff --git a/scripts/compile b/scripts/compile new file mode 100755 index 0000000..f038562 --- /dev/null +++ b/scripts/compile @@ -0,0 +1,64 @@ +#!/bin/bash + +# A script to compile any (here defined) type of text file to a target format +# Depends on: bash, basename, pdflatex +# By David Penkowoj, 2021/08/02 + +# Function to compile .lp to .pdf files +LP_TO_PDF() { + lilypond "$1" --pdf -s -o "$2.pdf" && + printf "Successfully compiled %s to %s\n" "$1" "$2.pdf" || + printf "[ Error ] Couldn't compile %s\n" "$1" +} + +# Function to compile .md to .pdf files +MD_TO_PDF() { + pandoc "$1" -o "$2.pdf" && + printf "Successfully compiled %s to %s\n" "$1" "$2.pdf" || + printf "[ Error ] Couldn't compile %s\n" "$1" +} + +# Function to compile .tex to .pdf files without making a mess +TEX_TO_PDF() { + printf "If the script seems to hang, try pressing \n" + + pdflatex "$1" > /dev/null && + pdflatex "$1" > /dev/null && # This is to ensure certain tex elements being drawn + rm -rf "$2.toc" "$2.log" "$2.aux" && + printf "Successfully compiled %s to %s\n" "$2.tex" "$2.pdf" || + printf "[ Error ] Couldn't compile %s\n" "$2.tex" +} + +# Check if file exists +if [[ -e "$1" ]]; then + # Determine filename and extension + FILENAME="$(basename -- "$1")" + EXTENSION="${FILENAME##*.}" + + # Check if there is a extension at all + if [[ "$FILENAME" == "$EXTENSION" ]]; then + printf "[ Error ] The specified file has no extension\n" + exit 1 + fi + + # Do the respective compile actions + case "$EXTENSION" in + "tex") + TEX_TO_PDF "$1" "${FILENAME%.*}" + ;; + "md") + MD_TO_PDF "$1" "${FILENAME%.*}" + ;; + "lp") + LP_TO_PDF "$1" "${FILENAME%.*}" + ;; + "pov") + povray "$1" + ;; + *) + printf "[ Error ] There is no entry on how to handle '%s' files.\n" "$EXTENSION" + exit 1 + esac +fi + +exit 0 -- cgit v1.2.3