Skip to content
Permalink
Browse files
Patch the Pandoc LaTeX template instead of providing our own, which i…
…s too hard to maintain (#1563)

* Patch pandoc LaTeX template

Patch the pandoc LaTeX template to include the document subtitle (unnecessary with pandoc 2.6 onwards) using `--include-in-header` rather than overwriting its built-in template, avoiding compability problems with newer versions of pandoc. Closes #1510.

* Missing quotes

* Fix changelog typo

* Ensure self-contained is set for LaTeX

* Less verbose graphics setting

* move news of #1563 to v1.18

* cosmetic

* force --self-contained regardless of the template

* factor out pandoc_path_arg(rmarkdown_system_file(...)) to system_file_arg()

* support compact titles via a header include compact-title.tex

I didn't consider ef41eb4. I think it is a relatively minor issue and not worth the effort (if we have to bring it back, we need to test has_yaml_parameter(, 'author') and has_yaml_parameter(, 'date'), and conditionally include more titling hacks)

* mention the PR #252 which introduced the titling hacks

* cosmetic

* shouldn't change the value of the `template` argument when it is `default`

* add Andrew Dunning to the list of contributors

* also closes #1649
  • Loading branch information
adunning authored and yihui committed Nov 25, 2019
1 parent 00a4a45 commit b2adfda04db26fd9014ca4cc64af91e9835550b4
Showing 15 changed files with 55 additions and 1,158 deletions.
@@ -15,6 +15,7 @@ Authors@R: c(
person("Richard", "Iannone", role = "aut", email = "rich@rstudio.com", comment = c(ORCID = "0000-0003-3925-190X")),
#
# Contributors, ordered alphabetically by first name
person("Andrew", "Dunning", role = "ctb"),
person("Atsushi", "Yasumoto", role = "ctb", comment = c(ORCID = "0000-0002-8335-495X")),
person("Barret", "Schloerke", role = "ctb"),
person("Christophe", "Dervieux", role = "ctb"),
@@ -1,6 +1,8 @@
rmarkdown 1.18
================================================================================

- For `pdf_document()`, now we patch Pandoc's built-in LaTeX template to include the document subtitle (unnecessary with pandoc 2.6 onwards) and reduce the vertical spacing before title using `--include-in-header` rather than overwriting the built-in template, avoiding compability problems with newer versions of Pandoc (thanks, @adunning, #1563).

- `find_external_resources()` works now when multiple files are specified in the `includes` option of the output format (thanks, @andrie, #1677).

- `find_external_resources()` can find external resources specified in the output format's `reference_doc` or `reference_docx` option now (thanks, @jmcphers, #1696).
@@ -111,7 +111,7 @@ beamer_presentation <- function(toc = FALSE,
args <- c(args, pandoc_highlight_args(highlight))

# latex engine
latex_engine = match.arg(latex_engine, c("pdflatex", "lualatex", "xelatex"))
latex_engine <- match.arg(latex_engine, c("pdflatex", "lualatex", "xelatex"))
args <- c(args, pandoc_latex_engine_args(latex_engine))

# citation package
@@ -31,8 +31,8 @@ github_document <- function(toc = FALSE,

# add special markdown rendering template to ensure we include the title fields
pandoc_args <- c(
pandoc_args, "--template", pandoc_path_arg(rmarkdown_system_file(
"rmarkdown/templates/github_document/resources/default.md"))
pandoc_args, "--template", system_file_arg(
"rmarkdown/templates/github_document/resources/default.md")
)

pandoc2 <- pandoc2.0()
@@ -51,13 +51,13 @@ github_document <- function(toc = FALSE,
if (html_preview) {
format$post_processor <- function(metadata, input_file, output_file, clean, verbose) {

css <- pandoc_path_arg(rmarkdown_system_file(
"rmarkdown/templates/github_document/resources/github.css"))
css <- system_file_arg(
"rmarkdown/templates/github_document/resources/github.css")
# provide a preview that looks like github
args <- c(
"--standalone", "--self-contained", "--highlight-style", "pygments",
"--template", pandoc_path_arg(rmarkdown_system_file(
"rmarkdown/templates/github_document/resources/preview.html")),
"--template", system_file_arg(
"rmarkdown/templates/github_document/resources/preview.html"),
"--variable", paste0("github-markdown-css:", css),
"--email-obfuscation", "none", # no email obfuscation
if (pandoc2) c("--metadata", "pagetitle=PREVIEW") # HTML5 requirement
@@ -260,11 +260,11 @@ html_document <- function(toc = FALSE,
}

# template path and assets
if (identical(template, "default"))
args <- c(args, "--template",
pandoc_path_arg(rmarkdown_system_file("rmd/h/default.html")))
else if (!is.null(template))
args <- c(args, "--template", pandoc_path_arg(template))
template_file <- if (identical(template, "default")) {
rmarkdown_system_file("rmd/h/default.html")
} else template
if (!is.null(template_file))
args <- c(args, "--template", pandoc_path_arg(template_file))

# validate code_folding
code_folding <- match.arg(code_folding)
@@ -281,12 +281,9 @@ ioslides_presentation <- function(logo = NULL,
args <- c(args, includes_to_pandoc_args(includes))

# template path and assets
if (!is.null(template) && file.exists(template))
args <- c(args, "--template", template)
else
args <- c(args,
"--template",
pandoc_path_arg(rmarkdown_system_file("rmd/ioslides/default.html")))
if (is.null(template) || !file.exists(template))
template <- rmarkdown_system_file("rmd/ioslides/default.html")
args <- c(args, "--template", pandoc_path_arg(template))

# html dependency for ioslides
extra_dependencies <- append(extra_dependencies,
@@ -103,7 +103,7 @@ pdf_document <- function(toc = FALSE,
extra_dependencies = NULL) {

# base pandoc options for all PDF output
args <- c()
args <- c("--self-contained")

# table of contents
args <- c(args, pandoc_toc_args(toc, toc_depth))
@@ -112,26 +112,14 @@ pdf_document <- function(toc = FALSE,
if (identical(template, "default")) {

pandoc_available(error = TRUE)
# choose the right template
# patch pandoc template if necessary
version <- pandoc_version()
if (version >= "1.17.0.2")
latex_template <- "default-1.17.0.2.tex"
else if (version >= "1.15.2")
latex_template <- "default-1.15.2.tex"
else if (version >= "1.14")
latex_template <- "default-1.14.tex"
else
latex_template <- "default.tex"

# add to args
args <- c(args, "--template",
pandoc_path_arg(rmarkdown_system_file(paste0("rmd/latex/",
latex_template))))
if (version <= "2.5") args <- c(
args, "--include-in-header", system_file_arg("rmd/latex/subtitle.tex")
)

} else if (!is.null(template)) {
args <- c(args, "--template", pandoc_path_arg(template))
} else {
args <- c(args, "--self-contained")
}

# numbered sections
@@ -144,7 +132,7 @@ pdf_document <- function(toc = FALSE,
args <- c(args, pandoc_highlight_args(highlight))

# latex engine
latex_engine = match.arg(latex_engine, c("pdflatex", "lualatex", "xelatex"))
latex_engine <- match.arg(latex_engine, c("pdflatex", "lualatex", "xelatex"))
args <- c(args, pandoc_latex_engine_args(latex_engine))

# citation package
@@ -155,7 +143,7 @@ pdf_document <- function(toc = FALSE,
args <- c(args, includes_to_pandoc_args(includes))

# make sure the graphics package is always loaded
if (identical(template, "default")) args <- c(args, "--variable", "graphics=yes")
if (identical(template, "default")) args <- c(args, "--variable", "graphics")

# lua filters (added if pandoc > 2)
args <- c(args, pandoc_lua_filters(c("pagebreak.lua", "latex-div.lua")))
@@ -185,8 +173,9 @@ pdf_document <- function(toc = FALSE,
args <- c(args, "--variable", "geometry:margin=1in")

# use titling package to change title format to be more compact by default
if (!has_yaml_parameter(input_test, "compact-title"))
args <- c(args, "--variable", "compact-title:yes")
if (!has_yaml_parameter(input_test, "compact-title")) args <- c(
args, "--include-in-header", system_file_arg("rmd/latex/compact-title.tex")
)
}

if (length(extra_dependencies) || has_latex_dependencies(knit_meta)) {
@@ -60,10 +60,8 @@ slidy_presentation <- function(incremental = FALSE,

# template path and assets
if (identical(template, "default"))
args <- c(args, "--template",
pandoc_path_arg(rmarkdown_system_file(
"rmd/slidy/default.html")))
else if (!is.null(template))
template <- rmarkdown_system_file("rmd/slidy/default.html")
if (!is.null(template))
args <- c(args, "--template", pandoc_path_arg(template))

# html dependency for slidy
@@ -37,6 +37,9 @@ rmarkdown_system_file <- function(...) {
system.file(..., package = "rmarkdown")
}

system_file_arg <- function(...) {
pandoc_path_arg(rmarkdown_system_file(...))
}

#' @rdname rmarkdown_format
#' @export
@@ -0,0 +1,16 @@
% https://github.com/rstudio/rmarkdown/issues/337
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}

% https://github.com/rstudio/rmarkdown/pull/252
\usepackage{titling}
\setlength{\droptitle}{-2em}

\pretitle{\vspace{\droptitle}\centering\huge}
\posttitle{\par}

\preauthor{\centering\large\emph}
\postauthor{\par}

\predate{\centering\large\emph}
\postdate{\par}

0 comments on commit b2adfda

Please sign in to comment.