Skip to content

Commit 0fba364

Browse files
committed
restructured build process
1 parent a5fcd44 commit 0fba364

File tree

4 files changed

+156
-143
lines changed

4 files changed

+156
-143
lines changed

src/md-paper.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
version="0.1.2"
3+
version="0.1.3"
44

55
if brew ls --versions md-paper >/dev/null
66
then
@@ -79,7 +79,8 @@ case $1 in
7979
# convert latex to pdf
8080
if [ -e *.tex ]
8181
then
82-
ksh ${resources}/pdf.ksh
82+
ksh ${resources}/pdf.sh
83+
open *.pdf
8384
else
8485
echo "No (La)TeX file found"
8586
exit 1
@@ -90,7 +91,8 @@ case $1 in
9091
then
9192
# convert md to pdf
9293
sh ${resources}/tex.sh
93-
ksh ${resources}/pdf.ksh
94+
ksh ${resources}/pdf.sh
95+
open *.pdf
9496
else
9597
echo "No Markdown file found"
9698
exit 1

src/pdf.ksh

Lines changed: 0 additions & 138 deletions
This file was deleted.

src/pdf.sh

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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

src/tex.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/bin/sh
2-
31
# remove old file
42
if [ -e *.tex ]
53
then

0 commit comments

Comments
 (0)