# xsim-package: subexercises and points calculation

I want to setup exercises/questions for an exam. Some exercises will have subquestions. When there are no subquestions I can simply specify the "points" property and get that neat space in the right margin to fill in the points. However, I did not find a way to specify subquestions with points and have them correctly printed out. Below is a stitched together MWE, which illustrates the problem: using the \addpoints{} command, the points are added to the exercise, as shown in the total of the grade table, but they do not show up in the entry of the exercise itself or in the margin. How can I get subquestions to work?

Note: I have used the exercise package before, but don't think it provides similar functionality regarding grade tables etc.

\documentclass{article}
\usepackage{xsim}
\xsimsetup{
clear-aux,
solution/print          = false,
exercise/template       = mytemp,
}

\DeclareExerciseEnvironmentTemplate{mytemp}{%
\subsection*
{%
\XSIMmixedcase{\GetExerciseName}\nobreakspace
\GetExerciseProperty{counter}%
\IfInsideSolutionF
{%
\GetExercisePropertyT{subtitle}{ {\normalfont\itshape\PropertyValue}}%
}%
}
%   \GetExercisePropertyT{points}
%   {%
\marginpar
{%
\IfInsideSolutionF{\rule{1.2cm}{1pt}\slash}%
%           \printgoal{\PropertyValue}
\GetExerciseProperty{points} % this is the only part I added in, and I commented the GetExercisePropertyT conditional out.
\GetExercisePropertyT{bonus-points}{~(+\printgoal{\PropertyValue})}%
~\XSIMtranslate{point-abbr}%
}%
%   }%
}
{}

\begin{document}
\begin{exercise}
\begin{enumerate}
\end{enumerate}
\end{exercise}
\begin{exercise}[points=10]
another exercise
\end{exercise}
\end{document}

• – RL-S Jun 6 at 12:58

Ok, I think I found a solution that works at least for my purposes:

I defined a counter that gets set to zero in the pre-hook of every exercise and a custom command \addpts which increases that counter, then writes that value to the [points] property of the exercise and also prints out the value.

\documentclass{article}
\usepackage{calc}
\usepackage{xsim}
\xsimsetup{
clear-aux,
solution/print          = false,
}

\newcounter{expoints}
\SetExpandedExerciseProperty{points}{\theexpoints}%
(\points{#1})%
}
\xsimsetup{
exercise/pre-hook       ={\setcounter{expoints}{0}}
}

\begin{document}
\begin{exercise}
\begin{enumerate}
\end{enumerate}
\end{exercise}
\begin{exercise}[points=7]
another exercise
\end{exercise}
\begin{exercise}
\begin{enumerate}
\end{enumerate}
\end{exercise}
\end{document}


EDIT: I later found that I also need half points. Given that xsim already loads xparse (IIRC), you can use this LaTeX3 variant:

\documentclass{article}
\usepackage{xsim}
\xsimsetup{
clear-aux,
solution/print          = false,
}

\ExplSyntaxOn
\NewDocumentCommand{\declarefpvar}{m}
{
\fp_new:c { #1 }
}
\NewDocumentCommand{\setfpvar}{mm}
{
\fp_gset:cn { #1 } { #2 }
}
{
\fp_gadd:cn { #1 } { #2 }
}
\DeclareExpandableDocumentCommand{\usefpvar}{m}
{
\fp_use:c { #1 }
}
\ExplSyntaxOff

\declarefpvar{expoints}
\SetExpandedExerciseProperty{points}{\usefpvar{expoints}}%
(\points{#1})%
}
\xsimsetup{
exercise/pre-hook       ={\setfpvar{expoints}{0}},
}%

\begin{document}
\begin{exercise}
\begin{enumerate}
\end{enumerate}
\end{exercise}
\begin{exercise}[points=8]
another exercise
\end{exercise}
\begin{exercise}
\begin{enumerate}
\end{enumerate}
\end{exercise}
\end{document}


If you need a different decimal separator, say, a comma, load the siunitx package with

\usepackage{siunitx}
\sisetup{
decimalsymbol=comma,    %default is period
}


\xsimsetup{