summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/calctab
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-03-31 00:24:45 +0000
committerKarl Berry <karl@freefriends.org>2009-03-31 00:24:45 +0000
commit088ae35fa451f7492dec5997ba5f8d53df17f47e (patch)
tree318666da7317036fe66f06b9f0c6a845a5f97cf4 /Master/texmf-dist/tex/latex/calctab
parent4054ed60df3fdb5816ce59388b4c291c570e0b8c (diff)
calctab 0.6 (30mar09)
git-svn-id: svn://tug.org/texlive/trunk@12578 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/calctab')
-rw-r--r--Master/texmf-dist/tex/latex/calctab/calctab.sty559
1 files changed, 439 insertions, 120 deletions
diff --git a/Master/texmf-dist/tex/latex/calctab/calctab.sty b/Master/texmf-dist/tex/latex/calctab/calctab.sty
index 229ce5cd65f..12109f18540 100644
--- a/Master/texmf-dist/tex/latex/calctab/calctab.sty
+++ b/Master/texmf-dist/tex/latex/calctab/calctab.sty
@@ -1,82 +1,89 @@
-%% calctab.sty
-%% Copyright (C) 2009 Roberto Giacomelli <giaconet at tin dot it>
+% calctab.sty
%
-% This work may be distributed and/or modified under the
-% conditions of the LaTeX Project Public License, either version 1.3
-% of this license or (at your option) any later version.
-% The latest version of this license is in
-% http://www.latex-project.org/lppl.txt
-% and version 1.3 or later is part of all distributions of LaTeX
-% version 2005/12/01 or later.
+% Version: 0.6
+% Date: 2009_03_20
+%
+% Copyright (C) 2009 Roberto Giacomelli <giaconet at tin dot it>
+%
+% This work may be distributed and/or modified under the
+% conditions of the LaTeX Project Public License, either
+% version 1.3 of this license or any later version.
+% The latest version of this license is in
+% http://www.latex-project.org/lppl.txt and version 1.3
+% or later is part of all distributions of LaTeX version
+% 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Roberto Giacomelli
%
-% This work consists of the files calctab.sty, calctab_manual.pdf
-% and README.txt
-%
-% Please make attention to this important note:
-% This package is experimetal: the language syntax can be change.
+% This work consists of these files:
+% calctab.sty, calctab_manual.pdf and README
%
-% version 0.5
-% date: 2009_02_20
-%
-% History of 0.5 version
-% 1 - single row key definition without a fltpoint registry
-% 2 - add a package warning if the keys generate an override
-% 3 - new feature: id key for \add command
-% 4 - Fixed bug in single row key definition
-% 5 - add warning or error internal command, at the end of the listing code
-% 6 - new feature: interval keys 'from' and 'until' in opt arg of the \perc and \add command
-% complete by warning feature.
+% Please make attention to this important notice:
+% The language syntax can be change.
%
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{calctab}[2009/02/20 v0.5 Autocalc table environment]
+\ProvidesPackage{calctab}[2009/03/23 v0.6 Autocalc table environments]
%
% ''library'' package for the table's visual property
+\RequirePackage{alphalph}
\RequirePackage{booktabs}
\RequirePackage{eurosym}
\RequirePackage[table]{xcolor}
-\RequirePackage{numprint}
+\RequirePackage{numprint}[2008/02/17]
%
% ''library'' package for algorithms and language implementation
\RequirePackage{xkeyval}
\RequirePackage{ifthen}
\RequirePackage{fltpoint}
+\RequirePackage{xstring}
+%
%
% length to tuning distance of central column of calctab table
% 8 mm is the default value
-\newlength{\ctsep}\setlength{\ctsep}{0.8cm}
+\newlength{\ctsep}\setlength{\ctsep}{8mm}
%
-% main row counter of the table
+% main counter of the table rows
\newcounter{ct@RowIndex}
%
-% loop simple counter
+% simple loop counter
\newcounter{ct@i}
+\newcounter{ct@k}
+%
+% macrokey definition commands
+\newcommand{\ct@makemacrokey}[1]{\expandafter\def\csname #1\endcsname##1{%
+ \expandafter\def\csname ct@#1\endcsname{##1}}}
%
-% macrokey definition command
-\newcommand{\makemacrokey}[1]{\expandafter\def\csname #1\endcsname##1{%
- \expandafter\def\csname @@#1\endcsname{##1}}}
+% apparence text commands definition and default assignments
+\ct@makemacrokey{ctcurrency}\ctcurrency{\euro}
+\ct@makemacrokey{ctdescription}\ctdescription{Items description}
+\ct@makemacrokey{ctontraslation}\ctontraslation{on}
+\ct@makemacrokey{ctheaderone}\ctheaderone{Q.ty}
+\ct@makemacrokey{ctheadertwo}\ctheadertwo{Price}
+
%
-% apparence command definition and default assignment
-\makemacrokey{ctcurrency}\ctcurrency{\euro}
-\makemacrokey{ctdescription}\ctdescription{Items description}
-\makemacrokey{ctontraslation}\ctontraslation{on}
+% boolean to control numeric loop: if ct@Globflag is true then
+% all row values are computed
+\newboolean{ct@Globflag}\setboolean{ct@Globflag}{true}
%
-% new boolean to control numeric loop, if ctGlobflag is true sum all row values
-\newboolean{ctGlobflag}\setboolean{ctGlobflag}{true}
+% new boolean to control behavior of the \inrule command
+\newboolean{ct@ifinrule}\setboolean{ct@ifinrule}{false}
+%
+% new boolean to control rule after an \add row
+\newboolean{ct@ifruleafteradd}\setboolean{ct@ifruleafteradd}{false}
%
% control flag of the from, until keys
% this flag is false if from and/or unil keys is/are not specified
\newboolean{ct@fromctrl}\setboolean{ct@fromctrl}{false}
\newboolean{ct@untilctrl}\setboolean{ct@untilctrl}{false}
%
-% definition of ordinary key
-% the ordinary keys is useful for assign a name to table row
-% note the use of different families
%
%
+% definitions of the ordinary keys
+% the ordinary keys is useful for to assign a name to row
+% note the use of different families
+%
\define@key{ctfamId}{id}{%
% save in ctreg@<idname> its row number
\expandafter\edef\csname ctreg@#1\endcsname{\thect@RowIndex}
@@ -90,13 +97,14 @@
\setboolean{ctflag\csname ctreg@#1\endcsname}{true}
}
% global flag is false if a key is specifed
- \setboolean{ctGlobflag}{false}
+ \setboolean{ct@Globflag}{false}
}%
}%
%
+%
% the id key for \add command
\define@key{ctfamAddid}{id}{%
- \ifthenelse{\boolean{ctGlobflag}}{%
+ \ifthenelse{\boolean{ct@Globflag}}{%
\expandafter\edef\csname ctref@#1\endcsname{\thect@RowIndex}
\define@key{ctfamLabel}{#1}[]{% set all row flag on true
\setcounter{ct@i}{1}
@@ -108,7 +116,7 @@
}
\stepcounter{ct@i}
}% end whiledo
- \setboolean{ctGlobflag}{false}
+ \setboolean{ct@Globflag}{false}
}
}{% else clause
\expandafter\edef\csname ctref@#1\endcsname{\ctref@temp}
@@ -117,7 +125,8 @@
\n@xt
}
}
-}
+}%
+%
%
% definition of ``interval'' keys
\define@key{ctfamLabel}{from}{%
@@ -127,103 +136,369 @@
\def\ct@fromrow{\csname ctreg@#1\endcsname}
\ifthenelse{\ct@fromrow=1}{\PackageWarning{calctab}{\ct@notusefulwarning{from}}}{}
\setboolean{ct@fromctrl}{true}
- \setboolean{ctGlobflag}{false}
+ \setboolean{ct@Globflag}{false}
}
-}
+}%
+%
%
\define@key{ctfamLabel}{until}{%
\@ifundefined{ctreg@#1}
- {\PackageError{calctab}{\ct@keynotexisterr{#1}}}
- {%
+ {\PackageError{calctab}{\ct@keynotexisterr{#1}}}{%
\def\ct@untilrow{\csname ctreg@#1\endcsname}
\ifthenelse{\ct@untilrow=\thect@RowIndex}{\PackageWarning{calctab}{\ct@notusefulwarning{until}}}{}
\setboolean{ct@untilctrl}{true}
- \setboolean{ctGlobflag}{false}
+ \setboolean{ct@Globflag}{false}
}
-}
+}%
%
-% table box allocation
-\newsavebox{\ctTabBox}
+% allocation of the table box
+\newsavebox{\ct@TabBox}
%
-% set standard decimal position
+% set standard decimal position (numprint package)
\nprounddigits{2}
%
+% internal \amount command control flag
+\newboolean{ct@isoperation}
%
-% main environment: definition
%
-\newenvironment{calctab}[1][]{%
+% main computation loop
+\newcommand\ct@Loop{%
+ \fpRegSet{ct@Sum}{0}
+ \setcounter{ct@i}{1}
+ \setcounter{ct@k}{0}
+ \edef\ct@labelreg{}% for the text labels row sequence (A+B+...)
+ \edef\ct@labeltemp{}%
+ \def\ct@plustext{}% '+' char
+ \whiledo{\not\(\value{ct@i}>\value{ct@RowIndex}\)}{%
+ \ifthenelse{\(\boolean{ctflag\thect@i}\OR\boolean{ct@Globflag}\)}{%
+ \fpRegAdd{ct@Sum}{ctRowValue\thect@i}%
+ \stepcounter{ct@k}
+ \ifthenelse{\value{ct@k}<3}{%
+ \edef\ct@labelreg{\ct@labelreg\ct@plustext\AlphAlph{\value{ct@i}}}
+ }{% else clause
+ \ifthenelse{\value{ct@k}>5}{%
+ \edef\ct@labeltemp{\ct@plustext$\, \cdots\,$\ct@plustext\AlphAlph{\value{ct@i}}}
+ }{%else clause
+ \edef\ct@labeltemp{\ct@labeltemp\ct@plustext\AlphAlph{\value{ct@i}}}
+ }
+ }
+ \setboolean{ctflag\thect@i}{false}% reset the row flag status
+ \def\ct@plustext{+}
+ }{%else clause: reset internal loop variables
+ \edef\ct@labelreg{\ct@labelreg\ct@labeltemp}
+ \setcounter{ct@k}{0}%
+ \edef\ct@labeltemp{}%
+ }%
+ \stepcounter{ct@i}%
+ }%
+ \edef\ct@labelreg{\ct@labelreg\ct@labeltemp}
+ \setboolean{ct@Globflag}{true}% reset the global flag status
+}%
+%
+%
+%
+%
+% calctab environment: definition code
+%
+\newenvironment{calctab}[1][]{%#1 is the optinal table's paragraph description
%set font family
\sffamily
%
-%set the token register (TeX primitive command resolve the tabular grouping problem)
-\toks255={\rowcolors{1}{gray!15}{}\begin{tabular}{clr}\midrule&\@@ctdescription & \@@ctcurrency \\\midrule}
+%set the token register (TeX primitive token register resolve the tabular grouping problem)
+\toks255={\rowcolors{1}{gray!15}{}\begin{tabular}{clr}\midrule&\ct@ctdescription & \ct@ctcurrency \\\midrule}
%
% reset main counter to starting value
\setcounter{ct@RowIndex}{0}
%
-% save paragraph table header to use it
-% in the environment end code
+% save paragraph table header to use it in the environment end code
\newcommand{\ct@FirstPar}[1]{#1}
%
% internal command definition
-\newcommand\ctLoop{%
- \fpRegSet{ctSum}{0}
- \setcounter{ct@i}{1}
- \edef\ctlabelreg{}% for text of labels row
- \edef\ctplustext{}% '+' char
- \whiledo{\not\(\value{ct@i}>\value{ct@RowIndex}\)}{%
- \ifthenelse{\(\boolean{ctflag\thect@i}\OR\boolean{ctGlobflag}\)}{%
- \fpRegAdd{ctSum}{ctRowValue\thect@i}%
- \setboolean{ctflag\thect@i}{false}% reset the row flag status
- \edef\ctlabelreg{\ctlabelreg\ctplustext\Alph{ct@i}}
- \edef\ctplustext{+}
- }{}%else clause denied
- \stepcounter{ct@i}%
- }%
- \setboolean{ctGlobflag}{true}% reset the global flag status
-}%
+%
%
% from until keys internal command
\newcommand{\ct@intervalloop}{%
- \ifthenelse{\(\boolean{ct@fromctrl}\OR\boolean{ct@untilctrl}\)}
- {
- \ifthenelse{\boolean{ct@fromctrl}}{\setboolean{ct@fromctrl}{false}}{\def\ct@fromrow{1}}
- \ifthenelse{\boolean{ct@untilctrl}}{\setboolean{ct@untilctrl}{false}}{\def\ct@untilrow{\thect@RowIndex}}
- \ifthenelse{\number\ct@fromrow<\number\ct@untilrow}
- {% canonical interval from until
- \ct@setintervalflag{\ct@fromrow}{\ct@untilrow}}
- {% negative interval 1 -> until plus from -> last row
- \ct@setintervalflag{1}{\ct@untilrow}
- \ct@setintervalflag{\ct@fromrow}{\thect@RowIndex}
- }% else clause denied
- }{}
+ \ifthenelse{\(\boolean{ct@fromctrl}\OR\boolean{ct@untilctrl}\)}{%
+ \ifthenelse{\boolean{ct@fromctrl}}{\setboolean{ct@fromctrl}{false}}{\def\ct@fromrow{1}}
+ \ifthenelse{\boolean{ct@untilctrl}}{\setboolean{ct@untilctrl}{false}}{\def\ct@untilrow{\thect@RowIndex}}
+ \ifthenelse{\number\ct@fromrow<\number\ct@untilrow}{% canonical interval from until
+ \ct@setintervalflag{\ct@fromrow}{\ct@untilrow}
+ }{% negative interval 1 -> until plus from -> last row
+ \ct@setintervalflag{1}{\ct@untilrow}
+ \ct@setintervalflag{\ct@fromrow}{\thect@RowIndex}
+ }
+ }{}% else clause denied
}
%
% internal command to set true the flags row in an interval
-\newcommand{\ct@setintervalflag}[2]{
+\newcommand{\ct@setintervalflag}[2]{%
% #1 arg -> start row value
% #2 arg -> finish row value
\setcounter{ct@i}{##1}
- \whiledo{\not\(\value{ct@i}>\number##2\)}{
- \ifthenelse{\boolean{ctflag\thect@i}}{
+ \whiledo{\not\(\value{ct@i}>\number##2\)}{%
+ \ifthenelse{\boolean{ctflag\thect@i}}{%
\PackageWarning{calctab}{\ct@overridingkeyerr{from or until}}
- }{
+ }{%
\setboolean{ctflag\thect@i}{true}
}
\stepcounter{ct@i}
}
+}%
+%
+%
+% #1 -> operator sign * / + -
+% #2 -> text for sign operation ($\, \times \,$)
+\newcommand{\ct@operator}[2]{%
+ \StrBefore{\ct@arg}{##1}[\ct@before]
+ \StrBehind{\ct@arg}{##1}[\ct@after]
+ \fpRegSet{ct@one}{\ct@before}
+ \fpRegMul{ct@one}{ct@unit}
+ \fpRegSet{ct@two}{\ct@after}
+ \fpRegCopy{ctRowValue\thect@RowIndex}{ct@one}
+ \IfStrEq{##1}{*}{\fpRegMul{ctRowValue\thect@RowIndex}{ct@two}}{}
+ \IfStrEq{##1}{/}{\fpRegDiv{ctRowValue\thect@RowIndex}{ct@two}}{}
+ \IfStrEq{##1}{+}{\fpRegAdd{ctRowValue\thect@RowIndex}{ct@two}}{}
+ \IfStrEq{##1}{-}{\fpRegSub{ctRowValue\thect@RowIndex}{ct@two}}{}
+ \fpRegRound{ctRowValue\thect@RowIndex}{-2}
+ \fpRegGet{ct@one}{\ct@before}
+ \fpRegGet{ct@two}{\ct@after}
+ \toks255=\expandafter{\the\toks255(}
+ \edef\ct@result{\noexpand\numprint{\ct@before}}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@result ##2}
+ \edef\ct@result{\noexpand\numprint{\ct@after}}
+ \toks255=\expandafter\expandafter\expandafter{%
+ \expandafter\the\expandafter\toks255\ct@result)\rule{\ctsep}{0pt}}
}
%
-\newcommand\amount[3][]{%
+%
+%
+%
+% interface inner command: \amount
+\newcommand\amount[3][]{%#1->opt arg #2->descr #3->amount
\stepcounter{ct@RowIndex}
\newboolean{ctflag\thect@RowIndex}%definition of bool flag for each row
\setboolean{ctflag\thect@RowIndex}{false}%initial value of ctflag<n>
\setkeys{ctfamId}{##1}%
- \fpRegSet{ctRowValue\thect@RowIndex}{##3}
%append the tabular entry to the token register
- \toks255=\expandafter{\the\toks255\Alph{ct@RowIndex}&##2\rule{\ctsep}{0pt}&\numprint{##3}\\}
+ \ifthenelse{\boolean{ct@ifinrule}}{%
+ \ifthenelse{\boolean{ct@ifruleafteradd}}{
+ \toks255=\expandafter{\the\toks255\midrule}
+ \setboolean{ct@ifruleafteradd}{false}
+ }{}
+ }{%
+ \setboolean{ct@ifruleafteradd}{false}
+ }
+ %
+ \toks255=\expandafter{\the\toks255\AlphAlph{\value{ct@RowIndex}}&##2 }
+ % elementary ``parse'' of the #3 argument
+ \fpRegSet{ct@unit}{1}
+ % elimination of the space char
+ \StrDel{##3}{ }[\ct@arg]
+ \IfBeginWith{\ct@arg}{-}{\setboolean{ct@isoperation}{true}}{\setboolean{ct@isoperation}{false}}
+ \ifthenelse{\boolean{ct@isoperation}}{%
+ \fpRegSet{ct@unit}{-1}
+ \StrBehind{\ct@arg}{-}[\ct@argt]
+ \def\ct@arg{\ct@argt}
+ }{}
+ \IfBeginWith{\ct@arg}{+}{\setboolean{ct@isoperation}{true}}{\setboolean{ct@isoperation}{false}}
+ \ifthenelse{\boolean{ct@isoperation}}{%
+ \StrBehind{\ct@arg}{+}[\ct@argt]
+ \def\ct@arg{\ct@argt}
+ }{}
+ %
+ \IfSubStr{\ct@arg}{*}{\setboolean{ct@isoperation}{true}}{\setboolean{ct@isoperation}{false}}
+ \ifthenelse{\boolean{ct@isoperation}}{% true
+ \ct@operator{*}{$\, \times \,$}
+ }{% false
+ \IfSubStr{\ct@arg}{/}{\setboolean{ct@isoperation}{true}}{\setboolean{ct@isoperation}{false}}
+ \ifthenelse{\boolean{ct@isoperation}}{%
+ \ct@operator{/}{$\, / \,$}
+ }{%
+ \IfSubStr{\ct@arg}{-}{\setboolean{ct@isoperation}{true}}{\setboolean{ct@isoperation}{false}}
+ \ifthenelse{\boolean{ct@isoperation}}{%
+ \ct@operator{-}{$\, - \,$}
+ }{%
+ \IfSubStr{\ct@arg}{+}{\setboolean{ct@isoperation}{true}}{\setboolean{ct@isoperation}{false}}
+ \ifthenelse{\boolean{ct@isoperation}}{%
+ \ct@operator{+}{$\, + \,$}
+ }{%
+ \fpRegSet{ctRowValue\thect@RowIndex}{\ct@arg}
+ }
+ }
+ }
+ }
+ \fpRegGet{ctRowValue\thect@RowIndex}{\ct@tempnumber}
+ \toks255=\expandafter{\the\toks255&}
+ \edef\ct@result{\noexpand\numprint{\ct@tempnumber}}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@result\\}
+ \setboolean{ct@ifinrule}{true}
+}%
+%
+%
+%
+\newcommand\perc[3][]{%
+ \stepcounter{ct@RowIndex}% another new row
+ \newboolean{ctflag\thect@RowIndex}% definition of bool flag for each row
+ \setboolean{ctflag\thect@RowIndex}{false}% initial value of ctflag<n>
+ % user id label task
+ \setkeys*{ctfamLabel}{##1}
+ \setrmkeys{ctfamId}
+ % 'from' and 'until' keys process
+ \ct@intervalloop
+ %
+ \addtocounter{ct@RowIndex}{-1}\ct@Loop\stepcounter{ct@RowIndex}
+ \fpDiv{\tempPerc}{##3}{100}%
+ \fpRegSet{tempreg}{\tempPerc}
+ \fpRegMul{ct@Sum}{tempreg}
+ \fpRegRound{ct@Sum}{-2}% approx to the second digit
+ \fpRegGet{ct@Sum}{\ct@tempnum}
+ \fpRegSet{ctRowValue\thect@RowIndex}{\ct@tempnum}
+ %
+ \ifthenelse{\boolean{ct@ifinrule}}{
+ \ifthenelse{\boolean{ct@ifruleafteradd}}{%
+ \toks255=\expandafter{\the\toks255\midrule}
+ \setboolean{ct@ifruleafteradd}{false}
+ }{}
+ }{
+ \setboolean{ct@ifruleafteradd}{false}
+ }
+ %
+ \toks255=\expandafter{\the\toks255\AlphAlph{\value{ct@RowIndex}}&##2 (\numprint{##3}\% \ct@ctontraslation{} }
+ \edef\ct@num{\noexpand\ct@labelreg)\noexpand\rule{\ctsep}{0pt}}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@num&}
+ \edef\ct@num{\noexpand\numprint{\ct@tempnum}}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@num\\}
+ \setboolean{ct@ifinrule}{true}
+}
+%
+\newcommand\add[2][]{%
+ \def\ctref@temp{##1}% save id list
+ \setkeys*{ctfamLabel}{##1}
+ \setrmkeys{ctfamAddid}
+ % 'from' and 'until' keys processing
+ \ct@intervalloop
+ %
+ \ifthenelse{\boolean{ct@ifinrule}}{\toks255=\expandafter{\the\toks255\midrule}}{}
+ \ct@Loop\fpRegGet{ct@Sum}{\ct@tempnum}
+ \toks255=\expandafter{\the\toks255\rowcolor{gray!15}&\bfseries##2 (}
+ \edef\ct@num{\noexpand\ct@labelreg)\noexpand\rule{\ctsep}{0pt}}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@num&\bfseries}
+ \edef\ct@num{\noexpand\numprint{\ct@tempnum}}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@num\\}
+ \setboolean{ct@ifinrule}{true}
+ \setboolean{ct@ifruleafteradd}{true}
+}
+%
+\newcommand\inrule{%
+ \ifthenelse{\boolean{ct@ifinrule}}{%
+ \toks255=\expandafter{\the\toks255\midrule}
+ }{
+ \PackageWarning{calctab}{\ct@inrulewarning}
+ }
+ \setboolean{ct@ifinrule}{false}
}%
%
+%
+%
+}{% calctab environment closing code
+ \begin{center}
+ \begin{lrbox}{\ct@TabBox}
+ \the\toks255\bottomrule
+ \end{tabular}
+ \end{lrbox}
+ \sffamily
+ \parbox{\wd\ct@TabBox}{
+ \ct@FirstPar\par\smallskip\par
+ \usebox{\ct@TabBox}}
+ \end{center}
+}
+%
+%
+%
+% xcalctab environment section definition
+%
+\newenvironment{xcalctab}[1][]{%
+%set font family
+\sffamily
+%
+% set the token register (TeX primitive command resolve the tabular grouping problem)
+\toks255={\rowcolors{1}{gray!15}{}%
+\begin{tabular}{cl*{3}{r}}\midrule&\ct@ctdescription &\ct@ctheaderone&\ct@ctheadertwo& \ct@ctcurrency \\\midrule}
+%
+% reset main counter to starting value
+\setcounter{ct@RowIndex}{0}
+%
+% save paragraph table header to use it in the environment end code
+\newcommand{\ct@FirstPar}[1]{#1}
+%
+% internal command definition
+%
+%
+%
+% from until keys internal command
+\newcommand{\ct@intervalloop}{%
+ \ifthenelse{\(\boolean{ct@fromctrl}\OR\boolean{ct@untilctrl}\)}{%
+ \ifthenelse{\boolean{ct@fromctrl}}{\setboolean{ct@fromctrl}{false}}{\def\ct@fromrow{1}}
+ \ifthenelse{\boolean{ct@untilctrl}}{\setboolean{ct@untilctrl}{false}}{\def\ct@untilrow{\thect@RowIndex}}
+ \ifthenelse{\number\ct@fromrow<\number\ct@untilrow}{% canonical interval from until
+ \ct@setintervalflag{\ct@fromrow}{\ct@untilrow}
+ }{% negative interval 1 -> until plus from -> last row
+ \ct@setintervalflag{1}{\ct@untilrow}
+ \ct@setintervalflag{\ct@fromrow}{\thect@RowIndex}
+ }
+ }{}% else clause denied
+}
+%
+% internal command to set true the flags row in an interval
+\newcommand{\ct@setintervalflag}[2]{%
+ % #1 arg -> start row value
+ % #2 arg -> finish row value
+ \setcounter{ct@i}{##1}
+ \whiledo{\not\(\value{ct@i}>\number##2\)}{%
+ \ifthenelse{\boolean{ctflag\thect@i}}{%
+ \PackageWarning{calctab}{\ct@overridingkeyerr{from or until}}
+ }{% else clause
+ \setboolean{ctflag\thect@i}{true}
+ }
+ \stepcounter{ct@i}
+ }
+}%
+%
+%
+%
+\newcommand\amount[4][]{%#1 ->opt #2->descr #3->qta #4->price
+ \stepcounter{ct@RowIndex}
+ \newboolean{ctflag\thect@RowIndex}%definition of bool flag for each row
+ \setboolean{ctflag\thect@RowIndex}{false}%initial value of ctflag<n>
+ \setkeys{ctfamId}{##1}%
+ % fp computation
+ \fpRegSet{ctRowValue\thect@RowIndex}{##3}% first number
+ \fpRegSet{ct@two}{##4}% second number
+ \fpRegMul{ctRowValue\thect@RowIndex}{ct@two}
+ \fpRegRound{ctRowValue\thect@RowIndex}{-2}
+ %
+ % now, we must control the ``rule'' case
+ \ifthenelse{\boolean{ct@ifinrule}}{
+ \ifthenelse{\boolean{ct@ifruleafteradd}}{%
+ \toks255=\expandafter{\the\toks255\midrule}
+ \setboolean{ct@ifruleafteradd}{false}
+ }{}
+ }{
+ \setboolean{ct@ifruleafteradd}{false}
+ }%
+ %
+ %
+ % append the tabular entry to the token register
+ \toks255=\expandafter{\the\toks255\AlphAlph{\value{ct@RowIndex}}&##2\rule{\ctsep}{0pt}&\numprint{##3}&\numprint{##4}&}
+ \fpRegGet{ctRowValue\thect@RowIndex}{\ct@tempnum}
+ \edef\ct@num{\noexpand\numprint{\ct@tempnum}}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@num\\}
+ % rule regolation
+ \setboolean{ct@ifinrule}{true}
+}%
+%
+%
+%
\newcommand\perc[3][]{%
\stepcounter{ct@RowIndex}% another new row
\newboolean{ctflag\thect@RowIndex}% definition of bool flag for each row
@@ -234,18 +509,29 @@
% 'from' and 'until' keys process
\ct@intervalloop
%
- \addtocounter{ct@RowIndex}{-1}\ctLoop\stepcounter{ct@RowIndex}
+ \addtocounter{ct@RowIndex}{-1}\ct@Loop\stepcounter{ct@RowIndex}
\fpDiv{\tempPerc}{##3}{100}%
\fpRegSet{tempreg}{\tempPerc}
- \fpRegMul{ctSum}{tempreg}
- \fpRegRound{ctSum}{-2}% approx to the second digit
- \fpRegGet{ctSum}{\atempnumber}
- \fpRegSet{ctRowValue\thect@RowIndex}{\atempnumber}
- \toks255=\expandafter{\the\toks255\Alph{ct@RowIndex}&##2 (\numprint{##3}\% \@@ctontraslation{} }
- \edef\ctnum{\noexpand\ctlabelreg)\noexpand\rule{\ctsep}{0pt}}
- \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ctnum&}
- \edef\ctnum{\noexpand\numprint{\atempnumber}}
- \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ctnum\\}
+ \fpRegMul{ct@Sum}{tempreg}
+ \fpRegRound{ct@Sum}{-2}% approx to the second digit
+ \fpRegGet{ct@Sum}{\ct@tempnum}
+ \fpRegSet{ctRowValue\thect@RowIndex}{\ct@tempnum}
+ %
+ \ifthenelse{\boolean{ct@ifinrule}}{%
+ \ifthenelse{\boolean{ct@ifruleafteradd}}{%
+ \toks255=\expandafter{\the\toks255\midrule}
+ \setboolean{ct@ifruleafteradd}{false}
+ }{}%
+ }{% else clause
+ \setboolean{ct@ifruleafteradd}{false}
+ }%
+ %
+ \toks255=\expandafter{\the\toks255\AlphAlph{\value{ct@RowIndex}}&##2 (\numprint{##3}\% \ct@ctontraslation{} }
+ \edef\ct@num{\noexpand\ct@labelreg)\noexpand\rule{\ctsep}{0pt}}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@num&&&}
+ \edef\ct@num{\noexpand\numprint{\ct@tempnum}}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@num\\}
+ \setboolean{ct@ifinrule}{true}
}
%
\newcommand\add[2][]{%
@@ -255,24 +541,40 @@
% 'from' and 'until' keys process
\ct@intervalloop
%
- \ctLoop\fpRegGet{ctSum}{\atempnumber}
- \toks255=\expandafter{\the\toks255\midrule\rowcolor{gray!15}&\bfseries##2 (}
- \edef\ctnum{\noexpand\ctlabelreg)\noexpand\rule{\ctsep}{0pt}}
- \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ctnum&\bfseries}
- \edef\ctnum{\noexpand\numprint{\atempnumber}}
- \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ctnum\\}
+ \ifthenelse{\boolean{ct@ifinrule}}{\toks255=\expandafter{\the\toks255\midrule}}{}
+ \ct@Loop\fpRegGet{ct@Sum}{\ct@tempnum}
+ \toks255=\expandafter{\the\toks255\rowcolor{gray!15}&\bfseries##2 (}
+ \edef\ct@num{\noexpand\ct@labelreg)}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@num&&&\bfseries}
+ \edef\ct@num{\noexpand\numprint{\ct@tempnum}}
+ \toks255=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks255\ct@num\\}
+ % rule case analisys flag setup
+ \setboolean{ct@ifinrule}{true}
+ \setboolean{ct@ifruleafteradd}{true}
+}
+%
+% this command remain internal!
+\newcommand\inrule{%
+ \ifthenelse{\boolean{ct@ifinrule}}{%
+ \toks255=\expandafter{\the\toks255\midrule}
+ }{
+ \PackageWarning{calctab}{\ct@inrulewarning}
+ }
+ \setboolean{ct@ifinrule}{false}
}%
%
+%
+%
}{% calctab environment closing code
\begin{center}
- \begin{lrbox}{\ctTabBox}
+ \begin{lrbox}{\ct@TabBox}
\the\toks255\bottomrule
\end{tabular}
\end{lrbox}
\sffamily
- \parbox{\wd\ctTabBox}{
+ \parbox{\wd\ct@TabBox}{
\ct@FirstPar\par\smallskip\par
- \usebox{\ctTabBox}}
+ \usebox{\ct@TabBox}}
\end{center}
}
%
@@ -280,12 +582,29 @@
% package warning and error macro definition part code
%
% the user has defined a key that not exist
-\newcommand{\ct@keynotexisterr}[1]{The key #1 not exist}
+\newcommand{\ct@keynotexisterr}[1]{The key '#1' not exist}
%
% in the id list command optional argument, a key is been specifed more then one time
-\newcommand{\ct@overridingkeyerr}[1]{The #1 key is just specifed in optional arg sequence.\MessageBreak
-Overriding ignored}
+\newcommand{\ct@overridingkeyerr}[1]{The '#1' key is just specifed in a previous optional arg sequence.\MessageBreak
+Overlap ignored}
+%
+\newcommand{\ct@notusefulwarning}[1]{The key '#1' is not influential on computation}
+\newcommand{\ct@inrulewarning}[1]{A rule cannot be draw at this point. Command ignored}
+%
+%
+%
+% Version 0.6 Changes history
+%
+% 0.6.1 - 2009_03_03 - New \inrule command to draw a rule among the table rows
+% 0.6.2 - 2009_03_03 - Fixed bug: the absense of a rule after an add row
+% 0.6.3 - 2009_03_05 - New xcalctab environment (extended environment with the 'quantity' and 'price' columns)
+% 0.6.4 - 2009_03_10 - New feature: automatic trunked of the description string (A+B+C+...) if it is long than more five items
+% 0.6.5 - 2009_03_10 - Substituted the standard LaTeX command \Alph with \AlphAlph by Oberdiek to eliminate the 26 rows limit
+% 0.6.6 - 2009_03_12 - New feature for \amount command: basic binary operation with two numbers thanks to xstring package
+%
+% 0.6.7 - 2009_03_xx - New command \calc for basic operation with two numbers.
+% 0.6.8 - 2009_03_xx - Minor internal adjustments
+%
%
-\newcommand{\ct@notusefulwarning}[1]{The key '#1' is non influential on calc}
%
-% end of file calctab.sty \ No newline at end of file
+% end of file calctab.sty