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?

3
  • No, there is no built-in solution in exsheets.
    – cgnieder
    Jan 23 '14 at 17:05
  • Thanks for the speedy response. Would it be worth filing a feature request on the exsheets issue tracker?
    – Steve
    Jan 23 '14 at 17:11
  • I'm not sure. I currently have no idea how I would implement a question re-ordering with a suitable user interface
    – cgnieder
    Jan 23 '14 at 17:50
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}
5
  • Is there a way to import the whole collection randomly without specifying the number of exercises? That is, something like \printrandomexercises [sort = false, collection = exam] {all}
    – jowe_19
    Mar 27 at 11:40
  • @jowe_19 do you mean all exercises in the document or only all of one specific collection?
    – cgnieder
    Apr 6 at 7:55
  • Rather all of one specific collection.
    – jowe_19
    Apr 6 at 17:13
  • 1
    @jowe_19 I'll add a counter that will hold the number of exercises in a collection to the next release
    – cgnieder
    Apr 7 at 9:38
  • Great news, thank you.
    – jowe_19
    Apr 8 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.