2

Consider creating exams using the exams package in R.

When using exams2nops there is a parameter showpoints that, when set to TRUE will show the points of each exercise. However, for exams2pdf this parameter is not available.

How to display the points per exercise when using exams2pdf?

Sebastian Sauer
  • 1,555
  • 15
  • 24

1 Answers1

3

(The answer below is adapted from the R/exams forum at https://R-Forge.R-project.org/forum/forum.php?thread_id=33884&forum_id=4377&group_id=1337.)

There is currently no built-in solution to automatically display the number of points in exams2pdf(). The points= argument only stores the number of points in the R object that exams2pdf() creates (as in other exams2xyz() interfaces) but not in the individual PDF files.

Thus, if you want the points to be displayed you need to do it in some way yourself. A simple solution would be to include it in the individual exercises already, possibly depending on the kind of interface used, e.g., something like this for an .Rmd exercise:

pts <- 17
pts_string <- if(match_exams_call() == "exams2pdf") {
  sprintf("_(%s points)_", pts)
} else {
  ""
}

And then at the beginning of the "Question":

Question
========
`r pts_string` And here starts the question text...

Finally in the meta-information

expoints: `r pts`

This always includes the desired points in the meta-information but only displays them in the question when using exams2pdf(...). This is very flexible and can be easily customized further. The only downside is that it doesn't react to the exams2pdf(..., points = ...) argument.

In .Rnw exercises one would have to use \Sexpr{...} instead of r .... Also the pts_string should be something like sprintf("\\emph{(%s points)}", pts).

Finally, a more elaborate solution would be to create a suitable \newcommand in the .tex template you use. If all exercises have the same number of points, this is not hard to do. But if all the different exercises could have different numbers of points, it would need to be more involved.

The main reason for supporting this in exams2nops() but not exams2pdf() is that the former has a rather restrictive format and vocabulary. In the latter case, however, the point is to give users all freedom regarding layout, language, etc. Hence, I didn't see a solution that is simple enough but also flexible enough to cover all use-cases of exams2pdf().

Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49
  • 1
    Update: I've included a worked example how the text for the points could be included in the exercise directly. – Achim Zeileis Apr 16 '20 at 10:28
  • Am I correct to state that the former solution does not allow to calculate the total points of the exam as it just ouputs the string. Whay would you add it in the meta-data then? – Jens Buysse May 04 '20 at 18:03
  • The total points can be handled "as usual" in the `header` argument. For example, setting `header = list(totalpoints = 100)` will create the statement `\totalpoints{100}` in the header section of the master LaTeX template. Thus, the template would need to provide that command and insert it into all the places where required. – Achim Zeileis May 04 '20 at 22:16
  • I was looking more into the solution provided standard in the exam class LaTeX. Something like adding the numpoints in the metadata of the question, so that the point per question would be shown next to the question and the total amount of points calculated in the header of the exam pdf. – Jens Buysse May 06 '20 at 19:18
  • 1
    Yes, that is also what Sebastian is after. Currently this is not easy but a workaround like the one shown in my response could be used to tackle this. A more general solution of adding a "finisher" transformation is what I want to add to exams2html() and exams2pdf(). But this will take some more time and work. – Achim Zeileis May 06 '20 at 21:13
  • Ok. 'm using the solution above in the mean time. Time is precious to get the exam generated for all students :) – Jens Buysse May 07 '20 at 16:21