As explained in this chapter of the R Markdown Cookbook, it is possible to make custom blocks in R Markdown files with this syntax (here, to center some text):
:::{.center data-latex=""}
Hello
:::
However, using cat() to render this sort of block (as explained in this chapter) does not work.
Full example:
---
output: rmarkdown::pdf_document
---
<!-- WORKS -->
:::{.center data-latex=""}
Hello
:::
<!-- DOES NOT WORK -->
```{r, results='asis', echo=FALSE}
print(
'
:::{.center data-latex=""}\n
Hello\n
:::
'
)
```
Why is the second part not rendering correctly? How to solve that?
