-
Notifications
You must be signed in to change notification settings - Fork 0
/
md2latexfull
executable file
·64 lines (44 loc) · 1.64 KB
/
md2latexfull
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
#!/bin/zsh
# Captures the date for later use
#date=`date +"%m-%d-%y"`
# Capture the current working directory
cwd=$(pwd)
# Make .md2latex directory to work on generating final output.
#mkdir -p "$(pwd)/.md2latex/build"
# Markdown file we are going to work on.
#mdfile="$(pwd)/.md2latex/$1"
# Latex output
#texout="$(pwd)/.md2latex/pandocked.tex"
texout=pandocked.tex
# Final Latex
#texfinal="$(pwd)/.md2latex/build/final.tex"
texfinal=final.tex
# Build directory
#build="$(pwd)/.md2latex/build"
# Copy the markdown file to .md2latex directory
#echo cp $1 $mdfile
# Run Pandoc to turn the markdown file with the bulk of the document into a .TeX file
pandoc -f markdown --latex-engine=pdflatex -R -i $1 -o $texout
# Remove some of the junk that Markdown adds when converting to TeX.
sed -i .bak 's/\[<+->\]//g' $texout
sed -i .bak 's/\\def\\labelenumi{\\arabic{enumi}.}//g' $texout
sed -i .bak 's/\\itemsep1pt\\parskip0pt\\parsep0pt//g' $texout
# Concatenate the header file (with the preambles, TOC, etc), the pandoc-created TeX file,
# and the footer file (with the bibliography) into a single buildable TeX file
cat "$cwd/includes/header.tex" $texout "$cwd/includes/footer.tex" > $texfinal
# Copy latex style files and bib files to build.
#cp -r $cwd/*.cls $build
#cp -r $cwd/*.bib $build
# Move into the build folder, which keeps the TeX junk and included files out of the main folder
#cd $build
# Build PDF
latexmk final.tex -pdf -pdflatex="pdflatex -interaction=nonstopmode"
#pdflatex final.tex
# Copy the PDF back
#cp final.pdf $cwd
#cd $cwd
mv final.pdf $1.pdf
# Open the PDF generated in my PDF reader of choice
open $1.pdf
rm final.*
rm pandocked.*