rr-exams

R/Exams change font


I am using R/exams via exams2nops() to generate PDFs. The font everywhere is sans serif, which I don't like. But I know that the front page must be unaltered as much as possible in order not to affect scanning afterwards.

Can I keep the first page unaltered (just change the logo, but stay in sans serif), and then change the font from page 2 onward to use LaTeX's Computer Modern Roman (text and math)? I tried to edit the original code of exams::make_nops_template(), but the best I managed is to change the font everywhere (including front page).


Solution

  • Background: You don't need to alter the source code of the package or the template. It is written in such a way that the sans serif font (Helvetica) is enforced for all the elements that need to be scanned (especially exam type and exam ID). Everything else can in principle be changed - and is changed in fact by various of the supported languages.

    Update: To further facilitate changing fonts, especially for the math elements, the current development version 2.4-2 of the package on R-Forge gained a new argument exams2nops(..., helvet = TRUE). If TRUE, the default, the template loads

    \usepackage{helvet}
    \usepackage[helvet]{sfmath}
    

    But by setting helvet = FALSE, this is suppressed

    Answer: For further modifications in the template the arguments exams2nops(..., usepackage = ..., header = ...) can be used. With usepackage you can specify a vector of character strings which are then turned into \usepackage{...} lines in the template. And header can be a character string with any LaTeX code that should be included in the header.

    Example: To switch to a serif font for the exam, you can either just switch off the Helvetica font and use the default LaTeX serif font. Or you can additionally load another font such as Times New Roman via the {times} LaTeX package.

    exams2nops("deriv2.Rmd", helvet = FALSE)
    exams2nops("deriv2.Rmd", helvet = FALSE, usepackage = "times")