-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateIMG.sh
executable file
·48 lines (43 loc) · 1.14 KB
/
generateIMG.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
#!/bin/bash
BASE_PATH=$(cd $(dirname $0) && pwd -P)
VERBOSE=false
DEBUG=false
generateIMG(){
# FIXME: test file is .tex
file=${1%.*}
$VERBOSE && echo "Generating SVG and PNG from $1"
$DEBUG && OUT=/dev/stdout || OUT=/dev/null
pdflatex -interaction=nonstopmode -output-directory=/tmp "${file}.tex" >$OUT \
&& pdf2svg "/tmp/$(basename ${file}).pdf" "${file}.svg" \
&& rsvg-convert --output "${file}.png" "${file}.svg"
RESULT=$?
$VERBOSE && echo "Result: $([ $RESULT == 0 ] && echo OK || echo NOK)"
}
usage(){
echo "Usage: `basename $0` [-v] [-d] PATH..." >&2
echo " -v Verbose mode" >&2
echo " -d Debug mode (implies verbose)" >&2
}
while getopts vd opt; do
case "$opt" in
v) VERBOSE=true;;
d) VERBOSE=true; DEBUG=true;;
*) usage; exit 1;;
esac
done
shift $(($OPTIND-1))
if [ "$#" -eq 0 ]; then
usage
exit 1
fi
for path in "$@"; do
if [ -d "$path" ]; then
for file in "$path"/*; do
generateIMG "$file"
done
elif [ -f "$path" ]; then
generateIMG "$path"
else
echo "$path: file or folder not found"
fi
done