在NBConvert中取消代码? IPython的 [英] Suppress code in NBConvert? IPython

查看:97
本文介绍了在NBConvert中取消代码? IPython的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经想出如何抑制大型代码块出现在最终的NB转换(PDF)输出中。

I have figured out how to suppress large code blocks from showing up in final NB convert (PDF) output.

将LaTex命令放在原始单元格中在我不希望在最终输出中的代码之前

By putting the LaTex command in a "raw cell before the code I don't want to have in the final output

\iffalse

跟随此结尾在原始单元格中

Followed By this at the end In a raw cell

\fi

但是当我需要展示时,这仍然留给我一些丑陋的代码数字等等虽然笔记本的基本目的是显示带有结果的代码,有时对于非技术受众我们只需要输出..任何想法?

But That still leaves me with some ugly code when I need to show figures and the like and while the base purpose of the notebook is to show code with results, sometimes for a non tech audience we only need the output.. Any Ideas?

如果有人受到启发有点相关..任何方式在降价单元格中包含python变量,这样可以有计算结果的动态文本吗?抱歉第二个问题但是我不确定我是否想要单独问这个有一些奇怪的原因。

Somewhat related if anyone is inspired.. any way to include python variables in the markdown cells so one could have dynamic text with calculated result? Sorry for a second issue but I'm not sure I want to ask this one separately for some strange reason.

推荐答案

抑制代码单元格(o nly input)可以使用自定义模板。与此问题中讨论的类似,例如必须使用以下内容(在IPython 1.x中)创建 latex_nocode.tplx (在工作目录中)

To suppress the code cells (only input) a custom template can be used. Similar as discussed in this question, a template e.g. latex_nocode.tplx has to be created (in the working directory) with the following content (for IPython 1.x)

((*- extends 'latex_article.tplx' -*))
% Disable input cells
((* block input_group *))
((* endblock input_group *))

使用此模板,例如

ipython nbconvert - -to = latex --template = latex_nocode.tplx --post = pdf file.ipynb

也许我应该这样添加输入块被简单地替换为空白块(实际上是输入单元被禁用的乳胶注释)。

检查预定义的乳胶模板时,可以识别各个块(代码,降价,标题等),可以设置相应的自定义模板以根据需要设置输出样式。

Maybe I should add that this way the input block is simply replaced by a blank block (actually a latex comment that input cells are disabled).
When checking the predefined latex templates, the individual blocks (code, markdown, heading, etc) can be identified and a respective custom templates can be set-up to style the output as desired.

因为用户1248490指出自IPython 2.0以来要扩展的乳胶模板称为
article.tplx report.tplx base.tplx 。因此,上面的示例应该看起来像

as user1248490 pointed out since IPython 2.0 the latex templates to be extended are called article.tplx, report.tplx or base.tplx. Hence the example from above should look like

((*- extends 'article.tplx' -*))
% Disable input cells
((* block input_group *))
((* endblock input_group *))

这篇关于在NBConvert中取消代码? IPython的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆