| 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-l3} |
| 11 |
\usepackage{listofitems} |
| 12 |
\usepackage{fancyvrb} |
| 13 |
\usepackage{fancyhdr} |
| 14 |
\usepackage{tabularray} |
| 15 |
\usepackage{fontawesome5} |
| 16 |
\fancyhf{} |
| 17 |
\renewcommand{\headrulewidth}{0pt} |
| 18 |
\lfoot{\sffamily\small [commalists-tools-l3]} |
| 19 |
\cfoot{\sffamily\small - \thepage{} -} |
| 20 |
\rfoot{\hyperlink{matoc}{\small\faArrowAltCircleUp[regular]}} |
| 21 |
\usepackage{hologo} |
| 22 |
\providecommand\tikzlogo{Ti\textit{k}Z} |
| 23 |
\providecommand\TeXLive{\TeX{}Live\xspace} |
| 24 |
\let\TikZ\tikzlogo |
| 25 |
|
| 26 |
\usepackage{hyperref} |
| 27 |
\urlstyle{same} |
| 28 |
\hypersetup{pdfborder=0 0 0} |
| 29 |
\usepackage[margin=2cm]{geometry} |
| 30 |
\setlength{\parindent}{0pt} |
| 31 |
\def\TPversion{0.20b} |
| 32 |
\def\TPdate{24/03/2026} |
| 33 |
\usepackage{tcolorbox} |
| 34 |
\usepackage{pgffor} |
| 35 |
\tcbuselibrary{breakable,skins,hooks,listingsutf8} |
| 36 |
%\usepackage{soul} |
| 37 |
%\sethlcolor{lightgray!25} |
| 38 |
|
| 39 |
\lstset{ |
| 40 |
language=[LaTeX]TeX,% |
| 41 |
basicstyle=\ttfamily,% |
| 42 |
keywordstyle={\color{blue}},% |
| 43 |
classoffset=0,% |
| 44 |
keywords={},% |
| 45 |
alsoletter={-},% |
| 46 |
keywordstyle={\color{blue}},% |
| 47 |
classoffset=1,% |
| 48 |
alsoletter={-},% |
| 49 |
morekeywords={commalists-tools-l3},% |
| 50 |
keywordstyle={\color{violet}},% |
| 51 |
classoffset=2,% |
| 52 |
alsoletter={-},% |
| 53 |
morekeywords={\ctshowlist,\ctsortasclist,\ctsortdeslist,\ctaddvalinlist,\ctremovevalinlist,\ctboolvalinlist,\cttestifvalinlist,\ctcountvalinlist,\ctminoflist,\ctmaxoflist,\ctmeanoflist,\ctsumoflist,\ctprodoflist,\ctreverselist,\ctgetvaluefromlist,\ctlenoflist,\ctgetindexfromlist,\ctsublist,\ctslicelist,\cttransformlist,\ctuniqlist,\ctintersectlists,\ctmergelists,\ctdifflist,\ctsymdifflist},% |
| 54 |
keywordstyle={\color{green!50!black}},% |
| 55 |
classoffset=3,% |
| 56 |
morekeywords={asc,des},% |
| 57 |
keywordstyle={\color{orange}} |
| 58 |
} |
| 59 |
|
| 60 |
\newtcblisting{DemoCode}[1]{% |
| 61 |
enhanced,width=\linewidth,% |
| 62 |
bicolor,size=title,% |
| 63 |
colback=cyan!10!white,% |
| 64 |
colbacklower=cyan!5!white,% |
| 65 |
colframe=cyan!75!black,% |
| 66 |
listing options={% |
| 67 |
breaklines=true,% |
| 68 |
breakatwhitespace=true,% |
| 69 |
style=tcblatex,basicstyle=\small\ttfamily,% |
| 70 |
tabsize=4,% |
| 71 |
commentstyle={\itshape\color{gray}}, |
| 72 |
keywordstyle={\color{blue}},% |
| 73 |
classoffset=0,% |
| 74 |
keywords={\usepackage,\includegraphics,xstring,listofitems,\readlist,\showitems,\xintFor,\xintSeq},% |
| 75 |
alsoletter={-},% |
| 76 |
keywordstyle={\color{blue}},% |
| 77 |
classoffset=1,% |
| 78 |
alsoletter={-},% |
| 79 |
morekeywords={commalists-tools-l3},% |
| 80 |
keywordstyle={\color{violet}},% |
| 81 |
classoffset=2,% |
| 82 |
alsoletter={-},% |
| 83 |
morekeywords={\ctshowlist,\ctsortasclist,\ctsortdeslist,\ctaddvalinlist,\ctremovevalinlist,\ctboolvalinlist,\cttestifvalinlist,\ctcountvalinlist,\ctminoflist,\ctmaxoflist,\ctmeanoflist,\ctsumoflist,\ctprodoflist,\ctreverselist,\ctgetvaluefromlist,\ctlenoflist,\ctgetindexfromlist,\ctsublist,\ctslicelist,\cttransformlist,\ctuniqlist,\ctintersectlists,\ctmergelists,\ctdifflist,\ctsymdifflist,\ctgetvaluefromcycllist},% |
| 84 |
keywordstyle={\color{green!50!black}},% |
| 85 |
classoffset=3,% |
| 86 |
morekeywords={asc,des},% |
| 87 |
keywordstyle={\color{orange}} |
| 88 |
},% |
| 89 |
#1 |
| 90 |
} |
| 91 |
|
| 92 |
\newtcbinputlisting\DemoCodeFile[1]{% |
| 93 |
enhanced,width=\linewidth,% |
| 94 |
bicolor,size=title,% |
| 95 |
colback=lightgray!10!white,% |
| 96 |
colbacklower=lightgray!5!white,% |
| 97 |
colframe=lightgray!75!black,% |
| 98 |
listing options={% |
| 99 |
breaklines=true,% |
| 100 |
breakatwhitespace=true,% |
| 101 |
style=tcblatex, |
| 102 |
basicstyle=\scriptsize\ttfamily,% |
| 103 |
tabsize=2,% |
| 104 |
commentstyle={\itshape\color{gray}},% |
| 105 |
%lastline=148 |
| 106 |
},% |
| 107 |
breakable, |
| 108 |
listing only,% |
| 109 |
listing file={#1} |
| 110 |
} |
| 111 |
|
| 112 |
\NewDocumentCommand\ShowCode{ m }{% |
| 113 |
\lstinline{#1}% |
| 114 |
} |
| 115 |
|
| 116 |
\begin{document} |
| 117 |
|
| 118 |
\thispagestyle{empty} |
| 119 |
|
| 120 |
\begin{center} |
| 121 |
\begin{minipage}{0.88\linewidth} |
| 122 |
\begin{tcolorbox}[colframe=yellow,colback=yellow!15] |
| 123 |
\begin{center} |
| 124 |
\renewcommand{\arraystretch}{1.25}% |
| 125 |
\begin{tabular}{c} |
| 126 |
{\Huge \texttt{commalists-tools-l3}}\\ |
| 127 |
\\ |
| 128 |
{\large\hologo{LaTeX3}}\\ |
| 129 |
\\ |
| 130 |
{\LARGE Macros for manipulating numeral} \\ |
| 131 |
{\LARGE comma separated lists:} \\ |
| 132 |
{\LARGE sorting, adding, removing, etc} \\ |
| 133 |
\\ |
| 134 |
{\small \texttt{Version \TPversion{} -- \TPdate}} |
| 135 |
\end{tabular} |
| 136 |
\end{center} |
| 137 |
\end{tcolorbox} |
| 138 |
\end{minipage} |
| 139 |
\end{center} |
| 140 |
|
| 141 |
\begin{center} |
| 142 |
\begin{tabular}{c} |
| 143 |
\texttt{Cédric Pierquet}\\ |
| 144 |
{\ttfamily c pierquet -- at -- outlook . fr}\\ |
| 145 |
\texttt{\url{https://github.com/cpierquet/latex-packages/tree/main/commalists-tools}} \\ |
| 146 |
\end{tabular} |
| 147 |
\end{center} |
| 148 |
|
| 149 |
\hrule |
| 150 |
|
| 151 |
\vfill |
| 152 |
|
| 153 |
\begin{tcblisting}{colframe=lightgray,colback=lightgray!5,listing only} |
| 154 |
\def\mytestlist{14,10,15,11,9,10} |
| 155 |
\ctlenoflist*{\mytestlist} |
| 156 |
\ctminoflist*{\mytestlist} |
| 157 |
\ctmaxoflist*{14,10,15,11,9,10} |
| 158 |
\ctsortasclist*{\mytestlist} |
| 159 |
\ctmeanoflist*{\mytestlist} |
| 160 |
\ctremovevalinlist*{10}{\mytestlist} |
| 161 |
\cttestifvalinlist{15}{\mytestlist}{true}{false} |
| 162 |
\ctgetvaluefromlist*{\mytestlist}{3} |
| 163 |
\ctgetindexfromlist*{15}{\mytestlist} |
| 164 |
\ctsublist*{\mytestlist}{*}{4} |
| 165 |
\end{tcblisting} |
| 166 |
|
| 167 |
\begin{tcolorbox}[colframe=lightgray,colback=lightgray!5] |
| 168 |
\def\mytestlist{14,10,15,11,9,10} |
| 169 |
We consider the list: \mytestlist\par\smallskip |
| 170 |
There's \ctlenoflist*{\mytestlist} values in the list\par\smallskip |
| 171 |
The minimum value is \ctminoflist*{\mytestlist} and the maximum is \ctmaxoflist*{14,10,15,11,9,10}\par\smallskip |
| 172 |
Ascending sorted list is \ctsortasclist*{\mytestlist}\par\smallskip |
| 173 |
Mean value of the list is \ctmeanoflist*{\mytestlist}\par\smallskip |
| 174 |
If we remove the value 10, then the list is \ctremovevalinlist*{10}{\mytestlist}\par\smallskip |
| 175 |
We test if 15 is in the list: \cttestifvalinlist{15}{\mytestlist}{true}{false}\par\smallskip |
| 176 |
The third value of the list is \ctgetvaluefromlist*{\mytestlist}{3}\par\smallskip |
| 177 |
15 is in index \ctgetindexfromlist*{15}{\mytestlist} in the list\par\smallskip |
| 178 |
Sublist [-,4] of the list is: \ctsublist*{\mytestlist}{*}{4} |
| 179 |
\end{tcolorbox} |
| 180 |
|
| 181 |
\vfill~ |
| 182 |
|
| 183 |
\hrule |
| 184 |
|
| 185 |
\vspace*{5mm} |
| 186 |
|
| 187 |
\pagebreak |
| 188 |
|
| 189 |
\phantomsection |
| 190 |
|
| 191 |
\hypertarget{matoc}{} |
| 192 |
|
| 193 |
\tableofcontents |
| 194 |
|
| 195 |
\vspace*{5mm} |
| 196 |
|
| 197 |
\pagebreak |
| 198 |
|
| 199 |
\section{Introduction} |
| 200 |
|
| 201 |
In order to load \texttt{commalists-tools-l3}, simply use: |
| 202 |
|
| 203 |
\begin{DemoCode}{listing only} |
| 204 |
\usepackage{commalists-tools-l3} |
| 205 |
\end{DemoCode} |
| 206 |
|
| 207 |
All code is written in \hologo{LaTeX3}, so no extra packages are needed. |
| 208 |
|
| 209 |
\medskip |
| 210 |
|
| 211 |
{\footnotesize\faLightbulb} See also the \href{https://ctan.org/pkg/tuple}{\texttt{tuple}} package on CTAN, which provides a more complete and fully expandable approach to numeral list operations, with an elegant \texttt{object.method} chaining syntax! |
| 212 |
|
| 213 |
\section{Global usage} |
| 214 |
|
| 215 |
\subsection{Tools} |
| 216 |
|
| 217 |
Package \texttt{commalists-tools-l3} supports (basic) manipulations on numeral comma separated lists: |
| 218 |
|
| 219 |
\begin{itemize} |
| 220 |
\item sorting; |
| 221 |
\item adding values; |
| 222 |
\item removing values; |
| 223 |
\item counting values; |
| 224 |
\item mean, sum, product; |
| 225 |
\item get value, get length; |
| 226 |
\item etc. |
| 227 |
\end{itemize} |
| 228 |
|
| 229 |
Starred versions only print the result, whereas non starred versions store the result into a macro. |
| 230 |
|
| 231 |
\medskip |
| 232 |
|
| 233 |
{\small\faLightbulb} Macros are prefixed with \ShowCode{\\ct...} (for \textsf{\textbf{\underline{c}}ommalists-\textbf{\underline{t}}ools}). |
| 234 |
|
| 235 |
\subsection{The macro for printing} |
| 236 |
|
| 237 |
\begin{DemoCode}{listing only} |
| 238 |
%just printing, with optional separator |
| 239 |
\ctshowlist[sep]{list} |
| 240 |
\end{DemoCode} |
| 241 |
|
| 242 |
\begin{DemoCode}{} |
| 243 |
\ctshowlist{1, 2,3, 4, 6} |
| 244 |
\end{DemoCode} |
| 245 |
|
| 246 |
\begin{DemoCode}{} |
| 247 |
\def\mytmplist{12, -4, 5,7 ,8, 9, 0} |
| 248 |
\ctshowlist[\,/\,]{\mytmplist} |
| 249 |
\end{DemoCode} |
| 250 |
|
| 251 |
\section{The macros for calculating} |
| 252 |
|
| 253 |
\subsection{Length, minimum, maximum} |
| 254 |
|
| 255 |
\begin{DemoCode}{listing only} |
| 256 |
%getting length of list, only printing |
| 257 |
\ctlenoflist*{list} |
| 258 |
%storing length of list into macro (\resmylen by default) |
| 259 |
\ctlenoflist{list} |
| 260 |
%getting min of list, only printing |
| 261 |
\ctminoflist*{list} |
| 262 |
%storing min of list into \macro (\resmin by default) |
| 263 |
\ctminoflist{list}[\macro] |
| 264 |
%getting max of list, only printing |
| 265 |
\ctmaxoflist*{list} |
| 266 |
%storing max of list into \macro (\resmax by default) |
| 267 |
\ctmaxoflist{list}[\macro] |
| 268 |
\end{DemoCode} |
| 269 |
|
| 270 |
\begin{DemoCode}{} |
| 271 |
%only printing |
| 272 |
\ctlenoflist*{14,10,15,11,9,10}\\ |
| 273 |
%only printing |
| 274 |
\ctminoflist*{14,10,15,11,9,10} and \ctmaxoflist*{14,10,15,11,9,10} |
| 275 |
\end{DemoCode} |
| 276 |
|
| 277 |
\begin{DemoCode}{} |
| 278 |
%storing len/min/max of list |
| 279 |
\def\mytestlist{10,14.5,20,12,8.5} |
| 280 |
\ctlenoflist{\mytestlist}[\mylen]Length of list is \mylen\ \& |
| 281 |
\ctminoflist{\mytestlist}[\mymin]Min of list is \mymin\ \& |
| 282 |
\ctmaxoflist{\mytestlist}[\mymax]Max of list is \mymax |
| 283 |
\end{DemoCode} |
| 284 |
|
| 285 |
\subsection{Mean, sum, prod} |
| 286 |
|
| 287 |
\begin{DemoCode}{listing only} |
| 288 |
%getting mean of list, only printing |
| 289 |
\ctmeanoflist*{list} |
| 290 |
%storing mean of list into \macro (\resmean by default) |
| 291 |
\ctmeanoflist{list}[\macro] |
| 292 |
%getting sum of list, only printing |
| 293 |
\ctsumoflist*{list} |
| 294 |
%storing max of list into \macro (\ressum by default) |
| 295 |
\ctsumoflist{list}[\macro] |
| 296 |
%getting prod of list, only printing |
| 297 |
\ctprodoflist*{list} |
| 298 |
%storing max of list into \macro (\resprod by default) |
| 299 |
\ctprodoflist{list}[\macro] |
| 300 |
\end{DemoCode} |
| 301 |
|
| 302 |
\begin{DemoCode}{} |
| 303 |
%only printing |
| 304 |
\ctmeanoflist*{14,10,15,11,9,10} \\ |
| 305 |
%storing |
| 306 |
\ctmeanoflist{14,10,15,11,9,10}[\mymean]\mymean \\ |
| 307 |
%only printing |
| 308 |
\ctsumoflist*{14,10,15,11,9,10} and \ctprodoflist*{14,10,15,11,9,10} \\ |
| 309 |
%storing |
| 310 |
\ctsumoflist{14,10,15,11,9,10}[\mysum]\ctprodoflist{14,10,15,11,9,10}[\myprod] |
| 311 |
The sum is \mysum\ and the prod is \myprod |
| 312 |
\end{DemoCode} |
| 313 |
|
| 314 |
\section{Macros for manipulating} |
| 315 |
|
| 316 |
\subsection{Sorting} |
| 317 |
|
| 318 |
\begin{DemoCode}{listing only} |
| 319 |
%sorting (asc), only printing |
| 320 |
\ctsortasclist*{list} |
| 321 |
%sorting (asc) and storing (overwrite) |
| 322 |
\ctsortasclist{list} |
| 323 |
%sorting (des), only printing |
| 324 |
\ctsortdeslist*{list} |
| 325 |
%sorting (des) and storing (overwrite) |
| 326 |
\ctsortdeslist{list} |
| 327 |
\end{DemoCode} |
| 328 |
|
| 329 |
\begin{DemoCode}{} |
| 330 |
%sorting (asc), only printing |
| 331 |
\ctsortasclist*{14,10,15,11.5,9,10}\\ |
| 332 |
%sorting (asc) and storing within \myreslist |
| 333 |
\def\tmpsortlist{14,10,15,11.5,9,10} |
| 334 |
\ctsortasclist{\tmpsortlist}[\myreslist]\myreslist\\ |
| 335 |
%analysing |
| 336 |
\readlist*\tmpSORTlist{\myreslist} |
| 337 |
\showitems{\tmpSORTlist} |
| 338 |
\end{DemoCode} |
| 339 |
|
| 340 |
\begin{DemoCode}{} |
| 341 |
%sorting (des), only printing |
| 342 |
\ctsortdeslist*{14,10,15,11.5,9,10}\\ |
| 343 |
%sorting (asc) and storing within \myreslist |
| 344 |
\def\tmpsortlist{14,10,15,11.5,9,10} |
| 345 |
\ctsortdeslist{\tmpsortlist}[\myreslist]\myreslist\\ |
| 346 |
%analysing |
| 347 |
\readlist*\tmpSORTlist{\myreslist} |
| 348 |
\showitems{\tmpSORTlist} |
| 349 |
\end{DemoCode} |
| 350 |
|
| 351 |
\subsection{Extract element, add/remove element} |
| 352 |
|
| 353 |
\begin{DemoCode}{listing only} |
| 354 |
%extract value, only printing |
| 355 |
\ctgetvaluefromlist*{list}{index} |
| 356 |
%extract value and storing into macro (\myelt by default) |
| 357 |
\ctgetvaluefromlist{list}{index}[\macro] |
| 358 |
\end{DemoCode} |
| 359 |
|
| 360 |
\begin{DemoCode}{} |
| 361 |
%extract value, only printing |
| 362 |
\def\listtmp{1,2,3,6,3,1,5,7,3}% |
| 363 |
\ctgetvaluefromlist*{\listtmp}{4}\par\smallskip |
| 364 |
%storing |
| 365 |
\ctgetvaluefromlist{\listtmp}{-1}[\mylastelt]The last element is \mylastelt |
| 366 |
\end{DemoCode} |
| 367 |
|
| 368 |
\begin{DemoCode}{listing only} |
| 369 |
%extract value (cyclic list), only printing |
| 370 |
\ctgetvaluefromcycllist*{list}{index} |
| 371 |
%extract value (cyclic list) and storing into macro (\myelt by default) |
| 372 |
\ctgetvaluefromcycllist{list}{index}[\macro] |
| 373 |
\end{DemoCode} |
| 374 |
|
| 375 |
\begin{DemoCode}{} |
| 376 |
%extract value (cyclic list), only printing |
| 377 |
\def\listtmp{A,B,C,D,E,F}% |
| 378 |
\ctgetvaluefromcycllist*{\listtmp}{10}\par\smallskip |
| 379 |
%storing |
| 380 |
\ctgetvaluefromcycllist{\listtmp}{-10}[\myelt]\myelt |
| 381 |
\end{DemoCode} |
| 382 |
|
| 383 |
\begin{DemoCode}{listing only} |
| 384 |
%adding, only printing |
| 385 |
\ctaddvalinlist*{values}{list} |
| 386 |
%adding and storing (overwrite) |
| 387 |
\ctaddvalinlist{values}{list} |
| 388 |
%removing, only printing |
| 389 |
\ctremovevalinlist*{value}{list} |
| 390 |
%removing and storing (overwrite) |
| 391 |
\ctremovevalinlist{value}{list} |
| 392 |
\end{DemoCode} |
| 393 |
|
| 394 |
\begin{DemoCode}{} |
| 395 |
%only printing |
| 396 |
\ctaddvalinlist*{3}{1,2,5,6}\\ |
| 397 |
%defining and adding |
| 398 |
\def\tmpaddlist{1,2,4,5,6} |
| 399 |
\ctaddvalinlist{3}{\tmpaddlist}\tmpaddlist\\ |
| 400 |
%analysing |
| 401 |
\readlist*\tmpADDlist{\tmpaddlist} |
| 402 |
\showitems{\tmpADDlist} |
| 403 |
\end{DemoCode} |
| 404 |
|
| 405 |
\begin{DemoCode}{} |
| 406 |
%only printing |
| 407 |
\ctremovevalinlist*{3}{1,2,3,6,3,1,5,7,3}\\ |
| 408 |
%defining and removing within \mytmplist |
| 409 |
\def\tmpremlist{1,2,3,6,3,1,5,7,3} |
| 410 |
\ctremovevalinlist{3}{\tmpremlist}\mytmplist\\ |
| 411 |
%analysing |
| 412 |
\readlist*\tmpREMlist{\mytmplist} |
| 413 |
\showitems{\tmpREMlist} |
| 414 |
\end{DemoCode} |
| 415 |
|
| 416 |
\subsection{Reverse} |
| 417 |
|
| 418 |
\begin{DemoCode}{listing only} |
| 419 |
%reversing, only printing |
| 420 |
\ctreverselist*{list} |
| 421 |
%reversing and storing (overwrite) |
| 422 |
\ctreverselist{list} |
| 423 |
\end{DemoCode} |
| 424 |
|
| 425 |
\begin{DemoCode}{} |
| 426 |
%only printing |
| 427 |
\ctreverselist*{14,10,15,11,9,10}\\ |
| 428 |
%reversing and storing |
| 429 |
%storing |
| 430 |
\ctreverselist{14,10,15,11,9,10}[\myreverse]\myreverse\\ |
| 431 |
%analysing |
| 432 |
\readlist*\tmpREVERSElist{\myreverse} |
| 433 |
\showitems{\tmpREVERSElist} |
| 434 |
\end{DemoCode} |
| 435 |
|
| 436 |
\subsection{Sub-list} |
| 437 |
|
| 438 |
\begin{DemoCode}{listing only} |
| 439 |
%extracting a sub-list, only printing (* = start or end of list) |
| 440 |
\ctsublist*{list}{begin}{end} |
| 441 |
%extracting a sub-list and storing into \macro (\mysublist by default) |
| 442 |
\ctsublist{list}{begin}{end}[\macro] |
| 443 |
\end{DemoCode} |
| 444 |
|
| 445 |
\begin{DemoCode}{} |
| 446 |
\def\mylist{10,20,30,40,50,60,70} |
| 447 |
%indices 2 to 5, only printing |
| 448 |
\ctsublist*{\mylist}{2}{5}\\ |
| 449 |
%from start to index 4, only printing |
| 450 |
\ctsublist*{\mylist}{*}{4}\\ |
| 451 |
%from index 3 to end, only printing |
| 452 |
\ctsublist*{\mylist}{3}{*}\\ |
| 453 |
%whole list (* on both sides), only printing |
| 454 |
\ctsublist*{\mylist}{*}{*} |
| 455 |
\end{DemoCode} |
| 456 |
|
| 457 |
\begin{DemoCode}{} |
| 458 |
\def\mylist{10,20,30,40,50,60,70} |
| 459 |
%storing sub-list [2,5] into \myresult |
| 460 |
\ctsublist{\mylist}{2}{5}[\myresult]Sub-list [2,5]: \myresult\\ |
| 461 |
%storing sub-list [*,3] into \myresultb |
| 462 |
\ctsublist{\mylist}{*}{3}[\myresultb]Sub-list [*,3]: \myresultb\\ |
| 463 |
%storing sub-list [5,*] into \myresultc |
| 464 |
\ctsublist{\mylist}{5}{*}[\myresultc]Sub-list [5,*]: \myresultc |
| 465 |
\end{DemoCode} |
| 466 |
|
| 467 |
\begin{DemoCode}{listing only} |
| 468 |
%slicing by formula (x variable), only printing |
| 469 |
\ctslicelist*{list}{formula} |
| 470 |
%slicing by formula and storing into \macro (\myslicelist by default) |
| 471 |
\ctslicelist{list}{formula}[\macro] |
| 472 |
\end{DemoCode} |
| 473 |
|
| 474 |
\begin{DemoCode}{} |
| 475 |
\def\mylist{10,20,30,40,50,60,70,80,90,100} |
| 476 |
%even indices (2*x), only printing |
| 477 |
\ctslicelist*{\mylist}{2*x}\\ |
| 478 |
%odd indices (2*x-1), only printing |
| 479 |
\ctslicelist*{\mylist}{2*x-1}\\ |
| 480 |
%formula 3*x+1, only printing |
| 481 |
\ctslicelist*{\mylist}{3*x+1}\\ |
| 482 |
%square indices (x^2), only printing |
| 483 |
\ctslicelist*{\mylist}{x^2} |
| 484 |
\end{DemoCode} |
| 485 |
|
| 486 |
\begin{DemoCode}{} |
| 487 |
\def\mylist{10,20,30,40,50,60,70,80,90,100} |
| 488 |
%storing slice with 2*x into \myresult |
| 489 |
\ctslicelist{\mylist}{2*x}[\myresult]Slice formula 2*x: \myresult\\ |
| 490 |
%storing slice with x^2 into \myresultb |
| 491 |
\ctslicelist{\mylist}{x^2}[\myresultb]Slice formula x\^{}2: \myresultb |
| 492 |
\end{DemoCode} |
| 493 |
|
| 494 |
\subsection{Transform} |
| 495 |
|
| 496 |
\begin{DemoCode}{listing only} |
| 497 |
%transforming a list through formula, only printing |
| 498 |
\cttransformlist*[round]{list}{formula} |
| 499 |
%transforming a list through formula and storing into \macro (\mytransformlist by default) |
| 500 |
\cttransformlist*[round]{list}{formula}[\macro] |
| 501 |
\end{DemoCode} |
| 502 |
|
| 503 |
\begin{DemoCode}{} |
| 504 |
\def\mylist{10,20,30,40,50,60,70,80,90,100} |
| 505 |
%transform with 3x+1, only printing |
| 506 |
\cttransformlist*{\mylist}{3*x+1}\\ |
| 507 |
%transform with x^2, only printing |
| 508 |
\cttransformlist*{\mylist}{x^2}\\ |
| 509 |
%formula sqrt(x), only printing |
| 510 |
\cttransformlist*{10,20,30}{sqrt(x)}\\ |
| 511 |
%formula round(sqrt(x),3), only printing |
| 512 |
\cttransformlist*[3]{\mylist}{sqrt(x)}\\ |
| 513 |
\end{DemoCode} |
| 514 |
|
| 515 |
\begin{DemoCode}{} |
| 516 |
\def\mylist{10,20,30,40,50,60,70,80,90,100} |
| 517 |
%storing transform with 2*x into \myresult |
| 518 |
\cttransformlist{\mylist}{2*x}[\myresult]Transform formula 2*x:\\ |
| 519 |
\myresult\\ |
| 520 |
%storing transform with x^2-sqrt(x) into \myresultb |
| 521 |
\cttransformlist[1]{\mylist}{x^2-sqrt(x)}[\myresultb]Transform formula x\^{}2-sqrt(x):\\ |
| 522 |
\myresultb |
| 523 |
\end{DemoCode} |
| 524 |
|
| 525 |
\subsection{Remove duplicate entries} |
| 526 |
|
| 527 |
\begin{DemoCode}{listing only} |
| 528 |
%removing duplicates, only printing |
| 529 |
\ctuniqlist*{list} |
| 530 |
%removing duplicates with optional sorting [asc] or [des] |
| 531 |
\ctuniqlist*[asc]{list} |
| 532 |
\ctuniqlist*[des]{list} |
| 533 |
%removing duplicates and storing into \macro (\myuniqlist by default) |
| 534 |
\ctuniqlist{list}[\macro] |
| 535 |
\ctuniqlist[asc]{list}[\macro] |
| 536 |
\ctuniqlist[des]{list}[\macro] |
| 537 |
\end{DemoCode} |
| 538 |
|
| 539 |
\begin{DemoCode}{} |
| 540 |
\def\mylist{1,2,3,2,4,3,5,1} |
| 541 |
%without sorting, only printing |
| 542 |
\ctuniqlist*{\mylist}\\ |
| 543 |
%with ascending sort, only printing |
| 544 |
\ctuniqlist*[asc]{\mylist}\\ |
| 545 |
%with descending sort, only printing |
| 546 |
\ctuniqlist*[des]{\mylist} |
| 547 |
\end{DemoCode} |
| 548 |
|
| 549 |
\begin{DemoCode}{} |
| 550 |
\def\mylist{5,2,9,2,1,5,7,3,1} |
| 551 |
%storing without sort into \myuniq |
| 552 |
\ctuniqlist{\mylist}[\myuniq]No sort: \myuniq\\ |
| 553 |
%storing with [asc] into \myuniqasc |
| 554 |
\ctuniqlist[asc]{\mylist}[\myuniqasc]With [asc]: \myuniqasc\\ |
| 555 |
%storing with [des] into \myuniqdes |
| 556 |
\ctuniqlist[des]{\mylist}[\myuniqdes]With [des]: \myuniqdes |
| 557 |
\end{DemoCode} |
| 558 |
|
| 559 |
\section{With two lists} |
| 560 |
|
| 561 |
\subsection{Intersection} |
| 562 |
|
| 563 |
\begin{DemoCode}{listing only} |
| 564 |
%intersection of two lists, only printing |
| 565 |
\ctintersectlists*{list1}{list2} |
| 566 |
%intersection with optional sorting [asc] or [des], only printing |
| 567 |
\ctintersectlists*[asc]{list1}{list2} |
| 568 |
\ctintersectlists*[des]{list1}{list2} |
| 569 |
%intersection and storing into \macro (\myintersectlist by default) |
| 570 |
\ctintersectlists{list1}{list2}[\macro] |
| 571 |
\ctintersectlists[asc]{list1}{list2}[\macro] |
| 572 |
\ctintersectlists[des]{list1}{list2}[\macro] |
| 573 |
\end{DemoCode} |
| 574 |
|
| 575 |
\begin{DemoCode}{} |
| 576 |
\def\mylistA{1,3,5,7,9,11,13} |
| 577 |
\def\mylistB{3,6,9,12,15,7,1} |
| 578 |
%without sorting, only printing |
| 579 |
\ctintersectlists*{\mylistA}{\mylistB}\\ |
| 580 |
%with ascending sort, only printing |
| 581 |
\ctintersectlists*[asc]{\mylistA}{\mylistB}\\ |
| 582 |
%with descending sort, only printing |
| 583 |
\ctintersectlists*[des]{\mylistA}{\mylistB} |
| 584 |
\end{DemoCode} |
| 585 |
|
| 586 |
\begin{DemoCode}{} |
| 587 |
\def\mylistA{4,8,2,6,10,3,7} |
| 588 |
\def\mylistB{2,5,8,11,6,3} |
| 589 |
%storing without sort into \myinter |
| 590 |
\ctintersectlists{\mylistA}{\mylistB}[\myinter]No sort: \myinter\\ |
| 591 |
%storing with [asc] into \myinterasc |
| 592 |
\ctintersectlists[asc]{\mylistA}{\mylistB}[\myinterasc]With [asc]: \myinterasc\\ |
| 593 |
%storing with [des] into \myinterdes |
| 594 |
\ctintersectlists[des]{\mylistA}{\mylistB}[\myinterdes]With [des]: \myinterdes |
| 595 |
\end{DemoCode} |
| 596 |
|
| 597 |
\subsection{Union (merge)} |
| 598 |
|
| 599 |
\begin{DemoCode}{listing only} |
| 600 |
%union of two lists (no duplicates), only printing |
| 601 |
\ctmergelists*{list1}{list2} |
| 602 |
%union with optional sorting [asc] or [des], only printing |
| 603 |
\ctmergelists*[asc]{list1}{list2} |
| 604 |
\ctmergelists*[des]{list1}{list2} |
| 605 |
%union and storing into \macro (\mymergelist by default) |
| 606 |
\ctmergelists{list1}{list2}[\macro] |
| 607 |
\ctmergelists[asc]{list1}{list2}[\macro] |
| 608 |
\ctmergelists[des]{list1}{list2}[\macro] |
| 609 |
\end{DemoCode} |
| 610 |
|
| 611 |
\begin{DemoCode}{} |
| 612 |
\def\mylistA{1,3,5,7,9} |
| 613 |
\def\mylistB{3,6,9,12,15} |
| 614 |
%without sorting, only printing |
| 615 |
\ctmergelists*{\mylistA}{\mylistB}\\ |
| 616 |
%with ascending sort, only printing |
| 617 |
\ctmergelists*[asc]{\mylistA}{\mylistB}\\ |
| 618 |
%with descending sort, only printing |
| 619 |
\ctmergelists*[des]{\mylistA}{\mylistB} |
| 620 |
\end{DemoCode} |
| 621 |
|
| 622 |
\begin{DemoCode}{} |
| 623 |
\def\mylistA{4,8,2,6,10} |
| 624 |
\def\mylistB{2,5,8,11,6} |
| 625 |
%storing without sort into \mymerge |
| 626 |
\ctmergelists{\mylistA}{\mylistB}[\mymerge]No sort: \mymerge\\ |
| 627 |
%storing with [asc] into \mymergeasc |
| 628 |
\ctmergelists[asc]{\mylistA}{\mylistB}[\mymergeasc]With [asc]: \mymergeasc\\ |
| 629 |
%storing with [des] into \mymergedes |
| 630 |
\ctmergelists[des]{\mylistA}{\mylistB}[\mymergedes]With [des]: \mymergedes |
| 631 |
\end{DemoCode} |
| 632 |
|
| 633 |
\subsection{Difference} |
| 634 |
|
| 635 |
\begin{DemoCode}{listing only} |
| 636 |
%difference A\B (elements in A absent from B), only printing |
| 637 |
\ctdifflist*{listA}{listB} |
| 638 |
%difference with optional sorting [asc] or [des], only printing |
| 639 |
\ctdifflist*[asc]{listA}{listB} |
| 640 |
\ctdifflist*[des]{listA}{listB} |
| 641 |
%difference and storing into \macro (\mydifflist by default) |
| 642 |
\ctdifflist{listA}{listB}[\macro] |
| 643 |
\ctdifflist[asc]{listA}{listB}[\macro] |
| 644 |
\ctdifflist[des]{listA}{listB}[\macro] |
| 645 |
\end{DemoCode} |
| 646 |
|
| 647 |
\begin{DemoCode}{} |
| 648 |
\def\mylistA{1,3,5,7,9,11,13} |
| 649 |
\def\mylistB{3,7,11,15,19} |
| 650 |
%without sorting, only printing |
| 651 |
\ctdifflist*{\mylistA}{\mylistB}\\ |
| 652 |
%with ascending sort, only printing |
| 653 |
\ctdifflist*[asc]{\mylistA}{\mylistB}\\ |
| 654 |
%with descending sort, only printing |
| 655 |
\ctdifflist*[des]{\mylistA}{\mylistB} |
| 656 |
\end{DemoCode} |
| 657 |
|
| 658 |
\begin{DemoCode}{} |
| 659 |
\def\mylistA{4,8,2,6,10,3,7} |
| 660 |
\def\mylistB{2,5,8,11,6,3} |
| 661 |
%storing without sort into \mydiff |
| 662 |
\ctdifflist{\mylistA}{\mylistB}[\mydiff]No sort: \mydiff\\ |
| 663 |
%storing with [asc] into \mydiffasc |
| 664 |
\ctdifflist[asc]{\mylistA}{\mylistB}[\mydiffasc]With [asc]: \mydiffasc\\ |
| 665 |
%storing with [des] into \mydiffdes |
| 666 |
\ctdifflist[des]{\mylistA}{\mylistB}[\mydiffdes]With [des]: \mydiffdes |
| 667 |
\end{DemoCode} |
| 668 |
|
| 669 |
\subsection{Symmetric difference} |
| 670 |
|
| 671 |
\begin{DemoCode}{listing only} |
| 672 |
%symmetric difference (elements in A or B but not both), only printing |
| 673 |
\ctsymdifflist*{listA}{listB} |
| 674 |
%symmetric difference with optional sorting [asc] or [des], only printing |
| 675 |
\ctsymdifflist*[asc]{listA}{listB} |
| 676 |
\ctsymdifflist*[des]{listA}{listB} |
| 677 |
%symmetric difference and storing into \macro (\mysymdifflist by default) |
| 678 |
\ctsymdifflist{listA}{listB}[\macro] |
| 679 |
\ctsymdifflist[asc]{listA}{listB}[\macro] |
| 680 |
\ctsymdifflist[des]{listA}{listB}[\macro] |
| 681 |
\end{DemoCode} |
| 682 |
|
| 683 |
\begin{DemoCode}{} |
| 684 |
\def\mylistA{1,3,5,7,9,11,13} |
| 685 |
\def\mylistB{3,7,11,15,19} |
| 686 |
%without sorting, only printing |
| 687 |
\ctsymdifflist*{\mylistA}{\mylistB}\\ |
| 688 |
%with ascending sort, only printing |
| 689 |
\ctsymdifflist*[asc]{\mylistA}{\mylistB}\\ |
| 690 |
%with descending sort, only printing |
| 691 |
\ctsymdifflist*[des]{\mylistA}{\mylistB} |
| 692 |
\end{DemoCode} |
| 693 |
|
| 694 |
\begin{DemoCode}{} |
| 695 |
\def\mylistA{4,8,2,6,10,3,7} |
| 696 |
\def\mylistB{2,5,8,11,6,3} |
| 697 |
%storing without sort into \mysymdiff |
| 698 |
\ctsymdifflist{\mylistA}{\mylistB}[\mysymdiff]No sort: \mysymdiff\\ |
| 699 |
%storing with [asc] into \mysymdiffasc |
| 700 |
\ctsymdifflist[asc]{\mylistA}{\mylistB}[\mysymdiffasc]With [asc]: \mysymdiffasc\\ |
| 701 |
%storing with [des] into \mysymdiffdes |
| 702 |
\ctsymdifflist[des]{\mylistA}{\mylistB}[\mysymdiffdes]With [des]: \mysymdiffdes |
| 703 |
\end{DemoCode} |
| 704 |
|
| 705 |
\section{Macros with testing} |
| 706 |
|
| 707 |
\subsection{Value in list ?} |
| 708 |
|
| 709 |
\begin{DemoCode}{listing only} |
| 710 |
%testing if value is in list, with boolean result in \macro (\resisinlist by default) |
| 711 |
\ctboolvalinlist{value}{list}[\macro] |
| 712 |
%conditionnal test if value is in list, according to xint syntax |
| 713 |
\cttestifvalinlist{3}{0,1,2,3}{true}{false} |
| 714 |
\end{DemoCode} |
| 715 |
|
| 716 |
\begin{DemoCode}{} |
| 717 |
%test with xint syntax |
| 718 |
\cttestifvalinlist{-1}{0,1,2,3}{true}{false}\\ |
| 719 |
%test with xint syntax |
| 720 |
\cttestifvalinlist{3}{0,1,2,3}{true}{false}\\ |
| 721 |
%boolean macro |
| 722 |
\def\myteslist{0,5,10,5,6,9,7,8} |
| 723 |
\ctboolvalinlist{5}{\myteslist}[\resisinlist]\resisinlist |
| 724 |
\end{DemoCode} |
| 725 |
|
| 726 |
\subsection{Count value} |
| 727 |
|
| 728 |
\begin{DemoCode}{listing only} |
| 729 |
%counting value, only printing |
| 730 |
\ctcountvalinlist*{value}{list} |
| 731 |
%counting value, with result in \macro (\rescount by default) |
| 732 |
\ctcountvalinlist{value}{list}[\macro] |
| 733 |
\end{DemoCode} |
| 734 |
|
| 735 |
\begin{DemoCode}{} |
| 736 |
%only printing |
| 737 |
\ctcountvalinlist*{8}{1,2,3,4,5,6,6,7,8,8,8,9}\\ |
| 738 |
%storing |
| 739 |
\def\tmpcountlist{1,2,3,4,5,6,6,7,8,8,8,9} |
| 740 |
\ctcountvalinlist{6}{\tmpcountlist}[\rescountsix]\rescountsix\\ |
| 741 |
\ctcountvalinlist{10}{\tmpcountlist}[\rescountten]\rescountten |
| 742 |
\end{DemoCode} |
| 743 |
|
| 744 |
\subsection{Get index} |
| 745 |
|
| 746 |
\begin{DemoCode}{listing only} |
| 747 |
%index value (first occurency), only printing |
| 748 |
\ctgetindexfromlist*{value}{list} |
| 749 |
%index value (first occurency), with result in \macro (\resmyindex by default) |
| 750 |
\ctgetindexfromlist{value}{list}[\macro] |
| 751 |
\end{DemoCode} |
| 752 |
|
| 753 |
\begin{DemoCode}{} |
| 754 |
%only printing |
| 755 |
\ctgetindexfromlist*{8}{1,2,3,4,5,6,6,7,8,8,8,9}\\ |
| 756 |
%storing |
| 757 |
\def\tmpindexlist{1,2,3,4,5,6,6,7,8,8,8,9} |
| 758 |
\ctgetindexfromlist{6}{\tmpindexlist}[\resindexsix]\resindexsix\\ |
| 759 |
\ctgetindexfromlist{10}{\tmpindexlist}[\resindexten]\resindexten |
| 760 |
\end{DemoCode} |
| 761 |
|
| 762 |
\pagebreak |
| 763 |
|
| 764 |
\section{History} |
| 765 |
|
| 766 |
\texttt{0.20b: Extract element with cyclic version of list} |
| 767 |
|
| 768 |
\texttt{0.20a: Sub-list extraction + transform list + merge/intersection + improvements} |
| 769 |
|
| 770 |
\texttt{0.1.9: Improvements with \hologo{LaTeX3}, tks to \textit{ankaa3908}} |
| 771 |
|
| 772 |
\texttt{0.1.8: Get index from value} |
| 773 |
|
| 774 |
\texttt{0.1.7: Improvements with \hologo{LaTeX3}} |
| 775 |
|
| 776 |
\texttt{0.1.6: Initial version,code written in \hologo{LaTeX3}} |
| 777 |
|
| 778 |
\section{The code} |
| 779 |
|
| 780 |
\DemoCodeFile{commalists-tools-l3.sty} |
| 781 |
|
| 782 |
\end{document} |