我正在尝试创建一个nbconvert (6.x)模板,该模板稍微修改默认的latex模板。
我在no_header中创建了一个“<userprofile>\Miniconda3\share\jupyter\nbconvert\templates\no_header”模板
.
+-- no_header
| +-- conf.json
| +-- no_header.tex.j2conf.json包含:
{
"base_template": "latex",
"mimetypes": {
"text/latex": true,
"text/tex": true,
"application/pdf": true
}
}no_header.tex.j2包含:
((*- extends 'latex' -*))
((*- block packages -*))
asdf
((* endblock packages *))我从packages中取了块名为style_jupyter.tex.j2。本节包含一些使用包命令。
然后,我创建了一个简单的笔记本,并尝试使用模板通过命令将其转换为tex:
jupyter nbconvert --to=latex --template=no_header my_nb.ipynb
该命令成功地创建了tex输出,但它似乎没有使用模板。如果我将模板参数省略到cli调用中,输出将完全相同。此外,生成的文件中不存在字符串asdf,进一步表明模板未被激活。
使用--debug运行上述命令时,no_header模板将列在“模板路径”列表下。另外,当我拼错模板名时,我得到了一个错误,所以我认为调用确实找到了模板,但不知怎么没有使用它。
到目前为止我尝试过的是:
这里有人能帮我吗?
发布于 2022-02-23 17:15:47
conf.json文件很好,但我认为您需要调用入口点index.tex.j2。模板的名称是由目录定义的,而不是.j2文件名。
然后,在no_header/index.tex.j2中,指定要从哪个模板继承,例如从标准的乳胶文章中借用,如下所示:
((=- Default to the notebook output style -=))
((*- if not cell_style is defined -*))
((* set cell_style = 'style_jupyter.tex.j2' *))
((*- endif -*))
((=- Inherit from the specified cell style. -=))
((* extends cell_style *))
((*- block docclass -*))
\documentclass[11pt]{article}
((*- endblock docclass -*))然后,要定制packages部分,您可以添加如下所示:
((*- block packages -*))
asdf
((* endblock packages *))想必你会想要在“包”块中放更多。如果您想要添加某些块而不是覆盖,请包含一个超级()调用。
默认的latex模板目录中有许多文件,这些文件添加了大量的latex命令;您可以跟踪继承链(在上面的示例中,从style_jupyter.tex.j2开始)以查看所有不同的块被调用了什么,以便您可以根据需要对它们进行调整(例如,“边距”)。
https://stackoverflow.com/questions/68015894
复制相似问题