xsim-package:子练习和积分计算

xsim-package:子练习和积分计算

我想为考试设置练习/问题。有些练习会有子问题。当没有子问题时,我只需指定“points”属性,并在右边距中留出整齐的空间来填写点数。但是,我没有找到一种方法来指定带有点数的子问题并正确打印出来。下面是一个拼接在一起的 MWE,它说明了问题:使用 \addpoints{} 命令,点数被添加到练习中,如成绩表的总数所示,但它们不会显示在练习本身的条目中或边距中。我怎样才能让子问题发挥作用?

注意:我以前使用过练习包,但认为它没有提供关于成绩表等方面的类似功能。

\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}

答案1

好的,我想我找到了一个至少对我的目的有用的解决方案:

我定义了一个计数器,该计数器在每个练习的预挂钩中设置为零,并定义了一个自定义命令 \addpts,它会增加该计数器,然后将该值写入练习的 [points] 属性并打印出该值。

\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}

上述代码的输出

编辑:我后来发现我还需要半点。鉴于 xsim 已经加载了 xparse (IIRC),您可以使用这个 LaTeX3 变体:

\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}

如果你需要不同的小数分隔符,比如逗号,可以使用以下命令加载 siunitx 包

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

并添加

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

这在我的计算机上有效。

相关内容