-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·65 lines (49 loc) · 1.71 KB
/
build
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
#!/bin/bash
#
# Very simple shorthand script for performing the generation
# commands for compiling the default document.
#
if [[ -z $1 ]]; then
FNAME='default'
else
FNAME=$1
fi
SCRIPT_DIR=$(dirname $0)
IFS='.' read -ra SOURCE_FILE <<< "$FNAME"
SOURCE_TEX="${SOURCE_FILE[0]}.tex"
OUTPUT_AUX="${SOURCE_FILE[0]}.aux"
OUTPUT_PDF="${SOURCE_FILE[0]}.pdf"
OUTPUT_IDX="${SOURCE_FILE[0]}.idx"
SCRATCH_DIR="/dev/shm/$USER/tanagra/${SOURCE_FILE[0]}"
PDFLATEX_OPTIONS="-c-style-errors -output-directory=${SCRATCH_DIR} "
BIBER_OPTIONS="--output-directory $SCRATCH_DIR --quiet"
DELETE_COMMAND=
PDF_VIEWER='evince'
if [[ ! -z $(which trash 2>/dev/null) ]]; then
DELETE_COMMAND='trash'
elif [[ ! -z $(which safe_rm 2>/dev/null) ]]; then
DELETE_COMMAND='safe_rm'
else
DELETE_COMMAND='/bin/rm -f'
fi
if [[ ! -d $SCRATCH_DIR ]]; then
mkdir -p $SCRATCH_DIR || (echo "Unable to create [$SCRATCH_DIR], exiting."; exit)
fi
pdflatex $PDFLATEX_OPTIONS "$SCRIPT_DIR/$SOURCE_TEX"
biber $BIBER_OPTIONS ${SOURCE_FILE[0]}
pdflatex $PDFLATEX_OPTIONS "$SCRIPT_DIR/$SOURCE_TEX"
makeindex "$SCRIPT_DIR/$SOURCE_TEX"
pdflatex $PDFLATEX_OPTIONS "$SCRIPT_DIR/$SOURCE_TEX"
if [[ -f "$SCRIPT_DIR/$OUTPUT_PDF" ]] && [[ "$SCRATCH_DIR/$OUTPUT_PDF" ]]; then
$DELETE_COMMAND "$SCRIPT_DIR/$OUTPUT_PDF"
fi
if [[ -f "$SCRATCH_DIR/$OUTPUT_PDF" ]]; then
mv -f "$SCRATCH_DIR/$OUTPUT_PDF" "$SCRIPT_DIR"
fi
#
# This is just calling evince, a PDF reader, so I can view the final output.
#
if [[ -f "$SCRIPT_DIR/$FNAME.pdf" ]] && [[ ! -z $(which $PDF_VIEWER 2>/dev/null) ]]; then
$PDF_VIEWER $SCRIPT_DIR/$FNAME.pdf &
fi
echo find "$SCRIPT_DIR" -maxdepth 1 -type f -regex ".*\(aux\|bbl\|blg\|log\|nav\|out\|snm\|toc\|bcf\|ind\|ilg\|xml\)$" -exec $DELETE_COMMAND {} \;