I'm learning LaTeX3 and trying to do simple calculations on floats in a longtblr environment.
Trouble is that I cannot manage to dynamically compute sub-totals per row. The global total is working fine but the sub-total is evaluated only once. (l_subtot_fp should be 6 on the first row and 8 on the second)
The second problem is : How do you append rows containing the alignment character "&" ? I get "Misplaced alignment tab character &." error if I add them.
I suspect a TeX expansion enigma, can anyone clarify this ?
Thanks a lot in advance for any helping answer !
\documentclass{article}
\usepackage{tabularray}
\ExplSyntaxOn
\tl_new:N \g_rowlist_tl
\fp_set:Nn \g_total_fp {0}
\newcommand*{\NewRow}[3]{
\fp_set:Nn \l_subtot_fp {#2}
\fp_set:Nn \l_subtot_fp { \l_subtot_fp * #3 }
% Next line should contain three "&" like this:
% \tl_put_right:Nn \g_rowlist_tl {#1 & #2 & #3 & {\fp_use:N \l_subtot_fp}\\}
\tl_put_right:Nn \g_rowlist_tl {#1 #2 #3 {\fp_use:N \l_subtot_fp}\\}
\fp_add:Nn \g_total_fp {\l_subtot_fp}
}
\begin{document}
\NewRow{A}{3}{2}
\NewRow{B}{2}{4}
% Dynamic version (NOT WORKING)
\begin{longtblr}{cccc}
\tl_use:N \g_rowlist_tl
Total &&& \fp_eval:n {\g_total_fp}
\end{longtblr}
% What I would like to generate
\begin{longtblr}{cccc}
A & 3 & 2 & 6\\
B & 2 & 4 & 8\\
Total &&& 14
\end{longtblr}
\end{document}
\ExplSyntaxOff
tabularray
which will be released on June 1st. See github.com/lvjr/tabularray/issues/81 for more details.