Search code examples
r-exams

R/exams: How to change default "Exam 1" produced by exams2html


Is there a way to change the "Exam 1" to another word like "Homework 1" by passing arguments?

If not, is there a default template I can modify?

My last resort is to modify the built html files but it's not very convenient.


Solution

  • The exams2html() function takes an argument template which defaults to "plain.html". This template is shipped with the exams package and contains:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    
    <head>
    <title>Exam ##ID##</title>
    <style type="text/css">
    body{font-family: Arial, Helvetica, Sans;}
    </style>
    <meta charset="utf-8" />
    </head>
    
    <body>
    <h2>Exam ##ID##</h2>
    
    ##\exinput{exercises}##
    
    </body>
    </html>
    

    The ##ID## is replaced by the ID (from 1 to n) and the ##\exinput{exercises}## is replaced by an ordered list <ol> containing the questions and optionally also the solutions. You can modify this template in any way you need and call it, say, homework.html. Then you can call:

    exams2html(..., template = "/path/to/homework.html",
      question = "<h4>Exercise</h4>", solution = FALSE)
    

    which sets the template and also modifies the way the question is displayed while suppressing the solution.

    Remark: The placeholders ##ID## and ##\exinput{exercises}## are a bit awkward (analogous to the placeholders in LaTeX templates for exams2pdf()) and not very flexible. It has been on my wishlist to make this more flexible, e.g., using {{mustache}} templating via the whisker package, but so far I didn't get round to tackle that.