-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtocbasic.dtx
More file actions
2224 lines (2211 loc) · 80.1 KB
/
tocbasic.dtx
File metadata and controls
2224 lines (2211 loc) · 80.1 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
% ======================================================================
% ======================================================================
%
% This is a modified version of tocbasic.dtx, explicitly
% permitted by Markus Kohm. Maintainer of this modified version is
% Marei Peischl.
%
% This file is based on revision 4120 of the repository:
% https://sourceforge.net/p/koma-script/.
% The copyright notice below is left unchanged to simplify
% the integration of this project into KOMA-Script
%
% ======================================================================
% ======================================================================
% tocbasic.dtx
% Copyright (c) Markus Kohm, 2008-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: tocbasic.dtx 4132 2024-10-24 09:32:44Z kohm $
%<identify>%%% (run: identify)
%<prepare>%%% (run: prepare)
%<option>%%% (run: option)
%<execoption>%%% (run: execoption)
%<body>%%% (run: body)
%<exit>%%% (run: exit)
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
\begingroup
\def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
\filedate$Date: 2024-10-24 11:32:44 +0200 (Thu, 24 Oct 2024) $
\def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
\filerevision$Revision: 4132 $
\endgroup
\ProvidesFile{tocbasic.dtx}[\filedate\space\filerevision\space
%</dtx>
%<package&identify>\NeedsTeXFormat{LaTeX2e}[1995/12/01]
%<package&identify>\ProvidesPackage{tocbasic}[%
%<package&identify&tagging-lab>2024-09-15
%<*dtx|(package&identify)>
%!KOMAScriptVersion
package
%<*dtx>
source
%</dtx>
%</dtx|(package&identify)>
%<package&identify> (handling toc-files)%
%<*dtx>
(dtx)%
%</dtx>
%<*dtx|(package&identify)>
]
%</dtx|(package&identify)>
%<*dtx>
\ifx\documentclass\undefined
\input scrdocstrip.tex
\@@input scrkernel-version.dtx
\@@input scrstrip.inc
\KOMAdefVariable{COPYRIGHTFROM}{2008}
\generate{\usepreamble\defaultpreamble
\file{tocbasic.sty}{%
\from{tocbasic.dtx}{package,identify}%
\from{tocbasic.dtx}{package,prepare}%
\from{tocbasic.dtx}{package,option}%
\from{tocbasic.dtx}{package,execoption}%
\from{tocbasic.dtx}{package,body,deprecated}%
\from{scrkernel-tocstyle.dtx}{package,body}%
\from{scrkernel-tocstyle.dtx}{package,style,gobble}%
\from{scrkernel-tocstyle.dtx}{package,style,dottedtocline}%
\from{scrkernel-tocstyle.dtx}{package,style,undottedtocline}%
\from{scrkernel-tocstyle.dtx}{package,style,largetocline}%
\from{scrkernel-tocstyle.dtx}{package,style,tocline}%
\from{scrkernel-tocstyle.dtx}{package,style,toctext}%
\from{scrkernel-tocstyle.dtx}{package,style,default}%
\from{tocbasic.dtx}{package,exit}%
\from{scrlogo.dtx}{logo}%
}%
}%
\@@input scrstrop.inc
\else
\let\endbatchfile\relax
\fi
\endbatchfile
\documentclass[USenglish]{koma-script-source-doc}
\usepackage{babel}
\setcounter{StandardModuleDepth}{2}
\begin{document}
\DocInput{tocbasic.dtx}
\end{document}
%</dtx>
% \fi
%
% \changes{v3.36}{2022/02/10}{switch over from \cls*{scrdoc} to
% \cls*{koma-script-source-doc}}
% \changes{v3.36}{2022/02/10}{require package \pkg*{scrlogo} instead of
% defining \cs{KOMAScript}}
% \changes{v3.40}{2023/04/17}{guide names changed}
%
% \GetFileInfo{tocbasic.dtx}
% \title{Handling of Tables and Lists of Contents with
% \href{https://komascript.de}{\KOMAScript} Package \pkg*{tocbasic}}
% \author{\href{mailto:komascript@gmx.info}{Markus Kohm}}
% \date{Revision \fileversion{} of \filedate}
% \maketitle
% \begin{abstract}
% The main purpose of package \pkg*{tocbasic} is to provide features for
% authors of classes and packages to create own tables or lists of contents
% like the list of figures and the list of tables and thereby allow other
% classes or packages some types of control over these. For examples package
% \pkg*{tocbasic} delegates language control of all these tables and lists
% of contents to package \pkg{babel}. So automatic change of language
% will be provided inside all these tables and lists of contents. Using
% \pkg*{tocbasic} will exculpate authors of classes and packages from
% implementation of such features.
%
% \KOMAScript{} classes use \pkg*{tocbasic} not only for the table of
% contents but also for the already mentioned lists of figures and tables.
% \end{abstract}
% \tableofcontents
%
% \section{User Manual}
%
% You can find the user manuals of \pkg*{tocbasic} in the \KOMAScript{}
% manual, either the German \file{scrguide-de.pdf} or the English
% \file{scrguide-en.pdf}.
%
%
% \MaybeStop{\PrintIndex}
%
%
% \section{Implementation}
% \label{sec:implementation}
%
% \begin{macrocode}
%<*package>
% \end{macrocode}
%
% All macros with prefix \cs{tb@} or \cs{@} are internal macros and should not
% be used by package and class authors. Macros with prefix \cs{tocbasic@} are
% internal macros, that may be used by class and packages authors. Macros
% without \texttt{@} are interface commands and may be used by class and
% package authors and users.
%
% Note: Parts of the implementation of package \pkg*{tocbasic} are
% out-sourced into file \file{scrkernel-tocbasic.dtx}.
%
%
% \subsection{Requirements}
% \label{sec:packages}
%
% \changes{v3.42}{2023/09/08}{We need at least \LaTeX{} 2022-06-01}
% For full functionality at least \LaTeX{} 2022-06-01 is needed.
% \begin{macrocode}
%<*prepare>
\newif\if@tocbasic@old@latex@found
\ifnum 0=\ifcsname IfFormatAtLeastTF\endcsname
\IfFormatAtLeastTF{2022-06-01}{1}{0}
\else
0
\fi\relax
\PackageWarningNoLine{tocbasic}{%
LaTeX kernel too old!\MessageBreak
For full functionality the package needs at least\MessageBreak
LaTeX 2022-06-01.\MessageBreak
You are using an older LaTeX version.\MessageBreak
So the functionality will be limited.\MessageBreak
Note that this also can result in error messages,\MessageBreak
that would not raise with an up-to-date LaTeX%
}
\@tocbasic@old@latex@foundtrue
\fi
%</prepare>
% \end{macrocode}
% \changes{v3.41}{2023/06/28}{required packages moved to \texttt{prepare} run}
% \changes{v3.41}{2023/06/28}{\pkg{expl3} and \pkg{xparse} are required}
% Package \pkg*{scrbase} is needed to process all macro options.
% \begin{macrocode}
%<*prepare>
\RequirePackage{scrbase}
%</prepare>
% \end{macrocode}
%
% Now we can load \pkg{xparse} if needed, which also would load \pkg{expl3}:
% \begin{macrocode}
%<*prepare>
\scr@ifundefinedorrelax{NewDocumentCommand}{%
\RequirePackage{xparse}[2018-04-12]%
}{}
%</prepare>
% \end{macrocode}
%
%
% \subsection{Options}
% \label{sec:options}
%
% \changes{v3.42}{2023/09/08}{with old \LaTeX{} all options are unknown}
%
% \begin{option}{enablepatch,disablepatch}
% \changes{v3.42}{2023/09/08}{new}
% From version 3.42 there a several optional patches executed while
% |\begin{document}|. Every one of that patch can be enabled or disabled.
% \ExplSyntaxOn
% \begin{macro}{\@@_patch_all_bool,\@@_patch_starttoc_bool,\@@_patch_chapter_bool,
% \@@_patch_listoffigures_bool,\@@_patch_listoftables_bool}
% \ExplSyntaxOff
% \changes{v3.42}{2023/09/08}{new}
% Enabling and disabling will be done using a boolean variable with default
% |false| (disabled). The |all| patch is somehow different. In enables or
% disables doing all patches. So |disablepatch=all| does not disable all
% patches but disables to ignore the single patches.
% \begin{macrocode}
%<@@=tocbasic>
%<*option>
\if@tocbasic@old@latex@found\else
\ExplSyntaxOn
\bool_new:N \@@_patch_all_bool
\bool_new:N \@@_patch_starttoc_bool
\bool_new:N \@@_patch_chapter_bool
\bool_new:N \@@_patch_listoffigures_bool
\bool_new:N \@@_patch_listoftables_bool
% \end{macrocode}
% \end{macro}
% \ExplSyntaxOff
% The most simple part of the story is the definition of the two
% options. Both allow a comma separated list of patches to set the
% corresponding boolean value to |true| or |false|.
% \begin{macrocode}
\DeclareKeys
{
enablepatch .code = \@@_endisable_patch:nn {#1} \c_true_bool,
enablepatch .usage = preamble,
enablepatch .value_required:n = true,
disablepatch .code = \@@_endisable_patch:nn {#1} \c_false_bool,
disablepatch .usage = preamble,
disablepatch .value_required:n = true,
}
% \end{macrocode}
% \ExplSyntaxOn
% \begin{macro}{\@@_endisable_patch:nn}
% \ExplSyntaxOff
% \changes{v3.42}{2023/09/08}{new}
% \changes{v3.43}{2024/10/22}{deprecated \cs{char\_uppercase:N} replaced by
% \cs{text\_uppercase:n}}
% Switch the patch \#1 depending on argument \#2 or raise a warning for
% unknown patches.
% \begin{macrocode}
\msg_new:nnnn { tocbasic } { unknown-patch }
{
\text_uppercase:n #1bling~of~unknown~patch~#2~ignored.
}
{
You've~tried~to~#1able~patch~#2,~
but~this~is~not~a~known~patch.~
Because~of~this~your~attempt~is~ignored.~
See~the~KOMA-Script~user~manual~for~more~information~about~known~patches.
}
\cs_new:Nn \@@_endisable_patch:nn
{
\clist_map_inline:nn { #1 }
{
\cs_if_exist:cTF { @@_patch_##1_bool }
{
\bool_set_eq:cN { @@_patch_##1_bool } #2
}
{
\exp_args:Nnnx \msg_warning:nnnn { tocbasic } { unknown-patch }
{ \bool_if:NTF #2 { en } { dis } } { ##1 }
}
}
}
\ExplSyntaxOff
\fi
%</option>
% \end{macrocode}
% \end{macro}
% \ExplSyntaxOff
% The patch codes are executed while |\begin{document}|. Some patches may be
% dangerous, in which case message |dangerous-patch| is used.
% \begin{description}
% \item[ToDo:] We are using the old \cs{AtBeginDocument} here. Maybe a new
% hook would be cleaner.
% \end{description}
% \begin{macrocode}
%<*body>
\if@tocbasic@old@latex@found\else
\ExplSyntaxOn
\msg_new:nnnn { tocbasic } { dangerous-patch }
{
Dangerous~#2~patch~enabled \str_if_empty:nF { #1 } { ~using~#1 } .
}
{
\str_if_empty:nF { #1 } { Class~#1~does~not~need~the~#2~patch.~ }
Using~this~patch~can~even~result~in~harm.~
If~you~are~not~sure~that~this~patch~is~needed,~
you~should~not~enable~it.~
Please,~see~the~KOMA-Script~user~manual~for~more~information~about~
the~#2~patch.
}
\AtBeginDocument
{
% \end{macrocode}
% The patches are:
% \begin{description}
% \item[\texttt{all}:] activate all other patches. The \texttt{chapter} patch
% is not enabled for \KOMAScript{} classes. So if you want to use this patch
% with a \KOMAScript{} class\,---\,which usually will not make sense\,---\,,
% you have to use an explicit |enabelpatch=chapter|.
% \begin{macrocode}
\bool_if:NT \@@_patch_all_bool
{
\bool_set_true:N \@@_patch_starttoc_bool
\cs_if_exist:NF \KOMAClassName
{ \bool_set_true:N \@@_patch_chapter_bool }
\bool_set_true:N \@@_patch_listoffigures_bool
\bool_set_true:N \@@_patch_listoftables_bool
}
% \end{macrocode}
% \item[\texttt{chapter}:] patches \cs{@makechapterhead} to add \cs{addvspace}
% to every float list. It does \emph{not} patch \cs{@makeschapterhead}. Note
% that this patch should not be activated using a \KOMAScript{} class unless
% you are using an incompatible \cs{chapter} definition. This patch is
% potentially dangerous. So we raise at least a note and maybe a warning.
% \begin{macrocode}
\bool_if:NT \@@_patch_chapter_bool
{
\cs_if_exist:NTF \KOMAClassName
{
\exp_args:Nnnx \msg_warn:nnnn { tocbasic } { dangerous-patch }
{ \KOMAClassName } { chapter }
}
{
\exp_args:Nnnx \msg_note:nnnn { tocbasic } { dangerous-patch }
{ } { chapter }
}
\hook_gput_code:nnn { cmd/@makechapterhead/before } { tocbasic }
{
\doforeachtocfile[float]{
\addtocontents{\@currext}{\protect\addvspace{10\p@}}
}
}
}
% \end{macrocode}
% \item[\texttt{starttoc}:] executes \cs{tocbasicautomode}
% \begin{macrocode}
\bool_if:NT \@@_patch_starttoc_bool \tocbasicautomode
% \end{macrocode}
% \item[\texttt{listoffigures}] redefines \cs{listoffigures} to use
% \pkg*{tocbasic} (but without changing \cs{l@figure}, because
% \cs{DeclareTOCSTyleEntry} already has defaults for \texttt{figure}).
% \begin{macrocode}
\bool_if:NT \@@_patch_listoffigures_bool
{
\renewcommand*{\listoffigures}{\listoftoc{\ext@figure}}%
\providecommand*{\listoflofname}{\listfigurename}%
}
% \end{macrocode}
% \item[\texttt{listoftables}] redefines \cs{listoftables} to use
% \pkg*{tocbasic} (but without changing \cs{l@table}, because
% \cs{DeclareTOCSTyleEntry} already has defaults for \texttt{table}).
% \begin{macrocode}
\bool_if:NT \@@_patch_listoftables_bool
{
\renewcommand*{\listoftables}{\listoftoc{\ext@table}}%
\providecommand*{\listoflotname}{\listtablename}%
}
% \end{macrocode}
% \end{description}
% \begin{macrocode}
}
\ExplSyntaxOff
\fi
%</body>
%<@@=>
% \end{macrocode}
% \end{option}
% \ExplSyntaxOff
%
% \begin{macrocode}
%<*execoption>
\if@tocbasic@old@latex@found
\ProcessOptions
\else
\ProcessKeyOptions
\fi
%</execoption>
% \end{macrocode}
%
%
% \subsection{Unwanted packages}
% \label{sec:unpackages}
%
% There are packages, that are not recommended to be used together with
% \pkg*{tocbasic}:
% \begin{macrocode}
%<*body>
% \end{macrocode}
% \begin{description}
% \item[\pkg{multitoc}:] This package implements multi-column ToCs using
% \pkg{multicol}. Unfortunately there is a bug in that package, that
% disables all extensions but \file{toc}, \file{lof} and \file{lot} and
% even these if the corresponding option has not been set.
% \begin{macrocode}
\AfterPackage*{multitoc}{%
\@ifpackagelater{multitoc}{2022/02/10}{}{%
\PackageWarningNoLine{tocbasic}{%
Usage of package `multitoc' is not recommended!\MessageBreak
Note, this package generally results in empty ToCs\MessageBreak
for all extension but `toc', `lof' and `lot' and\MessageBreak
even for these extensions if you do not use the\MessageBreak
corresponding multitoc options.\MessageBreak
It is recommended to use:\MessageBreak
\space\space\string\usepackage{multicol}\MessageBreak
\space\space\string\BeforeStartingTOC{\string\begin{multicols}{2}}%
\MessageBreak
\space\space\string\AfterStartingTOC{\string\end{multicols}}%
\MessageBreak
instead of loading package `multitoc'.\MessageBreak
See the KOMA-Script manual for more information\MessageBreak
about using \string\BeforeStartingTOC\space and
\string\AfterStartingTOC\MessageBreak
and the multicol manual for more information\MessageBreak
about the `multicols' environment%
}%
}%
}
% \end{macrocode}
% \end{description}
% \begin{macrocode}
%</body>
% \end{macrocode}
%
%
% \subsection{Having a list of all toc-files}
% \label{sec:listoftocs}
%
% If we have a list of all toc-files we may do commands for all
% toc-files. Somethimes it may be usefull to known the package, that created
% the toc-file, so this information will be stored additionally.
%
% \begin{macro}{\tb@listoftocs}
% This is the list of toc-files. The list will be:
% \begin{quote}
% \cs{do}\marg{extension}\marg{class or
% package}\cs{do}\marg{extension}\marg{class or package}\dots
% \end{quote}
% With this, adding and processing the list will be very fast but removing
% an element will be very slow.
%
% The initial state of the list will be \emph{empty}.
% \begin{macrocode}
%<*body>
\newcommand*{\tb@listoftocs}{}
% \end{macrocode}
% \end{macro}
%
% \begin{command}{\ifattoclist,\Ifattoclist}
% \changes{v3.28}{2019/11/19}{\cs{ifattoclist} renamed to \cs{Ifattoclist}}
% This command tests, if an extension is already at the list of toc-files. The
% extension has to be the first argument. The second argument will be done, if
% the extension is already at the list of toc-files. The third argument will
% be done, if the extension is at the list of toc-files not yet.
% \begin{macrocode}
\providecommand*{\ifattoclist}{%
\PackageWarning{tocbasic}{Usage of deprecated command
`\string\ifattoclist'.\MessageBreak
The command has been renamed because of a\MessageBreak
recommendation of The LaTeX Project Team.\MessageBreak
Please replace `\string\ifattoclist' by `\string\Ifattoclist'%
}%
\Ifattoclist
}
\newcommand{\Ifattoclist}[1]{%
\begingroup
\def\do##1##2{%
\edef\reserved@a{##1}%
\ifx\reserved@a\reserved@b\@tempswatrue\fi
}%
\edef\reserved@b{#1}\@tempswafalse\tb@listoftocs
\if@tempswa\aftergroup\@firstoftwo\else\aftergroup\@secondoftwo\fi
\endgroup
}
% \end{macrocode}
% \end{command}^^A \ifattoclist,\Ifattoclist
%
% \begin{macro}{\tb@optowner}
% \changes{v3.41}{2023/06/28}{new}
% Several of the following commands use an optional argument for the
% owner. Almost always if the argument is not given but \cs{@currname} is not
% empty \texttt{\cs{@currname}.\cs{@currext}} should be used. If the argument
% is not given but \cs{@currname} is empty, an empty value should be used. And
% if the optional argument is given, it should be used unchanged. So here is a
% helper macro for exactly this logic. Note, that argument here is not
% optional but mandatory and should be an optional argument of
% \cs{NewDocumentCommand}.
% \begin{macrocode}
\newcommand*{\tb@optowner}[1]{%
\IfValueTF{#1}{%
#1%
}{%
\ifx\@currname\@empty\else
\@currname.\@currext%
\fi
}%
}
% \end{macrocode}
% \end{macro}
% \begin{command}{\addtotoclist}
% \changes{v3.06a}{2010/09/14}{expand the arguments while adding them to the
% internal list}
% \changes{v3.41}{2023/06/28}{using \cs{NewDocumentCommand} to not need all
% the helpers}
% This command adds an extension to the list of toc-files. The first,
% optional argument is the class or package name with the corresponding
% extension of class or package files. If this argument was omitted
% \pkg*{tocbasic} tries to get it automatically. This should be
% successfull while loading a class or package but not while processing any
% command of a class or package after loading the class or package. The
% second, mandatory argument is the extension of the toc-file. NOTE: An
% empty first argument is not the same like omitting the first argument!
% \begin{macrocode}
\NewDocumentCommand\addtotoclist{om}{%
\edef\reserved@b{\tb@optowner{#1}}%
\Ifattoclist{#2}{%
\PackageError{tocbasic}{%
file extension `#2' cannot be used twice
}{%
File extension `#2' is already used by a toc-file, while
\ifx\relax#1\relax someone\else #2\fi\MessageBreak
tried to use it again for a toc-file.\MessageBreak
This may be either an incompatibility of packages, an error at a
package,\MessageBreak
or a mistake by the user.\MessageBreak
}%
}{%
\begingroup
\edef\reserved@a{%
\noexpand\g@addto@macro\noexpand\tb@listoftocs{%
\noexpand\do{#2}{\reserved@b}}}\reserved@a
\endgroup
\ifx\reserved@b\@empty\else
\@ifundefined{tb@\reserved@b @add@hook}{}{%
\edef\reserved@a{%
\noexpand\def\noexpand\@currext{#2}%
\noexpand\@nameuse{tb@\reserved@b @add@hook}%
\noexpand\def\noexpand\@currext{\@currext}%
}\reserved@a
}%
\fi
\edef\reserved@a{%
\noexpand\def\noexpand\@currext{#2}%
\noexpand\@nameuse{tb@@add@hook}%
\noexpand\def\noexpand\@currext{\@currext}%
}\reserved@a
}%
}
% \end{macrocode}
% \begin{macro}[noprint]{\@addtotoclist,\scr@addtotoclist,
% \@@addtotoclist,\scr@@addtotoclist}
% \changes{v1.0a}{2008/11/11}{\cs{@addtotoclist} renamed to
% \cs{scr@addtotoclist} because of package \pkg{flowfram}}
% \changes{v1.0a}{2008/11/11}{\cs{@@addtotoclist} renamed to
% \cs{scr@@addtotoclist} because of package \pkg{flowfram}}
% \changes{v3.28}{2019/11/19}{\cs{ifattoclist} replaced by
% \cs{Ifattoclist}}
% \changes{v3.41}{2023/06/28}{removed}
% \end{macro}
% \end{command}
%
% \begin{command}{\owneroftoc}
% \changes{v3.22}{2016/08/09}{added}
% \changes{v3.28}{2019/11/18}{\cs{ifstr} renamed to \cs{Ifstr}}
% Returns the owner of a TOC or uses the owner of a TOC as argument of the
% optional argument, if it exists.
% \begin{macrocode}
\newcommand*{\owneroftoc}[2][\@firstofone]{%
\begingroup
\let\reserved@a\endgroup
\def\do##1##2{\Ifstr{#2}{##1}{\def\reserved@a{\endgroup#1{##2}}}{}}%
\tb@listoftocs
\reserved@a
}
% \end{macrocode}
% \end{command}
% \begin{command}{\categoryoftoc}
% \changes{v3.27}{2019/05/12}{added}
% Synonym for \cs{owneroftoc}.
% \begin{macrocode}
\newcommand*{\categoryoftoc}{\owneroftoc}
% \end{macrocode}
% \end{command}
%
% \begin{command}{\AtAddToTocList}
% \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
% \cs{kernel@ifnextchar}}
% \changes{v3.41}{2023/06/28}{using \cs{NewDocumentCommand} to not need all
% the helpers}
% Action to be done, when adding a toc-file of a known owner. The first
% optional argument is the owner. The second, mandatory argument is the
% action. While doing the action \cs{@currext} will be the extension of the
% added toc-file. If the first argument was omitted \pkg*{tocbasic} tries
% to get it automatically. This should be successfull while loading a class
% or package but not while processing any command of a class or package
% after loading the class or package. The second, mandatory argument is the
% extension of the toc-file. NOTE: An empty first argument is not the same
% like omitting the first argument, but set's up the general hook. The
% general hook will be done for every adding after the individual hook (this
% means, you may dactivate features at the individual hook before processing
% the general hook). But the individual hook will not be processed for
% toc-files without any owner!
% \begin{macrocode}
\NewDocumentCommand\AtAddToTocList{o}{%
\edef\reserved@a{\tb@optowner{#1}}%
\@ifundefined{tb@\reserved@a @add@hook}%
{\@namedef{tb@\reserved@a @add@hook}{}}%
{}%
\expandafter\g@addto@macro\csname tb@\reserved@a @add@hook\endcsname
}
% \end{macrocode}
% \begin{macro}[noprint]{\@AtAddToTocList,\@@AtAddToTocList}
% \changes{v3.41}{2023/06/28}{removed}
% \end{macro}
% \end{command}
%
% \begin{macro}{\tocbasic@extend@babel}
% \changes{v3.28}{2019/11/19}{\cs{iftocfeature} replaced by
% \cs{Iftocfeature}}
% \changes{v3.38}{2022/07/22}{first test feature than availability}
% NOTE: To extend the original \cs{bbl@set@language} the argument of
% \cs{tocbasic@extend@babel} must not be a local macro (like \cs{@currext})
% \begin{macrocode}
\newcommand*{\tocbasic@extend@babel}[1]{%
\Iftocfeature{#1}{nobabel}{%
\PackageInfo{tocbasic}{omitting babel extension for `#1'\MessageBreak
because of feature `nobabel' available\MessageBreak
for `#1'}%
}{%
\scr@ifundefinedorrelax{bbl@set@language}{%
\PackageInfo{tocbasic}{omitting babel extension for `#1'\MessageBreak
because of missing \string\bbl@set@language}%
}{%
% \end{macrocode}
% \changes{v3.23}{2017/02/23}{using \cs{BabelContentsFiles} if available}
% Since version 3.9a provides adding extensions to the language switch
% preparation. So it is used if it is available.
% \begin{macrocode}
\scr@ifundefinedorrelax{BabelContentsFiles}{%
\PackageInfo{tocbasic}{setting babel extension for `#1'}%
\expandafter\gdef\expandafter\bbl@set@language
\expandafter##\expandafter1%
\expandafter{%
\bbl@set@language{##1}%
\addtocontents{#1}{\xstring\select@language{\languagename}}%
}%
}{%
\@expandtwoargs\in@{,#1,}{,\BabelContentsFiles,}%
\ifin@
\PackageInfo{tocbasic}{omitting babel extension for
`#1'\MessageBreak
because it is already in \string\BabelContentsFiles}%
\else
\PackageInfo{tocbasic}{setting babel extension for `#1'}%
\xdef\BabelContentsFiles{\BabelContentsFiles,#1}%
\fi
}%
}%
}%
}
% \end{macrocode}
% This feature should be used for all toc-files (unless feature
% \opt{nobabel} was set for the toc-file).
% \begin{macrocode}
\AtAddToTocList[]{\expandafter\tocbasic@extend@babel\expandafter{\@currext}}
% \end{macrocode}
% \end{macro}
%
% \begin{command}{\removefromtoclist}
% \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
% \cs{kernel@ifnextchar}}
% \changes{v3.22}{2016/09/06}{missing \cs{global} added}
% \changes{v3.41}{2023/06/28}{using \cs{NewDocumentCommand} to not need all
% the helpers}
% This command will remove an extension from the list of toc-files. If the
% first, optional argument is given, the extension will only be removed, if
% it was added by the given owner. NOTE: An empty first argument is not the
% same like omitting the first argument!
% \begin{macrocode}
\NewDocumentCommand\removefromtoclist{om}{%
\begingroup
\let\tb@oldlist\tb@listoftocs
\edef\reserved@b{#2}%
\global\let\tb@listoftocs\empty
\def\do##1##2{%
\edef\reserved@a{##1}%
\ifx\reserved@a\reserved@b
\IfValueT{#1}{%
\begingroup
\edef\@currext{##2}%
\edef\reserved@b{#1}%
\ifx\@currext\reserved@b
\else
\g@addto@macro\tb@listoftocs{\do{##1}{##2}}%
\fi
\endgroup
}%
\else
\g@addto@macro\tb@listoftocs{\do{##1}{##2}}%
\fi
}%
\tb@oldlist
\endgroup
}
% \end{macrocode}
% \begin{macro}[noprint]{\scr@removefromtoclist,\@removefromtoclist,
% \scr@@removefromtoclist,\@@removefromtoclist}
% \changes{v3.28}{2019/11/22}{\cs{@removefromtoclist} renamed to
% \cs{scr@removefromtoclist}}
% \changes{v3.28}{2019/11/22}{\cs{@@removefromtoclist} renamed to
% \cs{scr@removefromtoclist}}
% \changes{v3.41}{2023/06/28}{removed}
% \end{macro}
% \end{command}
%
% \begin{command}{\doforeachtocfile}
% \changes{v3.09}{2011/03/01}{\cs{@currext} defined using \cs{edef} instead
% of \cs{def}}
% \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
% \cs{kernel@ifnextchar}}
% \changes{v3.41}{2023/06/28}{using \cs{NewDocumentCommand} to not need all
% the helpers}
% This command does the second, mandatory argument for each toc-file at the
% list of toc-files. If the first, optional argument was given this will be
% done only for the toc-files of that owner. NOTE: An empty first argument
% is not the same like omitting the first argument!
% While processing the second argument \cs{@currext} is the extension of
% the toc-file. The second argument will be processed with increased group
% level!
% See \cs{addtoeachtocfile} for an example of usage of
% \cs{doforeachtocfile}.
% \begin{macrocode}
\NewDocumentCommand\doforeachtocfile{o+m}{%
\IfValueTF{#1}{%
\def\do##1##2{%
\edef\reserved@a{#1}\edef\reserved@b{##2}%
\ifx\reserved@a\reserved@b \edef\@currext{##1}#2\fi
}%
}{%
\def\do##1##2{\edef\@currext{##1}#2}%
}%
\edef\reserved@a{%
\noexpand\tb@listoftocs
\noexpand\def\noexpand\@currext{\@currext}%
}\reserved@a
% \end{macrocode}
% \changes{v3.41}{2023/05/16}{don't \cs{let}\cs{do}\cs{relax}}
% Former versions of \KOMAScript{} have used |\let\do\relax| to undefined
% \cs{do} after the walk-through. But some packages like \pkg{dynkin-diagrams}
% have had problems using \cs{renewcommand} instead of \cs{def} or \cs{let} to
% change \cs{do}. So from version 3.41 \KOMAScript{} has changed this to
% |\let\do\noexpand|, because this is the default of \LaTeX{} after
% |\begin{document}|. However, this is only a workaround for a
% workaround. Best would be to remove the final change of \cs{do}. But this
% could also break packages.
% \begin{macrocode}
\let\do\noexpand
}
% \end{macrocode}
% \begin{macro}[noprint]{\@doforeachtocfile,\@@doforeachtocfile}
% \changes{v3.41}{2023/06/28}{removed}
% \end{macro}
% \end{command}
%
% \begin{command}{\addtoeachtocfile}
% \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
% \cs{kernel@ifnextchar}}
% \changes{v3.41}{2023/06/28}{using \cs{NewDocumentCommand} to not need all
% the helpers}
% This command calls \cs{addtocontents} with the section, mandatory
% argument for each toc-file at the list of toc-files. If the first,
% optional argument was given this will be done only for the toc-files of
% that owner. NOTE: An empty first argument is not the same like omitting
% the first argument! And don't forget to protect the commands, that should
% not be expanded, at the mandatory argument.
% \begin{macrocode}
\NewDocumentCommand\addtoeachtocfile{o+m}{%
\doforeachtocfile[{#1}]{\addtocontents{\@currext}{#2}}%
}
%</body>
% \end{macrocode}
% \begin{macro}[noprint]{\@addtoeachtocfile,\@@addtoeachtocfile}
% \changes{v3.03b}{2009/06/08}{typo fix at usage of \cs{doforeachtocfile}}
% \changes{v3.41}{2023/06/28}{removed}
% \end{macro}
% \end{command}
%
% \subsection{Adding entries into toc-files}
%
% We have a new general command to add entries to several toc-files at
% once. And we have some special commands for the table of contents.
%
% \begin{command}{\addcontentslinetoeachtocfile}
% \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
% \cs{kernel@ifnextchar}}
% \changes{v3.41}{2023/06/28}{using \cs{NewDocumentCommand} to not need all
% the helpers}
% Something like a combination of \cs{addtoeachtocfile} and
% \cs{addcontentsline}.
% \begin{macrocode}
%<*body>
\NewDocumentCommand\addcontentslinetoeachtocfile{omm}{%
\doforeachtocfile[{#1}]{\addcontentsline{\@currext}{#2}{#3}}%
}
% \end{macrocode}
% \begin{macro}[noprint]{\@addcontentslinetoeachtocfile,
% \@@addcontentslinetoeachtocfile}
% \changes{v3.41}{2023/06/28}{removed}
% \end{macro}
% \end{command}
%
% \begin{command}{\addxcontentsline}
% \changes{v3.12}{2013/09/24}{added}
% \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
% \cs{kernel@ifnextchar}}
% \changes{v3.41}{2023/06/28}{using \cs{NewDocumentCommand} to not need all
% the helpers}
% This will be used instead of \cs{addcontentsline} to generate numbered or
% not numbered entries to a toc-file. First argument is the toc-file, second
% the entry type, e.g., |chapter|, the third is the entry number or empty and
% the fourth and last is the entry text.
% \begin{macrocode}
\NewDocumentCommand\addxcontentsline{mmO{}m}{%
\scr@ifundefinedorrelax{add#2#1entry}{%
\tocbasic@addxcontentsline{#1}{#2}{#3}{#4}%
}{%
\@nameuse{add#2#1entry}{#3}{#4}%
}%
}
% \end{macrocode}
% \begin{macro}[noprint]{\@addxcontentsline}
% \changes{v3.12}{2013/09/24}{added}
% \changes{v3.41}{2023/06/28}{removed}
% \end{macro}
% \begin{command}{\nonumberline}
% \changes{v3.12}{2013/09/24}{added}
% Either \cs{relax} or \cs{numberline} depending on the feature
% \opt{numberline}.
% \begin{macrocode}
\newcommand*{\nonumberline}{}%
% \end{macrocode}
% \end{command}
% \begin{macro}{\tocbasic@addxcontentsline}
% This may be used to either use a heading type command or the general default
% one. You are not allowed to use it in the definition of a heading type
% command like \cs{addchaptertocentry}! You may use
% \cs{tocbasic@addxcontentsline} at the definition of those commands.
% \begin{macrocode}
\newcommand*{\tocbasic@addxcontentsline}[4]{%
\IfArgIsEmpty{#3}{%
\addcontentsline{#1}{#2}{\protect\nonumberline#4}%
}{%
\addcontentsline{#1}{#2}{\protect\numberline{#3}#4}%
}%
}
% \end{macrocode}
% \end{macro}
% \end{command}
%
% \begin{command}{\addxcontentslinetoeachtocfile}
% \changes{v3.12}{2013/09/24}{added}
% \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
% \cs{kernel@ifnextchar}}
% \changes{v3.41}{2023/06/28}{using \cs{NewDocumentCommand} to not need all
% the helpers}
% Similar to \cs{addcontentslinetoeachtocfile} using
% \cs{addxcontentsline} instead of \cs{addcontentsline}.
% \begin{macrocode}
\NewDocumentCommand\addxcontentslinetoeachtocfile{omom}{%
\doforeachtocfile[{#1}]{\addxcontentsline{\@currext}{#2}[{#3}]{#4}}
}
%</body>
% \end{macrocode}
% \begin{macro}[noprint]{\@addxcontentslinetoeachtocfile,
% \@@addxcontentslinetoeachtocfile,
% \@@@addxcontentslinetoeachtocfile,
% \@@@@addxcontentslinetoeachtocfile}
% \changes{v3.12}{2013/09/24}{added}
% \changes{v3.41}{2023/06/28}{removed}
% \end{macro}
% \end{command}
%
%
% \subsection{Show list of toc-file}
% \label{sec:showlistoftocfile}
%
% If you have a toc-file you want a list-of-command for this toc-file,
% too. Here are basics and high level commands for this.
%
% \begin{macro}{\tocbasic@starttoc}
% \changes{v3.17}{2015/03/23}{usage of feature \opt{noparskipfake}}
% \changes{v3.27}{2019/07/08}{hack to add \cs{par} at end of (main) file}
% \changes{v3.28}{2019/11/19}{\cs{iftocfeature} replaced by
% \cs{Iftocfeature}}
% \changes{v3.32}{2020/08/25}{replace \cs{par} hack by \cs{par} solution}
% \changes{v3.32}{2020/08/25}{reentrant warning}
% Some basics are done like setting up \cs{parskip}, \cs{parindent} and
% \cs{parfillskip}, a general hook will be called, an individual hook will
% be called, the toc will be started, an individual hook will be called, an
% general hook wil be called, that's it.
% \begin{macrocode}
%<*body>
\newcommand*{\tocbasic@starttoc}[1]{%
\begingroup
\tocbasic@reentrant@warning
\def\tocbasic@reentrant@warning{%
\PackageWarning{tocbasic}{%
Loading one auxiliary file inside the setup context\MessageBreak
of another auxiliary file is not recommended.\MessageBreak
In this case settings for `\@currext' could also influence\MessageBreak
settings of `#1' and local states of `#1' can also\MessageBreak
influence local states of `\@currext'%
}%
}%
\edef\@currext{#1}%
\Iftocfeature{\@currext}{noparskipfake}{}{%
\ifvmode
\@tempskipa\lastskip
\vskip-\lastskip
\addtolength{\@tempskipa}{\parskip}%
\vskip\@tempskipa
\fi
}%
\setlength{\parskip}{\z@}%
\setlength{\parindent}{\z@}%
\setlength{\parfillskip}{\z@\@plus 1fil}%
\csname tocbasic@@before@hook\endcsname
\csname tb@#1@before@hook\endcsname
\@starttoc{#1}%
\BeforeClosingMainAux{%
\addtocontents{#1}{%
\string\providecommand\string\tocbasic@end@toc@file{}%
\string\tocbasic@end@toc@file
}%
}%
\edef\@currext{#1}%
\csname tb@#1@after@hook\endcsname
\csname tocbasic@@after@hook\endcsname
\endgroup
}
% \end{macrocode}
% \begin{macro}{tocbasic@end@toc@file}
% \changes{v3.32}{2020/08/25}{added}
% \begin{macrocode}
\newcommand*{\tocbasic@end@toc@file}{\par}
% \end{macrocode}
% \end{macro}^^A \tocbasic@end@toc@file
% \begin{macro}{\tocbasic@reentrant@warning}
% \changes{v3.32}{2020/08/25}{added}
% \begin{macrocode}
\newcommand*{\tocbasic@reentrant@warning}{}
% \end{macrocode}
% \end{macro}^^A \tocbasic@reentrant@warning
% \begin{macro}{\tocbasic@@before@hook,\tocbasic@@after@hook}
% These are the general hooks. They may be used by classes and packages for
% commands, that should be used for all lists of not only the own lists of,
% e.\,g., \KOMAScript{} may use it to handle option \opt{tocleft}.
% \begin{macrocode}
\newcommand*{\tocbasic@@before@hook}{}
\newcommand*{\tocbasic@@after@hook}{}
% \end{macrocode}
% \end{macro}^^A \tocbasic@@before@hook,\tocbasic@@after@hook
% \begin{command}{\BeforeStartingTOC,\AfterStartingTOC}
% \changes{v3.04b}{2010/01/05}{fix:define the hook if not already defined}
% \changes{v3.06}{2010/06/09}{fix: using \cs{@ifundefined} instead of
% undefined \cs{scr@ifundefinedorrelax}}