1

I am writing exercises sheets for my student and I want to print only solutions to odd (or even) numbered exercises using LaTeX xsim. I have searched on Google and looked in the xsim manual, but couldn't find anything. So is there an easy way to print only odd numbered solutions with xsim?

Thanks and have a great day Nicolas Leduc

1 Answer 1

2

Just an attempt:

\documentclass{article}
\usepackage{xsim}

\xsimsetup{
  exercise/within=section,
}

\begin{document}
\section{title}
\begin{exercise}
  first exercise
\end{exercise}
\begin{solution}
  first solution
\end{solution}

\begin{exercise}
  second exercise
\end{exercise}
\begin{solution}
  second solution
\end{solution}

\begin{exercise}
  third exercise
\end{exercise}
\begin{solution}
  third solution
\end{solution}

\section{title}
\begin{exercise}
  first exercise
\end{exercise}
\begin{solution}
  first solution
\end{solution}

\begin{exercise}
  second exercise
\end{exercise}
\begin{solution}
  second solution
\end{solution}

\begin{exercise}
  third exercise
\end{exercise}
\begin{solution}
  third solution
\end{solution}

\ForEachUsedExerciseByID{%
  \ifodd\GetExerciseProperty{counter-value}\relax
    \XSIMprint{solution}{#1}{#2}%
  \fi
}
\end{document}

enter image description here

2
  • Could you also do that or similar for a book with a list of end of chapter exercises and then a final "Solution to odd exercises" chapter?
    – JPMD
    Aug 9 at 11:52
  • 1
    @JPMD It seems to me the current example can already do this, you only need to change exercise/within=section to exercise/within=chapter. If you encountered any problems, feel free to post a follow-up (new) question and add a comment here to get me informed. Aug 10 at 6:26

You must log in to answer this question.

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