SCM

Forum: support

Monitor Forum | Start New Thread Start New Thread
RE: Problem when recycling old questions [ reply ]
By: Marcos Marvá on 2017-06-09 08:00
[forum:45192]
Once again, Achim, many many thanks!

RE: Problem when recycling old questions [ reply ]
By: Achim Zeileis on 2017-06-09 06:57
[forum:45191]
Well, modifying the files with the strip.white=false option is not so difficult and probably the cleanest and most robust option. White the following function you can add to all code chunks that have results=tex the option strip.white=false:

add_stripwhite_false <- function(file) {
rnw <- readLines(file)
ix <- which(grepl(">>=", rnw, fixed = TRUE) & grepl("tex", rnw, fixed = TRUE))
rnw[ix] <- gsub(">>=", ",strip.white=false>>=", rnw[ix], fixed = TRUE)
writeLines(rnw, file)
}

Then, this works:

add_stripwhite_false("020001.Rnw")

And you could easily loop over your .Rnw files. Note that the code assumes that no strip.white option is present currently. If that were the case the line with the grepl would need to be adapted accordingly.

For exams2pdf() but not all other interfaces it is also easy to add this option when processing the .Rnw files:

exams2pdf("020001.Rnw", strip.white = "false")

RE: Problem when recycling old questions [ reply ]
By: Marcos Marvá on 2017-06-09 05:52
[forum:45190]
Many thanks for pointing out a solution so quickly!!
I have just added an extra line as suggested and worked fine...it would be nice to find a workaround so that it is not needed retouching all the other questions in our repo

RE: Problem when recycling old questions [ reply ]
By: Achim Zeileis on 2017-06-07 14:41
[forum:45182]
The more elegant solution is to use the strip.white=false option in Sweave:

\begin{question}
<<echo=false, results=tex, strip.white=false>>=
writeLines(question)
@
\end{question}

RE: Problem when recycling old questions [ reply ]
By: Achim Zeileis on 2017-06-07 14:30
[forum:45181]
Thanks! The problem comes from \end{question} and \end{solution} ending up in the same line as the last text line after running Sweave. See the output of Sweave("020001.Rnw") that shows this problem.

This is no problem for LaTeX itself but it confuses read_exercises() which is internally used by exams2pdf(). I have to check whether I can add a workaround for this in read_exercises().

The simple workaround is to replace:

<<echo=False, results=tex>>=
cat(paste(answer,collapse=""))
@
\end{solution}

by

<<echo=False, results=tex>>=
cat(paste(answer,collapse=""))
@

\end{solution}

with an additional blank line after @. Analogously for the question.

Bonus comment: writeLines(answer) would be easier than cat(paste(answer,collapse="")). But it has the same problem with the blank line.

RE: Problem when recycling old questions [ reply ]
By: Marcos Marvá on 2017-06-07 14:02
[forum:45180]
here is a link to download the zip file

http://www3.uah.es/marcos_marva/problem-exams2pdf.zip

thanks

RE: Problem when recycling old questions [ reply ]
By: Achim Zeileis on 2017-06-07 13:57
[forum:45179]
Marcos, thanks for your message.

There are some subtle differences between exams() and exams2pdf() which are also described in the vignette. My guess is that you did not adapt the definition of the \exmchoice macro in the LaTeX template. See page 8 of vignette("exams", package = "exams").

I can also have a look but unfortunately the R-Forge forum messes up binary attachments at the moment. That's why I couldn't have a look at the .zip you provided. Could you either put the file up on your web page? Or alternatively, provide each of the necessary files as a separate attachment in a separate reply? Sorry for the inconvenience!

Problem when recycling old questions [ reply ]
By: Marcos Marvá on 2017-06-07 13:46
[forum:45178]

problem-exams2pdf.zip (1) downloads
We have found problems when using old questions and exams2pdf() to generate exams. Everything works with exams.

In the attached (question, exam templates and the script we use to generate the exam) file there is an example.

Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge