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?
- Install Pandoc from pandoc.org, or with a package manager (
brew install pandocon macOS). - 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.
- Run the basic command in the folder with your file:
pandoc book.md -o book.pdf- 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:
pandoc book.md -o book.pdf --pdf-engine=xelatex
pandoc book.md -o book.epub
pandoc book.md -o book.docxFor 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:
pandoc book.md -o book.pdf --pdf-engine=xelatex \
-V mainfont="Lora" -V sansfont="Inter"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.
Should you use Pandoc for your Markdown to PDF?
Three questions, and they are quite reliable:
- Does the document have citations, cross-references or mathematics? If yes, use Pandoc. Nothing below overrides this.
- 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.
- 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 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 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. Pandoc also converts Markdown to Word; 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 and compare its page preview with Pandoc's PDF.