如何在 bookdown::gitbook 中使用自定义 pandoc HTML 模板

How to use a custom pandoc HTML template in bookdown::gitbook

我想为 bookdown 项目编写自定义模板。从 bookdown 包的 documentation 我读到可以用自定义模板替换默认模板,比如 my_custom_template.html,通过在 YAML header 中包含 template: "my_custom_template.html" 就像

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 (thanks to the PR #570)以来,这已成为可能。


这是不可能的,它是这样记录的:在所用函数 (?bookdown::gitbook) 的文档中,template 被排除在要传递给 [= 的可用参数列表之外12=],以及 toctheme。您链接到的页面中也提到了这一点:

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).