4

I currently have a few bookdown projects which are hosted as Github.io projects. Across these projects I use custom defined css styling for chunks, which allow for code folding boxes and coloured notes.

I'd like to be able to render these projects in a pdf version as well as the html. Clearly this would require changing the chunk options for a large number of code chunks so doing it manually would not be feasible.
For example a chunk such as

```{r, engine=block2, type='fold'}
Some uninspired R code ```

Is unable to be rendered to pdf due to the html required for styling. Therefore if there a way to change this, and chunks like these, to a format which allows for pdf rendering.

I was wondering if anybody has a good system in place for doing this?

Oska Fentem
  • 135
  • 6
  • You can use pandoc filters with conditional statements to trigger different behaviour according to which output format you desire. See https://jmablog.com/post/pandoc-filters/ for how pandoc filters work. This can be used in conjunction with the `bs4_book` output format for bookdown, see https://bookdown.org/yihui/bookdown/html.html – Elliot Jun 24 '22 at 04:10

0 Answers0