summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/commalists-tools/doc/commalists-tools-doc.tex
blob: 49ddbd07ac4c7916ea982442142a63474118aedc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
% !TeX TXS-program:compile = txs:///arara
% arara: pdflatex: {shell: no, synctex: no, interaction: batchmode}
% arara: pdflatex: {shell: no, synctex: no, interaction: batchmode}

\documentclass[11pt,a4paper]{ltxdoc}
\usepackage{bera}
\usepackage{inconsolata}
\usepackage[T1]{fontenc}
\usepackage[scale=0.875]{cabin}
\usepackage{commalists-tools}
\usepackage{fancyvrb}
\usepackage{fancyhdr}
\usepackage{tabularray}
\usepackage{fontawesome5}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\lfoot{\sffamily\small [commalists-tools]}
\cfoot{\sffamily\small - \thepage{} -}
\rfoot{\hyperlink{matoc}{\small\faArrowAltCircleUp[regular]}}
\usepackage{hologo}
\providecommand\tikzlogo{Ti\textit{k}Z}
\providecommand\TeXLive{\TeX{}Live\xspace}
\let\TikZ\tikzlogo

\usepackage{hyperref}
\urlstyle{same}
\hypersetup{pdfborder=0 0 0}
\usepackage[margin=2cm]{geometry}
\setlength{\parindent}{0pt}
\def\TPversion{0.1.3}
\def\TPdate{22/10/2024}
\usepackage{tcolorbox}
\usepackage{pgffor}
\tcbuselibrary{breakable,skins,hooks,listingsutf8}
%\usepackage{soul}
%\sethlcolor{lightgray!25}

\lstset{
	language=[LaTeX]TeX,%
	basicstyle=\ttfamily,%
	keywordstyle={\color{blue}},%
	classoffset=0,%
	keywords={},%
	alsoletter={-},%
	keywordstyle={\color{blue}},%
	classoffset=1,%
	alsoletter={-},%
	morekeywords={commalists-tools},%
	keywordstyle={\color{violet}},%
	classoffset=2,%
	alsoletter={-},%
	morekeywords={\sortasclist,\sortdeslist,\addvalinlist,\removevalinlist,\boolvalinlist,\xintifvalinlist,\countvalinlist,\minoflist,\maxoflist,\meanoflist,\sumoflist,\prodoflist,\reverselist,\getvaluefromlist,\lenoflist,\getvaluefromlist,\definemylist,\countvalindeflist,\lenofdeflist,\meanofdeflist,\sumofdeflist,\prodofdeflist,\getvaluefromdeflist},%
	keywordstyle={\color{green!50!black}},%
	classoffset=3,%
	morekeywords={},%
	keywordstyle={\color{orange}}
}

\newtcblisting{DemoCode}[1]{%
	enhanced,width=\linewidth,%
	bicolor,size=title,%
	colback=cyan!10!white,%
	colbacklower=cyan!5!white,%
	colframe=cyan!75!black,%
	listing options={%
		breaklines=true,%
		breakatwhitespace=true,%
		style=tcblatex,basicstyle=\small\ttfamily,%
		tabsize=4,%
		commentstyle={\itshape\color{gray}},
		keywordstyle={\color{blue}},%
		classoffset=0,%
		keywords={\usepackage,\includegraphics,xstring,listofitems,\readlist,\showitems,\xintFor,\xintSeq},%
		alsoletter={-},%
		keywordstyle={\color{blue}},%
		classoffset=1,%
		alsoletter={-},%
		morekeywords={euromoney},%
		keywordstyle={\color{violet}},%
		classoffset=2,%
		alsoletter={-},%
		morekeywords={\sortasclist,\sortdeslist,\addvalinlist,\removevalinlist,\boolvalinlist,\xintifvalinlist,\countvalinlist,\minoflist,\maxoflist,\meanoflist,\sumoflist,\prodoflist,\reverselist,\getvaluefromlist,\lenoflist,\getvaluefromlist,\definemylist,\countvalindeflist,\lenofdeflist,\meanofdeflist,\sumofdeflist,\prodofdeflist,\getvaluefromdeflist},%
		keywordstyle={\color{green!50!black}},%
		classoffset=3,%
		morekeywords={},%
		keywordstyle={\color{orange}}
	},%
	#1
}

\newtcbinputlisting\DemoCodeFile[1]{%
	enhanced,width=\linewidth,%
	bicolor,size=title,%
	colback=lightgray!10!white,%
	colbacklower=lightgray!5!white,%
	colframe=lightgray!75!black,%
	listing options={%
		breaklines=true,%
		breakatwhitespace=true,%
		style=tcblatex,
		basicstyle=\scriptsize\ttfamily,%
		tabsize=4,%
		commentstyle={\itshape\color{gray}},%
		%lastline=148
	},%
	breakable,
	listing only,%
	listing file={#1}
}

\NewDocumentCommand\ShowCode{ m }{%
	\lstinline{#1}%
}

\begin{document}

\thispagestyle{empty}

\begin{center}
	\begin{minipage}{0.88\linewidth}
		\begin{tcolorbox}[colframe=yellow,colback=yellow!15]
			\begin{center}
				\renewcommand{\arraystretch}{1.25}%
				\begin{tabular}{c}
					{\Huge \texttt{commalists-tools}}\\
					\\
					{\LARGE Macros for manipulating numeral} \\
					{\LARGE comma separated lists:} \\
					{\LARGE sorting, adding, removing, etc} \\
					\\
					{\small \texttt{Version \TPversion{} -- \TPdate}}
				\end{tabular}
			\end{center}
		\end{tcolorbox}
	\end{minipage}
\end{center}

\begin{center}
	\begin{tabular}{c}
		\texttt{Cédric Pierquet}\\
		{\ttfamily c pierquet -- at -- outlook . fr}\\
		\texttt{\url{https://github.com/cpierquet/commalists-tools}} \\
	\end{tabular}
\end{center}

\hrule

\vfill

\begin{tcblisting}{colframe=lightgray,colback=lightgray!5,listing only}
\def\mytestlist{14,10,15,11,9,10}
\lenoflist*{\mytestlist}
\minoflist*{\mytestlist}
\maxoflist*{14,10,15,11,9,10}
\sortasclist*{\mytestlist}
\meanoflist*{\mytestlist}
\removevalinlist*{10}{\mytestlist}
\xintifvalinlist{15}{\mytestlist}{true}{false}
\getvaluefromlist*{\mytestlist}{3}
\end{tcblisting}

\begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
\def\mytestlist{14,10,15,11,9,10}
We consider the list: \mytestlist\par\smallskip
There's \lenoflist*{\mytestlist} values in the list\par\smallskip
The minimum value is \minoflist*{\mytestlist} and the maximum is \maxoflist*{14,10,15,11,9,10}\par\smallskip
Ascending sorted list is \sortasclist*{\mytestlist}\par\smallskip
Meaning value of the list is \meanoflist*{\mytestlist}\par\smallskip
If we remove the value 10, then the list is \removevalinlist*{10}{\mytestlist}\par\smallskip
We test if 15 is in the list: \xintifvalinlist{15}{\mytestlist}{true}{false}\par\smallskip
The third value of the list is \getvaluefromlist*{\mytestlist}{3}

\end{tcolorbox}

\vfill~

%\hrule
%
%\medskip

%\emph{%
%	The \textsf{luarandom} package do the same things, but with the obligation to compile with \hologo{LuaLaTeX}.
%}
%
%\medskip

\hrule

\vspace*{5mm}

\pagebreak

\phantomsection

\hypertarget{matoc}{}

\tableofcontents

\vspace*{5mm}

%\hrule

\pagebreak

\section{Loading, useful packages}

In order to load \texttt{randintlist}, simply use:

\begin{DemoCode}{listing only}
\usepackage{commalists-tools}
\end{DemoCode}

Loaded packages are \texttt{listofitems}, \texttt{xintexpr} and \texttt{xstring}.

\smallskip

The idea is to propose "reusage" of lists with \texttt{listofitems} or other commands, for example.

\section{The individual macros}

\subsection{Global usage}

Package \texttt{commalists-tools} supports (basic) manipulations on numeral comma separated lists:

\begin{itemize}
	\item sorting;
	\item adding values;
	\item removing values;
	\item counting values;
	\item mean, sum, product;
	\item get value, get length;
	\item etc.
\end{itemize}

Starred versions only print the result, whereas non starred versions store the result into a macro.

\medskip

\hfill\textbf{All engines \TeX\ are compatible with this package.}\hfill~

\subsection{The macros for calculating}

\begin{DemoCode}{listing only}
%getting length of list, only printing
\lenoflist*{list}
%storing length of list into macro (\resmylen by default)
\lenoflist{list}
%getting min of list, only printing
\minoflist*{list}
%storing min of list into \macro (\resmin by default)
\minoflist{list}[\macro]
%getting max of list, only printing
\maxoflist*{list}
%storing max of list into \macro (\resmax by default)
\maxoflist{list}[\macro]
\end{DemoCode}

\begin{DemoCode}{}
%only printing
\lenoflist*{14,10,15,11,9,10}\\
%only printing
\minoflist*{14,10,15,11,9,10} and \maxoflist*{14,10,15,11,9,10}
\end{DemoCode}

\begin{DemoCode}{}
%storing len/min/max of list
\def\mytestlist{10,14.5,20,12,8.5}
\lenoflist{\mytestlist}[\mylen]Length of list is \mylen\ \&
\minoflist{\mytestlist}[\mymin]Min of list is \mymin\ \&
\maxoflist{\mytestlist}[\mymax]Max of list is \mymax
\end{DemoCode}

\begin{DemoCode}{listing only}
%getting mean of list, only printing
\meanoflist*{list}
%storing mean of list into \macro (\resmean by default)
\meanoflist{list}[\macro]
%getting sum of list, only printing
\sumoflist*{list}
%storing max of list into \macro (\ressum by default)
\sumoflist{list}[\macro]
%getting prod of list, only printing
\prodoflist*{list}
%storing max of list into \macro (\resprod by default)
\prodoflist{list}[\macro]
\end{DemoCode}

\begin{DemoCode}{}
%only printing
\meanoflist*{14,10,15,11,9,10} \\
%storing
\meanoflist{14,10,15,11,9,10}[\mymean]\mymean \\
%only printing
\sumoflist*{14,10,15,11,9,10} and \prodoflist*{14,10,15,11,9,10} \\
%storing
\sumoflist{14,10,15,11,9,10}[\mysum]\prodoflist{14,10,15,11,9,10}[\myprod]
The sum is \mysum\ and the prod is \myprod
\end{DemoCode}

\subsection{Macros for manipulating}

\begin{DemoCode}{listing only}
%sorting (asc), only printing
\sortasclist*{list}
%sorting (asc) and storing (overwrite)
\sortasclist{list}
%sorting (des), only printing
\sortdeslist*{list}
%sorting (des) and storing (overwrite)
\sortdeslist{list}
\end{DemoCode}

\begin{DemoCode}{}
%sorting (asc), only printing
\sortasclist*{14,10,15,11.5,9,10}\\
%sorting (asc) and storing (overwrite)
\def\tmpsortlist{14,10,15,11.5,9,10}
\sortasclist{\tmpsortlist}\tmpsortlist\\
%analysing
\readlist*\tmpSORTlist{\tmpsortlist}
\showitems{\tmpSORTlist}
\end{DemoCode}

\begin{DemoCode}{listing only}
%extract value, only printing
\getvaluefromlist*{list}{index}
%extract value and storing into macro (\myelt by default)
\getvaluefromlist{list}{index}[\macro]
\end{DemoCode}

\begin{DemoCode}{}
%extract value, only printing
\def\listtmp{1,2,3,6,3,1,5,7,3}%
\getvaluefromlist*{\listtmp}{4}\par\smallskip
%storing
\getvaluefromlist{\listtmp}{-1}[\mylastelt]The last element is \mylastelt
\end{DemoCode}

\begin{DemoCode}{}
%sorting (des), only printing
\sortdeslist*{14,10,15,11.5,9,10}\\
%sorting (asc) and storing (overwrite)
\def\tmpsortlist{14,10,15,11.5,9,10}
\sortdeslist{\tmpsortlist}\tmpsortlist\\
%analysing
\readlist*\tmpSORTlist{\tmpsortlist}
\showitems{\tmpSORTlist}
\end{DemoCode}

\begin{DemoCode}{listing only}
%adding, only printing
\addvalinlist*{values}{list}
%adding and storing (overwrite)
\addvalinlist{values}{list}
%removing, only printing
\removevalinlist*{value}{list}
%removing and storing (overwrite)
\removevalinlist{value}{list}
\end{DemoCode}

\begin{DemoCode}{}
%only printing
\addvalinlist*{3}{1,2,5,6}\\
%defining and adding
\def\tmpaddlist{1,2,4,5,6}
\addvalinlist{3}{\tmpaddlist}\tmpaddlist\\
%analysing
\readlist*\tmpADDlist{\tmpaddlist}
\showitems{\tmpADDlist}
\end{DemoCode}

\begin{DemoCode}{}
%only printing
\removevalinlist*{3}{1,2,3,6,3,1,5,7,3}\\
%defining and removing
\def\tmpremlist{1,2,3,6,3,1,5,7,3}
\removevalinlist{3}{\tmpremlist}\tmpremlist\\
%analysing
\readlist*\tmpREMlist{\tmpremlist}
\showitems{\tmpREMlist}
\end{DemoCode}

\begin{DemoCode}{listing only}
%reversing, only printing
\reverselist*{list}
%reversing and storing (overwrite)
\reverselist{list}
\end{DemoCode}

\begin{DemoCode}{}
%only printing
\reverselist*{14,10,15,11,9,10}\\
%reversing and storing
%storing
\reverselist{14,10,15,11,9,10}[\myreverse]\myreverse\\
%analysing
\readlist*\tmpREVERSElist{\myreverse}
\showitems{\tmpREVERSElist}
\end{DemoCode}

\subsection{Macros with testing}

\begin{DemoCode}{listing only}
%testing if value is in list, with boolean result in \macro (\resisinlist by default)
\boolvalinlist{value}{list}[\macro]
%conditionnal test if value is in list, according to xint syntax
\xintifvalinlist{3}{0,1,2,3}{true}{false}
\end{DemoCode}

\begin{DemoCode}{}
%test with xint syntax
\xintifvalinlist{-1}{0,1,2,3}{true}{false}\\
%test with xint syntax
\xintifvalinlist{3}{0,1,2,3}{true}{false}\\
%boolean macro
\def\myteslist{0,5,10,5,6,9,7,8}
\boolvalinlist{5}{\myteslist}[\resisinlist]\resisinlist
\end{DemoCode}

\begin{DemoCode}{listing only}
%counting value, only printing
\countvalinlist*{value}{list}
%counting value, with result in \macro (\rescount by default)
\countvalinlist{value}{list}[\macro]
\end{DemoCode}

\begin{DemoCode}{}
%only printing
\countvalinlist*{8}{1,2,3,4,5,6,6,7,8,8,8,9}\\
%storing
\def\tmpcountlist{1,2,3,4,5,6,6,7,8,8,8,9}
\countvalinlist{6}{\tmpcountlist}[\rescountsix]\rescountsix\\
\countvalinlist{10}{\tmpcountlist}[\rescountten]\rescountten
\end{DemoCode}

\pagebreak

\section{Macros for already processed lists}

In order to speed up the process, it's possible to "define" a list (processed with \texttt{listofitems}) and the to call specific macros.

\begin{DemoCode}{listing only}
%define a list, to be processed by listofitems
\definemylist{rawlist}{processed list}

%Specific macros (same specs as above)
\lenofdeflist(*){processed list, without \ !}[\macro]
\countvalindeflist(*){val}{processed list, without \ !}[\macro]
\meanofdeflist(*){processed list, without \ !}[\macro]
\sumofdeflist(*){processed list, without \ !}[\macro]
\prodofdeflist(*){processed list, without \ !}[\macro]
\getvaluefromdeflist(*){processed list, without \ !}{index}[\macro]
\end{DemoCode}

\begin{DemoCode}{}
%define a list, to be processed by listofitems
\definemylist{1,4,5,6,7,8,9,19,9,9,10}{\mydeflist}\showitems{\mydeflist}

%Specific macros
\lenofdeflist*{mydeflist}\\
\getvaluefromdeflist*{mydeflist}{5}\\
\countvalindeflist*{9}{mydeflist}\\
\meanofdeflist*{mydeflist}\\
\sumofdeflist*{mydeflist}\\
\prodofdeflist*{mydeflist}
\end{DemoCode}

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 :-)

\pagebreak

\section{History}

\texttt{0.1.3: Duplicate macro with ProfMaquette (so new name)}

\texttt{0.1.2: Alternative macros for already treated lists}

\texttt{0.1.1: Compatibility with decimals, len of list, get value}

\texttt{0.1.0: Initial version}

\section{The code}

\DemoCodeFile{commalists-tools.sty}

\end{document}