如何在 bookdown::gitbook 中使用自定义 pandoc HTML 模板 [英] How to use a custom pandoc HTML template in bookdown::gitbook
问题描述
我想为 bookdown 项目编写自定义模板.从 bookdown 包的 documentation 我读到可以使用自定义模板替换默认模板,例如 my_custom_template.html
,通过在 YAML 标头中包含 template: "my_custom_template.html"
像
I'd like to write a custom template for a bookdown project. From the documentation of the bookdown package I read that it is possible to replace the default template with a custom one, say my_custom_template.html
, by including template: "my_custom_template.html"
in the YAML header like
bookdown::gitbook:
template: my_custom_template.html
这样做会产生以下错误:
Doing so yields the following error:
Error in rmarkdown::html_document(..., extra_dependencies = c(extra_dependencies, :
formal argument "template" matched by multiple actual arguments
Calls: <Anonymous> ... do.call -> <Anonymous> -> html_document2 -> <Anonymous>
Execution halted
Error in eval(expr, envir, enclos) :
Failed to compile the book to bookdown::gitbook
在我看来,默认模板是硬编码的,因此无法那么容易地覆盖.
It seems to me that the default template is hardcoded and thus cannot be overriden that easy.
还有其他方法可以包含自定义模板吗?
Is there another way to include a custom template?
推荐答案
更新:自从 bookdown v0.8(感谢 PR #570).
Update: This has become possible since bookdown v0.8 (thanks to the PR #570).
这是不可能的,它是这样记录的:在所用函数的文档中 (?bookdown::gitbook
) template
从列表中排除要传递给 rmarkdown::html_document()
的可用参数,以及 toc
和 theme
.您链接到的页面中也提到了这一点:
This is not possible, and it is documented this way: In the documentation for the used function (?bookdown::gitbook
) template
is excluded from the list of available parameters to be passed to rmarkdown::html_document()
, along with toc
and theme
. This is also mentioned in the page you are linking to:
html_document() 有几个参数是硬编码的在 gitbook() 中,您不能更改它们:toc = TRUE(必须有一个目录),主题 = NULL(不使用任何 Bootstrap 主题),以及模板(存在一个内部 GitBook 模板).
There are a few arguments of html_document() that have been hard-coded in gitbook() and you cannot change them: toc = TRUE (there must be a table of contents), theme = NULL (not using any Bootstrap themes), and template (there exists an internal GitBook template).
这篇关于如何在 bookdown::gitbook 中使用自定义 pandoc HTML 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!