1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Anchoring Macros Margin Bars}
15
16\unprotect
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\installcorenamespace{sidebar}
59
60\installcommandhandler \??sidebar {sidebar} \??sidebar
61
62\newcount\c_anch_sidebars_n
63\newcount\c_anch_sidebars_current
64\newdimen\d_anch_sidebars_distance
65\newcount\c_anch_sidebars_level
66
67
68
69
70
71
72
73\setupsidebar
74 [\c!rulethickness=\dimexpr\bodyfontsize6\relax,
75 \c!rulecolor=\s!black,
76 \c!alternative=0,
77 \c!topoffset=\zeropoint,
78 \c!bottomoffset=\zeropoint,
79 \c!distance=.5\bodyfontsize,
80 \c!level=,
81 \c!leftmargindistance=\zeropoint]
82
83\let\setupsidebars\setupsidebar
84
85\unexpanded\def\startsidebar
86 {\dodoubleempty\anch_sidebars_start}
87
88\def\anch_sidebars_start[#1][#2]
89 {\bgroup
90 \dontleavehmode
91 \advance\c_anch_sidebars_level\plusone
92 \global\advance\c_anch_sidebars_n\plusone
93 \c_anch_sidebars_current\c_anch_sidebars_n\relax
94 \doifelseassignment{#1}
95 {\edef\currentsidebar{\the\c_anch_sidebars_level}
96 \checksidebarparent
97 \setupcurrentsidebar[#1]}
98 {\def\currentsidebar{#1}
99 \setupcurrentsidebar[#2]}
100 \scratchdistance\sidebarparameter\c!distance\relax
101 \scratchdimen\sidebarparameter\c!leftmargindistance\relax
102 \edef\m_level{\sidebarparameter\c!level}
103 \ifx\m_level\empty
104 \ifnum\c_anch_sidebars_level=\plusone
105 \ifzeropt\scratchdimen
106 \advance\d_anch_sidebars_distance\scratchdistance\relax
107 \else
108 \d_anch_sidebars_distance\scratchdimen
109 \fi
110 \else
111 \advance\d_anch_sidebars_distance\scratchdistance\relax
112 \fi
113 \else
114 \ifnum\m_level=\plusone
115 \ifzeropt\scratchdimen
116 \advance\d_anch_sidebars_distance\scratchdistance\relax
117 \else
118 \d_anch_sidebars_distance\scratchdimen
119 \fi
120 \else
121 \d_anch_sidebars_distance\dimexpr\scratchdimen\numexpr\m_level\plusone\relax\dimexpr\scratchdistance\relax\relax
122 \fi
123 \fi
124 \startpositionoverlay{\v!text1}
125 \normalexpanded{\setMPpositiongraphicrange
126 {b:sidebar:\the\c_anch_sidebars_n}
127 {e:sidebar:\the\c_anch_sidebars_n}
128 {mpos:sidebar}
129 {self=sidebar:\the\c_anch_sidebars_n,
130 linewidth=\sidebarparameter\c!rulethickness,
131 linecolor=\sidebarparameter\c!rulecolor,
132 alternative=\sidebarparameter\c!alternative,
133 topoffset=\the\dimexpr\sidebarparameter\c!topoffset,
134 bottomoffset=\the\dimexpr\sidebarparameter\c!bottomoffset,
135 distance=\the\d_anch_sidebars_distance}
136 }
137 \stoppositionoverlay
138 \bpos{sidebar:\the\c_anch_sidebars_current}
139 \ignorespaces}
140
141\unexpanded\def\stopsidebar
142 {\removelastspace
143 \epos{sidebar:\the\c_anch_sidebars_current}
144 \carryoverpar\egroup}
145
146
147
148
149\startMPpositionmethod{mpos:sidebar}
150 \startMPpositiongraphic{mpos:sidebar}{linecolor,linewidth,distance,alternative}
151 anch_sidebars_draw (
152 \MPp\MPbself,\MPp\MPeself,\MPy\MPbself,\MPy\MPeself,\MPh\MPbself,\MPd\MPeself,
153 \MPx{\textanchor},\MPy{\textanchor},\MPw{\textanchor},\MPh{\textanchor},
154 \MPvar{alternative},\MPvar{distance},\MPvar{linewidth},\MPvar{linecolor},
155 \MPvar{topoffset}, \MPvar{bottomoffset}
156 ) ;
157 \stopMPpositiongraphic
158 \MPpositiongraphic{mpos:sidebar}{}
159\stopMPpositionmethod
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190\definesidebar
191 [\v!margin]
192 [\c!leftmargindistance=\dimexpr\leftmargindistance\sidebarparameter\c!rulethickness2\relax]
193
194\dorecurse{5}{\definesidebar[\v!margin:#1][\v!margin]}
195
196\unexpanded\def\setupmarginrule
197 {\dodoubleargument\anch_marginrules_setup}
198
199\def\anch_marginrules_setup[#1][#2]
200 {\ifsecondargument
201 \setupsidebar[\v!margin:#1][#2]
202 \else
203 \setupsidebar[\v!margin][#1]
204 \fi}
205
206\let\setupmarginrules\setupmarginrule
207
208\unexpanded\def\startmarginrule
209 {\dosingleempty\anch_marginrules_start}
210
211\def\anch_marginrules_start[#1]
212 {\edef\m_anch_marginrules_kind{#1}
213 \ifx\m_anch_marginrules_kind\empty
214 \anch_sidebars_start[\v!margin][]
215 \else
216 \doifelseassignment\m_anch_marginrules_kind
217 {\anch_sidebars_start[\v!margin][#1]}
218 {\anch_marginrules_check{#1}
219 \anch_sidebars_start[\v!margin:#1][\c!level=#1]}
220 \fi}
221
222\def\anch_marginrules_check#1
223 {\doifnotcommandhandler\??sidebar{\v!margin:#1}{\definesidebar[\v!margin:#1][\v!margin]}}
224
225\let\stopmarginrule\stopsidebar
226
227\protect \endinput
228 |