summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/ncctools/nccsect.dtx
blob: 980915c91a0ea01df795c2dfacf1c26bbc847542 (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
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
% \iffalse
%%
%% File: nccsect.dtx Copyright (C) 2002--2005 by Alexander I. Rozhenko
%%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{nccsect}
%<package>         [2005/06/15 v1.3 Extended Section, Caption, and TOC Handling (NCC)]
%
% \changes{v1.00}{2002/02/01}{This version is uploaded to CTAN}
% \changes{v1.01}{2002/02/08}{\NCC@thetocchapter hook added}
% \changes{v1.02}{2002/02/13}{Bug in using the \nosectiontag fixed}
% \changes{v1.02}{2002/03/19}{Test for caption with empty text added}
% \changes{v1.03}{2002/05/19}{Vskips in captions after style changes now}
% \changes{v1.04}{2002/05/22}{Centering in captions now works}
% \changes{v1.1}{2004/12/12}{Introduce |\NCC@sec@reset@controls|}
% \changes{v1.1}{2004/12/12}{Simplify making sections. The |\NCC@makesection| now
%                            incompatible with previous version!!!}
% \changes{v1.1}{2004/12/12}{Revised version: many internal changes}
% \changes{v1.1}{2004/12/12}{Documentation was prepared}
% \changes{v1.2}{2005/04/15}{Emulate |\@makecaption| for compatibility}
% \changes{v1.2}{2005/04/15}{Compatibility with the supertabular package added}
% \changes{v1.2}{2005/04/15}{Compatibility with the longtable package added}
% \changes{v1.2}{2005/05/20}{Introduce |\beforechapter| hook}
% \changes{v1.2}{2005/05/20}{Add |\StartHromTextArea| and |\StartFromHeaderArea|}
% \changes{v1.2}{2005/05/21}{Add |\epigraph| and |\epigraphparameters|}
% \changes{v1.2}{2005/05/22}{Add |\captionstyle| and related staff}
% \changes{v1.2}{2005/05/22}{Add |\TOCMarginDrift|}
% \changes{v1.2}{2005/05/22}{Add |\applystyle| command to TOC Entry style}
% \changes{v1.2}{2005/06/08}{Set |\@twocolumnfalse| in before-chapter hook}
% \changes{v1.2}{2005/06/08}{Allow sectioning in |\beforechapter| hook}
% \changes{v1.3}{2005/06/15}{Fixed bug with using |\applystyle| command}
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{nccsect,nccboxes,desclist}
\GetFileInfo{nccsect.sty}
\begin{document}
\title{The \textsf{nccsect} package\thanks{This file
        has version number \fileversion, last
        revised \filedate.}}
\author{Alexander I. Rozhenko\\rozhenko@oapmg.sscc.ru}
\date{\filedate}
\maketitle
\DocInput{nccsect.dtx}
\end{document}
%</driver>
% \fi
%
% \section{The Scope and Objectives}
%
% The package changes the implementation of sections, captions,
% and toc-entries in the \LaTeX\ kernel. The reasons for the changes
% are concerned with the following disadvantages of the
% standard \LaTeX\ implementation:
%
% \paragraph{1} Standard \LaTeX\ sectioning commands can prepare
% display sections in the single style: justified paragraph
% with hand indented number. To change this style to another
% one (centered, par-indented, or else), you need
% to re-implement the internal |\@sect| command. It is no
% control for this style on user's level.
%
% \paragraph{2} If you want to customize the presentation a number in
% a section (for example, put a paragraph mark \S\ before a number
% or put a point after a number), you at least need to
% re-implement the |\@sect| command.
%
% \paragraph{3} The sectioning commands provide no straightforward
% control for running headings. The marking commands
% like the |\sectionmark| solve this problem partially.
% Using them within parameter of sectioning command,
% you can change the mark properly, but this solution does not work in
% complicated documents which use first and last marks
% appearing on a page. The safe solution consists in direct
% replacement a mark prepared within the |\@sect| command
% to a custom mark.
%
% \paragraph{4} Special efforts are required to pass a section
% without number to the header and to the toc-list. There is no simple
% solution providing this action.
%
% \paragraph{5} Captions for tables and figures are prepared in
% just the same way, although, they are usually used in different
% places of floating environments: table captions start
% \textit{before\/} a table, but figure captions go \textit{after\/}
% a figure. So, the vertical skip inserted before a caption is
% unnecessary for table captions. The right solution is to design
% captions for different float types in different ways.
%
% \paragraph{6} The star-form of captions is absent. It is useful
% when a document contains an alone figure or table. Moreover,
% in fiction books, unnumbered captions useful.
%
% \paragraph{7} The design of toc-entries is hard for modifications.
% It is much better to calculate the skips in toc-entries on the
% base of prototyping technique instead of hard-coding them
% with absolute values. Moreover, the skips for nested sections
% must depend on of higher level skips. For example, if we
% change skips for a section entry, the skips for subsection entries
% should be adjusted automatically.
%
% \bigskip
% The package eliminates above-mention disadvantages of the standard
% \LaTeX\ implementation. The commands implemented in it are divided
% into two levels: user level and design level. The user-level commands
% are intended for use within a document and the design-level commands
% are directed to class and package writers.
%
% \section{User Interface}
%
% The table below shows sectioning commands provided with standard
% \LaTeX\ classes. Every section has a \textit{level\/} (an integer
% number). Sections can be printed in one of two modes:
% \textit{display\/} or \textit{run-in\/} mode. Display section is
% prepared as a separate justified paragraph having a hand indent if a
% section has a number. Run-in section starts a paragraph.
% \begin{center}\catcode`|=12
% \small\tabcolsep=10pt
% \renewcommand\cboxstyle{\footnotesize}
% \begin{tabular}{|l|c|c|}\hline
% \hfill\cbox{Command}\hfill\mbox{} &
% \hfill\cbox{Level}\hfill\mbox{} &
% \hfill\cbox{Mode}\hfill\mbox{}\\\hline
% \Strut/.8/
% \cs{part} & $-$1 or 0\footnotemark & display \\
% \cs{chapter} & 0\footnotemark & display \\
% \cs{section} & 1 & display \\
% \cs{subsection} & 2 & display \\
% \cs{subsubsection} & 3 & display \\
% \cs{paragraph} & 4 & run-in \\
% \cs{subparagraph} & 5 & run-in \\
% \hline
% \end{tabular}\footnotetext[1]{The \cs{part} command has zero level
% in article-like classes and has the negative level in book-like
% classes. In book-like classes a part is prepared on
% a separate page.}\footnotetext{The \cs{chapter} command is defined
% in book-like classes only.}
% \end{center}
%
% \DescribeMacro\startsection
% The package redefines all standard sectioning commands except
% the |\part| command in the book-like class. Along with the
% commands shown in the table above, you can use the following
% uniform notations:
% \begin{quote}
% |\startsection|\marg{level}\oarg{toc-entry}\marg{title}\quad or\\
% |\startsection|\marg{level}|*|\marg{title}
% \end{quote}
% The \meta{level} is a level of section. The first command
% produces a numbered section (if~the numbering depth allows this)
% and the last one produces a section without number.
% As for the standard \LaTeX\ sectioning, the first variant of
% the |\startsection| command additionally passes their arguments
% to the section mark command (if the mark command exists)
% and to the aux-file.
% The last variant does no additional actions.
%
% \bigskip
% \textbf{NOTE}: The package allows declaring additional section
% levels. They, of course, have no predefined alias names as
% standard section levels.
%
% \bigskip
% \DescribeMacro\sectionstyle
% The |\sectionstyle|\marg{style} command allows change
% a style of subsequent display sections. The following styles
% are predefined:
% \begin{desclist}{\tt}{ \rm\hfill---}[hangindent*]\itemsep=0mm
% \item[hangindent]  standard LaTeX style (default).
% \item[hangindent*] the same as |hangindent|, but ragged right.
% \item[parindent]  section titles are indented on |\parindent|.
% \item[parindent*] the same as |parindent|, but ragged right.
% \item[center] section titles are centered.
% \end{desclist}
% You can apply the |\sectionstyle| so many times in the document
% as you want. This command complies with standard \LaTeX\ scoping
% rules.
%
% \DescribeMacro\indentaftersection
% \DescribeMacro\noindentaftersection
% The paragraph indentation after a display section is controlled with
% the |\indentaftersection| and |\noindentaftersection| commands.
% The first one allows and the last one suppresses
% indentation after section. The commands act on the subsequent
% display sections in the scope of their use.
%
% The customization of a number tag and running head of a concrete
% section is provided with so-call \textit{modifiers}. A modifier
% is a command acting on the nearest sectioning command going after it.
% Usually, the modifiers are placed just before a sectioning command.
% All modifiers act with non-starred versions of sections.
% If the next sectioning command is starred, modifiers are ignored.
%
% \DescribeMacro\norunninghead
% The |\norunninghead| command suppresses generation of running head for the
% next non-starred section, i.e.\ it skips the call of section mark command
% in the next section.
%
% \DescribeMacro\runninghead
% The |\runninghead|\marg{running-title} command overrides a text going to the
% running head when a new non-starred section starts and an appropriate\linebreak
% |\pagestyle| is in use. This command has higher priority
% than the |\norunninghead|.
%
% \DescribeMacro\noheadingtag
% The |\noheadingtag| command suppresses a number tag in the next section,
% but all other attendant actions are executed (writing to the aux-file and
% updating the running head).
%
% \DescribeMacro\headingtag
% The |\headingtag|\marg{tag} command overrides a number tag in the next
% section. It has the higher priority than |\noheadingtag|. Overridden
% section tag can be referred with the |\label| command.
% All fragile commands in the overridden tag should be protected.
%
% \DescribeMacro{\headingtag*}
% The |\headingtag*|\marg{tag} command prepares a number tag as is, ignoring
% the tag style, prefix, and suffix. The aux-file and running head are not
% updated in this case.
%
% \DescribeMacro\skipwritingtoaux
% The |\skipwritingtoaux| suppresses writing to aux-file for the next section
% command.
%
% \bigskip
% \textbf{NOTE}: All modifiers use global settings.
%
% \bigskip
% \DescribeMacro\caption
% \DescribeMacro{\caption*}
% The captions are implemented in this package using the same technique as
% the sectioning commands. There are two versions of caption command
% allowed within floating environments:
% \begin{quote}
% |\caption|\oarg{toc-entry}\marg{title}\quad and\\
% |\caption*|\marg{title}
% \end{quote}
% The first one works in the same manner as the standard \LaTeX\ |\caption|
% command. Its star-version prepares a caption without number and preceding
% words `Figure' or `Table'.
%
% You can use line breaking commands in captions. But in this case,
% you need to set the optional \meta{toc-entry} parameter to avoid
% translation errors.
%
% \DescribeMacro\captionstyle
% \DescribeMacro\captiontagstyle
% \DescribeMacro\captionwidth
% Caption appearance can be customized. You can customize ether all caption
% types or only selected caption type. The following commands do this:
% \begin{quote}
% |\captionstyle|\oarg{type}\marg{style}\\
% |\captiontagstyle|\oarg{type}\marg{style}\\
% |\captionwidth|\oarg{type}\marg{length}
% \end{quote}
% If |type| is omitted, these commands are applied to all types (out of floats)
% or to the current type (inside a float). If both typed and non-typed
% cases are specified for a float type, typed case has a
% precedence before non-typed one. The |\captionstyle| specifies a style
% the caption text will be formatted:
% \begin{desclist}{\tt}{}[centerlast]
% \item[default] standard \LaTeX's style,
% \item[para] simple paragraph,
% \item[left] all lines are flushed left,
% \item[center] all lines are centered,
% \item[right] all lines are flushed right, or
% \item[centerlast] as |para|, but the last line is centered.
% \end{desclist}
% The |\captiontagstyle| specifies a position of caption tag:
% \begin{desclist}{\tt}{}[centerlast]
% \item[para] tag is formatted together with text;
% \item[left] tag is adjusted to the left in a separate line;
% \item[center] tag is centered in a separate line; or
% \item[right] tag is adjusted to the right in a separate line.
% \end{desclist}
% The |\captionwidth| specifies a width of caption. Defaults:
% \begin{quote}
% |\captionstyle{default}|\\
% |\captiontagstyle{para}|\\
% |\captionwidth{\linewidth}|
% \end{quote}
%
% \bigskip
% \textbf{NOTE}: The above-described section modifiers can be used with non-starred
% captions. Although, the |\runninghead| and |\norunninghead| commands
% have no sense with captions, but you can do them working if define
% a |\figuremark| or |\tablemark| command.
%
% \section{Declare Sections and Captions}
%
% \DescribeMacro\DeclareSection
% To define or redefine a section or caption command, you can use
% in the preamble of your document the
% following command:
% \begin{quote}
% |\DeclareSection|\marg{level}\marg{type}\oarg{indent}\marg{prefix}\\
% |               |\marg{beforeskip}\marg{afterskip}\marg{style}
% \end{quote}
% \begin{desclist}{}{}[\meta{beforeskip}]
% \item[\meta{level}] a section level number. Zero and negative values
%      are interpreted as follows:
%      0 means declaring the |\chapter| or |\part| command depending on a
%        class used; a negative value means declaring a caption.
%
% \item[\meta{type}] a section type. For zero level, this
%      parameter is ignored. For negative level, it defines a float type
%      (i.e., |figure| or |table|). For positive level, it defines
%      a counter name. The name of marking command is composed from
%      the type as |\|\meta{type}|mark|.
%
% \item[\meta{indent}] indentation of heading from the left margin
%      (zero is default). Ignored for negative levels.
%
% \item[\meta{prefix}] a prefix inserted before a section-number tag
%      (usually empty). In chapter, part, or caption declaration commands,
%      it is inserted right before the tag name, e.g., before the |\@chapapp|,
%      |\partname|, |\figurename|, or |\tablename| command.
%
% \item[\meta{beforeskip}] the skip to leave above the heading.
%
% \item[\meta{afterskip}] if positive, then the skip to leave below
%      the heading, else negative of skip to leave to right of run-in
%      heading. The negative value is allowed for positive section levels
%      only.
%
% \item[\meta{style}] commands to set a style. The last command in
%      this argument may be a command such as |\MakeUppercase| that
%      takes an argument. The section heading will be supplied as the
%      argument to this command. So setting it to, say,
%      |\bfseries\MakeUppercase| would produce bold, uppercase headings.
% \end{desclist}
% Sections having nonnegative \meta{level} and positive \meta{afterskip}
% are display sections. They are declared with the |hangindent| style
% and do not obey the |\sectionstyle| command.
%
% \DescribeMacro{\DeclareSection*}
% To declare a display section having dynamic alignment controlled with the
% |\sectionstyle| command, use the star-version of the previous command:
% \begin{quote}
% |\DeclareSection*|\marg{level}\marg{type}\marg{prefix}\\
% |                |\marg{beforeskip}\marg{afterskip}\marg{style}
% \end{quote}
% A negative \meta{afterskip} has no meaning in this case.
%
% \DescribeMacro\bff
% To prepare bold section headings,
% you can use the |\bff| command in the \meta{style} parameter.
% It tries to set everything bold. Its definition is the following:
% \begin{quote}
% |\newcommand{\bff}{\normalfont\bfseries\mathversion{bold}}|
% \end{quote}
%
% Examples of section and caption declarations:
% \begin{quote}
% |\DeclareSection{-2}{table}{}{0pt}{10pt}{}|\\
% |\DeclareSection{-1}{figure}{}{10pt}{0pt}{}|\\
% |\DeclareSection*{1}{section}{}%|\\
% |                {3.5ex plus 1ex minus .2ex}%|\\
% |                {2.3ex plus .2ex}{\Large\bff}|
% \end{quote}
% Here we declare the table caption command with zero skip
% before it and |10pt| skip after it. On contrary, the
% figure caption command produced |10pt| skip before it
% and zero skip after it. The |\section| command is declared with
% dynamic horizontal alignment. It is prepared in the |\Large|
% font with everything bold.
%
% \DescribeMacro\SectionTagSuffix
% The |\SectionTagSuffix|\marg{suffix} command specifies a suffix
% inserted after a section number tag. For example, the command
% \begin{quote}
% |\SectionTagSuffix{.\quad}|
% \end{quote}
% sets the decimal point after every section number tag.
% Sections of 0th level ignore this suffix. The default tag is |\quad|.
% The command can be used in the preamble only.
%
% \DescribeMacro\CaptionTagSuffix
% The |\CaptionTagSuffix|\marg{suffix} command specifies a suffix
% inserted after a caption number tag. It can be used in the preamble only.
% The default caption tag is:
% \begin{quote}
% |\CaptionTagSuffix{:\hskip .7em plus .2em minus .1em}|
% \end{quote}
%
% \section{Declare TOC-Entries}
%
% \DescribeMacro\DeclareTOCEntry
% To declare an entry of table of contents or other lists
% (list of figures or list of tables), use the following command
% (in the preamble only):
% \begin{quote}
% |\DeclareTOCEntry|\marg{level}\marg{action}\marg{prefix}\marg{prototype}\\
% |                |\marg{style}\oarg{next}
% \end{quote}
% \begin{desclist}{}{\hfill}[\meta{prototype}]
% \item[\meta{level}] a section level number.
%      For zero and negative level the following commands are created:
%      0 means |\l@chapter| or |\l@part| depending on class used;
%      $-1$ means |\l@figure|; $-2$ means |\l@table|. If level
%      is greater than 5, the name of toc-entry command is
%      generated as |\l@section@|\meta{level-in-roman},
%      i.e., the 6th level toc-entry is |\l@section@vi|.
%
% \item[\meta{action}] commands applied before entry is produced (usually empty).
%
% \item[\meta{prefix}] text inserted before the section number (usually empty).
%
% \item[\meta{prototype}] prototype of number for alignment the toc-entry body.
%      The hang indent of this toc-entry will be equal to the width of
%      \begin{quote}
%      \meta{prefix}\meta{prototype}\meta{numberline-suffix}.
%      \end{quote}
%
% \item[\meta{style}] commands to set a style. The last command in this argument
%      may be a command such as |\MakeUppercase| that takes an
%      argument. The produced entry will be supplied as the
%      argument to this command. So setting it to, say,
%      |\bfseries\MakeUppercase| would produce bold,
%      uppercase entry. This style is applied to the number also.
%      To apply different styles to the text of entry and to its page
%      number, use in this parameter the command
%      \begin{quote}
%      |\applystyle|\marg{text-style}\marg{number-style}
%      \end{quote}
%
% \item[\meta{next}] prototype for left margin adjustment for an entry of the
%      next level. Default is the hang indent of the current toc-entry.
% \end{desclist}
% A toc-entry is produced within a group.
%
% \DescribeMacro\NumberlineSuffix
% The |\NumberlineSuffix|\marg{calc-suffix}\marg{actual-suffix}
% command allows customize a skip inserted after
% numbers in TOC-like entries. The \meta{calc-suffix} parameter
% is used in calculations of hang indent of toc-entries and the
% \meta{actual-suffix} is really inserted at the end of number.
% The \marg{calc-suffix} is usually wider than the \meta{actual-suffix}.
% The default is |\NumberlineSuffix{\quad}{\enskip}|.
% This command is available in the preamble only.
%
% \DescribeMacro\PnumPrototype
% The |\PnumPrototype|\marg{prototype} command is used for adjustment
% the right margin of the text of toc-entries in toc-lists.
% Default is |\PnumPrototype{99}|.
% If your document has more than 99 pages, use
% |\PnumPrototype{999}|.
% This command is available in the preamble only.
%
% \DescribeMacro\TOCMarginDrift
% The |\TOCMarginDrift|\marg{increment} command specifies a value of
% right-margin drift in TOCs. The increment is applied after the |\@plus|
% token in definition of right margin. Empty argument means no drift.
% Examples:
% \begin{quote}
% |\TOCMarginDrift{2em}|\\
% |\TOCMarginDrift{1fil}|
% \end{quote}
% The command can be use anywhere in the document.
%
% \DescribeMacro\runinsectionskip
% This command is useful in the \meta{action} parameter of the
% toc-entry declaration to produce the skip before a toc-entry
% equal to the skip before run-in sections.
%
% The following example shows how toc-entries are declared in books:
% \begin{quote}
% |\DeclareTOCEntry{-2}{}{}{9.9}{}% table|\\
% |\DeclareTOCEntry{-1}{}{}{9.9}{}% figure|\\
% |\DeclareTOCEntry{0}{\runinsectionskip\def\@dotsep{1000}%|\\
% |  \aftergroup\penalty\aftergroup\@highpenalty}{}{9}{\bff}% chapter|\\
% |\DeclareTOCEntry{1}{}{}{9.9}{}[9.9]% section|\\
% |\DeclareTOCEntry{2}{}{}{9.9.9}{}[9.9.9]% subsection|\\
% |\DeclareTOCEntry{3}{}{}{}{}[\qquad]% subsubsection|
% \end{quote}
% The number prototype for figures and tables is `9.9' here.
% The |\l@chapter| entry applies the run-in section skip before it and
% redefines the |\@dotsep| command to remove dot leaders.
% Using the |\aftergroup| command, it inserts the |\@highpenalty|
% after this toc-entry to avoid a page break at this point.
% The left margin adjustment after section and nested toc-entries
% is calculated here using the prototype of widest section number.
% This produces the following nesting:
% \begin{flushleft}
% {\bf 1\quad Chapter}\\
% \jhbox{{\bf 1\quad}}{}1.1\quad Section\\
% \jhbox{{\bf 1\quad}1.1}{}1.1.1\quad Subsection\\
% \jhbox{{\bf 1\quad}1.11.1.1}{}Subsubsection
% \end{flushleft}
%
% \section{Declare New Float Types}
%
% The standard \LaTeX\ classes provide two types of floating environments:
% figures and tables. If you have prepared a new floating
% environment in some way (i.e., using the |float| package by Anselm
% Lingnau), you can declare a caption for the new float
% with the commands described in previous sections.
%
% \DescribeMacro\RegisterFloatType
% In books, when a new chapter starts, the |\chapter| command
% puts a special vertical skip to the contents of list of figures and
% of list of tables. This behaviour can be easy extended to new float types
% if you register them within this package. The registration is
% provided with the following command:
% \begin{quote}
% |\RegisterFloatType|\marg{float-type}
% \end{quote}
% After the float type is registered, you can declare a toc-entry
% for it using the negation of its registration number in the
% \meta{level} parameter. The
% first new float type is registered third (after the figure and table).
% So, you must
% use \meta{level} = $-3$ for it, $-4$ for the next registered float
% type and so on.
%
% In the following example, we define a new float type, |program|,
% and prepare the caption and toc-entry commands for it.
% The caption of programs
% is supposed to be used at the beginning of program.
% So, we make it in the same manner as the table caption.
% \begin{quote}
% |\documentclass{book}|\\
% |\usepackage{float,nccsect}|\\
% |\newfloat{program}{tp}{lop}[chapter]|\\
% |\floatname{program}{Program}|\\
% |\RegisterFloatType{program}|\\
% |\DeclareSection{-3}{program}{}{0pt}{10pt}{}|\\
% |\DeclareTOCEntry{-3}{}{}{9.9}{}|
% \end{quote}
%
% To produce a list of programs, you can then use the |\listof|
% command from the |float| package as follows:
% \begin{quote}
% |\listof{program}{List of Programs}|
% \end{quote}
% \StopEventually{}
%
% \section{Epigraphs and Related Staff}
%
% \DescribeMacro\beforechapter
% \DescribeMacro\epigraph
% To put epigraph before any chapter, you can use two methods:
% low-level |\beforechapter|\marg{anything} hook or
% user-level command
% \begin{quote}
% |\epigraph|\oarg{width}\marg{text}\marg{author}
% \end{quote}
% The last one applies a special formatting to epigraph and
% calls the first one. The |\beforechapter| hook inserts its
% contents at the beginning of page just before a chapter
% instead of spacing specified in the chapter declaration.
%
% \DescribeMacro\epigraphparameters
% Formatting of user-level epigraph is provided with the
% following command
% \begin{quote}
% |\epigraphparameters|\marg{style}\marg{width}\marg{height}\marg{author-style}\\
% |                   |\marg{after-action}
% \end{quote}
% Here \meta{style} is a style applied to the whole epigraph
% (font selection, spacing and positioning, etc.), the \meta{width}
% is the default epigraph width (can be changed in an epigraph),
% the \meta{author-style} is the style applied to the author's
% signature, and the \meta{after-action} is an action applied after
% the epigraph (usually a vertical spacing). All styles and actions
% are applied in the vertical mode. An \meta{author-style} can finish with
% one-argument macro getting the author of epigraph and formatting it.
%
% \DescribeMacro\epigraphwidth
% In |\epigraphparameters|, you can use the |\epigraphwidth| macro
% which contains a selected epigraph width.
%
% The default style is:
% \begin{quote}
% |\epigraphparameters{\StartFromHeaderArea\small\raggedleft}|\\
% |                   {.45\linewidth}{5\baselineskip}|\\
% |                   {\raggedleft\itshape}{\vspace{2ex}}|
% \end{quote}
%
% \DescribeMacro\StartFromTextArea
% The |\vspace*| command applied at the beginning of page has one serious
% disadvantage: it skips more space that specified in its parameter.
% To remove this disadvantage, we introduce the |\StartFromTextArea|
% command that
% inserts a zero-height strut and allows use the |\vspace| command after it
% without troubles.
%
% \DescribeMacro\StartFromHeaderArea
% You can also extend the text area on the header if apply the
% |\StartFromHeaderArea| command at the beginning of page.
% Such action is useful in epigraphs: the first chapter's page usually
% has an empty header and positioning an epigraph from the header
% is the good practice.
%
% \section{The Implementation}
%
% \begin{macro}{\NCC@secskip}
% \begin{macro}{\NCC@runskip}
% The package shares the following commands with the
% |nccthm| package:
% \begin{quote}
% |\NCC@secskip|\marg{skip} adds the \meta{skip} before a section,\\
% |\NCC@runskip| is a skip inserted before run-in sections.
% \end{quote}
% We protect the definitions of these commands with testing
% the |nccthm| package to be already loaded.
%    \begin{macrocode}
%<*package>
\@ifpackageloaded{nccthm}{}{%
  \def\NCC@secskip#1{%
    \if@noskipsec \leavevmode \fi \par
    \if@nobreak \everypar{}\else
      \addpenalty\@secpenalty
      \addvspace{#1}%
    \fi
  }
  \def\NCC@runskip{2.75ex \@plus 1ex \@minus .2ex}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\runinsectionskip}
% This command is useful in toc-entries:
%    \begin{macrocode}
\newcommand{\runinsectionskip}{\NCC@secskip{\NCC@runskip}}
%    \end{macrocode}
% \end{macro}
%
% \subsection{The Kernel}
%
% We start with declaring the section controls (modifiers):
% \begin{desclist}{\tt}{\hfill}[NCC@nosecmark]\raggedright
% \item[NCC@nosectag] is true if |\noheadingtag| is applied;
% \item[NCC@secstartag] is true if |\headingtag*|\marg{tag} is applied;
% \item[\cs{NCC@sectag}] saves a value of the |\headingtag| parameter;
% \item[NCC@nosecmark] is true if |\norunninghead| is applied;
% \item[\cs{NCC@secmark}\rm\marg{mark-command}] executes the \meta{mark-command}
% with the parameter of |\runninghead| command;
% \item[NCC@noaux] is true if |\skipwritingtoaux| is applied.
% \end{desclist}
%    \begin{macrocode}
\newif\ifNCC@nosectag
\newif\ifNCC@secstartag
\newif\ifNCC@nosecmark
\newif\ifNCC@noaux
%    \end{macrocode}
%
% \begin{macro}{\NCC@global}
% We reset all controls globally, but in the |\beforechapter|
% hook we need to reset them locally. So, we reset all controls
% using the |\NCC@global| modifier which value is |\global| by default.
%    \begin{macrocode}
\let\NCC@global\global
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@sec@reset@controls}
% This command resets all controls to default values.
% It must be applied at the end of every section command.
%    \begin{macrocode}
\def\NCC@sec@reset@controls{%
  \NCC@global\NCC@nosectagfalse
  \NCC@global\NCC@secstartagfalse
  \NCC@global\let\NCC@sectag\relax
  \NCC@global\NCC@nosecmarkfalse
  \NCC@global\let\NCC@secmark\relax
  \NCC@global\NCC@noauxfalse
}
\NCC@sec@reset@controls
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\norunninghead}
% \begin{macro}{\runninghead}
% \begin{macro}{\noheadingtag}
% \begin{macro}{\headingtag}
% \begin{macro}{\headingtag*}
% \begin{macro}{\skipwritingtoaux}
% User interface to section controls:
%    \begin{macrocode}
\newcommand{\norunninghead}{\NCC@global\NCC@nosecmarktrue}
\newcommand*{\runninghead}[1]{\NCC@global\def\NCC@secmark##1{##1{#1}}}
\newcommand{\noheadingtag}{\NCC@global\NCC@nosectagtrue}
\newcommand{\headingtag}{%
  \@ifstar{\NCC@global\NCC@secstartagtrue\NCC@setsectag}{\NCC@setsectag}%
}
\def\NCC@setsectag#1{\NCC@global\def\NCC@sectag{#1}}
\newcommand{\skipwritingtoaux}{\NCC@global\NCC@noauxtrue}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NCC@makesection}
% The |\NCC@makesection|\marg{type}\marg{level}\marg{toc-entry}\marg{toc-action}
% produces a section or caption. It analyzes the modifiers and customizes
% sections or captions. The \meta{toc-action} parameter contains an
% attendant action that must be applied at the end of macro.
% It writes a toc-entry to aux-file.
%
% The command uses the following hooks that must be prepared
% before its call:
% \begin{desclist}{}{}[\cs{NCC@make}\marg{action}]
% \item[\cs{NCC@makesectag}\marg{value}] produces a tag using the
%      given value;
%
% \item[\cs{NCC@make}\marg{action}] makes a section or caption heading
%      and applies the \meta{action} after heading. Before the call
%      of this command, the |\@svsec| macro is prepared (it contains a
%      prepared tag).
% \end{desclist}
% We start from the case when the |\headingtag*|\marg{tag} modifier was
% applied and the section tag was saved in the |\NCC@sectag| macro.
% We apply the |\NCC@make| procedure with the given section tag.
% Attendant actions are ignored for this case.
%    \begin{macrocode}
\def\NCC@makesection#1#2#3#4{%
  \ifNCC@secstartag
    \let\@svsec\NCC@sectag
    \NCC@make{}%
  \else
%    \end{macrocode}
% Prepare a tag creation command in the |\the|\meta{type} macro.
% We can do some temporary changes here that will be restored
% at the end of macro. The restore hook is prepared in the
% |\NCC@restsec| command.
%    \begin{macrocode}
    \ifx\NCC@sectag\relax
%    \end{macrocode}
% The |\noheadingtag| case: we temporary set the |secnumdepth|
% counter to very low negative value. This prevents numbering
% this section:
%    \begin{macrocode}
      \ifNCC@nosectag
        \edef\NCC@restsec{%
          \noexpand\c@secnumdepth \the\c@secnumdepth\relax
        }%
        \c@secnumdepth -1000
%    \end{macrocode}
% The ordinary case: No restore actions is necessary here.
%    \begin{macrocode}
      \else
        \let\NCC@restsec\relax
        \ifnum#2>\c@secnumdepth \else\refstepcounter{#1}\fi
      \fi
%    \end{macrocode}
% The |\headingtag|\marg{tag} case: we temporary let the
% |\the|\meta{type} macro to be equal to the |\NCC@sectag|
% command produced by the |\headingtag|,
% save the original value in the |\NCC@thesec| command,
% and prepare the |\NCC@restsec| macro.
%    \begin{macrocode}
    \else
      \expandafter\let\expandafter\NCC@thesec\csname the#1\endcsname
      \def\NCC@restsec{%
        \expandafter\let\csname the#1\endcsname\NCC@thesec
      }%
      \expandafter\let\csname the#1\endcsname\NCC@sectag
      \protected@edef\@currentlabel{\NCC@sectag}%
    \fi
%    \end{macrocode}
%
% Prepare section tag in the |\@svsec| command:
%    \begin{macrocode}
    \ifnum #2>\c@secnumdepth
      \let\@svsec\@empty
    \else
      \protected@edef\@svsec{%
        \protect\NCC@makesectag{\csname the#1\endcsname}%
      }%
    \fi
%    \end{macrocode}
%
% We cannot do the marking right now because the producing of section
% can be suspended to the beginning of the nearest paragraph
% (in run-in sections). So, we need to prepare a mark action
% in a command that will save its state as long as necessary.
% This command is |\NCC@makemark|.
%    \begin{macrocode}
    \let\NCC@makemark\@empty
    \@ifundefined{#1mark}{}{%
      \ifx\NCC@secmark\relax
%    \end{macrocode}
% Ordinary case: prepare the section mark with the
% \meta{toc-entry} parameter.
%    \begin{macrocode}
        \ifNCC@nosecmark \else
          \def\NCC@makemark{\csname #1mark\endcsname{#3}}%
        \fi
%    \end{macrocode}
% The |\runninghead|\marg{heading} case:
% pass the mark command in the parameter of |\NCC@secmark|.
% We need to save the |\NCC@secmark| value in some command
% and pass this command within |\NCC@makemark| because
% the |\NCC@secmark| could be removed before the use.
%    \begin{macrocode}
      \else
        \let\NCC@savesecmark\NCC@secmark
        \def\NCC@makemark{%
          \NCC@savesecmark{\csname #1mark\endcsname}%
          \let\NCC@savesecmark\relax
        }%
      \fi
    }%
%    \end{macrocode}
%
% Make the section. We must apply the restore action at
% the end action of |\NCC@make| command by the same reason that
% the section making may be suspended:
%    \begin{macrocode}
    \ifNCC@noaux
      \NCC@make{\NCC@makemark \NCC@restsec}%
    \else
      \NCC@make{\NCC@makemark #4\NCC@restsec}%
    \fi
%    \end{macrocode}
%
% Reset modifiers:
%    \begin{macrocode}
  \fi
  \NCC@sec@reset@controls
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Section Making Commands}
%
% \begin{macro}{\indentaftersection}
% \begin{macro}{\noindentaftersection}
% Introduce macros controlling indentation after display sections:
%    \begin{macrocode}
\newcommand{\indentaftersection}{\@afterindenttrue}
\newcommand{\noindentaftersection}{\@afterindentfalse}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\SectionTagSuffix}
% The |\SectionTagSuffix|\marg{suffix} sets a suffix after a section tag:
%    \begin{macrocode}
\newcommand*{\SectionTagSuffix}[1]{\def\NCC@asecnum{#1}}
\@onlypreamble\SectionTagSuffix
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@defaultsectag}
% This command restores the making tag command to its default
% value.
%    \begin{macrocode}
\def\NCC@makesectag@default#1{#1\NCC@asecnum}
\def\NCC@defaultsectag{\let\NCC@makesectag\NCC@makesectag@default}
\NCC@defaultsectag
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@secname}
% The |\NCC@secname|\marg{level} command generates section name
% (|section|,\linebreak |subsection|, \ldots,
% or |section@vi|, |section@vii|, \ldots\ for new section levels).
% This name is used as the second parameter of the |\addcontentsline|
% command and in the declarations of toc-entries.
%    \begin{macrocode}
\def\NCC@secname#1{%
  \ifcase#1\relax \or section\or subsection\or subsubsection\or
    paragraph\or subparagraph\else section@\romannumeral#1\fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@startsection}
% The |\@startsection| command
% has the same syntax as the original \LaTeX\ version:
% \begin{quote}
% |\@startsection|\marg{type}\marg{level}\marg{indent}\marg{beforeskip}\\
% |              |\marg{afterskip}\marg{style}
% \end{quote}
% but works in a bit different way: it ignores the sign of
% \meta{beforeskip}. In the original version the testing
% was applied to set an appropriate |afterindent| mode.
% But we change this mode using |\indentaftersection| and
% |\noindentaftersection| macros.
%    \begin{macrocode}
\def\@startsection#1#2#3#4#5#6{%
  \@tempskipa #4\relax
  \ifdim \@tempskipa <\z@ \@temskipa -\@tempskipa \fi
  \NCC@secskip \@tempskipa
  \secdef{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}{\@ssect{#3}{#4}{#5}{#6}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makesec}
% We save the interface of |\@ssect| and |\@sect| commands, but
% change their implementation. They are based on the following
% command:
% \begin{quote}
% |\NCC@makesec|\marg{indent}\marg{style}\marg{heading}\marg{afterskip}\marg{action}
% \end{quote}
% In fact, there are two versions of this command:
% the traditional version, |\NCC@makesect|, and the
% version with dynamic control of section style,\linebreak |\NCC@makesecx|.
% The first one is the default version. To be sure, that this
% version will be used by default, we every time let
% the |\NCC@makesec| to be equal to |\NCC@makesect| after
% a section is produced.
% \end{macro}
%
% \begin{macro}{\@ssect}
% The starred form of section:
% \begin{quote}
% |\@ssect|\marg{indent}\marg{beforeskip}\marg{afterskip}\marg{style}\marg{heading}
% \end{quote}
%    \begin{macrocode}
\def\@ssect#1#2#3#4#5{%
  \let\@svsec\@empty
  \NCC@makesec{#1}{#4}{#5}{#3}{}%
  \NCC@sec@reset@controls
  \let\NCC@makesec\NCC@makesect
  \NCC@defaultsectag
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@sect}
% The base form of section:
% \begin{quote}
% |\@sect|\marg{type}\marg{level}\marg{indent}\marg{beforeskip}\marg{afterskip}\marg{style}\\
% |      |\oarg{toc-entry}\marg{heading}
% \end{quote}
%    \begin{macrocode}
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \def\NCC@make{\NCC@makesec{#3}{#6}{#8}{#5}}%
  \NCC@makesection{#1}{#2}{#7}{%
    \addcontentsline{toc}{\NCC@secname{#2}}{%
      \ifnum #2>\c@secnumdepth \else
        \protect\numberline{\csname the#1\endcsname}%
      \fi
      #7%
    }%
  }%
  \let\NCC@makesec\NCC@makesect
  \NCC@defaultsectag
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makesect}
% The traditional section making command:
% \begin{quote}
% |\NCC@makesect|\marg{indent}\marg{style}\marg{heading}\marg{afterskip}\marg{action}
% \end{quote}
%    \begin{macrocode}
\def\NCC@makesect#1#2#3#4#5{%
  \@tempskipa #4\relax
  \ifdim \@tempskipa>\z@
    \begingroup \normalfont
      #2{\@hangfrom{\hskip #1\relax\@svsec}%
          \interlinepenalty \@M\ignorespaces #3\@@par}%
    \endgroup
    #5%
  \else
    \def\@svsechd{{\normalfont #2{\hskip #1\relax
                   \@svsec\ignorespaces #3}}#5}%
  \fi
  \@xsect{#4}%
}
\let\NCC@makesec\NCC@makesect
%    \end{macrocode}
% \end{macro}
%
% \subsection{Make Sections with Dynamic Control}
%
% \begin{macro}{\NCC@sec}
% A style of sections having dynamic control is defined by the
% |\NCC@sec|\marg{tag} hook. This hook is applied inside a group
% preparing a heading.
% \end{macro}
%
% \begin{macro}{\sectionstyle}
% The |\sectionstyle|\marg{style} changes a style of display sections.
% In fact, it calls the |\NCC@sec@|\meta{style} command.
%    \begin{macrocode}
\newcommand*{\sectionstyle}[1]{%
  \@ifundefined{NCC@sec@#1}%
    {\PackageError{nccsect}{Unknown section style `#1'}{}}%
    {\csname NCC@sec@#1\endcsname}%
}
\def\NCC@sec@hangindent{\def\NCC@sec##1{\@hangfrom{##1}}}
\@namedef{NCC@sec@hangindent*}{%
  \def\NCC@sec##1{\@hangfrom{##1}\rightskip\@flushglue}%
}
\def\NCC@sec@parindent{\def\NCC@sec##1{\@hangfrom\indent##1}}
\@namedef{NCC@sec@parindent*}{%
  \def\NCC@sec##1{\@hangfrom\indent\rightskip\@flushglue##1}%
}
\def\NCC@sec@center{\def\NCC@sec##1{\centering##1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makesecx}
% The dynamic section making command:
% \begin{quote}
% |\NCC@makesecx|\marg{indent}\marg{style}\marg{heading}\marg{afterskip}\marg{action}
% \end{quote}
% It prepares only display sections and ignores the \meta{indent} parameter.
%    \begin{macrocode}
\def\NCC@makesecx#1#2#3#4#5{%
  \begingroup\normalfont
    #2{\NCC@sec{\@svsec}\interlinepenalty \@M\ignorespaces #3\@@par}%
  \endgroup #5%
  \par \nobreak \vskip #4\relax \@afterheading \ignorespaces
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Make the Main Section}
%
% \begin{macro}{\NCC@startmainsec}
% The main section is a section of zero level.
% It is prepared with the following command:
% \begin{quote}
% |\NCC@startmainsec|\marg{alignment}\marg{prefix}\marg{beforeskip}\\
% |                 |\marg{afterskip}\marg{style}
% \end{quote}
% It starts either a new chapter or a new part depending on the class
% loaded. To decide what version should be prepared, we test the
% |\chapter| command on existence.
%    \begin{macrocode}
\@ifundefined{chapter}{%
%    \end{macrocode}
%
% The case of an article-like class. Zero-level section is the |\part|.
%    \begin{macrocode}
  \def\NCC@startmainsec#1#2#3#4#5{%
    \def\NCC@makesectag##1{\leavevmode#2\partname\nobreakspace##1}%
    \NCC@secskip{#3}%
    \secdef{\@part{#1}{#4}{#5}}{\@spart{#1}{#4}{#5}}%
  }
%    \end{macrocode}
%
% \begin{macro}{\@spart}
% Prepare the starred version of part:
% \begin{quote}
% |\@spart|\marg{alignment}\marg{afterskip}\marg{style}\marg{heading}
% \end{quote}
%    \begin{macrocode}
  \def\@spart#1#2#3#4{%
    \let\@svsec\@empty
    \NCC@makepart{#1}{#3}{#4}{#2}{}%
    \NCC@sec@reset@controls
    \NCC@defaultsectag
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@part}
% Prepare the non-starred version of part:
% \begin{quote}
% |\@part|\marg{alignment}\marg{afterskip}\marg{style}\oarg{toc-entry}\marg{heading}
% \end{quote}
%    \begin{macrocode}
  \def\@part#1#2#3[#4]#5{%
    \def\NCC@make{\NCC@makepart{#1}{#3}{#5}{#2}}%
    \NCC@makesection{part}{\z@}{#4}{%
      \addcontentsline{toc}{part}{%
        \ifnum \c@secnumdepth>\m@ne \protect\numberline{\thepart}\fi
        #4%
      }%
    }%
    \NCC@defaultsectag
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makepart}
% This command makes a part.
% \begin{quote}
% |\NCC@makepart|\marg{alignment}\marg{style}\marg{heading}\marg{afterskip}\marg{action}
% \end{quote}
% The |\@svsec| is either |\@empty| or contains a part tag.
%    \begin{macrocode}
  \def\NCC@makepart#1#2#3#4#5{%
    \begingroup \normalfont
      \ifx\@svsec\@empty \else #1{\@svsec\@@par}\nobreak \fi
      \interlinepenalty \@M #1{#2{#3}\@@par}%
    \endgroup
    #5%
    \par\nobreak \vskip #4\relax \@afterheading \ignorespaces
  }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\partmark}
% Define the |\partmark| if it is undefined before.
%    \begin{macrocode}
  \providecommand*\partmark[1]{\markboth{}{}}
}{
%    \end{macrocode}
% \end{macro}
%
% The case of a book-like class. Zero-level section is the |\chapter|.
%    \begin{macrocode}
  \def\NCC@startmainsec#1#2#3#4#5{%
    \NCC@startchap
    \def\NCC@makesectag##1{\leavevmode#2\@chapapp\nobreakspace##1}%
    \secdef{\@chapter{#1}{#3}{#4}{#5}}{\@schapter{#1}{#3}{#4}{#5}}%
  }
%    \end{macrocode}
%
% \begin{macro}{\beforechapter}
% The |\beforechapter|\marg{something} hook is applied to the nearest
% chapter. An empty value of its parameter means no hook.
%    \begin{macrocode}
  \newcommand\beforechapter[1]{\gdef\NCC@beforechapter{#1}}
  \beforechapter{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@schapter}
% Prepare the starred version of chapter:
% \begin{quote}
% |\@schapter|\marg{alignment}\marg{beforeskip}\marg{afterskip}\marg{style}\marg{heading}
% \end{quote}
%    \begin{macrocode}
  \def\@schapter#1#2#3#4#5{%
    \let\@svsec\@empty
    \NCC@makechapter{#1}{#2}{#4}{#5}{#3}{}%
    \NCC@sec@reset@controls
    \NCC@defaultsectag
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@chapter}
% Prepare the non-starred version of chapter:
% \begin{quote}
% |\@chapter|\marg{alignment}\marg{beforeskip}\marg{afterskip}\marg{style}\\
% |         |\oarg{toc-entry}\marg{heading}
% \end{quote}
% It uses the |\NCC@infloats|\marg{action} hook that applies the specified
% action for all registered float types.
%    \begin{macrocode}
  \def\@chapter#1#2#3#4[#5]#6{%
    \@ifundefined{if@mainmatter}{}{\if@mainmatter\else\noheadingtag\fi}%
    \def\NCC@make{\NCC@makechapter{#1}{#2}{#4}{#6}{#3}}%
    \NCC@makesection{chapter}{\z@}{#5}{%
      \typeout{\@chapapp\space\thechapter.}%
      \addcontentsline{toc}{chapter}{%
        \ifnum \c@secnumdepth>\m@ne
          \protect\numberline{\NCC@thetocchapter}\fi
        #5%
      }%
      \NCC@infloats{\addtocontents{\@nameuse{ext@\@captype}}%
                      {\protect\runinsectionskip}}%
    }%
    \NCC@defaultsectag
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@startchap}
% The start chapter hook:
%    \begin{macrocode}
  \def\NCC@startchap{%
    \if@openright\cleardoublepage\else\clearpage\fi
    \thispagestyle{plain}\global\@topnum\z@
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@thetocchapter}
% The following hook allows redefine the appearance of chapter name
% in the TOC:
%    \begin{macrocode}
  \def\NCC@thetocchapter{\thechapter}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makechapter}
% This command makes a chapter:
% \begin{quote}
% |\NCC@makechapter|\marg{alignment}\marg{beforeskip}\marg{style}\marg{heading}\\
% |                |\marg{afterskip}\marg{action}
% \end{quote}
% The |\@svsec| is either |\@empty| or contains a chapter tag.
%    \begin{macrocode}
  \def\NCC@makechapter#1#2#3#4#5#6{%
    \if@twocolumn
      \@topnewpage[\NCC@makechaphead{#1}{#2}{#3}{#4}{#5}]%
    \else
      \NCC@makechaphead{#1}{#2}{#3}{#4}{#5}%
    \fi
    #6%
    \@afterheading
    \ignorespaces
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makechaphead}
% This command makes a chapter head:
% \begin{quote}
% |\NCC@makechaphead|\marg{alignment}\marg{beforeskip}\marg{style}\marg{heading}\\
% |                 |\marg{afterskip}
% \end{quote}
%    \begin{macrocode}
  \def\NCC@makechaphead#1#2#3#4#5{%
    \ifx\NCC@beforechapter\@empty
      \StartFromTextArea \vspace{#2}%
    \else
      \begingroup
        \@twocolumnfalse
        \let\NCC@global\@empty
        \NCC@sec@reset@controls
        \normalfont \NCC@beforechapter \par
      \endgroup
      \beforechapter{}%
    \fi
    \begingroup \normalfont
      \ifx\@svsec\@empty \else #1{\@svsec\@@par}\fi
      \interlinepenalty \@M #1{#3{#4}\@@par}%
    \endgroup
    \par\nobreak \vskip #5\relax
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\epigraph}
% \begin{macro}{\epigraphparameters}
% \begin{quote}
% |\epigraph|\oarg{width}\marg{text}\marg{author}\\
% |\epigraphparameters|\marg{style}\marg{width}\marg{height}\marg{author-style}\\
% |                   |\marg{after-action}
% \end{quote}
%    \begin{macrocode}
  \newcommand*\epigraph[1][\NCC@epigraphwidth]{\NCC@epigraph{#1}}
  \newcommand*\epigraphparameters[5]{%
    \def\NCC@epigraphwidth{#2}%
    \long\def\NCC@epigraph##1##2##3{
      \beforechapter{\def\epigraphwidth{##1}%
        #1\par
        \NCC@makeepigraph{#3}{##2}{#4{##3}}\par
        #5%
      }%
    }%
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\NCC@makeepigraph}
% \begin{quote}
% |\NCC@makeepigraph|\marg{height}\marg{text}\marg{author}
% \end{quote}
%    \begin{macrocode}
  \long\def\NCC@makeepigraph#1#2#3{%
    \@begin@tempboxa\vtop{\setlength{\hsize}{\epigraphwidth}%
        \@parboxrestore{#2\@@par}#3\@@par
      }%
      \setlength\@tempdima{#1}\advance\@tempdima -\totalheight
      \ifdim\@tempdima>\z@
        \advance\@tempdima\depth
        \dp\@tempboxa\@tempdima
      \fi
      \leavevmode\box\@tempboxa
    \@end@tempboxa
  }
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Make Captions}
%
% \begin{macro}{\CaptionTagSuffix}
% The |\CaptionTagSuffix|\marg{suffix} sets a suffix after a caption tag:
%    \begin{macrocode}
\newcommand*{\CaptionTagSuffix}[1]{\def\NCC@acapnum{#1}}
\@onlypreamble\CaptionTagSuffix
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\captionstyle}
% The |\captionstyle|\oarg{type}\marg{style} selects a style to be applied
% to the caption text. Three styles are available now: |default|, |center|,
% and |centerlast|.
%    \begin{macrocode}
\newcommand*\captionstyle[1][]{%
  \NCC@set@capkey{style}{style}{#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\captiontagstyle}
% The |\captiontagstyle|\oarg{type}\marg{style} selects a style of caption tag:
% |right| or |para|.
%    \begin{macrocode}
\newcommand*\captiontagstyle[1][]{%
  \NCC@set@capkey{tag}{tag style}{#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\captionwidth}
% The |\captionwidth|\oarg{type}\marg{length} specifies a caption width.
% Default width is |\linewidth|.
%    \begin{macrocode}
\newcommand*\captionwidth[2][]{%
  \NCC@prepare@capkey{width}{#1}{\setlength{\hsize}{#2}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@set@capkey}
% |\NCC@set@capkey|\marg{key}\marg{description}\marg{type}\marg{value}
%    \begin{macrocode}
\def\NCC@set@capkey#1#2#3#4{%
  \@ifundefined{NCC@makecap#1@#4}
  {\PackageError{nccsect}{Unknown caption #2 `#4'}{}%
  }{%
    \edef\@tempa{\noexpand\NCC@prepare@capkey{#1}{#3}{%
        \expandafter\noexpand\csname NCC@makecap#1@#4\endcsname
      }%
    }%
    \@tempa
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@prepare@capkey}
% |\NCC@prepare@capkey|\marg{key}\marg{type}\marg{definition}
%    \begin{macrocode}
\def\NCC@prepare@capkey#1#2{%
  \def\@tempa{#2}%
  \ifx\@tempa\@empty
    \ifx\@captype\@undefined \else \let\@tempa\@captype \fi
  \fi
  \expandafter\def\csname NCC@cap#1@\@tempa\endcsname
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@apply@cap}
% |\NCC@apply@cap|\marg{key}
%    \begin{macrocode}
\def\NCC@apply@cap#1{%
  \@ifundefined{NCC@cap#1@\@captype}%
    {\let\@tempa\@empty}{\let\@tempa\@captype}%
  \csname NCC@cap#1@\@tempa\endcsname
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@startcaption}
% This command starts a caption:
% \begin{quote}
% |\NCC@startcaption|\marg{beforeskip}\marg{afterskip}\marg{style}
% \end{quote}
%    \begin{macrocode}
\def\NCC@startcaption#1#2#3{%
  \secdef{\NCC@caption{#1}{#2}{#3}}{\NCC@scaption{#1}{#2}{#3}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@scaption}
% Starred version of caption:
% \begin{quote}
% |\NCC@scaption|\marg{beforeskip}\marg{afterskip}\marg{style}\marg{text}
% \end{quote}
%    \begin{macrocode}
\long\def\NCC@scaption#1#2#3#4{%
  \let\@svsec\@empty
  \NCC@makecaption{#3}{#1}{#4}{#2}{}%
  \NCC@sec@reset@controls
  \NCC@defaultsectag
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@caption}
% Non-starred version of caption:
% \begin{quote}
% |\NCC@caption|\marg{beforeskip}\marg{afterskip}\marg{style}\oarg{toc-entry}\marg{text}
% \end{quote}
%    \begin{macrocode}
\long\def\NCC@caption#1#2#3[#4]#5{%
  \def\NCC@make{\NCC@makecaption{#3}{#1}{#5}{#2}}%
  \NCC@makesection{\@captype}{\z@}{#4}{%
    \begingroup
      \let\centering\@empty
      \addcontentsline{\@nameuse{ext@\@captype}}{\@captype}{%
        \ifnum \c@secnumdepth>\m@ne
          \protect\numberline{\@nameuse{the\@captype}}\fi
        #4%
      }%
    \endgroup
  }%
  \NCC@defaultsectag
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecaption}
% This command makes a caption:
% \begin{quote}
% |\NCC@makecaption|\marg{style}\marg{beforeskip}\marg{text}\marg{afterskip}\marg{action}
% \end{quote}
% The |\@svsec| is either |\@empty| or contains a caption tag.
%    \begin{macrocode}
\long\def\NCC@makecaption#1#2#3#4#5{%
  \begingroup\par\normalfont
    #1{}\addvspace{#2}\noindent
%    \end{macrocode}
% Calculate in |\@tempcnta| caption variants:
% 0~-- no caption, 1~-- caption tag only, 2~-- caption text only,
% 3~-- both caption tag and text are nonempty.
%    \begin{macrocode}
    \ifx\@svsec\@empty \@tempcnta\z@ \else \@tempcnta\@ne \fi
    \def\@tempa{#3}%
    \ifx\@tempa\@empty \else \advance\@tempcnta\tw@ \fi
%    \end{macrocode}
% Put caption in a parbox aligned at the top line.
%    \begin{macrocode}
    \ifnum\@tempcnta=\z@ \else
      \vtop{\NCC@apply@cap{width}\@parboxrestore
        \NCC@apply@cap{tag}{#3}\@@par}\par
%    \end{macrocode}
% We avoid insert zero skip after parbox to allow captions of
% side-by-side figures to be aligned at their top line.
%    \begin{macrocode}
      \setlength\@tempskipa{#4}%
      \ifdim\@tempskipa=\z@ \else \vskip \@tempskipa\fi
    \fi
  \endgroup
  #5%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecaptag@para}
% The |\NCC@makecaptag@para|\marg{text} prepares run-in tag.
%    \begin{macrocode}
\long\def\NCC@makecaptag@para#1{%
  \ifnum\@tempcnta<\thr@@ \let\NCC@acapnum\@empty\fi
  \NCC@apply@cap{style}{{\@svsec}\ignorespaces#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecaptag@left}
% The |\NCC@makecaptag@left|\marg{text} prepares flush-left tag.
%    \begin{macrocode}
\def\NCC@makecaptag@left{\NCC@separate@captag\raggedright}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecaptag@center}
% The |\NCC@makecaptag@center|\marg{text} prepares centered tag.
%    \begin{macrocode}
\def\NCC@makecaptag@center{\NCC@separate@captag\centering}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecaptag@right}
% The |\NCC@makecaptag@right|\marg{text} prepares flush-right tag.
%    \begin{macrocode}
\def\NCC@makecaptag@right{\NCC@separate@captag\raggedleft}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@separate@captag}
% The |\NCC@separate@captag|\marg{style}\marg{text} prepares a
% caption tag in a separate line.
%    \begin{macrocode}
\long\def\NCC@separate@captag#1#2{%
  \ifodd\@tempcnta
    {\let\NCC@acapnum\@empty #1\@svsec\@@par}%
  \fi
  \ifnum\@tempcnta>\@ne
    \ifnum\@tempcnta=\thr@@ \vskip .5ex\fi
    \NCC@apply@cap{style}{#2}%
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@default}
% The |\NCC@makecapstyle@default|\marg{text} prepares caption text
% in default \LaTeX's style.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@default#1{%
  \setbox\@tempboxa\vtop{\hsize\linewidth\@parboxrestore#1\@@par}%
  \ifdim\dp\@tempboxa<\baselineskip \centering#1%
  \else \box\@tempboxa \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@para}
% The |\NCC@makecapstyle@para|\marg{text} prepares ordinary caption.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@para#1{#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@left}
% The |\NCC@makecapstyle@left|\marg{text} prepares flush-left caption.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@left#1{\raggedright#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@right}
% The |\NCC@makecapstyle@right|\marg{text} prepares flush-right caption.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@right#1{\raggedleft#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@center}
% The |\NCC@makecapstyle@center|\marg{text} prepares centered caption.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@center#1{\centering#1}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@makecapstyle@centerlast}
% The |\NCC@makecapstyle@centerlast|\marg{text} prepares caption with
% last line centered.
%    \begin{macrocode}
\long\def\NCC@makecapstyle@centerlast#1{%
  \leftskip\z@\@plus 1fil%
  \rightskip\z@\@plus -1fil%
  \parfillskip\z@\@plus 2fil\relax#1%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\RegisterFloatType}
% The |\RegisterFloatType|\marg{type} command registers a float type:
%    \begin{macrocode}
\newcommand*{\RegisterFloatType}[1]{%
  \edef\NCC@floatlist{\NCC@floatlist{#1}}%
}
\let\NCC@floatlist\@empty
\@onlypreamble\RegisterFloatType
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@infloats}
% The |\NCC@infloats|\marg{action} command applies the given \meta{action}
% to all registered float types. During the cycle,
% the |\@captype| contains a name of float and
% the |\@tempcnta| is equal to its registration number
% (1~for the figure float, 2~for the table float, and so on).
%    \begin{macrocode}
\def\NCC@infloats#1{%
  \@tempcnta\z@
  \let\NCC@temp \@captype
  \expandafter \@tfor \expandafter \@captype
    \expandafter :\expandafter =\NCC@floatlist \do
  {\advance\@tempcnta\@ne #1}%
  \let\@captype\NCC@temp
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Declare Sections and Captions}
%
% \begin{macro}{\DeclareSection}
% Now we can implement the |\DeclareSection| command.
% It generates:
% \begin{desclist}{}{}
% \item[\cs{NCC@mainsection}] command if \meta{level} = 0;
% \item[\cs{NCC@section}\meta{level-in-roman}] command if \meta{level} $>$ 0;
% \item[\cs{NCC@cap@}\meta{float-type}] command if \meta{level} $<$ 0.
% \end{desclist}
%    \begin{macrocode}
\newcommand{\DeclareSection}{\@ifstar{\NCC@dsecx}{\NCC@dsec}}
\def\NCC@dsec#1#2{%
  \@ifnextchar[{\NCC@dsect{#1}{#2}}{\NCC@dsect{#1}{#2}[\z@skip]}%
}
\@onlypreamble\DeclareSection
\@onlypreamble\NCC@dsec
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@dsect}
% The non-starred version of section declaration command
% prepares display sections with traditional formatting:
% \begin{quote}
% |\NCC@dsect|\marg{level}\marg{type}\oarg{indent}\marg{prefix}\marg{beforeskip}\\
% |          |\marg{afterskip}\marg{style}
% \end{quote}
% It is also used for generation of run-in sections
% and captions.
%    \begin{macrocode}
\def\NCC@dsect#1#2[#3]#4#5#6#7{%
  \ifnum#1>\z@
    \expandafter\def\csname NCC@section\romannumeral#1\endcsname{%
      \def\NCC@makesectag####1{#4####1\NCC@asecnum}%
      \let\NCC@makesec\NCC@makesect
      \@startsection{#2}{#1}{#3}{#5}{#6}{#7}}%
  \else
    \ifnum#1=\z@
      \def\NCC@mainsection{%
        \NCC@startmainsec{\@hangfrom{\hskip #3}\rightskip\@flushglue}%
          {#4}{#5}{#6}{#7}%
      }%
    \else
      \NCC@dsecf{#2}{#4}{#5}{#6}{#7}%
    \fi
  \fi
}
\@onlypreamble\NCC@dsect
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@dsecx}
% The starred version of section declaration command
% prepares display sections with dynamic formatting:
% \begin{quote}
% |\NCC@dsecx|\marg{level}\marg{type}\marg{prefix}\marg{beforeskip}\marg{afterskip}\marg{style}
% \end{quote}
% It can be also used for generation of captions.
%    \begin{macrocode}
\def\NCC@dsecx#1#2#3#4#5#6{%
  \ifnum#1>\z@
    \expandafter\def\csname NCC@section\romannumeral#1\endcsname{%
      \def\NCC@makesectag####1{#3####1\NCC@asecnum}%
      \let\NCC@makesec\NCC@makesecx
      \@startsection{#2}{#1}{\z@}{#4}{#5}{#6}}%
  \else
    \ifnum#1=\z@
      \def\NCC@mainsection{%
        \NCC@startmainsec{\NCC@sec{}\rightskip\@flushglue}%
          {#3}{#4}{#5}{#6}%
      }%
    \else
      \NCC@dsecf{#2}{#3}{#4}{#5}{#6}%
    \fi
  \fi
}
\@onlypreamble\NCC@dsecx
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@dsecf}
% This command declares captions of floats:
% \begin{quote}
% |\NCC@dsecf|\marg{type}\marg{prefix}\marg{beforeskip}\marg{afterskip}\marg{style}
% \end{quote}
%    \begin{macrocode}
\def\NCC@dsecf#1#2#3#4#5{%
  \expandafter\def\csname NCC@cap@#1\endcsname{%
    \def\NCC@makesectag####1{#2{\csname #1name\endcsname}%
      \nobreakspace####1\NCC@acapnum}%
    \NCC@startcaption{#3}{#4}{#5}%
  }%
}
\@onlypreamble\NCC@dsectf
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@makecaption}
% We emulate here the |\@makecaption{\fnum@|\meta{type}|}|\marg{caption}
% command to provide the compatibility with packages using it.
% It calls the |\NCC@cap@|\meta{type} command using the type specified
% in |\@captype| command. The counter is already stepped
% before this command and all necessary things are written
% to aux. Therefore, we turn off writing to aux and decrease a value of
% the float counter by |-1| because it will be stepped within again.
%    \begin{macrocode}
\long\def\@makecaption#1#2{%
  \begingroup
    \skipwritingtoaux
    \addtocounter\@captype\m@ne
    \csname NCC@cap@\@captype\endcsname[]{#2}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
%
% Add patches to the |supertabular| and |longtable| packages if they are used:
%    \begin{macrocode}
\AtBeginDocument{%
  \@ifpackageloaded{supertabular}{%
    \long\def\ST@caption#1[#2]#3{\par%
      \addcontentsline{\csname ext@#1\endcsname}{#1}%
        {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
      \def\@captype{#1}%
      \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
    }%
  }{}%
  \@ifpackageloaded{longtable}{%
    \def\LT@makecaption#1#2#3{%
      \LT@mcol\LT@cols c{\hbox to\z@{\hss
        \parbox[t]\LTcapwidth{\def\@captype{table}%
          \ifx#1\@gobble \NCC@cap@table*{#3}%
          \else \@makecaption{\fnum@table}{#3}%
          \fi
        }%
        \hss
      }}%
    }%
  }{}%
}
%    \end{macrocode}
%
% \subsection{Declare TOC-Entries}
%
% \begin{macro}{\DeclareTOCEntry}
% The toc-entries declaration command:
% \begin{quote}
% |\DeclareTOCEntry|\marg{level}\marg{action}\marg{prefix}\marg{prototype}\\
% |                |\marg{style}\oarg{next}
% \end{quote}
%    \begin{macrocode}
\newcommand*{\DeclareTOCEntry}[5]{%
  \@ifnextchar[{\NCC@dtoc{#1}{#2}{#3}{#4}{#5}}%
               {\NCC@dtoc{#1}{#2}{#3}{#4}{#5}%
                [{#3#4\let\NCC@do\@firstoftwo\NCC@atocnum}]}%
}
\def\NCC@dtoc#1#2#3#4#5[#6]{%
%    \end{macrocode}
% Declare a toc-entry command for a registered float.
% We scan the registration list and find the necessary
% float type comparing its registration number with the negation
% of level. The generated command is |\l@|\meta{float-type}:
%    \begin{macrocode}
  \ifnum#1<\z@
    \@tempswatrue
    \NCC@infloats{%
      \ifnum#1=-\@tempcnta
        \expandafter\def\csname l@\@captype\endcsname
          {\NCC@tocentry\z@{#2}{#3}{#4}{#5}}%
        \@tempswafalse
        \@break@tfor
      \fi
    }%
%    \end{macrocode}
% Incorrect level number. Generate an error.
%    \begin{macrocode}
    \if@tempswa
      \@tempcnta#1\relax
      \@tempcnta -\@tempcnta
      \PackageError{nccsect}
        {Float type registration number \the\@tempcnta\space
         is out of range}{}%
    \fi
  \else
%    \end{macrocode}
% Prepare in |\@tempa| a command name: |\l@section| or |\l@subsection|
% or \ldots\ or |\l@subparagraph| or |\l@section@vi| or \ldots:
%    \begin{macrocode}
    \ifnum#1>\z@
      \edef\@tempa{\noexpand\def\expandafter\noexpand
                   \csname l@\NCC@secname{#1}\endcsname}%
%    \end{macrocode}
% or |\l@part| or |\l@chapter|:
%    \begin{macrocode}
    \else
      \@ifundefined{chapter}{\def\@tempa{\def\l@part}}%
                            {\def\@tempa{\def\l@chapter}}%
    \fi
%    \end{macrocode}
% Declare the toc-entry:
%    \begin{macrocode}
    \@tempa{\NCC@tocentry{#1}{#2}{#3}{#4}{#5}}%
%    \end{macrocode}
% Prepare in the |\l@tocskip@|\meta{next-level-in-roman} command
% the left margin adjustment command:
%    \begin{macrocode}
    \@tempcnta #1\relax \advance\@tempcnta\@ne
    \expandafter\def\csname l@tocskip@\romannumeral\@tempcnta
      \endcsname{\NCC@tocadj{#5{#6}}}%
  \fi
}
\@onlypreamble\DeclareTOCEntry
\@onlypreamble\NCC@dtoc
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@tocentry}
% This command makes a toc-entry:
% \begin{quote}
% |\NCC@tocentry|\marg{level}\marg{action}\marg{prefix}\marg{prototype}\\
% |             |\marg{style}\marg{entry}\marg{page-number}
% \end{quote}
%    \begin{macrocode}
\def\NCC@tocentry#1#2#3#4#5#6#7{%
  \ifnum #1>\c@tocdepth \else
    \par\begingroup\normalfont #2%
      \let\applystyle\@firstoftwo
%    \end{macrocode}
% Calculate the left margin in the |\@tempdimb| register
% applying the |\l@tocskip@i|, \ldots, |\l@tocskip@|\meta{level-in-roman}
% commands:
%    \begin{macrocode}
      \@tempdimb\z@ \@tempcnta #1\relax
      \@whilenum \@tempcnta >\z@\do
        {\@nameuse{l@tocskip@\romannumeral \@tempcnta}%
         \advance\@tempcnta\m@ne}%
%    \end{macrocode}
% Prepare the |\NCC@maketocnum|\marg{tag} command creating
% a number-line tag:
%    \begin{macrocode}
      \def\NCC@maketocnum##1{\NCC@do{#5}{}{#3##1\NCC@atocnum}}%
%    \end{macrocode}
% Calculate the hang indent value in |\@tempdima|:
%    \begin{macrocode}
      \settowidth\@tempdima{\let\NCC@do\@firstoftwo\NCC@maketocnum{#4}}%
%    \end{macrocode}
% Produce the toc-entry:
%    \begin{macrocode}
      \@dottedtocline{#1}{\@tempdimb}{\@tempdima}%
        {\let\NCC@do\@secondoftwo#5{\ignorespaces#6\unskip}}%
        {\let\applystyle\@secondoftwo#5{#7}}%
%    \end{macrocode}
% Allow break after toc-entry:
%    \begin{macrocode}
      \@nobreakfalse
    \endgroup
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@tocadj}
% The command increases |\@tempdimb| on the width of the argument:
%    \begin{macrocode}
\def\NCC@tocadj#1{\settowidth\@tempdima{#1}\advance\@tempdimb\@tempdima}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\numberline}
% Redefine the |\numberline|\marg{tag} command to work correct
% if the width of tag is greater than |\@tempdima|. The
% tag is prepared with the |\NCC@maketocnum|\marg{tag} command.
%    \begin{macrocode}
\def\numberline#1{%
  \setbox\@tempboxa\hbox{\NCC@maketocnum{#1}}%
  \ifdim \wd\@tempboxa > \@tempdima
    \box\@tempboxa
  \else
    \hb@xt@\@tempdima{\unhbox\@tempboxa\hfil}%
  \fi
  \ignorespaces
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@maketocnum}
% The default implementation of the |\NCC@maketocnum|\marg{tag} command.
% We must define it because the |\numberline| command must
% work out of scope of toc-entries.
%    \begin{macrocode}
\def\NCC@maketocnum#1{#1\let\NCC@do\@secondoftwo\NCC@atocnum}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NumberlineSuffix}
% The |\NumberlineSuffix|\marg{calc-suffix}\marg{actual-suffix}
% command saves suffices inserted after number tag in the |\numberline|
% command. It saves it in the |\NCC@atocnum| hook as parameters of
% |\NCC@do| command. Letting the last one to |\@firstoftwo| or
% |\@secondoftwo|, we select the \meta{calc-suffix} or \meta{actual-suffix}
% respectively.
%    \begin{macrocode}
\newcommand*{\NumberlineSuffix}[2]{\def\NCC@atocnum{\NCC@do{#1}{#2}}}
\@onlypreamble\NumberlineSuffix
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\TOCMarginDrift}
% The |\TOCMarginDrift|\marg{drift} specifies a drift of right margin
% in TOC.
%    \begin{macrocode}
\newcommand*\TOCMarginDrift[1]{%
  \def\@tempa{#1}%
  \ifx\@tempa\@empty \let\NCC@tocdrift\@empty
  \else \def\NCC@tocdrift{\@plus #1\relax}\fi
}
\TOCMarginDrift{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\PnumPrototype}
% The |\PnumPrototype|\marg{prototype} command saves the page number
% prototype in the |\NCC@pnum| hook and applies the |\NCC@setpnum|
% command.
%    \begin{macrocode}
\newcommand*{\PnumPrototype}[1]{\def\NCC@pnum{#1}\NCC@setpnum}
\@onlypreamble\PnumPrototype
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NCC@setpnum}
% The |\NCC@setpnum| command calculates the page number widths in
% |\@pnumwidth| and the toc right margin in |\@tocrmarg|.
% If the toc-style is customizable, we recommend to apply this
% command right after toc-styling commands to update margins
% for the new toc-style.
%    \begin{macrocode}
\def\NCC@setpnum{%
  \settowidth\@tempdima{\NCC@pnum}%
  \edef\@pnumwidth{\the\@tempdima}%
  \advance\@tempdima 1em
  \edef\@tocrmarg{\the\@tempdima \noexpand\NCC@tocdrift}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Service and Defaults}
%
% \begin{macro}{\StartFromTextArea}
% The command is applied at the beginning of page
% to set current position exactly at the first line
% of text area.
%    \begin{macrocode}
\newcommand\StartFromTextArea{\par
  {\parskip\z@ \strut\par}\vskip -\baselineskip
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\StartFromHeaderArea}
% The command is applied at the beginning of page
% to set current position exactly at the header line.
%    \begin{macrocode}
\newcommand\StartFromHeaderArea{%
  \StartFromTextArea
  \vskip -\headsep \vskip -\ht\strutbox
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bff}
% The |\bff| command tries to set everything bold.
%    \begin{macrocode}
\newcommand{\bff}{\normalfont\bfseries\mathversion{bold}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\startsection}
% Define the |\startsection| command:
%    \begin{macrocode}
\newcommand*{\startsection}[1]{%
  \ifnum#1>\z@
    \def\@tempa{\csname NCC@section\romannumeral#1\endcsname}%
  \else
    \ifnum#1=\z@
      \def\@tempa{\NCC@mainsection}%
    \else
      \def\@tempa{\part}%
    \fi
  \fi
  \@tempa
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\section}
% \begin{macro}{\subsection}
% \begin{macro}{\subsubsection}
% \begin{macro}{\paragraph}
% \begin{macro}{\subparagraph}
% Set aliases for the positive section levels:
%    \begin{macrocode}
\def\section{\startsection\@ne}
\def\subsection{\startsection\tw@}
\def\subsubsection{\startsection\thr@@}
\def\paragraph{\startsection4}
\def\subparagraph{\startsection5}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\caption}
% Redefine the |\caption| command. We do this at the beginning
% of document to reject possible redefinitions of captions
% in other packages such as |float|. I think this is not the
% |float|'s responsibility to decide where a caption must go on:
% before or after the float body. And what about complicated
% floats consisting of side floats and etc.? We also reset to zero
% the |\abovecaptionskip| and |\belowcaptionskip| registers if they
% are specified to provide partial compatibility with the |float|
% package. If the registers are not specified (as in |ncc| class),
% they are emulated with macros.
%    \begin{macrocode}
\AtBeginDocument{%
  \def\caption{%
    \ifx\@captype\@undefined
      \@latex@error{\noexpand\caption outside float}\@ehd
      \expandafter\@gobble
    \else
      \expandafter\@firstofone
    \fi
    {\csname NCC@cap@\@captype\endcsname}%
  }%
  \@ifundefined{abovecaptionskip}{\def\abovecaptionskip{\z@}}%
               {\abovecaptionskip\z@}%
  \@ifundefined{belowcaptionskip}{\def\belowcaptionskip{\z@}}%
               {\belowcaptionskip\z@}%
}
%    \end{macrocode}
% \end{macro}
%
% Register standard floats:
%    \begin{macrocode}
\RegisterFloatType{figure}
\RegisterFloatType{table}
%    \end{macrocode}
%
% Declare all sections and captions except the main section:
%    \begin{macrocode}
\DeclareSection{-2}{table}{}{\z@}{10pt}{}
\DeclareSection{-1}{figure}{}{10pt}{\z@}{}
\DeclareSection*1{section}{}%
                {3.5ex \@plus 1ex \@minus .2ex}%
                {2.3ex \@plus .2ex}{\Large\bff}
\DeclareSection*2{subsection}{}%
                {3.25ex \@plus 1ex \@minus .2ex}%
                {1.5ex \@plus .2ex}{\large\bff}
\DeclareSection*3{subsubsection}{}%
                {3ex \@plus 1ex \@minus .2ex}%
                {1.5ex \@plus .2ex}{\normalsize\bff}
\DeclareSection4{paragraph}{}%
                {\NCC@runskip}{-1em}{\normalsize\bff}
\DeclareSection5{subparagraph}[\parindent]{}%
                {\NCC@runskip}{-1em}{\normalsize\bff}
\@ifundefined{chapter}{
%    \end{macrocode}
%
% \begin{macro}{\part}
% Declare the main section and toc-entries for the
% article-like style:
%    \begin{macrocode}
  \def\part{\startsection\z@}
  \DeclareSection*0{part}{\Large\bff}%
                  {5ex \@plus 1ex \@minus .2ex}%
                  {4ex \@plus .2ex}{\huge\bff}
  \DeclareTOCEntry{-2}{}{}{9}{}% table
  \DeclareTOCEntry{-1}{}{}{9}{}% figure
  \DeclareTOCEntry0{\runinsectionskip\def\@dotsep{1000}}{}{III}{\bff}[]
  \DeclareTOCEntry1{\runinsectionskip}{}{9}{}
  \DeclareTOCEntry2{}{}{9.9}{}
  \DeclareTOCEntry3{}{}{9.9.9}{}
}{
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\chapter}
% Declare the main section, toc-entries for the
% book-like style, and specify default epigraph parameters:
%    \begin{macrocode}
  \def\chapter{\startsection\z@}
  \DeclareSection*0{chapter}{\vspace{3ex}\huge\bff}{10ex}%
                  {8ex \@plus .2ex}{\Huge\bff}
  \DeclareTOCEntry{-2}{}{}{9.9}{}% table
  \DeclareTOCEntry{-1}{}{}{9.9}{}% figure
  \DeclareTOCEntry0{\runinsectionskip\def\@dotsep{1000}%
                    \aftergroup\penalty\aftergroup\@highpenalty}{}{9}{\bff}
  \DeclareTOCEntry1{}{}{9.9}{}[9.9]
  \DeclareTOCEntry2{}{}{9.9.9}{}[9.9.9]
  \DeclareTOCEntry3{}{}{}{}[\qquad]
  \epigraphparameters{\StartFromHeaderArea\small\raggedleft}%
                     {.45\linewidth}{5\baselineskip}%
                     {\raggedleft\itshape}{\vspace{2ex}}
}
%    \end{macrocode}
% \end{macro}
%
% Declare other toc-entries:
%    \begin{macrocode}
\DeclareTOCEntry4{}{}{}{}[\qquad]
\DeclareTOCEntry5{}{}{}{}[\qquad]
%    \end{macrocode}
%
% Set defaults:
%    \begin{macrocode}
\noindentaftersection
\sectionstyle{hangindent}
\SectionTagSuffix{\quad}
\captionwidth{\linewidth}
\captionstyle{default}
\captiontagstyle{para}
\CaptionTagSuffix{:\hskip .7em \@plus .2em \@minus .1em}
\NumberlineSuffix{\quad}{\enskip}
\PnumPrototype{99}
%</package>
%    \end{macrocode}
\endinput