Sometimes I would like LaTeX to automatically calculate sums (or other simple arithmetic) for me, eg. in a table. I would like to ensure that when I update the table, I don't accidentally forget to update some sums. I also wouldn't want to maintain the table in another program, eg. a spreadsheet, or use some external script to generate LaTeX output. Is this possible without writing a lot of macros and completely bloating the tabular syntax?
For example:
\begin{tabular}{l l l l | l}
& Foo & Bar & Baz & \\
Small & 5 & 3 & 11 & \rowsum{} \\
Medium & 9 & 2 & 23 & \rowsum{} \\
Large & 13 & 15 & 44 & \rowsum{} \\
\hline
& \colsum{} & \colsum{} & \colsum{} & \\
\end{tabular}
Here, \rowsum
and \colsum
would somehow calculate the sum of their respective rows and columns, and I would not need to worry about calculating them by hand.