I have a qmd Quarto file with different output formats, html and pdf.
My goal is, to generate graphics in dependence of the output format.
How can I detect in an R cell, if the processing output format is html or pdf?
A simple if statement would be sufficient.
---
title: My title
format:
html:
toc: true
toc-depth: 3
html-math-method: katex
pdf:
keep-tex: true
toc: true
number-sections: true
colorlinks: true
---
´´´
>Solution :
Using knitr::is_html_output you could do:
---
title: My title
format:
html:
toc: true
toc-depth: 3
html-math-method: katex
pdf:
keep-tex: true
toc: true
number-sections: true
colorlinks: true
---
```{r}
if (knitr::is_html_output()) {
print("HTML")
} else {
print("pdf")
}
```
Which in case of html will give:
and for pdf:

