I'm trying to build exam sheets with xsim using collections where exercises doesn't show up in the id order.

The exercises print in the specified order (= counter order) in the exam itself but in the id order in the grading table which can be confusing.

Here is a MWE:


  print-solutions/headings=false ,



  Exercise one.
  Answer one.

  Exercise two.
  Answer two.

  Exercise three.
  Answer three.

\printexercise{exercise}{one,three, two}


Here is what I get:

enter image description here

And here is what I would like to have (exercises 2 and 3 are switched in the grading table):

enter image description here

As far as understood from the manual of the package, xsim only include build-in functions to sort exercises by Type then ID or by ID. I've tried to dig in the source code of the package to build a function to sort exercises by counter but it's beyond my present abilities.

Is there a build-in (or an easy) way to do so that I overlooked? Otherwise, have you an idea of how to get it?

1 Answer 1


The reason for this is that the exercises are set up or defined in the order they appear even if they're not printed immediately. This defines properties like id or exercise-body and so on.

Some properties are first set when the exercises are actually printed, such as the exercise number.

The default templates for the grading tables use \ForEachUsedExerciseByType{} to loop through the exercises which uses the order in which the exercises have been defined.

At the moment there is no easy way to loop through the exercises in the order they have been printed. IMHO this is worth a feature request. I opened your issue on github for this again.

  • Thank you for your answer! This got me thinking, one way to solve this without changing the core of the package might be to write the grading table as it is now in an auxiliary file and to use this auxiliary file to look for the needed info (exercice name, counter and points) when we need it. It's not pretty nor efficient in compilation time, but it might work. Mar 19, 2021 at 22:11
  • @ParticuleAlpha there is no need for a core change. The only thing needed is another loop. The information is already available: xsim writes a number of stuff in an auxilliary file (look for a file with the ending .xsim
    – cgnieder
    Mar 20, 2021 at 9:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .