Skip to content

Commit

Permalink
graphicx needs to be loaded correctly in each template
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv committed Nov 27, 2024
1 parent f180e02 commit e8e2150
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 3 additions & 2 deletions inst/rmarkdown/templates/lncs/resources/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@

% Add imagehandling
$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command.
$if(graphics)$$if(pandoc321)$
% Custom command from Pandoc 3.2.1 to scale images if necessary
$if(graphics)$
\usepackage{graphicx}
$if(pandoc321)$
% Custom command from Pandoc 3.2.1 to scale images if necessary
\makeatletter
\newsavebox\pandoc@box
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
Expand Down
17 changes: 12 additions & 5 deletions tests/testthat/test-check-template.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ temp_file <- list.files(pkg_file_template(), recursive = TRUE, pattern = "templa
# Rjournal template has another name
temp_file[grep("rjournal", temp_file)] <- pkg_file_template("rjournal", "resources", "RJwrapper.tex")

expect_contains <- function(file, pattern, nb = 1, ...) {
expect_contains <- function(file, pattern, nb = 1, at_least = NULL, ...) {
content <- xfun::read_utf8(file)
matched <- grepl(pattern, content, ...)
if (any(matched) && sum(matched) == nb) {
succeed()
return(invisible(file))
if (any(matched)) {
nb_match <- sum(matched)
if (is.null(at_least) && nb_match == nb) {
succeed()
return(invisible(file))
} else if (!is.null(at_least) && nb_match >= at_least) {
succeed()
return(invisible(file))
}
}
msg <- if (!any(matched)) {
sprintf(
Expand All @@ -23,7 +29,7 @@ expect_contains <- function(file, pattern, nb = 1, ...) {
sprintf(
"%s template contains %s instead of %s",
sQuote(basename(dirname(dirname(file)))),
sum(matched),
if (is.null(at_least)) nb_match else sprintf("at least %s", at_least),
nb
)
}
Expand Down Expand Up @@ -53,6 +59,7 @@ test_that("part for Pandoc's tables is defined in all templates", {
test_that("part for Pandoc's \\pandocbounded command is defined in all templates", {
for (f in temp_file) {
expect_contains(f, "if(graphics)", fixed = TRUE)
expect_contains(f, "graphicx", fixed = TRUE, at_least = 1)
expect_contains(f, "if(pandoc321)", fixed = TRUE)
expect_contains(f, "\\pandocbounded", fixed = TRUE)
}
Expand Down

0 comments on commit e8e2150

Please sign in to comment.