VSCode_LaTeX/scripts/pdflatex.sh

24 lines
779 B
Bash
Executable File

#!/bin/bash
FILEDIRNAME=${1%/*}
FILE=${1##*/}
echo "fileDirname : $FILEDIRNAME"
echo "file : $FILE"
if [ ${FILE: -4} == ".tex" ]; then
cd "$FILEDIRNAME"
pdflatex -synctex=1 -interaction=nonstopmode -output-directory="$FILEDIRNAME" "$FILE" > ~/.vscode/.pdflatex_log
if [ $? == 0 ]; then # check success status (return value) of the last command (pdflatex)
echo -e "\033[32mCreated \"${FILE%.*}.pdf\" successfully.\033[0m";
# lsof -- "${FILE%.*}.pdf" > /dev/null; # check if .pdf file if allready opened
# if [ $? != 0 ]; then
# ( nohup evince "${FILE%.*}.pdf" > /dev/null; exit; ) # open the created .pdf
# fi
else
cat ~/.vscode/.pdflatex_log
echo -e "\033[31mERROR: Compiling \"${FILE}\" failed.\033[0m";
fi
else
echo "$FILE is not a *.tex file."
fi