4

Is there something like a \nextpointssum command which prints the sum of all points since the last occurrence of \nextpointssum in exsheets?

\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}
student
  • 29,003

1 Answers1

2

The solution is actually pretty straightforward – at least if you don't use the command twice between exercises:

\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

The complete document:

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

enter image description here

cgnieder
  • 66,645