1
+ # pick first markdown the file finds
2
+ TEX=$( find * .tex)
3
+ # remove .md file name
4
+ FILE=${TEX% .tex}
5
+
6
+ function ERROR {
7
+ echo -e " \033[38;5;1mERROR: ${1} "
8
+ exit 1
9
+ }
10
+
11
+ function LOADING {
12
+ echo " $1 "
13
+
14
+ STEP_SIZE=5
15
+ TOTAL_STEPS=$(( 100 / STEP_SIZE))
16
+ FILE_SIZE=$( wc -l ${FILE} .tex | cut -c 6-8)
17
+
18
+ for (( k = 0 ; k < $TOTAL_STEPS ; k++ ))
19
+ do
20
+ echo -ne " \033[K"
21
+ echo -n " [ "
22
+
23
+ for (( i = 0 ; i < k; i++ ))
24
+ do
25
+ echo -n " #"
26
+ done
27
+
28
+ for (( j = i ; j < $TOTAL_STEPS ; j++ ))
29
+ do
30
+ echo -n " "
31
+ done
32
+
33
+ echo -n " ]"
34
+
35
+ STEP=$(( k * STEP_SIZE))
36
+ echo -ne " ${STEP} %\r"
37
+
38
+ DELAY=$(( ( ( RANDOM % 5 ) * FILE_SIZE ) / 2000 ))
39
+ sleep ${DELAY} s
40
+ done
41
+ }
42
+
43
+ function delete {
44
+ if [ -e * .${1} ]
45
+ then
46
+ rm * .${1}
47
+ fi
48
+ }
49
+
50
+ # Remove old files
51
+ delete pdf
52
+ delete log
53
+ delete aux
54
+ delete toc
55
+ delete lof
56
+ delete lot
57
+ delete bbl
58
+ delete blg
59
+ delete out
60
+
61
+ # check if bibliography exists
62
+ # if yes, process it
63
+ if [ -e * .bib ] || [ -e * .bibtex ]
64
+ then
65
+ LOADING " (1/3) Processing bibliography" &
66
+ pdflatex ${FILE} .tex > pdf.log && \
67
+ bibtex ${FILE} .aux > bib.log &
68
+ wait
69
+ if [ -e * .pdf ]
70
+ then
71
+ echo " [ #################### ] 100 %"
72
+ echo
73
+ rm * .pdf
74
+ else
75
+ ERROR " Could not process bibliography"
76
+ fi
77
+
78
+ # convert latex to pdf using pdflatex
79
+ LOADING " (2/3) Preparing conversion from LaTeX to PDF" &
80
+ pdflatex ${FILE} .tex > pdf.log &
81
+ wait
82
+ if [ -e * .pdf ]
83
+ then
84
+ echo " [ #################### ] 100 %"
85
+ echo
86
+ rm * .pdf
87
+ else
88
+ ERROR " PDF build failed"
89
+ fi
90
+
91
+ # pdflatex needs to repeat the process to account for the processing of table of contents and similar environments
92
+ LOADING " (3/3) Converting LaTeX to PDF" &
93
+ pdflatex ${FILE} .tex > pdf.log &
94
+ wait
95
+ if [ -e * .pdf ]
96
+ then
97
+ echo " [ #################### ] 100 %"
98
+ echo
99
+ else
100
+ ERROR " PDF build failed"
101
+ fi
102
+ else
103
+ # convert latex to pdf using pdflatex
104
+ LOADING " (1/2) Preparing conversion from LaTeX to PDF" &
105
+ pdflatex ${FILE} .tex > pdf.log &
106
+ wait
107
+ if [ -e * .pdf ]
108
+ then
109
+ echo " [ #################### ] 100 %"
110
+ echo
111
+ rm * .pdf
112
+ else
113
+ ERROR " PDF build failed"
114
+ fi
115
+
116
+ # pdflatex needs to repeat the process to account for the processing of table of contents and similar environments
117
+ LOADING " (2/2) Converting LaTeX to PDF" &
118
+ pdflatex ${FILE} .tex > pdf.log &
119
+ wait
120
+ if [ -e * .pdf ]
121
+ then
122
+ echo " [ #################### ] 100 %"
123
+ echo
124
+ else
125
+ ERROR " PDF build failed"
126
+ fi
127
+ fi
128
+
129
+ # Delete build files generated by pdflatex if they exist
130
+ if [ " $1 " == " --log" ] || [ " $2 " == " --log" ]
131
+ then
132
+ mkdir logs
133
+ mv * .log logs/
134
+ " log files are in logs folder"
135
+ else
136
+ delete log
137
+ fi
138
+ if [ " $1 " == " --aux" ] || [ " $2 " == " --aux" ]
139
+ then
140
+ mkdir aux
141
+ mv * .log aux/
142
+ " aux files are in logs folder"
143
+ else
144
+ delete aux
145
+ delete out
146
+ delete toc
147
+ delete lof
148
+ delete lot
149
+ delete bbl
150
+ delete blg
151
+ fi
0 commit comments