HTML-bookdown 中的特定部分

HTML-specific section in bookdown

我在 R 中使用 bookdown。我有一些 部分 我只想出现在 HTML (gitbook) 版本(而不是 PDF 版本)中。

我知道 is_html_output(),但这似乎不是我想要的,而且除了非常简单的文本之外,它不起作用。所以这有效:

`r if (knitr:::is_html_output())'
## Some text {-}

Things to say to HTML readers.
'
`

但由于 don't 中的勾号,这不会(不会编译):

`r if (knitr:::is_html_output())'
## Some text {-}

Things I don't want to say to PDF readers.
'
`

我希望放入块中的任何 R 代码也都失败了。

所以虽然我可以使用 is_html_output(),但它极大地限制了我可以做的事情。

有没有一种简单的方法可以使某些文本(整节和其他大量文本)仅在 HTML 版本中可见?

看起来很简单...但我找不到解决方案。感谢您的帮助。

P.

您可以考虑使用 child documents,例如

```{r, child = if (knitr::is_html_output()) 'child.Rmd'}

那你就可以在child.Rmd里面写任意内容了。