How to convert IPython notebooks to PDF and HTML?

前端 未结 18 1358
有刺的猬
有刺的猬 2020-12-12 10:49

I want to convert my ipython-notebooks to print them, or simply send them in html format. I have noticed that there exists a tool to do that already, nbconvert. Although I h

18条回答
  •  一整个雨季
    2020-12-12 11:13

    nbconvert is not yet fully replaced by nbconvert2, you can still use it if you wish, otherwise we would have removed the executable. It's just a warning that we do not bugfix nbconvert1 anymore.

    The following should work :

    ./nbconvert.py --format=pdf yourfile.ipynb 
    

    If you are on a IPython recent enough version, do not use print view, just use the the normal print dialog. Graph beeing cut in chrome is a known issue (Chrome does not respect some print css), and works much better with firefox, not all versions still.

    As for nbconvert2, it still highly dev and docs need to be written.

    Nbviewer use nbconvert2 so it's pretty decent with HTML.

    List of current available profiles:

    $ ls -l1 profile|cut -d. -f1
    
    base_html
    blogger_html
    full_html
    latex_base
    latex_sphinx_base
    latex_sphinx_howto
    latex_sphinx_manual
    markdown
    python
    reveal
    rst
    

    Give you the existing profiles. (You can create your own, cf future doc, ./nbconvert2.py --help-all should give you some option you can use in your profile.)

    then

    $ ./nbconvert2.py [profilename] --no-stdout --write=True 
    

    And it should write your (tex) files as long as extracted figures in cwd. Yes I know this is not obvious, and it will probably change hence no doc...

    The reason for that is that nbconvert2 will mainly be a python library where in pseudo code you can do :

     MyConverter = NBConverter(config=config)
     ipynb = read(ipynb_file)
     converted_files = MyConverter.convert(ipynb)
     for file in converted_files :
         write(file)
    

    Entry point will come later, once the API is stabilized.

    I'll just point out that @jdfreder (github profile) is working on tex/pdf/sphinx export and is the expert to generate PDF from ipynb file at the time of this writing.

提交回复
热议问题