Here's a solution that uses LaTeX to generate the PDF. If you have long-form text in the Markdown files and would like to optimize for typographic readability (and I suspect you do), LaTeX tends to do a much better job compared to HTML engines.
It uses pandoc
as an intermediary between Markdown and LaTeX, and also produces the PDF for you.
Main script
#!/bin/bash
md-dir="MARKDOWN_DIRECTORY_HERE"
pdf-dir="PDF_DIRECTORY_HERE"
cd "${md-dir}"
for filename in *.md; do
target-pdf="${pdf-dir}/${filename}.pdf"
pandoc "${filename}" -t latex --latex-engine=xelatex -V geometry=a4paper -V fontsize=11pt -V listings -V header-includes="\usepackage{fancyhdr}\pagestyle{fancyplain}\cfoot{}\rhead{\thepage}\lhead{\texttt{\lstinline/${filename}/}}" -V header-includes="\linespread{2.0}" -o "${target-pdf}"
echo "produced ${filename}.pdf"
lpr "${target-pdf}"
done
Required setup
- Get
pandoc
from Homebrew: brew install pandoc
- Install the minimal version of LaTeX called BasicTeX
Testing if you got the setup correct
You should be able to run in a new Terminal window (with bash)
echo "test" | pandoc -t latex --latex-engine=xelatex -o test.pdf
and get a valid test.pdf
document with just the word "test"
Customizations
There's a lot you can tweak with the LaTeX settings from the command line
- tweak the line spacing by changing the
\linespread{2.0}
multiplier
- adjust markings by replacing
geometry=a4paper
with geometry=a4paper,left=XXmm,right=XXmm,top=XXmm,bottom=XXmm
- change font size by chaining
11pt
to either 10pt or 12pt, and everything should scale accordingly
- change the main font by adding another argument to
pandoc
: -V mainfont="NAME OF FONT"
. You can also set monofont
this way.