Skip to content

Commit

Permalink
fix: font instruction issue with PDF and quarto
Browse files Browse the repository at this point in the history
fix #625
  • Loading branch information
davidgohel committed Apr 12, 2024
1 parent 9850174 commit a77d19c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: flextable
Type: Package
Title: Functions for Tabular Reporting
Version: 0.9.6.006
Version: 0.9.6.007
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"),
email = "david.gohel@ardata.fr"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ loops or `if` statements.
## Issues

- fix issue with `as_image()` when the table contains no text.
- fix font instruction issue with PDF and quarto

# flextable 0.9.5

Expand Down
5 changes: 5 additions & 0 deletions R/latex_str.R
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ get_pdf_engine <- function() {
rd <- grep("--pdf-engine", pandoc_args)
if (length(rd)) {
engine <- pandoc_args[rd + 1]
} else if (is_in_quarto()) {
engine <- rmarkdown::metadata$`pdf-engine`
if (is.null(engine) || engine == "") {
engine <- "xelatex"
}
} else {
engine <- "pdflatex"
}
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,25 @@ test_that("white spaces are protected", {
str <- flextable:::gen_raw_latex(ft)
expect_true(grepl("{\\ }", str, fixed = TRUE))
})


test_that("fonts are defined in latex", {
gdtools::register_liberationsans()
ft <- flextable::flextable(head(cars, n = 1)) |>
flextable::font(fontname = "Liberation Sans", part = "body")

# R Markdown with pdflatex
knitr::opts_knit$set("quarto.version"=NULL)
latex_str <- flextable:::gen_raw_latex(ft, quarto = FALSE)
expect_no_match(latex_str, regexp = "Liberation Sans", fixed = TRUE)

knitr::opts_knit$set("rmarkdown.pandoc.args"= c("--pdf-engine", "xelatex"))
latex_str <- flextable:::gen_raw_latex(ft, quarto = FALSE)
expect_match(latex_str, regexp = "Liberation Sans", fixed = TRUE)
knitr::opts_knit$set("rmarkdown.pandoc.args"= NULL)

# quarto
knitr::opts_knit$set("quarto.version"=1)
latex_str <- flextable:::gen_raw_latex(ft, quarto = TRUE)
expect_match(latex_str, regexp = "Liberation Sans", fixed = TRUE)
})

0 comments on commit a77d19c

Please sign in to comment.