Debian Codegraph @

texmf-dist/doc/latex/randintlist/randintlist-l3-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{randintlist-l3}
11 \usepackage{listofitems,xintexpr}
12 \usepackage{fancyvrb}
13 \usepackage{fancyhdr}
14 \usepackage{tabularray}
15 \usepackage{fontawesome5}
16 \fancyhf{}
17 \renewcommand{\headrulewidth}{0pt}
18 \lfoot{\sffamily\small [randintlist-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.20a}
32 \def\TPdate{20/02/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={randintlist-l3},%
50 keywordstyle={\color{violet}},%
51 classoffset=2,%
52 alsoletter={-},%
53 morekeywords={\rdlgenlist,\rdlgetitem},%
54 keywordstyle={\color{green!50!black}},%
55 classoffset=3,%
56 morekeywords={min,max,nb,seed,sort,sep,repeat,excluded},%
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,tikz,calc,simplekv,graphicx,\readlist,\showitems,\xintFor,\xintSeq},%
75 alsoletter={-},%
76 keywordstyle={\color{blue}},%
77 classoffset=1,%
78 alsoletter={-},%
79 morekeywords={randintlist-l3},%
80 keywordstyle={\color{violet}},%
81 classoffset=2,%
82 alsoletter={-},%
83 morekeywords={\rdlgenlist,\rdlgetitem},%
84 keywordstyle={\color{green!50!black}},%
85 classoffset=3,%
86 morekeywords={min,max,nb,seed,sort,sep,repeat,excluded},%
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=4,%
104 commentstyle={\itshape\color{gray}},%
105 lastline=246
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{randintlist-l3}}\\
127 \\
128 {\Large\hologo{LaTeX3}}\\
129 \\
130 {\LARGE Creating random integer number lists,} \\
131 {\LARGE with multiple numbers or not,} \\
132 {\LARGE sorted or not.} \\
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/randintlist}} \\
146 \end{tabular}
147 \end{center}
148
149 \hrule
150
151 \vfill
152
153 \begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
154 10 numbers, between 1 and 100, without repetition:
155
156 \hfill\rdlgenlist[min=1,max=100,nb=10,repeat=false]{\mylist}\textcolor{red}{\mylist}\hfill~
157
158 The 5th value is:
159
160 \hfill\textcolor{blue}{\rdlgetitem*{\mylist}{5}}\hfill~
161 \end{tcolorbox}
162
163 \begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
164 10 numbers, between 1 and 100, without multiples of 5:
165
166 \hfill\rdlgenlist[min=1,max=100,nb=10,excluded={5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100}]{\mylist}\textcolor{olive}{\mylist}\hfill~
167
168 The 9th value is:
169
170 \hfill\textcolor{purple}{\rdlgetitem*{\mylist}{9}}\hfill~
171 \end{tcolorbox}
172
173 \begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
174 15 numbers, between 1 and 20, with repetition:
175
176 \hfill\rdlgenlist[min=1,max=20,nb=15,repeat]{\mylist}\textcolor{red}{\mylist}\hfill~
177
178 The last value is:
179
180 \hfill\textcolor{blue}{\rdlgetitem*{\mylist}{-1}}\hfill~
181 \end{tcolorbox}
182
183 \begin{tcolorbox}[colframe=lightgray,colback=lightgray!5]
184 6 sorted numbers, between 1 and 51, without repetition:
185
186 \hfill\rdlgenlist[min=1,max=51,nb=6,sort=asc,repeat=false]{\mylist}ascending: \textcolor{red}{\mylist}\hfill~
187
188 \hfill\rdlgenlist[min=1,max=51,nb=6,sort=des,repeat=false]< {>} >{\mylist}descending: \textcolor{red}{\mylist}\hfill~
189 \end{tcolorbox}
190
191 \vfill~
192
193 \hrule
194
195 \medskip
196
197 \emph{%
198 1. The \textsf{luarandom} package do the same things, but with the obligation to compile with \hologo{LuaLaTeX}.
199 }
200
201 \emph{%
202 2. The \textsf{tuple} package is so much better\ldots take a look\ldots
203 }
204
205 \medskip
206
207 \hrule
208
209 \vspace*{5mm}
210
211 \pagebreak
212
213 \phantomsection
214
215 \hypertarget{matoc}{}
216
217 \tableofcontents
218
219 \vspace*{5mm}
220
221 %\hrule
222
223 \pagebreak
224
225 \section{Loading, useful packages}
226
227 In order to load \texttt{randintlist-l3}, simply use:
228
229 \begin{DemoCode}{listing only}
230 \usepackage{randintlist-l3}
231 \end{DemoCode}
232
233 All code is written in \hologo{LaTeX3}, so no extra packages are needed.
234
235 \section{The Macros}
236
237 \subsection{Global usage}
238
239 Package \texttt{randintlist-l3} supports the creation of random integer number lists where a number will appear only once or multiple times. Generated lists can be used with \texttt{listofitems}.
240
241 \medskip
242
243 {\small\faLightbulb} Macros are prefixed with \ShowCode{\\rdl...} (for \textsf{\textbf{\underline{r}}an\textbf{\underline{d}}int\textbf{\underline{l}}ist}).
244
245 \subsection{Generate the list}
246
247 \begin{DemoCode}{listing only}
248 %generate list
249 \rdlgenlist[keys]{\macro}
250 \end{DemoCode}
251
252 Available keys are:
253
254 \begin{itemize}
255 \item \ShowCode{min}: minimum value (default \ShowCode{1});
256 \item \ShowCode{max}: maximum value (default \ShowCode{100});
257 \item \ShowCode{nb}: number of values (default \ShowCode{10});
258 \item \ShowCode{sort}: sorting options, within \ShowCode{no/asc/dec} (default \ShowCode{no});
259 \item \ShowCode{repeat}: boolean to authorize repeating values (default \ShowCode{true});
260 \item \ShowCode{excluded}: list of excluded values (default \ShowCode{empty});
261 \item \ShowCode{seed}: random seed value according to used packages (default \ShowCode{-1}).
262 \end{itemize}
263
264 \begin{DemoCode}{}
265 %default values
266 \rdlgenlist{\mylistA}\mylistA
267 \end{DemoCode}
268
269 \begin{DemoCode}{}
270 %10 between 1 and 50, with ascending
271 \rdlgenlist[sort=asc,min=1,max=50,nb=10,repeat=false]{\mylistB}\mylistB
272 \end{DemoCode}
273
274 \begin{DemoCode}{}
275 %15 between 1 and 50, with ascending and repetitions allowed
276 \rdlgenlist[sort=asc,min=1,max=50,nb=15]{\mylistC}\mylistC
277 \end{DemoCode}
278
279 \begin{DemoCode}{}
280 %15 between 1 and 50, without multiples of 5
281 \rdlgenlist[%
282 sort=asc,min=1,max=50,nb=15,%
283 excluded={5,10,15,20,25,30,35,40,45,50}]%
284 {\mylistC}\mylistC
285 \end{DemoCode}
286
287 \begin{DemoCode}{}
288 %list used with listofitems
289 \rdlgenlist{\mylistD}\mylistD\par
290 \readlist*\mylistused{\mylistD}\showitems{\mylistused}\par
291 \mylistused[1]; \mylistused[-1]
292 \end{DemoCode}
293
294 \begin{DemoCode}{}
295 %list, with alt sep, used with listofitems
296 \rdlgenlist<+>{\mylistZ}\mylistZ\par
297 \setsepchar{+}\readlist*\mylistused{\mylistZ}\showitems{\mylistused}\par
298 \mylistused[1]; \mylistused[-1]
299 \end{DemoCode}
300
301 \subsection{Accessing elements}
302
303 \begin{DemoCode}{listing only}
304 %accessing item
305 \rdlgetitem(*){\macro}{index}[\macrores]
306 \end{DemoCode}
307
308 \begin{DemoCode}{}
309 %with default keys
310 \rdlgenlist{\mylistE}raw list: \mylistE\par
311 items list:\par
312 \xintFor* #1 in {\xintSeq{1}{6}}\do{\rdlgetitem*{\mylistE}{#1}\par}
313 first element: \rdlgetitem*{\mylistE}{1}\par
314 \end{DemoCode}
315
316 \begin{DemoCode}{}
317 \rdlgetitem{\mylistE}{3}[\myres]%
318 third element: \myres
319 \end{DemoCode}
320
321 \pagebreak
322
323 \section{History}
324
325 \texttt{0.20a: Improvements with \hologo{LaTeX3}}
326
327 \texttt{0.1.6: Improvements with \hologo{LaTeX3}}
328
329 \texttt{0.1.5: Initial version}
330
331 \section{The code}
332
333 \DemoCodeFile{randintlist-l3.sty}
334
335 \end{document}