strc-lev.mklx /size: 3423 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=strc-lev,
3%D        version=2010.09.23,
4%D          title=\CONTEXT\ Structure Macros,
5%D       subtitle=Automatic Levels,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Structure Macros / Automatic Levels}
15
16%D This module is the result of a discussion between Alan Braslau and
17%D me. I used to have a private (\MKII) module for this but the new
18%D structure code in \MKIV\ is more suitable for this so now we have
19%D it as core functionality. For the moment this an experiment that
20%D Alan and I conduct so it might evolve.
21
22\registerctxluafile{strc-lev}{}
23
24\unprotect
25
26\permanent\tolerant\protected\def\definesectionlevels[#category]#spacer[#list]%
27  {\clf_definesectionlevels{#category}{#list}} % we could scan/use public at the lua end
28
29\permanent\tolerant\protected\def\startsectionlevel[#category]%
30  {\doifelseassignment{#category}%
31     {\clf_startsectionlevel\plusone{\v!default}{\currentnamedsection}[#category]}%
32     {\clf_startsectionlevel\plusone {#category}{\currentnamedsection}}}
33
34\permanent\protected\def\stopsectionlevel
35  {\clf_stopsectionlevel} % we could use public at the lua end
36
37\permanent\tolerant\protected\def\startsubjectlevel[#category]%
38  {\doifelseassignment{#category}%
39     {\clf_startsectionlevel\plustwo{\v!default}{\currentnamedsection}[#category]}%
40     {\clf_startsectionlevel\plustwo {#category}{\currentnamedsection}}}
41
42\permanent\protected\def\stopsubjectlevel
43  {\clf_stopsectionlevel} % we could use public at the lua end
44
45\permanent\tolerant\protected\def\nostarthead[#category]#spacer[#S#settings]#spacer[#S#userdata]%
46  {\blank
47   \noindentation{\tttf[start missing section level #category]}
48   \blank}
49
50\permanent\tolerant\protected\def\nostophead[#category]%
51  {\blank
52   \noindentation{\tttf[stop missing section level #category]}
53   \blank}
54
55\definesectionlevels
56  [\v!default]
57  [{\v!chapter,\v!title},
58   {\v!section,\v!subject},
59   {\v!subsection,\v!subsubject},
60   {\v!subsubsection,\v!subsubsubject},
61   {\v!subsubsubsection,\v!subsubsubject},
62   {\v!subsubsubsubsection,\v!subsubsubject}]
63
64\aliased\let\definestructurelevels\definesectionlevels
65\aliased\let\startstructurelevel  \startsectionlevel
66\aliased\let\stopstructurelevel   \stopsectionlevel
67
68\protect \endinput
69
70% \starttext
71%
72% \definehead[xxxxxxsection][subsubsection]
73% \setuphead [xxxxxxsection][color=red]
74%
75% \definesectionlevels[main][chapter,section,subsection,subsubsection]
76% \definesectionlevels[next][chapter,section,subsection,xxxxxxsection]
77%
78% \startsectionlevel [main] [title=first top level]
79%
80%     \startsectionlevel [main] [title=first lower level]
81%         \startsectionlevel [main] [title=second lower level]
82%             \startsectionlevel [main] [title=third lower level]
83%                 test
84%             \stopsectionlevel
85%         \stopsectionlevel
86%     \stopsectionlevel
87%
88%     \startsectionlevel [main] [title=first lower level]
89%         \startsectionlevel [main] [title=second lower level]
90%             \startsectionlevel [next] [title=third lower level]
91%                 test
92%             \stopsectionlevel
93%         \stopsectionlevel
94%     \stopsectionlevel
95%
96% \stopsectionlevel
97%
98% \stoptext
99