我已经制作了一个自定义的nbconvert模板,并希望可以从启动nbconvert
实用程序的任何文件夹中对其进行访问。我应该在哪里放置模板?
我在官方文档中找不到任何内容。我已经尝试了jupyter配置的常用位置,例如/usr/share/jupyter
,~/.local/share/jupyter
,~/.jupyter
,但无济于事。
到目前为止,我唯一找到的地方是python包所在的文件夹:
$ pip show nbconvert | grep Location | cut -d" " -f2
/usr/lib/python3.6/site-packages
如果我在此处创建
nbconvert/templates/html
目录并将模板放在其中,则nbconvert --to html --template <my_template_name> ...
可以正常工作。但这是一个丑陋的hack,每次我更新nbconvert时都需要重新做一次。似乎我可以为nbconvert提供环境变量,但我希望避免使用此选项。
最佳答案
您需要通过创建 nbconvert
文件并将其存储在jupyter_nbconvert_config.py
中,告诉~/.jupyter
查找模板。
我将其用于LaTeX-这是我的文件的样子:
import os
c = get_config()
c.LatexExporter.template_path = ['.', os.path.expanduser('~/.jupyter/templates')]
c.LatexExporter.template_file = 'custom_latex.tplx'
假设您的模板扩展了现有模板,则在设置
'.'
时需要包括template_path
,以便知道在哪里寻找标准模板。