deleting auto-generated files, iff pdf was successfully rendered

This commit is contained in:
Pedro Cabral
2026-07-17 12:22:46 +02:00
parent b15d162916
commit 35e9e3ae5a

View File

@@ -19,6 +19,9 @@ FILE="$1"
# append .tex file extension, iff not already passed
[[ "$FILE" != *.tex ]] && FILE="${FILE}.tex"
# remove the .tex extension from the file name to get the base name
BASE="${FILE%.tex}"
# Check that the file exists
if [[ ! -f "$FILE" ]]; then
echo -e "${BOLD}${RED}Error${RESET}${RED}: File '$FILE' not found.${RESET}"
@@ -28,8 +31,24 @@ fi
# Detect active \usepackage{fontspec} (ignore commented lines)
if grep -Eq '^[^%]*\\usepackage\{fontspec\}' "$FILE"; then
echo -e "${BLUE}Detected fontspec → Using XeLaTeX${RESET}"
xelatex -synctex=1 -interaction=nonstopmode -file-line-error "$FILE"
LATEX_CMD=(xelatex -synctex=1 -interaction=nonstopmode -file-line-error "$FILE")
else
echo -e "${BLUE}No active fontspec → Using pdfLaTeX${RESET}"
pdflatex -synctex=1 -interaction=nonstopmode -file-line-error "$FILE"
LATEX_CMD=(pdflatex -synctex=1 -interaction=nonstopmode -file-line-error "$FILE")
fi
"${LATEX_CMD[@]}"
rm -f \
"${BASE}.aux" \
"${BASE}.bbl" \
"${BASE}.bcf" \
"${BASE}.blg" \
"${BASE}.fdb_latexmk" \
"${BASE}.fls" \
"${BASE}.log" \
"${BASE}.out" \
"${BASE}.run.xml" \
"${BASE}.synctex.gz" \
"${BASE}.toc" \
"${BASE}.xdv"