diff --git a/build/build-latex-smart.sh b/build/build-latex-smart.sh index aaf9f79..983bd1f 100755 --- a/build/build-latex-smart.sh +++ b/build/build-latex-smart.sh @@ -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"