Skip to Content
DocumentationGenerate a LaTeX-based PDF from Markdown

Generate a LaTeX-based PDF from Markdown

Generating a PDF from Markdown requires Pandoc and a LaTeX engine. This guide covers the full process: converting Obsidian or Markdown notes into a clickable, navigable PDF with table of contents, headings, and custom headers/footers.

Unlike a simple “Export to PDF” in Obsidian, this method ensures:

  • Clickable table of contents
  • PDF bookmarks for headings
  • Unicode support
  • Custom footers and headers
  • Full control over layout and fonts

You can run this pipeline locally on Windows, macOS, or Linux. It works with:

  1. Markdown files exported from Obsidian
  2. Any standard Markdown source
  3. Optional LaTeX customization
Caution

You must have a LaTeX distribution installed (MiKTeX, TeX Live, or MacTeX) and your binaries accessible via PATH. Pandoc cannot produce PDFs without a LaTeX engine.


Prerequisites

  • Pandoc  installed and accessible from the terminal
  • LaTeX distribution installed, used MikTeX  for Windows here

Check installations

Terminal
pandoc --version pdflatex --version
Note

On Windows, ensure your project path is short to avoid issues during compilation (e.g., C:\GitHub\notes).


Configure Your LaTeX Header (Optional)

For headers, footers, fonts, and page numbering, create a LaTeX header file, e.g., header.tex:

1. Create header.tex

\usepackage{fancyhdr} \pagestyle{fancy} \fancyhf{} \fancyfoot[C]{\thepage} \fancyhead[L]{My Markdown Notes} \fancyhead[R]{Generated PDF} \renewcommand{\headrulewidth}{0.4pt} \renewcommand{\footrulewidth}{0pt}

2. Place header.tex in your working directory

This file will be included in the Pandoc build command.


Generate the PDF

1. Basic PDF generation

Terminal
pandoc "YourNote.md" -o "YourNote.pdf" --toc --pdf-engine=xelatex
  • --toc generates a clickable table of contents
  • --pdf-engine=xelatex ensures Unicode support and modern font handling

2. PDF generation with custom LaTeX header

Terminal
pandoc "YourNote.md" -o "YourNote.pdf" --toc --pdf-engine=xelatex -H header.tex

This applies your custom headers, footers, and layout.


Notes on File Organization

  • Multiple Markdown files: you can combine them in order:
Terminal
pandoc chapter1.md chapter2.md chapter3.md -o fullbook.pdf --toc --pdf-engine=xelatex -H header.tex
  • Unicode symbols: XeLaTeX or LuaLaTeX is required; pdflatex cannot handle non-ASCII symbols.

  • Font customization: set the main font via Pandoc variable:

Terminal
pandoc "YourNote.md" -o "YourNote.pdf" --toc --pdf-engine=xelatex -V mainfont="Latin Modern Roman" -H header.tex

Verification

After compilation:

  • Open the PDF

  • Verify that:

  • Table of contents links work

  • Headings are clickable

  • Custom headers and footers appear

  • Unicode symbols render correctly

Tip

Keep a consistent workflow directory structure for Obsidian notes, headers, and output PDFs to simplify repeated builds.


Created: 25.01.2026

Last Updated: 25.01.2026