Getting IPython Notebooks Converted to PDF

So if you’re using IPython notebook, awesome.  I have recently started using it and it’s definitely taken the role as my primary tool for quick plotting and data analysis.  Soon it may make sense to start blogging with it, as it outputs very friendly HTML with all the nice figures and formatted code as regular IPython.

But how do you get it to output PDF?  Well there is nbconvert, which has been merged into the main IPython trunk, but you need a lot of TeX packages for it to work.  And to get all the requisite (old) TeX packages, which are not available through Canonical’s centralized repo system :-(, you need to get TeXLive!  This is not in the official Canonical PPA anymore (it is apparently in 12.10), but for 12.04 you must sidestep authority, and add some backdoor PPA (personal package archive).  This can be dangerous if you don’t know who you’re dealing with, but this one seems to be maintained be the official release manager.  Here goes:

sudo add-apt-repository ppa:texlive-backports/ppa
sudo apt-get update
sudo apt-get install texlive

sudo apt-get install texlive-latex-extra
That should give you all the TeX packages you need (there are a lot). Next, simply run the merged IPython code in the directory where your .ipynb files are:
ipython nbconvert <your_file_name_here>.ipynb –to latex –post PDF
And voila!  Perfectly typesetted (ack) IPython notebooks.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s