简体   繁体   English

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

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

I'd like to write a custom template for a bookdown project.我想为 bookdown 项目编写一个自定义模板。 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 包的文档中,我读到可以用自定义模板替换默认模板,比如my_custom_template.html ,通过在 YAML 标头中包含template: "my_custom_template.html" ,如

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?还有另一种方法可以包含自定义模板吗?

Update : This has become possible since bookdown v0.8 (thanks to the PR #570 ).更新:从bookdown v0.8开始这已经成为可能(感谢 PR #570 )。


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 .这是不可能的,它是这样记录的:在使用的函数( ?bookdown::gitbook )的文档中, template被排除在要传递给rmarkdown::html_document()的可用参数列表中,以及toctheme This is also mentioned in the page you are linking to:您链接到的页面中也提到了这一点:

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).有一些 html_document() 的参数已经在 gitbook() 中硬编码,您无法更改它们:toc = TRUE(必须有目录),theme = NULL(不使用任何 Bootstrap 主题),以及模板(存在一个内部 GitBook 模板)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM