tabularray e \gappto

tabularray e \gappto

Como um novo comando, uso \problempara compor testes para meus alunos de matemática. Às vezes também incluo quantos créditos você pode reunir em um determinado problema. Se eu usar a creditschave, tudo funcionará bem. Mas também tenho um \task[<credits>]comando com o qual posso imprimir questões menores e seus créditos (veja MWE abaixo). O problema que estou enfrentando atualmente é que os créditos dados com o \taskcomando serão colocados várias vezes em vez de apenas uma vez. Você tem alguma dica? Obrigado!


\documentclass[12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xifthen}    
\usepackage{tikz}
\usepackage{tabularray}
  \UseTblrLibrary{booktabs, counter}

\makeatletter
\def\credit{}
\newcounter{WS@credits}
\setcounter{WS@credits}{0}
\newcounter{subtask}
\setcounter{subtask}{1}
\renewcommand{\thesubtask}{\alph{subtask})}
\newcommand{\task}[1][]{%
    \ifthenelse{\isempty{#1}}{%
        \thesubtask%
        \stepcounter{subtask}%
    }{%
        \thesubtask%
        \addtocounter{WS@credits}{#1}%
        \ifnum\arabic{subtask}=1%
            \gappto\credit{(#1~p)}%
        \else%
            \gappto\credit{\\(#1~p)}%
        \fi%
        \stepcounter{subtask}%
    }%
}

\newcommand{\problem@credits}{}
\define@key{problem}{credits}[\problem@credits]{\renewcommand{\problem@credits}{%
    \addtocounter{WS@credits}{#1}%
    (#1~p)%
    }%
}

\newcounter{probctr}
\setcounter{probctr}{1}

\newcommand{\problem}[3][]{
    \setkeys{problem}{#1}%
    \begin{tblr}{colspec={>{\bfseries}lX}, column{1}={leftsep=0ex, rightsep=1.5ex}, column{2}={leftsep=0ex, rightsep=0ex}}
        \tikz[remember picture, baseline=(probctrbox.base)]{%
            \node[anchor=north west] (probctrbox) at (0,0) {A\arabic{probctr}};
        } &
        {#2}%
    \end{tblr}%
    \tikz[remember picture, overlay]{%
        \node at (probctrbox.south) [below, font=\scriptsize\normalfont]{\parbox{7ex}{\centering\ifdefempty{\credit}{\problem@credits}{\credit}}};
    }
    \stepcounter{probctr}
    \setcounter{subtask}{1}
    \renewcommand{\credit}{}
    \renewcommand{\problem@credits}{}
}
\makeatother

\begin{document}
\problem[credits=3]{
Write as power expressions.

\begin{tblr}{colspec={*{2}{>{\bfseries}lX}}, column{odd}={rightsep=0ex}}
    \task & $2\cdot 2\cdot 2\cdot 2$ &
        \task & $3\cdot 3\cdot 3\cdot 3\cdot 3\cdot 3$
\end{tblr}
}{
\begin{tblr}{colspec={*{2}{>{\bfseries}lX}}, column{odd}={rightsep=0ex}}
    \task & $=2^4$ &
        \task & $=3^6$
\end{tblr}
}

\problem{
Write as power expressions.

\begin{tblr}{colspec={*{2}{>{\bfseries}lX}}, column{odd}={rightsep=0ex}}
    \task[1] & $2\cdot 2\cdot 2\cdot 2$ &
        \task[3] & $3\cdot 3\cdot 3\cdot 3\cdot 3\cdot 3$
\end{tblr}
}{
\begin{tblr}{colspec={*{2}{>{\bfseries}lX}}, column{odd}={rightsep=0ex}}
    \task & $=2^4$ &
        \task & $=3^6$
\end{tblr}
}
\end{document}

informação relacionada