Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export an IPython notebook to HTML for a blog post?

What is the best way to get an ipython notebook into html format for use in a blog post?

It is easy to turn an ipython notebook into a PDF, but I'd rather publish as an html notebook.

I've found that if I download the notebook as a .ipynb file, then load it onto gist, then look at it with the ipython notebook viewer (nbviewer.ipython.org), THEN grab the html source, I can paste it into a blog post (or just load it as html anywhere) and it looks about right. However, if I use the "print view" option directly from ipython, the source contains a bunch of javascript rather than the processed html, which is not useful since the images and text are not directly included.

The %pastebin magic is also not particularly helpful for this task, since it pastes the python code and not the ipython notebook formatted code.

EDIT: Note that this is under development; see the comments under the accepted answer.

EDIT May 2 2014: As per Nathaniel's comment, a new answer is needed for ipython 2.0

like image 417
keflavich Avatar asked Sep 19 '12 20:09

keflavich


People also ask

How do I export a Jupyter notebook to HTML?

This method is as simple as clicking File, Download as, HTML (. html). Jupyter will then download the notebook as an HTML file to wherever the browser defaults for downloaded files.


2 Answers

The right way is described in: http://blog.fperez.org/2012/09/blogging-with-ipython-notebook.html. Then you can do nbconvert -f blogger-html your_notebook.ipynb to get the html code for your post.

like image 139
Daniel Avatar answered Oct 16 '22 18:10

Daniel


One step further from the answer above. To create a PDF file,

  1. create a tex file

    nbconvert -f latex your_notebook.ipynb
    
  2. convert tex to pdf :

    pdflatex your_notebook.tex
    
like image 11
Tooblippe Avatar answered Oct 16 '22 18:10

Tooblippe