-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimgcompile.sh
executable file
·125 lines (123 loc) · 3.2 KB
/
imgcompile.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
USR="$(pwd)"
CUR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $USR
SUB=false
PDF=true
IMG=false
BACKGROUND=true
COMPDIR=""
COMPBOOL=false
COMPILED=""
FLAGS=""
for ARG in $@;
do
if [ "$COMPBOOL" = true ] && [ ! -f $ARG ]
then
cd $USR
cd $ARG
COMPBOOL=false
if [ ! -d $ARG ]
then
mkdir $ARG
fi
COMPDIR="$(pwd)"
FLAGS+="-d $COMPDIR "
cd $USR
continue
fi
case $ARG in
"--help")
echo "Usage:"
echo " Pass .tex files in any argument position for compilation"
echo " Pass directories to compile all .tex files in the directory"
echo "Flags:"
echo " -i: converts all latex files to jpg or png (see nobackground) following this flag with imagemagick"
echo " -s: compiles the subdirectories of all directories after this flag"
echo " -d: takes the next non-file in the list as arguments as a compilation directory"
echo " --nopdf: removes the compiled pdf file"
echo " --nobackground: converts files to .png with no background instead of .jpg"
continue
;;
"-i")
IMG=true
FLAGS+="-i "
continue
;;
"-s")
SUB=true
FLAGS+="-s "
continue
;;
"-d")
COMPBOOL=true
continue
;;
"--nopdf")
PDF=false
FLAGS+="--nopdf "
continue
;;
"--nobackground")
BACKGROUND=false
FLAGS+="--nobackground "
continue
;;
esac
if [ ! -d $ARG ] && [ ! -f $ARG ]
then
echo "file or directory doesn't exist"
continue
fi
if [ -d $ARG ]
then
cd $ARG
$CUR/imgcompile.sh $FLAGS $(find . -name "*.tex")
if [ "$SUB" = true ]
then
SUBDIRECTORIES=$(find -maxdepth 1 -type d)
$CUR/imgcompile $FLAGS $SUBDIRECTORIES
fi
continue
else
TEX=${ARG##*/}
NAME=${TEX%%.tex}
if [ "${TEX##*.}" != "tex" ]
then
echo Not a .tex file. Skipping...
continue
fi
DIR=${ARG%%/$TEX}
cd $DIR
pdflatex -interaction=batchmode $TEX
if [ "$PDF" = true ]
then
COMPILED+="$NAME.pdf "
else
rm "$NAME.pdf"
fi
if [ "$IMG" = true ]
then
if [ "$BACKGROUND" = true ]
then
convert -quality 100 "${TEX%%.tex}.pdf" "$NAME.jpg"
COMPILED+=$(find . -name "$NAME*.jpg")
else
convert -quality 100 "${TEX%%.tex}.pdf" "$NAME.png"
COMPILED+=$(find . -name "$NAME*.png")
fi
fi
rm "$NAME.aux" "$NAME.log"
if [ "$COMPDIR" != "" ]
then
echo $(pwd)
mv $COMPILED $COMPDIR
fi
cd $USR
if [ "$SUB" = true ]
then
SUBDIRECTORIES=$(find -maxdepth 1 -type d)
$CUR/imgcompile $FLAGS $SUBDIRECTORIES
fi
fi
done