exams2html | R Documentation |
Automatic generation of exams in HTML format.
exams2html(file, n = 1L, nsamp = NULL, dir = ".", template = "plain.html", name = NULL, quiet = TRUE, edir = NULL, tdir = NULL, sdir = NULL, verbose = FALSE, rds = FALSE, question = "<h4>Question</h4>", solution = "<h4>Solution</h4>", mathjax = NULL, resolution = 100, width = 4, height = 4, svg = FALSE, encoding = "UTF-8", envir = NULL, converter = NULL, seed = NULL, exshuffle = NULL, ...) make_exercise_transform_html(converter = c("ttm", "tth", "pandoc", "tex2image"), base64 = TRUE, options = NULL, ...) make_exams_write_html(template = "plain", name = NULL, question = "<h4>Question</h4>", solution = "<h4>Solution</h4>", mathjax = FALSE)
file |
character. A specification of a (list of) exercise files. |
n |
integer. The number of copies to be compiled from |
nsamp |
integer. The number(s) of exercise files sampled from each
list element of |
dir |
character specifying the output directory (default:
current working directory). If only a single HTML file is produced
and no |
template |
character. A specification of a HTML template. |
name |
character. A name prefix for resulting exercises. |
quiet |
logical. Should output be suppressed when calling
|
edir |
character specifying the path of the directory (along with its
sub-directories) in which the files in |
tdir |
character specifying a temporary directory, by default
this is chosen via |
sdir |
character specifying a directory for storing supplements, by
default this is chosen via |
verbose |
logical. Should information on progress of exam generation be reported? |
rds |
logical indicating whether the return list should also be saved as an RDS data file. |
question |
character or logical. Should the question be included in the HTML
output? If |
solution |
character or logical, see argument |
mathjax |
logical. Should the JavaScript from https://www.MathJax.org/
be included for rendering mathematical formulas? By default |
resolution, width, height |
numeric. Options for rendering PNG (or SVG)
graphics passed to |
svg |
logical. Should graphics be rendered in SVG or PNG (default)? |
encoding |
character, ignored. The encoding is always assumed to be UTF-8. |
envir |
argument passed to |
base64 |
logical. Should supplementary files be embedded using Base 64 coding?
Argument |
converter, ... |
arguments passed on to |
seed |
integer matrix or logical. Either |
exshuffle |
logical or integer. If the |
options |
list of options to be passed on to
|
exams2html
generates exams in a very simple HTML format
using xexams
. It proceeds by (1) calling xweave
on each exercise, (2) reading the resulting LaTeX code, (3) transforming
the LaTeX code to HTML, and (4) embedding the HTML code in a template
(a simple and plain template is used by default).
For steps (1) and (2) the standard drivers in xexams
are used.
For step (3) a suitable transformation function is set up on the fly
using make_exercise_transform_html
. This transforms the
LaTeX code in question
/questionlist
and
solution
/solutionlist
by leveraging one of four
functions: ttm
produces HTML with MathML
for mathematical formulas, tth
produces
plain HTML that aims to emulate mathematical formulas,
pandoc_convert
employs pandoc offering different
options for handling formulas, and tex2image
runs
LaTeX and turns the result into a single image. In all cases, images
can either be stored in supplementary files or embedded directly in Base 64 coding.
For step (4) a simple writer function is set up on the fly that embeds the transformed HTML code into a template and writes a single HTML file for each exam.
exams2html
returns a list of exams as generated by xexams
.
make_exercise_transform_html
returns a function that is suitable for being
supplied as driver$transform
to xexams
.
make_exams_write_html
returns a function that is suitable for being
supplied as driver$write
to xexams
.
Zeileis A, Umlauf N, Leisch F (2014). Flexible Generation of E-Learning Exams in R: Moodle Quizzes, OLAT Assessments, and Beyond. Journal of Statistical Software, 58(1), 1–36. doi: 10.18637/jss.v058.i01.
xexams
,
ttm
,
tth
,
pandoc_convert
,
tex2image
,
browseURL
## load package and enforce par(ask = FALSE) options(device.ask.default = FALSE) if(interactive() && requireNamespace("png")) { ## compile a single random exam (displayed in the browser) exams2html(list( "boxplots.Rmd", c("tstat.Rmd", "ttest.Rmd", "confint.Rmd"), c("regression.Rmd", "anova.Rmd"), "scatterplot.Rmd", "relfreq.Rmd" )) ## various versions of displaying mathematical formulae ## via MathML (displayed correctly in MathML-aware browsers, e.g. Firefox) exams2html("tstat") ## via MathML + MathJax (should work in all major browsers, ## note the display options you get when right-clicking on the formulas ## in the browser) exams2html("tstat", mathjax = TRUE) ## via plain HTML (works in all browsers but with inferior formatting) exams2html("tstat", converter = "tth") ## via HTML with embedded picture (works in all browsers but ## is slow and requires LaTeX and ImageMagick) ## Not run: exams2html("tstat", converter = "tex2image") ## End(Not run) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.