summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/koma-script/scrkernel-floats.dtx
blob: f7c1a126d6407c8694728250226391cf4ba42a6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
% \iffalse meta-comment
% ======================================================================
% scrkernel-floats.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-floats.dtx 4032 2023-04-17 09:45:11Z kohm $
%<option>%%%            (run: option)
%<body>%%%            (run: body)
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
\begingroup
  \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
  \filedate$Date: 2023-04-17 11:45:11 +0200 (Mo, 17. Apr 2023) $
  \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
  \filerevision$Revision: 4032 $
  \edef\reserved@a{%
    \noexpand\endgroup
    \noexpand\ProvidesFile{scrkernel-floats.dtx}%
                          [\filedate\space\filerevision\space
                           KOMA-Script source
                           (floats)]
  }%
\reserved@a
\documentclass[USenglish]{koma-script-source-doc}
\usepackage{babel}
\setcounter{StandardModuleDepth}{2}
\begin{document}
\DocInput{scrkernel-floats.dtx}
\end{document}
%</dtx>
% \fi
%
% \changes{v2.95}{2002/07/01}{new by splitting \file{scrclass.dtx}}
% \changes{v3.36}{2022/02/22}{switch over from \cls*{scrdoc} to
%   \cls*{koma-script-source-doc}}
% \changes{v3.36}{2022/02/22}{implementation documentation in English}
% \changes{v3.40}{2023/04/17}{guide names changed}
%
% \GetFileInfo{scrkernel-floats.dtx}
% \title{Code for the Foats of the
%   \href{https://komascript.de}{\KOMAScript} Classes}
% \author{\href{mailto:komascript@gmx.info}{Markus Kohm}}
% \date{Revision \fileversion{} of \filedate}
% \maketitle
% \begin{abstract}
%   The code for floats in \file{scrkernel-floats.dtx} is older than the
%   generic hook mechanism in the \LaTeX{} kernel. Because of this, it
%   currently does not use the kernel hook mechanism. Mostly it is also older
%   then the \KOMAScript{} package \pkg*{tocbasic} to implement and manage
%   floats. So several code has been adapted several times and maybe a general
%   re-implementation would be a good idea.
% \end{abstract}
% \tableofcontents
%
% \section{User Manual}
%
% You can find the user documentation the commands implemented here in the
% \KOMAScript{} manual, either the German \file{scrguide-de.pdf} or the English
% \file{scrguide-en.pdf}.
%
% \subsection{Features not yet in the user manuals}
%
% \DescribeEnv{figure-,table-}
% These are non floating versions of \env{figure} and \env{table} defined
% using \cs{DeclareNewTOC}. See the description of this command in the
% \KOMAScript{} manuals for more information.
%
%
% \MaybeStop{\PrintIndex}
%
%
% \section{Implementation of Floats}
%
% All this code is for the classes only and not for the \KOMAScript{} letter
% class, because letter classes usually do not provide floats. If you need
% letters with floats, just use \KOMAScript{} class \cls*{scrartcl} with
% \KOMAScript{} package \pkg*{scrletter}.
%
%    \begin{macrocode}
%<*class&!letter>
%    \end{macrocode}
% 
% \subsection{Some macros and configurations for the options}
%
% We need some of the macros an settings already when processing the options.
%
% \begin{macro}{\@captionabovefalse,\@captionabovetrue,\if@captionabove}
% \changes{v2.8h}{2001/07/19}{added}
% \changes{v3.09}{2011/03/23}{moved before definition of options}
% Boolean switch to decide whether a \cs{caption} has to behave like
% \cs{captionabove} or \cs{captionbelow}. The default is \cs{captionbelow}.
%    \begin{macrocode}
%<*option>
\newif\if@captionabove\@captionabovefalse
%    \end{macrocode}  
% \end{macro}^^A \if@captionabove
%
% \begin{macro}{\@tablecaptionabovefalse,\@tablecaptionabovetrue,\if@tablecaptionabove}
% \changes{v2.8h}{2001/07/19}{added}
% \changes{v2.8k}{2001/08/15}{moved from \pkg*{typearea} into the classes}
% \changes{v2.98c}{2008/02/18}{moved before definition of options}
% Boolean switch to decide whether a \cs{caption} inside a \env{table}
% environment has to behave like \cs{captionabove} or \cs{captionbelow}. The
% default is \cs{captionbelow}.
%    \begin{macrocode}
\newif\if@tablecaptionabove\@tablecaptionabovefalse
%    \end{macrocode}
% \end{macro}^^A \if@tablecaptionabove
%
% \begin{macro}{\@figurecaptionabovefalse,\@figurecaptionabovetrue,\if@figurecaptionabove}
% \changes{v3.09}{2011/03/23}{added}
% Boolean switch to decide whether a \cs{caption} inside a \env{figure}
% environment has to behave like \cs{captionabove} or \cs{captionbelow}. The
% default is \cs{captionbelow}.
%    \begin{macrocode}
\newif\if@figurecaptionabove\@figurecaptionabovefalse
%    \end{macrocode}
% \end{macro}^^A \if@figurecaptionabove
%
% \begin{macro}{\onelinecaptionsfalse,\onelinecaptionstrue,\ifonelinecaptions}
% \changes{v2.8q}{2001/11/17}{added}
% \changes{v2.98c}{2008/03/03}{earlier definition}
% The boolean is used to distinguish whether or not use a special handling of
% captions with one text line only. The name of the boolean is traditionally
% but nevertheless should seen as internal.
%    \begin{macrocode}
\newif\ifonelinecaptions\onelinecaptionstrue
%    \end{macrocode}
% \end{macro}^^A \ifonelinecaptions
%
% \begin{macro}{\scap@pos}
% \changes{v2.8q}{2001/11/22}{added}
% \changes{v2.98c}{2008/03/03}{earlier definition}
% Environment \env{captionbeside} supports several horizontal placements for
% the caption beside the object:
% \begin{description}
% \item[\texttt{i}:] caption inner beside the object, which means left beside
%   on odd pages and right beside on even pages (note: single-sided documents
%   have only odd pages),
% \item[\texttt{l}:] caption left beside the object,
% \item[\texttt{o}:] caption outer beside the object, which means right beside
%   on odd pages and left beside on even pages (note: single-sided documents
%   have only odd pages),
% \item[\texttt{r}:] caption right beside the object.
% \end{description}
% The default is right beside.
%    \begin{macrocode}
\newcommand*{\scap@pos}{r}
%    \end{macrocode}
% \end{macro}^^A \scap@pos
%
% \begin{macro}{\scap@valign}
% \changes{v2.8q}{2001/11/22}{added}
% \changes{v2.98c}{2008/03/03}{earlier definition}
% Environment \env{captionbeside} support different vertical alignments
% for the object box:
% \begin{description}
% \item[\texttt{c}:] centered,
% \item[\texttt{b}:] bottom,
% \item[\texttt{t}:] top.
% \end{description}
% The default is bottom.
%    \begin{macrocode}
\newcommand*{\scap@valign}{b}
%    \end{macrocode}
% \end{macro}^^A \scap@valign
%
% \subsection{Options for the captions}
%
% \begin{option}{captions}
% \changes{v2.98c}{2008/02/18}{new \pkg*{keyval} option}
% \changes{v3.09}{2011/04/02}{new values \opt{heading}, \opt{signature},
%   \opt{figureheading}, \opt{figuresignature}}
% \changes{v3.17}{2015/03/11}{using \cs{FamilyKeyState}}
% \changes{v3.17}{2015/03/11}{using internal value storage}
% \changes{v3.39}{2022/11/11}{initial dot removed from member argument of
%   option storage commands}
% This is the general option for the settings of captions. Because of
% compatibility with package \pkg{caption}, several of the macros, that are
% used to handle the values to the option, cannot be renamed and have to be
% used. This makes it difficult to change anything here. However, the
% currently provides values are:
%    \begin{macrocode}
\KOMA@key{captions}{%
  \KOMA@set@ncmdkey{captions}{@tempa}{%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=heading}:] change the \cs{caption} default to \cs{captionabove}.
% \end{description}
%    \begin{macrocode}
    {heading}{0},{above}{0},{top}{0},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=signature}:] change the \cs{caption} default to \cs{captionbelow}.
% \end{description}
%    \begin{macrocode}
    {signature}{1},{below}{1},{bot}{1},{bottom}{1},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=tableheading}:] change the \cs{caption} default inside
%   \env{table} environments to \cs{captionabove}.
% \end{description}
%    \begin{macrocode}
    {tableheading}{2},%
    {tableabove}{2},{abovetable}{2},{abovetabular}{2},{topattable}{2},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=tablesignature}:] change the \cs{caption} default inside
%   \env{table} environment to \cs{captionbelow}.
% \end{description}
%    \begin{macrocode}
    {tablesignature}{3},%
    {tablebelow}{3},{belowtable}{3},{belowtabular}{3},{bottomattable}{3},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=figureheading}:] change the \cs{caption} default inside
%   \env{figure} environments to \cs{captionabove}.
% \end{description}
%    \begin{macrocode}
    {figureheading}{4},{figureabove}{4},{abovefigure}{4},{topatfigure}{4},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=figuresignature}:] change the \cs{caption} default inside
%   \env{figure} environment to \cs{captionbelow}.
% \end{description}
%    \begin{macrocode}
    {figuresignature}{5},{figurebelow}{5},{belowfigure}{5},{bottomatfigure}{5},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=oneline}:] special treatment for one line captions.
% \end{description}
%    \begin{macrocode}
    {oneline}{6},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=oneline}:] no special treatment for one line captions.
% \end{description}
%    \begin{macrocode}
    {nooneline}{7},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=rightbeside}:] change horizontal \env{captionbeside} placement
% to right beside (see \cs{scap@pos} above).
% \end{description}
%    \begin{macrocode}
    {rightbeside}{8},{besideright}{8},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=leftbeside}:] change horizontal \env{captionbeside} placement
% to left beside (see \cs{scap@pos} above).
% \end{description}
%    \begin{macrocode}
    {leftbeside}{9},{besideleft}{9},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=innerbeside}:] change horizontal \env{captionbeside} placement
% to inner beside (see \cs{scap@pos} above).
% \end{description}
%    \begin{macrocode}
    {innerbeside}{10},{besideinner}{10},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=outerbeside}:] change horizontal \env{captionbeside} placement
% to outer beside (see \cs{scap@pos} above).
% \end{description}
%    \begin{macrocode}
    {outerbeside}{11},{besideouter}{11},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=topbeside}:] change vertical \env{captionbeside} alignment
% to top (see \cs{scap@valign} above).
% \end{description}
%    \begin{macrocode}
    {topbeside}{12},{besidetop}{12},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=centeredbeside}:] change vertical \env{captionbeside} alignment
% to centered (see \cs{scap@valign} above).
% \end{description}
%    \begin{macrocode}
    {centeredbeside}{13},{besidecentered}{13},%
    {middlebeside}{13},{besidemiddle}{13},%
%    \end{macrocode}
% \begin{description}
% \item[\opt{=bottombeside}:] change vertical \env{captionbeside} alignment
% to bottom (see \cs{scap@valign} above).
% \end{description}
%    \begin{macrocode}
    {bottombeside}{14},{besidebottom}{14}%
  }{#1}%
  \ifx\FamilyKeyState\FamilyKeyStateProcessed
    \ifcase \@tempa\relax % heading
      \@tablecaptionabovetrue
      \@figurecaptionabovetrue
      \@captionabovetrue
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{heading}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{signature}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{heading}%
   \or % signature
      \@tablecaptionabovefalse
      \@figurecaptionabovefalse
      \@captionabovefalse
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{heading}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{signature}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{signature}%
    \or % tableheading
      \@tablecaptionabovetrue
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{tableheading}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{tablesignature}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{tableheading}%
    \or % tablesignature
      \@tablecaptionabovefalse
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{tableheading}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{tablesignature}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{tablesignature}%
    \or % figureheading
      \@figurecaptionabovetrue
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{figureheading}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{figuresignature}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{figureheading}%
    \or % figuresignature
      \@figurecaptionabovefalse
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{figureheading}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{figuresignature}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{figuresignature}%
    \or % oneline
      \onelinecaptionstrue
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{oneline}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{nooneline}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{oneline}%
    \or % nooneline
      \onelinecaptionsfalse
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{oneline}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{nooneline}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{nooneline}%
    \or % rightbeside
      \renewcommand*{\scap@pos}{r}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{rightbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{leftbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{innerbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{outerbeside}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{rightbeside}%
    \or % leftbeside
      \renewcommand*{\scap@pos}{l}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{rightbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{leftbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{innerbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{outerbeside}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{leftbeside}%
    \or % innerbeside
      \renewcommand*{\scap@pos}{i}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{rightbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{leftbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{innerbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{outerbeside}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{innerbeside}%
    \or % outerbeside
      \renewcommand*{\scap@pos}{o}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{rightbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{leftbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{innerbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{outerbeside}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{outerbeside}%
    \or % topbeside
      \renewcommand*{\scap@valign}{t}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{topbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{centeredbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{bottombeside}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{topbeside}%
    \or % centeredbeside
      \renewcommand*{\scap@valign}{c}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{topbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{centeredbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{bottombeside}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{centeredbeside}%
    \or % bottombeside
      \renewcommand*{\scap@valign}{b}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{topbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{centeredbeside}%
      \KOMA@kav@remove{\KOMAClassFileName}{captions}{bottombeside}%
      \KOMA@kav@add{\KOMAClassFileName}{captions}{bottombeside}%
    \fi
  \fi
}
\KOMA@kav@add{\KOMAClassFileName}{captions}{signature}
\KOMA@kav@add{\KOMAClassFileName}{captions}{tablesignature}
\KOMA@kav@add{\KOMAClassFileName}{captions}{figuresignature}
\KOMA@kav@add{\KOMAClassFileName}{captions}{oneline}
\KOMA@kav@add{\KOMAClassFileName}{captions}{rightbeside}
\KOMA@kav@add{\KOMAClassFileName}{captions}{bottombeside}
%    \end{macrocode}
% \end{option}^^A captions
%
% \begin{option}{tablecaptionabove,tablecaptionbelow}
% \changes{v2.8h}{2001/07/19}{added}
% \changes{v2.8k}{2001/08/15}{moved from \pkg*{typearea} into the classes}
% \changes{v2.98c}{2008/02/18}{obsolete} 
% \changes{v3.01a}{2008/11/20}{deprecated}
% \changes{v3.99}{2022/11/16}{not with \KOMAScript~4}
% Implementation of deprecated options by mapping them to corresponding
% \pkg*{keyval} options.
%    \begin{macrocode}
%<*!v4>
\KOMA@DeclareDeprecatedOption{tablecaptionabove}{captions=tableheading}
\KOMA@DeclareDeprecatedOption{tablecaptionbelow}{captions=tablesignature}
%</!v4>
%    \end{macrocode}
% \end{option}^^A tablecaptionabove,tablecaptionbelow
%
% \begin{option}{origlongtable}
% \changes{v2.8l}{2001/08/16}{added}
% If package \pkg{longtable} is loaded, the classes redefine table titles
% of that package. However, if the option has been set, this is prevented.
% \begin{macro}{\@komalongtablefalse,\@komalongtabletrue,\if@komalongtable}
% \changes{v2.8l}{2001/08/16}{added}
% The wanted behaviour is stored in a boolean.
%    \begin{macrocode}
\newif\if@komalongtable\@komalongtabletrue
\DeclareOption{origlongtable}{\@komalongtablefalse}
%    \end{macrocode}
% \end{macro}^^A \if@komalongtable
% \end{option}^^A origlongtable
%
% \begin{option}{onelinecaption,noonelinecaption}
% \changes{v2.8q}{2001/11/17}{new option}
% \changes{v2.98c}{2008/03/03}{obsolete} 
% \changes{v2.98c}{2008/03/03}{extra code for \pkg{caption2} removed}
% \changes{v3.01a}{2008/11/20}{deprecated}
% \changes{v3.99}{2022/11/16}{not with \KOMAScript~4}
% Implementation of deprecated options by mapping them to corresponding
% \pkg*{keyval} options.
%    \begin{macrocode}
%<*!v4>
\KOMA@DeclareDeprecatedOption{onelinecaption}{captions=oneline}
\KOMA@DeclareDeprecatedOption{noonelinecaption}{captions=nooneline}
%</!v4>
%</option> 
%    \end{macrocode}
% \end{option}^^A onelinecaption,noonelinecaption
%
%
% \subsection{Macros and commands for the captions}
%
% \changes{v2.2c}{1995/05/25}{support for CJK added}
% The initial feature for defining captions somehow different from the
% standard classes was a request of Werner Lember to add support for CJK
% languages. However not everything is changed. For example the usual lengths
% of the standard classes are still defined, but interpreted somehow different.
%
% \begin{length}{\abovecaptionskip,\belowcaptionskip}
% The distance above and below a caption. The default for captions below the
% object is 10\,pt above the caption and 0 below. Note: For captions above
% the object the lengths are switched: \len{abovecaptionskip} is used
% \emph{below} the caption and \len{belowcaptionskip} is used \emph{above}
% the caption then.
%    \begin{macrocode}
%<*body>
\newlength{\abovecaptionskip}
\newlength{\belowcaptionskip}
\setlength{\abovecaptionskip}{10\p@}
\setlength{\belowcaptionskip}{0\p@}
%    \end{macrocode}
% \end{length}^^A \abovecaptionskip,\belowcaptionskip
% \begin{command}{\captionformat}
% \changes{v2.3c}{1995/08/06}{added}
% Separator between label (with number) an text only.
%    \begin{macrocode}
\newcommand*{\captionformat}{:\ }
%    \end{macrocode}
% \end{command}^^A \captionformat
% \begin{command}{\captionabove,\captionbelow}
% \changes{v2.8h}{2001/07/19}{added}
% \begin{macro}{\scr@caption}
% \changes{v2.8h}{2001/07/19}{added}
% We have two different commands \cs{captionabove} and \cs{captionbelow} to
% distinguish captions above or below the object. Internally both use
% \cs{scr@caption}, but set either \cs{@captionabovetrue} or
% \cs{@captionabovefalse}. To allow other packages (e.g. \pkg{hyperref} to
% redefine \cs{caption} the final definition of \cs{scr@caption} is done in
% |\begin{document}|. We cannot use \cs{caption} inside \cs{captionabove} or
% \cs{captionbelow}, because we do use a redefinition of \cs{capion} to use
% \cs{captionabove} or \cs{captionbelow} via \opt{atbegin} at \cs{DeclareNewTOC}.
%    \begin{macrocode}
\newcommand{\scr@caption}{}
\AtBeginDocument{\let\scr@caption\caption}
%    \end{macrocode}
% \end{macro}^^A \scr@caption
% Jetzt ist es möglich durch einfaches Umlegen des Schalters für die
% korrekte Darstellung zu sorgen:
%    \begin{macrocode}
\newcommand{\captionabove}{\@captionabovetrue\scr@caption}
\newcommand{\captionbelow}{\@captionabovefalse\scr@caption}
%    \end{macrocode}
% \end{command}^^A \captionabove,\captionbelow
%
%
% \begin{environment}{captionbeside}
% \changes{v2.8q}{2001/11/22}{added}
% Placing captions above or below the object inside a float is easy. But to
% place it beside the object an additional environment is needed. This has to
% collect the object (environment body) into a box and then print it side by
% side with a second box with the caption. Note: This cannot work with
% tables of package \pkg{longtable} or \pkg{supertabular} or similar packages.
% \begin{quote}\raggedright
%   |\begin{captionbeside}|\oarg{list
%     entry}\marg{caption}\oarg{position}\oarg{with}\oarg{offset}|*|\\
%     \dots\\
%   |\end{captionbeside}|
% \end{quote}
% Note: The asterisk is optional and changes the meaning of \meta{offset}.
% \begin{macro}{\scap@caption}
% \changes{v2.8q}{2001/11/22}{added}
% The \meta{caption} is locally stored into helper macro \cs{scap@caption}.
%    \begin{macrocode}
\newcommand*{\scap@caption}{}
%    \end{macrocode}
% \end{macro}^^A \scap@caption
% \begin{macro}{\scap@width}
% \changes{v2.8q}{2001/11/22}{added}
% The optional \meta{width}, which is the width of the whole environment
% inclusive caption, is locally stored into helper macro \cs{scap@width}. The
% default is the while line width.
%    \begin{macrocode}
\newcommand*{\scap@width}{\linewidth}
%    \end{macrocode}
% \end{macro}^^A \scap@width
% \begin{macro}{\scap@move}
% \changes{v2.8q}{2001/11/22}{added}
% If \cs{scap@width} is not the line width, the environment is horizontal
% centered by default. But if \meta{offset} is used, this is used as a
% distance from the left margin. This is locally stored into helper macro
% \cs{scap@move}.
%    \begin{macrocode}
\newcommand*{\scap@move}{\z@}
%    \end{macrocode}
% \end{macro}^^A \scap@move
% \begin{macro}{\scap@altfalse,\scap@alttrue,\ifscap@alt}
% \changes{v2.8q}{2001/11/22}{added}
% The boolean switch \cs{ifscap@alt} is used to decide if in twoside mode the
% movement of \cs{scap@move} has to be done from the left or the right margin
% and to left or to the right.
%    \begin{macrocode}
\newif\ifscap@alt
%    \end{macrocode}
% \end{macro}^^A \ifscap@alt
% \begin{macro}{\scap@currentlabel}
% \changes{v2.8q}{2001/11/24}{added}
% \begin{macro}{\scap@currentcounter,\scap@currentlabelname,\scap@currentHref}
% \changes{v3.38}{2022/07/30}{added}
% Because of using \cs{caption} inside a box and inside an environment, a
% label after the \env{captionbeside} environment usually would not reference
% the caption number. To preserve this after the end of the
% \env{captionbeside} the current label and counter are locally stored into
% global \cs{scap@currentlabel} and restored after the end of the environment
% using \cs{aftergroup}. Note: You can have only one \cs{label} inside!
%    \begin{macrocode}
\newcommand*{\scap@currentlabel}{}
\newcommand*{\scap@currentlabelname}{}
\newcommand*{\scap@currentHref}{}
%    \end{macrocode}
% \end{macro}^^A \scap@currentcounter … \scap@currentHref
% \end{macro}^^A \scap@currentlabel
% \begin{macro}{\@@@captionbeside,\@@captionbeside,\@captionbeside}
% \changes{v2.8q}{2001/11/22}{added}
% \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by \cs{kernel@ifnextchar}}
% \begin{macro}{\@@@@captionbeside}
% \changes{v2.8q}{2001/11/22}{added}
% \changes{v3.20}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% To handle all the optional arguments and the optional star at the end,
% several helper macros are needed (because we currently do not use \pkg{xparse}).
%    \begin{macrocode}
\newcommand*{\@captionbeside}{}
\long\def\@captionbeside[#1]#2{%
  \kernel@ifnextchar [%]
    {\@@captionbeside[{#1}]{#2}}
    {\c@pti@nb@sid@[{#1}]{#2}}%
}
\newcommand*{\@@captionbeside}{}
\long\def\@@captionbeside[#1]#2[#3]{%
  \def\scap@pos{#3}%
  \kernel@ifnextchar [%]
    {\@@@captionbeside[{#1}]{#2}}
    {\c@pti@nb@sid@[{#1}]{#2}}%
}
\newcommand*{\@@@captionbeside}{}
\long\def\@@@captionbeside[#1]#2[#3]{%
  \def\scap@width{#3}%
  \kernel@ifnextchar [%]
    {\@@@@captionbeside[{#1}]{#2}}
    {\setlength{\@tempdima}{#3}%
      \addtolength{\@tempdima}{-\linewidth}%
      \setlength{\@tempdima}{-.5\@tempdima}%
      \edef\scap@move{\the\@tempdima}%
      \c@pti@nb@sid@[{#1}]{#2}}%
}
\newcommand*{\@@@@captionbeside}{}
\long\def\@@@@captionbeside[#1]#2[#3]{%
  \def\scap@move{#3}%
  \kernel@ifstar
    {\scap@alttrue\c@pti@nb@sid@[{#1}]{#2}}
    {\scap@altfalse\c@pti@nb@sid@[{#1}]{#2}}%
}
%    \end{macrocode}
% \end{macro}^^A \@@@@captionbeside
% \end{macro}^^A \@@@captionbeside … \@captionbeside
% \begin{macro}{\c@pti@nb@sid@b@x}
% \changes{v2.8q}{2001/11/22}{added}
% We also use our own box register to collect the environment body.
%    \begin{macrocode}
\newbox\c@pti@nb@sid@b@x
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\c@pti@nb@sid@}
% \changes{v2.8q}{2001/11/22}{added}
% \changes{v2.98c}{2008/03/11}{vertical alignment fixed}
% \changes{v3.07a}{2010/11/04}{vertical alignment \texttt{t} and \texttt{b}
%   fixed}
% \changes{v3.99}{2022/11/10}{vertical alignment fixed}
% This is the real beginning of the environment. After collecting all the
% arguments into local macros. Until version 4 the vertical alignment was
% totally broken at least, if font element \fnt{caption} changes font
% size. From version 4 we try to take care on this. However, the current
% solution could still fail, if the first resp. last line of content of the
% environment changes the font size.
%    \begin{macrocode}
\newcommand{\c@pti@nb@sid@}{}
%<*!v4>
\long\def\c@pti@nb@sid@[#1]#2{%
  \def\scap@caption{%
    \if c\scap@valign
      \setlength{\abovecaptionskip}{\z@}%
    \else \if t\scap@valign
        \setlength{\abovecaptionskip}{-\ht\strutbox}%
      \else \if b\scap@valign
          \setlength{\abovecaptionskip}{\z@}%
        \fi
      \fi
    \fi
    \setlength{\belowcaptionskip}{-\dp\strutbox}%
    \captionbelow[{#1}]{#2}%
  }%
  \begin{lrbox}{\c@pti@nb@sid@b@x}%
}
%</!v4>
%<*v4>
\long\def\c@pti@nb@sid@[#1]#2{%
  \def\scap@caption{%
    \abovecaptionskip\z@
    \belowcaptionskip\z@
    \if t\scap@valign
      {%
        \usekomafont{caption}{%
          \global\@tempdima\ht\strutbox
        }%
      }%
      \setlength{\abovecaptionskip}{-\@tempdima}%
    \fi
    \if b\scap@valign  
      {%
        \usekomafont{caption}{%
          \global\@tempdima\dp\strutbox
        }%
      }%
      \setlength{\belowcaptionskip}{\dimexpr\dp\strutbox-2\@tempdima\relax}%
    \fi
    \captionbelow[{#1}]{#2}%
  }%
  \begin{lrbox}{\c@pti@nb@sid@b@x}%
}
%</v4>
%    \end{macrocode}
% \end{macro}^^A \c@pti@nb@sid@
% Now we can use all of the helper macros to begin the environment. We use
% \LaTeX{} kernel macro \cs{@dblarg} to define an argument with first
% optional argument defaults to mandatory second argument.
%    \begin{macrocode}
\newenvironment*{captionbeside}{%
  \@dblarg\@captionbeside
}{%
%    \end{macrocode}
% This was easy (because of using all the helper macros), but the end of the
% environment isn't. Here we do all the calculations for printing.
% \changes{v2.9a}{2002/06/27}{\cs{ifthispageodd} replaced by \cs{if@thispageodd}}
% \changes{v3.28}{2019/11/19}{\cs{ifthispageodd} replaced by \cs{Ifthispageodd}}
%    \begin{macrocode}
  \end{lrbox}%
  \settowidth{\@tempdima}{\usebox\c@pti@nb@sid@b@x}%
  \setlength{\@tempdimb}{\scap@width}%
  \addtolength{\@tempdimb}{-\@tempdima}%
  \addtolength{\@tempdimb}{-\columnsep}%
  \ifdim \@tempdimb<2em
    \ClassWarning{\KOMAClassName}{%
      caption beside will be very, very small.\MessageBreak
      In most cases this will result in overfull and\MessageBreak
      underfull \string\hbox\space messages%
    }%
  \fi
  \onelinecaptionsfalse
  \setcapwidth[r]{\@tempdimb}%
  \let\@tempa\scap@pos
  \setlength{\@tempdimc}{\scap@move}%
  \if i\scap@pos\def\@tempa{l}\fi
  \if o\scap@pos\def\@tempa{r}\fi
  \if@twoside
    \Ifthispageodd{}{%
      \if o\scap@pos\def\@tempa{l}\fi
      \if i\scap@pos\def\@tempa{r}\fi
      \ifscap@alt
        \addtolength{\@tempdimc}{\scap@width}%
        \addtolength{\@tempdimc}{-\linewidth}%
        \setlength{\@tempdimc}{-\@tempdimc}%
      \fi
    }%
  \fi
  \hspace*{\@tempdimc}%
%    \end{macrocode}
% \changes{v2.9p}{2003/12/10}{\cs{@temdima} replaced by
%   \cs{wd}\cs{c@pti@nb@sid@b@x}, because \cs{@temdima} would be changed}
% \changes{v3.38}{2022/07/20}{using \cs{scap@currentcounter}}
% \changes{v3.38}{2022/07/20}{using \cs{scap@currentlabelname}}
% \changes{v3.38}{2022/07/20}{using \cs{scap@currentHref}}
%    \begin{macrocode}   
  \if l\@tempa
    \rlap{%
      \parbox[\scap@valign]{\@tempdimb}{\scap@caption
        \global\let\scap@currentlabel\@currentlabel
        \global\let\scap@currentcounter\@currentcounter
        \global\let\scap@currentlabelname\@currentlabelname
        \global\let\scap@currentHref\@currentHref
      }%
      \nobreak\hskip\columnsep
      \parbox[\scap@valign]{\wd\c@pti@nb@sid@b@x}{\usebox\c@pti@nb@sid@b@x}%
    }%
  \else
    \rlap{%
      \parbox[\scap@valign]{\wd\c@pti@nb@sid@b@x}{\usebox\c@pti@nb@sid@b@x}%
      \nobreak\hskip\columnsep
      \parbox[\scap@valign]{\@tempdimb}{\scap@caption
        \global\let\scap@currentlabel\@currentlabel
        \global\let\scap@currentcounter\@currentcounter
        \global\let\scap@currentlabelname\@currentlabelname
        \global\let\scap@currentHref\@currentHref
      }%
    }%
  \fi
  \par
  \aftergroup\let\aftergroup\@currentlabel\aftergroup\scap@currentlabel
  \aftergroup\let\aftergroup\@currentcounter\aftergroup\scap@currentcounter
  \aftergroup\let\aftergroup\@currentlabelname\aftergroup\scap@currentlabelname
  \aftergroup\let\aftergroup\@currentHref\aftergroup\scap@currentHref
}
%    \end{macrocode}
% \end{environment}^^A captionbeside
%
%
% \begin{fontelement}{caption,captionlabel}
% We need two font elements for the caption at whole and the label part only.
% \begin{macro}{\capfont,\caplabelfont}
% \changes{v2.8c}{2001/06/29}{\cs{normalcolor} added}
% Originally two user macros has been used to change the fonts. To stay
% compatible with old \KOMAScript{} and also i.e. with package \pkg{caption},
% we still define \cs{capfont} and \cs{caplabelfont} as internal storage of
% the font elements. But already from \KOMAScript{} version 2.8c these should
% be interpreted as internal macros.
%    \begin{macrocode}
\newcommand*\capfont{\normalfont\normalcolor}
\newcommand*\caplabelfont{\normalfont\normalcolor}
%    \end{macrocode}
% \end{macro}^^A \capfont,\caplabelfont
% \begin{macro}{\scr@fnt@caption,\scr@fnt@captionlabel}
% \changes{v2.8o}{2001/09/14}{added}
% Because of that non-default for the internal storage the font elements have
% to be defined \emph{manually} instead of using \cs{newkomafont}.
%    \begin{macrocode}
\newcommand*{\scr@fnt@caption}{\capfont}
\newcommand*{\scr@fnt@captionlabel}{\caplabelfont}
%    \end{macrocode}
% \end{macro}^^A \scr@fnt@caption,\scr@fnt@captionlabel
% \end{fontelement}^^A caption,captionlabel
%
% \begin{macro}{\@makecaption}
% \changes{v2.3a}{1995/07/08}{using \cs{sbox} instead of \cs{setbox}}
% \changes{v2.3a}{1995/07/08}{using \cs{@minipagefalse}}
% \changes{v2.3f}{1995/12/09}{using same font switching for long and short captions}
% \changes{v2.5g}{1999/10/09}{supporting partial hanging captions}
% \begin{macro}{\dofullc@pfalse,\dofullc@ptrue,\ifdofullc@p}
% The boolean switch \cs{ifdofullc@p} is true for caption texts, that should
% be full hanging (behind the label part), which is the default.
%    \begin{macrocode}
\newif\ifdofullc@p
\dofullc@ptrue
%    \end{macrocode}
% \end{macro}^^A  \ifdofullc@p
% \begin{macro}{\if@capbreak}
% \changes{v2.8j}{2001/07/30}{added}
% The boolean switch \cs{if@capbreak} is true, if the label should be followed
% by a line break, which is not the case by default.
%    \begin{macrocode}
\newif\if@capbreak
\@capbreakfalse
%    \end{macrocode}
% \end{macro}^^A \@capbreakfalse
% \begin{command}{\setcapindent}
% \begin{macro}{\@@setcaptindent,\@setcapindent}
% \changes{v2.8j}{2001/07/30}{using \cs{if@capbreak}}
% \changes{v2.8l}{2001/08/17}{using \cs{edef}\cs{cap@indent} instead of
%   \cs{def}\cs{cap@indent}}
% \changes{v2.8q}{2001/11/17}{redefined after loading \pkg{caption2}}
% \changes{v3.20}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \changes{v3.34}{2021/03/22}{special treatment of \pkg{caption2} removed}
% The user can configure the indent using:
% \begin{quote}
%   \cs{setcapindent}*\marg{indent}
% \end{quote}
% The optional asterisk activates a line break between the label and the
% text. The \meta{indent} is always an indent of the text from the left. A
% local dimension assignment is done to report errors here and not at
% usage of \cs{cap@indent}.
%    \begin{macrocode}
\newcommand*{\setcapindent}{\kernel@ifstar{\@@setcapindent}{\@setcapindent}}
\newcommand*{\@setcapindent}[1]{%
  \setlength{\@tempdima}{#1}%
  \ifdim\@tempdima>\hsize
    \addtolength{\@tempdima}{-\hsize}\@capbreaktrue
  \else
    \@capbreakfalse
  \fi
  \edef\cap@indent{\the\@tempdima}%
  \dofullc@pfalse
}
\newcommand*{\@@setcapindent}[1]{%
  \setlength{\@tempdima}{#1}%
  \edef\cap@indent{\the\@tempdima}%
  \dofullc@pfalse\@capbreaktrue
}
%    \end{macrocode}
% \end{macro}^^A \@@setcaptindent,\@setcapindent
% \end{command}^^A \setcapindent
% \begin{command}{\setcaphanging}
% \changes{v2.8q}{2001/11/17}{redefined after loading \pkg{caption2}}
% \changes{v3.34}{2021/03/22}{special treatment of \pkg{caption2} removed}
% Alternatively the user can select the full hanging printing.
%    \begin{macrocode}
\newcommand*{\setcaphanging}{\dofullc@ptrue\@capbreakfalse}
%    \end{macrocode}
% \end{command}
% Now, we have all to define \cs{@makecaption} as needed by the \LaTeX{} kernel.
% \changes{v2.5g}{1999/10/09}{using \cs{newcommand}}
% \changes{v2.8h}{2001/07/19}{support for headings and signatures}
% \changes{v2.8j}{2001/07/30}{using \cs{@@makecaption}}
% \changes{v2.8q}{2001/11/17}{special treatment of one line captions is optional}
% \changes{v2.8q}{2001/11/17}{caption width can be limited}
%    \begin{macrocode}
\newcommand{\@makecaption}[2]{%
  \if@captionabove
    \vskip\belowcaptionskip
  \else
    \vskip\abovecaptionskip
  \fi
  \@@makecaption\@firstofone{#1}{#2}%
  \if@captionabove
    \vskip\abovecaptionskip
  \else
    \vskip\belowcaptionskip
  \fi
}
%    \end{macrocode}
% \begin{macro}{\cap@width,\cap@left,\cap@right}
% \changes{v2.8q}{2001/11/17}{added}
% Multi line captions can printed with a reduced with. If the width is reduced
% the left an right margin can be changed. The defaults are centering.
%    \begin{macrocode}
\newcommand*{\cap@width}{\hsize}
\newcommand*{\cap@left}{\hfill}
\newcommand*{\cap@right}{\hfill}
%    \end{macrocode}
% \end{macro}^^A \cap@width,\cap@left,\cap@right
% \begin{command}{\setcapwidth}
% \changes{v2.8q}{2001/11/17}{added}
% \changes{v2.9a}{2002/06/27}{\cs{ifthispageodd} replaced by \cs{if@thispageodd}}
% \changes{v2.97}{2007/02/27}{minimum width for captions is 0\,pt}
% \changes{v3.28}{2019/11/19}{\cs{ifthispageodd} replaced by \cs{Ifthispageodd}}
% \changes{v3.34}{2021/03/22}{special treatment of \pkg{caption2} removed}
% The user command:
% \begin{quote}
%   \cs{setcapwidth}\oarg{alignment}\marg{width}
% \end{quote}
% is one choice to set \cs{cap@width} to \meta{width}. The optional
% \meta{alignment} (as usual |l|, |r|, |o|, or |i|) also changes \cs{cap@left}
% and \cs{cap@right}.
%    \begin{macrocode}
\newcommand*{\setcapwidth}[2][]{%
  \begingroup%
    \setlength{\@tempdima}{#2}%
    \ifdim\@tempdima <\z@
      \@tempdima\z@
      \ClassWarning{\KOMAClassName}{%
        caption width less than 0pt not allowed.\MessageBreak
        Setting caption width to 0pt%
      }%
    \fi
    \edef\@tempa{\endgroup\def\noexpand\cap@width{\the\@tempdima}}%
  \@tempa
  \begingroup
    \edef\@tempa{#1}%
    \def\@tempb{c}\ifx\@tempa\@tempb
      \endgroup
      \def\cap@margin{\let\cap@left=\hfill\let\cap@right=\hfill}%
    \else
      \def\@tempb{l}\ifx\@tempa\@tempb
        \endgroup
        \def\cap@margin{\let\cap@left=\relax\let\cap@right\hfill}%
      \else
        \def\@tempb{r}\ifx\@tempa\@tempb
          \endgroup
          \def\cap@margin{\let\cap@left=\hfill\let\cap@right=\relax}%
        \else
          \def\@tempb{i}\ifx\@tempa\@tempb
            \endgroup
            \def\cap@margin{%
              \let\cap@left=\relax
              \let\cap@right=\hfill
              \if@twoside
                \Ifthispageodd{}{%
                  \let\cap@left=\hfill
                  \let\cap@right=\relax
                }%
              \fi
            }%
          \else
            \def\@tempb{o}\ifx\@tempa\@tempb
              \endgroup
              \def\cap@margin{%
                \let\cap@left=\hfill
                \let\cap@right=\relax
                \if@twoside
                  \Ifthispageodd{}{%
                    \let\cap@left=\relax
                    \let\cap@right=\hfill
                  }%
                \fi
              }%
            \else
              \ifx \@tempa\@empty\else
                \ClassError{\KOMAClassName}{%
                  unknown optional position argument%
                }{%
                  You've used `#1' as position argument at
                  \string\setcaptionwidth,\MessageBreak
                  but only ONE of `c', `l', `r', `i`, `o` ist
                  allowed.\MessageBreak
                  Argument will be ignored, if you'll continue.%
                }%
              \fi
              \endgroup
  \fi\fi\fi\fi\fi
}
%    \end{macrocode}
% \end{command}^^A \setcapwidth
% \begin{command}{\setcapdynwidth}
% \changes{v3.20}{2016/03/31}{added}
% Ulrike Fischer requested for an alternative, that does not behave like
% \cs{setlength} and therefore sets the length already at usage of
% \cs{setcapwidth} but at usage of \cs{cap@width}. This is
% \cs{setcapdynwidth}. But in this case mistakes can result in errors while
% usage of \cs{cap@width} too.
%    \begin{macrocode}
\newcommand*{\setcapdynwidth}[2][]{%
  \def\cap@width{#2}%
  \begingroup
    \edef\@tempa{#1}%
    \def\@tempb{c}\ifx\@tempa\@tempb
      \endgroup
      \def\cap@margin{%
        \ifdim \cap@width<\z@
          \ClassWarning{\KOMAClassName}{%
            caption width less than 0pt not allowed.\MessageBreak
            Setting caption width to 0pt%
          }%
          \let\cap@width\z@
        \fi
        \let\cap@left=\hfill\let\cap@right=\hfill}%
    \else
      \def\@tempb{l}\ifx\@tempa\@tempb
        \endgroup
        \def\cap@margin{%
          \ifdim \cap@width<\z@
            \ClassWarning{\KOMAClassName}{%
              caption width less than 0pt not allowed.\MessageBreak
              Setting caption width to 0pt%
            }%
            \let\cap@width\z@
          \fi
          \let\cap@left=\relax\let\cap@right\hfill}%
      \else
        \def\@tempb{r}\ifx\@tempa\@tempb
          \endgroup
          \def\cap@margin{%
            \ifdim \cap@width<\z@
              \ClassWarning{\KOMAClassName}{%
                caption width less than 0pt not allowed.\MessageBreak
                Setting caption width to 0pt%
              }%
              \let\cap@width\z@
            \fi
            \let\cap@left=\hfill\let\cap@right=\relax}%
        \else
          \def\@tempb{i}\ifx\@tempa\@tempb
            \endgroup
            \def\cap@margin{%
              \ifdim \cap@width<\z@
                \ClassWarning{\KOMAClassName}{%
                  caption width less than 0pt not allowed.\MessageBreak
                  Setting caption width to 0pt%
                }%
                \let\cap@width\z@
              \fi
              \let\cap@left=\relax
              \let\cap@right=\hfill
              \if@twoside
                \Ifthispageodd{}{%
                  \let\cap@left=\hfill
                  \let\cap@right=\relax
                }%
              \fi
            }%
          \else
            \def\@tempb{o}\ifx\@tempa\@tempb
              \endgroup
              \def\cap@margin{%
                \ifdim \cap@width<\z@
                  \ClassWarning{\KOMAClassName}{%
                    caption width less than 0pt not allowed.\MessageBreak
                    Setting caption width to 0pt%
                  }%
                  \let\cap@width\z@
                \fi
                \let\cap@left=\hfill
                \let\cap@right=\relax
                \if@twoside
                  \Ifthispageodd{}{%
                    \let\cap@left=\relax
                    \let\cap@right=\hfill
                  }%
                \fi
              }%
            \else
              \ifx \@tempa\@empty\else
                \ClassError{\KOMAClassName}{%
                  unknown optional position argument%
                }{%
                  You've used `#1' as position argument at
                  \string\setcaptionwidth,\MessageBreak
                  but only ONE of `c', `l', `r', `i`, `o` ist
                  allowed.\MessageBreak
                  Argument will be ignored, if you'll continue.%
                }%
              \fi
              \endgroup
  \fi\fi\fi\fi\fi
}
%    \end{macrocode}
% \end{command}^^A \setcapdynwidth
% \begin{macro}{\cap@margin}
% \changes{v2.8q}{2001/11/17}{added}
% \cs{cap@margin} is used to recalculate \cs{cap@left} and \cs{cap@right}
% inside \cs{@@makecaption}, if the margins has been set using
% \cs{setcapmargin}. Default is no such action.
%    \begin{macrocode}
\newcommand*{\cap@margin}{}
\let\cap@margin=\relax%
%    \end{macrocode}
% \end{macro}^^A \cap@margin
% \begin{command}{\setcapmargin}
% \changes{v2.8q}{2001/11/17}{neu}
% \changes{v3.20}{2016/04/12}{\cs{@ifstar} replaced by \cs{kernel@ifstar}}
% \begin{macro}{\@@setcapmargin,\@setcapmargin}
% \changes{v2.8q}{2001/11/17}{added}
% \changes{v2.9a}{2002/06/27}{\cs{ifthispageodd} replaced by \cs{if@thispageodd}}
% \changes{v3.28}{2019/11/19}{\cs{ifthispageodd} replaced by \cs{Ifthispageodd}}
% \changes{v3.34}{2021/03/22}{special treatment for \pkg{caption2} removed}
% Instead of setting of the width of the caption, the left and right margin
% can be set. The star variant switch left and right depending on odd or even
% side in two side mode.
%    \begin{macrocode}
\newcommand*{\setcapmargin}{\kernel@ifstar{\@setcapmargin}{\@@setcapmargin}}
\newcommand*{\@setcapmargin}[2][\@tempdimb]{%
  \def\cap@margin{%
    \onelinecaptionsfalse
    \begingroup
      \setlength{\@tempdima}{\hsize}%
      \setlength{\@tempdimb}{#2}%
      \addtolength{\@tempdima}{-\@tempdimb}%
      \setlength{\@tempdimc}{#1}%
      \addtolength{\@tempdima}{-\@tempdimc}%
      \edef\@tempa{\endgroup
        \def\noexpand\cap@width{\the\@tempdima}%
        \noexpand\if@twoside
          \noexpand\Ifthispageodd{%
            \def\noexpand\cap@left{\noexpand\hspace*{\the\@tempdimc}}%
            \def\noexpand\cap@right{\noexpand\hspace*{\the\@tempdimb}}%
          }{%
            \def\noexpand\cap@right{\noexpand\hspace*{\the\@tempdimc}}%
            \def\noexpand\cap@left{\noexpand\hspace*{\the\@tempdimb}}%
          }%
        \noexpand\else
          \def\noexpand\cap@left{\noexpand\hspace*{\the\@tempdimc}}%
          \def\noexpand\cap@right{\noexpand\hspace*{\the\@tempdimb}}%
        \noexpand\fi
      }%
    \@tempa
  }%
}
\newcommand*{\@@setcapmargin}[2][\@tempdimb]{%
  \def\cap@margin{%
    \onelinecaptionsfalse
    \begingroup
      \setlength{\@tempdima}{\hsize}%
      \setlength{\@tempdimb}{#2}%
      \addtolength{\@tempdima}{-\@tempdimb}%
      \setlength{\@tempdimc}{#1}%
      \addtolength{\@tempdima}{-\@tempdimc}%
      \edef\@tempa{\endgroup
        \def\noexpand\cap@width{\the\@tempdima}%
        \def\noexpand\cap@left{\noexpand\hspace*{\the\@tempdimc}}%
        \def\noexpand\cap@right{\noexpand\hspace*{\the\@tempdimb}}%
      }%
    \@tempa
  }%
}
%    \end{macrocode}
% \end{macro}^^A \@@setcapmargin,\@setcapmargin
% \end{command}^^A \setcapmargin
% \begin{macro}{\@@makecaption}
% The main job is done by \cs{@@makecaption}. It has an additional first
% argument, that has to be either \cs{@gobble} or \cs{@firstofone}. This is
% used to either set a label or not. This is needed for captions of
% \pkg{longtable}.
% \changes{v2.8q}{2002/05/17}{avoid double increase of footnote number}
% \changes{v2.95}{2004/01/30}{fixing vertical skips also with \pkg{float}}
% \changes{v2.95a}{2006/07/13}{fixing vertical skips with \pkg{color}}
% \changes{v2.97c}{2007/06/06}{\cs{unskip}\cs{strut} added to fix vertical
%   positions in some \emph{above} cases}
% \changes{v3.02a}{2009/01/24}{braces fixed}
% \changes{v3.11c}{2013/06/12}{using \cs{usekomafont}}
% \changes{v3.12}{2013/06/12}{one \cs{usekomafont} replaced by \cs{usesizeofkomafont}}
% \changes{v3.21}{2016/05/31}{re-implemented}
%    \begin{macrocode}
\newcommand{\@@makecaption}[3]{%
%    \end{macrocode}
% Recalculate the margins.
%    \begin{macrocode}
  \cap@margin
%    \end{macrocode}
% Test for special treatment of one line captions.
% \changes{v3.22}{2016/09/01}{local redefinition of \cs{stepcounter} and
%   \cs{refstepcounter} because of \pkg{isodate}}
%    \begin{macrocode}
  \begingroup
    \ifonelinecaptions
      \def\stepcounter##1{\advance\value{##1}\@ne}%
      \let\refstepcounter\stepcounter
      \let\label\@gobble
      \let\@footnotetext=\@gobble
      \let\hypertarget\@gobbletwo
%    \end{macrocode}
% \changes{v3.22}{2016/09/01}{special treatment of hard coded line breaks}
% If there are hard coded line breaks using |\\| or \cs{newline}, we inform
% the user to use a multi-line caption.
%    \begin{macrocode}
      \edef\@xnewline{%
        \unexpanded{\ClassInfo{\KOMAClassName}{%
            Workaround for not recommended usage of \string\\ or\MessageBreak
            \string\newline in caption text
          }%
          \hspace*{\linewidth}\hspace{1sp}%
        }%
        \unexpanded\expandafter{\@xnewline}%
      }%
      \edef\@xcentercr{%
        \unexpanded{\ClassInfo{\KOMAClassName}{%
            Workaround for not recommended usage of \string\\ or\MessageBreak
            \string\newline in caption text
          }%
          \hspace*{\linewidth}\hspace{1sp}%
        }%
        \unexpanded\expandafter{\@xcentercr}%
      }%
      \settowidth{\@tempdima}{\scr@@makesinglelinecaption{#1}{#2}{#3}}%
%    \end{macrocode}
% \changes{v3.34}{2021/03/22}{fix of maximum line width of single line
%   captions}
% Until \KOMAScript~3.34 the test here was wrong, because it used
% \cs{linewidth}, which is still the whole line width not the maximum caption
% width. From \KOMAScript~3.34 \cs{cap@width} is used.
%    \begin{macrocode}
      \ifdim\@tempdima>\cap@width
        \aftergroup\scr@makemultilinecaption
      \else
        \aftergroup\scr@makesinglelinecaption
      \fi
    \else
      \aftergroup\scr@makemultilinecaption
    \fi
  \endgroup
  {#1}{#2}{#3}%
}
%    \end{macrocode}
% \begin{macro}{\scr@@makesinglelinecaption,\scr@makesinglelinecaption}
% \changes{v3.21}{2016/05/31}{added}
% The output of single line captions. The first argument once again is
% \cs{@gobble} (to not show a label) or \cs{@firstofone} (to show the
% label). Argument two and three are the label (without separator, that is
% added here) and the caption text.
%    \begin{macrocode}
\newcommand{\scr@makesinglelinecaption}[3]{%
  {%
    \usefontofkomafont{caption}{%
      \hb@xt@\hsize{%
        \cap@left
        \scr@@makesinglelinecaption{#1}{#2}{#3}%
        \cap@right
      }\par\kern\dp\strutbox%
    }%
  }\kern-\dp\strutbox
}
\newcommand{\scr@@makesinglelinecaption}[3]{%
    \usekomafont{caption}{\strut\ignorespaces
      #1{{\usekomafont{captionlabel}{#2\captionformat}}}%
      \ignorespaces #3\unskip}%
}
%    \end{macrocode}
% \end{macro}^^A \scr@@makesinglelinecaption,\scr@makesinglelinecaption
% \begin{macro}{\scr@makemultilinecaption}
% \changes{v3.21}{2016/05/31}{added}
% The output of multi line captions. The arguments are same as above.
%    \begin{macrocode}
\newcommand{\scr@makemultilinecaption}[3]{%
  {%
    \usefontofkomafont{caption}{%
      \hb@xt@\hsize{%
        \cap@left
        \vbox{\hsize\cap@width\linewidth\hsize
%    \end{macrocode}
% \changes{v3.25}{2017/11/15}{caption alignment added}
% First of all we have to use the ragged type depending in the float/caption
% type. If the float/caption type is unknown we can use the general ragged
% type only.
%    \begin{macrocode}
          \scr@ifundefinedorrelax{@captype}{%
            \ClassWarning{\KOMAClassName}{%
              `\string\caption' outside float.\MessageBreak
              Seems you are using `\string\caption' outside a
              float.\MessageBreak
              Maybe you are using a package that uses
              `\string\@makecaption'\MessageBreak
              without setting `\string\@captype' before.\MessageBreak
              Because I cannot detect the caption type, I'm using\MessageBreak
              the empty one.%
            }%
            \let\@captype\@empty
          }{}%
          \scr@ifundefinedorrelax{ragged\@captype caption}{\raggedcaption}{%
            \@nameuse{ragged\@captype caption}%
          }%
%    \end{macrocode}
% Maybe we have to us a full hanging caption.
% \changes{v3.25}{2017/11/15}{Using \cs{scr@endstrut} instead of \cs{unskip}\cs{strut}}
%    \begin{macrocode}
          \ifdofullc@p
            \@hangfrom{%
              \strut
              \scr@smashdp{%
                #1{%
                  \usekomafont{caption}{%
                    \usekomafont{captionlabel}{#2\captionformat}%
                  }%
                }%
              }%
            }%
            {\usekomafont{caption}{#3\scr@endstrut\par}}%
%    \end{macrocode}
% Maybe a partial hanging caption with line break after the label.
%    \begin{macrocode}
          \else
            \ifdim\cap@indent<\z@
              \strut
              #1{%
                \usekomafont{caption}{%
                  \usekomafont{captionlabel}{#2\captionformat\par}%
                }%
              }%
              \noindent{\usekomafont{caption}{%
                  \hspace*{-\cap@indent}#3\scr@endstrut\par
              }}%
%    \end{macrocode}
% Or a line break after the label with full hanging.
%    \begin{macrocode}
            \else
              \if@capbreak
                \strut
                #1{%
                  \usekomafont{caption}{%
                    \usekomafont{captionlabel}{#2\captionformat\par}%
                  }%
                }%
                \noindent\@hangfrom{\hspace*{\cap@indent}}%
                {\usekomafont{caption}{#3\scr@endstrut\par}}%
%    \end{macrocode}
% \changes{v3.27a}{2019/10/21}{missing usage of \fnt{caption} added}
% Or no line break but still with indent.
%    \begin{macrocode}
              \else
                \@hangfrom{\scr@smashdp\strut\hspace*{\cap@indent}}%
                {%
                  \hspace{-\cap@indent}%
                  \scr@smashdp{%
                    #1{\usekomafont{caption}{%
                        \usekomafont{captionlabel}{#2\captionformat}%
                      }%
                    }%
                  }%
                  {\usekomafont{caption}{#3\scr@endstrut}\par}%
                }%
              \fi
            \fi
          \fi
%    \end{macrocode}
% Here we could also add the not hanging version without line break:
%    \begin{macrocode}
%<*neverusethis>
%          #1{{\usekomafont{caption}{%
%              \usekomafont{captionlabel}{#2\captionformat}}}}%
%          {\usekomafont{capion}{\ignorespaces #3\scr@endstrut\par}%
%</neverusethis>
%    \end{macrocode}
% But this is not needed, because it is the same like indent of 0.
%    \begin{macrocode}
        }%
        \cap@right
      }\par\kern\dp\strutbox
    }%
  }\kern-\dp\strutbox
}
%    \end{macrocode}
% \begin{command}{\setcaptionalignment}
% \begin{macro}{\@setcaptionalignment}
% \changes{v3.25}{2017/11/15}{added}
% \changes{v3.28}{2019/11/18}{\cs{ifstr} replaced by \cs{Ifstr}}
% It is better for users to not define the \cs{raggedcaption} and
% \cs{ragged\dots caption} commands themselves to avoid mistakes. So we have
% \begin{quote}
%   \cs{setcaptionalignment}\oarg{float}\marg{alignment}
% \end{quote}
% If \meta{float} is used, \cs{ragged\meta{float}caption} will be changed. If
% \meta{float} is not used, but \cs{@captype} is defined (and not \cs{relax})
% \cs{ragged\cs{@captype}caption} is defined. If \meta{float} is empty or
% \cs{captype} is undefined (or \cs{relax}) and \meta{float} is not used,
% \cs{raggedcaption} will be changed.
%    \begin{macrocode}
\newcommand*\setcaptionalignment{%
  \kernel@ifnextchar [%]
    {\@setcaptionalignment}
    {%
      \scr@ifundefinedorrelax{@captype}{\@setcaptionalignment}{%
        \edef\reserved@a{\noexpand\@setcaptionalignment[{\@captype}]}\reserved@a
      }%
    }%
}%
\newcommand*\@setcaptionalignment[2][]{%
%    \end{macrocode}
% If \meta{float} is not empty it should be the name of a already defined
% floating environment. Otherwise we report a warning, but nevertheless define
% the command.
%    \begin{macrocode}
  \IfArgIsEmpty{#1}{}{%
    \expandafter\ifnum 
    \scr@ifundefinedorrelax{#1}{0}{\scr@ifundefinedorrelax{end#1}{0}{1}}=0
      \ClassWarning{\KOMAClassName}{%
        float type `#1' defined not yet,\MessageBreak
        but setting ragged mode for captions of\MessageBreak
        float type `#1'%
      }%
    \fi
  }%
%    \end{macrocode}
% Depending on \meta{alignment} the command will be changed:
% \begin{description}
% \item[\texttt{j}] -- justified (\cs{ragged\dots caption} becomes \cs{relax}).
% \item[\texttt{l}] -- left aligned (\cs{ragged\dots caption} becomes
%                      \cs{raggedright}).
% \item[\texttt{r}] -- right aligned (\cs{ragged\dots caption} becomes
%                      \cs{raggedleft}).
% \item[\texttt{c}] -- centered (\cs{ragged\dots caption} becomes
%                      \cs{centering}.
% \end{description}
% Note: If \pkg{ragged2e} has been loaded, \cs{LaTeXraggedright},
% \cs{LaTeXraggedleft} and \cs{LaTeXcentering} are used and the following
% additional \meta{alignment}s are supported:
% \begin{description}
% \item[\texttt{J}] -- justified (\cs{ragged\dots caption} becomes \cs{justifying}).
% \item[\texttt{L}] -- left aligned (\cs{ragged\dots caption} becomes
%                      \cs{RaggedRight}).
% \item[\texttt{R}] -- right aligned (\cs{ragged\dots caption} becomes
%                      \cs{RaggedLeft}).
% \item[\texttt{C}] -- centered (\cs{ragged\dots caption} becomes
%                      \cs{Centering}.
% \end{description}
% Without \pkg{ragged2e} the upper case letters are same like lower case
% letters, but additionally warn. Note: The implementation does also work, if
% \pkg*{scrlayer-scrpage} has defined \cs{LaTeXraggedright} etc.
%    \begin{macrocode}
  \def\reserved@a{#2}%
  \Ifstr{\reserved@a}{j}{%
    \expandafter\let\csname ragged#1caption\endcsname\@empty
  }{%
    \Ifstr{\reserved@a}{l}{%
      \scr@ifundefinedorrelax{LaTeXraggedright}{%
        \expandafter\let\csname ragged#1caption\endcsname\raggedright
      }{%
        \expandafter\let\csname ragged#1caption\endcsname\LaTeXraggedright
      }%
    }{%
      \Ifstr{\reserved@a}{r}{%
        \scr@ifundefinedorrelax{LaTeXraggedleft}{%
          \expandafter\let\csname ragged#1caption\endcsname\raggedleft
        }{%
          \expandafter\let\csname ragged#1caption\endcsname\LaTeXraggedleft
        }%
      }{%
        \Ifstr{\reserved@a}{c}{%
          \scr@ifundefinedorrelax{LaTeXcentering}{%
            \expandafter\let\csname ragged#1caption\endcsname\centering
          }{%
            \expandafter\let\csname ragged#1caption\endcsname\LaTeXcentering
          }%
        }{%
          \Ifstr{\reserved@a}{J}{%
            \scr@ifundefinedorrelax{justifying}{%
              \scr@caption@raggede@warning{J}{\justifying}%
              \expandafter\let\csname ragged#1caption\endcsname\@empty
            }{%
              \expandafter\let\csname ragged#1caption\endcsname\justifying
            }%
          }{%
            \Ifstr{\reserved@a}{L}{%
              \scr@ifundefinedorrelax{RaggedRight}{%
                \scr@caption@raggede@warning{L}{\RaggedRight}%
                \expandafter\let\csname ragged#1caption\endcsname\raggedright
              }{%
                \expandafter\let\csname ragged#1caption\endcsname\RaggedRight
              }%
            }{%
              \Ifstr{\reserved@a}{R}{%
                \scr@ifundefinedorrelax{RaggedLeft}{%
                  \scr@caption@raggede@warning{R}{\RaggedLeft}%
                  \expandafter\let\csname ragged#1caption\endcsname\raggedleft
                }{%
                  \expandafter\let\csname ragged#1caption\endcsname\RaggedLeft
                }%
              }{%
                \Ifstr{\reserved@a}{C}{%
                  \scr@ifundefinedorrelax{Centering}{%
                    \scr@caption@raggede@warning{C}{\Centering}%
                    \expandafter\let\csname ragged#1caption\endcsname\centering
                  }{%
                    \expandafter\let\csname ragged#1caption\endcsname\Centering
                  }%
                }{%
                  \Ifstr{\reserved@a}{}{%
                    \expandafter\let\csname ragged#1caption\endcsname\relax
                  }{%
                    \ClassError{\KOMAClassName}{unknown alignment char `#2'}{%
                      \string\setcaptionalignment\space supports
                      only:\MessageBreak 
                      \space\space c - centered captions,\MessageBreak
                      \space\space j - justified captions,\MessageBreak
                      \space\space l - left align captions,\MessageBreak
                      \space\space r - right aligned captions,\MessageBreak
                      \space\space C - centered captions with
                      `ragged2e',\MessageBreak 
                      \space\space J - justified captions with
                      `ragged2e',\MessageBreak 
                      \space\space L - left align captions with
                      `ragged2e',\MessageBreak 
                      \space\space R - right aligned captions with
                      `ragged2e',\MessageBreak 
                      or an empty argument to remove special
                      alignment.\MessageBreak 
                      If you'd continue, I'd not change the alignment.%
                    }%
                  }%
                }%
              }%
            }%
          }%
        }%
      }%
    }%
  }%
}
%    \end{macrocode}
% \begin{macro}{\scr@caption@raggede@warning}
% \changes{v3.25}{2017/11/15}{added}
% The warning used above.
%    \begin{macrocode}
\newcommand*{\scr@caption@raggede@warning}[2]{%
  \begingroup
    \lowercase{\def\reserved@a{#1}}%
    \ClassWarning{\KOMAClassName}{%
      `\string#2' undefined!\MessageBreak
      To avoid replacing caption alignment `#1' by `\reserved@a'\MessageBreak
      you should load package `ragged2e' before using\MessageBreak
      `\string\setcaptionalignment'%
    }%
  \endgroup
}
%    \end{macrocode}
% \begin{command}{\raggedcaption}
% \changes{v3.25}{2017/11/15}{added}
% The default alignment is standard alignment (empty means no change).
%    \begin{macrocode}
\newcommand*\raggedcaption{}
%    \end{macrocode}
% \end{command}^^A \raggedcaption
% \end{macro}^^A \scr@caption@raggede@warning
% \end{macro}^^A \@setcaptionalignment
% \end{command}^^A \setcaptionalignment
% \end{macro}^^A \scr@makemultilinecaption
% \end{macro}^^A \@@makecaption
% \end{macro}^^A \@makecaption
%
% \subsection{Special treatment of \texorpdfstring{\pkg*{longtable}}{`longtable'} captions}
%
% \begin{macro}{\LT@makecaption}
% \changes{v2.8j}{2001/07/30}{added}
% \changes{v2.8k}{2001/08/15}{do nothing if \pkg{caption2} has been loaded or
%   option \opt{origlongtable} has been used}
% \changes{v2.8q}{2001/11/18}{width and alignment by \KOMAScript{}}
% \changes{v2.8q}{2001/11/18}{using \cs{AfterPackage}}
% \changes{v2.9s}{2004/08/24}{vertical skips fixed by moving \cs{vskip}}
% \changes{v3.34}{2021/03/22}{special treatment of \pkg{caption2} removed}
% \begin{macro}{\LT@array,\LT@caption}
% \changes{v2.8q}{2001/11/18}{added}
% \begin{macro}{\scr@caption@before@longtable@warning}
% \changes{v2.98c}{2008/03/03}{added}
% The code for \pkg{longtable} has to be delayed until loading the package.
%    \begin{macrocode}
\newcommand*{\scr@caption@before@longtable@warning}[1]{%
  \ClassWarning{\KOMAClassName}{%
    you've loaded package `#1' before package\MessageBreak
    `longtable'!\MessageBreak
    Because of this package `#1' isn't able to\MessageBreak
    control `\string\caption' at longtables. \space After loading
    \MessageBreak 
    package `#1' KOMA-Script also doesn't control\MessageBreak
    `\string\caption'.\MessageBreak
    I think, you should load package `caption' after\MessageBreak
    package `longtable'%
  }%
}
\AfterPackage{longtable}{%
  \if@komalongtable
    \renewcommand{\LT@makecaption}[3]{%
      \noalign{%
        \if@captionabove
          \vskip\belowcaptionskip
        \else
          \vskip\abovecaptionskip
        \fi
      }%
      \LT@mcol\LT@cols c{%
        \hbox to\z@{\hss\parbox[t]\linewidth{%
%    \end{macrocode}
% \changes{v3.25}{2017/11/15}{\cs{@captype} set to \texttt{table}}
% To make \cs{raggedtablecaption} available, \cs{@captype} has to be defined.
%    \begin{macrocode}
            \def\@captype{table}%
            \@@makecaption{#1}{#2}{#3}%
            \endgraf
            \if@captionabove
              \vskip\abovecaptionskip
            \else
              \vskip\belowcaptionskip
            \fi
          }%
          \hss
        }%
      }%
    }%
    \newcommand*{\scr@LT@array}{}%
    \let\scr@LT@array=\LT@array
    \renewcommand*{\LT@array}{%
      \let\scr@caption=\LT@caption
      \def\captionabove{\noalign{\global\@captionabovetrue}%
        \scr@caption}%
      \def\captionbelow{\noalign{\global\@captionabovefalse}%
        \scr@caption}%
      \if@tablecaptionabove
        \let\LT@caption=\captionabove
      \else
        \let\LT@caption=\captionbelow
      \fi
      \scr@LT@array
    }%
    \ClassInfo{\KOMAClassName}{%
      longtable captions redefined%
    }%
  \fi
}
%    \end{macrocode}  
% \end{macro}^^A \scr@caption@before@longtable@warning
% \end{macro}^^A \LT@array,\LT@caption
% \end{macro}^^A \LT@makecaption
%
% \subsection{Special treatment of the \texorpdfstring{\pkg*{float}}{`float'} package}
%
% \begin{macro}{\fs@komaabove,\fs@komabelow,\floatc@komascript}
% \changes{v2.8j}{2001/07/30}{added}
% We define two float style for package \pkg{float}: \texttt{komaabove} and
% \texttt{komabelow}. However this is done independent of loading \pkg{float},
% because maybe someone else also uses those styles (but I don't think so).
% Note: Internal macros of \pkg{float} has to be used for the definitions.
%    \begin{macrocode}
\newcommand*{\fs@komaabove}{%
  \let\@fs@capt\floatc@komascript
  \let\@fs@pre\@empty
  \def\@fs@mid{\vskip\abovecaptionskip}%
  \let\@fs@post\@empty
  \let\@fs@iftopcapt\iftrue}
\newcommand*{\fs@komabelow}{%
  \let\@fs@capt\floatc@komascript
  \let\@fs@pre\@empty
  \def\@fs@mid{\vskip\abovecaptionskip}%
  \let\@fs@post\@empty
  \let\@fs@iftopcapt\iffalse}
\newcommand{\floatc@komascript}{\@@makecaption\@firstofone}
%    \end{macrocode}
% \end{macro}^^A \fs@komabove,\fs@komabelow,\floatc@komascript
%
%
% \subsection{Where to place floats}
%
% \begin{counter}{topnumber}
% \begin{command}{\topfraction}
% \begin{counter}{bottomnumber}
% \begin{command}{\bottomfraction}
% \begin{counter}{totalnumber}
% \begin{command}{\textfraction}
% \begin{command}{\floatpagefraction}
% \begin{counter}{dbltopnumber}
% \begin{command}{\dbltopfraction}
% \begin{command}{\dblfloatpagefraction}
% These are constants used by the \LaTeX{} kernel to decide where to place a
% float. See the kernel documentation for more information.
%    \begin{macrocode}
\setcounter{topnumber}{2}
\renewcommand*\topfraction{.7}
\setcounter{bottomnumber}{1}
\renewcommand*\bottomfraction{.3}
\setcounter{totalnumber}{3}
\renewcommand*\textfraction{.2}
\renewcommand*\floatpagefraction{.5}
\setcounter{dbltopnumber}{2}
\renewcommand*\dbltopfraction{.7}
\renewcommand*\dblfloatpagefraction{.5}
%    \end{macrocode}
% \end{command}
% \end{command}
% \end{counter}
% \end{command}
% \end{command}
% \end{counter}
% \end{command}
% \end{counter}
% \end{command}
% \end{counter}
%
%
% \subsection{Caption without float}
%
% \begin{command}{\captionof}
% \changes{v3.05}{2009/07/08}{added}
% \changes{v3.09}{2011/03/21}{using internal \cs{scr@caption}}
% \changes{v3.09a}{2011/04/13}{handling of
%   \opt{captions\quotechar=tableheading} and \opt{captions\quotechar=figureheading}}
% \begin{command}{\captionaboveof,\captionbelowof}
% \changes{v3.09}{2011/03/21}{added}
% We do not only provide a \cs{captionof} like \pkg{caption} or \pkg{capt-of}
% but also \cs{captionaboveof} and \cs{captionbelowof}. Users should not
% additionally use \pkg{capt-of}, but if they do, the definition of that
% package will be used instead (which is usually not, what the user want, but
% what they decided to do).
%    \begin{macrocode}
\newcommand*{\captionof}[1]{\def\@captype{#1}%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname if@#1captionabove\endcsname\iftrue
    \@captionabovetrue
  \fi
  \scr@caption}
\newcommand*{\captionaboveof}{\@captionabovetrue\captionof}
\newcommand*{\captionbelowof}{\@captionabovefalse\captionof}
\BeforePackage{capt-of}{\let\captionof\relax}
%    \end{macrocode}
% \end{command}^^A \captionaboveof,\captionbelowof
% \end{command}^^A \captionof
%
% \begin{environment}{captionofbeside}
% \changes{v3.10}{2011/09/02}{added}
% The analogue environment to \cs{captionbeside} to be used outside
% floats.
% \begin{description}
% \item[ToDo:] Wouldn't it be a good idea to test for already defined
% \cs{@captype} inside \env{captionbeside} and then expect an additional first
% argument \meta{float}? In this case user could simply us \env{captionbeside}
% the same way as \env{captionofbeside}.
% \end{description}
%    \begin{macrocode}
\newenvironment{captionofbeside}[1]{%
  \def\@captype{#1}%
  \captionbeside
}{%
  \endcaptionbeside
}
%    \end{macrocode}
% \end{environment}
%
%
% \subsection{Names}
%
% \begin{command}{\figurename,\tablename}
% \changes{v3.36}{2022/02/15}{explicit definition for English languages}
% The names to be used for the float labels.
%    \begin{macrocode}
\newcommand*\figurename{Figure}
\providecaptionname{american,australian,british,canadian,english,newzealand,%
  UKenglish,ukenglish,USenglish,usenglish}\figurename{Figure}
\newcommand*\tablename{Table}
\providecaptionname{american,australian,british,canadian,english,newzealand,%
  UKenglish,ukenglish,USenglish,usenglish}\tablename{Table}
%    \end{macrocode}
% \end{command}^^A \figurename,\tablename
%
%
% \subsection{Defining the \env{figure} environment}
%
% \begin{environment}{figure*,figure-,figure}
% \changes{v2.2c}{1995/05/25}{initial CJK support}
% \changes{v2.8h}{2001/07/19}{\cs{caption} is \cs{captionbelow}}
% \changes{v3.25}{2017/10/10}{re-implemented using \pkg*{tocbasic}}
% \changes{v3.36}{2022/02/22}{define additional non-float}
% \begin{counter}{figure}
% \changes{v3.25}{2017/10/10}{implicit by \cs{DeclareNewTOC}}
% \end{counter}
% We do the main job using \cs{DeclareNewTOC}:
%    \begin{macrocode}
\DeclareNewTOC[%
  type=figure,
  float,
  nonfloat,
%<book|report>  counterwithin=chapter,
%    \end{macrocode}
% \begin{macro}{\fps@figure}
% Default placement (by \cs{DeclareNewTOC}) \textbf{t}op, \textbf{b}ottom,
% \textbf{p}age.
%    \begin{macrocode}
  floatpos=tbp,
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ftype@figure}
% Numerical float type 1 (by \cs{DeclareNewTOC}).
%    \begin{macrocode}
  floattype=1,
%    \end{macrocode}
% \end{macro}
% \changes{v3.11c}{2013/03/01}{fix: one \cs{caption} change removed}
% \changes{v3.20}{2016/04/07}{internal redefinition of \cs{caption}}
%    \begin{macrocode}
  tocentryindent=1.5em,
  tocentrynumwidth=2.3em,
  atbegin=\def\caption{%
    \if@figurecaptionabove\expandafter\captionabove
    \else\expandafter\captionbelow\fi
  }
%    \end{macrocode}
% \begin{macro}{\ext@figure}
% Extension to be used (by \cs{DeclareNewTOC})
%    \begin{macrocode}
]{lof}
%    \end{macrocode}
% \end{macro}
% \begin{command}{\thefigure}
% \changes{v2.97e}{2007/11/23}{using chapter number in main-matter only}
% \changes{v3.27}{2019/06/26}{\cs{relax} replaced by percent}
% \changes{v3.35}{2021/10/12}{use chapter number only of greater than zero}
% \changes{v3.35}{2021/10/12}{redefine \cs{thefigure} only if compatibility is
%   less or equal 2.97d resp. less than 3.35}
%    \begin{macrocode}
%<*!v4>
%<*book|report>
\expandafter\ifnum\scr@v@is@le{2.97d}%
  \renewcommand*\thefigure{\thechapter.\@arabic\c@figure}
\fi
%</book|report>
%<*article>
\expandafter\ifnum\scr@v@is@lt{3.35}%
  \renewcommand*\thefigure{\@arabic\c@figure}
\fi
%</article>
%</!v4>  
%    \end{macrocode}
% \end{command}
% \begin{macro}{\fnum@figure}
% \begin{command}{\figureformat}
% \changes{v2.3c}{1995/08/06}{added}
% The print format of the number (by \cs{DeclareNewTOC}).
% \end{command}
% \end{macro}
% \end{environment}
%
%
% \subsection{Defining the \env{table} environment}
%
% Note: This is almost the same as defining the \env{figure} environment. So
% read the previous section first.
%
% \begin{environment}{table*,table-,table}
% \changes{v2.2c}{1995/05/25}{initial CJK support}
% \changes{v2.8h}{2001/07/19}{\cs{caption} is \cs{captionbelow}}
% \changes{v3.25}{2017/10/10}{re-implemented using \pkg*{tocbasic}}
% \changes{v3.36}{2022/02/22}{define additional non-float}
% \begin{counter}{table}
% \changes{v3.25}{2017/10/10}{implicit by \cs{DeclareNewTOC}}
% \end{counter}
% We do the main job using \cs{DeclareNewTOC}:
%    \begin{macrocode}
\DeclareNewTOC[%
  type=table,
  float,
  nonfloat,
%<book|report>  counterwithin=chapter,
%    \end{macrocode}
% \begin{macro}{\fps@table}
% Default placement (by \cs{DeclareNewTOC}) \textbf{t}op, \textbf{b}ottom,
% \textbf{p}age.
%    \begin{macrocode}
  floatpos=tbp,
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ftype@table}
% Numerical float type 2 (by \cs{DeclareNewTOC}).
%    \begin{macrocode}
  floattype=2,
%    \end{macrocode}
% \end{macro}
% \changes{v3.20}{2016/04/07}{internal redefinition of \cs{caption}}
%    \begin{macrocode}
  tocentryindent=1.5em,
  tocentrynumwidth=2.3em,
  atbegin=\def\caption{%
    \if@tablecaptionabove\expandafter\captionabove
    \else\expandafter\captionbelow\fi
  }
%    \end{macrocode}
% \begin{macro}{\ext@table}
% Extension to be used (by \cs{DeclareNewTOC})
%    \begin{macrocode}
]{lot}
%    \end{macrocode}
% \end{macro}
% \begin{command}{\thetable}
% \changes{v2.97e}{2007/11/23}{using chapter number in main-matter only}
% \changes{v3.27}{2019/06/26}{\cs{relax} replaced by percent}
% \changes{v3.35}{2021/10/12}{use chapter number only of greater than zero}
% \changes{v3.35}{2021/10/12}{redefine \cs{thetable} only if compatibility is
%   less or equal 2.97d resp. less than 3.35}
%    \begin{macrocode}
%<*!v4>
%<*book|report>
\expandafter\ifnum\scr@v@is@le{2.97d}%
  \renewcommand*\thetable{\thechapter.\@arabic\c@table}
\fi
%</book|report>
%<*article>
\expandafter\ifnum\scr@v@is@lt{3.35}%
  \renewcommand*\thetable{\@arabic\c@table}
\fi
%</article>
%</!v4>
%</body>
%    \end{macrocode}
% \end{command}
% \begin{macro}{\fnum@table}
% \begin{command}{\tableformat}
% \changes{v2.3c}{1995/08/06}{added}
% The print format of the number (by \cs{DeclareNewTOC}).
% \end{command}
% \end{macro}
% \end{environment}
%
%    \begin{macrocode}
%</class&!letter>
%    \end{macrocode}
% 
% \Finale
% \PrintChanges
% 
\endinput
% Local Variables:
% mode: doctex
% ispell-local-dictionary: "en_US"
% eval: (flyspell-mode 1)
% TeX-master: t
% TeX-engine: luatex-dev
% eval: (setcar (or (cl-member "Index" (setq-local TeX-command-list (copy-alist TeX-command-list)) :key #'car :test #'string-equal) (setq-local TeX-command-list (cons nil TeX-command-list))) '("Index" "mkindex %s" TeX-run-index nil t :help "makeindex for dtx"))
% End: