Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 % ======================================================================
3 % scrkernel-index.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-index.dtx 4181 2025-06-14 09:11:13Z 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-06-14 11:11:13 +0200 (Sa, 14. Jun 2025) $
29 \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
30 \filerevision$Revision: 4181 $
31 \edef\reserved@a{%
32 \noexpand\endgroup
33 \noexpand\ProvidesFile{scrkernel-index.dtx}%
34 [\filedate\space\filerevision\space
35 KOMA-Script source
36 (index)]%
37 }%
38 \reserved@a
39 \documentclass[USenglish]{koma-script-source-doc}
40 \usepackage{babel}
41 \setcounter{StandardModuleDepth}{2}
42 \begin{document}
43 \DocInput{scrkernel-index.dtx}
44 \end{document}
45 %</dtx>
46 % \fi
47 %
48 % \changes{v2.95}{2002/07/01}{new by splitting \file{scrclass.dtx}}
49 % \changes{v3.36}{2022/02/15}{switch over from \cls*{scrdoc} to
50 % \cls*{koma-script-source-doc}}
51 % \changes{v3.36}{2022/02/15}{whole implementation documentation in English}
52 % \changes{v3.40}{2023/04/17}{guide names changed}
53 %
54 % \GetFileInfo{scrkernel-index.dtx}
55 % \title{Index Code of the
56 % \href{https://komascript.de}{\KOMAScript} Classes}
57 % \author{\href{mailto:[email protected]}{Markus Kohm}}
58 % \date{Revision \fileversion{} of \filedate}
59 % \maketitle
60 % \begin{abstract}
61 % The index code of the \KOMAScript{} classes in \file{scrkernel-index.dtx}
62 % is somehow different from the code of the standard classes. It provides
63 % several options and other configuration possibilities.
64 % \end{abstract}
65 % \tableofcontents
66 %
67 % \section{User Manual}
68 %
69 % You can find the user documentation the commands implemented here in the
70 % \KOMAScript{} manual, either the German \file{scrguide-de.pdf} or the
71 % English \file{scrguide-en.pdf}.
72 %
73 % \MaybeStop{\PrintIndex}
74 %
75 % \section{Implementation of the Index}
76 %
77 % The letter class \cls*{scrlttr2} does not provide an index. All other
78 % classes do.
79 %
80 % \begin{macrocode}
81 %<*!letter>
82 % \end{macrocode}
83 %
84 %
85 % \subsection{Options}
86 %
87 % \begin{option}{index}
88 % \changes{v2.98c}{2008/03/04}{added}
89 % \changes{v3.17}{2015/03/12}{internal value storage}
90 % \changes{v3.18}{2015/06/15}{new value \opt{numbered}}
91 % \changes{v3.18}{2015/06/15}{new value \opt{leveldown}}
92 % \changes{v3.18}{2015/06/15}{new value \opt{standardlevel}}
93 % \changes{v2.7a}{2001/01/04}{improved link generation with \cls*{scrbook} or
94 % \cls*{scrreprt} and \pkg{hyperref}}
95 % \changes{v2.98c}{2008/03/04}{redefining \cs{idx@@heading} instead of
96 % \cs{idx@@heading}}
97 % \changes{v3.18}{2015/06/15}{new value \opt{leveldown}}
98 % \changes{v3.39}{2022/11/11}{initial dot removed from member argument of
99 % option storage commands}
100 % The option allow several values for several features:
101 % \begin{labeling}{\opt{=standardlevel}:}
102 % \item[\opt{=default}:] use not numbered heading without ToC entry, but
103 % without affecting the heading level;
104 % \item[\opt{=totoc}:] use not numbered heading with ToC entry, but
105 % without affecting the heading level;
106 % \item[\opt{=numbered}:] use numbered heading (with ToC entry), but
107 % without affecting the heading level;
108 % \item[\opt{=leveldown}:] use a subheading (e.g. \cs{subsection} instead
109 % of \cs{section} in \cls*{scrartcl}), without affecting numbered or not and
110 % ToC entry or not;
111 % \item[\opt{=standardlevel}:] don't use a subheading, without affecting
112 % numbered or not and ToC entry or not.
113 % \end{labeling}
114 % To do so, the option redefines \cs{idx@heading}.
115 % \begin{macro}{\idx@@heading}
116 % \changes{v2.98c}{2008/03/04}{added}
117 % \changes{v3.18}{2015/06/15}{using \opt{leveldown}}
118 % This is the macro to print the heading of the index (nothing else). It has
119 % one mandatory argument: the text to be used as heading. There will be one
120 % additional code level above this: \cs{idx@heading}, that will be defined in
121 % the \texttt{body} run. \cs{idx@heading} has to be defined before, so it can
122 % be redefined by the \opt{index} option. In opposite to the standard classes
123 % we want to use \cs{chapter} in two column mode. This can be done, because of
124 % significant changes of \cs{chapter} definition. Note: If someone uses the
125 % standard classes hack of package \pkg*{scrhack} or even another headings
126 % package like \pkg*{titlesec} this could fail. But this is not my problem,
127 % because usage of such packages and hacks is not recommended at all.
128 % \begin{macrocode}
129 %<*option>
130 \newcommand*{\idx@@heading}{%
131 \ifidx@leveldown
132 %<article> \expandafter\subsection
133 %<book|report> \expandafter\section
134 \else
135 %<article> \expandafter\section
136 %<book|report> \expandafter\chapter
137 \fi*%
138 }
139 % \end{macrocode}
140 % \begin{macro}{\idx@@mark,\idx@@forcemark,\idx@@forcemarknumbered}
141 % \changes{v3.41}{2023/05/05}{added}
142 % We also need a command to do the mark for the running head to be used if a
143 % sectioning command without automatic usage of \cs{chaptermark},
144 % \cs{sectionmark} or \cs{subsectionmark} is used. For headings with automatic
145 % usage of \cs{chaptermark}, \cs{sectionmark} or \cs{subsectionmark} it should
146 % not be used, despite the fact, that this usually would result in not setting
147 % both marks. The command has the same argument as \cs{idx@@heading}. This is
148 % the same code, previously used in \cs{idx@heading}.
149 % \begin{macrocode}
150 \newcommand*{\idx@@forcemark}[1]{%
151 \ifidx@leveldown
152 %<report|book> \addsecmark{#1}%
153 %<*article>
154 \begingroup
155 \value{secnumdepth}=-\maxdimen
156 \subsectionmark{#1}%
157 \endgroup
158 %</article>
159 \else
160 \@mkdouble{\MakeMarkcase{#1}}%
161 \fi
162 }
163 \newcommand*{\idx@@forcemarknumbered}[1]{%
164 \ifidx@leveldown
165 %<report|book> \sectionmark{#1}%
166 %<article> \subsectionmark{#1}%
167 \else
168 %<report|book> \chaptermark{#1}%
169 %<article> \sectionmark{#1}%
170 \fi
171 }
172 \newcommand*{\idx@@mark}{}
173 \let\idx@@mark\idx@@forcemark
174 % \end{macrocode}
175 % \end{macro}
176 % \begin{macro}{\idx@leveldowntrue,\idx@leveldownfalse,\ifidx@leveldown}
177 % \changes{v3.18}{2015/06/15}{added}
178 % The boolean switch \cs{ididx@leveldown} is needed to distinguish the heading
179 % level to be used (option values \opt{leveldown} and \opt{standardlevel}).
180 % \begin{macrocode}
181 \newif\ifidx@leveldown
182 \KOMA@key{index}{%
183 \KOMA@set@ncmdkey{index}{@tempa}{%
184 {notoc}{0},{nottotoc}{0},{default}{0},{plainheading}{0},%
185 {totoc}{1},{toc}{1},{notnumbered}{1},%
186 {numbered}{2},{totocnumbered}{2},{numberedtotoc}{2},{tocnumbered}{2},%
187 {numberedtoc}{2},%
188 {leveldown}{3},%
189 {standardlevel}{4}%
190 }{#1}%
191 \ifx\FamilyKeyState\FamilyKeyStateProcessed
192 \ifcase \@tempa\relax
193 \KOMA@kav@remove{\KOMAClassFileName}{toc}{noindex}%
194 \KOMA@kav@remove{\KOMAClassFileName}{toc}{indexnumbered}%
195 \KOMA@kav@remove{\KOMAClassFileName}{toc}{index}%
196 \KOMA@kav@remove{\KOMAClassFileName}{index}{notoc}%
197 \KOMA@kav@remove{\KOMAClassFileName}{index}{numbered}%
198 \KOMA@kav@remove{\KOMAClassFileName}{index}{toc}%
199 \KOMA@kav@add{\KOMAClassFileName}{toc}{noindex}%
200 \KOMA@kav@add{\KOMAClassFileName}{index}{notoc}%
201 \renewcommand*{\idx@@heading}{%
202 \ifidx@leveldown
203 %<article> \expandafter\subsection
204 %<book|report> \expandafter\section
205 \else
206 %<article> \expandafter\section
207 %<book|report> \expandafter\chapter
208 \fi*%
209 }%
210 \let\idx@@mark\idx@@forcemark
211 \or
212 \KOMA@kav@remove{\KOMAClassFileName}{toc}{noindex}%
213 \KOMA@kav@remove{\KOMAClassFileName}{toc}{indexnumbered}%
214 \KOMA@kav@remove{\KOMAClassFileName}{toc}{index}%
215 \KOMA@kav@remove{\KOMAClassFileName}{index}{notoc}%
216 \KOMA@kav@remove{\KOMAClassFileName}{index}{numbered}%
217 \KOMA@kav@remove{\KOMAClassFileName}{index}{toc}%
218 \KOMA@kav@add{\KOMAClassFileName}{toc}{index}%
219 \KOMA@kav@add{\KOMAClassFileName}{index}{toc}%
220 \renewcommand*{\idx@@heading}{%
221 \ifidx@leveldown
222 %<article> \expandafter\expandafter\expandafter\subsection\expandafter*%
223 %<book|report> \expandafter\addsec
224 \else
225 %<article> \expandafter\addsec
226 %<book|report> \expandafter\addchap
227 \fi
228 }%
229 \let\idx@@mark\idx@@forcemark
230 \or
231 \KOMA@kav@remove{\KOMAClassFileName}{toc}{noindex}%
232 \KOMA@kav@remove{\KOMAClassFileName}{toc}{indexnumbered}%
233 \KOMA@kav@remove{\KOMAClassFileName}{toc}{index}%
234 \KOMA@kav@remove{\KOMAClassFileName}{index}{notoc}%
235 \KOMA@kav@remove{\KOMAClassFileName}{index}{numbered}%
236 \KOMA@kav@remove{\KOMAClassFileName}{index}{toc}%
237 \KOMA@kav@add{\KOMAClassFileName}{toc}{indexnumbered}%
238 \KOMA@kav@add{\KOMAClassFileName}{index}{numbered}%
239 \renewcommand*{\idx@@heading}{%
240 \ifidx@leveldown
241 %<article> \expandafter\subsection
242 %<book|report> \expandafter\section
243 \else
244 %<article> \expandafter\section
245 %<book|report> \expandafter\chapter
246 \fi
247 }%
248 \let\idx@@mark\idx@@forcemarknumbered
249 \or
250 \KOMA@kav@remove{\KOMAClassFileName}{index}{leveldown}%
251 \KOMA@kav@remove{\KOMAClassFileName}{index}{standardlevel}%
252 \KOMA@kav@add{\KOMAClassFileName}{index}{leveldown}%
253 \idx@leveldowntrue
254 \or
255 \KOMA@kav@remove{\KOMAClassFileName}{index}{leveldown}%
256 \KOMA@kav@remove{\KOMAClassFileName}{index}{standardlevel}%
257 \KOMA@kav@add{\KOMAClassFileName}{index}{standardlevel}%
258 \idx@leveldownfalse
259 \fi
260 \fi
261 }
262 \KOMA@kav@add{\KOMAClassFileName}{toc}{noindex}
263 \KOMA@kav@add{\KOMAClassFileName}{index}{notoc}
264 \KOMA@kav@add{\KOMAClassFileName}{index}{standardlevel}
265 % \end{macrocode}
266 % \end{macro}^^A \ifidx@leveldown …
267 % \end{macro}^^A \idx@@heading
268 % \end{option}^^A index
269 %
270 % \begin{option}{idxtotoc}
271 % \changes{v2.3h}{1995/01/21}{added}
272 % \changes{v2.98c}{2008/03/04}{obsolete}
273 % \changes{v3.01a}{2008/11/20}{deprecated}
274 % \changes{v3.99}{2022/11/16}{not with \KOMAScript~4}
275 % \begin{macrocode}
276 %<!v4>\KOMA@DeclareDeprecatedOption{idxtotoc}{index=totoc}
277 %</option>
278 % \end{macrocode}
279 % \end{option}
280 %
281 %
282 % \subsection{User commands and macros}
283 %
284 % \begin{command}{\setindexpreamble}
285 % \changes{v2.6c}{2000/06/10}{added}
286 % \changes{v2.6d}{2000/07/20}{\cs{let} replaced by \cs{newcommand*}}
287 % \changes{v2.95}{2002/07/01}{\cs{let} and \cs{def}}
288 % \begin{macro}{\index@preamble}
289 % \changes{v2.6c}{2000/06/10}{added}
290 % The index preamble is placed between the heading an the index itself. The
291 % user can define it using \cs{setindexpreamble}. \cs{index@preamble} is the
292 % storage. Note: \cs{setindexpreamble} does read the argument itself. This
293 % makes it easier to patch the user level command. But because of this it has
294 % to long.
295 % \begin{macrocode}
296 %<*body>
297 \newcommand*{\index@preamble}{}
298 \let\index@preamble=\relax
299 \newcommand{\setindexpreamble}[1]{\def\index@preamble{#1}}
300 % \end{macrocode}
301 % \end{macro}
302 % \end{command}
303 %
304 % \begin{macro}{\idx@heading}
305 % \changes{v2.3h}{1995/01/21}{added}
306 % \changes{v2.4c}{1996/04/04}{handling of running heads fixed}
307 % \changes{v2.4g}{1996/11/04}{two-columned index with \cls*{scrartcl} fixed}
308 % \changes{v2.6c}{2000/06/10}{support for index preamble after heading}
309 % \changes{v2.7j}{2001/05/27}{output of preamble moved to \env{theindex}}
310 % \changes{v2.9l}{2003/01/19}{\cs{if@twoside} replaced by \cs{if@openright}}
311 % \changes{v2.98c}{2008/03/04}{using \cs{idx@@heading}}
312 % \changes{v3.10}{2011/08/31}{using \cs{MakeMarkcase}}
313 % \changes{v3.10a}{2012/03/08}{brackets from previous change fixed}
314 % \changes{v3.12}{2013/09/24}{never make an index entry to the other ToC but
315 % the table of contents}
316 % \changes{v3.25}{2017/10/13}{using \cs{@mkright} and \cs{@mkdouble}}
317 % \changes{v3.26}{2018/09/03}{usage of \cs{addsecmark} or \cs{subsectionmark}
318 % instead of \cs{@mkright}}
319 % \changes{v3.41}{2023/05/05}{using \cs{idx@@mark}}
320 % \changes{v3.41}{2023/05/05}{\cs{cleardoublepage} or \cs{clearpage} only, if
321 % not \opt{leveldown}}
322 % Macro to make the index heading and preamble.
323 % \begin{macrocode}
324 \newcommand*{\idx@heading}{%
325 %<report|book> \ifidx@leveldown\else\if@openright\cleardoublepage\else\clearpage\fi\fi
326 \twocolumn[%
327 %<report|book> \@chaptertolistsfalse
328 \idx@@heading{\indexname}]%
329 \idx@@mark{\indexname}%
330 }
331 % \end{macrocode}
332 % \end{macro}
333 %
334 % \begin{environment}{theindex}
335 % \changes{v2.8d}{2001/07/05}{\cs{indexpagestyle} instead of \pstyle{plain}}
336 % \changes{v2.3h}{1995/01/21}{using \cs{idx@heading}}
337 % \changes{v2.7j}{2001/05/27}{output of preamble added}
338 % \changes{v3.19}{2015/08/25}{using \cs{indexpagestyle} only if not empty}
339 % This definition is similar to the definition of the standard classes. As
340 % addition it supports a preamble text, a variable heading, and resets the
341 % paragraph end line fill.
342 % \begin{macrocode}
343 \newenvironment{theindex}{%
344 \if@twocolumn
345 \@restonecolfalse
346 \else
347 \@restonecoltrue
348 \fi
349 \columnseprule \z@
350 \columnsep 35\p@
351 %<book|report> \setchapterpreamble{\index@preamble}%
352 \idx@heading
353 %<article> \index@preamble\par\nobreak
354 \ifx\indexpagestyle\@empty\else\thispagestyle{\indexpagestyle}\fi
355 \parindent\z@
356 \setlength{\parskip}{\z@ \@plus .3\p@}%
357 \setlength{\parfillskip}{\z@ \@plus 1fil}%
358 \let\item\@idxitem
359 }{%
360 \if@restonecol\onecolumn\else\clearpage\fi
361 }
362 % \end{macrocode}
363 % \begin{macro}{\@idxitem}
364 % A new index entry
365 % \begin{command}{\subitem,\subsubitem}
366 % \changes{v2.3g}{1996/01/14}{using \cs{@idxitem} saves memory}
367 % sub-entry, sub-sub-entry,
368 % \begin{command}{\indexspace}
369 % or (vertical) distance.
370 % \begin{macrocode}
371 \newcommand*\@idxitem{\par\hangindent 40\p@}
372 % \begin{macrocode}
373 \newcommand*\subitem{\@idxitem \hspace*{20\p@}}
374 \newcommand*\subsubitem{\@idxitem \hspace*{30\p@}}
375 \newcommand*\indexspace{%
376 \par \vskip 10\p@ \@plus5\p@ \@minus3\p@\relax
377 }
378 % \end{macrocode}
379 % \end{command}^^A \indexspace
380 % \end{command}^^A \subitem,\subsubitem
381 % \end{macro}^^A \@idxitem
382 % \end{environment}^^A theindex
383 %
384 %
385 % \subsection{Language dependent terms}
386 %
387 % \begin{command}{\indexname}
388 % \changes{v3.36}{2022/02/15}{explicit definition for English languages}
389 % The name of the index (used by \cs{idx@heading}).
390 % \begin{macrocode}
391 \newcommand*\indexname{Index}
392 \providecaptionname{american,australian,british,canadian,english,newzealand,%
393 UKenglish,ukenglish,USenglish,usenglish}\indexname{Index}
394 %</body>
395 % \end{macrocode}
396 % \end{command}
397 %
398 %
399 % \begin{macrocode}
400 %</!letter>
401 % \end{macrocode}
402 %
403 % \Finale
404 % \PrintChanges
405 %
406 \endinput
407 % Local Variables:
408 % mode: doctex
409 % ispell-local-dictionary: "en_US"
410 % eval: (flyspell-mode 1)
411 % TeX-master: t
412 % TeX-engine: luatex-dev
413 % 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"))
414 % End:
415