summaryrefslogtreecommitdiff
path: root/tex/context/base/node-rul.mkiv
blob: 90bcd9e403f42cc14c7a88db89cd2172bd9c6ffb (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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
%D \module
%D   [       file=node-rul,
%D        version=2009.11.03, % 1995.10.10,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Bars,
%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.

% todo: ex and and em traveling with attribute

\writestatus{loading}{ConTeXt Core Macros / Bars}

%D The name of this file might change.

%D \macros
%D   {underbar,underbars,
%D    overbar,overbars,
%D    overstrike,overstrikes,
%D    setupbar}
%D
%D In the rare case that we need undelined words, for instance
%D because all font alternatives are already in use, one can
%D use \type{\underbar} and \type{\overstrike} and their plural
%D forms.
%D
%D \startbuffer
%D \underbars{drawing \underbar{bars} under words is a typewriter leftover}
%D \overstrikes{striking words makes them \overstrike{unreadable} but
%D sometimes even \overbar{top lines} come into view.}
%D \stopbuffer
%D
%D \typebuffer
%D
%D \startvoorbeeld
%D \startlines
%D \getbuffer
%D \stoplines
%D \stopvoorbeeld
%D
%D The next macros are derived from the \PLAIN\ \TEX\ one, but
%D also supports nesting. The \type{$} keeps us in horizontal
%D mode and at the same time applies grouping.
%D
%D \showsetup{underbar}
%D \showsetup{underbars}
%D \showsetup{overbar}
%D \showsetup{overbars}
%D \showsetup{overstrike}
%D \showsetup{overstrikes}
%D
%D \showsetup{setupunderbar}

%D todo: mkvi this file ... no redefine, just pass all parameters, too messy now
%D (due to grouping) so better hash settings at the lua end

\unprotect

%definesystemattribute[ruled]
%definesystemattribute[shifted]

\registerctxluafile{node-rul}{1.001}

\installcommandhandler \??on {bar} \??on

\newtoks\checkalldefinedbars

\let\setupbars\setupbar

\appendtoks
   \ifsecondargument
     \dodefinebarindeed\currentbar
   \else
     \the\checkalldefinedbars
   \fi
\to \everysetupbar

\appendtoks
   \ifcsname\??on:\currentbar:c\endcsname
     \csname\??on:\currentbar:c\endcsname\zerocount
   \else
     \expandafter\newcount\csname\??on:\currentbar:c\endcsname
   \fi
   \normalexpanded{\checkalldefinedbars{\doredefinebar{\currentbar}\the\checkalldefinedbars}}%
   \dodefinebarindeed\currentbar
   \setuevalue\currentbar{\doruled{\currentbar}}%
\to \everydefinebar

\unexpanded\def\dodefinebarindeed#1%
  {\begingroup
   \edef\currentbar{#1}%
   \doifsomethingelse{\barparameter\c!color}
     {\donetrue\colored[\barparameter\c!color]}
     {\donefalse}%
   \normalexpanded
     {\endgroup
      \scratchcounter\ctxlua{nodes.rules.define {
        method        = \barparameter\c!method,
        offset        = \barparameter\c!offset,
        continue      = "\barparameter\c!continue",
        dy            = \barparameter\c!dy,
        rulethickness = \barparameter\c!rulethickness,
        unit          = "\barparameter\c!unit",
        order         = "\barparameter\c!order",
        max           = \barparameter\c!max,
        ma            = \ifdone\the\attribute\colormodelattribute  \else0\fi,
        ca            = \ifdone\the\attribute\colorattribute       \else0\fi,
        ta            = \ifdone\the\attribute\transparencyattribute\else0\fi
      }}}%
   \setevalue{\??on#1:a}{\the\scratchcounter}}

\let\doredefinebar\dodefinebarindeed

\unexpanded\def\doruled#1%
  {\groupedcommand{\dodoruled{#1}}\relax}

\def\dodoruled
  {\ctxlua{nodes.rules.enable()}%
   \glet\dodoruled\dodoruledindeed
   \dodoruled}

\def\dodoruledindeed#1% maybe reverse the 1000
  {\advance\csname\??on:#1:c\endcsname\plusone % local ?
   \scratchcounter\csname\??on:#1:c\endcsname
   \attribute\ruledattribute\numexpr
     1000*\scratchcounter
     +\csname\??on#1\ifcsname\??on#1:\number\scratchcounter\s!parent\endcsname:\number\scratchcounter\fi:a\endcsname
   \relax}

% ungrouped

\unexpanded\def\startbar[#1]%
  {\begingroup
   \dodoruled{#1}}

\unexpanded\def\stopbar
  {\endgroup}

\newcount\currentbarnesting % todo: same as colors

\unexpanded\def\pushbar[#1]%
  {\global\advance\currentbarnesting\plusone
   \expandafter\edef\csname\??on:s:\number\currentbarnesting\endcsname
     {\attribute\ruledattribute\the\attribute\ruledattribute}% stack
   \dodoruled{#1}}

\unexpanded\def\popbar
  {\csname\??on:s:\number\currentbarnesting\endcsname
   \global\advance\currentbarnesting\minusone}

\setupbars
  [\c!method=0,                 % new: 0=center nested, 1=stack nested
   \c!continue=\v!no,
   \c!offset=0,                 % upwards, replaces: topoffset bottomoffset
   \c!dy=0,
   \c!max=3,
   \c!rulethickness=.1,
   \c!order=\v!foreground,
   \c!unit=ex,                  % so now we are relative
   \c!color=]                   % replaces: rulecolor

% \definebar[touchbar]    [\c!method=0,\c!dy=-0.4,\c!offset=-0.0]
% \definebar[touchbars]   [touchbar]   [\c!continue=\v!yes]

\definebar[\v!overstrike]  [\c!method=0,\c!dy= 0.4,\c!offset= 0.5,\c!continue=\v!yes]
\definebar[\v!underbar]    [\c!method=1,\c!dy=-0.4,\c!offset=-0.3,\c!continue=\v!yes]
\definebar[\v!overbar]     [\c!method=1,\c!dy= 0.4,\c!offset= 1.8,\c!continue=\v!yes]

\definebar[\v!overstrikes] [\v!overstrike] [\c!continue=\v!no]
\definebar[\v!underbars]   [\v!underbar]   [\c!continue=\v!no]
\definebar[\v!overbars]    [\v!overbar]    [\c!continue=\v!no]

% we want these always so ...

\expandafter\let\expandafter\overstrike \csname\v!overstrike \endcsname
\expandafter\let\expandafter\underbar   \csname\v!underbar   \endcsname
\expandafter\let\expandafter\overbar    \csname\v!overbar    \endcsname
\expandafter\let\expandafter\overstrikes\csname\v!overstrikes\endcsname
\expandafter\let\expandafter\underbars  \csname\v!underbars  \endcsname
\expandafter\let\expandafter\overbars   \csname\v!overbars   \endcsname

\unexpanded\def\setupunderbar[#1]% too incompatible for the moment
  {}

%D This will move: (a bit duplicated)

\installcommandhandler \??ra {shift} \??ra

\newtoks\checkalldefinedshifts

\let\setupshifts\setupshift

\appendtoks
  \ifsecondargument
     \dodefineshiftindeed\currentshift
   \else
     \the\checkalldefinedshifts
   \fi
\to \everysetupshift

\appendtoks
   \ifcsname\??ra:\currentshift:c\endcsname
     \csname\??ra:\currentshift:c\endcsname\zerocount
   \else
     \expandafter\newcount\csname\??ra:\currentshift:c\endcsname
   \fi
   \normalexpanded{\checkalldefinedshifts{\doredefineshift{\currentshift}\the\checkalldefinedshifts}}%
   \dodefineshiftindeed{\currentshift}%
   \setuevalue\currentshift{\doshifted{\currentshift}}%
\to \everydefineshift

\unexpanded\def\dodefineshiftindeed#1%
  {\begingroup
   \edef\currentshift{#1}%
   \normalexpanded
     {\endgroup
      \scratchcounter\ctxlua{nodes.shifts.define {
        method   = \shiftparameter\c!method,
        continue = "\shiftparameter\c!continue",
        dy       = \shiftparameter\c!dy,
        unit     = "\shiftparameter\c!unit",
      }}}%
   \setevalue{\??ra#1:a}{\the\scratchcounter}}

\let\doredefineshift\dodefineshiftindeed

% \unexpanded\def\doshifted#1%
%   {\groupedcommand{\dodoshifted{#1}}\relax}

\def\dodoshifted
  {\ctxlua{nodes.shifts.enable()}%
   \glet\dodoshifted\dodoshiftedindeed
   \dodoshifted}

\def\dostartisolation{\signalcharacter}
\def\dostopisolation {\signalcharacter}
\def\doisolator      {\signalcharacter}

\def\doisolatedgroupedalign#1#2%
  {\groupedcommand
     {\begingroup\dostartisolation\begingroup#1}
     {#2\endgroup\dostopisolation\endgroup}}

\def\dosetupisolatedalign#1%
  {\doisolator
   \setupalign[#1]\relax}

\def\dodoshiftedindeed#1%
  {\def\currentshift{#1}%
   \advance\csname\??ra:#1:c\endcsname\plusone
   \scratchcounter\csname\??ra:#1:c\endcsname
   \attribute\shiftedattribute\numexpr1000*\scratchcounter
     +\csname\??ra#1\ifcsname\??ra#1:\number\scratchcounter\s!parent\endcsname:\number\scratchcounter\fi:a\endcsname
   \dosetshiftattributes\c!style\c!color
   \dosetupisolatedalign{\shiftparameter\c!align}}

\unexpanded\def\doshifted#1%
  {\doisolatedgroupedalign{\dodoshifted{#1}}{}}

\unexpanded\def\startshift[#1]%
  {\begingroup
   \dodoshifted{#1}}

\unexpanded\def\stopshift
  {\endgroup}

\setupshifts
  [\c!method=0,
   \c!continue=\v!no,
   \c!dy=0,
   \c!unit=ex,
   \c!align=,
   \c!style=,
   \c!color=]

\def\v!shiftup  {shiftup}
\def\v!shiftdown{shiftdown}

\defineshift [\v!shiftup]   [\c!method=0,\c!dy=-1,\c!unit=ex,\c!continue=\v!yes,\c!style=\txx,\c!color=]
\defineshift [\v!shiftdown] [\c!method=1,\c!dy=.3,\c!unit=ex,\c!continue=\v!yes,\c!style=\txx,\c!color=]

% we want these always so ...

\expandafter\let\expandafter\shiftup   \csname\v!shiftup   \endcsname
\expandafter\let\expandafter\shiftdown \csname\v!shiftdown \endcsname

\protect \endinput

% obsolete:

\setupunderbar
  [\c!alternative=a,
   \c!rulethickness=\linewidth,
   \c!bottomoffset=1.5pt,
   \c!topoffset=2.5pt,
   \c!rulecolor=]