How can I reset the exercise counter within the same exercise type. I don’t want to create different exercise types as I want to create question bank and use collection option. I have attached MWE and required output. I am beginner and I am open even if some one can improve my code by using XSIM.
My MWE
\documentclass[a4paper,12pt]{article}
\usepackage{xsim}
\usepackage{tasks}
\settasks{
label = (\theexercise\arabic*) ,
label-width = 5ex,
item-indent=6ex
}
\DeclareExerciseType{question}{
exercise-env = question ,
solution-env = answer ,
exercise-name = Question ,
solution-name = Answer ,
exercise-template = item ,
solution-template = solution ,
% exercise/the-counter = \arabic{exercise}. ,
counter = exercise, % shares a counter with the `exercise' type
}
\DeclareExerciseEnvironmentTemplate{item}
{\item[\GetExerciseProperty{counter}]
\GetExercisePropertyT{points}
{%
\marginpar
{%
\par\vspace{2.5ex plus .2ex}
[\printgoal{\PropertyValue}]%
}%
}%
}%
{}
\DeclareExerciseEnvironmentTemplate{solution}
{\item[\GetExerciseProperty{counter}]}
{}
\newenvironment{questions}
{\itemize}
{\enditemize}
\newenvironment{answers}
{\itemize}
{\enditemize}
\usepackage{lipsum}
\xsimsetup{
exercise/the-counter = \arabic{exercise}.,
% exercise/within = section,
% answer/print = true,
}
\begin{document}
\section*{Section A}
\begin{questions}
\begin{question}[points=4]
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[66]
\end{answer}
\begin{question}
Answer the following questions.
\begin{tasks}
\task \lipsum[75]
\task question.
\end{tasks}
\end{question}
\begin{question}
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[75]
\end{answer}
\end{questions}
\section*{Section B}
\begin{questions}
\begin{question}[points=4]
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[66]
\end{answer}
\begin{question}
Answer the following questions.
\begin{tasks}
\task \lipsum[75]
\task question.
\end{tasks}
\end{question}
\begin{question}
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[75]
\end{answer}
\end{questions}
% \begin{answers}
% \item[] \printsolutions
% \end{answers}
\end{document}
Required output:


\section{…}instead of\section*{…}and to use\DeclareExerciseTypeoptionwithin=section. – cabohah Mar 17 '23 at 09:18\section*macros which don't increase thesectioncounter. Therefore linking theexercisecounter to this counter has no effect at\section*. You could add\usepackage{xpatch} \xpretocmd{\section}{\setcounter{exercise}{0}}{}{}to your preamble, but it is probably indeed better to use unstarred\sectionmacros (as suggested in the comment above) and maybe hide the section number in some way. – Jasper Habicht Mar 17 '23 at 09:24