I need to produce exercise sheets, and I am looking for a package providing exercise/answer environments. I tried for now exercise and exsheets packages, and I can almost do what I want but there is always a restriction.

I would like to produce a list of exercises such that :

  • An exercise can possibly be just one line "Exercise 1. Blah blah blah?"
  • An exercise can possibly be longer, with multiple questions. In that case the first line would just be "Exercise X. Title" and then there would be one line per question, with proper numeration.
  • I should be able to give the solution for each exercise or question, and choose to display the solution or not.
  • When there are multiple questions, I should be able to give an answer for each question (and not only for the whole exercise). The answer should appear after each question.
  • The exercises and answers are written directly in the same source file.
  • It is possible to customize the way the answer are written (e.g. to add a fbox or color)
  • Ideally, also being able to add some symbol to specify the difficulty, but this is not essential.

What would be, according to you, the best package to do that, or the one requiring as few tricks as possible?

  • Have a look at the very flexible xsim.
    – TeXnician
    Oct 9, 2017 at 10:26
  • I actually wanted to try it, but I cannot get it working on my computer. It does not come with the distribution, and when I install it separately (~/texmf), I get a conflict with scrlfile when loading the package (undefined control sequence l.211 \file_input_stop)… not sure what is the cause exactly. As it is a recent package, maybe it is not stable yet ? Do you know any other package with similar capabilities ?
    – Zooky
    Oct 9, 2017 at 11:36
  • It does come with any current distro. Which one are you using?
    – TeXnician
    Oct 9, 2017 at 11:37
  • 2
    xsim was never part of TeX Live 2016 and it relies on other packages newer than the ones in TeX Live 2016. You need to install TeX Live 2017. I would recommend installing “vanilla” TeX Live instead of the one in the repo, any way. See tex.stackexchange.com/questions/301126/…
    – cgnieder
    Oct 9, 2017 at 12:21
  • 1
    If you do not want to do that heavy step maybe there's some idea for some of the older packages...
    – TeXnician
    Oct 9, 2017 at 13:20

1 Answer 1


All of the mentioned points should be doable using the xsim package (which is the successor of exsheets). I do not have enough knowledge of other exercise packages to be able to judge if they allow similar things…

Here is a suggestion about how you could use xsim to achieve what you want. Hopefully the code is self-explanatory.


% declare a boolean property:
% declare a tag like property:

% declare a template which typesets exercises differently according to given
% properties:
    \GetExercisePropertyT{level}{\marginpar{\sffamily Level: #1}}%
    \textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}.} %

% declare a tcolorbox template for the solutions:

% declare a user command for short answers:

% setup exercises and solutions:
  exercise-template = exercise ,
  solution-template = solution

% remove this option to hide the answers:
% \xsimsetup{solution/print=true}



  Just a short exercise
  The somewhat longer solution to the short exercise. \lipsum[1]

\begin{exercise}[subtitle=This one has a title,level=easy]
  Answer the following questions.
    \item question \answer{answer}
    \item question \answer{answer}

  A long exercise. \lipsum[4]\answer{The answer}

  Another short exercise.\answer{The answer}


This gives

enter image description here


enter image description here

depending on wether solution/print=true has been set or not.

  • This is perfect! Thank you very much, I really appreciate this example.
    – Zooky
    Oct 9, 2017 at 21:28

You must log in to answer this question.

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