forked from openframeworks/ofBook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_ofBook.sh
executable file
·73 lines (58 loc) · 1.78 KB
/
create_ofBook.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
#!/usr/bin/env bash
# Shell script for creating the OF book!
# requires Pandoc 1.12
# Pandoc options here: http://johnmacfarlane.net/pandoc/README.html#synopsis
USAGE="Usage:
./create_ofBook.sh html
./create_ofBook.sh pdf
./create_ofBook.sh tex
List detected files:
./create_ofBook.sh debug"
if [ -z "$1" ]
then
echo "No argument supplied!"
echo "$USAGE"
exit 1
fi
# general options:
GENERAL_OPTS="-N --smart --toc --toc-depth=4 -s -p"
# Latex-related options
# Note: PDF output requires Latex, too
# Note: requires xetex currently due to UTF8 problems with regular latex
LATEX_OPTS="--latex-engine=xelatex -V papersize=a4 -V documentclass=scrbook -V links-as-notes"
# html-related options
HTML_OPTS="--self-contained --mathml"
# Find chapter files
FILES=$(find $(pwd) -type f -name "chapter.md" | sort | tr "\n" " ")
# put all the images into an images folder in the root folder, so that
# pandoc finds them from relative links
#mkdir -p images
#rm -rf ./images/*
#cp ./*/images/*.* ./images/
# option string construction
if [ "$1" = "html" ] ; then
OPTS="$GENERAL_OPTS $HTML_OPTS"
elif [ "$1" = "tex" ] ; then
OPTS="$GENERAL_OPTS $LATEX_OPTS"
elif [ "$1" = "pdf" ] ; then
OPTS="$GENERAL_OPTS $LATEX_OPTS"
elif [ "$1" = "debug" ] ; then
echo "List of discovered files:"
echo $FILES
exit 0
else
echo "Invalid argument $1!"
echo "$USAGE"
exit 1
fi
#create the book
#pandoc $FILES $OPTS -o ofBook.$1
for f in */chapter.md; do sed "s/\!\[\([^]]*\)\](\([^)]*\))/\![\1](`dirname $f`\/\2)/g" $f | sed "s/<img src=\"\([^\"]*\)\"/<img src=\"`dirname $f`\/\1\"/g"; printf "\n\n\n\n"; done | pandoc $OPTS -o ofBook.$1
retval=$?
if [ "$retval" == 0 ] ; then
#remove temporary image folder
rm -rf ./images
else
echo "Some error occured!"
fi
exit $retval