ipython notebook nbconvert - how to remove red 'out[N]' text in top left hand corner of cell output?

前端 未结 2 1657
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 16:48

I am using nbconvert to produce something as close as possible to a polished journal article.

I have successfully hidden input code using a custom nbconvert templat

2条回答
  •  遥遥无期
    2020-12-10 17:16

    Depending on the version of IPython you are using, there are more or less hackish ways to remove the Out[ ] prompts.

    IPython 1.x

    Assuming that you use the latex_article base, a custom template (sphinx_template.tplx) with removed input blocks could look like

    ((* extends 'latex_article.tplx' *))
    ((* block input *))
    ((* endblock input *))
    ((* block output_group *))
       % Add remainer of the document contents below.
       ((* for output in cell.outputs *))
            ((( render_output(output) )))
       ((* endfor *))
    ((* endblock *))
    

    To finally remove the prompt, you need to use the simple mode of the Sphinx style, hence use it like ipython nbconvert --to latex --SphinxTransformer.output_style=simple --template=sphinx_template.tplx test.ipynb

    IPython Master

    In IPython master additional cell styles have been added, see e.g. PR4112. How to use these styles is shown e.g. in example1 and examples2.

    To sum up, here the template (bw_python.tplx) could look like (with inputs)

    ((= This line selects the cell style. =))
    ((* set cell_style = 'style_bw_python.tplx' *))
    
    ((= This line inherits from the built in template that you want to use. =))
    ((* extends 'latex_article.tplx' *))
    

    This is used without additional options, hence ipython nbconvert --to=latex --template=bw_python.tplx test.ipynb

提交回复
热议问题