SCM

Forum: support

Monitor Forum | Start New Thread Start New Thread
RE: Latex exam template customization - shuffling problem [ Reply ]
By: Achim Zeileis on 2019-11-22 02:03
[forum:47168]
Modifications at exercise level are not possible. What happens internally is:

(1) The .Rnw is Sweaved to .tex.

(2) The .tex is read into R and decomposed into its parts: question, questionlist, solution, solutionlist, metainfo

(3) Depending on the output format the decomposed text is inserted into an output file format (possibly after conversion to HTML, etc.).

In step (2) the {answerlist} anvironment is read and only its \item elements stored.

In step (3) the answerlist elements are inserted into some document. In the case of .tex/.pdf output including a vanilla {answerlist} environment.

That's why youre modified answerlist option is not passed on.

RE: Latex exam template customization - shuffling problem [ Reply ]
By: Lucio Palazzo on 2019-11-21 21:22
[forum:47166]
Thanks for your help, now it works properly!
I tried all the possible choices you proposed and the multicol command seems to be the most versatile. Nonetheless, I will try in the free time to inject in some way also the task package. The main difficulties I am encountering at this time is that the debugging phase is not so straightforward.

By the way, sorry if I bother you but I have another question. I noticed that in some cases answers don't fit properly in an horizontal alignment. I am now trying to generalize a little this new environment in order to admit questions to have either horizontal or vertical lists in the same exam page.

My idea is to add an option in the answerlist environment that allows to choose the alignment of the answers, I tried to adopt some solutions but without much success.
I started adding an option in the \newenvironment line:

\newenvironment{answerlist}[1][1]{\renewcommand{\labelenumi}{(\alph{enumi})}\begin{multicols}{#1}\begin{enumerate}}{\end{enumerate}\end{multicols}}

In my view this would allow me to set in the .Rnw file either the vertical or horizontal display by adding the [5] option just after the list declaration, for instance:


- Nothing to add for a vertical format since I set [1] as default option

\begin{answerlist}
\item ....
\begin{answerlist}


- while an horizontal layout may be obtained by using the [5] option

\begin{answerlist}[5]
\item ....
\begin{answerlist}


The problem is that it would appear the compiler is not reading the option I declared in the .Rnw script, everytime he will only consider the default option set in the \newenvironment command. What could possibly be the problem?


Thanks again for the help!

RE: Latex exam template customization - shuffling problem [ Reply ]
By: Achim Zeileis on 2019-11-20 02:40
[forum:47161]

plain-horiz.tex (10) downloads
Hmm, I'm surprised that this works partially at all! .Rnw exercises depends on the {answerlist} environment to get the metainformation right. You must not replace that with another environment.

So the intended way to go about is to keep such kind of formatting out of the .Rnw exercises. The formatting should be done in the .tex template only.

In this particular case, you can easily re-define the {answerlist} environment within the .tex template to obtain the horizontal display. Attached you find a solution based on the {multicol} package. With that you can do:

ex <- c("deriv2.Rnw", "tstat2.Rnw")
exams2pdf(ex, template = "plain-horiz.tex")

In addition "plain-horiz.tex" also shows in the comments how {paralist} or {enumitem} can be used to obtain the desired layout. Presumably some solution could also be obtained using the {task} package.

Finally, note that you can easily use that horizontal display also in exams2nops exams! These have the advantage that they can be automatically scanned:

exams2nops(ex,
usepackage = "multicol",
header = "\\renewenvironment{answerlist}{\\renewcommand{\\labelenumi}{(\\alph{enumi})}\\begin{multicols}{5}\\begin{enumerate}}{\\end{enumerate}\\end{multicols}}"
)

Latex exam template customization - shuffling problem [ Reply ]
By: Lucio Palazzo on 2019-11-19 10:53
[forum:47160]

solution_mod1.pdf (6) downloads

Hello to everyone,

I am working on a custom version of the pdf multiple choice Latex exam, the goal is to use exams2pdf() to create a pdf starting from a customized .tex file. Even if in my intentions I would make the code as generalized as possible, at the moment I am mainly focusing on 5-single choice questions with answer shuffling.

Over all the minor changes I made, I am looking in particular at a way to print multiple choiche answers in horizontal format.
There is not just a "stylish" reason, I would like to save paper and to store as much questions as possible in a single page.

Here I will try to explain briefly what I have done:

1) I decided to include the "tasks" package both into the exam and solution templates and added this new command into the header:


\newenvironment{answerlistTASKS}{\tasks[counter-format = {(tsk[a])},label-offset = {3mm},label-format = {\bfseries}](5)}{\endtasks}

2) Then I wrote an .Rnw file as follows:


----------------------------------------------------------------------------------------

%%% R SCRIPT
<<echo=FALSE, results=hide>>=
## parameters
pos <- round(runif(1,min=0.2,max=0.8),2)
neg <- 1 - pos
## solution
sol <- round(dbinom(2,5,pos),2)
ans <- round(
c(sol - 0.33,
sol,
sol/2,
1-sol,
(1-sol)/2
),digits=2)
res <- ans==sol
@


%%%% QUESTION
\begin{question}
Bitcoin is a new digital currency that fluctuates in value everyday. Suppose that the value goes up with probability $\Sexpr{pos}$ and it goes down with probability
$\Sexpr{neg}$.
Let us assume that price variations on different days are independent on each other, what is the probability that the value of a Bitcoin in a total of five days will go up twice and go down three times?

TEST LINE: SOLUTION=$\Sexpr{sol}$

\begin{answerlistTASKS}
\task \Sexpr{ans[1]}
\task \Sexpr{ans[2]}
\task \Sexpr{ans[3]}
\task \Sexpr{ans[4]}
\task \Sexpr{ans[5]}
\end{answerlistTASKS}
\end{question}

%%%% SOLUTION EXPLAINATION
\begin{solution}
Solution.

\begin{answerlistTASKS}
\task False.
\task True.
\task False.
\task False.
\task False.
\end{answerlistTASKS}

\end{solution}


%%%% METADATA
\exname{bitcoin}
\extype{schoice}
\exsolution{01000}
\exshuffle{TRUE}

----------------------------------------------------------------------------------------


Even if the resulting pdf file seems to be correct, there is a problem with the solution box. in fact, by looking at the printed correct answer, there is a matching with the solution list but not with the checked box in the first page.

It seems that the \exmchoice command is working properly since it marks at a shuffled answer, while the answer and solution list items are not shuffling.

Do you have any suggestion regarding this problem? I am not capable to understand clearly how the shuffling procedure works, especially how it switches item positions in a list.

To clarify what is the problem I will share as attachment one of the bad pdf output file I generated, as you can see the "X" symbol in the first page is in the (d) box, while the correct answer is the second, corresponding to the position I set in the .Rnw script. If I generate other solutions, the "X" in first page shuffles again while the true answer is still in the second position.

I hope you might help me.

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