strc-mar-old.mkxl /size: 5110 b    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=strc-mar,
3%D        version=2008.10.20,
4%D          title=\CONTEXT\ Structure Macros,
5%D       subtitle=Markings,
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 / Markings}
15
16\registerctxluafile{strc-mar-old}{autosuffix}
17
18\unprotect
19
20%D Synchronizing marks is a rather tricky and messy business. When setting a mark, a
21%D node is added to the list in order for to \TEX\ be able to figure out the 3
22%D current marks when a page is made (last mark on previous page, first on current
23%D page, last on current page; in \LUATEX\ we might at one point have the first on
24%D the next page as well).
25%D
26%D Resetting a mark is not easy. An empty one will not erase the last one on the
27%D previous page for instance. In \LUATEX\ we can clear a marks state register with
28%D \type {\clearmarks} but since this is an immediate operation it might have
29%D unwanted side effects when \TEX\ has collected several pages of text and
30%D finishing off these pages uses marks.
31%D
32%D In \MKIV\ we provide an alternative model that permits some more control over the
33%D way marks are used. It is not entirely compatible with \MKII\ or previous \MKIV\
34%D implementations but in practice this is not a real problem. It's also easier now
35%D to extend this mechanism.
36
37% first last previous next top bottom [:nocheck]
38% current
39% default page all keep
40
41\definesystemattribute [marks] [global]
42
43\installcorenamespace{marking}
44
45\installcommandhandler \??marking {marking} \??marking
46
47\newconditional\inhibitgetmarking % will become private
48\newconditional\inhibitsetmarking % will become private
49
50\newtoks       \everymarking
51
52\appendtoks
53    \clf_definemarking{\currentmarking}{\currentmarkingparent}%
54\to \everydefinemarking
55
56\permanent\protected\tolerant\def\relatemarking           [#1]#*[#2]{\clf_relatemarking{#1}{#2}}
57\permanent\protected\tolerant\def\resetmarking                  [#1]{\clf_resetmarking{#1}}
58\permanent\protected\tolerant\def\synchronizemarking[#1]#*[#2]#*[#3]{\ifvoid#2\else\clf_synchronizemarking{#1}#2{#3}\fi}
59\permanent                   \def\doifelsemarking                 #1{\clf_doifelsemarking{#1}}  % no \noexpanded
60
61\aliased\let\clearmarking\resetmarking % different in the new situation
62
63\def\strc_markings_synchronize#1#2#3{\ifvoid#2\else\clf_synchronizemarking{#1}#2{#3}\fi} % called in page-ini
64
65\permanent\protected\tolerant\def\setmarking[#1]#:#2%
66  {\ifconditional\inhibitsetmarking\else
67     \doifelse{\namedmarkingparameter{#1}\c!expansion}\v!yes
68       {\clf_setmarking{#1}{#2}}%
69       {\clf_setmarking{#1}{\detokenize{#2}}}%
70   \fi}
71
72\aliased\let\marking        \setmarking
73\aliased\let\doifmarkingelse\doifelsemarking
74
75% defaults
76
77\setupmarking
78  [\c!expansion=\v!no,
79   \c!separator=\space\emdash\space,
80   \c!filtercommand=\firstofoneargument,
81   \c!state=\v!start]
82
83% fetching, regular interface
84
85\permanent\protected\def\getmarking
86  {\ifconditional\inhibitgetmarking
87     \expandafter\strc_markings_get_nop
88   \else
89     \expandafter\strc_markings_get_yes
90   \fi}
91
92\tolerant\def\strc_markings_get_nop[#-]#*[#-]#*[#-]%
93  {}
94
95\tolerant\def\strc_markings_get_yes[#1]#*[#2]#*[#3]%
96  {\ifcstok{\namedmarkingparameter{#1}\c!state}\v!start
97     \begingroup
98     \setsystemmode\v!marking
99     \the\everymarking
100     \ifparameter#3\or
101       \clf_getmarking{#1}{#2}{#3}%
102     \else
103       \clf_getmarking{#1}{\v!page}{#2}%
104     \fi
105     \endgroup
106  \fi}
107
108% the fetchers are fully expandable: [name][method]
109
110\permanent\tolerant\def\fetchonemark[#1]#*[#2]{\ifconditional\inhibitgetmarking\else\clf_fetchonemark {#1}{\v!page}{#2}\fi}
111\permanent\tolerant\def\fetchtwomarks     [#1]{\ifconditional\inhibitgetmarking\else\clf_fetchtwomarks{#1}{\v!page}\fi}
112\permanent\tolerant\def\fetchallmarks     [#1]{\ifconditional\inhibitgetmarking\else\clf_fetchallmarks{#1}{\v!page}\fi}
113
114\aliased\let\fetchmark\fetchonemark
115
116% also fully expandable but here we have: [name][range][method]
117
118\permanent\tolerant\def\fetchonemarking[#1]#*[#2]#*[#3]{\ifconditional\inhibitgetmarking\else\clf_fetchonemark {#1}{#2}{#3}\fi}
119\permanent\tolerant\def\fetchtwomarkings     [#1]#*[#2]{\ifconditional\inhibitgetmarking\else\clf_fetchtwomarks{#1}{#2}\fi}
120\permanent\tolerant\def\fetchallmarkings     [#1]#*[#2]{\ifconditional\inhibitgetmarking\else\clf_fetchallmarks{#1}{#2}\fi}
121
122\aliased\let\fetchmarking\fetchonemarking
123
124\permanent\def\markingseparator#1{\namedmarkingparameter{#1}\c!separator}
125\permanent\def\markingcommand  #1{\namedmarkingparameter{#1}\c!filtercommand}
126
127%D Experimental:
128%D
129%D \starttyping
130%D \definemarking[boxmark]
131%D
132%D \setbox0\ruledvbox{
133%D     \marking[boxmark]{tufte} \input tufte \par
134%D     \marking[boxmark]{ward}  \input ward  \par
135%D }
136%D
137%D \synchronizemarking[zerobox][0] \box0
138%D
139%D marks: (\getmarking[boxmark][zerobox][first],\getmarking[boxmark][zerobox][last])
140%D \stoptyping
141
142\protect \endinput
143