Debian Codegraph @

texmf-dist/source/latex/koma-script/scrkernel-listsandtabulars.dtx

raw
1 % \iffalse meta-comment
2 % ======================================================================
3 % scrkernel-listsandtabulars.dtx
4 % Copyright (c) Markus Kohm, 2002-2025
5 %
6 % This file is part of the LaTeX2e KOMA-Script bundle.
7 %
8 % This work may be distributed and/or modified under the conditions of
9 % the LaTeX Project Public License, version 1.3c of the license.
10 % The latest version of this license is in
11 % http://www.latex-project.org/lppl.txt
12 % and version 1.3c or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later and of this work.
14 %
15 % This work has the LPPL maintenance status "author-maintained".
16 %
17 % The Current Maintainer and author of this work is Markus Kohm.
18 %
19 % This work consists of all files listed in MANIFEST.md.
20 % ======================================================================
21 %%% From File: $Id: scrkernel-listsandtabulars.dtx 4138 2025-02-10 13:55:51Z kohm $
22 %<option>%%% (run: option)
23 %<body>%%% (run: body)
24 %<*dtx>
25 \ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
26 \begingroup
27 \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
28 \filedate$Date: 2025-02-10 14:55:51 +0100 (Mo, 10. Feb 2025) $
29 \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
30 \filerevision$Revision: 4138 $
31 \edef\reserved@a{%
32 \noexpand\endgroup
33 \noexpand\ProvidesFile{scrkernel-listsandtabulars.dtx}%
34 [\filedate\space\filerevision\space
35 KOMA-Script source
36 (lists and tabulars)]
37 }%
38 \reserved@a
39 \documentclass[USenglish]{koma-script-source-doc}
40 \usepackage{babel}
41 \usepackage{hvlogos}
42 \setcounter{StandardModuleDepth}{2}
43 \begin{document}
44 \DocInput{scrkernel-listsandtabulars.dtx}
45 \end{document}
46 %</dtx>
47 % \fi
48 %
49 % \changes{v2.95}{2002/07/01}{first version after splitting \file{scrclass.dtx}}
50 % \changes{v3.36}{2022/02/15}{switch over from \cls*{scrdoc} to
51 % \cls*{koma-script-source-doc}}
52 % \changes{v3.36}{2022/02/15}{whole implementation documentation in English}
53 % \changes{v3.40}{2023/04/17}{guide names changed}
54 %
55 % \GetFileInfo{scrkernel-listsandtabulars.dtx}
56 % \title{Code of Lists, Tabulars and Similar Objects of the
57 % \href{https://komascript.de}{\KOMAScript} Classes}
58 % \author{\href{mailto:[email protected]}{Markus Kohm}}
59 % \date{Revision \fileversion{} of \filedate}
60 % \maketitle
61 % \begin{abstract}
62 % \file{scrkernel-listandtabulars.dtx} provides mainly code for all kind of
63 % lists namely \env{itemize}, \env{enumerate}, \env{description},
64 % \env{labeling}, \env{quote}, \env{quotation} and \env{addmargin} for all
65 % \KOMAScript{} classes. And because the code for \env{tabbing} and
66 % \env{tabular} is only some lines, it is added here too.
67 % \end{abstract}
68 % \tableofcontents
69 %
70 % \section{User Manual}
71 %
72 % You can find the user documentation the commands implemented here in the
73 % \KOMAScript{} manual, either the German \file{scrguide-de.pdf} or the
74 % English \file{scrguide-en.pdf}.
75 %
76 % \MaybeStop{\PrintIndex}
77 %
78 % \section{Implementation of Lists}
79 %
80 % \subsection{Options}
81 %
82 % The environments do not depend on options.
83 %
84 % \subsection{List margins}
85 %
86 % \begin{length}{\leftmargini,\leftmarginii,\leftmarginiii,\leftmarginiv,
87 % \leftmarginv,\leftmarginvi,\leftmargin}
88 % Usually lists can be nested at most six levels (but usually only four are
89 % used). So we have to define six different margins depending on the level
90 % (roman number added to \cs{leftmargin}):
91 % \begin{macrocode}
92 %<*body>
93 %<*class>
94 %<*!letter>
95 \if@twocolumn
96 \setlength{\leftmargini}{2em}
97 \else
98 %</!letter>
99 \setlength{\leftmargini}{2.5em}
100 %<!letter>\fi
101 \setlength{\leftmarginii}{2.2em}
102 \setlength{\leftmarginiii}{1.87em}
103 \setlength{\leftmarginiv}{1.7em}
104 %<*!letter>
105 \if@twocolumn
106 \setlength{\leftmarginv}{.5em}
107 \setlength{\leftmarginvi}{.5em}
108 \else
109 %</!letter>
110 \setlength{\leftmarginv}{1em}
111 \setlength{\leftmarginvi}{1em}
112 %<!letter>\fi
113 \setlength{\leftmargin}{\leftmargini}
114 % \end{macrocode}
115 % \end{length}^^A \leftmargini … \leftmarginvi,\leftmargin
116 %
117 %
118 % \subsection{List labels}
119 %
120 % \begin{length}{\labelsep,\labelwidth}
121 % If a list has a label we need a label width and a horizontal distance after
122 % the label.
123 % \begin{macrocode}
124 \setlength{\labelsep}{.5em}
125 \setlength{\labelwidth}{\leftmargini}
126 \addtolength{\labelwidth}{-\labelsep}
127 % \end{macrocode}
128 % \end{length}^^A \labelsep,\labewidth
129 %
130 %
131 % \subsection{List penalties}
132 %
133 % \begin{macro}{\@beginparpenalty,\@endparpenalty,\@itempenatly}
134 % Page breaks at the begin an end of lists or items are better than somewhere
135 % else but not much.
136 % \begin{macrocode}
137 \@beginparpenalty=-\@lowpenalty
138 \@endparpenalty =-\@lowpenalty
139 \@itempenalty =-\@lowpenalty
140 % \end{macrocode}
141 % \end{macro}
142 %
143 %
144 % \subsection{List items}
145 %
146 % \begin{command}{\theenumi,\theenumii,\theenumiii,\theenumiv}
147 % There are four levels of \env{enumerate} items with their numbers in Arabic,
148 % lower case letters, lowercase Roman numbers, uppercase letters.
149 % \begin{macrocode}
150 \renewcommand*\theenumi{\@arabic\c@enumi}
151 \renewcommand*\theenumii{\@alph\c@enumii}
152 \renewcommand*\theenumiii{\@roman\c@enumiii}
153 \renewcommand*\theenumiv{\@Alph\c@enumiv}
154 % \end{macrocode}
155 % \end{command}
156 %
157 % \begin{command}{\labelenumi}
158 % \begin{command}{\labelenumii}
159 % \changes{v2.4m}{1997/02/28}{opening brace removed}
160 % \changes{v3.44}{2025/02/10}{usage of font element}
161 % \begin{command}{\labelenumiii,\labelenumiv}
162 % \changes{v3.44}{2025/02/10}{usage of font element}
163 % The printed labels consist of the previously defined numbers followed by a
164 % dot or brace.
165 % \begin{macrocode}
166 \newcommand*\labelenumi{\usekomafont{labelenumi}{\theenumi.}}
167 \newcommand*\labelenumii{\usekomafont{labelenumii}{\theenumii)}}
168 \newcommand*\labelenumiii{\usekomafont{labelenumiii}{\theenumiii.}}
169 \newcommand*\labelenumiv{\usekomafont{labelenumiv}{\theenumiv.}}
170 % \end{macrocode}
171 % \end{command}
172 % \end{command}
173 % \end{command}
174 %
175 % \begin{macro}{\p@enumii,\p@enumiii,\p@enumiv}
176 % References to \env{enumerate} items are prefixed by the parent number and
177 % additional separation signs like braces.
178 % \begin{macrocode}
179 \renewcommand*\p@enumii{\theenumi}
180 \renewcommand*\p@enumiii{\p@enumii(\theenumii)}
181 \renewcommand*\p@enumiv{\p@enumiii\theenumiii}
182 % \end{macrocode}
183 % \end{macro}
184 %
185 % \begin{command}{\labelitemi,\labelitemii,\labelitemiii,\labelitemiv}
186 % \changes{v2.5g}{1999/10/09}{math mode eliminated}
187 % \changes{v3.33}{2021/02/15}{Usage of new font element}
188 % The characters used for \env{itemize} items. Again four levels are
189 % supported. All of them use a own font element.
190 % \begin{macrocode}
191 \newcommand*\labelitemi{\usekomafont{labelitemi}{\textbullet}}
192 \newcommand*\labelitemii{\usekomafont{labelitemii}{\textendash}}
193 \newcommand*\labelitemiii{\usekomafont{labelitemiii}{\textasteriskcentered}}
194 \newcommand*\labelitemiv{\usekomafont{labelitemiv}{\textperiodcentered}}
195 % \end{macrocode}
196 % \end{command}^^A \labelitemi … \labelitemiv
197 %
198 %
199 % \subsection{Definition of the environments}
200 %
201 % \begin{environment}{description}
202 % \begin{command}{\descriptionlabel}
203 % \changes{v3.36}{2022/02/15}{using \cs{usekomafont\{descriptionlabel\}} instead
204 % of \cs{descfont}}
205 % This is used to describe a single term. The terms should be short, because
206 % line breaks inside the terms are not supported. The term is the optional
207 % argument of \cs{item}. It is printed with font of element \fnt{descriptionlabel}.
208 % \begin{macrocode}
209 \newenvironment{description}{%
210 \list{}{\labelwidth\z@ \itemindent-\leftmargin
211 \let\makelabel\descriptionlabel}%
212 }{%
213 \endlist
214 }
215 \newcommand*{\descriptionlabel}[1]{%
216 \hspace{\labelsep}\usekomafont{descriptionlabel}{#1}%
217 }
218 % \end{macrocode}
219 % \end{command}
220 % \end{environment}
221 %
222 % \begin{environment}{labeling}
223 % \begin{command}{\labelinglabel}
224 % \changes{v3.02}{2009/01/01}{using font elements \fnt{labelinglabel} and
225 % \fnt{labelingseparator}}
226 % \changes{v3.02c}{2009/01/28}{using font elements \fnt{labelinglabel} and
227 % \fnt{labelingseparator} also for the calculation of the width}
228 % \changes{v3.03a}{2009/04/02}{fixed argument in the label width calculation}
229 % The \env{labeling} environment is an extension of \env{description}. It has
230 % an optional separation string (\texttt{\#1}) added behind every label. The
231 % width of the labels are the width of the mandatory argument (\texttt{\#2}).
232 % \begin{macrocode}
233 %</class>
234 \newenvironment{labeling}[2][]{%
235 \def\sc@septext{#1}%
236 \list{}{\settowidth{\labelwidth}{{%
237 \usekomafont{labelinglabel}{#2%
238 \usekomafont{labelingseparator}{\sc@septext}}%
239 }}%
240 \leftmargin\labelwidth \advance\leftmargin by \labelsep
241 \let\makelabel\labelinglabel
242 }%
243 }{%
244 \endlist
245 }
246 \newcommand\labelinglabel[1]{%
247 \usekomafont{labelinglabel}{#1\hfil
248 \usekomafont{labelingseparator}{\sc@septext}}%
249 }
250 %<*class>
251 % \end{macrocode}
252 % \end{command}
253 % \end{environment}
254 %
255 % \begin{environment}{verse}
256 % \changes{v2.3g}{1996/01/14}{\cs{item} does not wait for \texttt{[]}}
257 % The environment for short poems.
258 % \begin{macrocode}
259 \newenvironment{verse}{%
260 \let\\=\@centercr
261 \list{}{\itemsep=\z@
262 \itemindent=-1.5em
263 \listparindent=\itemindent
264 \rightmargin=\leftmargin
265 \advance\leftmargin by1.5em
266 }%
267 \item\relax
268 }{%
269 \endlist
270 }
271 % \end{macrocode}
272 % \end{environment}
273 %
274 % \begin{environment}{quotation,quote}
275 % \changes{v2.3g}{1996/01/14}{\cs{item} does not wait for \texttt{[]}}
276 % Two environments for left and right indented text. The difference of both
277 % is: \env{quotation} works with paragraph indent (first line is indented),
278 % \env{quote} works with paragraph distance.
279 % \begin{macrocode}
280 \newenvironment{quotation}{%
281 \list{}{\listparindent 1em%
282 \itemindent \listparindent
283 \rightmargin \leftmargin
284 \parsep \z@ \@plus\p@
285 }%
286 \item\relax
287 }{%
288 \endlist
289 }
290 \newenvironment{quote}{%
291 \list{}{\rightmargin\leftmargin}%
292 \item\relax
293 }{%
294 \endlist
295 }
296 % \end{macrocode}
297 % \end{environment}
298 %
299 % \begin{environment}{addmargin}
300 % \changes{v2.8q}{2001/11/29}{added}
301 % \changes{v2.95a}{2006-07-20}{\cs{@listdepth} reset}
302 % \begin{environment}{addmargin*}
303 % \changes{v2.8q}{2001/11/29}{added}
304 % \changes{v2.95a}{2006-07-20}{\cs{@listdepth} reset}
305 % \changes{v3.17}{2015/03/23}{improved handling of page breaks at the beginning}
306 % \changes{v3.22}{2016/08/02}{page break test for double-sided documents}
307 % Both environments are similar to \env{quote} and \env{quotation}, but the
308 % indent is not fix. If only the mandatory argument (\texttt{\#2}) is used, it
309 % is the left and right indent. If the optional argument (\texttt{\#1}) is
310 % also used, it is the left indent with \env{addmargin} resp. the inner indent
311 % with \env{addmargin*}. Note, negative indents will extend to the
312 % margins. Note, that page breaks inside \env{addmargin*} should be avoided,
313 % because they result in wrong margins at the second, fourth, sixth etc. page.
314 % \begin{macro}{\@addmargin}
315 % \changes{v2.8q}{2001/11/29}{added}
316 % \changes{v2.95}{2002/07/01}{\cs{item} does not wait for \texttt{[]}}
317 % \changes{v2.9q}{2003/03/24}{unchanged \len{labelsep}}
318 % \changes{v2.95a}{2006/07/20}{unchanged \cs{@tmpcnta}}
319 % \changes{v3.05b}{2010/04/29}{\len{partopsep} has to be 0 instead of
320 % \len{parskip} because of adding \len{topsep}}
321 % \changes{v3.17}{2015/03/23}{improved handling of page breaks at the beginning}
322 % \changes{v3.28}{2019/11/19}{\cs{ifthispageodd} replaced by \cs{Ifthispageodd}}
323 % \begin{macro}{\scr@addmargin@startpage}
324 % \changes{v3.12}{2013/10/26}{added}
325 % \changes{v3.12}{2013/10/26}{page break test for \env{addmargin*}}
326 % \changes{v3.22}{2016/10/21}{unchanged \len{topsep} and \len{partopsep}}
327 % \begin{macrocode}
328 %</class>
329 \newenvironment{addmargin}{%
330 \@tempswafalse\@addmargin
331 }{%
332 \advance\@listdepth\@ne
333 \endlist
334 }
335 \newenvironment{addmargin*}{%
336 \@tempswafalse
337 \if@twoside\is@thispageodd[]\ifthispagewasodd\else\@tempswatrue\fi
338 \edef\scr@addmargin@startpage{\csname tpo@\scr@tpo\endcsname}\fi
339 \@addmargin
340 }{%
341 \if@twoside
342 \unskip\nobreak\Ifthispageodd{}{}%
343 \expandafter\ifx\csname tpo@\scr@tpo\endcsname\scr@addmargin@startpage\else
344 %<class> \ClassWarning{\KOMAClassName}{%
345 %<package> \PackageWarning{scrextend}{%
346 page break inside `addmargin*' environment.\MessageBreak
347 A `addmargin*' environment starting on page
348 \scr@addmargin@startpage\MessageBreak
349 ends on page \csname tpo@\scr@tpo\endcsname.\MessageBreak
350 This will result in potential wrong margins on\MessageBreak
351 every other page.\MessageBreak
352 So maybe you should change the `addmargin*'\MessageBreak
353 environment, that ends%
354 }%
355 \fi
356 \fi
357 \advance\@listdepth\@ne
358 \endlist
359 }
360 \newcommand*{\@addmargin}[2][\@tempa]{%
361 \list{}{%
362 \if@tempswa
363 \def\@tempa{\leftmargin}%
364 \setlength{\leftmargin}{#2}%
365 \setlength{\rightmargin}{#1}%
366 \else
367 \def\@tempa{\rightmargin}%
368 \setlength{\rightmargin}{#2}%
369 \setlength{\leftmargin}{#1}%
370 \fi
371 \setlength{\listparindent}{\parindent}%
372 \setlength{\itemsep}{\parskip}%
373 \setlength{\itemindent}{\z@}%
374 \setlength{\@tempskipa}{\topsep}%
375 \setlength{\topsep}{\z@}%
376 \setlength{\parsep}{\parskip}%
377 \setlength{\@tempskipb}{\partopsep}%
378 \setlength{\partopsep}{\z@}%
379 \let\makelabel\@gobble
380 \setlength{\labelwidth}{\z@}%
381 \advance\@listdepth\m@ne
382 }%
383 %<!v4> \expandafter\ifnum\scr@v@is@ge{3.22}%
384 \setlength{\topsep}{\@tempskipa}%
385 \setlength{\partopsep}{\@tempskipb}%
386 %<!v4> \fi
387 \item\is@thispageodd@setlabel\nobreak\ignorespaces
388 }
389 %<*class>
390 % \end{macrocode}
391 % \end{macro}
392 % \end{macro}
393 % \end{environment}
394 % \end{environment}
395 %
396 %
397 % \subsection{Font elements of lists}
398 %
399 % \begin{fontelement}{descriptionlabel}
400 % \changes{v2.8o}{2001/09/14}{added}
401 % The font element is defined indirect by some macros to stay compatible with
402 % \KOMAScript{} before the design of font elements.
403 % \begin{macro}{\descfont}
404 % \changes{v3.20}{2016/01/29}{\cs{sffamily} replaced by \cs{@gr@gsffamily}}
405 % \changes{v3.39}{2023/04/04}{\cs{@gr@gsfamily} replaced by \cs{maybesffamily}}
406 % The font of the item labels of \env{description}. The command \cs{descfont}
407 % should not be used by users. Think of it as an internal macro. The user
408 % space name is because of compatibility to very old \KOMAScript{} versions.
409 % \begin{macrocode}
410 \newcommand*\descfont{\maybesffamily\bfseries}
411 % \end{macrocode}
412 % \end{macro}
413 % \begin{macro}{\scr@fnt@descriptionlabel}
414 % The font element uses \cs{descfont}.
415 % \begin{macrocode}
416 \newcommand*{\scr@fnt@descriptionlabel}{\descfont}
417 % \end{macrocode}
418 % \end{macro}
419 % \end{fontelement}
420 %
421 % \begin{fontelement}{labelitemi,labelitemii,labelitemiii,labelitemiv,itemizelabel}
422 % \changes{v3.33}{2021/02/15}{added}
423 % \begin{command}{\labelitemfont}
424 % \changes{v3.33}{2021/02/15}{added}
425 % Due to a change in the LaTeX kernel 2020/02/02 the \env{itemize} items
426 % react on font changes. For this the standard classes have been changed to
427 % set the item \emph{bullets} using \cs{labelitemfont} which is
428 % \cs{normalfont} by default. I've adapted this using also \cs{labelitemfont}
429 % for compatibility but only to store the font of font element
430 % \fnt{itemizelabel} which is the default of the level depending font
431 % elements. \fnt{itemlabelii} differs, because the default \cs{textendash}
432 % should be bold.
433 % \begin{macrocode}
434 \newcommand*{\labelitemfont}{\normalfont}
435 \newcommand*\scr@fnt@itemizelabel{\labelitemfont}
436 \newkomafont{labelitemi}{\usekomafont{itemizelabel}}
437 \newkomafont{labelitemii}{\usekomafont{itemizelabel}\bfseries}
438 \newkomafont{labelitemiii}{\usekomafont{itemizelabel}}
439 \newkomafont{labelitemiv}{\usekomafont{itemizelabel}}
440 %</class>
441 % \end{macrocode}
442 % \end{command}
443 % \end{fontelement}
444 %
445 % \begin{fontelement}{labelenumi,labelenumii,labelenumiii,labelenumiv,enumeratelabel}
446 % \changes{v3.44}{2025/02/10}{added}
447 % There has been a user request to add a font for \env{enumerate} items similar
448 % to the fonts for \env{itemize} items.
449 % \begin{macrocode}
450 \newkomafont{enumeratelabel}{}
451 \newkomafont{labelenumi}{\usekomafont{enumeratelabel}}
452 \newkomafont{labelenumii}{\usekomafont{enumeratelabel}}
453 \newkomafont{labelenumiii}{\usekomafont{enumeratelabel}}
454 \newkomafont{labelenumiv}{\usekomafont{enumeratelabel}}
455 % \end{macrocode}
456 % \end{fontelement}
457 %
458 % \begin{fontelement}{labelinglabel,labelingseparator}
459 % \changes{v3.02}{2009/01/01}{added}
460 % The \env{labeling} environment has two font elements, one for the whole
461 % label and one for the separator only. The default is no change.
462 % \begin{macrocode}
463 \newkomafont{labelinglabel}{}
464 \newkomafont{labelingseparator}{}
465 % \end{macrocode}
466 % \end{fontelement}
467 %
468 %
469 % \section{Implementation of Tabulars, Array etc.}
470 %
471 % All these environments are implemented in the \LaTeX{} kernel already. We
472 % only need some configuration parameters.
473 %
474 % \begin{length}{\arraycolsep,\tabcolsep,\arrayrulewidth,\doublerulewidth,
475 % \tabbingsep}
476 % These are the distances between columns in \env{array} and \env{tabular},
477 % the width of lines/rules independent from \env{array} or \env{tabular} and
478 % the distance of double lines/rules (two consecutive \cs{hline}). The last
479 % one, \cs{tabbingsep}, is the \cs{'} distance in \env{tabbing} environments.
480 % All values are same as in the standard classes.
481 % \begin{macrocode}
482 %<*class>
483 \setlength\arraycolsep{5\p@}
484 \setlength\tabcolsep{6\p@}
485 \setlength\arrayrulewidth{.4\p@}
486 \setlength\doublerulesep{2\p@}
487 \setlength\tabbingsep{\labelsep}
488 %</class>
489 % \end{macrocode}
490 % \end{length}^^A \arraycolsep … \tabbingsep
491 %
492 %
493 % \begin{macrocode}
494 %</body>
495 % \end{macrocode}
496 %
497 % \Finale
498 % \PrintChanges
499 %
500 \endinput
501 % Local Variables:
502 % mode: doctex
503 % ispell-local-dictionary: "en_US"
504 % eval: (flyspell-mode 1)
505 % TeX-master: t
506 % TeX-engine: luatex-dev
507 % eval: (setcar (or (cl-member "Index" (setq-local TeX-command-list (copy-alist TeX-command-list)) :key #'car :test #'string-equal) (setq-local TeX-command-list (cons nil TeX-command-list))) '("Index" "mkindex %s" TeX-run-index nil t :help "makeindex for dtx"))
508 % End: