added smart build

This commit is contained in:
Pedro Cabral
2026-02-21 00:15:52 +01:00
parent 0df5a0a64c
commit c3cbc61406
2 changed files with 53 additions and 1 deletions

35
build/build-latex-smart.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
set -euo pipefail
# Color definitions
BOLD='\033[1m'
RED='\033[31m'
BLUE='\033[34m'
RESET='\033[0m'
# Ensure a file parameter is passed
if [[ $# -lt 1 ]]; then
echo -e "${BOLD}${RED}Error${RESET}${RED}: No .tex file provided.${RESET}"
echo "Usage: $0 <file.tex>"
exit 1
fi
FILE="$1"
# append .tex file extension, iff not already passed
[[ "$FILE" != *.tex ]] && FILE="${FILE}.tex"
# Check that the file exists
if [[ ! -f "$FILE" ]]; then
echo -e "${BOLD}${RED}Error${RESET}${RED}: File '$FILE' not found.${RESET}"
exit 1
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"
else
echo -e "${BLUE}No active fontspec → Using pdfLaTeX${RESET}"
pdflatex -synctex=1 -interaction=nonstopmode -file-line-error "$FILE"
fi