编辑以提供有关模板的更多信息:
从这里开始获取有关模板的一般信息。您可以在与笔记本相同的路径中创建一个.tplx
文件,并在从命令行运行nbconvert
时将其指定为模板:!jupyter nbconvert --to python 'example.ipynb' --stdout --template=my_custom_template.tplx
。或者,通过修改位于~.jupyter
目录中的jupyter_notebook_config.py
文件,在导出为Latex时指定默认模板。如果此文件不存在,则可以通过从命令行运行jupyter notebook --generate-config
命令来生成它。我的模板也位于~/.jupyter
目录中,因此我将以下内容添加到了我的jupyter_notebook_config.py
中:
# Insert this at the top of the file to allow you to reference
# a template in the ~.jupyter directory
import os.path
import sys
sys.path.insert(0, os.path.expanduser("~") + '/.jupyter')
# Insert this at the bottom of the file:
c.LatexExporter.template_file = 'my_template' # no .tplx extension here
c.LatexExporter.template_path = ['.', os.path.expanduser("~") + '/.jupyter'] # nbconvert will look in ~/.jupyter
((*- for cell in nb.cells -*))
循环遍历笔记本中的所有单元格。后面的if
语句检查每个单元格的类型并调用适当的块。null.tplx
。每个模板定义(或重新定义)一些块。层次结构是null->display_priority->document_contents->base->style_*->article
。article.tplx
并向标题添加一些Latex命令,以设置您想要的表格。参考this blog post,了解如何设置自定义模板的示例。