5

I'm using the excellent exsheets package, and I'd like to have different orders of questions in the different variants of my test. That is, I'd like \variant{1} to print one order of questions, \variant{2} to print another, etc. So given a document like:

\documentclass[12pt]{article}
\usepackage{exsheets}

\SetVariations{2}
\variant{1}

\begin{document}

\begin{question}
foo
\end{question}

\begin{question}
bar
\end{question}

\begin{question}
baz
\end{question}

\end{document}

For \variant{1} I'd like it to render something like:

Exercise 1.
foo
Exercise 2.
bar
Exercise 3.
baz

And for \variant{2} I'd like it to render in some other order, say:

Exercise 1.
baz
Exercise 2.
bar
Exercise 3.
foo

I've managed to achieve something like this by defining commands like \varyreversethree which work like the following:

\documentclass[12pt]{article}
\usepackage{exsheets}

\SetVariations{2}
\variant{2}

\newcommand{\varyreversethree}[3]{\vary{#1#2#3}{#3#2#1}}

\begin{document}

\varyreversethree{
\begin{question}
foo
\end{question}
}{
\begin{question}
bar
\end{question}
}{
\begin{question}
baz
\end{question}
}

\end{document}

Some things I don't like about this solution are that I have to define a new version of it for each possible number of things that might be reversed, and I can't leave any blank lines between the arguments (e.g. between questions) or later arguments are lost.

Is there a better way to do this in exsheets?

Steve
  • 231

1 Answers1

3

With exsheets successor xsim something like this would be possible:

\documentclass{article}
\usepackage{xsim}

\DeclareExerciseCollection{exam}

\begin{document}

\collectexercises{exam}
\begin{exercise}
  foo
\end{exercise}
\begin{exercise}
  bar
\end{exercise}
\begin{exercise}
  baz
\end{exercise}
\collectexercisesstop{exam}

\printrandomexercises[sort=false,collection=exam]{3}

\end{document}

enter image description here

The aux file of the example above has

\XSIM {random}{a}{3,1,2}

Deleting the aux file or manually changing the order of numbers in this line will lead to another order. (That is, deleting the file may lead to the same order as the first time…). For example \XSIM {random}{a}{1,3,2} now gives:

enter image description here

If you want more control over the order in which the exercises are printed, you can do something like this:

\documentclass{article}
\usepackage{xsim,pgffor}

\DeclareExerciseCollection{exam}

\begin{document}

\collectexercises{exam}
\begin{exercise}
  foo
\end{exercise}
\begin{exercise}
  bar
\end{exercise}
\begin{exercise}
  baz
\end{exercise}
\collectexercisesstop{exam}

\foreach \x in {3,1,2}{
  \XSIMexpandcode{\printexercise{exercise}{\x}}
}

\end{document}
cgnieder
  • 66,645