-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrkernel-basics.dtx
More file actions
5403 lines (5403 loc) · 195 KB
/
scrkernel-basics.dtx
File metadata and controls
5403 lines (5403 loc) · 195 KB
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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
% ======================================================================
% scrkernel-basics.dtx
% Copyright (c) Markus Kohm, 2002-2023
%
% 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.md.
% ======================================================================
%%% From File: $Id: scrkernel-basics.dtx 4074 2023-07-14 15:56:59Z kohm $
%<prepare>%%% (run: prepare)
%<option>%%% (run: option)
%<body>%%% (run: body)
%<load>%%% (run: load)
%<package&prepare>\NeedsTeXFormat{LaTeX2e}[1995/06/01]
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
\begingroup
\def\filedate$#1: #2-#3-#4 #5${\def\filedate{#2/#3/#4}}
\filedate$Date: 2023-07-14 17:56:59 +0200 (Fri, 14 Jul 2023) $
\def\filerevision$#1: #2 ${\def\filerevision{r#2}}
\filerevision$Revision: 4074 $
\edef\reserved@a{%
\noexpand\endgroup
\noexpand\ProvidesFile{scrkernel-basics.dtx}%
[\filedate\space\filerevision\space
KOMA-Script
}
\reserved@a
%</dtx>
%<*dtx|(package&prepare)>
%<package>\ProvidesPackage{%
%<package&base> scrbase%
%<package&koma> scrkbase%
%<package>}[%
%!KOMAScriptVersion
package
%<*dtx>
source
%</dtx>
(%
%<base> KOMA-Script-independent
%<koma> KOMA-Script-dependent
basics and keyval usage)]
%</dtx|(package&prepare)>
%<*dtx>
\ifx\documentclass\undefined
\input scrdocstrip.tex
\@@input scrkernel-version.dtx
\@@input scrstrip.inc
\KOMAdefVariable{COPYRIGHTFROM}{2002}
\generate{\usepreamble\defaultpreamble
\file{scrbase.sty}{%
\from{scrkernel-version.dtx}{package,scrbase}%
\from{scrkernel-basics.dtx}{package,prepare,base}%
\from{scrkernel-basics.dtx}{package,option,base}%
\from{scrkernel-language.dtx}{package,option,base}%
\from{scrkernel-basics.dtx}{package,body,base}%
\from{scrkernel-language.dtx}{package,body,base}%
\from{scrlogo.dtx}{logo}%
}%
}
\@@input scrstrop.inc
\else
\let\endbatchfile\relax
\fi
\endbatchfile
\documentclass[USenglish]{koma-script-source-doc}
\usepackage{babel}
\usepackage{hvlogos}
\setcounter{StandardModuleDepth}{2}
\begin{document}
\DocInput{scrkernel-basics.dtx}
\end{document}
%</dtx>
% \fi^^A meta-comment
%
% \changes{v1.0}{2002/07/06}{starting implementation}
% \changes{v3.12}{203/03/05}{usage of \cs{@tempa}, \cs{@tempb}, \cs{@tempc}
% eliminated}
% \changes{v3.36}{2022/02/16}{switch over from \cls*{scrdoc} to
% \cls*{koma-script-source-doc}}
% \changes{v3.36}{2022/02/21}{whole implementation documentation in English}
% \changes{v3.40}{2023/04/17}{guide names changed}
%
% \GetFileInfo{scrkernel-basics.dtx}
% \title{Basic Funktionality Used by Almost all
% \href{https://komascript.de}{\KOMAScript} Classes and Packages}
% \author{\href{mailto:komascript@gmx.info}{Markus Kohm}}
% \date{Revision \fileversion{} of \filedate}
% \maketitle
% \begin{abstract}
% New versions of \KOMAScript{} make increasing use of the \pkg{keyval}
% package. The \pkg{keyval} package is part of the \pkg{graphics} package
% and as such must be included on all \TeX{} systems with \LaTeX{}. However,
% it does not meet the requirements of \KOMAScript{} in some
% respects. Therefore, extensions are made here which can be used by
% \KOMAScript classes and \KOMAScript packages.
%
% In addition, more and more parts of \KOMAScript{} are used by more than
% one package or by packages and classes. These basic things have therefore
% been split into two packages, \pkg*{scrbase} (for things that can also be
% used by other classes and packages) and \pkg*{scrkbase} (for things that
% are reserved for \pkg*{scrkbase}). This makes the packages and classes
% themselves smaller and they can still be used independently. Of course you
% can also use this package without the rest of \KOMAScript{}.
% \end{abstract}
% \tableofcontents
%
% \section{User Manual}
%
% You can find the user documentation of package \pkg*{scrbase} and the
% commands implemented in \file{scrkernel-basics.dtx} in the \KOMAScript{}
% manual, either the German \file{scrguide-de.pdf} or the English
% \file{scrguide-en.pdf}.
%
%
% \subsection{Features not yet in the user manuals}
%
% Some user commands are not documented in the \KOMAScript{} manuals, e.g.,
% because they are not stable enough to be used by average users or more or
% less for internal usage only. Some are only not documented in the
% \KOMAScript{} manual, because nobody has done it yet.
%
% \DescribeCommand\IfLTXAtLeastTF
% \marginpar{\raggedleft\tiny Added: 2021-01-31}%
% This is the same like \cs{IfFormatAtLeast} of \LaTeX{} from 2020/10/01, but
% works also with older \LaTeX{} kernels.
%
% \DescribeCommand\Ifislengthprimitive
% \marginpar{\raggedleft\tiny Added: 2015/10/19\\Renamed: 2022/02/17}%
% \cs{Ifislengthprimitive}\marg{macro}\marg{then code}\marg{else code}
% expands the \meta{macro} and tests if the result can be used as a length
% primitive. If this is the case the \meta{then code} is executed, otherwise
% the \meta{else code}. Note, that this command can be false negative,
% because, i.e., with \LuaLaTeX{} there can be primitives, that are like length,
% but that are not known by \cs{Ifislengthprimitive}.
%
% \DescribeCommand\Ifisdefchar
% \marginpar{\raggedleft\tiny Added: 2015/10/19\\Renamed: 2022/02/17}%
% \cs{Ifislengthprimitive}\marg{macro}\marg{then code}\marg{else code}
% expands the \meta{macro} and tests if the result is a \cs{char}. If this is
% the case the \meta{then code} is executed, otherwise the \meta{else code}.
% Note, that this command can be false positive, if the \cs{char} value is
% incorrect.
%
%
% \MaybeStop{\PrintIndex}
%
% \section{Implementation of \pkg*{scrbase} and \pkg*{scrkbase}}
%
% \subsection{Loading \pkg*{scrkbase}}
% Who ever loads ths package, always wants the same version of the already
% used \KOMAScript version.
% \begin{macrocode}
%<*load>
\RequirePackage{scrkbase}[\KOMAScriptVersion]
%</load>
% \end{macrocode}
%
%
% \subsection{\eTeX{} test}
% \changes{v3.02c}{2009/02/19}{error message without \eTeX}
%
% \begin{macrocode}
%<*prepare>
%<*base>
\begingroup
\def\reserved@b{}%
\def\reserved@a#1{%
\PackageError{scrbase}{seems you are not running e-TeX#1}{%
Since 2004 the LaTeX team recommends to use e-TeX.\MessageBreak
KOMA-Script since version 2.95 uses several e-TeX features.\MessageBreak
At actual systems `latex' should already use e-TeX.\MessageBreak
At deprecated systems it may be called `elatex'.\MessageBreak
Use either unsupported KOMA-Script up to version 2.9u or\MessageBreak
ask you administrator for LaTeX using e-TeX#1.\MessageBreak
Not using e-TeX#1 is a fatal error!\MessageBreak
Processing cannot be continued!}%
\endgroup
\batchmode \errmessage{}\csname @@end\endcsname\end\relax
\csname endinput\endcsname
}%
\expandafter\ifx\csname eTeXversion\endcsname\relax\else
\ifnum\eTeXversion <2
\def\reserved@b{ V 2}%
\else
\let\reserved@a\endgroup
\fi
\fi
\expandafter\reserved@a\expandafter{\reserved@b}
%</base>
% \end{macrocode}
%
%
% \subsection{The \KOMAScript-only package loads the universal package}
%
% Once again the same version is wanted.
% \begin{macrocode}
%<koma>\RequirePackage{scrbase}[\KOMAScriptVersion]
% \end{macrocode}
%
% \subsection{Package \pkg*{scrlfile}}
%
% We need to react on the loading other packages like \pkg{polyglossia}. For
% this we use \pkg*{scrlfile}. But we can use any version.
%
% \begin{macrocode}
%<base>\RequirePackage{scrlfile}
% \end{macrocode}
%
% \subsection{Package \pkg*{keyval}}
%
% The \KOMAScript{} key handling bases on package \pkg{keyval}.
% \begin{macrocode}
%<base>\RequirePackage{keyval}
% \end{macrocode}
%
%
% \subsection{Using protected kernel macros}
% Some package like \pkg{amsgen} redefine internal \LaTeX{} kernel macros, but
% break them for other purposes than the own. So I have to make them work
% again. The \KOMAScript{} classes have less problems with this, because most
% of these packages cannot be loaded before a class. So the classes can simply
% copy the original macro, before it is redefined. But I do not know, when a
% package is loaded. So I have to implement the whole macro again with another
% name (and can only hope, that such packages do not damage them also).
%
% \begin{macro}{\kernel@ifstar}
% \changes{v3.20}{2016/04/12}{added}
% I hope, the \LaTeX{} kernel will define this in future and other packages do
% not redefine like they do with \cs{@ifstar}. So I use \cs{providecommand} to
% not redefine the kernel macro, if it does exist.
% \begin{macrocode}
%<base>\providecommand*\kernel@ifstar[1]{\kernel@ifnextchar*{\@firstoftwo{#1}}}
% \end{macrocode}
% \end{macro}^^A \kernel@ifstar
%
%
% \subsection{Improved \LaTeX{} kernel commands}
% The \LaTeX{} kernel already provides some useful commands, but some can be
% improved.
%
% \begin{command}{\rloop}
% \changes{v3.30}{2020/03/07}{added}
% The \cs{loop} \dots \cs{repeat} of the \LaTeX{} kernel cannot be used inside
% a \cs{loop} \dots \cs{repeat} without extra code for preserving
% \cs{iterate}. So here is a re-entrant version that is also long. This
% version can be used even inside a \cs{loop} \dots \cs{repeat}. However you
% should not use \cs{loop} \dots \cs{repeat} inside \cs{rloop} \dots
% \cs{repeat}.
% \begin{macrocode}
%<*base>
\newcommand{\rloop}[1]{}
\long\def\rloop#1\repeat{%
\ifdefined\iterate
\edef\iterate{\unexpanded{#1\relax\expandafter\iterate\fi\def\iterate}%
{\unexpanded\expandafter{\iterate}}}%
\else
\def\iterate{#1\relax\expandafter\iterate\fi\let\iterate\relax}%
\fi
\iterate
}
%</base>
% \end{macrocode}
% \end{command}
%
% \begin{command}{\IfLTXAtLeastTF}
% \changes{v3.33}{2021/01/21}{new}
% This is the same like \cs{IfFormatAtLeastTF} of the current \LaTeX{} kernel,
% but does also work, if \cs{IfFormatAtLeastTF} is not defined because of
% very old \LaTeX{} kernel.
% \begin{macrocode}
%<*base>
\newcommand*{\IfLTXAtLeastTF}{\@ifl@t@r\fmtversion}
\ifcsname IfFormatAtLeastTF\endcsname
\let\IfLTXAtLeastTF\IfFormatAtLeastTF
\fi
\@onlypreamble\IfLTXAtLeastTF
%</base>
% \end{macrocode}
% \end{command}
%
%
% \subsection{Testing macros}
%
% \begin{macro}{\scr@ifundefinedorrelax}
% \changes{v2.95c}{2006/08/12}{added}
% \changes{v2.97b}{2007/03/08}{broken logic fixed}
% \changes{v2.97c}{2007/04/18}{broken functionality fixed}
% \changes{v2.97c}{2007/04/18}{\cs{scr@ifundefined} renamed}
% \changes{v3.02c}{2009/02/19}{special treatment of \eTeX{} removed}
% This macro is like \cs{@ifundefined}, but does not define the test macro
% \cs{relax} if it was undefined before. Note: With up-to-date \LaTeX{} this
% is the same with the original \cs{@ifundefined}.
% \begin{macrocode}
%<*base>
\newcommand{\scr@ifundefinedorrelax}[1]{%
\ifcsname #1\endcsname
\expandafter\ifx\csname #1\endcsname\relax
\expandafter\expandafter\expandafter\@firstoftwo
\else
\expandafter\expandafter\expandafter\@secondoftwo
\fi
\else
\expandafter\@firstoftwo
\fi
}
%</base>
% \end{macrocode}
% \end{macro}^^A \scr@ifundefinedorrelax
%
%
% \subsection{Extending messages}
%
% \begin{command}{\PackageErrorNoLine}
% \changes{v3.12}{2013/09/19}{added}
% \changes{v3.28}{2019/11/23}{nonsense command removed}
% Falk correctly stated, that \cs{PackageError} already does not show a line
% number. So we do not need this command.
% \end{command}
%
%
% \subsection{Definition of the \KOMAScript{} \pkg*{keyval} basis}
%
% \KOMAScript{} could use \pkg{keyval} keys with the same set of keywords
% ``\texttt{KOMA}'' to make it possible, that packages can redefine keys of
% classes and other packages. However this would be dangerous and can easily
% break. So we split the set of keywords in an family of keywords and family
% member of keywords and define commands to process the keywords either of a
% member or a whole family.
%
% \begin{command}{\DefineFamily,\DefineFamilyMember,\DefineFamilyKey}
% \changes{v3.00}{2008/04/30}{added}
% \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by \cs{kernel@ifnextchar}}
% \begin{macro}{\scr@if@family}
% \changes{v3.00}{2008/04/30}{added}
% \begin{macro}{\scr@if@familymember}
% \changes{v3.00}{2008/04/30}{added}
% \changes{v3.27}{2019/07/19}{the empty member exists by default}
% \begin{macro}{\scr@define@family@key}
% \changes{v3.00}{2008/04/30}{added}
% \begin{macro}{\scr@define@family@key@nodefault}
% \changes{v3.00}{2008/04/30}{added}
% \changes{v3.18a}{2015/07/03}{missing \% added}
% Family, member of a family and \pkg{keyval} key for a member of a
% family. The default of the member of a family is always the file name of a
% class or package (while reading the file).
% \begin{macrocode}
%<*base>
\newcommand*{\DefineFamily}[1]{%
\scr@ifundefinedorrelax{#1@key@familylist}{%
\@namedef{#1@key@familylist}{}%
}{}%
}
\newcommand*{\scr@if@family}[2]{%
\scr@ifundefinedorrelax{#1@key@familylist}{%
\PackageError{scrbase}{%
unknown family `#1'%
}{%
You've tried to #2 for family `#1'.\MessageBreak
This my be done only for previous defined families.\MessageBreak
You should call `\string\DefineFamily{#1}' first.%
}%
}%
}
\newcommand*{\DefineFamilyMember}[2][.\@currname.\@currext]{%
\scr@if@family{#2}{define a family member}{%
\edef\reserved@a{%
\noexpand\in@{#2#1,}{\csname #2@key@familylist\endcsname}}%
\reserved@a
\ifin@\else
\expandafter\edef\csname #2@key@familylist\endcsname{%
\@nameuse{#2@key@familylist}#2#1,}%
\fi
}%
}
\newcommand*{\scr@if@familymember}[3]{%
\scr@if@family{#2}{#3}{%
\IfArgIsEmpty{#1}{%
\@firstofone
}{%
\edef\reserved@a{%
\noexpand\in@{#2#1,}{\csname #2@key@familylist\endcsname}}%
\reserved@a
\ifin@
\expandafter\@firstofone
\else
\PackageError{scrbase}{%
unknown member `#1' at family `#2'%
}{%
You've tried to #3 for member `#1' of family `#2'.\MessageBreak
This my be done only for previous defined family members.\MessageBreak
You should call `\string\DefineFamilyMember[{#1}]{#2}' first.%
}%
\expandafter\@gobble
\fi
}%
}%
}
\newcommand*{\DefineFamilyKey}[3][.\@currname.\@currext]{%
\kernel@ifnextchar[%]
{%
\edef\reserved@a{#1}%
\expandafter\scr@define@family@key
\expandafter{\reserved@a}{#2}{#3}%
}{%
\edef\reserved@a{#1}%
\expandafter\scr@define@family@key@nodefault
\expandafter{\reserved@a}{#2}{#3}%
}%
}
\newcommand{\scr@define@family@key}{}
\long\def\scr@define@family@key#1#2#3[#4]#5{%
\scr@if@familymember{#1}{#2}{define a key}{%
\define@key{#2#1}{#3}[{#4}]{%
\def\FamilyOfKey{#2}\def\FamilyMemberOfKey{#1}%
\FamilyKeyStateUnknown
#5%
\def\FamilyOfKey{#2}\def\FamilyMemberOfKey{#1}%
}%
}%
}
\newcommand{\scr@define@family@key@nodefault}[4]{%
\scr@if@familymember{#1}{#2}{define a key}{%
\define@key{#2#1}{#3}{%
\def\FamilyOfKey{#2}\def\FamilyMemberOfKey{#1}%
\FamilyKeyStateUnknown
#4%
\def\FamilyOfKey{#2}\def\FamilyMemberOfKey{#1}%
}%
\@namedef{KV@#2#1@#3@default}{%
\def\FamilyOfKey{#2}\def\FamilyMemberOfKey{#1}%
\FamilyKeyStateNeedValue
}%
}%
}
%</base>
% \end{macrocode}
% \end{macro}^^A \scr@define@family@key@nodefault
% \end{macro}^^A \scr@define@family@key
% \end{macro}^^A \scr@if@familymember
% \end{macro}^^A \scr@if@family
% \end{command}^^A \DefineFamily,\DefineFamilyMember,\DefineFamilyKey
%
%
% \begin{command}{\RelaxFamilyKey}
% \changes{v3.15}{2014/12/03}{added}
% Sometimes it is useful to be able to \emph{un-define} a key. This will not
% un-define all helper macros but only the key and a default value will become
% \cs{relax}.
% \begin{macrocode}
%<*base>
\newcommand*{\RelaxFamilyKey}[3][.\@currname.\@currext]{%
\scr@ifundefinedorrelax{KV@#2#1@#3}{}{%
\expandafter\let\csname KV@#2#1@#3\endcsname\relax
}%
\scr@ifundefinedorrelax{KV@#2#1@#3@default}{}{%
\expandafter\let\csname KV@#2#1@#3@default\endcsname\relax
}%
}
%</base>
% \end{macrocode}
% \end{command}^^A \RelaxFamilyKey
%
% \begin{command}{\FamilyKeyState,\FamilyKeyStateProcessed,\FamilyKeyStateUnknown,
% \FamilyKeyStateUnknownValue,\FamilyKeyStateNeedValue}
% \changes{v3.12}{2013/03/04}{added}
% \cs{FamilyKeyState} is the state of processing a key. The initial state is
% \cs{FamilyKeyStateUnknown}, so the state is indeed unknown. If a key has
% been processed by the definition code and everything is OK, you should run
% \cs{FamilyKeyStateProcessed}. This will set \cs{FamilyKeyState} also to
% \cs{FamilyKeyStateProcessed} to indicate, the key has been processed
% successfully. If the value assigned to the key is unknown, you should run
% \cs{FamilyKeyStateUnknownValue}. And if the value is needed but no value has
% been assigned, \cs{FamilyKeyStateNeedValue} is the correct choice. Note:
% \cs{FamilyKeyState} is valid only immediately after processing a key.
% \begin{macrocode}
%<*base>
\newcommand*{\FamilyKeyState}{}
\newcommand*{\FamilyKeyStateUnknown}{%
\let\FamilyKeyState\FamilyKeyStateUnknown
}
\newcommand*{\FamilyKeyStateUnknownValue}{%
\let\FamilyKeyState\FamilyKeyStateUnknownValue
}
\newcommand*{\FamilyKeyStateNeedValue}{%
\let\FamilyKeyState\FamilyKeyStateNeedValue
}
\newcommand*{\FamilyKeyStateProcessed}{%
\let\FamilyKeyState\FamilyKeyStateProcessed
}
\let\FamilyKeyState\FamilyKeyStateUnknown
%</base>
% \end{macrocode}
% \end{command}^^A \FamilyKeyState … \FamilyKeyStateNeedValue
%
% \begin{command}{\FamilyOfKey,\FamilyMemberOfKey}
% \changes{v3.12}{2013/03/04}{added}
% While processing a key, this is the family and the member of family.
% \begin{macrocode}
%<*base>
\newcommand*{\FamilyOfKey}{}
\newcommand*{\FamilyMemberOfKey}{}
%</base>
% \end{macrocode}
% \end{command}^^A \FamilyOfKey,\FamilyMemberOfKey
%
% \begin{macro}{\KOMA@key}
% \changes{v2.97c}{2007/04/19}{optional argument added}
% \changes{v3.17}{2015/02/24}{rudimentary value storage}
% \changes{v3.39}{2022/11/11}{initial dot added automatically}
% \pkg{keyval} keys of \KOMAScript{} are defined with \cs{KOMAkey} to setup
% the family to ``\texttt{KOMA}'' automatically. Additionally the value
% storage is initialized.
% \begin{macrocode}
%<*koma>
\newcommand*{\KOMA@key}[1][\@currname.\@currext]{%
\DefineFamilyMember[{.#1}]{KOMA}%
\@ifundefined{scr@kav@KOMA.#1}{\@namedef{scr@kav@KOMA.#1}{}}{}%
\DefineFamilyKey[{.#1}]{KOMA}%
}
%</koma>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KOMA@kav@add}
% \changes{v3.17}{2015/02/24}{added}
% \changes{v3.39}{2022/11/11}{initial dot added automatically}
% This macro stores a \texttt{\meta{key}=\meta{value}} pair in a internal
% list. The first argument is the family member, the second the \meta{key} and
% the third the \meta{value}.
% \begin{macrocode}
%<*koma>
\newcommand*{\KOMA@kav@add}[3]{%
\@ifundefined{scr@kav@KOMA.#1}{%
\KOMA@internal@error\KOMA@kav@add{#1}%
}{%
\expandafter\l@addto@macro\csname scr@kav@KOMA.#1\endcsname{\do{{#2}{#3}}}%
}%
}
%</koma>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KOMA@kav@xadd}
% \changes{v3.17}{2015/02/24}{added}
% This macro stores a \texttt{\meta{key}=\meta{value}} pair in a internal
% list after expanding both, the \meta{key} and the \meta{value}. The first
% argument is the family member, the second the \meta{key} and the third the
% \meta{value}.
% \begin{macrocode}
%<*koma>
\newcommand*{\KOMA@kav@xadd}[3]{%
\@ifundefined{scr@kav@KOMA.#1}{%
\KOMA@internal@error\KOMA@kav@xadd{#1}%
}{%
\protected@edef\reserved@a{{#2}{#3}}%
\expandafter\l@addto@macro\csname scr@kav@KOMA.#1\expandafter\endcsname
\expandafter{\expandafter\do\expandafter{\reserved@a}}%
}%
}
%</koma>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KOMA@kav@remove}
% \changes{v3.17}{2015/02/24}{added}
% This macro removes a \texttt{\meta{key}=\meta{value}} pair from the internal
% list. The first argument is the family member, the second the \meta{key} and
% the third the \meta{value}.
% \begin{macrocode}
%<*koma>
\newcommand*{\KOMA@kav@remove}[3]{%
\@ifundefined{scr@kav@KOMA.#1}{%
\KOMA@internal@error\KOMA@kav@remove{#1}%
}{%
\begingroup
\def\reserved@a{\endgroup\@namedef{scr@kav@KOMA.#1}{}}%
\edef\reserved@b{\detokenize{{#2}{#3}}}%
\def\do##1{%
\edef\reserved@c{\detokenize{##1}}%
\ifx\reserved@b\reserved@c\else
\l@addto@macro\reserved@a{%
\expandafter\l@addto@macro\csname scr@kav@KOMA.#1\endcsname{%
\do{##1}%
}%
}%
\fi
}%
\@nameuse{scr@kav@KOMA.#1}%
\reserved@a
}%
}
%</koma>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KOMA@kav@removekey}
% \changes{v3.17}{2015/02/24}{added}
% \changes{v3.39}{2022/11/11}{initial dot added automatically}
% This macro removes all \texttt{\meta{key}=\meta{value}} pairs of a given
% \meta{key} from the internal list. The first argument is the family member,
% the second the \meta{key}.
% \begin{macrocode}
%<*koma>
\newcommand*{\KOMA@kav@removekey}[2]{%
\@ifundefined{scr@kav@KOMA.#1}{%
\KOMA@internal@error\KOMA@kav@removekey{#1}%
}{%
\begingroup
\def\reserved@a{\endgroup\@namedef{scr@kav@KOMA.#1}{}}%
\edef\reserved@b{\detokenize{#2}}%
\def\reserved@d##1##2{\edef\reserved@c{\detokenize{##1}}}%
\def\do##1{%
\reserved@d##1\relax
\ifx\reserved@b\reserved@c\else
\l@addto@macro\reserved@a{%
\expandafter\l@addto@macro\csname scr@kav@KOMA.#1\endcsname{%
\do{##1}%
}%
}%
\fi
}%
\@nameuse{scr@kav@KOMA.#1}%
\reserved@a
}%
}
%</koma>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KOMA@kav@replacevalue,\KOMA@kav@xreplacevalue}
% \changes{v3.17}{2015/02/25}{added}
% \changes{v3.39}{2022/11/11}{initial dot added automatically}
% If \cs{FamilyKeyState} is \cs{FamilyKeyStateProcessed},
% these macros replace a \texttt{\meta{key}=\meta{value}} pair in the internal list.
% The first argument is the family member, the second the \meta{key} and the
% third is the new \meta{value}. \cs{KOMA@kav@xreplacevalue} expands both, the
% \meta{key} and the \meta{value}.
% \begin{macrocode}
%<*koma>
\newcommand*{\KOMA@kav@replacevalue}[3]{%
\ifx\FamilyKeyState\FamilyKeyStateProcessed
\@ifundefined{scr@kav@KOMA.#1}{%
\KOMA@internal@error\KOMA@kav@replacevalue{#1}%
}{%
\KOMA@kav@removekey{#1}{#2}%
\KOMA@kav@add{#1}{#2}{#3}%
}%
\fi
}
\newcommand*{\KOMA@kav@xreplacevalue}[3]{%
\ifx\FamilyKeyState\FamilyKeyStateProcessed
\@ifundefined{scr@kav@KOMA.#1}{%
\KOMA@internal@error\KOMA@kav@replacevalue{#1}%
}{%
\KOMA@kav@removekey{#1}{#2}%
\KOMA@kav@xadd{#1}{#2}{#3}%
}%
\fi
}
%</koma>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KOMA@kav@replacebool}
% \changes{v3.17}{2015/02/24}{added}
% \changes{v3.39}{2022/11/11}{initial dot added automatically}
% If \cs{FamilyKeyState} is \cs{FamilyKeyStateProcessed},
% this macro replaces the value of a if key in the internal list.
% The first argument is the family member, the second the \meta{key} and the
% third is the boolean switch (\cs{if\dots} statement) representing the new value.
% \begin{macrocode}
%<*koma>
\newcommand*{\KOMA@kav@replacebool}[3]{%
\ifx\FamilyKeyState\FamilyKeyStateProcessed
\@ifundefined{scr@kav@KOMA.#1}{%
\KOMA@internal@error\KOMA@kav@replacebool{#1}%
}{%
\KOMA@kav@remove{#1}{#2}{false}%
\KOMA@kav@remove{#1}{#2}{true}%
\expandafter\ifx\csname if#3\expandafter\endcsname
\csname iftrue\endcsname
\KOMA@kav@xadd{#1}{#2}{true}%
\else
\KOMA@kav@xadd{#1}{#2}{false}%
\fi
}%
\fi
}
%</koma>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KOMA@kav@defall}
% \changes{v3.17}{2015/02/24}{added}
% \changes{v3.39}{2022/11/11}{initial dot added automatically}
% This macro defines a macro/command with the \texttt{\meta{key}=\meta{value}}
% list of all stored pairs. The first argument is the macro/command to be
% defined with the list. The second is the family member.
% \begin{macrocode}
%<*koma>
\newcommand*{\KOMA@kav@defall}[2]{%
\@ifundefined{scr@kav@KOMA.#2}{%
\KOMA@internal@error\KOMA@kav@defall{#1}%
}{%
\begingroup
\let\reserved@a\@empty
\def\reserved@b##1##2{\l@addto@macro\reserved@a{,{##1=##2}}}%
\def\do##1{\reserved@b##1}%
\@nameuse{scr@kav@KOMA.#2}%
\ifx\reserved@a\@empty
\def\reserved@b{\endgroup\let#1\@empty}%
\else
\edef\reserved@b{%
\unexpanded{\endgroup\def#1}{%
\unexpanded
\expandafter\expandafter\expandafter{%
\expandafter\@gobble\reserved@a}}}%
\fi
\reserved@b
}%
}
%</koma>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KOMA@kav@defone}
% \changes{v3.17}{2015/02/25}{added}
% \changes{v3.28}{2019/11/18}{\cs{ifstrstart} renamed to \cs{Ifstrstart}}
% \changes{v3.39}{2022/11/11}{initial dot added automatically}
% This macro defines a macro/command with all stored values of a \meta{key}
% from the internal list of \texttt{\meta{key}=\meta{value}} pairs.
% The first argument is the macro/command to be defined. The second is the
% family member and the third is the \meta{key}.
% \begin{macrocode}
%<*koma>
\newcommand*{\KOMA@kav@defone}[3]{%
\@ifundefined{scr@kav@KOMA.#2}{%
\KOMA@internal@error\KOMA@kav@defall{#1}%
}{%
\begingroup
\let\reserved@a\@empty
\def\reserved@b##1##2{%
\Ifstr{##1}{#3}{\l@addto@macro\reserved@a{,{##2}}}{}%
}%
\def\do##1{\reserved@b##1}%
\@nameuse{scr@kav@KOMA.#2}%
\ifx\reserved@a\@empty
\def\reserved@b{\endgroup\let#1\@empty}%
\else
\edef\reserved@b{%
\unexpanded{\endgroup\def#1}{%
\unexpanded
\expandafter\expandafter\expandafter{%
\expandafter\@gobble\reserved@a}}}%
\fi
\reserved@b
}%
}
%</koma>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\KOMA@internal@error}
% \changes{v3.17}{2015/02/24}{added}
% \changes{v3.39}{2022/11/11}{bug report address changed}
% General internal error message with the recommendation to report a bug.
% \begin{macrocode}
%<*koma>
\newcommand*{\KOMA@internal@error}[2]{%
\PackageError{scrkbase}{internal error using \string#1{#2}}{%
You've found an internal error either in KOMA-Script or a third
party\MessageBreak
definition, that uses KOMA-Script internal macros.\MessageBreak
Please send a bug report with a minimal but complete example,
that\MessageBreak
shows this error, to komascript at gmx dot info or report it
at\MessageBreak
<https://sf.net/p/koma-script/tickets/> (you need an account to do so).%
}%
}
%</koma>
% \end{macrocode}
% \end{macro}
%
% \subsection{Options}
%
% From version 2.97c \KOMAScript{} processes all options in the order they
% have been set and no longer in the order they have been defined. This is
% much more intuitive for users. Packages first process the global options
% then the local options.
%
% \begin{macro}{\@globaloptionslist}
% \changes{v2.96}{2006/11/26}{added}
% \changes{v2.96}{2006/11/26}{process class options}
% \changes{v3.20}{2016/02/06}{delay decisions}
% The lost of global options is sometimes needed. But because \pkg{xkeyval}
% has the opinion it should remove all options with equal char from the list
% of class options, we define out own macro with a copy of the class
% options. Until \KOMAScript{} 3.19a the copy has been done here. But if
% \pkg*{scrbase} is loaded before \cs{documentclass} this is too early. From
% \KOMAScript{} 3.20 the assignment has been moved to
% \cs{FamilyProcessOptions}. And from \KOMAScript{} 3.33 the normal class
% option list is only used if the raw option list is not available.
% \begin{macrocode}
%<*base>
\newcommand*{\@globaloptionslist}{}
%</base>
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\scr@removeunused,\scr@optiontest,\scr@pti@ntest}
% \changes{v2.97c}{2007/04/18}{added}
% \changes{v3.12}{2013/03/04}{removed}
% \end{macro}^^A \scr@removeunused,\scr@optiontest,\scr@pti@ntest
%
% \begin{command}{\FamilyProcessOptions}
% \changes{v3.00}{2008/04/30}{added}
% \changes{v3.11a}{2012/06/11}{classes do not report errors for unknown values}
% \changes{v3.12}{2013/03/04}{error handling}
% \changes{v3.33}{2021/03/02}{new version using raw options lists of \LaTeX{}
% 2021/05/01}
% Note: Wrong values should not result in errors or warnings and only seldom
% in information. The best is to signal all kind of errors via
% \cs{FamilyKeyState}. Only values, that cannot be handled by any family
% member have to be reported. This is done inside \cs{FamilyProcessOptions}
% depending on \cs{FamilyKeyState} of each member.
% Note also: This command is not re-entrant. So it cannot be used while
% processing another option.
% Note also: We use 2021/05/01 instead of the official \LaTeX{} release date,
% to detect a \LaTeX{} kernel version with raw option lists, because there
% were relevant earlier \LaTeX{} developer releases with that date.
% \begin{macrocode}
%<*base>
\IncludeInRelease{2021/05/01}{\FamilyProcessOptions}%
{Usage of raw or classic option list}
\newcommand*{\FamilyProcessOptions}[2][.\@currname.\@currext]{%
% \end{macrocode}
% Before processing of the options we have to execute an initialise several
% hooks:
% \begin{macrocode}
\ifx\AtEndOfFamilyOptions\scr@AtEndOfFamilyOptions
\PackageError{scrbase}{nested \string\FamilyProcessOptions\space
detected\MessageBreak}{%
\string\FamilyProcessOptions\space has been used while processing or
setting options.\MessageBreak
This is currently not allowed. You should contact the author of the
causing\MessageBreak
code.\MessageBreak
This error is fatal. You should not continue.%
}%
\fi
\scr@ifundefinedorrelax{scr@before@process@options@#2@hook}{}{%
\@nameuse{scr@before@process@options@#2@hook}%
}%
\scr@ifundefinedorrelax{scr@before@process@options@#2#1@hook}{}{%
\@nameuse{scr@before@process@options@#2#1@hook}%
\expandafter\let\csname scr@before@process@options@#2#1@hook\endcsname
\relax
}%
\scr@ifundefinedorrelax{scr@after@options@#2@hook}{%
\@namedef{scr@after@options@#2@hook}{%
\@namedef{scr@after@options@#2@hook}{}%
}%
}{%
\expandafter\edef\csname scr@after@options@#2@hook\endcsname{%
\noexpand\@namedef{scr@after@options@#2@hook}{%
\unexpanded\expandafter\expandafter\expandafter
{\csname scr@after@options@#2@hook\endcsname}%
}%
}%
}%
\ifx\AtEndOfFamilyOptions\scr@AtEndOfFamilyOptions@immediate
\@namedef{scr@after@options@#2@hook@topmost}{%
\@namedef{scr@after@options@#2@hook@topmost}{}%
}%
\expandafter\l@addto@macro\csname scr@after@options@#2@hook\endcsname{%
\let\AtEndOfFamilyOptions\scr@AtEndOfFamilyOptions@immediate
\@nameuse{scr@after@options@#2@hook@topmost}%
}%
\let\AtEndOfFamilyOptions\scr@AtEndOfFamilyOptions
\fi
\let\ds@\@empty
% \end{macrocode}
% Here we set up \cs{@curroptions} to the raw options of the current class or
% package or empty if the options are not defined.
% \begin{macrocode}
\@ifundefined{@raw@opt@\@currname.\@currext}{%
\let\@curroptions\@empty
}{%
\expandafter\let\expandafter\@curroptions
\csname @raw@opt@\@currname.\@currext\endcsname
}%
% \end{macrocode}
% If this is not a class, we first have to process all raw class options.
% \changes{v3.33}{2021/03/12}{switched to fast test like \LaTeX{} 2021/06/01}
% \changes{v3.34}{2021/05/30}{use \cs{@raw@classoptionslist} only, if defined}
% Note, if \pkg*{scrbase} or a depending package is loaded before the class,
% \cs{@raw@classoptionslist} should not be processed.
% \begin{macrocode}
\ifx\@currext\@clsextension\else
\@ifundefined{@raw@classoptionslist}{}{%
\@for\CurrentOption:=\@raw@classoptionslist\do{%
\scr@trim@spaces\CurrentOption
\ifx\CurrentOption\@empty\else
% \end{macrocode}
% \changes{v3.41}{2023/04/26}{only one step expansion while classic option
% test}
% Because we are using the raw option list, we do only a one step expansion of
% \cs{CurrentOption} here, because a full expansion could break.
% \begin{macrocode}
\@ifundefined{ds@\expandafter\detokenize\expandafter{\CurrentOption}}{%
\scr@ifprocess@curroption{#1}{#2}{%
\@expandtwoargs\@removeelement{%
\expandafter\@remove@eq@value\CurrentOption=\@nil}%
\@unusedoptionlist\@unusedoptionlist
}{}%
}{%
\@use@ption
\expandafter\let\csname ds@\CurrentOption\endcsname\@empty
}%
\fi
}%
}%
\fi
% \end{macrocode}
% \changes{v3.34}{2021/06/05}{extra test because of \LaTeX{} raw option issue}
% Afterwards we have to process the current options. Unfortunately there is an
% issue with the raw option list of the \LaTeX{} kernel, that could result in
% \cs{CurrentOption} in the option list instead of the one step expansion of
% \cs{CurrentOption} (see
% \url{https://sourceforge.net/p/koma-script/tickets/10/}). This would result
% in an infinite loop using the usual loop:
% \begin{macrocode}
%<*dontusethis>
\@for\CurrentOption:=\@curroptions\do{%
\scr@trim@spaces\CurrentOption
% \end{macrocode}
% \changes{v3.41}{2023/04/26}{only one step expansion while classic option
% test}
% Because we are using the raw option list, we do only a one step expansion of
% \cs{CurrentOption} here, because a full expansion could break.
% \begin{macrocode}
\@ifundefined{ds@\expandafter\detokenize\expandafter{\CurrentOption}}{%
\@use@ption
\scr@ifprocess@curroption{#1}{#2}{}\default@ds
}\@use@ption
}%
%</dontusethis>
% \end{macrocode}
% So for a little more rosbustnes we do an extra test.
% \begin{macrocode}
\@for\reserved@a:=\@curroptions\do{%
\scr@trim@spaces\reserved@a
\def\reserved@b{\CurrentOption}%
\ifx\reserved@a\reserved@b
\PackageError{scrbase}{%
\string\CurrentOption\space loop detected\MessageBreak
Perhaps someone uses:\MessageBreak\space\space
\ifx\@currext\@clsextension
\string\PassOptionsToClass
\else
\string\PassOptionsToPackage
\fi
{\string\CurrentOption}{…}.\MessageBreak
With LaTeX 2020/10/01 or 2021/06/01 this results in
\string\CurrentOption\MessageBreak
in the raw option list and therefore is not allowed.\MessageBreak
Please ask the class or package author to use:\MessageBreak\space\space
\string\expandafter
\ifx\@currext\@clsextension
\string\PassOptionsToClass
\else
\string\PassOptionsToPackage
\fi
\MessageBreak\space\space\space
\string\expandafter{\string\CurrentOption}{…}\MessageBreak
instead or update LaTeX (if possible)%
}%
\let\CurrentOption\@empty
\else
\let\CurrentOption\reserved@a
\fi
% \end{macrocode}
% \changes{v3.41}{2023/04/26}{only one step expansion while classic option
% test}
% Because we are using the raw option list, we do only a one step expansion of