Feature request: Creating tables from (tab-separated) values
Hello, This idea described below was partially inspired by "gnuplot contemptations", but mainly because writing tables with both LaTeX & ConTeXt is too complex in most cases. Natural tables are great since they offer anough flexibility to do "just about anything" with tables, but many tables are still simple "m values in n rows" and for those it's an annoying task to write those "\NC"s, "\eTR\bTR"s, ... even if it's just a matter of writing a script to transform the values to a suitable form. Christopher Creutzig has sent an interesting solution to the mailing list some time ago (see http://wiki.contextgarden.net/TABLE#Creating_tables_from_CSV_data_.28Comma_S...) and since then I've been thinking about a similar, slightly more powerful solution which could make table-typesetiting easier. I don't have enough skills to implement it, but here are some properties listed that such a solution should have. In case anyone finds this little project doable ... It would solve quite some headaches. - [very important] a possibility to define own macros, so that it would be easy to print any type of tables (natural tables, TaBlEs, ... or whatever form that could possibly come to someone's mind); for example \def\MyDef#1#2{\bTR\bTD#1\eTD\bTD#2\eTD\eTR}; the "machinery behind" would only have to "feed" these macros properly according - [important] possible to separate the data with different characters: tab, comma, multiple spaces, ampersand (&), ... - [very useful] a possibility to read the data from a block (\start...\stop...) or from a file; it would be handly to be able to use the same data file for making a plot and for printing the data into a table - [useful] possibility to ignore lines starting with '#' (optional; usually these are comments) - [not crucial] if comma (,) is separating the data, a possibility to escape it - [useful] a possibility to select which rows (columns) to print (for example rows "1-3,8-last" or "even", ...) - [optional, but still useful] replacing decimal points with commas - [optional] if the table was supposed to have 4 colums and only 2 are available, ignore/fill with empty arguments (don't panic with unnecessary errors) - [with luaTeX in mind] calculating sums of rows & columns & other Excel-like calculations & references accross tables ;) - well, that one wasn't meant seriously. Thanks a lot, Mojca
On Sat, 22 Apr 2006, Mojca Miklavec wrote:
- [with luaTeX in mind] calculating sums of rows & columns & other Excel-like calculations & references accross tables ;) - well, that one wasn't meant seriously.
Hello Mojca, should be possible even without luaTeX: \input realcalc % can be found on CTAN \def\SumFF{0} \def\SumEUR{0} \def\AddEUR#1{\Radd\SumEUR\SumEUR{#1}% \Rmul\R{#1}{6.55957}\Radd\R\R{0.005}\Rtrunc\R2\R \Radd\SumFF\SumFF\R \bTR \bTD\eTD \bTD#1\eTD \expanded{\bTD\R\eTD} \eTR} \def\PrintSums{\bTR \bTD Sums: \eTD \bTD\Rtrunc\SumEUR2\SumEUR \SumEUR\eTD \bTD\Rtrunc\SumFF2\SumFF \SumFF \eTD \eTR} \starttext \setupTABLE[r][each][align=flushright] \setupTABLE[r][1][align=middle] \bTABLE \bTR \bTH\eTH \bTH Euro \eTH \bTH FF \eTH \eTR \AddEUR{1.23} \AddEUR{2.34} \AddEUR{45.67} \PrintSums \eTABLE \stoptext With LaTeX, you can even replace the . by a , : \documentclass{article} \usepackage{dcolumn} \input{realcalc}% on CTAN \newcommand*\cc[1]{\multicolumn{1}{c}{#1}} \def\scanwert\ignorespaces#1\unskip{\gdef\WERT{#1}#1} \begin{document} \begin{tabular}{>{\scanwert}D{.}{,}{-1}% >{\Rmul\res\WERT{6.55957}\Radd\res\res{0.005}\Rtrunc\res2\res\res}% D{.}{,}{-1}}% \cc{Euro} & \cc{FF}\\\hline 20.33 & \\ 20.3 & \\ 20 & \\ 14.46 & \end{tabular} \end{document} Cheers, Peter -- http://pmrb.free.fr/contact/
On 4/22/06, Peter Münster wrote:
On Sat, 22 Apr 2006, Mojca Miklavec wrote:
- [with luaTeX in mind] calculating sums of rows & columns & other Excel-like calculations & references accross tables ;) - well, that one wasn't meant seriously.
Hello Mojca, should be possible even without luaTeX:
\input realcalc % can be found on CTAN
Thanks for the pointer! I've never used this one so far.
\def\SumFF{0} \def\SumEUR{0}
\def\AddEUR#1{\Radd\SumEUR\SumEUR{#1}% \Rmul\R{#1}{6.55957}\Radd\R\R{0.005}\Rtrunc\R2\R \Radd\SumFF\SumFF\R \bTR \bTD\eTD \bTD#1\eTD \expanded{\bTD\R\eTD} \eTR}
\def\PrintSums{\bTR \bTD Sums: \eTD \bTD\Rtrunc\SumEUR2\SumEUR \SumEUR\eTD \bTD\Rtrunc\SumFF2\SumFF \SumFF \eTD \eTR}
\starttext \setupTABLE[r][each][align=flushright] \setupTABLE[r][1][align=middle] \bTABLE \bTR \bTH\eTH \bTH Euro \eTH \bTH FF \eTH \eTR \AddEUR{1.23} \AddEUR{2.34} \AddEUR{45.67} \PrintSums \eTABLE \stoptext
With LaTeX, you can even replace the . by a , :
Stupid me! I forgot about the following trick \uccode`.=`, \WORD{3.14} (It can be surely done without using \WORD, but that was the easiest way to recall it from another evil example that Hans sent me some time ago.) Mojca
On Sun, 23 Apr 2006, Mojca Miklavec wrote:
Stupid me! I forgot about the following trick \uccode`.=`, \WORD{3.14}
Great! Could you also get aligncharacter=yes working, that would be nice! Cheers, Peter -- http://pmrb.free.fr/contact/
Hi, Here is a quick hack that converts csv to commalist values. Perhaps it helpful for someone. Documentation blurb: This module parses CSV data (somewhat) safely. After \def\dataline{a,,\j,a",a\j a",t{f},",","""","a""b"} \convertcsvdata\dataline\to \myascii \message{\meaning\myascii} output is: macro:->{a},{},{\j },{a"},{a\j a"},{t{f}},{,},{"},{a"b} The result is detokenized, like would be with \type{\convertargument}. Therefore, you will need to run \type{\scantokens} over the list items if the CVS data was actually \TeX{} code. Cheers, Taco
participants (3)
-
Mojca Miklavec
-
Peter Münster
-
Taco Hoekwater