-
Notifications
You must be signed in to change notification settings - Fork 89
Add tests for quarto, with pdflatex engine #702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bastienchassagnol
wants to merge
6
commits into
davidgohel:master
Choose a base branch
from
bastienchassagnol:feature/quarto-support-pdf-engine
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08d8342
add tests for quarto, with pdflatex engine
bastienchassagnol caa7c76
working solution, I believe
bastienchassagnol 206e2e4
compare distinct approaches of retrieving quarto metadata information
bastienchassagnol 5873df4
include recommended approach for retrieving quarto metadata in an int…
bastienchassagnol 7abc84f
Merge remote-tracking branch 'upstream/master' into feature/quarto-su…
bastienchassagnol 770518c
restore R files before automated air formatting, and perform instead …
bastienchassagnol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,11 +26,9 @@ list_latex_dep <- function(float = FALSE, wrapfig = FALSE) { | |
| return(list()) | ||
| } | ||
|
|
||
| is_quarto <- is_in_quarto() | ||
|
|
||
| fonts_ignore <- flextable_global$defaults$fonts_ignore | ||
| fontspec_compat <- get_pdf_engine() %in% c("xelatex", "lualatex") | ||
| if (!is_quarto && !fonts_ignore && !fontspec_compat) { | ||
| if (!fonts_ignore && !fontspec_compat) { | ||
| warning("fonts used in `flextable` are ignored because ", | ||
| "the `pdflatex` engine is used and not `xelatex` or ", | ||
| "`lualatex`. You can avoid this warning by using the ", | ||
|
|
@@ -43,7 +41,7 @@ list_latex_dep <- function(float = FALSE, wrapfig = FALSE) { | |
|
|
||
| x <- list() | ||
|
|
||
| if (fontspec_compat || is_quarto) { | ||
| if (fontspec_compat) { | ||
| x$fontspec <- latex_dependency("fontspec") | ||
| } | ||
| x$multirow <- latex_dependency("multirow") | ||
|
|
@@ -433,11 +431,24 @@ get_pdf_engine <- function() { | |
| if (length(rd)) { | ||
| engine <- pandoc_args[rd + 1] | ||
| } else if (is_in_quarto()) { | ||
| engine <- rmarkdown::metadata$`pdf-engine` | ||
| quarto_v <- quarto::quarto_version() | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
| if (quarto_v >= "1.8.0") { | ||
| # Modern and recommended way to retrieve metadata, from https://github.com/quarto-dev/quarto-cli/discussions/13371 | ||
| quarto_metadata <- jsonlite::read_json( | ||
| Sys.getenv("QUARTO_EXECUTE_INFO") | ||
| ) | ||
| # engine <- quarto_metadata$format$pandoc$`pdf-engine` -> this field is never empty | ||
| engine <- quarto_metadata$format$metadata$format$pdf$`pdf-engine` # this field has a value only if the yaml key `pdf-engine` is explicitly mentionned | ||
| } else { | ||
| # Old trick for calling metadata, only works if the rendering engine is knitr (and not jupyter) | ||
| quarto_metadata <- rmarkdown::metadata | ||
| engine <- quarto_metadata$format$pdf$`pdf-engine` | ||
| } | ||
| if (is.null(engine) || engine == "") { | ||
| engine <- "xelatex" | ||
| } | ||
| } else { | ||
| # Default pdf-engine for RMarkdown | ||
| engine <- "pdflatex" | ||
| } | ||
| engine | ||
|
|
||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| --- | ||
| title: "Pdflatex not working with flextable" | ||
| engine: knitr | ||
| format: | ||
| pdf: | ||
| pdf-engine: pdflatex # tectonic, latexmk, xelatex, lualatex | ||
| keep-tex: true | ||
| --- | ||
|
|
||
|
|
||
| ```{r} | ||
| #| label: setup | ||
|
|
||
| library(flextable) | ||
|
|
||
|
|
||
| # different ways to access quarto metadata ---- | ||
| ## Many things listed in quarto_metadata, like default options, but not the current options used in the yaml | ||
| quarto_metadata <- knitr::opts_current$get() | ||
| saveRDS(quarto_metadata, "./quarto_metadata.rds") | ||
|
|
||
| ## Only works for quarto version beyond 1.8, but lots of nice execution operations | ||
| quarto_metadata_second_way <- jsonlite::read_json( | ||
| Sys.getenv("QUARTO_EXECUTE_INFO")) | ||
| # two ways to reach the pdf-engine | ||
| all.equal(quarto_metadata_second_way$format$pandoc$`pdf-engine`, | ||
| quarto_metadata_second_way$format$metadata$format$pdf$`pdf-engine`) | ||
| saveRDS(quarto_metadata_second_way, "./quarto_metadata_second_way.rds") | ||
|
|
||
| ## This command returns exactly the yaml of the header, great!! :-) | ||
| rmarkdown_metadata <- rmarkdown::metadata | ||
| saveRDS(rmarkdown_metadata, "./rmarkdown_metadata.rds") | ||
|
|
||
| ## Returns only the output file | ||
| rmarkdown_pandoc_args <- knitr::opts_knit$get("rmarkdown.pandoc.args") | ||
| saveRDS(rmarkdown_pandoc_args, "./rmarkdown_pandoc_args.rds") | ||
|
|
||
| ## programamtic ways to run qmd, or Rmd scripts ---- | ||
| # rmarkdown::render("./tests/testthat/qmd/use-printer-with-pdflatex.qmd", | ||
| # output_format = c("pdf_document"), | ||
| # output_file = "C:/Users/basti/OneDrive/04. BNCL (Post Doc)/Open-Source Development/flextable/tests/testthat/qmd/use-printer-with-pdflatex.qmd") | ||
| # quarto::quarto_render("./tests/testthat/qmd/use-printer-with-pdflatex.qmd") | ||
| ``` | ||
|
|
||
|
|
||
| - `flextable` with Equations, see @tbl-flextable: | ||
|
|
||
| ```{r} | ||
| #| label: tbl-flextable | ||
|
|
||
|
|
||
| eqs_flextable <- c( | ||
| "(ax^2 + bx + c = 0)", | ||
| "a \\ne 0", | ||
| "x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}") | ||
| df <- tibble::tibble(`Y \\sim W` = eqs_flextable) | ||
|
|
||
|
|
||
| ft <- flextable(df) |> | ||
| compose(j = 1, part = "header", | ||
| value = as_paragraph(as_equation(`Y \\sim W`, width = 2, height = .5)), | ||
| use_dot = TRUE) |> | ||
| compose(j = 1, part = "body", | ||
| value = as_paragraph(as_equation(`Y \\sim W`, width = 2, height = .5))) |> | ||
| align(align = "center", part = "all") | ||
|
|
||
| ft | ||
|
|
||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_quartothere is not useful. In the first use case, only used for triggering a warning. In the second use case, it's onlyfontspec_compat, as returned by functionget_pdf\engine()that shoudl be used -> indeed, if the rendering is quarto, but the user-defined pdf-engine ispdflatex, you'll addfontspeclatex package dependancy, which is not compliant with the use ofpdflatex(will even return the error I've raised in the issue).There was a problem hiding this comment.
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:
airstylerR/latex_str.RpdflatexengineThere was a problem hiding this comment.
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.