0

When writing for publication, I greatly prefer the tikzDevice functionality of knitr, as it renders my plots in the same font as the document (among other things). I see that Quarto does this nicely in the PDF rendering. Here's a MWE:

---
title: "Untitled"
format: 
  pdf: default
  html: default
editor: visual
---

See the example in @fig-example

```{r, dev = 'tikz'}
#| label: fig-example
#| fig-cap: Example figure.
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point()
```

And the PDF output: PDF output

But when rendering to html, it tries to embed the PDF of the figure in a window:

HTML output

In bookdown, I could do something like dev = if(knitr::is_latex_output()){'tikz'}} but that doesn't seem to work in Quarto. I can also set the device with the global chunk option

knitr: 
  opts_chunk: 
    dev: 'tikz'

But this seems to apply to both PDF and html as well.

gregmacfarlane
  • 2,121
  • 3
  • 24
  • 53

1 Answers1

2

Adding this chunk to the front of the document seems to work, but it's a little bit clunky. I'm curious if there are any options that involve the YAML header options.

```{r}
if(knitr::is_latex_output()) {
  knitr::opts_chunk$set(dev = 'tikz')
}
```
gregmacfarlane
  • 2,121
  • 3
  • 24
  • 53