strc-sbe.mkiv /size: 4829 b    last modification: 2020-07-01 14:35
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
\unexpanded
\def
\definesectionblock
44
{
\dotripleargument
\strc_sectionblock_define
}
45 46
\def
\strc_sectionblock_define
[#
1
][#
2
][#
3
]
% singular plural settings
47
{
\strc_sectionblock_define_normal
[#
1
][#
3
]
%
48
%\expandafter\newif\csname if#2\endcsname % obsolete
49
\strc_sectionblock_set_environment
{
#
1
}
\empty
50
\setuvalue
{
\e!start
#
2
}{
\startsectionblock
[#
1
]
}
%
51
\setuvalue
{
\e!stop
#
2
}{
\stopsectionblock
}}
52 53
\ifdefined
\resetallstructuremarks
\else
54
\let
\resetallstructuremarks
\relax
55
\fi
56 57
\def
\strc_sectionblock_handle_page
58
{
\edef
\p_strc_sectionblock_page
{
\sectionblockparameter
\c!page
}
%
59
\ifx
\p_strc_sectionblock_page
\empty
\else
60
\page
[
\p_strc_sectionblock_page
]
%
61
\fi
}
62 63
\appendtoks
64
\strc_sectionblock_handle_page
65
\resetallstructuremarks
66
\strc_sectionblock_get_environment
\currentsectionblock
67
\sectionblockparameter
\c!before
% don't move
68
\dostarttagged
\t!division
\currentsectionblock
% no parents
69
\to
\everybeforesectionblock
70 71
\appendtoks
72
\sectionblockparameter
\c!after
% don't move
73
\strc_sectionblock_handle_page
74
\dostoptagged
75
\resetallstructuremarks
76
\to
\everyaftersectionblock
77 78
\unexpanded
\def
\setsectionblock
79
{
\dodoubleempty
\strc_sectionblock_set
}
80 81
\def
\strc_sectionblock_set
[#
1
][#
2
]
% used to set the default
82
{
\edef
\currentsectionblock
{
#
1
}
% from now on we assume a value
83
\setupcurrentsectionblock
[#
2
]
%
84
\clf_setsectionblock
{
#
1
}
85
bookmark
{
\sectionblockparameter
\c!bookmark
}
%
86
\relax
}
87 88
\let
\currentsectionblock
\empty
% was \s!unknown
89 90
\unexpanded
\def
\startsectionblock
91
{
\dodoubleempty
\strc_sectionblock_start
}
92 93
\unexpanded
\def
\strc_sectionblock_start
[#
1
][#
2
]
%
94
{
%\ctxlua{structures.counters.check(0)}% we assume sane usage of \page, as this is the only workable place (in push)
95
\begingroup
96
\edef
\currentsectionblock
{
#
1
}
% from now on we assume a value
97
\setupcurrentsectionblock
[#
2
]
%
98
\clf_pushsectionblock
{
#
1
}
99
bookmark
{
\sectionblockparameter
\c!bookmark
}
%
100
\relax
101
%\csname #1true\endcsname % obsolete
102
\setsystemmode
\currentsectionblock
103
\the
\everybeforesectionblock
\relax
104
\showmessage
\m!structures
1
\currentsectionblock
}
105 106
\unexpanded
\def
\stopsectionblock
107
{
\showmessage
\m!structures
2
\currentsectionblock
108
\the
\everyaftersectionblock
\relax
109
\clf_popsectionblock
110
\endgroup
}
111 112
%D \starttyping
113
%D \startsectionblockenvironment[frontpart]
114
%D \setupnumber[userpage][numberconversion=romannumerals,start=1]
115
%D \stopsectionblockenvironment
116
%D
117
%D \startsectionblockenvironment[bodypart]
118
%D \setupnumber[userpage][numberconversion=numbers,start=1]
119
%D \stopsectionblockenvironment
120
%D
121
%D \startsectionblockenvironment[backpart]
122
%D \setupnumber[userpage][numberconversion=numbers,start=1]
123
%D \stopsectionblockenvironment
124
%D
125
%D \starttext
126
%D \startfrontmatter \chapter{test} \stopfrontmatter
127
%D \startbodymatter \chapter{test} \stopbodymatter
128
%D \startappendices \chapter{test} \stopappendices
129
%D \stoptext
130
%D \stoptyping
131 132
\installcorenamespace
{
sectionblockenvironment
}
133 134
\unexpanded
\def
\strc_sectionblock_set_environment
#
1
#
2
%
135
{
\setvalue
{
\??sectionblockenvironment
#
1
}{
#
2
}}
136 137
\unexpanded
\def
\strc_sectionblock_get_environment
#
1
%
138
{
\csname
\??sectionblockenvironment
#
1
\endcsname
}
139 140
\unexpanded\setvalue
{
\e!start\v!sectionblockenvironment
}
%
141
{
\dosingleargument
\strc_sectionblock_environment_start
}
142 143
\letvalue
{
\e!stop\v!sectionblockenvironment
}
\relax
144 145
\def
\strc_sectionblock_environment_start
[#
1
]
% evt \pushendofline \popendofline
146
{
\grabuntil
{
\e!stop\v!sectionblockenvironment
}{
\strc_sectionblock_set_environment
{
#
1
}}}
147 148
\protect
\endinput
149