forked from ilammy/lisp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·88 lines (69 loc) · 1.88 KB
/
build.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
JOBNAME='lisp'
MAIN_FILE='!main.tex'
FIGURES_FILE='!figures_only'
INDEX_FILES='lisp-eng.idx lisp.idx'
LATEX_KEYS="-jobname=$JOBNAME -interaction=batchmode"
ROOT=$PWD
function prepare_pdf {
echo "== Preparing PDF =="
cd $ROOT/book-src
if command -v git >/dev/null 2>&1
then
git log -1 --format='\newcommand{\GitCommit}{%H}
\newcommand{\GitCommitDate}{%ci}' > git-version.tex
fi
pdflatex $LATEX_KEYS $MAIN_FILE
python $ROOT/makeindex.py $INDEX_FILES > $JOBNAME.ind
pdflatex $LATEX_KEYS $MAIN_FILE
python $ROOT/makeindex.py $INDEX_FILES > $JOBNAME.ind
pdflatex $LATEX_KEYS $MAIN_FILE
echo "== Done =="
mv $JOBNAME.pdf $ROOT
rm -f *.aux *.idx *.ind *.log *.out *.toc git-version.tex
}
function prepare_epub {
mkdir $ROOT/epub/OEBPS/images
echo "== Rendering images =="
cd $ROOT/book-src
pdflatex $LATEX_KEYS $FIGURES_FILE
pdflatex $LATEX_KEYS $FIGURES_FILE
mv $JOBNAME.pdf $ROOT/epub/OEBPS/images
rm *.aux *.log *.out
echo "== Converting to PNG =="
cd $ROOT/epub/OEBPS/images
convert -monitor -density 300 $JOBNAME.pdf -trim -quality 90 png%02d.png
rm $JOBNAME.pdf
echo "== Packaging EPUB =="
cd $ROOT/epub
for size in `ls $ROOT/epub/fontconfig`
do
echo " - ${size%.css}"
cp $ROOT/epub/fontconfig/$size $ROOT/epub/OEBPS/zz_fontsize.css
zip --quiet --recurse-paths --compression-method deflate \
--unicode UTF8 $JOBNAME-${size%.css}.epub mimetype META-INF OEBPS
done
echo "== Done =="
mv *.epub $ROOT
rm -rf $ROOT/epub/OEBPS/images
rm -f $ROOT/epub/OEBPS/zz_fontsize.css
}
function print_usage {
echo "Usage: $0 [epub | pdf]"
}
if [ $# -gt 1 ]
then
print_usage
exit 1
fi
case "$1" in
epub)
prepare_epub
;;
pdf|"")
prepare_pdf
;;
*)
print_usage
exit 1
esac