feature/intelligent-build #1

Merged
pcabral merged 3 commits from feature/intelligent-build into main 2026-02-21 00:20:09 +01:00
3 changed files with 54 additions and 1 deletions
Showing only changes of commit c3cbc61406 - Show all commits

19
.vscode/settings.json vendored
View File

@@ -1,3 +1,20 @@
{
"latex-workshop.latex.recipe.default": "latexmk (xelatex)"
"latex-workshop.latex.recipes": [
{
"name": "Smart LaTeX Build",
"tools": ["smart-build"]
}
],
"latex-workshop.latex.tools": [
{
"name": "smart-build",
"command": "bash",
"args": [
"%WORKSPACE_FOLDER%/build/build-latex-smart.sh",
"%DOC%"
]
}
],
"latex-workshop.latex.recipe.default": "Smart LaTeX Build",
"latex-workshop.formatting.latex": "latexindent"
}

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