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

一世执手 提交于 2019-11-28 11:24:00

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

%%HTML <style> div.prompt {display:none} </style>

This will hide both In and Out prompts

Note that this is only in your browser, the notebook itself isn't modified of course, and nbconvert will work just the same as before.

In case you want this in the nbconverted code as well, just put the <style>div.prompt {display:none}</style> in a Raw NBConvert cell.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!