[NTG-context] Feature request: Creating tables from (tab-separated) values

Peter Münster pmlists at free.fr
Sat Apr 22 20:02:45 CEST 2006


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/


More information about the ntg-context mailing list