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
?
(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
. Also the r ...
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()
.