我想为 bookdown 项目编写一个自定义模板。来自 documentation在 bookdown 包中,我读到可以用自定义模板替换默认模板,例如 my_custom_template.html
,方法是将 template: "my_custom_template.html"
包含在YAML header 如
bookdown::gitbook:
template: my_custom_template.html
这样做会产生以下错误:
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
在我看来,默认模板是硬编码的,因此不能轻易覆盖。
还有其他方法来包含自定义模板吗?
最佳答案
更新:自 bookdown v0.8 以来,这已成为可能(感谢 PR #570)。
这是不可能的,它是这样记录的:在所用函数的文档中 (?bookdown::gitbook
) template
被排除在以下列表之外要传递给 rmarkdown::html_document()
的可用参数,以及 toc
和 theme
。您链接到的页面中也提到了这一点:
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).
关于r - 如何在 bookdown::gitbook 中使用自定义 pandoc HTML 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52316862/