%%
%% This is file `coollist.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% coollist.dtx  (with options: `package')
%% 
%% This is a generated file
%% 
%% This file may be distributed and/or modified under the
%% conditions of the Limited General Product License
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{coollist}
 [2009/09/20 v1.4 COntent Oriented LaTeX Lists]
\RequirePackage{ifthen}
\RequirePackage{amsmath}
\RequirePackage{amssymb}
\RequirePackage{coolstr}
\RequirePackage{forloop}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
\newcounter{COOL@listlen}%
\newcommand{\COOL@listEnd}{@@@}%
\newcommand{\COOL@listStop}{@@}%
\newcommand{\setlistStop}[1]{\renewcommand{\COOL@listStop}{#1}}%
\newcommand{\setlistEnd}[1]{\renewcommand{\COOL@listEnd}{#1}}%
\newcounter{COOL@listpointer}%
\newboolean{COOL@found}%
\def\COOL@listgobble[#1]#2,#3,\COOL@listEnd{%
\ifthenelse{\equal{#3}{\COOL@listStop}}%
        {%
        \ifthenelse{\value{COOL@listpointer}=#1}%
                {%
                \setboolean{COOL@found}{true}%
                #2%
                }%
        % Else
                {%
                }%
        }%
        {%
        \ifthenelse{\value{COOL@listpointer}=#1}%
                {%
                \setboolean{COOL@found}{true}%
                #2%
                }%
        % Else
                {%
                }%
        \stepcounter{COOL@listpointer}%
        \COOL@listgobble[#1]#3,\COOL@listEnd%
        }%
}%
\newcommand{\listval}[2]{%
\ifthenelse{\equal{#1}{}}%
        {%
        \setcounter{COOL@listpointer}{0}%
        }%
        {%
        \setcounter{COOL@listpointer}{1}%
        \setboolean{COOL@found}{false}%
        \COOL@listgobble[#2]#1,\COOL@listStop,\COOL@listEnd%
        }%
}%
\def\COOL@liststore@gobbler[#1]#2,#3,\COOL@listEnd{%
\ifthenelse{\equal{#3}{\COOL@listStop}}%
        {%
        \expandafter\gdef\csname #1\roman{COOL@listpointer}\endcsname{#2}%
        }%
        {%
        \expandafter\gdef\csname #1\roman{COOL@listpointer}\endcsname{#2}%
        \stepcounter{COOL@listpointer}%
        \COOL@liststore@gobbler[#1]#3,\COOL@listEnd%
        }%
}
\newcommand{\liststore}[2]{%
\setcounter{COOL@listpointer}{1}%
\COOL@liststore@gobbler[#2]#1,\COOL@listStop,\COOL@listEnd%
\expandafter\xdef\csname #2length\endcsname{\arabic{COOL@listpointer}}%
}%
\newcommand{\listlen}[1]{%
\listval{#1}{0}%
\arabic{COOL@listpointer}
}%listlength
\newcommand{\listlenstore}[2]{%
\listval{#2}{0}%
\setcounter{#1}{\value{COOL@listpointer}}
}%listlength
\newcommand{\listcopy}[2]{%
\setcounter{COOL@listlen}{\csname #1length\endcsname}%
\forloop{COOL@listpointer}{1}{\NOT \value{COOL@listpointer} > \value{COOL@listlen}}%
        {%
        \expandafter\xdef\csname #2\roman{COOL@listpointer}\endcsname{\csname #1\roman{COOL@listpointer}\endcsname}%
        }%
\expandafter\xdef\csname #2length\endcsname{\csname #1length\endcsname}%
}
\newcounter{COOL@intsum}
\newcounter{COOL@register@ct}
\newcounter{COOL@register@len}
\newboolean{COOL@listsum@isint}
\newcommand{\listsum}[3][liststored=false]{%
\ifthenelse{ \equal{#1}{liststored=false} \OR \equal{#1}{storedlist=false} }%
        {%
        \liststore{#2}{COOL@listtosum@element@}%
        \listlenstore{COOL@listlen}{#2}%
        }%
{ \ifthenelse{ \equal{#1}{liststored=true} \OR \equal{#1}{storedlist=true} }%
        {%
        \listcopy{#2}{COOL@listtosum@element@}%
        \setcounter{COOL@listlen}{\COOL@listtosum@element@length}%
        }%
        {%
        \PackageError{cool}{Invalid listsum optional argument}%
                {optional argument may only be `storedlist=true', `liststored=true', `storedlist=false', or `liststored=false'}%
        }}%
\ifthenelse{ \value{COOL@listlen} < 1 }%
        {%
        \PackageWarning{cool}{List is empty}%
        \xdef#3{0}%
        }%
        {%
        \isint{\COOL@listtosum@element@i}{COOL@listsum@isint}%
        \ifthenelse{ \boolean{COOL@listsum@isint} }%
                {%
                \xdef\COOL@listsum@register@integers{\COOL@listtosum@element@i}%
                \setcounter{COOL@register@len}{0}%
                }%
                {%
                \gdef\COOL@listsum@register@integers{0}%
                \xdef\COOL@listsum@register@i{\COOL@listtosum@element@i}%
                \gdef\COOL@listsum@register@coef@i{1}%
                \setcounter{COOL@register@len}{1}%
                }%
        \forloop{COOL@listpointer}{2}{\NOT \value{COOL@listpointer} > \value{COOL@listlen}}%
                {%
                \xdef\COOL@listsum@element{\csname COOL@listtosum@element@\roman{COOL@listpointer}\endcsname}%
                \isint{\COOL@listsum@element}{COOL@listsum@isint}%
                \ifthenelse{ \boolean{COOL@listsum@isint} }%
                        {%
                        \setcounter{COOL@intsum}{\COOL@listsum@register@integers}%
                        \addtocounter{COOL@intsum}{\COOL@listsum@element}%
                        \xdef\COOL@listsum@register@integers{\arabic{COOL@intsum}}%
                        }%
                        {%
                        \setboolean{COOL@found}{false}%
                        \forloop{COOL@register@ct}{1}{\NOT \value{COOL@register@ct} > \value{COOL@register@len}}%
                                {%
                                \xdef\COOL@listsum@known@element{%
                                        \csname COOL@listsum@register@\roman{COOL@register@ct}\endcsname%
                                        }%
                                \ifthenelse{ \equal{\COOL@listsum@element}{\COOL@listsum@known@element} }%
                                        {%
                                        \xdef\COOL@listsum@known@element@coef{%
                                                \csname COOL@listsum@register@coef@\roman{COOL@register@ct}\endcsname%
                                                }%
                                        \setcounter{COOL@intsum}{\COOL@listsum@known@element@coef}%
                                        \addtocounter{COOL@intsum}{1}%
                                        \expandafter%
                                                \xdef\csname COOL@listsum@register@coef@\roman{COOL@register@ct}\endcsname%
                                                        {\arabic{COOL@intsum}}%
                                        \setboolean{COOL@found}{true}%
                                        }%
                                        {%
                                        }%
                                }%
                        \ifthenelse{ \boolean{COOL@found} }%
                                {}%
                                {%
                                \addtocounter{COOL@register@len}{1}%
                                \expandafter%
                                        \xdef\csname COOL@listsum@register@\roman{COOL@register@len}\endcsname%
                                                {\COOL@listsum@element}%
                                \expandafter%
                                        \xdef\csname COOL@listsum@register@coef@\roman{COOL@register@len}\endcsname{1}%
                                }%
                        }%
                }%
        \xdef\COOL@listsum@result{}%
        \ifthenelse{ \NOT \COOL@listsum@register@integers = 0 }%
                {
                \xdef\COOL@listsum@result{\COOL@listsum@result\COOL@listsum@register@integers}%
                \ifthenelse{ \NOT \value{COOL@register@len} = 0 }%
                        {%
                        \xdef\COOL@listsum@result{\COOL@listsum@result+}%
                        }{}%
                }{}%
        \forloop{COOL@register@ct}{1}{ \NOT \value{COOL@register@ct} > \value{COOL@register@len} }%
                {%
                \edef\COOL@listsum@curcoef{\csname COOL@listsum@register@coef@\roman{COOL@register@ct}\endcsname}%
                \ifthenelse{ \NOT \COOL@listsum@curcoef = 1}%
                        {%
                        \xdef\COOL@listsum@result{\COOL@listsum@result\COOL@listsum@curcoef}%
                        }{}%
                \xdef\COOL@listsum@result{\COOL@listsum@result\csname COOL@listsum@register@\roman{COOL@register@ct}\endcsname}%
                \ifthenelse{ \NOT \value{COOL@register@ct} = \value{COOL@register@len} }%
                        {%
                        \xdef\COOL@listsum@result{\COOL@listsum@result+}%
                        }{}%
                }%
        \xdef#3{\COOL@listsum@result}%
        }%
}
\endinput
%%
%% End of file `coollist.sty'.
