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