Parse tex root for more complex latex files

Allows parsing texroot comments so that you can compile a LaTeX document from outside of the document root, as long as it contains the usual magic comment format:
% !TEX root = doc.tex
This commit is contained in:
snailed 2022-08-10 11:53:24 +00:00 committed by GitHub
parent 606905268f
commit d92287afe0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,8 @@ cd "$dir" || exit 1
textype() { \ textype() { \
command="pdflatex" command="pdflatex"
texroot=$(grep -Poi "^ *% *\! *tex root *= *\w+(?:\.\w*)?" "$file" | cut -d "=" -f 2 | tr -d "[:blank:]")
[ -n "$texroot" ] && base=$texroot && echo "Compiling from TeX root: $texroot"
( head -n5 "$file" | grep -qi 'xelatex' ) && command="xelatex" ( head -n5 "$file" | grep -qi 'xelatex' ) && command="xelatex"
$command --output-directory="$dir" "$base" && $command --output-directory="$dir" "$base" &&
grep -qi addbibresource "$file" && grep -qi addbibresource "$file" &&