Converting an IPython Notebook to PDF

If you have an IPython Notebook (*.ipynb file), you may want to convert to PDF for distribution. If you read the documentation for ipython nbconvert, it seems fairly straightforward:

$ ipython nbconvert --to PDF <your notebook>.ipynb

However, if you run that, you’re likely to run into an error asking to you install Pandoc; this is because nbconvert relies on an intermediate conversion to LaTeX first, and then to the final PDF output. Pandoc is used for this. To install on OS X:

$ brew install pandoc

Running the conversion again yields another error, suggesting you need the pdflatex command; Pandoc doesn’t include any built-in support for LaTeX->PDF, so you’ll need a LaTeX install. The Pandoc documentation suggests BasicTeX:

$ brew cask install basictex

Trying conversion results in another failure. Turns out, you need to install some more LaTeX packages:

$ sudo tlmgr update --self
$ sudo tlmgr install adjustbox
$ sudo tlmgr install collectbox
$ sudo tlmgr install ucs

After this, you should be able to do your conversion and have a fairly-decent PDF output based on your IPython Notebook:

$ ipython nbconvert --to PDF <your notebook>.ipynb

One Comment »

  1. Hai,

    Thanks for the nice post, how to use the same procedure for windows OS(i installed pandoc and miktex, but still i am getting error while converting ipython notebooks to pdf, please advice

    Thanks
    Sumendar

Comments are now closed for this entry.