Converting markdown to PDF format for printing
Something I've repeatedly run into lately is trying to convert markdown documents to PDF formats.
This is a bit of a strange process because markdown for the most part is just a shorthand for web markup. This means that to render these documents you need a web browser or some sort of web rendering engine. To actually control the output and make it more suitable for printing there's some more steps involved.
Here's a quick way to get this to happen using Linux or wsl:
sudo apt install pandoc texlive texlive-xetex texlive-full
Note that the texlive-full is a large download (bigger than 5GB as of the time of writing).
Then there's a template that's useful for pandoc conversions:
https://github.com/Wandmalfarbe/pandoc-latex-template
You have to download these and install them into the pandoc templates folder.
Then to run this to convert a basic markdown document into a pdf:
pandoc example.md -o example.pdf --from markdown --template eisvogel
To get use of all the features provided by this template you may need to add metadata to the top of the markdown files like so:
---
title: "My document title"
author: [Example Author, Another Author]
date: "2025-04-13"
keywords: [Markdown, pdf, pandoc, document-conversion-pipelines]
---
The document contents are here...
If the markdown document has code samples you wish to have syntax highlighting applied to you can use the --listings option when converting:
pandoc example.md -o example.pdf --from markdown --template eisvogel --listings
While somewhat basic this workflow allows you to translate a markdown document to a pdf file without having to go the web rendering route.