-
Notifications
You must be signed in to change notification settings - Fork 73
/
compile.sh
executable file
·72 lines (55 loc) · 1.61 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
DIR=$PWD
SRC=$DIR/notes
OUT=$DIR/notes.pdf
CMP=$DIR/compile
WRK=/tmp/ai_notes
TEX=$WRK/notes.tex
function compile_pdf {
# Compile SVGs to PDFs so pandoc can handle them.
cd $SRC/assets
for svg in *.svg; do
rsvg-convert "$svg" -f pdf -o "${svg%.*}.pdf"
done
cd $SRC
# Create working directory
rm -rf $WRK
mkdir -p $WRK
# Insert pagebreaks between documents.
for f in *.md; do
sed '$a\'$'\n''\\pagebreak'$'\n' "$f"
done > $WRK/ai_notes.md
# Copy things over to working directory (bleh)
cp $CMP/template.latex $WRK/
cp $CMP/fonts/{*.otf,*.ttf} $WRK/
cp $CMP/postprocess.py $WRK/
ln -sfn $SRC/assets/ $WRK/assets
cd $WRK
# Process markdown file
python $WRK/postprocess.py $WRK/ai_notes.md $WRK/tmp.md
# Compile to .tex intermediary
pandoc -s tmp.md --latex-engine=xelatex --template=template.latex --mathjax --highlight-style=pygments --chapters -o $TEX
python $WRK/postprocess.py $TEX $WRK/tmp.tex
# Compile to PDF
# Run twice so table of contents works properly, see:
# <http://stackoverflow.com/questions/3863630/latex-tableofcontents-command-always-shows-blank-contents-on-first-build>
xelatex $WRK/tmp.tex
xelatex $WRK/tmp.tex
mv tmp.pdf $OUT
}
function compile_html {
python compile/html/compile.py
}
if [ -z $1 ]; then
echo -e "$(tput setaf 3)Specify 'pdf' or 'html'$(tput sgr0)"
exit
fi
echo "Compiling..."
if [ $1 == 'pdf' ]; then
compile_pdf
elif [ $1 == 'html' ]; then
compile_html
else
echo "Unrecognized format, please specify 'pdf' or 'html'"
exit
fi
echo "Compiled."