Skip to content

Conversation

@bastienchassagnol
Copy link

@bastienchassagnol bastienchassagnol commented Sep 13, 2025

Summary

Add Quarto minimal reprex tests, as the behaviour of Quarto documents differ from RMarkdown

Changes

  • Modified function R/latex_str.R paired with R/get_pdf_engine to support Quarto output.
  • Added unit tests: tests/testthat/qmd/use-printer-with-pdflatex.qmd

Rationale

Depending on the pdf-engine YAML option, you should not load fontspec package -> In quarto equally to Rmarkdown, the pdf-engine should be processed -> the differences between the two formats mostly lie in the way metadata for an individual quarto document is stored, see quarto-dev/quarto-cli#13371 for additional details.

Related

Fixes #701

Notes for maintainers

  • If you want me to squash commits, I can do that.
  • Interactive Debugging for Quarto is kinda stupid, requires calling rmarkdown::render, instead of quarto::quarto_render() -> however, doing this, you can't reproduce the error.

@bastienchassagnol bastienchassagnol marked this pull request as draft September 13, 2025 13:41
@bastienchassagnol bastienchassagnol marked this pull request as ready for review September 13, 2025 19:33
@bastienchassagnol
Copy link
Author

bastienchassagnol commented Sep 13, 2025

Current solution proposed is working, however, I've listed the following tracks of improvement:

  • Add automated testing for qmd generation, inspiring from ./tests/testthat/test-borders.R
  • Rewrite following code to make it more compact, and avoid nested if loops
  • Compare with Rmardkown parsing approaches listed here
  • Test, and add support for pdf-engine: tectonic, latexmk, as Quarto also accomodates for them -> do not know if they are compliant, or not with the fontspec package.
  if (length(rd)) {
    engine <- pandoc_args[rd + 1]
  } else if (is_in_quarto()) {
    # retrieve pdf engine if available
    engine <- rmarkdown::metadata$format$pdf$`pdf-engine`
    if (is.null(engine) || engine == "") {
      engine <- "xelatex"
    }
  } else {
    engine <- "pdflatex"
  }

@eli-daniels
Copy link
Collaborator

eli-daniels commented Oct 8, 2025

Hello @bastienchassagnol, thanks for the PR.

  1. Its really hard to see what changes have been made due to the code formatting edits. Could you remove those please, then happy to review.
  2. From a quick look you removed is_quarto, make sure to keep this.

@bastienchassagnol
Copy link
Author

Hi @eli-daniels — great to hear from you!

I’ll do my best to incorporate all the suggested changes. I have two quick comments:

  • Debugging while rendering to Quarto: Do you have any recommendations for streamlining debugging in interactive mode? It seems that, for now, the native RStudio debugger isn’t supported during Quarto rendering.

  • Regarding formatting differences:: I was initially surprised by the number of detected changes, as the edits I made were quite limited. On second thought, most differences are related to the use of [air](https://posit-dev.github.io/air/), the now-recommended formatter for R code. I’ve configured it to automatically restyle files on save — I can temporarily disable that option if preferred.

That said, @eli-daniels and @davidgohel, I’d be interested in your thoughts on the air formatter compared with the more traditional styler approach.

engine <- pandoc_args[rd + 1]
} else if (is_in_quarto()) {
engine <- rmarkdown::metadata$`pdf-engine`
quarto_v <- quarto::quarto_version()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eli-daniels the core changes are brought there.

Depending on the retrieved quarto version, two processes to retrieve metadata of a document:

  • Sys.getenv("QUARTO_EXECUTE_INFO") since Quarto v1.8, as described in details here
  • rmarkdown::metadata, the old-fahsioned way.

x <- list()

if (fontspec_compat || is_quarto) {
if (fontspec_compat) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I insist that variable is_quarto there is not useful. In the first use case, only used for triggering a warning. In the second use case, it's only fontspec_compat, as returned by function get_pdf\engine() that shoudl be used -> indeed, if the rendering is quarto, but the user-defined pdf-engine is pdflatex, you'll add fontspeclatex package dependancy, which is not compliant with the use of pdflatex (will even return the error I've raised in the issue).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eli-daniels (and @davidgohel ) sorry for my delayed answers. I've:

  • reverted the formatting changes induced by airstyler
  • precisely detail which chnages I have brought to R/latex_str.R
  • fetch the latest Quarto changes, and ensure that with my latest changes, rendering with Quarto is compliant with the choice of pdflatex engine

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accordingly, i believe that now, you can finally incporate my suggested PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad assumption of Quarto engine

2 participants