Skip to content

Commit 925917d

Browse files
authored
Update md2pdf.sh
1 parent 0a47791 commit 925917d

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

Build/md2pdf.sh

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
#!/bin/bash
22
# Script based on https://learnbyexample.github.io/tutorial/ebook-generation/customizing-pandoc/
3+
4+
Help()
5+
{
6+
# Display Help
7+
echo "Generate guide PDF from a master MarkDown file."
8+
echo
9+
echo "Syntax: md2pdf.sh ./Build/<mastermarkdown> <output.pdf>"
10+
echo
11+
exit
12+
}
13+
14+
while getopts ":h" option; do
15+
case $option in
16+
h | *) # display Help
17+
Help
18+
exit;;
19+
esac
20+
done
21+
22+
if [ -z "$1" ]
23+
then
24+
Help
25+
exit
26+
fi
27+
328
SCRIPT=$(readlink -f "$0")
429
SCRIPTPATH=$(dirname "$SCRIPT")
5-
6-
pandoc "$tfl" \
30+
echo -e "\e[1;32m Running Pandoc to generate the LaTex file. \e[0m"
31+
pandoc "$1" \
732
-f gfm \
833
--toc \
934
--listings \
@@ -20,15 +45,16 @@ pandoc "$tfl" \
2045
-V mainfont="DejaVu Serif" \
2146
-V monofont="DejaVu Sans Mono" \
2247
--pdf-engine=xelatex \
23-
-o temp.tex
48+
-o /tmp/temp.tex
2449

50+
echo -e "\e[1;32m Running Perl to format the output. \e[0m"
2551
fn="${2%.*}"
2652

27-
perl -0777 -pe 's/begin\{document\}\n\n\K(.*?^\}$)(.+?)\n/$2\n\\thispagestyle{empty}\n\n$1\n/ms' temp.tex > ${fn}.tex
28-
29-
xelatex ${SCRIPTPATH}/${fn}.tex &> /dev/null
30-
xelatex ${SCRIPTPATH}/${fn}.tex &> /dev/null
53+
perl -0777 -pe 's/begin\{document\}\n\n\K(.*?^\}$)(.+?)\n/$2\n\\thispagestyle{empty}\n\n$1\n/ms' /tmp/temp.tex > ${SCRIPTPATH}/${fn}.tex
3154

32-
rm temp.tex "$fn".{tex,toc,aux,log}
55+
echo -e "\e[1;32m Generating PDF. \e[0m"
56+
xelatex ${SCRIPTPATH}/${fn}.tex > ${SCRIPTPATH}/pdfgen.log
3357

58+
echo -e "\e[1;32m Cleanning temp files. \e[0m"
59+
rm /tmp/temp.tex "$fn".{tex,toc,aux,log}
3460

0 commit comments

Comments
 (0)