Skip to content

Instantly share code, notes, and snippets.

@rbento
Created May 16, 2026 23:19
Show Gist options
  • Select an option

  • Save rbento/04aa51f69a6bd78199fad1bcdebc93a9 to your computer and use it in GitHub Desktop.

Select an option

Save rbento/04aa51f69a6bd78199fad1bcdebc93a9 to your computer and use it in GitHub Desktop.

Convert Markdown to PDF

Cross-platform recipes using pandoc. Examples use guide.md as the source file.


1. Install Pandoc + LaTeX

Linux (Fedora)

sudo dnf install --skip-broken --skip-unavailable --assumeyes \
  pandoc texlive-xetex texlive-collection-fontsrecommended

Linux (Debian / Ubuntu)

sudo apt install pandoc texlive-xetex texlive-fonts-recommended

macOS

brew install pandoc
brew install --cask basictex

Open a new terminal so PATH picks up LaTeX, then:

sudo tlmgr update --self
sudo tlmgr install collection-fontsrecommended

2. Basic Conversion

Works the same on Linux and macOS.

pandoc guide.md -o guide.pdf \
  --pdf-engine=xelatex \
  --toc --number-sections

Flags:

  • --pdf-engine=xelatex — Unicode-friendly LaTeX engine
  • --toc — generate a table of contents
  • --number-sections — number the headings

3. Nicer Output with the Eisvogel Template

Polished tech-doc look: title page, page numbers, header/footer, syntax-highlighted code.

Install the template (once)

mkdir -p ~/.local/share/pandoc/templates
curl -L https://github.com/Wandmalfarbe/pandoc-latex-template/releases/latest/download/Eisvogel.tar.gz \
  | tar xz --strip-components=1 -C ~/.local/share/pandoc/templates eisvogel.latex

Convert

pandoc guide.md -o guide.pdf \
  --pdf-engine=xelatex \
  --template eisvogel \
  --toc --number-sections \
  --listings

4. Lightweight Alternative — No LaTeX

If you don't want a LaTeX install, use an HTML-to-PDF engine instead.

Install

Linux (Fedora):

sudo dnf install --skip-broken --skip-unavailable --assumeyes pandoc weasyprint

macOS:

brew install pandoc weasyprint

Convert

pandoc guide.md -o guide.pdf --pdf-engine=weasyprint

Output is decent but not LaTeX-grade. Fine for personal reference.


5. Troubleshooting

Problem Fix
! LaTeX Error: File 'X.sty' not found (macOS) sudo tlmgr install <package> (no .sty suffix)
! LaTeX Error: File 'X.sty' not found (Linux) sudo dnf install texlive-<package> or sudo apt install texlive-<package>
Emoji or special characters render as boxes Add --variable mainfont="DejaVu Sans" to the pandoc command
Code blocks overflow the page Add --listings flag (uses LaTeX listings package for wrapping)
Tables look cramped Add -V geometry:margin=2cm to widen the page area

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment