Background: In my previous question, Robert Fuster taught me how to define a global variable using calculator package.
I want to define a "counter" that also works with non-integers. I thus defined an \addtocounter-like macro as following (assuming that \mySum and \whatIAdd have been previously defined):
\ADD{\whatIAdd}{\mySum}{\mySum}
\GLOBALCOPY{\mySum}{\mySum}
My macro works well in normal text mode (see below). However, if I use it inside a table, it "mysteriously" does each addition once before plotting the table. Even if I reset it at the beginning, \mySum equals the sum of each \whatIAdd in my table.
Question: where does this artefact comes from, and how to remove it?
\documentclass{scrartcl}
\usepackage{calculator}
\usepackage{array,tabulary,booktabs}
%% Macro definition %%
\newenvironment{mytable}
{
\GLOBALCOPY{0}{\mySum}
\texttt{mySum} equal \mySum
\tabulary{\linewidth}{CC}
\toprule
\textbf{A}&\textbf{$\Sigma$ A}\\
\midrule
}{
\endtabulary
}
\newcommand{\makeline}[1]
{%
\COPY{#1}{\whatIAdd}
\ADD{\whatIAdd}{\mySum}{\mySum}
\GLOBALCOPY{\mySum}{\mySum}
%
\whatIAdd & \mySum\\
}
\newcommand{\resetMySum}{\GLOBALCOPY{0}{\mySum}\noindent I've reseted \texttt{mySum}. It's value is now \mySum .\newline}
\newcommand{\addMySum}[1]
{
\COPY{#1}{\whatIAdd}
\ADD{\whatIAdd}{\mySum}{\mySum}
\GLOBALCOPY{\mySum}{\mySum}
%
\noindent I added \whatIAdd{} to \texttt{mySum}. It's value is now \mySum .\newline
}
\begin{document}
\begin{minipage}{.25\textwidth}
\begin{mytable}
\makeline{0}
\makeline{1}
\makeline{42}
\bottomrule
\end{mytable}
\end{minipage}
\begin{minipage}{.75\textwidth}
\resetMySum
\addMySum{0}
\addMySum{1}
\addMySum{42}
\end{minipage}
\end{document}
