I have data presented in tabular environments and I want to process it, in LaTeX, in ways that require for multiple cells to be analyzed together. That's in addition to typesetting the cells themselves.
For example, my source file has things like
\begin{mytabularpresentation}
stuff & more stuff & yes \\
data & more data & no \\
\end{mytabularpresentation}
In addition to showing “stuff”, “yes”, etc., I want to process “stuff” and “yes” (i.e. I want to run \somecommand{stuff}{yes}), “data” and “no”, and so on.
Here's a M-ish WE with a toy example. I use global variables to store cell contents and recall them later on the same row.
\documentclass{article}
\usepackage{calc}
\usepackage{array}
\usepackage{collcell}
\newcommand{\labelcell}[1]{#1}
\newcolumntype{L}{>{\collectcell\labelcell}l<{\endcollectcell}}
\newcommand{\aye}[1]{\gdef\ayecontents{#1}#1}
\newcolumntype{A}{>{$\collectcell\aye}r<{\endcollectcell$}}
\newcommand{\bee}[1]{\gdef\beecontents{#1}#1}
\newcolumntype{B}{>{$\collectcell\bee}r<{\endcollectcell$}}
\newcolumntype{R}{>{$}r<{$}}
\newcounter{result}
\newcommand{\calcvalue}[1]{\setcounter{result}{#1}\theresult}
\begin{document}
\begin{tabular}{LABR}
sum & 3 & 2 & \calcvalue{\ayecontents+\beecontents} \\
product & 3 & 2 & \calcvalue{\ayecontents*\beecontents} \\
negative & 3 & & \calcvalue{-\ayecontents} \\
square root & \omit & 4 & \sqrt{\beecontents} \\
\omit & 76 & 89 & \calcvalue{\ayecontents*(42-\beecontents)} \\
\end{tabular}
\end{document}
This is pretty fragile. In my real use cases, I run into complications such as cells with \omit (which must be detected, rather than reusing the content from the previous row) and nested tables.
One thing I want to do, which the example above doesn't do, is collect information for the whole row. I thought of \everycr, but it isn't really supported in LaTeX, and when I tried forcing it, it caused errors, I think because I have some nonexpandable \everycr content which ends up at the beginning of the next row's first cell. MNWE:
\documentclass{article}
\usepackage{array}
\makeatletter
\newcommand{\ialignwitheverycr}[1]{%
}
\newenvironment{tabularwitheverycr}[1]{%
\let\orig@ialign\ialign%
\def\ialign{\everycr{#1}\tabskip\z@skip\let\ialign\orig@ialign\halign}%
\tabular%
}{%
\endtabular%
}
\makeatother
\begin{document}
\begin{tabularwitheverycr}{\def\stuff{}}{rl}
one & two \\
\multicolumn{1}{l}{hello} & world \\
\end{tabularwitheverycr}
\end{document}
Error: Misplaced \omit. on the \multicolumn call (plus a flurry of consequences).
How can I collect data from multiple columns in each row and act on them? Is there a ready-made package for that? If I need to roll my own, is there a better way than global variables, and how can I “finish up” a row?
Note that I want to keep the source as is. I am not changing my source to \somekindofrow{sum}{3}{2}{\calcvalue{\ayecontents+\beecontents}}.
spreadtab:\begin{spreadtab}{{tabular}{l*{3}{>{$}r<{$}}}} @ sum & 3 & 2 & b1+c1 \\ @ product & 3 & 2 & b2*c2\\ @ negative & 3 & & -1*b3 \\ @ square root & & 4 & \sqrt{:={c4}} \\ & 76 & 89 & b5*(42-c5) \\ \end{spreadtab}– cgnieder Jan 18 '17 at 22:53spreadtabas long as the data are numbers. But anyways – ifspreadtabcan't be of use for you don't use it. :) I don't know it much better then you do – I have rarely if ever used it myself… – cgnieder Jan 18 '17 at 23:02