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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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
191
192
193
194
|
%D \module
%D [ file=anch-bar,
%D version=2003.03.16,
%D title=\CONTEXT\ Anchoring Macros,
%D subtitle=Margin Bars and alike,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright=PRAGMA-ADE]
%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 Anchoring Macros / Margin Bars}
\unprotect
%D We will implement a sidebar mechanism using the
%D functionality from \type {core-pos}.
%D
%D \starttyping
%D \definesidebar[whow][rulecolor=green,distance=]
%D
%D \input tufte \par
%D \startsidebar
%D \input tufte \par
%D \input tufte \par
%D \startsidebar[whow]
%D \input tufte \par
%D \input tufte \par
%D \input tufte
%D \stopsidebar \par
%D \input tufte \par
%D \input tufte
%D \stopsidebar \par
%D \input tufte \par
%D \input tufte \par
%D \startsidebar
%D \input tufte \par
%D \input tufte \par
%D \input tufte \par
%D \input tufte \par
%D \input tufte
%D \stopsidebar \par
%D \input tufte \par
%D \input tufte \par
%D \startsidebar
%D \input tufte
%D \input tufte
%D \input tufte
%D \input tufte
%D \input tufte
%D \stopsidebar
%D \stoptyping
\newcount\currentsidebar
\newdimen\sidebardistance
\def\setupsidebars
{\dodoubleargument\dosetupsidebars}
\def\dosetupsidebars[#1][#2]%
{\ifsecondargument
\getparameters[\??br#1][#2]%
\else
\getparameters[\??br][#1]%
\fi}
% \setupMPvariables
% [mpos:bar]
% [linecolor=red,
% linewidth=2pt,
% distance=5pt]
\setupsidebars
[\c!rulethickness=2pt,
\c!rulecolor=red,
\c!distance=.5\bodyfontsize]
\def\definesidebar
{\dodoubleempty\dodefinesidebar}
\def\dodefinesidebar[#1][#2]%
{\copyparameters
[\??br#1][\??br]
[\c!rulethickness,\c!rulecolor,\c!distance]%
\getparameters
[\??br#1][#2]}
\def\startsidebar
{\dosingleempty\dostartsidebar}
\def\dostartsidebar[#1]%
{\bgroup
\dontleavehmode
\checktextbackgrounds
\global\advance\currentsidebar\plusone
\doifelsenothing{#1}
{\advance\sidebardistance\@@brdistance}
{\doifelsevaluenothing{\??br#1\c!distance}
{\advance\sidebardistance\@@brdistance}
{\sidebardistance\getvalue{\??br#1\c!distance}}}%
\startpositionoverlay{text-1}%
\expanded{\setMPpositiongraphicrange
{b:side:\the\currentsidebar}%
{e:side:\the\currentsidebar}%
{mpos:bar}%
{self=side:\the\currentsidebar,
linewidth=\getvalue{\??br#1\c!rulethickness},
linecolor=\getvalue{\??br#1\c!rulecolor},
distance=\the\sidebardistance}}%
\stoppositionoverlay
\bpos{side:\the\currentsidebar}\ignorespaces}
% \def\dostopsidebar#1%
% {\removelastspace\tpos{side:#1}\carryoverpar\egroup}
\def\stopsidebar
{\removelastspace\tpos{side:\the\currentsidebar}\carryoverpar\egroup}
\startMPpositionmethod{mpos:bar}
\startMPpositiongraphic{mpos:bar}{linecolor,linewidth,distance}%
StartPage ;
path p ; p :=
if \MPp\MPbself=\MPp\MPeself :
(xpart ulcorner Field[Text][Text],\MPy\MPbself+\MPh\MPbself) --
(xpart llcorner Field[Text][Text],\MPy\MPeself-\MPd\MPeself) ;
elseif RealPageNumber=\MPp\MPbself :
(xpart ulcorner Field[Text][Text],\MPy\MPbself+\MPh\MPbself) --
(llcorner Field[Text][Text]) ;
elseif RealPageNumber=\MPp\MPeself :
(ulcorner Field[Text][Text]) --
(xpart llcorner Field[Text][Text],\MPy\MPeself-\MPd\MPeself) ;
else :
(ulcorner Field[Text][Text]) --
(llcorner Field[Text][Text]) ;
fi ;
p := p shifted (-llcorner Field[Text][Text]-(\MPvar{distance},0)) ;
interim linecap := butt ;
draw p
withpen pencircle scaled \MPvar{linewidth}
withcolor \MPvar{linecolor} ;
StopPage ;
\stopMPpositiongraphic
\MPpositiongraphic{mpos:bar}{}%
\stopMPpositionmethod
%D We now reimplement the margin rules handler defined in
%D \type {core-rul}:
%D
%D \setupmarginrules[level=5]
%D
%D \startmarginrule[1]
%D First we set the level at~5. Next we typeset this first
%D paragraph as a level~1 one. As expected no rule show up.
%D \stopmarginrule
%D
%D \startmarginrule[5]
%D The second paragraph is a level~5 one. As we can see here,
%D the marginal rule gets a width according to its level.
%D \stopmarginrule
%D
%D \startmarginrule[8]
%D It will of course be no surprise that this third paragraph
%D has a even thicker margin rule. This behavior can be
%D overruled by specifying the width explictly.
%D \stopmarginrule
\definesidebar
[\v!margin]
[\c!rulecolor=\s!black,
\c!rulethickness=\@@karulethickness,
\c!distance=\dimexpr\leftmargindistance-\@@karulethickness/2\relax]
\definecomplexorsimple\startmarginrule
\def\simplestartmarginrule
{\complexstartmarginrule[1]}
\def\complexstartmarginrule[#1]%
{\bgroup
\ifnum#1<\@@kalevel\relax
\let\stopmarginrule\egroup
\else
\def\@@kadefaultwidth{#1}%
\let\stopmarginrule\dostopmarginrule
\@EA\startsidebar\@EA[\@EA\v!margin\@EA]%
\fi}
\def\dostopmarginrule
{\stopsidebar
\egroup}
\protect \endinput
|