### Bug description

Compiling a qmd file to PDF doesn't work if it contains an R HTML widget. Here is a minimal reproducible example with a leaflet map (but the behavior is the same with a visNetwork graph for example) :

````md
---
format:
  pdf:
    prefer-html: false
---

# Leaflet test

```{r}
library(leaflet)

leaflet() %>%
  addTiles()
```
````

When rendering to PDF with `prefer-html: false`, I get the following error message :

> Error : Functions that produce HTML output found in document targeting pdf output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your quarto file:
>
>  prefer-html: true
>
> Note however that the HTML output will not be visible in non-HTML formats.

If I set `prefer-html: true`, I get another error message during xelatex compilation step :

> compilation failed- error
> LaTeX Error: Missing \begin{document}.
>
> See the LaTeX manual or LaTeX Companion for explanation.
> Type  H <return>  for immediate help.
> ...                                              
>                                                  
> l.141 <
>        script src="site_libs/htmlwidgets-1.6.1/htmlwidgets.js"></script> 

Indeed, if I take a look at the generated TeX file there are `<script>` and `<link>` tags inserted inside TeX code.

I'm using quarto 1.2.335 with Visual Studio code under Linux (KDE Neon / Ubuntu 22.04).

Thanks a lot !



### Checklist

- [X] Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [X] Please [format your issue](https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us) so it is easier for us to read the bug report.
- [X] Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [X] Please document the operating system you're running. If on Linux, please provide the specific distribution.
cderv
2023-02-04T19:18:23Z
juba
documentation
v1.4
open
Can't compile to PDF when including an R HTML widget
https://github.com/quarto-dev/quarto-cli/issues/4225