summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/strc-swd.mkii
blob: 4a71b8781b8988eb8a26a73bec8defae4fcadd38 (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
%D \module
%D   [       file=strc-swd,
%D        version=2007.08.14,
%D          title=\CONTEXT\ Structure Macros,
%D       subtitle=Section Worlds,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D This is a prelude to a rewrite of sectioning.

% options : before after setups page text number label bookmark
% dodo    : listtext
%
% \startsectionworld[chapter][text={Test}]
% \stopsectionworld

\writestatus{loading}{ConTeXt Structure Macros / Sectionworlds}

\unprotect

\ifx\pushvalue\undefined

    \def\pushvalue#1{\expandafter\pushmacro\csname#1\endcsname}
    \def\popvalue #1{\expandafter\popmacro \csname#1\endcsname}

\fi

% brrr

\def\csnameexpanded#1#2%
  {\@EA\@EA\@EA\@EA\@EA\@EA\@EA#1\@EA\@EA\@EA\@EA\@EA\@EA\@EA#2\@EA\@EA\@EA\@EA\@EA\@EA\@EA}

\def\csnameexpandedoneargument#1#2%
  {\csnameexpanded\def\csexpandeda{#2}%
   \@EA#1\@EA{\csexpandeda}}

\def\csnameexpandedtwoarguments#1#2#3%
  {\csnameexpanded\def\csexpandeda{#2}%
   \csnameexpanded\def\csexpandedb{#3}%
   \@EA\@EA\@EA#1\@EA\@EA\@EA{\@EA\csexpandeda\@EA}\@EA{\csexpandedb}}

\def\csnameexpandedthreearguments#1#2#3#4%
  {\csnameexpanded\def\csexpandeda{#2}%
   \csnameexpanded\def\csexpandedb{#3}%
   \csnameexpanded\def\csexpandedc{#4}%
   \@EA\@EA\@EA\@EA\@EA\@EA\@EA#1\@EA\@EA\@EA\@EA\@EA\@EA\@EA{\@EA\@EA\@EA\csexpandeda\@EA\@EA\@EA}\@EA\@EA\@EA{\@EA\csexpandedb\@EA}\@EA{\csexpandedc}}

% \def\xx{XX}\setvalue{xx:yy}{abc \xx def}\def\param#1{\csname xx:#1\endcsname}
% \def\testa    #1{\defconvertedargument\ascii{#1}{\tttf\ascii}}
% \def\testb  #1#2{\defconvertedargument\ascii{#1 #2}{\tttf\ascii}}
% \def\testc#1#2#3{\defconvertedargument\ascii{#1 #2 #3}{\tttf\ascii}}
% \noindent 1 \csnameexpandedoneargument   \testa{\param{yy}}
% \noindent 2 \csnameexpandedtwoarguments  \testb{\param{yy}}{\param{yy}}
% \noindent 3 \csnameexpandedthreearguments\testc{\param{yy}}{\param{yy}}{\param{yy}}

% rewrite the sectioning to use the variables, a bit tricky because then
% we need a special expansion trick

\def\sectionworldparameter    #1{\csname\??sw\currentsectionworldname#1\endcsname}
\def\pushsectionworldparameter#1{\expandafter\pushmacro\csname\??sw\currentsectionworldname#1\endcsname}
\def\popsectionworldparameter #1{\expandafter\popmacro \csname\??sw\currentsectionworldname#1\endcsname}

\def\setupsectionworld
  {\dodoubleargument\dosetupsectionworld}

\def\dosetupsectionworld[#1][#2]%
  {\getparameters[\??sw#1][#2]} % maybe some extra things

\def\dochecksectionworld#1%
  {\ifcsname\??sw\currentsectionworldname\endcsname\else
     \getparameters
       [\??sw\currentsectionworldname]
       [\c!before=,
        \c!after=,
        \c!setups=,
        \c!page=]%
   \fi}

\def\startsectionworld
  {\dodoubleargument\dostartsectionworld}

\def\dostartsectionworld[#1][#2]%
  {\pushmacro\currentsectionworldname
   \def\currentsectionworldname{#1}%
   \dochecksectionworld\currentsectionworldname
   \pushsectionworldparameter\c!before
   \pushsectionworldparameter\c!after
   \pushsectionworldparameter\c!setups
   \getparameters
     [\??sw\currentsectionworldname]
     [\c!text=,\c!number=\finalsectionnumber,\c!label=,\c!bookmark=,#2]%
   \doifsomething{\sectionworldparameter\c!page}
     {\setsectieenkoppeling\currentsectionworldname
     %\handlepagebreak\currentsectionworldname
      \checknexthead\handlepagebreak\currentsectionworldname}%
   \sectionworldparameter\c!before
   \begingroup
   \doifsomething{\sectionworldparameter\c!page}
     {\settrue\ignorehandlepagebreak}%
   \doifsomething{\sectionworldparameter\c!setups}
     {\setups[\sectionworldparameter\c!setups]}%
   \csnameexpandedthreearguments \doconstructheadwithvars
     {\sectionworldparameter\c!label }%
     {\sectionworldparameter\c!number}%
     {\sectionworldparameter\c!text  }%
   \doifsomething{\sectionworldparameter\c!bookmark}
     {\expanded{\bookmark[\sectionworldparameter\c!bookmark]}}%
   \ignorespaces} % for inline heads

\def\doconstructheadwithvars#1%#2#3%
  {\dodododoconstructhead\currentsectionworldname[#1]}% {#2}{#3}}

\def\stopsectionworld
  {\endgraf
   \endgroup
   \sectionworldparameter\c!after
   \popsectionworldparameter\c!setups
   \popsectionworldparameter\c!after
   \popsectionworldparameter\c!before
   \popmacro\currentsectionworldname}

\protect \endinput