summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/strc-sbe.mkxl
blob: f2bc80659465c91c06972e70ae3b8d07892fe80a (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
%D \module
%D   [       file=strc-sbe,
%D        version=2008.10.20,
%D          title=\CONTEXT\ Structure Macros,
%D       subtitle=Section Block Environments,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Structure Macros / Section Block Environments}

\unprotect

% \def\ChapterEntry#1#2#3%
%   {chapter : \hbox to \hsize{\strut\bf#2\hss#3}\endgraf\placelist[section]}
%
% \startfrontmatter % optional
%   \placelist[chapter][alternative=command,command=\ChapterEntry,criterium=text] \page
% \stopfrontmatter  % optional
%
% \startbodymatter % optional
%   \chapter{first}  \section{one}   test \section{two}  test \page
%   \chapter{second} \section{alpha} test \section{beta} test \page
% \stopbodymatter  % optional

\installcorenamespace{sectionblock}

\installcommandhandler \??sectionblock {sectionblock} \??sectionblock

\setupsectionblock
  [\c!number=\v!yes,
   \c!page=\v!right] % otherwise marks are reset too soon

\newtoks\everybeforesectionblock
\newtoks\everyaftersectionblock

\let\strc_sectionblock_define_normal\definesectionblock

\permanent\overloaded\tolerant\protected\def\definesectionblock[#1]#*[#2]#*[#3]% singular plural settings
  {\strc_sectionblock_define_normal[#1][#3]%
  %\expandafter\newif\csname if#2\endcsname % obsolete
   \strc_sectionblock_set_environment{#1}\empty
   \frozen\protected\defcsname\e!start#2\endcsname{\startsectionblock[#1]}%
   \frozen\protected\defcsname\e!stop #2\endcsname{\stopsectionblock}}

\ifdefined \resetallstructuremarks \else
    \let\resetallstructuremarks\relax
\fi

\def\strc_sectionblock_handle_page
  {\edef\p_strc_sectionblock_page{\sectionblockparameter\c!page}%
   \ifempty\p_strc_sectionblock_page \else
      \page[\p_strc_sectionblock_page]%
   \fi}

\appendtoks
    \strc_sectionblock_handle_page
    \resetallstructuremarks
    \strc_sectionblock_get_environment\currentsectionblock
    \sectionblockparameter\c!before % don't move
    \dostarttagged\t!division\currentsectionblock % no parents
\to \everybeforesectionblock

\appendtoks
    \sectionblockparameter\c!after % don't move
    \strc_sectionblock_handle_page
    \dostoptagged
    \resetallstructuremarks
\to \everyaftersectionblock

\permanent\tolerant\protected\def\setsectionblock[#1]#*[#2]% used to set the default
  {\cdef\currentsectionblock{#1}% from now on we assume a value
   \setupcurrentsectionblock[#2]%
   \clf_setsectionblock{#1}
      bookmark {\sectionblockparameter\c!bookmark}%
   \relax}

\mutable\lettonothing\currentsectionblock % was \s!unknown

\permanent\tolerant\protected\def\startsectionblock[#1]#*[#2]%
  {%\ctxlua{structures.counters.check(0)}% we assume sane usage of \page, as this is the only workable place (in push)
   \begingroup
   \cdef\currentsectionblock{#1}% from now on we assume a value
   \setupcurrentsectionblock[#2]%
   \clf_pushsectionblock{#1}
     bookmark {\sectionblockparameter\c!bookmark}%
   \relax
  %\csname #1true\endcsname % obsolete
   \setsystemmode\currentsectionblock
   \the\everybeforesectionblock\relax
   \showmessage\m!structures1\currentsectionblock}

\permanent\protected\def\stopsectionblock
  {\showmessage\m!structures2\currentsectionblock
   \the\everyaftersectionblock\relax
   \clf_popsectionblock
   \endgroup}

%D \starttyping
%D \startsectionblockenvironment[frontpart]
%D   \setupnumber[userpage][numberconversion=romannumerals,start=1]
%D \stopsectionblockenvironment
%D
%D \startsectionblockenvironment[bodypart]
%D   \setupnumber[userpage][numberconversion=numbers,start=1]
%D \stopsectionblockenvironment
%D
%D \startsectionblockenvironment[backpart]
%D   \setupnumber[userpage][numberconversion=numbers,start=1]
%D \stopsectionblockenvironment
%D
%D \starttext
%D   \startfrontmatter \chapter{test} \stopfrontmatter
%D   \startbodymatter  \chapter{test} \stopbodymatter
%D   \startappendices  \chapter{test} \stopappendices
%D \stoptext
%D \stoptyping

\installcorenamespace{sectionblockenvironment}

\protected\def\strc_sectionblock_set_environment#1#2%
  {\defcsname\??sectionblockenvironment#1\endcsname{#2}}

\protected\def\strc_sectionblock_get_environment#1%
  {\csname\??sectionblockenvironment#1\endcsname}

\permanent\tolerant\protected\defcsname\e!start\v!sectionblockenvironment\endcsname[#1]% evt \pushendofline \popendofline
  {\grabuntil{\e!stop\v!sectionblockenvironment}{\strc_sectionblock_set_environment{#1}}}

\permanent\protected\expandafter\lettonothing\csname\e!stop\v!sectionblockenvironment\endcsname

\protect \endinput