Debian Codegraph @

texmf-dist/source/latex/coollist/coollist.dtx

raw
1 % \iffalse
2 %
3 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
4 %<package>\ProvidesPackage{coollist}
5 %<package> [2023/05/03 v1.4 COntent Oriented LaTeX Lists]
6 %<package>\RequirePackage{ifthen}
7 %<package>\RequirePackage{amsmath}
8 %<package>\RequirePackage{amssymb}
9 %<package>\RequirePackage{coolstr}
10 %<package>\RequirePackage{forloop}
11 %
12 % Update on 2023/05/03 purely to clarify the license; no code changes.
13 % This package is released under the GNU LGPL.
14 %
15 %<*driver>
16 \documentclass{ltxdoc}
17 \usepackage{coollist}
18 \usepackage{url}
19 \usepackage{pdflscape}
20 \EnableCrossrefs
21 \CodelineIndex
22 \RecordChanges
23 \begin{document}
24 \DocInput{coollist.dtx}
25 \end{document}
26 %</driver>
27 % \fi
28 %
29 %
30 % \CheckSum{251}
31 %
32 %
33 %% \CharacterTable
34 %% {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
35 %% 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
36 %% Digits \0\1\2\3\4\5\6\7\8\9
37 %% Exclamation \! Double quote \" Hash (number) \#
38 %% Dollar \$ Percent \% Ampersand \&
39 %% Acute accent \' Left paren \( Right paren \)
40 %% Asterisk \* Plus \+ Comma \,
41 %% Minus \- Point \. Solidus \/
42 %% Colon \: Semicolon \; Less than \<
43 %% Equals \= Greater than \> Question mark \?
44 %% Commercial at \@ Left bracket \[ Backslash \\
45 %% Right bracket \] Circumflex \^ Underscore \_
46 %% Grave accent \` Left brace \{ Vertical bar \|
47 %% Right brace \} Tilde \~}
48 %
49 % \changes{v1.0}{2006/08/14}{Initial Release}
50 % \changes{v1.1}{2001/10/06}{Added documentation for commands in separate section.}
51 % \changes{v1.1}{2001/10/06}{Added test cases/examples}
52 %
53 % \GetFileInfo{coollist.sty}
54 %
55 % \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ ,\!,\(,\),\,}
56 % \DoNotIndex{\@ne,\expandafter}
57 % \DoNotIndex{\advance,\begingroup,\catcode,\closein}
58 % \DoNotIndex{\newcommand,\renewcommand,\providecommand}
59 % \DoNotIndex{\closeout,\day,\def,\edef,\gdef,\xdef,\let,\empty,\endgroup}
60 % \DoNotIndex{\newcounter,\providecounter,\addtocounter,\setcounter,\stepcounter,\value,\arabic}
61 % \DoNotIndex{\if,\fi,\ifthenelse,\else,\setboolean,\boolean,\newboolean,\provideboolean,\equal,\AND,\OR,\NOT,\whiledo}
62 % \DoNotIndex{\ifcase,\ifcat,\or,\else}
63 % \DoNotIndex{\par,\parbox,\mbox,\hbox,\begin,\end,\nabla,\partial}
64 % \DoNotIndex{\overline,\bar,\small,\tiny,\mathchoice,\scriptsize,\textrm,\texttt}
65 % \DoNotIndex{\alpha,\beta,\gamma,\epsilon,\varepsilon,\delta,\zeta,\eta,\theta,\vartheta,\iota,\kappa,\lambda,\mu,\nu}
66 % \DoNotIndex{\xi,\omicron,\pi,\varpi,\rho,\varrho,\sigma,\tau,\upsilon,\phi,\varphi,\chi,\psi,\omega}
67 % \DoNotIndex{\Delta,\Gamma,\Theta,\Lambda,\Xi,\Pi,\Sigma,\Phi,\Psi,\Omega}
68 % \DoNotIndex{\digamma,\lceil,\rceil,\lfloor,\rfloor,\left,\right,\inp,\inb,\inbr,\inap,\nop}
69 % \DoNotIndex{\sum,\prod,\int,\log,\ln,\exp,\sin,\cos,\tan,\csc,\sec,\cot,\arcsin,\arccos,\arctan,\det}
70 % \DoNotIndex{\sinh,\cosh,\tanh,\csch,\sech,\coth,\arcsinh,\arccosh,\arctanh}
71 % \DoNotIndex{\mod,\max,\min,\gcd,\lcm,\wp,\arg,\dots,\infty,}
72 % \DoNotIndex{\frac,\binom,\braket,\@@atop}
73 % \DoNotIndex{\cdot,\ldots,\tilde,\times,\dagger,\relax}
74 % \DoNotIndex{\mathbb,\roman,\bf,\mathord,\cal,\DeclareMathOperator,\PackageError,\PackageWarning}
75 % \DoNotIndex{\csname,\endcsname,\ifx,\ifnum}
76 % \DoNotIndex{\COOL@Hypergeometric@pq,\COOL@Hypergeometric@pq@ab@value,\hideOnSF,\COOL@decide@paren}
77 % \DoNotIndex{\COOL@decide@indicies}
78 % \DoNotIndex{\mod,\bmod,\pmod,\pod,\operatorname}
79 % \DoNotIndex{\forLoop,\forloop}
80 % \DoNotIndex{\listval,\liststore,\isint,\isnumeric}
81 % \DoNotIndex{
82 % \COOL@list@temp@i,
83 % \COOL@list@temp@ii,
84 % \COOL@list@temp@iii}
85 %
86 % \title{The \textsf{coollist} package\thanks{This document
87 % corresponds to \textsf{coollist}~\fileversion,
88 % dated~\filedate.}}
89 % \author{nsetzer}
90 %
91 % \maketitle
92 %
93 % \setcounter{IndexColumns}{2}
94 % \StopEventually{\PrintChanges\PrintIndex}
95 %
96 % The \textsf{coollist} package is a ``sub" package of the \textsf{cool} package that seemed appropriate to publish
97 % independently since it may occur that one wishes to include the ability to manipulate lists without having to accept
98 % all the overhead of the \textsf{cool} package itself.
99 %
100 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 %\section{Basics}
103 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 %
106 % Lists are defined as a sequence of tokens separated by a comma. The \textsf{coollist} package allows the user
107 % to access certain elements of the list while neglecting others---essentially turning lists into a sort of
108 % array.
109 %
110 % List elements are accessed by specifying the position of the object within the list (the index of the item) and
111 % all lists start indexing at |1|.
112 %
113 %
114 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 %\section{Commands \& Descriptions}
117 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 %
120 % \DescribeMacro{\setlistStop}
121 % \DescribeMacro{\setlistEnd}
122 % |\setlistStop|\marg{string} and |\setlistEnd|\marg{string} allow the user to set the end of a list
123 % `character' in the rare event that the default values actually appear in the list.
124 % |listStop| is used to identify when the list actually terminates, while |listEnd| forces the reading macro to
125 % take in the entire list (without both entities, errors would occur if macros were included in the list).
126 %
127 % The default values are
128 %
129 % \begin{tabular}{ll}
130 % |listStop| & \makeatletter |@@| \makeatother \\
131 % |listEnd| & \makeatletter |@@@| \makeatother
132 % \end{tabular}
133 %
134 %
135 %
136 % \DescribeMacro{\listval}
137 % |\listval|\marg{list}\marg{index} returns the \meta{index} item of the comma delimited list \meta{list}
138 % or nothing if \meta{index} is outside the number of elements of the list.
139 % The first element of the list has index $1$.
140 %
141 %
142 %
143 % \DescribeMacro{\liststore}
144 % |\liststore|\marg{list}\marg{macro\_base\_name} stores the elements of comma delimited list \meta{list}
145 % in a set of macros having the first part of \meta{macro\_base\_name} and ending with the roman numermal
146 % index of the list.
147 %
148 % For example, |\liststore{1,2,3}{list}| would define |\listi|, |\listii|, and |\listiii| each
149 % holding |1|, |2|, |3|, respectively.
150 %
151 %
152 %
153 % \DescribeMacro{\listlen}
154 % |\listlen|\marg{list} returns the length of the comma delimited list \meta{list}, though it is not useful for
155 % storing this length.
156 % If you need to record the list's length for later use, it is better to use the function |\listlenstore|.
157 %
158 %
159 %
160 % \DescribeMacro{\listlenstore}
161 % |\listlenstore|\marg{counter}\marg{list} stores the length of the comma delimited list \meta{list} is the counter
162 % \meta{counter}.
163 %
164 %
165 %
166 % \DescribeMacro{\listcopy}
167 % |\listcopy|\marg{listtocopy}\marg{listcopybase} stores the elements of \meta{listtocopy} into the list
168 % \meta{listtocopybase}.
169 %
170 %
171 %
172 % \DescribeMacro{\listsum}
173 % |\listsum|\oarg{storedlist}\marg{list}\marg{macro} stores the sum of the comma delimited list \meta{list}
174 % (if \meta{storedlist} is |storedlist=false| or |liststored=false|) or the sum of the stored list with base name \meta{list}
175 % (if \meta{storedlist} is |storedlist=true| or |liststored=true|) in the macro \meta{macro}.
176 % Integers are recognized and summed accordingly. All other tokens are summed as variables with some
177 % integer coefficient as the end result.
178 %
179 %
180 %
181 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 %\section{Test Cases}
184 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 %
187 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
189 %\subsection{\texttt{$\backslash$listval}}
190 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
191 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 %
193 % \DescribeMacro{\listval}
194 %
195 % \begin{tabular}{ll}
196 % |\listval{1,2,3,4}{0}| & \listval{1,2,3,4}{0} (the null string) \\
197 % |$\listval{\alpha,\beta,\gamma}{2}$| & $\listval{\alpha,\beta,\gamma}{2}$ \\
198 % |\listval{a,b,c}{4}| & \listval{a,b,c}{4} (the null string)
199 % \end{tabular}
200 %
201 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
203 %\subsection{\texttt{$\backslash$liststore}}
204 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
205 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 %
207 % \DescribeMacro{\liststore}
208 %
209 % \begin{tabular}{ll}
210 % |\liststore{1,2,3,4}{temp}|
211 % \\
212 % |\tempi;\tempii;\tempiii;\tempiv| & \liststore{1,2,3,4}{temp} \tempi;\tempii;\tempiii;\tempiv
213 % \\[1cm]
214 % |\liststore{a_1,a_2,a_3,a_4}{temp}|
215 % \\
216 % |$\tempi;\tempii;\tempiii;\tempiv$| & \liststore{a_1,a_2,a_3,a_4}{temp} $\tempi;\tempii;\tempiii;\tempiv$
217 % \\[1cm]
218 % |\liststore{a,b}{temp}|
219 % \\
220 % |\tempi;\tempii| & \liststore{a,b,c}{temp} \tempi;\tempii
221 % \end{tabular}
222 %
223 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
225 %\subsection{\texttt{$\backslash$listlen}}
226 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
227 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 %
229 % \DescribeMacro{\listlen}
230 %
231 % \begin{tabular}{ll}
232 % |\listlen{1,2,3,4,5}| & \listlen{1,2,3,4,5} \\
233 % |\listlen{}| & \listlen{} \\
234 % |\listlen{1,2}| & \listlen{1,2} \\
235 % |\listlen{1}| & \listlen{1}
236 % \end{tabular}
237 %
238 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
240 %\subsection{\texttt{$\backslash$listlenstore}}
241 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
242 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 %
244 % \DescribeMacro{\listlen}
245 % |\newcounter{thelistlength}| \newcounter{thelistlength}
246 %
247 % \begin{tabular}{ll}
248 % |\listlenstore{thelistlength}{1,2,3,4,5}|
249 % \\
250 % |\arabic{thelistlength}| & \listlenstore{thelistlength}{1,2,3,4,5} \arabic{thelistlength}
251 % \\[1cm]
252 % |\listlenstore{thelistlength}{}|
253 % \\
254 % |\arabic{thelistlength}| & \listlenstore{thelistlength}{} \arabic{thelistlength}
255 % \\[1cm]
256 % \end{tabular}
257 %
258 %
259 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
261 %\subsection{\texttt{$\backslash$listcopy}}
262 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
263 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 %
265 % \DescribeMacro{\listcopy} copy elements of a list
266 %
267 % \begin{tabular}{ll}
268 % |\liststore{1,2,3}{temp}| \\
269 % |\listcopy{temp}{copiedlist}| \\
270 % |\copiedlisti;\copiedlistii;\copiedlistiii| &
271 % \liststore{1,2,3}{temp}\listcopy{temp}{copiedlist}\copiedlisti;\copiedlistii;\copiedlistiii
272 % \end{tabular}
273 %
274 %
275 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
277 %\subsection{\texttt{$\backslash$listsum}}
278 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
279 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 %
281 % \DescribeMacro{\listsum} Summing elements of lists
282 %
283 % \begin{tabular}{ll}
284 % |\listsum{1,2,3,4,5}{\thelistsum}| \\
285 % |\thelistsum| & \listsum{1,2,3,4,5}{\thelistsum}\thelistsum \\[1cm]
286 % |\listsum{1,2,3,a,b,a,a}{\thelistsum}| \\
287 % |\thelistsum| & \listsum{1,2,3,a,b,a,a}{\thelistsum}\thelistsum \\[1cm]
288 % |\liststore{1,2,3,5,j,k,j}{temp}| \\
289 % |\listsum[liststored=true]{temp}{\thelistsum}| \\
290 % |\thelistsum| &
291 % \liststore{1,2,3,5,j,k,j}{temp}\listsum[liststored=true]{temp}{\thelistsum}\thelistsum \\[1cm]
292 % |\listsum{a,b,c,d}{\thelistsum}| \\
293 % |\thelistsum| & \listsum{a,b,c,d}{\thelistsum}\thelistsum
294 % \end{tabular}
295 %
296 %
297 % \begin{landscape}
298 %
299 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 %\section{Implementation}
302 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 %
305 % This is just an internal counter for dealing with the lists, most often used for the length of the list.
306 %
307 % \begin{macrocode}
308 \newcounter{COOL@listlen}%
309 % \end{macrocode}
310 %
311 %
312 % \begin{macro}{\setlistEnd}
313 % \begin{macro}{\setlistStop}
314 %
315 % |\setlistStop{|\meta{string}|}| and |\setlistEnd{|\meta{string}|}| allow the user to set the end of a list `character's
316 % in the rare event that the default values actually appear in the list.
317 % Both of these entities are required to properly deliminate the list and avoid errors when macros are included in the list. The default values are
318 %
319 % \begin{macrocode}
320 \newcommand{\COOL@listEnd}{@@@}%
321 \newcommand{\COOL@listStop}{@@}%
322 % \end{macrocode}
323 %
324 % and they may be changed by the following commands (which utilize the |\renewcommand|):
325 %
326 % \begin{macrocode}
327 \newcommand{\setlistStop}[1]{\renewcommand{\COOL@listStop}{#1}}%
328 \newcommand{\setlistEnd}[1]{\renewcommand{\COOL@listEnd}{#1}}%
329 % \end{macrocode}
330 %
331 % \end{macro}
332 % \end{macro}
333 %
334 %
335 % This area defines the core technology behind the \textsf{coollist} package: the list ``gobbler".
336 % To properly eat a list a counter and a boolean need to be used. |listpointer| acts just like the name
337 % implies, as the current ``position" of the list. |found| indicates that the position has been found
338 %
339 % \begin{macrocode}
340 \newcounter{COOL@listpointer}%
341 \newboolean{COOL@found}%
342 % \end{macrocode}
343 %
344 % Now we come to ``the gobbler"---a recursive function that eats up a list and gives back the appropriate item.
345 % This must be done in \TeX{} primatives.
346 %
347 % The idea behind this is that ``the gobbler" eats up everything before the desired item and everything
348 % after the desired item.
349 %
350 % \begin{macrocode}
351 \def\COOL@listgobble[#1]#2,#3,\COOL@listEnd{%
352 \ifthenelse{\equal{#3}{\COOL@listStop}}%
353 {%
354 % \end{macrocode}
355 %
356 % we have reached the end of the list, just need to check if we need to output something
357 %
358 % \begin{macrocode}
359 \ifthenelse{\value{COOL@listpointer}=#1}%
360 {%
361 \setboolean{COOL@found}{true}%
362 #2%
363 }%
364 % Else
365 {%
366 }%
367 }%
368 % Else
369 {%
370 \ifthenelse{\value{COOL@listpointer}=#1}%
371 {%
372 \setboolean{COOL@found}{true}%
373 #2%
374 }%
375 % Else
376 {%
377 }%
378 \stepcounter{COOL@listpointer}%
379 % \end{macrocode}
380 %
381 % We must eat up the whole list no matter what or else the stuff beyond |#1| will be displayed. so we need
382 % to call ``the gobbler" again.
383 %
384 % \begin{macrocode}
385 \COOL@listgobble[#1]#3,\COOL@listEnd%
386 }%
387 }%
388 % \end{macrocode}
389 %
390 %
391 %
392 %
393 % \begin{macro}{\listval}
394 % \changes{v1.1}{2007/10/06}{alter behavior to do nothing for empty lists}
395 %
396 % |\listval|\marg{comma\_deliminated\_list}\marg{index}
397 %
398 % gives the \meta{index} value of \meta{comma\_deliminated\_list}---as in
399 %
400 % |\listval{1,2,3,4,5,6}{3}| = \listval{1,2,3,4,5,6}{3}
401 %
402 % |$\listval{\alpha,\beta,\gamma}{2}$| = $\listval{\alpha,\beta,\gamma}{2}$
403 %
404 % \begin{macrocode}
405 \newcommand{\listval}[2]{%
406 % \end{macrocode}
407 %
408 % check to see if the submitted list is empty. if it is, do nothing
409 %
410 % \begin{macrocode}
411 \ifthenelse{\equal{#1}{}}%
412 {%
413 % \end{macrocode}
414 %
415 % set the listpointer to zero because the list has no length
416 % \begin{macrocode}
417 \setcounter{COOL@listpointer}{0}%
418 }%
419 % \end{macrocode}
420 %
421 % Else
422 %
423 % \begin{macrocode}
424 {%
425 % \end{macrocode}
426 %
427 % start at the beginning of the list, so initialize |listpointer|
428 %
429 % \begin{macrocode}
430 \setcounter{COOL@listpointer}{1}%
431 % \end{macrocode}
432 %
433 % Assume that the target will not be found---it will be set to true by ``the gobbler" if it is
434 %
435 % \begin{macrocode}
436 \setboolean{COOL@found}{false}%
437 % \end{macrocode}
438 %
439 % Now call the gobbler---since the user shouldn't be forced to submit the end character (in fact
440 % he or she shouldn't even need to worry that an end character exists nor what it is), we add it
441 % on along with the `optional' parameter that tells us which element to retreive. To ensure that
442 % the entire list is read in by |\COOL@listgobbler| we need the list stop `character' too.
443 %
444 % \begin{macrocode}
445 \COOL@listgobble[#2]#1,\COOL@listStop,\COOL@listEnd%
446 }%
447 }%
448 % \end{macrocode}
449 %
450 % \end{macro}
451 %
452 %
453 %
454 % \begin{macro}{\liststore}
455 % \changes{v1.3}{2007/10/14}{added code to store the length of the list}
456 % \begin{macro}{\COOL@liststore@gobbler}
457 % The list may be stored in a macro of the user's choosing with the function. The syntax is
458 %
459 % |\liststore|\marg{csv\_list}\marg{macro\_base\_name}
460 %
461 % and the resulting list elements are stored in
462 %
463 % \meta{macro\_base\_name}\meta{list\_index\_roman}
464 %
465 % where \meta{list\_index\_roman} is the list index in roman numerals.
466 %
467 % Some examples will clarify:
468 %
469 % |\liststore{1,2,3,4}{temp}| \liststore{1,2,3,4}{temp}
470 %
471 % \noindent |\tempi;\tempii;\tempiii;\tempiv| yields \tempi;\tempii;\tempiii;\tempiv
472 %
473 %
474 % \noindent |\liststore{a_1,a_2,a_3,a_4}{temp}| \liststore{a_1,a_2,a_3,a_4}{temp}
475 %
476 % \noindent |\tempi;\tempii;\tempiii;\tempiv| yields $\tempi;\tempii;\tempiii;\tempiv$
477 % \begin{macrocode}
478 \def\COOL@liststore@gobbler[#1]#2,#3,\COOL@listEnd{%
479 \ifthenelse{\equal{#3}{\COOL@listStop}}%
480 {%
481 \expandafter\gdef\csname #1\roman{COOL@listpointer}\endcsname{#2}%
482 }%
483 % Else
484 {%
485 \expandafter\gdef\csname #1\roman{COOL@listpointer}\endcsname{#2}%
486 \stepcounter{COOL@listpointer}%
487 \COOL@liststore@gobbler[#1]#3,\COOL@listEnd%
488 }%
489 }
490 \newcommand{\liststore}[2]{%
491 \setcounter{COOL@listpointer}{1}%
492 \COOL@liststore@gobbler[#2]#1,\COOL@listStop,\COOL@listEnd%
493 % \end{macrocode}
494 % Now store the length
495 % \begin{macrocode}
496 \expandafter\xdef\csname #2length\endcsname{\arabic{COOL@listpointer}}%
497 }%
498 % \end{macrocode}
499 % \end{macro}
500 % \end{macro}
501 %
502 %
503 %
504 %
505 %
506 % \begin{macro}{\listlen}
507 %
508 % This returns the length of the list, though it is not useful for storing this length. If you need to record the
509 % list's length for later use, it is better to use the next function |\listlenstore|.
510 %
511 % The format is |\listlen|\marg{comma deliminated list}. It works by recording
512 % the value of |listpointer| after it has complete traversed the list. Since indexing starts at |1|, it uses the
513 % index |0| which will never ever be an index of the list, so ``the gobbler" will not return any value.
514 %
515 % Example: |\listlen{1,2,3,4,5}| = \listlen{1,2,3,4,5}
516 %
517 % \begin{macrocode}
518 \newcommand{\listlen}[1]{%
519 \listval{#1}{0}%
520 \arabic{COOL@listpointer}
521 }%listlength
522 % \end{macrocode}
523 %
524 % \end{macro}
525 %
526 %
527 %
528 %
529 % \begin{macro}{\listlenstore}
530 %
531 % This store the length of the list. The format is |\listlenstore|\marg{counter}\marg{comma deliminated list}.
532 %
533 % \begin{macrocode}
534 \newcommand{\listlenstore}[2]{%
535 \listval{#2}{0}%
536 \setcounter{#1}{\value{COOL@listpointer}}
537 }%listlength
538 % \end{macrocode}
539 %
540 % \end{macro}
541 %
542 %
543 %
544 %
545 %
546 % \begin{macro}{\listcopy}
547 % \changes{v1.3}{2007/10/14}{added this function to the package}
548 %
549 % This copies one list into another element by element.
550 %
551 % \begin{macrocode}
552 \newcommand{\listcopy}[2]{%
553 % \end{macrocode}
554 % Store the length of the list to be copied
555 % \begin{macrocode}
556 \setcounter{COOL@listlen}{\csname #1length\endcsname}%
557 % \end{macrocode}
558 % go through each element of the list and copy it to the new list
559 % \begin{macrocode}
560 \forloop{COOL@listpointer}{1}{\NOT \value{COOL@listpointer} > \value{COOL@listlen}}%
561 {%
562 \expandafter\xdef\csname #2\roman{COOL@listpointer}\endcsname{\csname #1\roman{COOL@listpointer}\endcsname}%
563 }%
564 \expandafter\xdef\csname #2length\endcsname{\csname #1length\endcsname}%
565 }
566 % \end{macrocode}
567 %
568 % \end{macro}
569 %
570 %
571 %
572 %
573 % \begin{macro}{\listsum}
574 % \changes{v1.2}{2007/10/10}{added this function to the package}
575 % \changes{v1.3}{2007/10/14}{altered function to take optional argument for summing stored lists}
576 % \changes{v1.4}{2009/09/20}{corrected optional argument to accept both `storedlist' and `liststored' due to original error in error message}
577 % Sum the contents of the list. Integers are recognized and summed, tokens are treated as independent variables.
578 % The function returns a string of the sum
579 %
580 % Counter for the coefficients
581 % \begin{macrocode}
582 \newcounter{COOL@intsum}
583 % \end{macrocode}
584 % Counter for the register index
585 % \begin{macrocode}
586 \newcounter{COOL@register@ct}
587 \newcounter{COOL@register@len}
588 % \end{macrocode}
589 % boolean for identifying integers
590 % \begin{macrocode}
591 \newboolean{COOL@listsum@isint}
592 % \end{macrocode}
593 %
594 % Now the function
595 %
596 % \begin{macrocode}
597 \newcommand{\listsum}[3][liststored=false]{%
598 % \end{macrocode}
599 % Check to see if the list is already stored. If it is, copy it; otherwise store it
600 % \begin{macrocode}
601 \ifthenelse{ \equal{#1}{liststored=false} \OR \equal{#1}{storedlist=false} }%
602 {%
603 % \end{macrocode}
604 % First store the entire list
605 % \begin{macrocode}
606 \liststore{#2}{COOL@listtosum@element@}%
607 % \end{macrocode}
608 % store the length of the list
609 % \begin{macrocode}
610 \listlenstore{COOL@listlen}{#2}%
611 }%
612 % \end{macrocode}
613 % ElseIf
614 % \begin{macrocode}
615 { \ifthenelse{ \equal{#1}{liststored=true} \OR \equal{#1}{storedlist=true} }%
616 {%
617 \listcopy{#2}{COOL@listtosum@element@}%
618 \setcounter{COOL@listlen}{\COOL@listtosum@element@length}%
619 }%
620 % \end{macrocode}
621 % Else
622 % \begin{macrocode}
623 {%
624 \PackageError{cool}{Invalid listsum optional argument}%
625 {optional argument may only be `storedlist=true', `liststored=true', `storedlist=false', or `liststored=false'}%
626 }}%
627 % \end{macrocode}
628 % check for the list having a non-zero length
629 % \begin{macrocode}
630 \ifthenelse{ \value{COOL@listlen} < 1 }%
631 {%
632 \PackageWarning{cool}{List is empty}%
633 \xdef#3{0}%
634 }%
635 % \end{macrocode}
636 % Else
637 % \begin{macrocode}
638 {%
639 % \end{macrocode}
640 % put the first list element into the register
641 % \begin{macrocode}
642 \isint{\COOL@listtosum@element@i}{COOL@listsum@isint}%
643 \ifthenelse{ \boolean{COOL@listsum@isint} }%
644 {%
645 \xdef\COOL@listsum@register@integers{\COOL@listtosum@element@i}%
646 \setcounter{COOL@register@len}{0}%
647 }%
648 % \end{macrocode}
649 % Else
650 % \begin{macrocode}
651 {%
652 % \end{macrocode}
653 % Initialize the integers register to zero; store the character and its coefficient
654 % \begin{macrocode}
655 \gdef\COOL@listsum@register@integers{0}%
656 \xdef\COOL@listsum@register@i{\COOL@listtosum@element@i}%
657 \gdef\COOL@listsum@register@coef@i{1}%
658 \setcounter{COOL@register@len}{1}%
659 }%
660 % \end{macrocode}
661 % Now go through each additional element making an index of the symbols and summing identical ones
662 % \begin{macrocode}
663 \forloop{COOL@listpointer}{2}{\NOT \value{COOL@listpointer} > \value{COOL@listlen}}%
664 {%
665 % \end{macrocode}
666 % Expand the element to a convenient storage macro
667 % \begin{macrocode}
668 \xdef\COOL@listsum@element{\csname COOL@listtosum@element@\roman{COOL@listpointer}\endcsname}%
669 % \end{macrocode}
670 % Check if this element is an integer
671 % \begin{macrocode}
672 \isint{\COOL@listsum@element}{COOL@listsum@isint}%
673 \ifthenelse{ \boolean{COOL@listsum@isint} }%
674 {%
675 % \end{macrocode}
676 % Grab the current value of the integers and store it in the register counter
677 % \begin{macrocode}
678 \setcounter{COOL@intsum}{\COOL@listsum@register@integers}%
679 \addtocounter{COOL@intsum}{\COOL@listsum@element}%
680 \xdef\COOL@listsum@register@integers{\arabic{COOL@intsum}}%
681 }%
682 % \end{macrocode}
683 % Else, it's not an integer so search to see if it matches known elements
684 % \begin{macrocode}
685 {%
686 \setboolean{COOL@found}{false}%
687 \forloop{COOL@register@ct}{1}{\NOT \value{COOL@register@ct} > \value{COOL@register@len}}%
688 {%
689 \xdef\COOL@listsum@known@element{%
690 \csname COOL@listsum@register@\roman{COOL@register@ct}\endcsname%
691 }%
692 \ifthenelse{ \equal{\COOL@listsum@element}{\COOL@listsum@known@element} }%
693 {%
694 % \end{macrocode}
695 % found the element so increment the coefficient
696 % (grab coefficient, store in ct, increment ct, store new ct)
697 % \begin{macrocode}
698 \xdef\COOL@listsum@known@element@coef{%
699 \csname COOL@listsum@register@coef@\roman{COOL@register@ct}\endcsname%
700 }%
701 \setcounter{COOL@intsum}{\COOL@listsum@known@element@coef}%
702 \addtocounter{COOL@intsum}{1}%
703 \expandafter%
704 \xdef\csname COOL@listsum@register@coef@\roman{COOL@register@ct}\endcsname%
705 {\arabic{COOL@intsum}}%
706 % \end{macrocode}
707 % flag the element as found and set the counter to the length of the register $+1$
708 % \begin{macrocode}
709 \setboolean{COOL@found}{true}%
710 }%
711 % \end{macrocode}
712 % Else do nothing
713 % \begin{macrocode}
714 {%
715 }%
716 }%
717 % \end{macrocode}
718 % Check to see if the element is a known element. If not, add it to the register
719 % \begin{macrocode}
720 \ifthenelse{ \boolean{COOL@found} }%
721 {}%
722 % \end{macrocode}
723 % Else
724 % \begin{macrocode}
725 {%
726 \addtocounter{COOL@register@len}{1}%
727 \expandafter%
728 \xdef\csname COOL@listsum@register@\roman{COOL@register@len}\endcsname%
729 {\COOL@listsum@element}%
730 \expandafter%
731 \xdef\csname COOL@listsum@register@coef@\roman{COOL@register@len}\endcsname{1}%
732 }%
733 }%
734 }%
735 % \end{macrocode}
736 % Finally, create and store the sum
737 % \begin{macrocode}
738 \xdef\COOL@listsum@result{}%
739 \ifthenelse{ \NOT \COOL@listsum@register@integers = 0 }%
740 {
741 \xdef\COOL@listsum@result{\COOL@listsum@result\COOL@listsum@register@integers}%
742 \ifthenelse{ \NOT \value{COOL@register@len} = 0 }%
743 {%
744 \xdef\COOL@listsum@result{\COOL@listsum@result+}%
745 }{}%
746 }{}%
747 \forloop{COOL@register@ct}{1}{ \NOT \value{COOL@register@ct} > \value{COOL@register@len} }%
748 {%
749 \edef\COOL@listsum@curcoef{\csname COOL@listsum@register@coef@\roman{COOL@register@ct}\endcsname}%
750 \ifthenelse{ \NOT \COOL@listsum@curcoef = 1}%
751 {%
752 \xdef\COOL@listsum@result{\COOL@listsum@result\COOL@listsum@curcoef}%
753 }{}%
754 \xdef\COOL@listsum@result{\COOL@listsum@result\csname COOL@listsum@register@\roman{COOL@register@ct}\endcsname}%
755 \ifthenelse{ \NOT \value{COOL@register@ct} = \value{COOL@register@len} }%
756 {%
757 \xdef\COOL@listsum@result{\COOL@listsum@result+}%
758 }{}%
759 }%
760 \xdef#3{\COOL@listsum@result}%
761 }%
762 }
763 % \end{macrocode}
764 %
765 % \end{macro}
766 %
767 %
768 % \end{landscape}
769 %
770 %
771 % \Finale
772 \endinput