# Pandoc Markdown to PDF: the commands, and where it stops

> How to convert Markdown to PDF with Pandoc: install, the basic command, PDF engines, fonts, margins and contents, and where Pandoc for books gets hard.

Canonical: https://buk.press/blog/pandoc-for-books

30 August 2026 · 5 min read · Updated 20 October 2026

To convert Markdown to PDF with Pandoc, install Pandoc and a PDF engine (a LaTeX distribution such as TeX Live or MiKTeX, or an alternative like Typst or WeasyPrint), then run pandoc input.md -o output.pdf. Add --pdf-engine=xelatex to use your own fonts, -V geometry:margin=2.5cm for margins and --toc for a contents page. Pandoc is the best tool for documents with citations, cross-references or mathematics, and for books built by a script; it stops being pragmatic when the requirements are visual, because every visual change means LaTeX or a template.

To convert Markdown to PDF with Pandoc, install Pandoc plus a PDF engine, then run `pandoc input.md -o output.pdf`. Pandoc writes the PDF through that engine (LaTeX by default), so the engine you pick decides which fonts and layout options you get.

## How do you convert Markdown to PDF with Pandoc?

1. **Install Pandoc** from pandoc.org, or with a package manager (`brew install pandoc` on macOS).
2. **Install a PDF engine.** For the LaTeX route, a TeX distribution: MacTeX on macOS, TeX Live on Linux, MiKTeX on Windows. Pandoc also supports other engines, including Typst and WeasyPrint, which are lighter installs.
3. **Run the basic command** in the folder with your file:

```
<code>pandoc book.md -o book.pdf</code>
```

1. **Add the options you need**, from the table below, and run it again.

| Option | What it does |
|---|---|
| `--pdf-engine=xelatex` | Use XeLaTeX, which can use any font installed on your system |
| `-V mainfont="Lora"` | Set the body font (needs XeLaTeX or LuaLaTeX) |
| `-V geometry:margin=2.5cm` | Set the page margins |
| `-V papersize=a4` | Set the page size (`letter` for US Letter) |
| `-V fontsize=11pt` | Set the base font size |
| `--toc` | Add a table of contents from your headings |
| `-N` | Number the sections |
| `--citeproc --bibliography=refs.bib` | Format citations and add a bibliography |
| `--pdf-engine=typst` | Use Typst instead of LaTeX |

If the command fails with a missing-package error, the LaTeX distribution is missing that package; install it with the distribution's package manager. A failed PDF with no LaTeX at all usually means no engine is installed.

## Is Pandoc good for books?

Yes, for the right book. Pandoc deserves its reputation. It converts between an unreasonable number of document formats, it is free, and pointed at a LaTeX engine it produces books that are genuinely beautifully set: better, out of the box, than most commercial software manages with help.

It is also a tool writers often abandon three weeks in, having produced something almost right. Both facts are true, and which one applies to you is predictable in advance.

## What does Pandoc do better than anything else?

### Real typesetting

With a LaTeX engine underneath, you get line-breaking decisions made across the whole paragraph rather than line by line. The practical effect is even spacing between words and few awkward gaps, the thing that makes a page look *set* rather than merely justified. Browsers do not do this. Word processors do not do this.

### Citations and cross-references

A BibTeX file plus `--citeproc` gives you formatted citations and a bibliography in any style you name, updating as you write. Cross-references know what page they are pointing at. If your document needs either of these, the comparison is over. Use Pandoc.

### Mathematics

LaTeX is the standard way to typeset mathematics, and nothing else in this space comes close.

### One source, many outputs

One command per target, from the same file:

```
<code>pandoc book.md -o book.pdf --pdf-engine=xelatex
pandoc book.md -o book.epub
pandoc book.md -o book.docx</code>
```

For a book that is regenerated by CI every time the manuscript changes, this is exactly right, and a hosted tool with a graphical interface is the wrong shape entirely.

## Where does Pandoc get hard?

Every item below is achievable. The point is not that Pandoc cannot do them. It is what each one costs the first time.

### Changing the typeface

Straightforward, once you know it goes through `fontspec` and requires XeLaTeX or LuaLaTeX rather than the default engine:

```
<code>pandoc book.md -o book.pdf --pdf-engine=xelatex \
  -V mainfont="Lora" -V sansfont="Inter"</code>
```

Different sizes for headings and body, or a different face for chapter openings, means a custom template. That is the moment the curve turns.

### A cover image

For EPUB it is one flag, `--epub-cover-image`. For PDF there is no flag: you write a title-page template, or you generate the cover separately and merge the PDFs afterwards with another tool.

### Seeing what you are doing

There is no preview. You compile, open the PDF, notice the chapter heading sits too close to the text, adjust, compile again. Each cycle is seconds to a minute: fast enough to tolerate and slow enough that you stop iterating well before the book is right. This, more than any single missing feature, is what makes design work in Pandoc feel like work.

### The error messages

When LaTeX fails it fails in LaTeX's own idiom, which assumes you know LaTeX. A missing package produces a wall of output whose actionable line is somewhere in the middle. Solvable, always; pleasant, never.

None of this is a design flaw. Pandoc is a conversion engine with a typesetting system behind it, and both are configured by writing code. That is the deal, and for the right document it is a very good deal.

## Should you use Pandoc for your Markdown to PDF?

Three questions, and they are quite reliable:

1. **Does the document have citations, cross-references or mathematics?** If yes, use Pandoc. Nothing below overrides this.
2. **Is the book produced by a build rather than by a person?** If yes, use Pandoc. A command-line tool is the right shape for a pipeline.
3. **Is the hard part how it looks, rather than what is in it?** If yes, the effort is going into learning a typesetting system rather than into the book, which is a fine thing to do deliberately and a poor thing to end up doing by accident.

The uncomfortable middle is the third case: a book with no citations and no mathematics, where the whole difficulty is that it should look good, and the author is spending evenings reading LaTeX documentation to move a chapter heading down by six points.

## What is the alternative to Pandoc?

That middle case is what [bukpress](https://buk.press/) is for. You keep writing Markdown; the design is a handful of controls rather than a template language, and the preview paginates with the same rules the export uses, so the compile-look-adjust loop happens as you type.

It does not do what Pandoc does. There are no citations, no bibliography, no LaTeX maths, no `--from docx`, and no command-line interface to put in a build. If your document needs any of those, Pandoc is the answer and this article is not trying to talk you out of it.

What it does instead is remove the parts of the middle case that are not writing: pagination, embedding, covers, and seeing the page. If that is your bottleneck, [the sample book](https://buk.press/sample-book) is the honest test (eight pages, nothing touched after export).

For the other routes from Markdown to PDF (print from a preview, VS Code, online converters), see [Markdown to PDF: 5 ways](https://buk.press/blog/markdown-to-pdf-guide). Pandoc also converts Markdown to Word; [Markdown to Word](https://buk.press/blog/markdown-to-word) covers the reference-document trick that makes the .docx come out clean.

## Next step

If your document has citations or maths, install Pandoc and run the basic command above. If it does not, paste the same Markdown into [bukpress](https://buk.press/markdown-to-pdf) and compare its page preview with Pandoc's PDF.

**About this article.** Written by the team that builds bukpress, which turns Markdown into print-ready PDF and EPUB books. Last checked 20 October 2026. Spotted something wrong or out of date? Write to [support@buk.press](mailto:support@buk.press).

## Read next

Guides 21 August 2026 · 8 min read

## [Markdown to PDF: 5 ways to convert an MD file](https://buk.press/blog/markdown-to-pdf-guide)

To convert Markdown to PDF, open the .md file in a tool that renders it and export: print to PDF from a browser preview, use a VS Code extension, paste it into an online converter, run Pandoc from the command line, or use a hosted typesetting tool. The quick routes are fine for a draft; for a document someone will read, sell or print, pick the route that gives you real page breaks, embedded fonts and margins you chose.

[Read it](https://buk.press/blog/markdown-to-pdf-guide)

How-to 21 August 2026 · 4 min read

## [How to control page breaks in Markdown](https://buk.press/blog/markdown-page-breaks)

Markdown has no page break because it describes structure, not pages, so every method is really an instruction to whatever renders it. The three that work are a raw HTML div with a CSS page-break rule, a LaTeX \newpage command through Pandoc, or a renderer that assigns a meaning to a plain-text marker.

[Read it](https://buk.press/blog/markdown-page-breaks)

Guides 30 August 2026 · 5 min read

## [From Markdown draft to published book: the whole pipeline](https://buk.press/blog/self-publish-from-markdown)

Six stages: mark up the manuscript by structure, add the front and back matter readers expect, design it once, export the formats each channel needs, check the output against a proof list, then upload. The writing is the long part; the pipeline itself is roughly a day.

[Read it](https://buk.press/blog/self-publish-from-markdown)

## Write it in Markdown. Ship a book.

bukpress turns the file you are already writing into a typeset PDF and EPUB: your type, your covers, no watermark, ever.

[Get Lifetime, $27 once](https://app.buk.press/signup)
