2026-03-16
Markdown to PDF Using Pandoc
I recently wrote some technical documentation in markdown and wanted to generate a nicely formatted pdf out of it. I used ChatGPT to give me some examples, not all the PDFs came out that nice but I got something useable.
Pandoc uses latex to convert markdown to PDF and so I needed to install various packages as I didn't have latex.
sudo dnf install texlive-scheme-basic texlive-xetex
sudo dnf install texlive-lm texlive-lm-math
sudo dnf install google-noto-serif-fonts google-noto-sans-fonts
I also wanted to have a codeblock background, this required having a tex file.
I have the following in codeblock.tex:
\usepackage{listings}
\usepackage{xcolor}
\definecolor{codegray}{RGB}{248,248,248}
\lstset{
backgroundcolor=\color{codegray},
basicstyle=\ttfamily\small,
frame=single,
rulecolor=\color{black!10},
breaklines=true,
columns=fullflexible
}
I also had to update my markdown with some frontmatter:
---
title: Document Title
author: Author
date: 2026
toc: true
toc-depth: 3
numbersections: true
fontsize: 11pt
geometry: margin=1in
---
...Rest of my document
Finally, the pandoc command:
pandoc doc.md \
--pdf-engine=xelatex \
--listings \
-H codeblock.tex \
--toc \
--number-sections \
-o doc.pdf