Reputation: 1819
In r-exams, we want to include R output within a cloze question sub-item; exported as PDF (for a printed exam). While printing of R output works fine in the regular question part, it fails within the \begin{answerlist} environment of the cloze sub-items.
Here's an MWE:
```{r echo=FALSE, message=FALSE, warning=FALSE}
tt <- t.test(rnorm(100), rnorm(100))
```
Question
========
Output *outside* of list environment:
```{r echo=FALSE, message=FALSE, warning=FALSE, comment=NA}
print(tt)
```
Answerlist
---------------
* Subquestion number 1.
Output *inside* of list environment:
$$\vspace*{0.1cm}$$
\
```{r echo=FALSE, message=FALSE, warning=FALSE, comment=NA}
print(tt)
```
* Subquestion number 2.
Solution
========
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Meta-information
================
exname: testoutput
extype: cloze
exclozetype: string|string
exsolution: x|x
expoints: 1|1
Which leads to this PDF:
The output loses all line breaks. Any ideas for work-arounds/solutions?
Upvotes: 3
Views: 916
Reputation: 17183
It is not possible to include such advanced formatting within the answerlist items. Partially, this is due to some systems we can render such questions into don't support this. Hence, all text in an answerlist item is collapsed internally into a single line of text. Consequently, code or graphics etc. are not supported there.
Possible workarounds include:
##ANSWER##
fields somewhere directly in the question text so that you can customize layout. I haven't got a worked "string" example but this "num" example might still be helpful: http://www.R-exams.org/templates/fourfold2/. Disadvantage: Only works for Moodle (and partially QTI) but not for PDF. Advantage: Flexible control over where user interaction elements are placed in the question text.By conditioning on match_exams_call()
it would in principle also be possible to combine some of the solutions above to achieve an exercise that works reasonably well for both PDF and Moodle, for example.
Upvotes: 3