My aim is to create a command for inserting tables, which will format the table, and add calculations on its values, given a file containing the raw data of the rows only.
\documentclass{article}
\usepackage{spreadtab,booktabs,xpatch}
\begin{document}
\begin{spreadtab}{{tabular}{lcc}}
\toprule
@ Product name & @ Price & @ Count \\
\midrule
\input{products}
\midrule
@ Total & :={sumprod(b2:[0,-1];c2:[1,-1])} & sum(c2:[0,-1]) \\
\bottomrule
\end{spreadtab}
\end{document}
where products.tex
includes
@ Plant & 60 & 2 \\
@ Book & 90 & 4 \\
@ Other & 100 & 10 \\
Pasting the lines of products.tex
into the matching place above works smoothly.
I wish to have the above code as a command, so I can use the same code to enter different table values, without repeating the heading and calculation definitions. However, the end result of using input
always leaves the summation values as 0, and the @
letter is now part of the text:
I guess the processing by spreadtab is done before the input is inserted - but I wonder if there is a way to solve it.
Following this question: Cannot use \toprule when doing \input inside tabular -- why?, I tried to add primitive tex input into the spreadtab environment. Meaning, I used
\makeatletter
\newcommand\primitiveinput[1]{\@@input #1 }
\makeatother
and replaced the line \input{products}
with \primitiveinput{products}
. But again no luck - I get the exact same output as using input
.
Any ideas?
\documentclass
and ending with\end{document}
as this will make it much easier for people to help you effectively. Have you looked at datatool or csvsimple? Perhaps one of those would help?