I am using bookdown in R. I have some sections I only want to appear in the HTML (gitbook) version (and not the PDF version).
I know about is_html_output()
, but that doesn't appear to be what I want, and doesn't work except for very simple bits of text. So this works:
`r if (knitr:::is_html_output())'
## Some text {-}
Things to say to HTML readers.
'
`
But this doesn't (does not compile) because of the tick in don't
:
`r if (knitr:::is_html_output())'
## Some text {-}
Things I don't want to say to PDF readers.
'
`
And any R code I wish to place in the chunk fails too.
So while I can use is_html_output()
, it very much restricts what I can do.
Is there an easy way to have some text--whole sections, and other large amounts--only visible in the HTML version?
Seems simple... but I can't find a solution. Thanks for help.
P.
You may consider using child documents, e.g.,
```{r, child = if (knitr::is_html_output()) 'child.Rmd'}
Then you can write arbitrary content in child.Rmd
.