summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/calctab
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-02-26 00:50:17 +0000
committerKarl Berry <karl@freefriends.org>2009-02-26 00:50:17 +0000
commit951ab8ce2fe8420509db19af0937bdddb314b1de (patch)
tree7a1a1901bfe72b8aa0655b5e0d07e98cb1d9e801 /Master/texmf-dist/tex/latex/calctab
parentddbbbe630665e57743e59ca5df71b2d054bd5d81 (diff)
new latex package calctab (24feb09)
git-svn-id: svn://tug.org/texlive/trunk@12235 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/calctab')
-rw-r--r--Master/texmf-dist/tex/latex/calctab/calctab.sty291
1 files changed, 291 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/calctab/calctab.sty b/Master/texmf-dist/tex/latex/calctab/calctab.sty
new file mode 100644
index 00000000000..229ce5cd65f
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/calctab/calctab.sty
@@ -0,0 +1,291 @@
+%% calctab.sty
+%% 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 (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.
+%
+% 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.
+%
+% 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.
+%
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{calctab}[2009/02/20 v0.5 Autocalc table environment]
+%
+% ''library'' package for the table's visual property
+\RequirePackage{booktabs}
+\RequirePackage{eurosym}
+\RequirePackage[table]{xcolor}
+\RequirePackage{numprint}
+%
+% ''library'' package for algorithms and language implementation
+\RequirePackage{xkeyval}
+\RequirePackage{ifthen}
+\RequirePackage{fltpoint}
+%
+% length to tuning distance of central column of calctab table
+% 8 mm is the default value
+\newlength{\ctsep}\setlength{\ctsep}{0.8cm}
+%
+% main row counter of the table
+\newcounter{ct@RowIndex}
+%
+% loop simple counter
+\newcounter{ct@i}
+%
+% macrokey definition command
+\newcommand{\makemacrokey}[1]{\expandafter\def\csname #1\endcsname##1{%
+ \expandafter\def\csname @@#1\endcsname{##1}}}
+%
+% apparence command definition and default assignment
+\makemacrokey{ctcurrency}\ctcurrency{\euro}
+\makemacrokey{ctdescription}\ctdescription{Items description}
+\makemacrokey{ctontraslation}\ctontraslation{on}
+%
+% new boolean to control numeric loop, if ctGlobflag is true sum all row values
+\newboolean{ctGlobflag}\setboolean{ctGlobflag}{true}
+%
+% 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
+%
+%
+\define@key{ctfamId}{id}{%
+ % save in ctreg@<idname> its row number
+ \expandafter\edef\csname ctreg@#1\endcsname{\thect@RowIndex}
+ % definition of the key <idvalue>, the id argument #1
+ \define@key{ctfamLabel}{#1}[]{
+ % activate ctflag<n>
+ \ifthenelse{\boolean{ctflag\csname ctreg@#1\endcsname}}{
+ %ops, overriding of keys condition
+ \PackageWarning{calctab}{\ct@overridingkeyerr{#1}}
+ }{%
+ \setboolean{ctflag\csname ctreg@#1\endcsname}{true}
+ }
+ % global flag is false if a key is specifed
+ \setboolean{ctGlobflag}{false}
+ }%
+}%
+%
+% the id key for \add command
+\define@key{ctfamAddid}{id}{%
+ \ifthenelse{\boolean{ctGlobflag}}{%
+ \expandafter\edef\csname ctref@#1\endcsname{\thect@RowIndex}
+ \define@key{ctfamLabel}{#1}[]{% set all row flag on true
+ \setcounter{ct@i}{1}
+ \whiledo{\not\(\value{ct@i}>\expandafter\number\csname ctref@#1\endcsname\)}{
+ \ifthenelse{\boolean{ctflag\thect@i}}{
+ \PackageWarning{calctab}{\ct@overridingkeyerr{#1}}
+ }{
+ \setboolean{ctflag\thect@i}{true}
+ }
+ \stepcounter{ct@i}
+ }% end whiledo
+ \setboolean{ctGlobflag}{false}
+ }
+ }{% else clause
+ \expandafter\edef\csname ctref@#1\endcsname{\ctref@temp}
+ \define@key{ctfamLabel}{#1}[]{% repeat the original id list
+ \edef\n@xt{\noexpand\setkeys{ctfamLabel}[id]{\csname ctref@#1\endcsname}}
+ \n@xt
+ }
+ }
+}
+%
+% definition of ``interval'' keys
+\define@key{ctfamLabel}{from}{%
+ \@ifundefined{ctreg@#1}
+ {\PackageError{calctab}{\ct@keynotexisterr{#1}}}
+ {%
+ \def\ct@fromrow{\csname ctreg@#1\endcsname}
+ \ifthenelse{\ct@fromrow=1}{\PackageWarning{calctab}{\ct@notusefulwarning{from}}}{}
+ \setboolean{ct@fromctrl}{true}
+ \setboolean{ctGlobflag}{false}
+ }
+}
+%
+\define@key{ctfamLabel}{until}{%
+ \@ifundefined{ctreg@#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}
+ }
+}
+%
+% table box allocation
+\newsavebox{\ctTabBox}
+%
+% set standard decimal position
+\nprounddigits{2}
+%
+%
+% main environment: definition
+%
+\newenvironment{calctab}[1][]{%
+%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}
+%
+% 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
+\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
+ }{}
+}
+%
+% 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}}
+ }{
+ \setboolean{ctflag\thect@i}{true}
+ }
+ \stepcounter{ct@i}
+ }
+}
+%
+\newcommand\amount[3][]{%
+ \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}\\}
+}%
+%
+\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}\ctLoop\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\\}
+}
+%
+\newcommand\add[2][]{%
+ \def\ctref@temp{##1}% save id list
+ \setkeys*{ctfamLabel}{##1}
+ \setrmkeys{ctfamAddid}
+ % '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\\}
+}%
+%
+}{% calctab environment closing code
+ \begin{center}
+ \begin{lrbox}{\ctTabBox}
+ \the\toks255\bottomrule
+ \end{tabular}
+ \end{lrbox}
+ \sffamily
+ \parbox{\wd\ctTabBox}{
+ \ct@FirstPar\par\smallskip\par
+ \usebox{\ctTabBox}}
+ \end{center}
+}
+%
+%
+% 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}
+%
+% 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@notusefulwarning}[1]{The key '#1' is non influential on calc}
+%
+% end of file calctab.sty \ No newline at end of file