我正在使用nbconvert生成尽可能接近精美期刊文章的内容。
我已经成功地使用自定义的nbconvert模板隐藏了输入代码。现在文档看起来非常好。
但是我不知道如何抑制输出单元格左上角明亮的红色“out[x]”语句。是否有任何设置或技巧能够去除这个呢?
谢谢,
John
我正在使用nbconvert生成尽可能接近精美期刊文章的内容。
我已经成功地使用自定义的nbconvert模板隐藏了输入代码。现在文档看起来非常好。
但是我不知道如何抑制输出单元格左上角明亮的红色“out[x]”语句。是否有任何设置或技巧能够去除这个呢?
谢谢,
John
%%HTML
<style>
div.prompt {display:none}
</style>
这将隐藏输入和输出提示
请注意,这仅在您的浏览器中生效,笔记本本身并没有被修改,而且nbconvert
仍然可以像以前一样工作。
如果您希望在nbconvert
后的代码中也有这个效果,只需将<style>div.prompt {display:none}</style>
放在一个原始NBConvert单元格中即可。
((* 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 *))
simple
模式,因此像这样使用它:ipython nbconvert --to latex --SphinxTransformer.output_style=simple --template=sphinx_template.tplx test.ipynb
IPython Master
在IPython主分支中添加了其他单元格样式,请参见PR4112。如何使用这些样式在example1和examples2中有所展示。((= 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' *))
ipython nbconvert --to=latex --template=bw_python.tplx test.ipynb
。IPython.display.display
来显示值。这将防止单元格输出。此外,使用%%capture
魔术命令,可以防止任何剩余输出(警告、错误等)被呈现。exclude_input=True
来隐藏所有输入单元格。%%capture --no-display
import logging
from IPython.display import display
logging.warning("this warning is captured and not displayed")
display(1+1)
将显示2
,没有任何Out[1]
或警告。
然后,您可以使用以下命令将笔记本导出为不带任何输入单元格的格式:
nbconvert.export(exporter, 'notebook.ipynb', exclude_input=True)