[英]Show only specific (tagged) input cells in pdf created with nbconvert from jupyter notebook
In various jupyter notebooks I want to manually specify which input cells to show and per default not show any input cell when converting it to a pdf or tex document. 在各种Jupyter笔记本电脑中,我想手动指定要显示的输入单元格,并且在将其转换为pdf或tex文档时默认情况下不显示任何输入单元格。
I already achieved not showing any input cells by using following latex template: 通过使用以下乳胶模板,我已经实现了不显示任何输入单元的效果:
((*- extends 'article.tplx' -*))
% Disable input cells
((* block input_group *))
((* endblock input_group *))
But now, when trying to add cell tags and then showing them or not I'm confusing. 但是现在,当尝试添加单元格标签然后显示或不显示它们时,我感到困惑。 I tried
我试过了
% Disable input cells if there is no "show" tag, else show
((*- block input_group -*))
((*- if 'show' in cell.metadata.get('tags', []) -*))
((*- block in_prompt -*))((*- endblock in_prompt -*))
((*- block input -*))((*- endblock input -*))
((*- else -*))
((*- endif -*))
((*- endblock input_group -*))
but it's always removing all input cells, the one with "show" tag too. 但它总是删除所有输入单元格,也带有“ show”标签的单元格。
While writing this question, I realized that i copied the lines 4 and 5 in the second code block from the wrong file. 在写这个问题时,我意识到我从错误的文件中复制了第二个代码块中的第4行和第5行。 It's from the
null.tplx
(skeleton) template, I should've used the style_ipython.tplx
from where it is most of the time inherited. 它来自
null.tplx
(骨架)模板,我应该在大多数情况下从那里使用style_ipython.tplx
。
I came up with the following code, which now really removes/hides/supresses all input cells except the ones with the "show" tag: 我想出了以下代码,该代码现在实际上删除/隐藏/隐藏了所有带有“ show”标签的输入单元格:
% Disable input cells if there is no "show" tag, else show
((*- block input_group -*))
((*- if 'show' in cell.metadata.get('tags', []) -*))
((( add_prompt(cell.source | highlight_code(strip_verbatim=True), cell, 'In ', 'incolor') )))
((*- else -*))
((*- endif -*))
((*- endblock input_group -*))
But then it will only work with the ipython style, not with the python one... maybe someone can help here? 但是,它仅适用于ipython样式,不适用于python样式...也许有人可以在这里提供帮助?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.