I am trying to write a document using the xsim package. It is divided into chapters and each contains its own exercises and its solutions, at the end of each.
At present, the structure of each chapter is written by hand as in ChManual.tex
but I would like to use something like macroChapter.tex
, which uses \thechapter
as parameter to invoke and print the collections defined for xsim.
The following MWE works if you use ChManual.tex
, if you uncomment the lines %\input{macroChapter.tex}
of chapters 1 and 2, it does not work showing an error: unknown-collection "collCh\thechapter"
.
\documentclass{report}
\usepackage{filecontents}
\usepackage{xsim}
\DeclareExerciseCollection{collCh1}
\DeclareExerciseCollection{collCh2}
\DeclareExerciseCollection{collChManual}
\begin{filecontents}{Ch1.tex}
\begin{exercise}
This is exercise 1 from chapter \thechapter.
\end{exercise}
\begin{solution}
This is solution of exercise 1 from chapter \thechapter.
\end{solution}
\end{filecontents}
\begin{filecontents}{Ch2.tex}
\begin{exercise}
This is exercise 1 from chapter \thechapter.
\end{exercise}
\begin{solution}
This is solution of exercise 1 from chapter \thechapter.
\end{solution}
\begin{exercise}
This is exercise 2 from chapter \thechapter.
\end{exercise}
\begin{solution}
This is solution of exercise 2 from chapter \thechapter.
\end{solution}
\end{filecontents}
\begin{filecontents}{ChManual.tex}
\begin{exercise}
This is exercise 1 from chapter \thechapter (Manual).
\end{exercise}
\begin{solution}
This is solution of exercise 1 from chapter \thechapter (Manual).
\end{solution}
\begin{exercise}
This is exercise 2 from chapter \thechapter (Manual).
\end{exercise}
\begin{solution}
This is solution of exercise 2 from chapter \thechapter (Manual).
\end{solution}
\end{filecontents}
\begin{filecontents}{macroChapter.tex}
This is chapter \thechapter.
\collectexercises{collCh\thechapter}
\input{Ch\thechapter.tex}
\collectexercisesstop{collCh\thechapter}
\printcollection[print=exercises]{collCh\thechapter}
Bla bla bla bla bla bla bla bla bla bla bla.
\printsolutions[chapter=\thechapter,collection=collCh\thechapter]
\end{filecontents}
\begin{filecontents}{manualChapter.tex}
This is chapter Manual.
\collectexercises{collChManual}
\input{ChManual.tex}
\collectexercisesstop{collChManual}
\printcollection[print=exercises]{collChManual}
Bla bla bla bla bla bla bla bla bla bla bla.
\printsolutions[chapter=3,collection=collChManual]
\end{filecontents}
\begin{document}
\chapter{One}
%\input{macroChapter.tex}
\chapter{Two}
%\input{macroChapter.tex}
\chapter{Manual}
\input{manualChapter.tex}
\end{document}
\input
is irrelevant.macroChapter.tex
file (included multiple times in main doc) to be completely parametric in function of the macro\thechapter
.