Writing an IPython notebook to HTML or PDF with Table Of Content

前端 未结 2 1688
旧巷少年郎
旧巷少年郎 2021-01-12 07:04

Im trying to create a report from my IPython notebook. Im using the toc extension to create a toc for my nb. I already converted the notebook to html, but the toc is not sh

相关标签:
2条回答
  • 2021-01-12 07:48

    Assuming you use IPython 1.x you have the following options to include the toc in the pdf

    • use the latex_book template
      (ipython nbconvert --to=latex --template=latex_book --post=pdf file.ipynb)

    • extend the latex_article (default) template
      Create a file with the following content (e.g. toc_latex.tplx) in the working dir:

      ((*- extends 'latex_article.tplx' -*))
      ((* block toc *))\tableofcontents((* endblock toc *))
      

      Use it as a template like
      ipython nbconvert --to=latex --template=toc_latex --post=pdf file.ipynb

    If you use IPython 2.x

    • use the latex_report template
      (ipython nbconvert --to=latex --template=latex_report --post=pdf file.ipynb)

    • the custom template could be something like

      ((*- extends 'latex_article.tplx' -*))
      ((* block abstract *))\tableofcontents((* endblock abstract *))
      
    0 讨论(0)
  • 2021-01-12 07:56

    I used a method without the nb extension to write the ToC to pdf (through Latex). I don't think it'd work when exporting as HTML though.

    I added this cell at the top of the notebook:

    %%latex
    \tableofcontents
    

    And then converted to pdf based on this answer

    jupyter nbconvert --to pdf --TemplateExporter.exclude_input=True my_notebook.ipynb
    
    0 讨论(0)
提交回复
热议问题