Skip to content

Instantly share code, notes, and snippets.

@nylander
Last active October 30, 2025 12:42
Show Gist options
  • Save nylander/d619944572c8aa0c6c911d3cfbea83f5 to your computer and use it in GitHub Desktop.
Save nylander/d619944572c8aa0c6c911d3cfbea83f5 to your computer and use it in GitHub Desktop.
Mardown to PDF conversion using pandoc
#!/bin/bash
# Convert Markdown to PDF using pandoc
# Last modified: tor aug 20, 2020 02:51
# Johan Nylander
# TODO: set mainfont to allow for special characters () -V 'mainfont:xxx xx'
hash pandoc 2>/dev/null || { echo >&2 "Cannot find pandoc. Aborting."; exit 1; }
for f in "$@"
do
echo -n "Converting ${f} ..."
g=${f%.md}.pdf
pandoc --wrap=auto \
--pdf-engine=xelatex \
-V 'mainfont:DejaVuSerif' \
-V 'mainfontoptions:Extension=.ttf, UprightFont=*, BoldFont=*-Bold, ItalicFont=*-Italic, BoldItalicFont=*-BoldItalic' \
-V 'sansfont:DejaVuSans.ttf' \
-V 'monofont:DejaVuSansMono.ttf' \
-V 'mathfont:texgyredejavu-math.otf' \
--columns=180 -V geometry:margin=1in "$f" -o "$g"
if [ -e "$g" ]; then
echo " to ${g}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment