Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/pdf_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"]])))

Expand Down
20 changes: 19 additions & 1 deletion inst/unitTests/test_pdf_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}