3

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,
    grading-table/template  = default,
    grading-table/type      = exercise,
    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}
    \gradingtable
    \begin{exercise}
        \begin{enumerate}
            \item subquestion 1 (\addpoints{5})
            \item subquestion 2 (\addpoints{7})
        \end{enumerate}
    \end{exercise}
    \begin{exercise}[points=10]
        another exercise
    \end{exercise}
\end{document}
2

1 Answer 1

4

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,
    grading-table/template  = default,
    grading-table/type      = exercise,
}

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

\begin{document}
    \gradingtable
    \begin{exercise}
        \begin{enumerate}
            \item subquestion 1 \addpts{2}
            \item subquestion 2 \addpts{3}
            \item subquestion 3 \addpts{5}
        \end{enumerate}
    \end{exercise}
    \begin{exercise}[points=7]
        another exercise
    \end{exercise}
    \begin{exercise}
        \begin{enumerate}
            \item subquestion 1 \addpts{1}
            \item subquestion 2 \addpts{2}
            \item subquestion 3 \addpts{3}
        \end{enumerate}
    \end{exercise}
\end{document}

output of the code above

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,
    grading-table/template  = default,
    grading-table/type      = exercise,
}

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

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

\begin{document}
    \gradingtable
    \begin{exercise}
        \begin{enumerate}
            \item subquestion 1 \addpts{2.5}
            \item subquestion 2 \addpts{3.5}
            \item subquestion 3 \addpts{5.5}
        \end{enumerate}
    \end{exercise}
    \begin{exercise}[points=8]
        another exercise
    \end{exercise}
    \begin{exercise}
        \begin{enumerate}
            \item subquestion 1 \addpts{1.5}
            \item subquestion 2 \addpts{2.5}
            \item subquestion 3 \addpts{3}
        \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
}

and add

\xsimsetup{
    goal-print              ={\num{#1}},
}

That works on my machine.

You must log in to answer this question.

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