nbconvert failed: LaTeX Error converting notebook to pdf
Fixes `nbconvert failed: LaTeX Error` converting a notebook to PDF: the generated .tex references a missing package or a bad cell output. Export the .tex, compile it by hand, and read the real LaTeX error. Not for missing xelatex.
TL;DR
The LaTeX error is from the .tex file nbconvert generated, not from nbconvert itself, so the first step is seeing that file: run jupyter nbconvert --to pdf with output kept, or convert --to latex and compile the .tex manually. The manual compile shows the actual missing package or bad command. Install the missing TeX package (or strip the offending cell output) and re-run.
nbconvert failed: LaTeX Error converting notebook to pdfUse this when
- nbconvert to PDF fails with a LaTeX Error naming a .tex line.
- HTML export of the same notebook works fine.
- The notebook contains rich outputs (tables, math, images).
Not for this skill when
- The error is
xelatex not found. That is a missing TeX install. - nbconvert fails before generating .tex. That is a template or nbconvert issue.
Steps
- Generate the .tex without compiling:
jupyter nbconvert --to latex nb.ipynb. Verify: you have nb.tex. - Compile it by hand:
xelatex nb.tex(or pdflatex per your setup). Verify: you see the real LaTeX error with a line number. - Read the offending .tex lines. Verify: you can name the missing package or the bad command (often from a cell output).
- Install the missing TeX package via your TeX distribution. Verify: the manual compile now succeeds.
- Re-run
jupyter nbconvert --to pdf nb.ipynb. Verify: the PDF builds cleanly.
Variant phrasings
nbconvert latex error pdf
Short form. Compile the .tex by hand.
jupyter pdf export latex failed
UI phrasing. The .tex holds the answer.
latex error converting notebook to pdf
General phrasing. Missing TeX package is the usual cause.
Compatibility: nbconvert 6/7 with a full TeX Live / MacTeX / MiKTeX install. xelatex is the default engine.
Why it happens
nbconvert renders the notebook to LaTeX and shells out to xelatex, but it surfaces only a summary of the LaTeX failure. The .tex it generated is a normal LaTeX document, and compiling it directly gives the full error context that nbconvert hides. Most failures are a missing LaTeX package (the notebook used a symbol the default template does not load) or a cell output containing characters LaTeX chokes on.
Edge cases / pitfalls
- Cell outputs with unescaped special characters (%, _, #) in text output break the .tex. Sanitize or strip those outputs.
- A minimal TeX install lacks most packages. Install the full scheme if you convert notebooks regularly.
- The default template may need
--PDF via LaTeXengine flags for unicode. xelatex handles unicode; pdflatex often does not. - Fixing the .tex by hand and recompiling does not fix the notebook. Fix the source (package or output), then regenerate.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_u-EXfvYDhwxWqDIFIJtNmw