仅打印自上次在表格中打印的点和以来的点和

仅打印自上次在表格中打印的点和以来的点和

是否有类似命令可以打印自上次出现exsheets\nextpointssum以来所有点的总和?\nextpointssum

\documentclass{article}

\usepackage{exsheets}

\begin{document}

\begin{question}{2}
  Question 1
\end{question}

\begin{question}{3}
  Question 2
\end{question}

%\nextpointssum %should print 5
%\currentpointssum % prints 5

\begin{question}{1}
  Question 3
\end{question}

\begin{question}{7}
  Question 4
\end{question}

%\nextpointssum % should print all points since last \nextpointssum i.e. 8
%\currentpointssum % prints 13 

\begin{question}{3}
  Question 5
\end{question}

\end{document}

答案1

解决方案实际上非常简单 - 至少如果你在练习之间不两次使用命令:

\ExplSyntaxOn
\fp_gzero_new:N \g_last_points_sum_fp
\fp_gzero_new:N \g_last_points_fp

\NewDocumentCommand \lastpointssum { s }
  {
    \fp_set:Nn \g_last_points_fp
      { \g__exsheets_points_sum_fp - \g_last_points_sum_fp }
    \fp_gset:Nn \g_last_points_sum_fp
      { \g_last_points_sum_fp + \g_last_points_fp }
    \bool_if:NTF \l__exsheets_parse_points_bool
      {
        \IfBooleanTF {#1}
          { \exsheets_parse_points:n { \g_last_points_fp } }
          { \exsheets_print_points:n { \g_last_points_fp } }
      }
      { \msg_warning:nnn {exsheets} {parse-points} {\lastpointssum} }
  }
\ExplSyntaxOff

完整文档:

\documentclass{article}

\usepackage{exsheets}

\ExplSyntaxOn
\fp_gzero_new:N \g_last_points_sum_fp
\fp_gzero_new:N \g_last_points_fp

\NewDocumentCommand \lastpointssum { s }
  {
    \fp_set:Nn \g_last_points_fp
      { \g__exsheets_points_sum_fp - \g_last_points_sum_fp }
    \fp_gset:Nn \g_last_points_sum_fp
      { \g_last_points_sum_fp + \g_last_points_fp }
    \bool_if:NTF \l__exsheets_parse_points_bool
      {
        \IfBooleanTF {#1}
          { \exsheets_parse_points:n { \g_last_points_fp } }
          { \exsheets_print_points:n { \g_last_points_fp } }
      }
      { \msg_warning:nnn {exsheets} {parse-points} {\lastpointssum} }
  }
\ExplSyntaxOff

\begin{document}

\begin{question}{2}
  Question 1
\end{question}

\begin{question}{3}
  Question 2
\end{question}

\lastpointssum\par % 5
\currentpointssum  % 5

\begin{question}{1}
  Question 3
\end{question}

\begin{question}{7}
  Question 4
\end{question}

\lastpointssum\par % 8
\currentpointssum  % 13

\begin{question}{3}
  Question 5
\end{question}

\lastpointssum\par % 3
\currentpointssum  % 16

\begin{question}{7}
  Question 4
\end{question}

\begin{question}{3}
  Question 5
\end{question}

\lastpointssum\par % 10
\currentpointssum  % 26

\end{document}

在此处输入图片描述

相关内容