Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 template. The doc is now looking very nice.

But I don't know how to suppress the bright red 'out[x]' statement in the top left corner of the output cells. Anyone know of any settings or hacks that are able to remove this also ?

Thanks,

John

like image 854
J Grif Avatar asked Nov 25 '13 04:11

J Grif


2 Answers

%%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.

like image 115
johnbaltis Avatar answered Nov 18 '22 14:11

johnbaltis


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

like image 44
Jakob Avatar answered Nov 18 '22 13:11

Jakob