Reputation: 25323
I have the following question:
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, include = FALSE}
correct <- c(
"A (correct)
\\vspace{1cm}
$$\\int f\\left(x\\right) dx$$
",
"B (correct)",
"C (correct)"
)
correct <- sample(correct, 2)
incorrect <- c(
"D (incorrect)",
"E (incorrect)",
"F (incorrect)",
"G (incorrect)",
"H (incorrect)",
"I (incorrect)"
)
incorrect <- sample(incorrect, 6)
```
Question
========
Select from the followings items.
\begin{answerlist}
\item `r correct[1]`
\item `r correct[2]`
\item `r incorrect[1]`
\item `r incorrect[2]`
\item `r incorrect[3]`
\item `r incorrect[4]`
\item `r incorrect[5]`
\item `r incorrect[6]`
\end{answerlist}
Meta-information
================
exname: My question
extype: mchoice
exsolution: 11000000
exshuffle: TRUE
And I use the following code to generate the exam:
library(exams)
myexam <- list(
"question.Rmd",
"question.Rmd",
"question.Rmd",
"question.Rmd"
)
exm <- exams2pdf(myexam,dir = "/tmp/", template = "x.tex")
exm[[1]][[1]]$metainfo$solution
where my template is:
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[portuges]{babel}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{longtable}
\usepackage{multicol}
\usepackage{enumitem}
\setlength{\parindent}{0em}
\setlength{\parskip}{\bigskipamount}
\pagestyle{fancy}
\setlength\headheight{55pt}
\fancyhf{} % sets both header and footer to nothing
\renewcommand{\headrulewidth}{0pt}
\newenvironment{answerlist}%
{\renewcommand{\labelenumii}{(\alph{enumii})}\begin{multicols}{4}\begin{enumerate}}%
{\end{enumerate}\end{multicols}}
\newenvironment{question}{\item }{}
%\setkeys{Gin}{keepaspectratio}
\begin{document}
This is my exam!
Part 1
\begin{enumerate}
%% \exinput{exercises}
\end{enumerate}
Part 2
\begin{enumerate}[resume]
\input{exercise4}
\end{enumerate}
\end{document}
However, the solution for my question 1 in the exam is not correct (exm[[1]][[1]]$metainfo$solution
). Is this a bug? Or am I doing something wrong?
However, the solution for my question 1 in the exam is not correct (exm[[1]][[1]]$metainfo$solution
). Is this a bug? Or am I doing something wrong?
(Sorry for repeating the last paragraphs, but otherwise Stackoverflow would not allow me to post -- it complains about too much code.)
Upvotes: 1
Views: 118
Reputation: 17183
The problem is that you use a LaTeX-style {answerlist}
environment in a Markdown exercise. Hence the answer list is not processed correctly internally but it is still rendered but only when doing so via LaTeX (as you do in exams2pdf()
). If you use exams2html("question.Rmd")
you see that the answer list is not shown. Unfortunately, no error is thrown, I will check whether this can be improved.
To fix the issue you need to use a Markdown-style question list, either "by hand"
Answerlist
----------
* `r correct[1]`
* `r correct[2]`
* `r incorrect[1]`
* `r incorrect[2]`
* `r incorrect[3]`
* `r incorrect[4]`
* `r incorrect[5]`
* `r incorrect[6]`
or via the answerlist()
function (as already shown in: Questions with a fixed and pre-specified number of true and false answers).
```{r, echo = FALSE, results = "asis"}
answerlist(c(correct, incorrect), markup = "markdown")
```
Upvotes: 1