Debian Codegraph @

texmf-dist/doc/latex/commalists-tools/commalists-tools-doc.tex

raw
1 % !TeX TXS-program:compile = txs:///arara
2 % arara: pdflatex: {shell: no, synctex: no, interaction: batchmode}
3 % arara: pdflatex: {shell: no, synctex: no, interaction: batchmode}
4
5 \documentclass[11pt,a4paper]{ltxdoc}
6 \usepackage{bera}
7 \usepackage{inconsolata}
8 \usepackage[T1]{fontenc}
9 \usepackage[scale=0.875]{cabin}
10 \usepackage{commalists-tools}
11 \usepackage{fancyvrb}
12 \usepackage{fancyhdr}
13 \usepackage{tabularray}
14 \usepackage{fontawesome5}
15 \fancyhf{}
16 \renewcommand{\headrulewidth}{0pt}
17 \lfoot{\sffamily\small [commalists-tools]}
18 \cfoot{\sffamily\small - \thepage{} -}
19 \rfoot{\hyperlink{matoc}{\small\faArrowAltCircleUp[regular]}}
20 \usepackage{hologo}
21 \providecommand\tikzlogo{Ti\textit{k}Z}
22 \providecommand\TeXLive{\TeX{}Live\xspace}
23 \let\TikZ\tikzlogo
24
25 \usepackage{hyperref}
26 \urlstyle{same}
27 \hypersetup{pdfborder=0 0 0}
28 \usepackage[margin=2cm]{geometry}
29 \setlength{\parindent}{0pt}
30 \def\TPversion{0.20b}
31 \def\TPdate{24/03/2026}
32 \usepackage{tcolorbox}
33 \usepackage{pgffor}
34 \tcbuselibrary{breakable,skins,hooks,listingsutf8}
35 %\usepackage{soul}
36 %\sethlcolor{lightgray!25}
37
38 \lstset{
39 language=[LaTeX]TeX,%
40 basicstyle=\ttfamily,%
41 keywordstyle={\color{blue}},%
42 classoffset=0,%
43 keywords={},%
44 alsoletter={-},%
45 keywordstyle={\color{blue}},%
46 classoffset=1,%
47 alsoletter={-},%
48 morekeywords={commalists-tools},%
49 keywordstyle={\color{violet}},%
50 classoffset=2,%
51 alsoletter={-},%
52 morekeywords={\sortasclist,\sortdeslist,\addvalinlist,\removevalinlist,\boolvalinlist,\testifvalinlist,\countvalinlist,\minoflist,\maxoflist,\meanoflist,\sumoflist,\prodoflist,\reverselist,\getvaluefromlist,\lenoflist,\getvaluefromlist,\definemylist,\countvalindeflist,\lenofdeflist,\meanofdeflist,\sumofdeflist,\prodofdeflist,\getvaluefromdeflist,\getvaluefromcycllist,\getvaluefromcycldeflist},%
53 keywordstyle={\color{green!50!black}},%
54 classoffset=3,%
55 morekeywords={},%
56 keywordstyle={\color{orange}}
57 }
58
59 \newtcblisting{DemoCode}[1]{%
60 enhanced,width=\linewidth,%
61 bicolor,size=title,%
62 colback=cyan!10!white,%
63 colbacklower=cyan!5!white,%
64 colframe=cyan!75!black,%
65 listing options={%
66 breaklines=true,%
67 breakatwhitespace=true,%
68 style=tcblatex,basicstyle=\small\ttfamily,%
69 tabsize=4,%
70 commentstyle={\itshape\color{gray}},
71 keywordstyle={\color{blue}},%
72 classoffset=0,%
73 keywords={\usepackage,\includegraphics,xstring,listofitems,\readlist,\showitems,\xintFor,\xintSeq},%
74 alsoletter={-},%
75 keywordstyle={\color{blue}},%
76 classoffset=1,%
77 alsoletter={-},%
78 morekeywords={euromoney},%
79 keywordstyle={\color{violet}},%
80 classoffset=2,%
81 alsoletter={-},%
82 morekeywords={\sortasclist,\sortdeslist,\addvalinlist,\removevalinlist,\boolvalinlist,\testifvalinlist,\countvalinlist,\minoflist,\maxoflist,\meanoflist,\sumoflist,\prodoflist,\reverselist,\getvaluefromlist,\lenoflist,\getvaluefromlist,\definemylist,\countvalindeflist,\lenofdeflist,\meanofdeflist,\sumofdeflist,\prodofdeflist,\getvaluefromdeflist,\getvaluefromcycllist,\getvaluefromcycldeflist},%
83 keywordstyle={\color{green!50!black}},%
84 classoffset=3,%
85 morekeywords={},%
86 keywordstyle={\color{orange}}
87 },%
88 #1
89 }
90
91 \newtcbinputlisting\DemoCodeFile[1]{%
92 enhanced,width=\linewidth,%
93 bicolor,size=title,%
94 colback=lightgray!10!white,%
95 colbacklower=lightgray!5!white,%
96 colframe=lightgray!75!black,%
97 listing options={%
98 breaklines=true,%
99 breakatwhitespace=true,%
100 style=tcblatex,
101 basicstyle=\scriptsize\ttfamily,%
102 tabsize=4,%
103 commentstyle={\itshape\color{gray}},%
104 %lastline=148
105 },%
106 breakable,
107 listing only,%
108 listing file={#1}
109 }
110
111 \NewDocumentCommand\ShowCode{ m }{%
112 \lstinline{#1}%
113 }
114
115 \begin{document}
116
117 \thispagestyle{empty}
118
119 \begin{center}
120 \begin{minipage}{0.88\linewidth}
121 \begin{tcolorbox}[colframe=yellow,colback=yellow!15]
122 \begin{center}
123 \renewcommand{\arraystretch}{1.25}%
124 \begin{tabular}{c}
125 {\Huge \texttt{commalists-tools}}\\
126 \\
127 {\LARGE Macros for manipulating numeral} \\
128 {\LARGE comma separated lists:} \\
129 {\LARGE sorting, adding, removing, etc} \\
130 \\
131 {\small \texttt{Version \TPversion{} -- \TPdate}}
132 \end{tabular}
133 \end{center}
134 \end{tcolorbox}
135 \end{minipage}
136 \end{center}
137
138 \begin{center}
139 \begin{tabular}{c}
140 \texttt{Cédric Pierquet}\\
141 {\ttfamily c pierquet -- at -- outlook . fr}\\
142 \texttt{\url{https://github.com/cpierquet/latex-packages/tree/main/commalists-tools}} \\
143 \end{tabular}
144 \end{center}
145
146 \hrule
147
148 \vfill
149
150 \begin{tcblisting}{colframe=lightgray,colback=lightgray!5,listing only}
151 \def\mytestlist{14,10,15,11,9,10}
152 \lenoflist*{\mytestlist}
153 \minoflist*{\mytestlist}
154 \maxoflist*{14,10,15,11,9,10}
155 \sortasclist*{\mytestlist}
156 \meanoflist*{\mytestlist}
157 \removevalinlist*{10}{\mytestlist}
158 \testifvalinlist{15}{\mytestlist}{true}{false}
159 \getvaluefromlist*{\mytestlist}{3}
160 \end{tcblisting}
161
162 \begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
163 \def\mytestlist{14,10,15,11,9,10}
164 We consider the list: \mytestlist\par\smallskip
165 There's \lenoflist*{\mytestlist} values in the list\par\smallskip
166 The minimum value is \minoflist*{\mytestlist} and the maximum is \maxoflist*{14,10,15,11,9,10}\par\smallskip
167 Ascending sorted list is \sortasclist*{\mytestlist}\par\smallskip
168 Meaning value of the list is \meanoflist*{\mytestlist}\par\smallskip
169 If we remove the value 10, then the list is \removevalinlist*{10}{\mytestlist}\par\smallskip
170 We test if 15 is in the list: \testifvalinlist{15}{\mytestlist}{true}{false}\par\smallskip
171 The third value of the list is \getvaluefromlist*{\mytestlist}{3}
172
173 \end{tcolorbox}
174
175 \vfill~
176
177 %\hrule
178 %
179 %\medskip
180
181 %\emph{%
182 % The \textsf{luarandom} package do the same things, but with the obligation to compile with \hologo{LuaLaTeX}.
183 %}
184 %
185 %\medskip
186
187 \hrule
188
189 \vspace*{5mm}
190
191 \pagebreak
192
193 \phantomsection
194
195 \hypertarget{matoc}{}
196
197 \tableofcontents
198
199 \vspace*{5mm}
200
201 %\hrule
202
203 \pagebreak
204
205 \section{Loading, useful packages}
206
207 In order to load \texttt{randintlist}, simply use:
208
209 \begin{DemoCode}{listing only}
210 \usepackage{commalists-tools}
211 \end{DemoCode}
212
213 Loaded packages are \texttt{listofitems}, \texttt{xintexpr} and \texttt{xstring}.
214
215 \smallskip
216
217 The idea is to propose "reusage" of lists with \texttt{listofitems} or other commands, for example.
218
219 \section{The individual macros}
220
221 \subsection{Global usage}
222
223 Package \texttt{commalists-tools} supports (basic) manipulations on numeral comma separated lists:
224
225 \begin{itemize}
226 \item sorting;
227 \item adding values;
228 \item removing values;
229 \item counting values;
230 \item mean, sum, product;
231 \item get value, get length;
232 \item etc.
233 \end{itemize}
234
235 Starred versions only print the result, whereas non starred versions store the result into a macro.
236
237 \medskip
238
239 \hfill\textbf{All engines \TeX\ are compatible with this package.}\hfill~
240
241 \subsection{The macros for calculating}
242
243 \begin{DemoCode}{listing only}
244 %getting length of list, only printing
245 \lenoflist*{list}
246 %storing length of list into macro (\resmylen by default)
247 \lenoflist{list}
248 %getting min of list, only printing
249 \minoflist*{list}
250 %storing min of list into \macro (\resmin by default)
251 \minoflist{list}[\macro]
252 %getting max of list, only printing
253 \maxoflist*{list}
254 %storing max of list into \macro (\resmax by default)
255 \maxoflist{list}[\macro]
256 \end{DemoCode}
257
258 \begin{DemoCode}{}
259 %only printing
260 \lenoflist*{14,10,15,11,9,10}\\
261 %only printing
262 \minoflist*{14,10,15,11,9,10} and \maxoflist*{14,10,15,11,9,10}
263 \end{DemoCode}
264
265 \begin{DemoCode}{}
266 %storing len/min/max of list
267 \def\mytestlist{10,14.5,20,12,8.5}
268 \lenoflist{\mytestlist}[\mylen]Length of list is \mylen\ \&
269 \minoflist{\mytestlist}[\mymin]Min of list is \mymin\ \&
270 \maxoflist{\mytestlist}[\mymax]Max of list is \mymax
271 \end{DemoCode}
272
273 \begin{DemoCode}{listing only}
274 %getting mean of list, only printing
275 \meanoflist*{list}
276 %storing mean of list into \macro (\resmean by default)
277 \meanoflist{list}[\macro]
278 %getting sum of list, only printing
279 \sumoflist*{list}
280 %storing max of list into \macro (\ressum by default)
281 \sumoflist{list}[\macro]
282 %getting prod of list, only printing
283 \prodoflist*{list}
284 %storing max of list into \macro (\resprod by default)
285 \prodoflist{list}[\macro]
286 \end{DemoCode}
287
288 \begin{DemoCode}{}
289 %only printing
290 \meanoflist*{14,10,15,11,9,10} \\
291 %storing
292 \meanoflist{14,10,15,11,9,10}[\mymean]\mymean \\
293 %only printing
294 \sumoflist*{14,10,15,11,9,10} and \prodoflist*{14,10,15,11,9,10} \\
295 %storing
296 \sumoflist{14,10,15,11,9,10}[\mysum]\prodoflist{14,10,15,11,9,10}[\myprod]
297 The sum is \mysum\ and the prod is \myprod
298 \end{DemoCode}
299
300 \subsection{Macros for manipulating}
301
302 \begin{DemoCode}{listing only}
303 %sorting (asc), only printing
304 \sortasclist*{list}
305 %sorting (asc) and storing (overwrite)
306 \sortasclist{list}
307 %sorting (des), only printing
308 \sortdeslist*{list}
309 %sorting (des) and storing (overwrite)
310 \sortdeslist{list}
311 \end{DemoCode}
312
313 \begin{DemoCode}{}
314 %sorting (asc), only printing
315 \sortasclist*{14,10,15,11.5,9,10}\\
316 %sorting (asc) and storing (overwrite)
317 \def\tmpsortlist{14,10,15,11.5,9,10}
318 \sortasclist{\tmpsortlist}\tmpsortlist\\
319 %analysing
320 \readlist*\tmpSORTlist{\tmpsortlist}
321 \showitems{\tmpSORTlist}
322 \end{DemoCode}
323
324 \begin{DemoCode}{listing only}
325 %extract value, only printing
326 \getvaluefromlist*{list}{index}
327 %extract value and storing into macro (\myelt by default)
328 \getvaluefromlist{list}{index}[\macro]
329 \end{DemoCode}
330
331 \begin{DemoCode}{listing only}
332 %extract value (cyclic list), only printing
333 \getvaluefromcycllist*{list}{index}
334 %extract value (cyclic list) and storing into macro (\myelt by default)
335 \getvaluefromcycllist{list}{index}[\macro]
336 \end{DemoCode}
337
338 \begin{DemoCode}{}
339 %extract value, only printing
340 \def\listtmp{1,2,3,6,3,1,5,7,3}%
341 \getvaluefromlist*{\listtmp}{4}\par\smallskip
342 %storing
343 \getvaluefromlist{\listtmp}{-1}[\mylastelt]The last element is \mylastelt
344 \end{DemoCode}
345
346 \begin{DemoCode}{}
347 %extract value (cyclic list), only printing
348 \def\listtmp{A,B,C,D,E,F}%
349 \getvaluefromcycllist*{\listtmp}{10}\par\smallskip
350 %storing
351 \getvaluefromcycllist{\listtmp}{-10}[\myelt]\myelt
352 \end{DemoCode}
353
354 \begin{DemoCode}{}
355 %sorting (des), only printing
356 \sortdeslist*{14,10,15,11.5,9,10}\\
357 %sorting (asc) and storing (overwrite)
358 \def\tmpsortlist{14,10,15,11.5,9,10}
359 \sortdeslist{\tmpsortlist}\tmpsortlist\\
360 %analysing
361 \readlist*\tmpSORTlist{\tmpsortlist}
362 \showitems{\tmpSORTlist}
363 \end{DemoCode}
364
365 \begin{DemoCode}{listing only}
366 %adding, only printing
367 \addvalinlist*{values}{list}
368 %adding and storing (overwrite)
369 \addvalinlist{values}{list}
370 %removing, only printing
371 \removevalinlist*{value}{list}
372 %removing and storing (overwrite)
373 \removevalinlist{value}{list}
374 \end{DemoCode}
375
376 \begin{DemoCode}{}
377 %only printing
378 \addvalinlist*{3}{1,2,5,6}\\
379 %defining and adding
380 \def\tmpaddlist{1,2,4,5,6}
381 \addvalinlist{3}{\tmpaddlist}\tmpaddlist\\
382 %analysing
383 \readlist*\tmpADDlist{\tmpaddlist}
384 \showitems{\tmpADDlist}
385 \end{DemoCode}
386
387 \begin{DemoCode}{}
388 %only printing
389 \removevalinlist*{3}{1,2,3,6,3,1,5,7,3}\\
390 %defining and removing
391 \def\tmpremlist{1,2,3,6,3,1,5,7,3}
392 \removevalinlist{3}{\tmpremlist}\tmpremlist\\
393 %analysing
394 \readlist*\tmpREMlist{\tmpremlist}
395 \showitems{\tmpREMlist}
396 \end{DemoCode}
397
398 \begin{DemoCode}{listing only}
399 %reversing, only printing
400 \reverselist*{list}
401 %reversing and storing (overwrite)
402 \reverselist{list}
403 \end{DemoCode}
404
405 \begin{DemoCode}{}
406 %only printing
407 \reverselist*{14,10,15,11,9,10}\\
408 %reversing and storing
409 %storing
410 \reverselist{14,10,15,11,9,10}[\myreverse]\myreverse\\
411 %analysing
412 \readlist*\tmpREVERSElist{\myreverse}
413 \showitems{\tmpREVERSElist}
414 \end{DemoCode}
415
416 \subsection{Macros with testing}
417
418 \begin{DemoCode}{listing only}
419 %testing if value is in list, with boolean result in \macro (\resisinlist by default)
420 \boolvalinlist{value}{list}[\macro]
421 %conditionnal test if value is in list, according to xint syntax
422 \testifvalinlist{3}{0,1,2,3}{true}{false}
423 \end{DemoCode}
424
425 \begin{DemoCode}{}
426 %test with xint syntax
427 \testifvalinlist{-1}{0,1,2,3}{true}{false}\\
428 %test with xint syntax
429 \testifvalinlist{3}{0,1,2,3}{true}{false}\\
430 %boolean macro
431 \def\myteslist{0,5,10,5,6,9,7,8}
432 \boolvalinlist{5}{\myteslist}[\resisinlist]\resisinlist
433 \end{DemoCode}
434
435 \begin{DemoCode}{listing only}
436 %counting value, only printing
437 \countvalinlist*{value}{list}
438 %counting value, with result in \macro (\rescount by default)
439 \countvalinlist{value}{list}[\macro]
440 \end{DemoCode}
441
442 \begin{DemoCode}{}
443 %only printing
444 \countvalinlist*{8}{1,2,3,4,5,6,6,7,8,8,8,9}\\
445 %storing
446 \def\tmpcountlist{1,2,3,4,5,6,6,7,8,8,8,9}
447 \countvalinlist{6}{\tmpcountlist}[\rescountsix]\rescountsix\\
448 \countvalinlist{10}{\tmpcountlist}[\rescountten]\rescountten
449 \end{DemoCode}
450
451 \pagebreak
452
453 \section{Macros for already processed lists}
454
455 In order to speed up the process, it's possible to "define" a list (processed with \texttt{listofitems}) and the to call specific macros.
456
457 \begin{DemoCode}{listing only}
458 %define a list, to be processed by listofitems
459 \definemylist{rawlist}{processed list}
460
461 %Specific macros (same specs as above)
462 \lenofdeflist(*){processed list, without \ !}[\macro]
463 \countvalindeflist(*){val}{processed list, without \ !}[\macro]
464 \meanofdeflist(*){processed list, without \ !}[\macro]
465 \sumofdeflist(*){processed list, without \ !}[\macro]
466 \prodofdeflist(*){processed list, without \ !}[\macro]
467 \getvaluefromdeflist(*){processed list, without \ !}{index}[\macro]
468 \getvaluefromcycldeflist(*){processed list, without \ !}{index}[\macro]
469 \end{DemoCode}
470
471 \begin{DemoCode}{}
472 %define a list, to be processed by listofitems
473 \definemylist{1,4,5,6,7,8,9,19,9,9,10}{\mydeflist}\showitems{\mydeflist}
474
475 %Specific macros
476 \lenofdeflist*{mydeflist}\\
477 \getvaluefromdeflist*{mydeflist}{5}\\
478 \getvaluefromcycldeflist*{mydeflist}{22}\\
479 \countvalindeflist*{9}{mydeflist}\\
480 \meanofdeflist*{mydeflist}\\
481 \sumofdeflist*{mydeflist}\\
482 \prodofdeflist*{mydeflist}
483 \end{DemoCode}
484
485 If the list needs to be "modified" (add, remove, reverse) the best is to use individual macros, and after use \textit{define} and specific macros :-)
486
487 \pagebreak
488
489 \section{History}
490
491 \texttt{0.20b: Extract element with cyclic list}
492
493 \texttt{0.20a: Improvements in L3 version of package}
494
495 \texttt{0.1.7: Improvements in L3 version of package}
496
497 \texttt{0.1.6: L3 version of package}
498
499 \texttt{0.1.5: Bugfix}
500
501 \texttt{0.1.4: Changing name of macro}
502
503 \texttt{0.1.3: Duplicate macro with ProfMaquette (so new name)}
504
505 \texttt{0.1.2: Alternative macros for already treated lists}
506
507 \texttt{0.1.1: Compatibility with decimals, len of list, get value}
508
509 \texttt{0.1.0: Initial version}
510
511 \section{The code}
512
513 \DemoCodeFile{commalists-tools.sty}
514
515 \end{document}