Debian Codegraph @

texmf-dist/source/latex-dev/latex-lab/latex-lab-enumitem.dtx

raw
1 % \iffalse meta-comment
2
3 %% File: latex-lab-block.dtx (C) Copyright 2021-2026 LaTeX Project
4 %
5 % It may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License (LPPL), either version 1.3c of this
7 % license or (at your option) any later version. The latest version
8 % of this license is in the file
9 %
10 % https://www.latex-project.org/lppl.txt
11 %
12 \def\ltlabenumdate{2026-04-21}
13 \def\ltlabenumversion{0.80f}
14
15 %<*driver>
16 \DocumentMetadata{tagging=on,pdfstandard=ua-2}
17 \documentclass[kernel]{l3in2edoc}
18
19 \usepackage{longtable,tikz}
20 \EnableCrossrefs
21 \CodelineIndex
22
23 \usepackage{todonotes}
24
25 \begin{document}
26 \DocInput{latex-lab-enumitem.dtx}
27 \end{document}
28 %</driver>
29 %
30 % \fi
31 %
32 %
33 % \title{The \textsf{latex-lab-enumitem} package\\
34 % Emulating enumitem}
35 % \author{\LaTeX{} Project\thanks{Initial implementation done by Ulrike Fischer}}
36 % \date{v\ltlabenumversion\ \ltlabenumdate}
37 %
38 % \maketitle
39 %
40 % \newcommand{\xt}[1]{\textsl{\textsf{#1}}}
41 % \newcommand{\TODO}[1]{\textbf{[TODO:} #1\textbf{]}}
42 % \newcommand{\docclass}{document class \marginpar{\raggedright document class
43 % customizations}}
44 %
45 % \newcommand\insttype[1]{\texttt{#1}}
46 %
47 %
48 % \providecommand\hook[1]{\texttt{#1}}
49 %
50 % \ProvideDocumentCommand\fmi{sO{}m}
51 % {\IfBooleanTF{#1}{\todo[inline,#2]{#3}}^^A
52 % {\todo[#2]{#3}}}
53 %
54 %
55 %
56 % \begin{abstract}
57 % The following code implements an emulation of \pkg{enumitem} usable with the Tagging Support Code.
58 % It does \emph{not} emulate every key and command of enumitem. Also syntax and behaviour
59 % can differ in place.
60 % \end{abstract}
61 %
62 %
63 % \section{Introduction}
64 %
65 % The \pkg{enumitem} package offers customizable and enhanced list environments
66 % but is not compatible with the Tagging Support Code where lists are
67 % reimplemented with templates.
68 %
69 % The following code partly emulates \pkg{enumitem} and should be loaded
70 % instead of the package.
71 %
72 % \section{Key emulation}
73 %
74 % A large part of the \pkg{enumitem} functionality is provided through keys. Such keys
75 % can be set in the optional argument of single lists and globally for some or all
76 % lists in the \cs{setlist} command. Some keys are simple interfaces to list parameters,
77 % other have quite complicated effects, e.g. if they force recalculations of dependant
78 % parameters.
79 %
80 % With the new \LaTeX implementation lists do have an optional argument too
81 % which process a key-value list.
82 % The key names differ to the one of \pkg{enumitem} but in a number of cases a
83 % simple mapping is possible. The \LaTeX{} key names are noted in the following
84 % tabular in the second column.
85 % They can be used instead of the \pkg{enumitem} keys (and will be a bit faster).
86 % The third column shows if the \pkg{enumitem} key has been already emulated and is usable
87 % in the optional argument. The fourth column shows if it is usable in \cs{setlist}.
88 %
89 %
90 % \begin{longtable}{>{\ttfamily}l>{\ttfamily}lcll}
91 % \caption{List of enumitem keys}\\
92 % \rmfamily \pkg{enumitem} key & \rmfamily \LaTeX{} key & opt.\ arg. & \cs{setlist} & comment\\ \hline \endhead
93 % label & \rmfamily (related: \texttt{item-label}) & & &see key description\\
94 % label*\\
95 % ref \\
96 % font,format & label-format & yes & & see key description!! \\
97 % format\\
98 % align & label-align & yes & & see key description\\
99 % topsep & begin-vspace & yes & & \\
100 % partopsep & begin-extra-vspace & yes & & \\
101 % parsep & para-vspace & yes & & \\
102 % itemsep & item-vspace & yes & & \\
103 % labelindent\\
104 % labelindent*\\
105 % leftmargin & left-margin & & & see key description\\
106 % rightmargin & right-margin & & & see key description\\
107 % listparindent & para-indent & & & see key description\\
108 % itemindent & item-indent & & & see key description\\
109 % labelsep & label-sep & & & see key description\\
110 % labelsep* \\
111 % labelwidth & label-width & & & see key description \\
112 % left \\
113 % widest \\
114 % widest*\\
115 % start & start & yes & ? \\
116 % resume & resume & yes & ? & see key description\\
117 % resume* \\
118 % series\\
119 % beginpenalty & begin-penalty & yes & ?\\
120 % midpenalty & item-penalty & yes & ? \\
121 % endpenalty & end-penalty & yes & ?\\
122 % before \\
123 % before* \\
124 % after\\
125 % after*\\
126 % first\\
127 % first*\\
128 % style\\
129 % noitemsep & \textit{meta-key} & yes \\
130 % nosep & \textit{meta-key} & yes \\
131 % wide & & partly & \\
132 % itemjoin\\
133 % itemjoin*\\
134 % afterlabel\\
135 % mode\\
136 % \end{longtable}
137 %
138 % \section{Package options}
139 %
140 % \pkg{enumitem} has a number of package options, but none of them will
141 % be supported by the emulation: adding support for the \pkg{enumerate} syntax
142 % (\texttt{shortlabels}) is not planed; inline lists are not yet implemented
143 % but once they are they will be available always.
144 %
145 % \begin{longtable}{lll}
146 % \caption{List of enumitem package options}\\
147 % \pkg{enumitem} option \\\hline\endhead
148 % shortlabels & \\
149 % inline & \\
150 % ignoredisplayed & \\
151 % series=override & \\
152 % sizes & \\
153 % loadonly &
154 % \end{longtable}
155 %
156 % \section{Commands}
157 %
158 % \begin{longtable}{lll}
159 % \caption{List of enumitem user commands}\\
160 % name & emulated & comment\\\hline\endhead
161 % \cs{SetLabelAlign}\\
162 % \cs{DrawEnumitemLabel} \\
163 % \cs{labelindent}\\
164 % {\cs{EnumitemId}}\\
165 % {\cs{SetEnumitemKey}} & yes \\
166 % {\cs{SetEnumitemValue}}\\
167 % {\cs{SetEnumerateShortLabel}} \\
168 % \cs{newlist} & yes \\
169 % \cs{renewlist}\\
170 % \cs{setlist} & yes & no size-dependent settings\\
171 % \cs{setlistdepth}\\
172 % \cs{AddEnumerateCounter}\\
173 % \cs{restartlist}\\
174 % \cs{SetEnumitemSize}
175 % \end{longtable}
176 %
177 % \section{Calculating values}
178 %
179 % When setting up the dimension of lists the values related to the left margin and
180 % placement of the label are typically the most challenging as four dimensions are involved
181 % (which can be negative). \pkg{enumitem} introduces a fifth dimension \cs{labelindent}.
182 %
183 % \begin{tikzpicture}[alt=List layout]
184 % \coordinate(leftmargin) at (0,0);
185 % \coordinate(labelleft) at (1,0);
186 % \coordinate(labelright) at (4,14pt);
187 % \draw (labelleft) rectangle (labelright);
188 % \draw [<->] ([yshift=-5pt]labelleft) --++(3,0) node[below,midway]{\texttt{\textbackslash labelwidth}};
189 % \draw[<->]([yshift=-1cm]leftmargin)--++(6,0)node[below,midway]{\texttt{\textbackslash leftmargin}};
190 % \draw[<->](labelright)--++(2,0)node[above,midway]{\texttt{\textbackslash labelsep}};
191 % \draw[<->](5,-5pt)--++(1,0)node[below]{\texttt{\textbackslash itemindent}};
192 % \draw(5,0)--++(0,-2)--++(5,0)--++(0,2cm+14pt)--++(-4,0)--++(0,-14pt)--cycle;
193 % \draw[<->](0,5pt)--++(1,0)node[above left]{\textit{\textbackslash labelindent}};
194 % \end{tikzpicture}
195 %
196 % The relation between the five values is set through the following equation:
197 %
198 % \verb!\labelindent + \labelwidth + \labelsep = \leftmargin + \itemindent!
199 %
200 % So obviously one of the dimensions is redundant and can be calculated if the others
201 % are given. By default \pkg{enumitem} calculates the new, \enquote{fake} dimension
202 % \cs{labelindent} but it is possible to give \cs{labelindent} a specific value
203 % and declare that another one is calculated by using \texttt{!} as value.
204 %
205 %
206 % Calculation should happen after all keys are set. The code here therefore executes a
207 % key \texttt{calculate} in the list code which looks which key is currently the dependant
208 % one and calculates its value.
209 %
210 % \pkg{enumitem} also offers an option to calculate \cs{labelwidth} based on the widest
211 % entry (which can be declared with the \texttt{widest} key) by using a star \texttt{*} as
212 % value.
213 %
214 % \section{Alignment}
215 %
216 %
217 %
218 % \begin{macrocode}
219 %<*package>
220 % \end{macrocode}
221 %
222 % \section{Implementation}
223 % \begin{macrocode}
224 \ProvidesExplPackage {latex-lab-enumitem} {\ltlabenumdate} {\ltlabenumversion}
225 {Emulating enumitem}
226 % \end{macrocode}
227 %
228 %
229 %
230 % \subsection{Key emulation}
231 %
232 % \subsubsection{\texttt{label}}
233 %
234 % \fmi{check all this code}
235 %
236 % The key \texttt{item-label} from the new \LaTeX{} list code
237 % changes the label representation from e.g. \cs{labelenumi}
238 % to the key value. Internally the representation of the current list is stored in
239 % \cs{l__block_item_label_tl}. It does not change \cs{labelenumi}, \cs{theenumi} or
240 % \cs{p@enumi} and so also doesn't affect references.
241 %
242 % The key \texttt{label} from \pkg{enumitem} works quite differently: it changes
243 % the label representation command \cs{labelenumi}, the counter representation
244 % \cs{theenumi} and sets \cs{p@enumi} to empty. So by default the reference is identical
245 % to the label representation and if a different reference is wanted it must be set
246 % with the \texttt{ref} key. To allow to use \cs{labelenumi} in nested list to create
247 % chained labels enumitem replaces all \verb+\roman*+ by \verb+\roman{enumi}+ (and similar
248 % for the other counter representations). The replacement code uses expansion and
249 % so enumitem will error if the star is used with an unknown counter representation like
250 % \verb+label=\fnsymbol*+ or \cs{alphalph}. Such unknown
251 % counter representation must first be added with \cs{AddEnumerateCounter}.
252 %
253 % The new code is less fragile. Counter representation must only be declared with \cs{AddEnumerateCounter}
254 % if the star-counter is used outside the current list (e.g. with the \texttt{label*} key.
255 %
256 % \begin{macrocode}
257 %<@@=block> % we might want a different module in the end
258 % \end{macrocode}
259 %
260 % At first a rather crude (slow) method to replace
261 % e.g. \verb+\roman*+ by \verb+\roman{enumi}+
262 % in the label representation. TODO: speed up.
263 %
264 % \begin{macrocode}
265 \clist_new:N \l_@@_normalize_cnt_clist
266 \clist_set:Nn \l_@@_normalize_cnt_clist
267 {\alph,\Alph,\roman,\Roman,\arabic,\fnsymbol}
268 % \end{macrocode}
269 % This command should only be used if \cs{l_@@_counter_tl} is not empty!
270 % \begin{macrocode}
271 \cs_new:Npn\@@_normalize_label:N #1
272 {
273 \clist_map_inline:Nn\l_@@_normalize_cnt_clist
274 {
275 \tl_replace_all:Nne#1 {##1*}{\exp_not:N##1{\l_@@_counter_tl}}
276 }
277 }
278 \cs_generate_variant:Nn\@@_normalize_label:N{c}
279 % \end{macrocode}
280 %
281 % \begin{macrocode}
282 \keys_define:nn{template/list/std}
283 {
284 label .code:n =
285 {
286 \tl_if_empty:NTF\l_@@_counter_tl
287 {
288 \tl_if_eq:NnTF\l_@@_inner_instance_tl{itemize}
289 {
290 \tl_set:cn{labelitem\int_to_roman:n{\l_@@_inner_level_counter_tl}}{#1}
291 }
292 {
293 \tl_set:cn{label\l_@@_inner_instance_tl\int_to_roman:n{\l_@@_inner_level_counter_tl}}{#1}
294 }
295 }
296 {
297 \tl_set:cn{label\l_@@_counter_tl}{#1}
298 \@@_normalize_label:c{label\l_@@_counter_tl}
299 \tl_set_eq:cc{the\l_@@_counter_tl}{label\l_@@_counter_tl}
300 \tl_set:cn{p@\l_@@_counter_tl}{}
301 }
302 }
303 }
304 % \end{macrocode}
305 %
306 %
307 %
308 %
309 % \subsubsection{\texttt{label*}}
310 % TODO:
311 %
312 % \subsubsection{\texttt{ref}}
313 % TODO:
314 %
315 % \subsubsection{\texttt{font}, \texttt{format}}
316 %
317 % \begin{macrocode}
318 \keys_define:nn{template/item/std}
319 { font .meta:n = {label-format={#1{##1}}}}
320 \keys_define:nn{template/item/std}
321 { format .meta:n = {label-format={#1{##1}}}}
322 % \end{macrocode}
323 %
324 % \subsubsection{\texttt{align}}
325 %
326 % Note: this also supports the value center but parleft is not implemented yet.
327 % TODO: test for differences in behavior.
328 % \begin{macrocode}
329 \keys_define:nn{template/list/std}
330 { align .meta:n = {label-align=#1}}
331 % \end{macrocode}
332 %
333 % \subsubsection{\texttt{topsep}}
334 % \begin{macrocode}
335 \keys_define:nn{template/block/std}
336 { topsep .meta:n = {begin-vspace=#1}}
337 % \end{macrocode}
338 %
339 % \subsubsection{\texttt{partopsep}}
340 % \begin{macrocode}
341 \keys_define:nn{template/block/std}
342 { partopsep .meta:n = {begin-extra-vspace=#1}}
343 % \end{macrocode}
344 %
345 % \subsubsection{\texttt{parsep}}
346 % \begin{macrocode}
347 \keys_define:nn{template/block/std}
348 { parsep .meta:n = {para-vspace=#1}}
349 % \end{macrocode}
350 %
351 % \subsubsection{\texttt{itemsep}}
352 % \begin{macrocode}
353 \keys_define:nn{template/block/std}
354 { itemsep .meta:n = {item-vspace=#1}}
355 % \end{macrocode}
356 %
357 % \subsubsection{\texttt{leftmargin}}
358 % TODO: handle special values ! and *.\\
359 % Special values do not work with \LaTeX{} key at the moment as it is a register!
360 % \begin{macrocode}
361 \keys_define:nn{template/block/std}
362 { leftmargin .meta:n = {left-margin=#1}}
363 % \end{macrocode}
364 %
365 % \subsubsection{\texttt{rightmargin}}
366 % TODO: handle special values ! and *.\\
367 % Special values do not work with \LaTeX{} key!
368 % \begin{macrocode}
369 \keys_define:nn{template/block/std}
370 { rightmargin .meta:n = {right-margin=#1}}
371 % \end{macrocode}
372 %
373 % \subsubsection{\texttt{listparindent}}
374 % TODO: handle special values ! and *.\\
375 % Special values do not work with \LaTeX{} key!
376 % \begin{macrocode}
377 \keys_define:nn{template/block/std}
378 { listparindent .meta:n = {para-indent=#1}}
379 % \end{macrocode}
380 %
381 % \subsubsection{\texttt{itemindent}}
382 % TODO: handle special values ! and *.\\
383 % Special values do not work with \LaTeX{} key!
384 % \begin{macrocode}
385 \keys_define:nn{template/list/std}
386 { itemindent .meta:n = {item-indent=#1}}
387 % \end{macrocode}
388 %
389 % \subsubsection{\texttt{labelsep}, \texttt{labelsep*}}
390 % TODO: handle special values ! and *.\\
391 % Special values do not work with \LaTeX{} key!
392 % \begin{macrocode}
393 \keys_define:nn{template/list/std}
394 { labelsep .meta:n = {label-sep=#1}}
395 % \end{macrocode}
396 %
397 % \subsubsection{\texttt{labelwidth}}
398 % TODO: handle special values ! and *.\\
399 % Special values do not work with \LaTeX{} key!
400 % \begin{macrocode}
401 \keys_define:nn{template/list/std}
402 { labelwidth .meta:n = {label-width=#1}}
403 % \end{macrocode}
404 %
405 % \subsubsection{\texttt{labelindent}, \texttt{labelindent*}}
406 % TODO:, see also \cs{labelindent}, note special value ! and *
407 %
408 % \subsubsection{\texttt{left}}
409 % TODO:
410 %
411 % \subsubsection{\texttt{widest}, \texttt{widest*}}
412 % TODO:
413 %
414 % \subsubsection{\texttt{start}}
415 % TODO: Test with setlist
416 %
417 % \subsubsection{\texttt{resume}}
418 % TODO: Test with setlist.\\
419 % The behavior of the key is different to enumitem,
420 % where grouping of the environments matters: in \pkg{enumitem}
421 % a enumerate that is e.g. in quote environment can not be resumed outside of the quote.
422 % With the \LaTeX{} code grouping does not matter.
423 %
424 % \subsubsection{\texttt{resume*}}
425 % TODO: decide if it should be implemented
426 %
427 % \subsubsection{\texttt{series}}
428 % TODO: decide if it should be implemented
429 %
430 % \subsubsection{\texttt{beginpenalty}, \texttt{midpenalty}, \texttt{endpenalty}}
431 % \begin{macrocode}
432 \keys_define:nn{template/block/std}
433 {
434 beginpenalty .meta:n = {begin-penalty=#1},
435 endpenalty .meta:n = {end-penalty=#1},
436 midpenalty .meta:n = {item-penalty=#1}
437 }
438 % \end{macrocode}
439 %
440 % \subsubsection{\texttt{before}, \texttt{before*}}
441 % TODO: describe behavior (second argument of list does not make sense)
442 % Implement with hooks?
443 %
444 % \subsubsection{\texttt{after}, \texttt{after*}}
445 % TODO: implement with hooks?
446 %
447 % \subsubsection{\texttt{first}, \texttt{first*}}
448 % TODO: implement with hooks?
449 %
450 % \subsubsection{\texttt{style}}
451 % TODO: values for description lists: standard, unboxed, nextline, sameline, multiline
452 %
453 % \subsubsection{\texttt{noitemsep}, \texttt{nosep}}
454 % \begin{macrocode}
455 \keys_define:nn{template/blockenv/std}
456 {
457 nosep .meta:n =
458 {
459 begin-vspace=0pt,
460 begin-extra-vspace=0pt,
461 end-vspace=0pt,
462 end-extra-vspace=0pt,
463 item-vspace=0pt,
464 para-vspace=0pt
465 }
466 }
467 \keys_define:nn{template/blockenv/std}
468 {
469 noitemsep .meta:n =
470 {
471 item-vspace=0pt,
472 para-vspace=0pt
473 }
474 }
475
476 % \end{macrocode}
477 %
478 %
479 % \subsubsection{\texttt{wide}}
480 % TODO: calculated value should be delayed ...
481 % \begin{macrocode}
482 \keys_define:nn{template/blockenv/std}
483 {
484 wide .meta:n =
485 {
486 label-align=left,
487 para-indent=#1,
488 left-margin=0pt,
489 label-width=0pt,
490 item-indent=\dimeval{#1+\labelsep} %should be delayed ....
491 },
492 wide .default:n = \parindent
493 }
494 % \end{macrocode}
495 %
496 %
497 % \subsubsection{\texttt{itemjoin}, \texttt{itemjoin*}, \texttt{afterlabel}}
498 % TODO
499 %
500 % \subsubsection{\texttt{mode}}
501 % TODO
502 %
503 %
504 %
505 % \subsection{Package options}
506 %
507 %
508 % \subsubsection{\texttt{shortlabels}}
509 %
510 %
511 % \subsubsection{\texttt{inline}}
512 % TODO, creates three environments enumerate*, itemize* and description*
513 %
514 %
515 % \subsubsection{\texttt{sizes}}
516 %
517 %
518 % \subsubsection{\texttt{loadonly}}
519 %
520 %
521 %
522 %
523 %\subsection{Command emulation}
524 %
525 %\subsubsection{\cs{SetLabelAlign}}
526 %
527 %
528 %\subsubsection{\cs{DrawEnumitemLabel}}
529 %
530 %
531 %\subsubsection{\cs{labelindent}}
532 % see also key labelindent
533 %
534 %
535 %\subsubsection{\cs{EnumitemId}}
536 %
537 %
538 %\subsubsection{\cs{SetEnumitemKey}}
539 %
540 % The \cs{SetEnumitemKey} defines shortcuts. We can defines them as
541 % \texttt{.meta:n} on the \insttype{block} level. If they are for
542 % the inner instances, they get passed down as necessary (this is
543 % slightly less efficient than defining them at the right level,
544 % but makes life easier).
545 % \begin{macrocode}
546 \NewDocumentCommand \SetEnumitemKey {mm} {
547 \keys_define:nn { template/block/std }
548 { #1 .meta:n = { #2 } }
549 }
550 % \end{macrocode}
551 %
552 % As an example, something like \texttt{noitemsep} could have been defined as
553 %\begin{verbatim}
554 % \SetEnumitemKey{noitemsep}{ itemsep=0pt, parsep=0pt }
555 %\end{verbatim}
556 % And this can even be done recursively, e.g.,
557 %\begin{verbatim}
558 % \SetEnumitemKey{nosep} { noitemsep, topsep=0pt, partopsep=0pt }
559 %\end{verbatim}
560 %
561 %
562 %\subsubsection{\cs{SetEnumitemValue}}
563 %
564 %
565 %\subsubsection{\cs{SetEnumerateShortLabel}}
566 %
567 %
568 %\subsubsection{\cs{newlist}}
569 %
570 % The \cs{newlist} command allows to define new lists which clones the
571 % standard lists. The last number describes the maximum number of levels.
572 % Note that with itemize and description at most 6 levels are allowed.
573 % This could be changed with
574 % \begin{verbatim}
575 % \setcounter{maxblocklevels}{7}
576 % \DeclareInstance{block}{std-list-7}{display}{}
577 % \end{verbatim}
578 % but as enumitem doesn't allow more levels either the code does not force it.
579 %
580 % Below is another implementation that supports arbitrarily many
581 % levels. At some point we need to decide what we want to do here
582 % and unify the code. Right now both sample implementations have
583 % their restrictions.
584 %
585 % \begin{macro}{\newlist}
586 % \begin{macrocode}
587 \NewDocumentCommand\newlist{mmm} %name, type, number
588 {
589 \str_case:nnF{#2}
590 {
591 {itemize} {\@@_setup_itemize:nn{#1}{#3}}
592 {enumerate} {\@@_setup_enumerate:nn{#1}{#3}}
593 {description}{\@@_setup_description:nn{#1}{#3}}
594 }
595 % \end{macrocode}
596 % TODO: message
597 % \begin{macrocode}
598 {\typeout{unknown~list~type~#2}
599 }
600 % \end{macrocode}
601 % TODO: For supporting \cs{setlist} we need to set up \cs{enitdp@\#1} if we
602 % use this implementation.
603 % \begin{macrocode}
604 }
605 %
606 % \end{macrocode}
607 % \end{macro}
608 %
609 % \begin{macro}{\@@_setup_itemize:nn}
610 % \changes{v0.80e}{2026/02/16}{Allow spaces before the optional argument (tagging/1237)}
611 % \begin{macrocode}
612 \cs_new_protected:Npn \@@_setup_itemize:nn #1#2 %#1 name of new list, #2 max levels
613 {
614 \DeclareInstanceCopy{blockenv}{#1}{itemize}
615 \EditInstance{blockenv}{#1}{inner-instance=#1}
616 \NewDocumentEnvironment{#1}{O{}}
617 { \SimpleBlockEnv {#1} {max-inner-levels= \int_min:nn{\c@maxblocklevels}{#2},##1} }
618 { \BlockEnvEnd }
619 \int_step_inline:nnn{1}{\int_min:nn{\c@maxblocklevels}{#2}}
620 {
621 \IfInstanceExistsTF{list}{itemize-##1}
622 {
623 \DeclareInstanceCopy{list}{#1-##1}{itemize-##1}
624 }
625 % \end{macrocode}
626 % The default label for lists below 4 is simply \cs{labelitemi}.
627 % \begin{macrocode}
628 {
629 \ExpandArgs{c}
630 \providecommand{labelitem\int_to_roman:n{##1}}{\labelitemi}
631 \DeclareInstance{list}{#1-##1}{std}
632 { item-label = \use:c{labelitem\int_to_roman:n{##1}}}
633 }
634 }
635 }
636 % \end{macrocode}
637 % \end{macro}
638 %
639 % \begin{macro}{\@@_setup_description:nn}
640 % \changes{v0.80e}{2026/02/16}{Allow spaces before the optional argument (tagging/1237)}
641 % \begin{macrocode}
642 \cs_new_protected:Npn \@@_setup_description:nn #1#2
643 {
644 \DeclareInstanceCopy{blockenv}{#1}{description}
645 \EditInstance{blockenv}{#1}{inner-instance=#1}
646 \DeclareInstanceCopy{list}{#1}{description}
647 \NewDocumentEnvironment{#1}{O{}}
648 { \SimpleBlockEnv{#1} {max-inner-levels= \int_min:nn{\c@maxblocklevels}{#2},##1} }
649 { \BlockEnvEnd }
650 }
651 % \end{macrocode}
652 % \end{macro}
653 %
654 % \begin{macro}{\@@_setup_enumerate:nn}
655 % \changes{v0.80e}{2026/02/16}{Allow spaces before the optional argument (tagging/1237)}
656 % \begin{macrocode}
657 \cs_new_protected:Npn \@@_setup_enumerate:nn #1#2
658 {
659 \DeclareInstanceCopy{blockenv}{#1}{enumerate}
660 \EditInstance{blockenv}{#1}{inner-instance=#1}
661 \NewDocumentEnvironment{#1}{O{}}
662 { \SimpleBlockEnv {#1} {max-inner-levels= #2,##1} }
663 { \BlockEnvEnd }
664 \int_step_inline:nnn{1}{#2}
665 {
666 \newcounter{#1\int_to_roman:n{##1}}
667 \ExpandArgs{c}
668 \newcommand{label#1\int_to_roman:n{##1}}
669 {\arabic{#1\int_to_roman:n{##1}}.}
670 \DeclareInstance{list}{#1-##1}{std}
671 {
672 item-label = \use:c{label#1\int_to_roman:n{##1}} ,
673 counter = {#1\int_to_roman:n{##1}}
674 }
675 }
676 }
677 % \end{macrocode}
678 % \end{macro}
679 %
680 %
681 %
682 % \begin{macro}{\newlist}
683 % This is an alternative implementation (not necessarily better).
684 % \changes{v0.80e}{2026/02/16}{Alternative implementation for \cs{newlist}}
685 % \begin{macrocode}
686 \cs_set_protected:Npn \newlist #1#2#3 {
687 \DeclareDocumentEnvironment {#1} { !O{} }
688 { \SimpleBlockEnv {#1}{##1} } { \BlockEnvEnd }
689 %
690 \DeclareInstanceCopy {blockenv} {#1} {#2}
691 %
692 % If #3 > maxblocklevels add additional std-list instances as necessary
693 %
694 \int_compare:nNnT { \value{maxblocklevels} } < {#3}
695 {
696 \int_step_inline:nnn { \value{maxblocklevels} + 1 } {#3}
697 {
698 \DeclareInstanceCopy {block} {std-list-##1} {std-list-\int_eval:n{ ##1 - 1 }}
699 % not sure if we should set up those as well ...
700 \DeclareInstanceCopy {block} {std-display-##1} {std-display-1}
701 \DeclareInstanceCopy {block} {quote-##1} {quote-1}
702 \DeclareInstanceCopy {block} {quotation-##1} {quotation-1}
703 \DeclareInstanceCopy {block} {verbatim-##1} {verbatim-1}
704 }
705 \setcounter{maxblocklevels}{#3}
706 }
707 %
708 \IfInstanceExistsTF{list}{#2} % no levels (as with description)
709 {
710 \EditInstance {blockenv} {#1} {
711 name = #1
712 ,inner-instance = #1
713 }
714 %
715 \DeclareInstanceCopy {list} {#1} {#2}
716 }
717 {
718 \int_new:c { g_@@_ #1 _depth_int }
719 %
720 \EditInstance {blockenv} {#1} {
721 name = #1
722 ,inner-instance = #1
723 ,max-inner-levels = #3
724 ,inner-level-counter:c = g_@@_ #1 _depth_int
725 }
726 %
727 \int_step_inline:nn {#3}
728 { \@@_setup_enum_list_instance:nnn {#1}{#2}{##1} }
729 }
730 %
731 % \end{macrocode}
732 % For supporting \cs{setlist} we need to set up \cs{enitdp@\#1}
733 % \begin{macrocode}
734 \cs_set_eq:cc { enitdp@#1 } { g_@@_ #1 _depth_int }
735 %
736 }
737 % \end{macrocode}
738 %
739 % \begin{macrocode}
740 \cs_new:Npn \@@_setup_enum_list_instance:nnn #1#2#3 {
741 \IfInstanceExistsF{list}{#2-#3}
742 { \DeclareInstanceCopy {list} {#2-#3} {#2-\int_eval:n{#3-1}} }
743 \DeclareInstanceCopy {list} {#1-#3} {#2-#3}
744 \str_case:nnF { #2 }
745 {
746
747 { enumerate }
748 {
749 \EditInstance {list} {#1-#3} {
750 counter:e = #1 \int_to_roman:n {#3}
751 ,item-label:c = label #1 \int_to_roman:n {#3}
752 }
753 \newcounter { #1 \int_to_roman:n {#3} }
754 \tl_new:c { label #1 \int_to_roman:n {#3} }
755 \tl_set:cn { label #1 \int_to_roman:n {#3} } { \arabic* }
756 }
757 { itemize }
758 {
759 \EditInstance {list} {#1-#3} {
760 item-label:c = label #1 \int_to_roman:n {#3}
761 }
762 \tl_new:c { label #1 \int_to_roman:n {#3} }
763 \tl_set:cn { label #1 \int_to_roman:n {#3} } { -- }
764 }
765 }
766 { \ERROR-#2-unknown }
767 }
768 % \end{macrocode}
769 % \end{macro}
770 %
771 %
772 %
773 %
774 %
775 %
776 %\subsubsection{\cs{renewlist}}
777 %
778 %
779 %
780 %\subsubsection{\cs{setlist}}
781 %
782 % For emulating \cs{setlist} I lifted most of the code directly
783 % from \pkg{enumitem} for now and made only minimal
784 % adjustments. Size-dependent settings via \verb=<...>= are not
785 % supported so far.
786 %
787 % TODO: rewrite in \pkg{expl3}.
788 % TODO: decide if we want to emulate size-dependent settings
789 %
790 % \begin{macrocode}
791 \ExplSyntaxOff
792 \makeatletter
793 % \end{macrocode}
794 %
795 % \begin{macrocode}
796 \newcommand\setlist{%
797 \@ifstar{\enit@setlist\@ne}{\enit@setlist\z@}}
798 % \end{macrocode}
799 %
800 % \begin{macrocode}
801 \def\enit@setlist#1{%
802 \@ifnextchar<%
803 {\enit@setlist@q#1}%
804 {\let\enit@forsize\@empty\enit@setlist@n#1}}
805 % \end{macrocode}
806 %
807 % Size-dependent settings are not supported at all.
808 % \begin{macrocode}
809 \def\enit@setlist@q#1<#2>{%
810 \enit@error
811 {Size feature not implemented}%
812 {Size dependent setting is not available in the emulation}%
813 % {Activate this feature with options 'sizes'}%
814 % {Size dependent setting with \string<\string> must be\MessageBreak
815 % explicitly activated with the package option 'sizes'}}
816 }
817 % \end{macrocode}
818 %
819 % \begin{macrocode}
820 \def\enit@setlist@n#1{%
821 \@ifnextchar[{\enit@setlist@x#1}{\enit@setlist@i#1\@empty}}
822 % \end{macrocode}
823 %
824 % \begin{macrocode}
825 % Let's accept \setlist[]*{}, too, because an error in <=3.5.1
826
827 \def\enit@setlist@x#1[#2]{%
828 \@ifstar{\enit@setlist@i\@ne{#2}}{\enit@setlist@i#1{#2}}}
829 % \end{macrocode}
830 %
831 % \begin{macrocode}
832 \def\enit@setlist@i#1#2#3{%
833 \let\enit@eltnames\relax
834 \let\enit@b\@empty
835 \let\enit@eltlevels\relax
836 \let\enit@c\@empty
837 \protected@edef\enit@a{#2}%
838 \@for\enit@a:=\enit@a\do{% the 2nd enit@a is first expanded
839 \enit@ifunset{enitdp@\enit@meaning\enit@a}%
840 {\edef\enit@c{\enit@c\enit@eltlevels{\enit@a}}}%
841 {\edef\enit@b{\enit@b\enit@eltnames{\enit@a}}}}%
842 \ifx\enit@b\@empty
843 \def\enit@b{\enit@eltnames{list}}%
844 \fi
845 \ifx\enit@c\@empty
846 \def\enit@c{\enit@eltlevels{0}}%
847 \fi
848 \def\enit@eltnames##1{%
849 \def\enit@a{##1}%
850 \enit@c}%
851 \def\enit@eltlevels##1{%
852 \enit@saveset\enit@a{##1}#1{#3}}%
853 \enit@b}%
854 % \end{macrocode}
855 %
856 % \begin{macrocode}
857 \let\c@enit@cnt\@tempcnta
858 % \end{macrocode}
859 %
860 % \begin{macrocode}
861 \def\enit@meaning{\expandafter\strip@prefix\meaning}
862 % \end{macrocode}
863 %
864 % \begin{macrocode}
865 \long\def\enit@afterelse#1\else#2\fi{\fi#1}
866 \long\def\enit@afterfi#1\fi{\fi#1}
867 % \end{macrocode}
868 %
869 % \begin{macrocode}
870 \def\enit@error{\PackageError{enumitem}}
871 % \end{macrocode}
872 %
873 % \begin{macrocode}
874 \def\enit@ifunset#1{%
875 \ifcsname#1\endcsname
876 \expandafter\ifx\csname#1\endcsname\relax
877 \enit@afterelse\expandafter\@firstoftwo
878 \else
879 \enit@afterfi\expandafter\@secondoftwo
880 \fi
881 \else
882 \expandafter\@firstoftwo
883 \fi
884 }
885 % \end{macrocode}
886 %
887 % \begin{macrocode}
888 \def\enit@saveset#1#2#3#4{%
889 \setcounter{enit@cnt}{#2}%
890 \ifx\enit@forsize\@empty
891 \ifcase#3%
892 \expandafter
893 \def\csname enit@@#1\romannumeral\c@enit@cnt\endcsname{#4}%
894 \or
895 \expandafter\let\expandafter\enit@b
896 \csname enit@@#1\romannumeral\c@enit@cnt\endcsname
897 \ifx\enit@b\relax
898 \let\enit@b\@empty
899 \fi
900 \expandafter\def
901 \csname enit@@#1\romannumeral\c@enit@cnt\expandafter\endcsname
902 \expandafter{\enit@b,#4}%
903 \fi
904 \else
905 \ifcase#3%
906 \enit@ifunset{enit@@#1\romannumeral\c@enit@cnt}%
907 {\expandafter\let
908 \csname enit@@#1\romannumeral\c@enit@cnt\endcsname\@empty}%
909 {}%
910 \expandafter\let\expandafter\enit@b
911 \csname enit@@#1\romannumeral\c@enit@cnt @@sizes\endcsname
912 \ifx\enit@b\relax
913 \let\enit@b\@empty
914 \fi
915 \toks@\expandafter{\enit@b}%
916 \edef\enit@b{\the\toks@\enit@forsize\enit@keys@sizes}%
917 \expandafter\def
918 \csname enit@@#1\romannumeral\c@enit@cnt @@sizes\expandafter\endcsname
919 \expandafter{\enit@b{#4}}%
920 \else
921 \enit@error{* and \string<\string> are not compatible}%
922 {Use either * or angles, but not both.}%
923 \fi
924 \fi}
925 % \end{macrocode}
926 %
927 % The \pkg{enumitem} code uses \texttt{enitdp@\meta{name}} to refer
928 % to the list level counter of the \meta{name} list. So we do need
929 % that around for each standard list and provide one when making a
930 % new list with \cs{newlist}.
931 %
932 % TODO: check how to do this when making new lists directly.
933 % \begin{macrocode}
934 \let\enitdp@enumerate\@enumdepth
935 \let\enitdp@itemize\@itemdepth
936 \let\enitdp@description\@descriptiondepth
937 % \end{macrocode}
938 %
939 % To put keys set with \cs{setlist} into the keyp processing of
940 % \insttype{blockenv} instances we sneak them in as if they are
941 % given in the optional argument. For this we evaluate
942 % \cs{enit@@list} (produced by \verb=\setlist{...}=),
943 % \cs{enit@@list\meta{roman num}} (produced by \verb=\setlist[num]{...}=),
944 % \cs{enit@@\meta{name}} (produced by \verb=\setlist[name]{...}=), and
945 % \cs{enit@@\meta{name}\meta{roman num}} (produced by
946 % \verb=\setlist[name,num]{...}=)
947 % in that order and collect all key settings stored in them and
948 % stored them in \cs{UnusedTemplateKeys} which is then used at the
949 % start of the \insttype{blockenv} template.
950 % \begin{macrocode}
951 \AddToHookWithArguments{blockenv}{%
952 % \end{macrocode}
953 % If \verb=\enitdp@#1= is undefined the current \insttype{blockenv}
954 % is not a list, so we bail out.
955 % \begin{macrocode}
956 \enit@ifunset{enitdp@#1}{}%
957 {%
958 % \end{macrocode}
959 % Otherwise put the current list level in \cs{@tempcnta} and then
960 % evaluate the four storage places for keys.
961 % \begin{macrocode}
962 \@tempcnta\csname enitdp@#1\endcsname
963 \advance\@tempcnta\@ne
964 \enit@setkeys{list}%
965 \enit@setkeys{list\romannumeral\@tempcnta}%
966 \enit@setkeys{#1}%
967 \enit@setkeys{#1\romannumeral\@tempcnta}%
968 }%
969 }
970 % \end{macrocode}
971 %
972 % \begin{macrocode}
973 \ExplSyntaxOn
974 % \end{macrocode}
975 % Evaluation means checking if \cs{enit@@\#1} exists and if so add
976 % its content to \cs{UnusedTemplateKeys} followed by a comma.
977 % Thus, if there aren't any keys then \cs{UnusedTemplateKeys}
978 % remains empty. Otherwise it ends in a comma so that the
979 % \insttype{blockenv} template can safely append any keys from the
980 % document to make the full list of keys to be evaluated by the
981 % template instance.
982 % \begin{macrocode}
983 \cs_new_protected:Npn \enit@setkeys #1 {
984 \enit@ifunset {enit@@#1} {}
985 {
986 \tl_set:Ne \UnusedTemplateKeys
987 {
988 \exp_not:o \UnusedTemplateKeys
989 \exp_not:v {enit@@#1}
990 ,
991 }
992 }
993 }
994 \makeatother
995 % \end{macrocode}
996 %
997 %
998 %\subsubsection{\cs{setlistdepth}}
999 %
1000 %
1001 %\subsubsection{\cs{AddEnumerateCounter}}
1002 %
1003 %
1004 %\subsubsection{\cs{SetEnumitemSize}}
1005 %
1006 %
1007 %\subsubsection{\cs{restartlist}}
1008 %
1009 %
1010 % \begin{macrocode}
1011 %</package>
1012 % \end{macrocode}