简体   繁体   English

仅显示从Jupyter Notebook用nbconvert创建的pdf中的特定(带标签)输入单元格

[英]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.

相关问题 将jupyter笔记本转换为pdf(彩色) - nbconvert jupyter notebook to pdf (with color) 使用 nbconvert 将 Jupyter 笔记本导出到 PDF 时的模板 - Templates while exporting Jupyter notebook to PDF with nbconvert 使用 Jupyter notebook 和 nbconvert 创建幻灯片时如何使单元格输入部分(代码)消失 - 仅显示输出? - How to make Cell input part (code) disappear -show only output- when creating slides using Jupyter notebook and nbconvert? 如何使用 nbconvert 从 Jupyter Notebook 到 HTML - How to use nbconvert from Jupyter Notebook to HTML 如何在使用 nbconvert 从 Jupyter 导出为 pdf 时显示宽表的所有 DataFrame/表列? - How to show all DataFrame/ table columns for wide tables while exporting as pdf from Jupyter using nbconvert? Nbconvert 不显示来自 jupyter notebook 的 styler dataframe - Nbconvert doesn't display styler dataframe from jupyter notebook 我需要什么降价模板,以便在使用nbconvert导出时,Jupyter笔记本中的输出单元格看起来与输入单元格不同 - What markdown template do I need such that output cells in Jupyter notebooks look different from input cells when exporting using nbconvert 仅执行大型 jupyter 笔记本中的一些单元格 - execute only some cells from a large jupyter notebook 使用 jupyter nbconvert 在不同的目录中运行 jupyter notebook - Run a jupyter notebook in a different directory with jupyter nbconvert 从 VSCode 导出 Juypter Notebook 时,如何只显示某些单元格输入或 output? - How do I only show certain cells input or output when exporting a Juypter Notebook from VSCode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM