-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.sh
56 lines (56 loc) · 2.33 KB
/
compile.sh
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
#!/bin/bash
BUILDDIR_FULL=$BIND_PATH/$BUILD_DIRECTORY
if [ ! "$CLEAN_BUILD" = "" ] && [ -d "$BUILDDIR_FULL" ]; then
rm -r "$BUILDDIR_FULL"
fi
mkdir -p "$BUILDDIR_FULL"
cp -r -u "$BIND_PATH"/* "$BUILDDIR_FULL/"
cd "$BUILDDIR_FULL"
# save old pdf
if [ "$DISABLE_DIFFPDF" = "" ]; then
if [ -f "$BIND_PATH/$TARGET.pdf" ]; then
cp -u "$BIND_PATH/$TARGET.pdf" "$TARGET-old.pdf"
else
echo "$TARGET.pdf doesn't exist, not generating diff!"
fi
fi
# this variable is empty by default -> fill to disable
if [ "$DISABLE_PYTHONTEX" = "" ]; then
# we could use a bare pdflatex here
# however, latexrun itself is smart enough to only run pdflatex once
# don't print the output since latexrun will be re-run anyway
python3 /latexrun.py --latex-args=--shell-escape --bibtex-cmd biber -O . $WARNINGS $TARGET > /dev/null
if [ -f "$TARGET.pytxcode" ]; then
# only run pythontex if a pytxcode file was generated
# this prevents the useless invocation of pythontex when the package wasn't used at all
if ! pythontex --interpreter python:python3 $TARGET &> "$BUILDDIR_FULL/$TARGET.pythontex.log"; then
# ony forward the pythontex log output if errors occured - we don't care otherwise
cat "$TARGET.pythontex.log"
fi
fi
fi
LATEX_ARGS="--shell-escape"
if [ "$DISABLE_SYNCTEX" = "" ]; then
LATEX_ARGS="$LATEX_ARGS --synctex=1"
fi
# this is a && chain - new files won't be copied if the build fails
python3 /latexrun.py --latex-args="$LATEX_ARGS" --bibtex-cmd biber -O . $WARNINGS $TARGET || exit
if [ "$DISABLE_SYNCTEX" = "" ]; then
# extract, rewrite and re-gz synctex
gunzip $TARGET.synctex.gz
# use python to re-write file paths (sed kept messing with windows' backslashes)
python3 -c "import sys; print(sys.stdin.read().replace(*sys.argv[1:3]))" "$BUILDDIR_FULL" "$HOST_PATH" < $TARGET.synctex > synctex.temp
mv synctex.temp $TARGET.synctex
# LaTeX workshop uses an uncompressed .synctex file instead of .synctex.gz so we don't have to recompress it
cp -u "$TARGET.synctex" "$BIND_PATH/$TARGET.synctex"
fi
if [ -f "$TARGET-old.pdf" ]; then
xvfb-run diff-pdf -v -m -s --output-diff="$TARGET-diff.pdf" "$TARGET-old.pdf" "$TARGET.pdf"
rm "$TARGET-old.pdf"
cp -u "$TARGET-diff.pdf" "$BIND_PATH/$TARGET-diff.pdf"
fi
cp -u "$TARGET.pdf" "$BIND_PATH/$TARGET.pdf"
if [ ! "$DELETE_TEMP" = "" ]; then
cd /
rm -r "$BUILDDIR_FULL"
fi