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