strc-sbe.mkxl /size: 4750 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=strc-sbe,
3%D        version=2008.10.20,
4%D          title=\CONTEXT\ Structure Macros,
5%D       subtitle=Section Block Environments,
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 / Section Block Environments}
15
16\unprotect
17
18% \def\ChapterEntry#1#2#3%
19%   {chapter : \hbox to \hsize{\strut\bf#2\hss#3}\endgraf\placelist[section]}
20%
21% \startfrontmatter % optional
22%   \placelist[chapter][alternative=command,command=\ChapterEntry,criterium=text] \page
23% \stopfrontmatter  % optional
24%
25% \startbodymatter % optional
26%   \chapter{first}  \section{one}   test \section{two}  test \page
27%   \chapter{second} \section{alpha} test \section{beta} test \page
28% \stopbodymatter  % optional
29
30\installcorenamespace{sectionblock}
31
32\installcommandhandler \??sectionblock {sectionblock} \??sectionblock
33
34\setupsectionblock
35  [\c!number=\v!yes,
36   \c!page=\v!right] % otherwise marks are reset too soon
37
38\newtoks\everybeforesectionblock
39\newtoks\everyaftersectionblock
40
41\let\strc_sectionblock_define_normal\definesectionblock
42
43\permanent\overloaded\tolerant\protected\def\definesectionblock[#1]#*[#2]#*[#S#3]% singular plural settings
44  {\strc_sectionblock_define_normal[#1][#3]%
45  %\expandafter\newif\csname if#2\endcsname % obsolete
46   \strc_sectionblock_set_environment{#1}\empty
47   \definemode[*#1]%
48   \frozen\protected\defcsname\e!start#2\endcsname{\startsectionblock[#1]}%
49   \frozen\protected\defcsname\e!stop #2\endcsname{\stopsectionblock}}
50
51\ifdefined \resetallstructuremarks \else
52    \let\resetallstructuremarks\relax
53\fi
54
55\def\strc_sectionblock_handle_page
56  {\edef\p_strc_sectionblock_page{\sectionblockparameter\c!page}%
57   \ifempty\p_strc_sectionblock_page \else
58      \page[\p_strc_sectionblock_page]%
59   \fi}
60
61\appendtoks
62    \strc_sectionblock_handle_page
63    \resetallstructuremarks
64    \strc_sectionblock_get_environment\currentsectionblock
65    \sectionblockparameter\c!before % don't move
66    \dostarttagged\t!division\currentsectionblock % no parents
67\to \everybeforesectionblock
68
69\appendtoks
70    \sectionblockparameter\c!after % don't move
71    \strc_sectionblock_handle_page
72    \dostoptagged
73    \resetallstructuremarks
74\to \everyaftersectionblock
75
76\permanent\tolerant\protected\def\setsectionblock[#1]#*[#S#2]% used to set the default
77  {\cdef\currentsectionblock{#1}% from now on we assume a value
78   \setupcurrentsectionblock[#2]%
79   \clf_setsectionblock{#1}
80      bookmark {\sectionblockparameter\c!bookmark}%
81   \relax}
82
83\mutable\lettonothing\currentsectionblock % was \s!unknown
84
85\permanent\tolerant\protected\def\startsectionblock[#1]#*[#S#2]%
86  {%\ctxlua{structures.counters.check(0)}% we assume sane usage of \page, as this is the only workable place (in push)
87   \begingroup
88   \cdef\currentsectionblock{#1}% from now on we assume a value
89   \setupcurrentsectionblock[#2]%
90   \clf_pushsectionblock{#1}
91     bookmark {\sectionblockparameter\c!bookmark}%
92   \relax
93  %\csname #1true\endcsname % obsolete
94   \setsystemmode\currentsectionblock
95   \expand\everybeforesectionblock\relax
96   \showmessage\m!structures1\currentsectionblock}
97
98\permanent\protected\def\stopsectionblock
99  {\showmessage\m!structures2\currentsectionblock
100   \expand\everyaftersectionblock\relax
101   \clf_popsectionblock
102   \endgroup}
103
104%D \starttyping
105%D \startsectionblockenvironment[frontpart]
106%D   \setupnumber[userpage][numberconversion=romannumerals,start=1]
107%D \stopsectionblockenvironment
108%D
109%D \startsectionblockenvironment[bodypart]
110%D   \setupnumber[userpage][numberconversion=numbers,start=1]
111%D \stopsectionblockenvironment
112%D
113%D \startsectionblockenvironment[backpart]
114%D   \setupnumber[userpage][numberconversion=numbers,start=1]
115%D \stopsectionblockenvironment
116%D
117%D \starttext
118%D   \startfrontmatter \chapter{test} \stopfrontmatter
119%D   \startbodymatter  \chapter{test} \stopbodymatter
120%D   \startappendices  \chapter{test} \stopappendices
121%D \stoptext
122%D \stoptyping
123
124\installcorenamespace{sectionblockenvironment}
125
126\protected\def\strc_sectionblock_set_environment#1#2%
127  {\defcsname\??sectionblockenvironment#1\endcsname{#2}}
128
129\protected\def\strc_sectionblock_get_environment#1%
130  {\csname\??sectionblockenvironment#1\endcsname}
131
132\permanent\tolerant\protected\defcsname\e!start\v!sectionblockenvironment\endcsname[#1]% evt \pushendofline \popendofline
133  {\grabuntil{\e!stop\v!sectionblockenvironment}{\strc_sectionblock_set_environment{#1}}}
134
135\permanent\protected\expandafter\lettonothing\csname\e!stop\v!sectionblockenvironment\endcsname
136
137\protect \endinput
138