jupyter nbconvert --to pdf notebook.ipynb is the command every tutorial gives you, and it is the command that most often fails. The error is usually one line long, mentions a program you have never installed, and arrives after a pause that made you think it was working.
This is a field guide to the five failures that account for almost all of them — and to the decision of whether to fix the toolchain or skip it.
The error: “xelatex not found on PATH”
The full message usually looks like this:
nbconvert.exporters.pdf.PDFExporter: xelatex not found on PATH,
if you have not installed xelatex you may need to do so.
There is nothing wrong with your notebook. nbconvert does not write PDFs directly. With --to pdf it converts the notebook to LaTeX and then calls xelatex to compile that LaTeX into a PDF. If the engine is not on your PATH, the pipeline stops at the last step.
What “installed” means here
You need three separate things, and installing one does not install the others:
- nbconvert — the Python package.
pip install nbconvert. - Pandoc — the document converter nbconvert uses internally.
brew install pandoc,apt install pandoc, or the installer from pandoc.org. - A TeX distribution — the engine that produces the PDF: TeX Live on Linux, MacTeX on macOS, MiKTeX on Windows.
A TeX distribution is large (hundreds of megabytes to several gigabytes). That is the real reason this error is common: people install nbconvert, see a Python package, and do not expect a typesetting system underneath it.
Install the TeX engine
# Debian / Ubuntu — xelatex plus the packages nbconvert templates need
sudo apt update
sudo apt install texlive-xetex texlive-fonts-recommended texlive-plain-generic
# macOS — full distribution (large) or the smaller BasicTeX
brew install --cask mactex
# or: brew install --cask basictex
# Windows — install MiKTeX from miktex.org, then reopen the terminal
After installing, open a new terminal. PATH changes made by installers do not reach a shell that was already running, which is the second most common reason people install TeX and still see the same error.
Verify before retrying:
which xelatex
xelatex --version
pandoc --version
which xelatex should print a path. If it prints nothing, the install worked but your shell cannot see it.
The other four failures
“pandoc not found”
pandoc: command not found
nbconvert shells out to Pandoc for the HTML-to-LaTeX step. Install it with your package manager (brew install pandoc, apt install pandoc, choco install pandoc) and confirm with pandoc --version. The Python package pypandoc does not replace the binary unless you also install pypandoc_binary.
“! LaTeX Error: File `…’ not found”
The template asks for a LaTeX package your distribution does not include. Minimal installs (BasicTeX, texlive-base) ship very few packages. Either install the missing package:
sudo tlmgr install <package-name>
or switch to a fuller distribution. On Debian, texlive-latex-extra and texlive-science cover most notebooks with math, tables and code listings.
“Unicode character not set up for use with LaTeX”
A character in a markdown cell — an em dash, a smart quote, an emoji, CJK text — has no LaTeX definition in the default font. xelatex handles Unicode far better than pdflatex, which is why it is the default, but emoji still fail. Two fixes:
- Replace the character, or wrap it in
\usepackage{...}-friendly markup. - Use a Unicode-capable font via a custom template, for example
\usepackage{fontspec}with a font that covers the glyphs.
This is the error that most often pushes people toward a browser converter: the notebook is fine, the typography is fine, and one emoji in a heading breaks the build.
“TeX capacity exceeded” or a build that hangs
Very long code listings, deeply nested lists or a huge table can exceed TeX’s default memory. Add a custom template with larger values, or split the notebook. A notebook with a 2,000-line traceback in a single output is also a sign that the output should be trimmed before export.
Fix it, or route around it?
The command-line route is worth fixing when:
- The PDF is generated by CI on every commit and must be reproducible.
- You need a house LaTeX template with a logo, fonts and page numbering.
- You want selectable, searchable text as a hard requirement.
- You are already maintaining a Python environment with Pandoc and TeX.
It is worth routing around when:
- You need one PDF, today, and do not want a 4 GB install.
- The notebook has Unicode or emoji that keep breaking the LaTeX build.
- You want to see where pages break before exporting.
- The notebook is client work you would rather not upload to a web service.
Three alternatives, in increasing order of effort:
1. Convert in the browser. The IPYNB to PDF converter parses the notebook, lays out each cell at the printed page width and assembles the PDF in the tab. No Pandoc, no TeX, no upload. It is the fastest route when the goal is a document rather than a reproducible build.
2. Use --to webpdf. This drives headless Chromium instead of LaTeX, so no TeX install is needed:
pip install "nbconvert[webpdf]"
python -m playwright install chromium
jupyter nbconvert --to webpdf notebook.ipynb
Chromium must be installed for Playwright, which is still a download, but it is smaller than a TeX distribution and avoids LaTeX font problems entirely. Page breaks follow the print CSS, so they are better than a raw print but less controlled than a layout pass.
3. Export HTML, then print. jupyter nbconvert --to html notebook.ipynb produces a self-contained HTML file. Open it in a browser and use Print → Save as PDF. The text stays selectable, and the browser chooses the page breaks.
A short checklist after the fix
# 1. All three tools visible
which jupyter pandoc xelatex
# 2. A minimal notebook works before you blame the big one
jupyter nbconvert --to pdf --no-input minimal.ipynb
# 3. Then the real file, with fresh outputs
jupyter nbconvert --to pdf --execute report.ipynb
If the minimal file works and the real one does not, the problem is content — a character, a package, a table — not the installation. If the minimal file fails too, the toolchain is still incomplete, and xelatex --version is the next thing to run.
The honest summary
nbconvert --to pdf is a document compiler wearing a notebook exporter’s clothes. It is excellent when you need a build pipeline and painful when you need a file. Knowing which of those you are doing saves an afternoon.
If you are in the second camp, convert the notebook in the browser and keep the LaTeX install for the project that actually needs it.