diff --git a/R/pdf_document.R b/R/pdf_document.R index 06ca48e..2c00dd0 100644 --- a/R/pdf_document.R +++ b/R/pdf_document.R @@ -80,12 +80,14 @@ pdf_document <- function(toc = TRUE, ## code chunks and code highlighting thm <- system.file("themes", "default.css", package = "BiocStyle") - opts_knit$set(out.format="latex"); + out_fmt <- opts_knit$get("out.format") + opts_knit$set(out.format="latex") head = c(head, "% code highlighting", knit_theme$get(thm)$highlight, readLines(file.path(resources, "tex", "highlighting-macros.def"))) - + opts_knit$set(out.format=out_fmt) + if (use_unsrturl) head = c(head, sprintf("\\AtBeginDocument{\\bibliographystyle{%s}}\n", sub(".bst$", "", template_files[["bst"]]))) diff --git a/inst/unitTests/test_pdf_document.R b/inst/unitTests/test_pdf_document.R index 478cfb5..112cc07 100644 --- a/inst/unitTests/test_pdf_document.R +++ b/inst/unitTests/test_pdf_document.R @@ -2,9 +2,27 @@ test_pdf_document <- function() { filename <- rmarkdown::draft(tempfile(fileext = ".Rmd"), edit = FALSE, template="pdf_document", package = "BiocStyle") lines <- BiocStyle:::readUTF8(filename) - lines <- BiocStyle:::modifyLines(lines, from = "title:", replace = FALSE, + lines <- BiocStyle:::modifyLines(lines, from = "title:", replace = FALSE, insert='subtitle: "Vignette Subtitle"') BiocStyle:::writeUTF8(lines, filename) rmarkdown::render(filename) unlink(filename) } + +test_pdf_document_restores_out_format <- function() { + ## Regression test for https://github.com/Bioconductor/BiocStyle/pull/108 + ## + ## BiocStyle::pdf_document() temporarily sets the global knitr option + ## 'out.format' to "latex" in order to look up the syntax highlighting + ## theme, but used to leave it set afterwards. This corrupted the knitr + ## state for anything rendered later in the same R session, e.g. pkgdown + ## building several articles (one of which uses BiocStyle::pdf_document) + ## within a single process, which itself relies on 'out.format' being + ## "html". + out_format_before <- knitr::opts_knit$get("out.format") + on.exit(knitr::opts_knit$set(out.format = out_format_before)) + + knitr::opts_knit$set(out.format = "html") + invisible(BiocStyle::pdf_document()) + checkIdentical(knitr::opts_knit$get("out.format"), "html") +}