Repository navigation
Expand file tree
/
Copy pathlize.sh
More file actions
executable file
·71 lines (52 loc) · 2.34 KB
/
Copy pathlize.sh
File metadata and controls
executable file
·71 lines (52 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -euo pipefail
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
PROJECT_ROOT="$SCRIPT_DIR"
export TEXINPUTS=.:$PROJECT_ROOT/tex/:
export SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-0}"
export TZ=UTC
echo "TEXINPUTS=$TEXINPUTS"
# LaTeXize an xml: NOT working yet!
XSLFILE="${2:-article}".xsl
XML_FILE="$1.xml"
TEX_FILE="$1.tex"
AUX_FILE="$1.aux"
PDF_FILE="$1.pdf"
rm "build/$1".* >/dev/null 2>&1 || echo no files to clean
# Forester 5.x outputs XML at output/forest/TREE_ID/index.xml
cp "output/forest/$1/index.xml" "build/$XML_FILE"
# brew install saxon
# bun add xslt3
bunx xslt3 -s:"build/$XML_FILE" -xsl:"assets/$XSLFILE" -o:"build/$TEX_FILE"
# LuaTeX otherwise generates a random PDF trailer ID. Tie it to the generated
# TeX so equal source renders to identical publication bytes across worktrees.
PDF_ID=$(shasum -a 256 "build/$TEX_FILE" | awk '{print toupper(substr($1, 1, 32))}')
WRAPPER_FILE="$1.lize.tex"
printf '\\pdfvariable trailerid {[<%s> <%s>]}\n\\input{%s}\n' "$PDF_ID" "$PDF_ID" "$TEX_FILE" > "build/$WRAPPER_FILE"
cd build || exit
# UNICOCE_LATEX=xelatex
UNICOCE_LATEX=lualatex
# if environment variable TEC is not set
if [ -z "${TEC:-}" ]; then
echo "lize.sh| using $UNICOCE_LATEX"
$UNICOCE_LATEX -halt-on-error -interaction=nonstopmode --shell-escape --jobname="$1" "$WRAPPER_FILE" # >/dev/null # 2>&1
# https://tex.stackexchange.com/a/295524/75671
# biber $TEX_FILE
# We should ignore bibtex errors if it's simply an empty .bib file
bibtex "$AUX_FILE" >/dev/null 2>&1 || echo "lize.sh| Ignoring bibtex error"
$UNICOCE_LATEX -halt-on-error -interaction=nonstopmode --shell-escape --jobname="$1" "$WRAPPER_FILE" # >/dev/null # 2>&1
$UNICOCE_LATEX -halt-on-error -interaction=nonstopmode --shell-escape --jobname="$1" "$WRAPPER_FILE" # >/dev/null # 2>&1
else
echo "lize.sh| using tectonic"
tectonic -Z shell-escape-cwd="$(pwd)" --keep-intermediates --keep-logs --outdir "$(pwd)" "$TEX_FILE" >/dev/null # 2>&1
fi
cd ..
if [ ! -s "build/$PDF_FILE" ]; then
echo "lize.sh| expected a non-empty build/$PDF_FILE" >&2
exit 1
fi
cp "build/$PDF_FILE" "output/forest/$PDF_FILE"
echo "lize.sh| Open build/$1.log to see the log."
echo "lize.sh| Open build/$TEX_FILE to see the LaTeX source."
echo "lize.sh| Open output/forest/$PDF_FILE to see the result."
# use ./lize.sh uts-0001 2>&1|grep lize to see a short output