Search code examples
latexr-exams

Including LaTeX packages in R/exams Rnw exercises


I would like to know, if possible, how to include other "simple" (I know it is a relative concept) LaTeX packages in my Rnw exercises for R/exams. I just want to use bbfonts. I can't define any new command as well. There is one question related to it here, but for Rmd exercises.

In my Rnw file I must have \usepackage[utf8]{inputenc}, why it doesn't accept any other packages (in fact R/exams ignores it)?


Solution

  • The answer regarding the support of LaTeX packages depends on the type of output you want to generate with R/exams.

    If you produce PDF output:
    Then internally pdfLaTeX is used and it is possible to load additional packages. However, this is not done in the individual exercises but in the master LaTeX template that ties the exercises together into a document. When you use exams2pdf() you can provide your own template to fully customize the appearance of your PDF exams, see Section 3 of vignette("exams", package = "exams"). When you use exams2nops() then you can still adapt the fixed template that this uses, either simply by usepackage = "bbfonts" or by including a suitable header = specification.

    If you produce HTML-based output:
    Then the LaTeX code is actually not processed by some LaTeX distribution but converted to HTML, either via pandoc or via ttm (TeX-to-MathML). This applies to all exams2xyz() interfaces for learning management systems like Moodle, Canvas, OpenOLAT, Ilias, Blackboard, etc. In this case the commands you can use are limited to what the converters support. See http://www.R-exams.org/tutorials/math/ for an overview and How to use a LaTeX package with R/exams? for some more practical comments.

    UTF-8 encoding:
    The encoding issue is best resolved by installing at least version 2.4-0 of the exams package. In that version the entire package was switched to UTF-8 and all standard templates have UTF-8 support enabled by default.