Skip to contents

These functions produce a new driver which matches the old one in most respects, but adds an argument sourcepos (and possibly others). If that argument is TRUE (the default) then concordances are handled by the new driver.

These functions are used to produce html_documentC and similar drivers in this package, but should also work on other drivers that produce HTML output using Pandoc.

Usage

html_with_concordance(driver)
pdf_with_concordance(driver)

Arguments

driver

An R Markdown driver that produces HTML, LaTeX or PDF using Pandoc.

Value

A new driver function.

Examples

html_with_concordance(rmarkdown::html_fragment)
#> function (sourcepos = TRUE, ...) 
#> {
#>     res <- driver(...)
#>     if (test_packages(FALSE)) {
#>         res$knitr$opts_knit$concordance <- sourcepos
#>         if (sourcepos) {
#>             res$knitr$opts_knit$out_format <- "markdown"
#>             oldpost <- res$post_processor
#>             res$post_processor <- function(metadata, input_file, 
#>                 output_file, ...) {
#>                 if (!is.null(oldpost)) 
#>                   res <- oldpost(metadata, input_file, output_file, 
#>                     ...)
#>                 else res <- output_file
#>                 processConcordance(res, res)
#>                 res
#>             }
#>             res$pandoc$from <- fix_pandoc_from_options(res$pandoc$from, 
#>                 sourcepos)
#>         }
#>     }
#>     res
#> }
#> <bytecode: 0x55d7edc2aad8>
#> <environment: 0x55d7edc2e838>
pdf_with_concordance(rmarkdown::latex_fragment)
#> function (latex_engine = "pdflatex", sourcepos = TRUE, defineSconcordance = TRUE, 
#>     ...) 
#> {
#>     test_packages()
#>     res <- driver(latex_engine = latex_engine, ...)
#>     res$knitr$opts_knit$concordance <- sourcepos
#>     if (sourcepos) {
#>         res$pandoc$from <- fix_pandoc_from_options(res$pandoc$from, 
#>             sourcepos)
#>         res$pandoc$lua_filters <- c(res$pandoc$lua_filters, system.file("rmarkdown/lua/pagebreak.lua", 
#>             package = "RmdConcord"), system.file("rmarkdown/lua/latex-datapos.lua", 
#>             package = "RmdConcord"))
#>         res$pandoc$RmdConcord_ext <- res$pandoc$ext
#>         res$pandoc$ext = ".tex"
#>         res$RmdConcord_post_processor <- res$post_processor
#>         res$post_processor <- function(yaml, infile, outfile, 
#>             ...) {
#>             workdir <- dirname(outfile)
#>             concordanceFile <- paste0(sans_ext(normalizePath(infile)), 
#>                 "-concordance.tex")
#>             origdir <- setwd(workdir)
#>             on.exit(setwd(origdir))
#>             processLatexConcordance(outfile, followConcordance = concordanceFile, 
#>                 defineSconcordance = defineSconcordance)
#>             outfile
#>         }
#>     }
#>     res
#> }
#> <bytecode: 0x55d7edd16c50>
#> <environment: 0x55d7edd1a2e8>