make_exercise_transform_pandoc {exams}R Documentation

Transform Exercises via Pandoc

Description

Generate an exercise transformer function based on pandoc_convert.

Usage

  make_exercise_transform_pandoc(to = "latex", base64 = to != "latex",
    attachfile = FALSE, ...)

Arguments

to

character. Specification of the output text format, typically "latex", "html", or "markdown".

base64

logical. Should supplementary files be embedded using Base 64 coding? Argument base64 may also be a character vector of file suffixes that should be encoded, e.g. base64 = c("png", "rda") will only encode PNG images and binary .rda files. If set to NULL only image files will be encoded.

attachfile

logical. Should attachfile rather than url be used in LaTeX, e.g., for embedding data files in PDF.

...

arguments to be passed on to pandoc_convert.

Details

The generator function make_exercise_transform_pandoc returns a function that can be used for the transform steps in xexams. It is a wrapper to pandoc_convert from rmarkdown but adds a couple of convenience features that are typically needed in R/exams exercises. Supplementary files can be handled by Base 64 encoding (often used for HTML output) or via attachfile in LaTeX (sometimes useful for PDF output). Some additional LaTeX commands and environments are supported, e.g., Sweave environments or negated logical comparison symbols. Finally, some default options from pandoc are changed, namely the defaults --wrap=preserve (instead of --wrap=auto) and --columns=99999 (instead of --columns=72).

Value

make_exercise_transform_pandoc returns a function that is suitable for being supplied as driver$transform to xexams.

See Also

xexams, make_exercise_transform_html, pandoc_convert

Examples

## load package and enforce par(ask = FALSE)
options(device.ask.default = FALSE)

## default transformation to LaTeX output
textrafo <- make_exercise_transform_pandoc()

## custom transformation to Markdown output without Base 64 files
mdtrafo <- make_exercise_transform_pandoc(to = "markdown", base64 = FALSE)

## read "lm" exercise via xexams, i.e., without transformation
## Rmd yields Markdown, Rnw yields LaTeX
lm_md <- xexams("lm.Rmd")[[1]][[1]]
lm_tex <- xexams("lm.Rnw")[[1]][[1]]

## original Markdown and transformed LaTeX
writeLines(lm_md$question)
writeLines(textrafo(lm_md)$question)

## original LaTeX and transformed Markdown
writeLines(lm_tex$question)
writeLines(mdtrafo(lm_tex)$question)

[Package exams version 2.4-0 Index]