-
Notifications
You must be signed in to change notification settings - Fork 0
/
conv.sh
executable file
·64 lines (57 loc) · 1.63 KB
/
conv.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
# Checks for the presence of markdown files
echo
md=$(ls -1 *.md 2>/dev/null | wc -l)
mdown=$(ls -1 *.mdown 2>/dev/null | wc -l)
mark=$(ls -1 *.markdown 2>/dev/null | wc -l)
present=$(($md+$mdown+$mark))
if [ "$present" -eq 0 ]; then
echo -e "No markdown files detected!\n"
exit
fi
# Checks for output directory and creates one if missing
if [ ! -d PDFs ]; then
mkdir PDFs
echo -e "Output folder created.\n"
else
echo -e "Selecting existing output folder.\n"
fi
# Finds and prints the total number of files to be compiled
files=$(ls -p | grep -v / | wc -l)
unread=$(ls -p PDFs/ | grep -v / | wc -l)
total=$((files-unread))
count=0
echo -e "Found $total files to convert\n"
# Asks user for the LaTeX engine to be used
echo -e "LaTeX engines\n------------\n"
PS3=$'\n'"Please choose a LaTeX engine: "
select option in pdflatex lualatex xelatex
do
case $option in
pdflatex)
echo -e "\npdflatex engine selected";;
lualatex)
echo -e "\nlualatex engine selected";;
xelatex)
echo -e "\nxelatex";;
*)
echo "Please choose an option";;
esac
break
done
echo
# Allows user to add custom LaTeX variables
echo -n "Would you like to add any LaTeX details(e.g. --variable mainfont:\"Gill Sans\")?: "
read variable
# Compiles documents
echo -e "\nBeginning conversion...\n"
find . -iname "*.mdown" | while read -r i; do
y="$i"
x="${y%.*}"
z="${x##*/}"
if [ ! -f ./PDFs/"$z".pdf ]; then
pandoc -f markdown "$i" --latex-engine=$option --variable font-family:sans-serif $variable -o ./PDFs/"$z".pdf
((count++))
echo $count/$total compiled.
fi
done
echo -e "\nAll files complete!"