node-rul.mkxl /size: 23 Kb    last modification: 2025-02-21 11:03
1%D \module
2%D   [       file=node-rul,
3%D        version=2009.11.03, % 1995.10.10,
4%D          title=\CONTEXT\ Core Macros,
5%D       subtitle=Bars,
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% todo: ex and and em traveling with attribute
15% todo: this will move to typo-rul + ctxcommands
16
17\writestatus{loading}{ConTeXt Core Macros / Bars}
18
19%D \macros
20%D   {underbar,underbars,
21%D    overbar,overbars,
22%D    overstrike,overstrikes,
23%D    setupbar}
24%D
25%D In the rare case that we need undelined words, for instance because all font
26%D alternatives are already in use, one can use \type {\underbar} and \type
27%D {\overstrike} and their plural forms.
28%D
29%D \startbuffer
30%D \underbars {drawing \underbar{bars} under words is a typewriter leftover}
31%D \overstrikes {striking words makes them \overstrike {unreadable} but
32%D sometimes even \overbar {top lines} come into view.}
33%D \stopbuffer
34%D
35%D \typebuffer
36%D
37%D \startlines
38%D \getbuffer
39%D \stoplines
40%D
41%D The formal definitions are:
42%D
43%D \showsetup{underbar}
44%D \showsetup{underbars}
45%D \showsetup{overbar}
46%D \showsetup{overbars}
47%D \showsetup{overstrike}
48%D \showsetup{overstrikes}
49%D
50%D \showsetup{setupbars}
51%D
52%D Units can be any normal \TEX\ unit:
53%D
54%D \startbuffer
55%D \setupbars[unit=mm,rulethickness=1]     bar\startbar[underbar]foo\stopbar bar\blank
56%D \setupbars[unit=ex,rulethickness=1]     bar\startbar[underbar]foo\stopbar bar\blank
57%D \setupbars[unit=pt,rulethickness=1]     bar\startbar[underbar]foo\stopbar bar\blank
58%D \setupbars[unit=pt,rulethickness=10pt]  bar\startbar[underbar]foo\stopbar bar
59%D \stopbuffer
60%D
61%D \typebuffer \blank \getbuffer \blank
62%D
63%D As with many early usage of \LUA\ in \MKIV\ this mechanism explores a way
64%D to deal with local settings at the \TEX\ end and remembering parameters
65%D at the \LUA\ end. We might do things differently now, but as settings normally
66%D don't change that often, we're not in a hurry to do that now. The problem at
67%D the \LUA\ end is that we don't know when to clean up.
68
69\unprotect
70
71%definesystemattribute[ruled]
72%definesystemattribute[shifted]
73
74\newdimension\d_rule_width
75\newdimension\d_rule_height
76\newdimension\d_rule_depth
77\newdimension\d_rule_h
78\newdimension\d_rule_v
79\newdimension\d_rule_line
80\newdimension\d_rule_offset
81\newdimension\d_rule_factor
82
83\mutable\lettonothing\m_rule_direction
84%mutable\lettonothing\m_rule_factor
85\mutable\lettonothing\m_rule_option
86\mutable\lettonothing\m_rule_color
87
88\registerctxluafile{node-rul}{autosuffix}
89
90\installcorenamespace{bar}
91\installcorenamespace{barstack}
92
93\installcommandhandler \??bar {bar} \??bar
94
95\mutable\lettonothing\p_node_color  % of just \p_*
96\mutable\lettonothing\p_node_text
97\mutable\lettonothing\p_node_offset
98
99\aliased\let\setupbars\setupbar
100
101\appendtoks
102    \frozen\protected\instance\edefcsname\currentbar\endcsname{\node_rules_direct{\currentbar}}%
103\to \everydefinebar
104
105% \protected\def\node_rules_direct#1%
106%   {\groupedcommand
107%      {\node_rules_set{#1}\barparameter\c!left}%
108%      {\relax\barparameter\c!right}}
109
110\protected\def\node_rules_direct#1%
111  {\groupedcommand
112     {\dontleavehmode % this should not be needed but it is in \bTD
113      \node_rules_set{#1}%
114      \barparameter\c!left
115      }%\ignorespaces}%
116     {%\removeunwantedspaces
117      \barparameter\c!right}}
118
119\permanent\protected\def\inlinebar[#1]%
120  {\node_rules_direct{#1}}
121
122%D \overbar{Über} \underbar{Unterstrich \underbar{steigt \overbar{auf} den \underbar{Unterberg}}}.
123%D
124%D \underbar {\underbar {\samplefile{tufte}}}\par
125%D \underbar {\underdot {\samplefile{tufte}}}\par
126%D \underbar {\underdot {\samplefile{tufte}}}\par
127%D \underdot {\underbar {\samplefile{tufte}}}\par
128%D \underbars{\underdot {\samplefile{tufte}}}\par
129%D \underbar {\underdots{\samplefile{tufte}}}\par
130%D \underdots{\underdots{\samplefile{tufte}}}\par
131
132\newinteger\c_node_rules_nesting % todo: same as colors
133\newinteger\c_node_rules_level
134\newinteger\c_node_rules_up
135\newinteger\c_node_rules_down
136
137\permanent\protected\def\node_rules_set#1%
138  {\cdef\currentbar{#1}%
139   \advanceby\c_node_rules_level\plusone
140   \usebarstyleandcolor\c!foregroundstyle\c!foregroundcolor
141   \edef\p_node_color   {\barparameter\c!color}% todo
142   \edef\p_node_offset  {\barparameter\c!offset}%
143   \edef\p_node_continue{\barparameter\c!continue}%
144   % better is a dedicated key: up/down .. todo
145   \scratchcounter\barparameter\c!method\relax
146   \ifnum\scratchcounter=\plustwo
147     % offset is dimension
148   \orelse\ifnum\scratchcounter=\plusthree
149     % offset is dimension
150   \else
151     % offset is number
152     \advanceby\ifdim\p_node_offset\onepoint<\zeropoint\c_node_rules_down\else\c_node_rules_up\fi\plusone
153   \fi
154   \ifx\p_node_continue\v!always
155      \attribute\runningtextattribute \minusone
156      \let\p_node_continue\v!yes % not needed
157   \fi
158   \clf_setrule
159         method        \scratchcounter
160         continue      {\p_node_continue}%
161         rulethickness {\barparameter\c!rulethickness}%
162         mp            {\includeMPgraphic{\barparameter\c!mp}}
163         ma            \c_attr_colormodel
164         ca            \rawcolorattribute\p_node_color
165         ta            \rawtransparencyattribute\p_node_color
166         order         {\barparameter\c!order}%
167     \ifnum\scratchcounter=\plustwo
168         height        {\barparameter\c!height}%
169         depth         {\barparameter\c!depth}%
170       \ifchkdimexpr\p_node_offset\or
171         offset        \number\lastchkdimension % dimension
172       \fi
173     \orelse\ifnum\scratchcounter=\plusthree
174         height        {\barparameter\c!height}%
175         depth         {\barparameter\c!depth}%
176       \ifchkdimexpr\p_node_offset\or
177         offset        \number\lastchkdimension % dimension
178      \fi
179     \else
180         unit          {\barparameter\c!unit}%
181         level         \c_node_rules_level
182         stack         \ifdim\p_node_offset\onepoint<\zeropoint\c_node_rules_down\else\c_node_rules_up\fi
183         max           \barparameter\c!max\relaxedspace % number
184         offset        \p_node_offset\relaxedspace % number
185         dy            \barparameter\c!dy\relaxedspace % number, also fraction
186         empty         {\barparameter\c!empty}%
187       \ifempty{\barparameter\c!text}\else
188         text          \hbox{\lastnamedcs}%
189         repeat        {\barparameter\c!repeat}%
190       \fi
191     \fi
192   \relax}
193
194\permanent\protected\def\resetbar
195  {\c_attr_ruled\attributeunsetvalue}
196
197\permanent\protected\def\nobar
198  {\groupedcommand
199     {\resetbar\barparameter\c!left}%
200     {\relax\barparameter\c!right}}
201
202\permanent\protected\def\startbar[#1]%
203  {\begingroup
204   \node_rules_set{#1}%
205   \ignorespaces
206   \barparameter\c!left}
207
208\permanent\protected\def\stopbar
209  {\removeunwantedspaces
210   \barparameter\c!right
211   \endgroup}
212
213\permanent\protected\def\setbar[#1]%
214  {\node_rules_set{#1}}
215
216\aliased\let\directsetbar\node_rules_set
217
218% ungrouped % todo: use the lua based stacker
219
220\permanent\protected\def\pushbar[#1]%
221  {\global\advanceby\c_node_rules_nesting\plusone
222   \edefcsname\??barstack\the\c_node_rules_nesting\endcsname
223     {\c_node_rules_level\the\c_node_rules_level
224      \c_attr_ruled      \the\c_attr_ruled}%
225   \node_rules_set{#1}}
226
227\permanent\protected\def\popbar
228  {\csname\??barstack\the\c_node_rules_nesting\endcsname\relax
229   \global\advanceby\c_node_rules_nesting\minusone}
230
231% we can save some by havign defaults at the lua end
232
233\setupbars
234  [\c!method=0,                 % new: 0=center nested, 1=stack nested
235   \c!continue=\v!no,
236   \c!level=\v!yes,
237   \c!empty=,                   % new: yes = hide text
238   \c!offset=0,                 % upwards, replaces: topoffset bottomoffset
239   \c!dy=0,
240   \c!max=3,
241   \c!style=,
242   \c!rulethickness=.1,
243   \c!order=\v!foreground,
244   \c!height=\zeropoint,
245   \c!depth=\zeropoint,
246   \c!unit=ex,                  % so now we are relative
247   \c!color=]                   % replaces: rulecolor
248
249% \definebar[touchbar]    [\c!method=0,\c!dy=-0.4,\c!offset=-0.0]
250% \definebar[touchbars]   [touchbar]   [\c!continue=\v!yes]
251
252\pushoverloadmode
253
254\aliased\let\normalmathoverbar    \overbar
255\aliased\let\normalmathunderbar   \underbar
256%aliased\let\normalmathoverstrike \overstrike
257%aliased\let\normalmathunderstrike\understrike
258
259\definebar[\v!overbar]   [\c!method=1,\c!dy=0.4,\c!offset=1.8,\c!continue=\v!yes]
260\definebar[\v!underbar]  [\c!method=1,\c!dy=-0.4,\c!offset=-0.3,\c!continue=\v!yes]
261\definebar[\v!overstrike][\c!method=0,\c!dy=0.4,\c!offset=0.5,\c!continue=\v!yes]
262
263\definebar
264  [\v!understrike]
265  [\c!method=0,
266   \c!offset=1.375,
267   \c!rulethickness=2.5,
268   \c!continue=\v!yes,
269   \c!order=\v!background,
270   \c!color=lightgray]
271
272\definebar[\v!overbars]    [\v!overbar]    [\c!continue=\v!no]
273\definebar[\v!underbars]   [\v!underbar]   [\c!continue=\v!no]
274\definebar[\v!overstrikes] [\v!overstrike] [\c!continue=\v!no]
275\definebar[\v!understrikes][\v!understrike][\c!continue=\v!no]
276
277\definebar
278  [\v!hiddenbar]
279  [\v!underbar]
280  [\c!continue=\v!yes,
281   \c!empty=\v!yes,
282   \c!left=\zwj,
283   \c!right=\zwj]
284
285\definebar
286  [\v!outline]
287  [\c!method=2,
288   \c!offset=\zeropoint,
289   \c!rulethickness=0.25,
290   \c!continue=\v!yes,
291   \c!order=\v!background,
292   \c!color=lightgray]
293
294\definebar
295  [\v!outlined]
296  [\v!outline]
297  [\c!height=\strutht,
298   \c!depth=\strutdp]
299
300%D \starttyping
301%D \definebar[mybar][backgroundbar][offset=.25ex,color=red]
302%D
303%D \startformula
304%D             a      \alignhere= b + c \breakhere
305%D     \mybar {d + e} \alignhere= f     \breakhere
306%D             g      \alignhere= h + i
307%D \stopformula
308%D \stoptyping
309
310\definebar
311  [\v!backgroundbar] % joke
312  [\c!method=3,
313   \c!offset=0,
314   \c!rulethickness=0.25,
315   \c!continue=\v!yes,
316   \c!order=\v!background,
317   \c!color=lightgray]
318
319\definebar
320  [mathbackground]
321  [backgroundbar]
322  [\c!continue=\v!always,
323   \c!max=1,
324   \c!height=\strutht,
325   \c!depth=\strutdp]
326
327% \setupbar[\v!overstrike][continue=all]
328
329% we want these always so ...
330
331\ifdefined\normalmathunderbar
332    \enforced\permanent\expandafter\let\expandafter\normaltextunderbar\csname\v!underbar\endcsname
333    \enforced\permanent\protected\def\underbar{\mathortext\normalmathunderbar\normaltextunderbar}
334\else
335    \enforced\permanent\expandafter\let\expandafter\underbar\csname\v!underbar\endcsname
336\fi
337
338\ifdefined\normalmathoverbar
339    \enforced\permanent\expandafter\let\expandafter\normaltextoverbar\csname\v!overbar\endcsname
340    \enforced\permanent\protected\def\overbar{\mathortext\normalmathoverbar\normaltextoverbar}
341\else
342    \enforced\permanent\expandafter\let\expandafter\overbar\csname\v!overbar\endcsname
343\fi
344
345% \ifdefined\normalmathunderstrike
346%     \enforced\permanent\expandafter\let\expandafter\normaltextunderstrike\csname\v!understrike\endcsname
347%     \enforced\permanent\protected\def\understrike{\mathortext\normalmathunderstrike\normaltextunderstrike}
348% \else
349%     \enforced\permanent\expandafter\let\expandafter\understrike\csname\v!understrike\endcsname
350% \fi
351%
352% \ifdefined\normalmathoverstrike
353%     \enforced\permanent\expandafter\let\expandafter\normaltextoverstrike\csname\v!overstrike\endcsname
354%     \enforced\permanent\protected\def\overstrike{\mathortext\normalmathoverstrike \normaltextoverstrike}
355% \else
356%     \enforced\permanent\expandafter\let\expandafter\overstrike\csname\v!overstrike\endcsname
357% \fi
358
359\enforced\permanent\expandafter\let\expandafter\overstrikes\csname\v!overstrikes\endcsname
360\enforced\permanent\expandafter\let\expandafter\underbars  \csname\v!underbars  \endcsname
361\enforced\permanent\expandafter\let\expandafter\overbars   \csname\v!overbars   \endcsname
362
363\enforced\permanent\protected\def\setupunderbar[#1]% too incompatible for the moment
364  {}
365
366\popoverloadmode
367
368%D An experimental new feature:
369%D
370%D \startbuffer
371%D test {\red\underrandoms{test me}} and \underrandom{test} or \underrandom{grep} \blank
372%D test {\red\underdashes {test me}} and \underdash  {test} or \underdash  {grep} \blank
373%D test {\red\underdots   {test me}} and \underdot   {test} or \underdot   {grep} \blank
374%D \stopbuffer
375%D
376%D \typebuffer \getbuffer
377
378\startuseMPgraphic{rules:under:random}
379    draw
380        ((0,RuleDepth) ... (RuleWidth,RuleDepth)) randomized (4*RuleThickness)
381        shifted (0,RuleFactor*RuleOffset)
382        withpen pencircle scaled RuleThickness
383        withcolor RuleColor ;
384    setbounds currentpicture to unitsquare xysized(RuleWidth,RuleHeight) ;
385\stopuseMPgraphic
386
387\startuseMPgraphic{rules:under:dash}
388    draw
389        ((0,RuleDepth) -- (RuleWidth,RuleDepth))
390        shifted (0,RuleFactor*RuleOffset)
391        dashed dashpattern(on RuleFactor/2 off RuleFactor/2)
392        withpen pencircle scaled RuleThickness
393        withcolor RuleColor ;
394    setbounds currentpicture to unitsquare xysized(RuleWidth,RuleHeight) ;
395\stopuseMPgraphic
396
397\startuseMPgraphic{rules:under:dots}
398    path p ; p := (0,RuleDepth) -- (RuleWidth,RuleDepth) ;
399    numeric l ; l := arclength(p);
400    l := l mod RuleThickness/4;
401    draw
402        p
403        shifted (l,RuleFactor*RuleOffset)
404        dashed dashpattern(off 2RuleThickness+l on 0 off 2RuleThickness)
405        withpen pencircle scaled 2RuleThickness
406        withcolor RuleColor ;
407    setbounds currentpicture to unitsquare xysized(RuleWidth,RuleHeight) ;
408\stopuseMPgraphic
409
410\definebar
411  [undergraphic]
412  [\c!mp=rules:under:dash,
413   \c!level=\v!auto,
414   \c!offset=-.2,
415   \c!dy=.4,
416   \c!continue=\v!yes,
417   \c!order=\v!background]
418
419\definebar[underrandom] [undergraphic][\c!mp=rules:under:random,]
420\definebar[underrandoms][underrandom] [\c!continue=\v!no]
421
422\definebar[underdash]   [undergraphic][\c!mp=rules:under:dash]
423\definebar[underdashes] [underdash]   [\c!continue=\v!no]
424
425\definebar[underdot]    [undergraphic][\c!mp=rules:under:dots]
426\definebar[underdots]   [underdot]    [\c!continue=\v!no]
427
428%D This will move: (a bit duplicated)
429
430\installcorenamespace{shift}
431
432\installcommandhandler \??shift {shift} \??shift
433
434\let\setupshifts\setupshift
435
436\appendtoks
437    \frozen\protected\instance\edefcsname\currentshift\endcsname{\node_shifts_direct{\currentshift}}%
438\to \everydefineshift
439
440\protected\def\node_shifts_set#1% todo: check parent ! todo: move attr etc to lua
441  {\ifhastok={#1}%
442     \setupcurrentshift[#1]%
443   \else
444     \cdef\currentshift{#1}%
445   \fi
446   \useshiftstyleandcolor\c!style\c!color
447   \dosetupisolatedalign{\shiftparameter\c!align}% a weird feature that i probably needed once
448   \clf_setshift
449       continue {\shiftparameter\c!continue}%
450       unit     {\shiftparameter\c!unit}%
451       method    \shiftparameter\c!method
452       dy        \shiftparameter\c!dy % number
453   \relax}
454
455\permanent\protected\def\startshift[#1]%
456  {\begingroup
457   \node_shifts_set{#1}%
458   \ignorespaces}
459
460\permanent\protected\def\stopshift
461  {\removeunwantedspaces
462   \endgroup}
463
464\protected\def\node_shifts_direct#1%
465  {\groupedcommand
466     {\begingroup\dostartisolation\begingroup\node_shifts_set{#1}\ignorespaces}
467     {\removeunwantedspaces\endgroup\dostopisolation\endgroup}}
468
469\setupshifts
470  [\c!method=0,
471   \c!continue=\v!no,
472   \c!dy=0,
473   \c!unit=ex,
474   \c!align=,
475   \c!style=,
476   \c!color=]
477
478\defineshift [\v!shiftup]   [\c!method=0,\c!dy=-1,\c!unit=ex,\c!continue=\v!yes,\c!style=\txx,\c!color=]
479\defineshift [\v!shiftdown] [\c!method=1,\c!dy=.3,\c!unit=ex,\c!continue=\v!yes,\c!style=\txx,\c!color=]
480
481% we want these always so ...
482
483\expandafter\let\expandafter\shiftup  \csname\v!shiftup  \endcsname
484\expandafter\let\expandafter\shiftdown\csname\v!shiftdown\endcsname
485
486% This is a weird helper.. these might go away:
487
488\permanent\protected\def\dostartisolation{\signalcharacter}
489\permanent\protected\def\dostopisolation {\signalcharacter}
490\permanent\protected\def\doisolator      {\signalcharacter}
491
492\permanent\protected\def\dosetupisolatedalign#1%
493  {\doisolator
494   \setupalign[#1]\relax}
495
496\permanent\protected\def\doisolatedgroupedalign#1#2%
497  {\groupedcommand
498     {\begingroup\dostartisolation\begingroup#1}
499     {#2\endgroup\dostopisolation\endgroup}}
500
501%D More rules.
502
503% The following code rocks and was written with the Toto Live in Poland bluray
504% in loop mode on my 5.1 surround development setup (the Toto lineup with Simon
505% Phillips on drums). The Amsterdam concert is equally energizing.
506
507\installcorenamespace{linefiller}
508
509\installcommandhandler \??linefiller {linefiller} \??linefiller
510
511\definesystemattribute[linefiller][public]
512
513\aliased\let\setuplinefillers\setuplinefiller
514
515\protected\def\node_linefiller_set#1% todo: check parent ! todo: move attr etc to lua
516  {\cdef\currentlinefiller{#1}%
517   \edef\p_node_color{\linefillerparameter\c!color}%
518   \clf_setlinefiller
519      %method         \linefillerparameter\c!method
520       location      {\linefillerparameter\c!location}%
521       scope         {\linefillerparameter\c!scope}%
522       mp            {\includeMPgraphic{\linefillerparameter\c!mp}}%
523       ma             \c_attr_colormodel
524       ca             \rawcolorattribute\p_node_color
525       ta             \rawtransparencyattribute\p_node_color
526       height         {\linefillerparameter\c!height}%
527       depth          {\linefillerparameter\c!depth}%
528       distance       {\linefillerparameter\c!distance}%
529       threshold      {\linefillerparameter\c!threshold}%
530       rulethickness  {\linefillerparameter\c!rulethickness}%
531   \relax}
532
533\permanent\tolerant\protected\def\startlinefiller[#1]#*[#S#2]%
534  {\begingroup
535   \par
536   \cdef\currentlinefiller{#1}%
537   \ifparameter#2\or
538     % we need to update settings
539     \setuplinefiller[#1][#2]% no \setupcurrentlinefiller as we need to update settings
540   \fi
541   \node_linefiller_set{#1}%
542   \linefillerparameter\c!before
543   \usealignparameter\linefillerparameter
544   \uselinefillerstyleandcolor\c!textstyle\c!textcolor} % bars have foregroundcolor
545
546\permanent\protected\def\stoplinefiller
547  {\par
548   \linefillerparameter\c!after
549   \endgroup}
550
551\permanent\protected\def\setlinefiller[#1]%
552  {\node_linefiller_set{#1}}
553
554\setuplinefillers
555  [%c!method=0,
556   %c!mp=,
557   \c!location=\v!both,
558   \c!scope=\v!local,
559   \c!distance=\zeropoint,
560   \c!threshold=\zeropoint,
561   \c!rulethickness=\linewidth,
562   \c!height=\linewidth,
563   \c!depth=\zeropoint,
564  %\c!textcolor=,
565  %\c!textstyle=,
566  %\c!align=,
567  %\c!before=,
568  %\c!after=,
569   \c!color=]
570
571\definelinefiller
572  [filler]
573  [\c!height=.75\exheight,
574  %\c!mp=rules:filler:demo,
575  %\c!threshold=.25\emwidth,
576   \c!distance=.25\emwidth,
577   \c!rulethickness=.25\exheight]
578
579%D Bonus:
580%D
581%D \starttyping
582%D \startuseMPgraphic{foo}
583%D     fill unitsquare
584%D         xyscaled (RuleWidth,RuleHeight+RuleDepth) enlarged (ExHeight/4,ExHeight/8)
585%D         shifted  (-ExHeight/8,ExHeight/16)
586%D         withcolor RuleColor ;
587%D \stopuseMPgraphic
588%D
589%D \definelinefiller[foo][mp=foo,color=darkred]
590%D
591%D \linefillerhbox[foo]{OEPS}
592%D \stoptyping
593
594\protected\def\node_backgrounds_filler_box#1#2[#3]%
595  {\bgroup
596   \clf_enablebackgroundboxes
597   \dowithnextbox{%
598     \node_linefiller_set{#3}% already sets the attribute
599     #1%
600        attr \backgroundattribute \plusone
601       {\box\nextbox}%
602     \egroup}%
603   #2}
604
605\permanent\protected\def\linefillerhbox{\node_backgrounds_filler_box\hpack\hbox}
606\permanent\protected\def\linefillervbox{\node_backgrounds_filler_box\vpack\vbox}
607\permanent\protected\def\linefillervtop{\node_backgrounds_filler_box\tpack\vtop}
608
609%D Bonus:
610
611% \autorule : defined at the lua end
612
613%D A joke:
614
615%D This will move: (a bit duplicated)
616
617\installcorenamespace{shadow}
618
619\installcommandhandler \??shadow {shadow} \??shadow
620
621\let\setupshadows\setupshadow
622
623\appendtoks
624    \frozen\protected\instance\edefcsname\currentshadow\endcsname{\node_shadows_direct{\currentshadow}}%
625\to \everydefineshadow
626
627\protected\def\node_shadows_set#1% todo: check parent ! todo: move attr etc to lua
628  {\ifhastok={#1}%
629     \setupcurrentshadow[#1]%
630   \else
631     \cdef\currentshadow{#1}%
632   \fi
633   \useshadowstyleandcolor\c!style\c!color
634   \edef\p_node_color{\shadowparameter\c!contrastcolor}% todo
635   \clf_setshadow
636       continue {\shadowparameter\c!continue}%
637       unit     {\shadowparameter\c!unit}%
638       weight   {\shadowparameter\c!weight}%
639       method   \shadowparameter\c!method
640       dx       \shadowparameter\c!dx\relaxedspace % number
641       dy       \shadowparameter\c!dy\relaxedspace % number
642       %
643       ma       \c_attr_colormodel
644       ca       \rawcolorattribute\p_node_color
645       ta       \rawtransparencyattribute\p_node_color
646   \relax}
647
648\permanent\protected\def\startshadow[#1]%
649  {\begingroup
650   \node_shadows_set{#1}%
651   \ignorespaces}
652
653\permanent\protected\def\stopshadow
654  {\removeunwantedspaces
655   \endgroup}
656
657\protected\def\node_shadows_direct#1%
658  {\groupedcommand
659     {\begingroup\dostartisolation\begingroup\node_shadows_set{#1}\ignorespaces}
660     {\removeunwantedspaces\endgroup\dostopisolation\endgroup}}
661
662\setupshadows
663  [\c!method=0,
664   \c!continue=\v!yes,
665   \c!dx=.04,
666   \c!dy=-.04,
667   \c!unit=ex,
668   \c!style=,
669   \c!color=,
670   \c!weight=100,
671   \c!contrastcolor=middlegray] % otherwise we don't see anything, users should set it anyway
672
673\defineshadow [shadowed]
674
675% \startTEXpage[offset=1ts]
676%     \samplefile{tufte}\removeunwantedspaces\space
677%     \startshadow[contrastcolor=red]\samplefile{tufte}\removeunwantedspaces\stopshadow\space
678%     \samplefile{tufte}
679% \stopTEXpage
680
681%D Quick and dirty, but useful in math matrices:
682
683\installcorenamespace{graphiclines}
684\installcorenamespace{graphiccolor}
685
686\newdimen\d_grph_line_width
687\newdimen\d_grph_line_offset
688\newcount\c_grph_line_action
689
690\defcsname\??graphiclines s\endcsname{\strut}
691\defcsname\??graphiclines m\endcsname{\setstrut\strutht.85\strutht\strutdp.85\strutdp}
692\defcsname\??graphiclines a\endcsname{\d_grph_line_offset 1ma}
693\defcsname\??graphiclines x\endcsname{\d_grph_line_offset 1ex}
694\defcsname\??graphiclines h\endcsname{\d_grph_line_offset \strutht}
695\defcsname\??graphiclines d\endcsname{\d_grph_line_offset-\strutdp}
696\defcsname\??graphiclines o\endcsname{\d_grph_line_offset \zeropoint}
697\defcsname\??graphiclines e\endcsname{\c_grph_line_action \plusone}  % end
698\defcsname\??graphiclines c\endcsname{\c_grph_line_action \plustwo}  % close + end
699\defcsname\??graphiclines r\endcsname{\c_grph_line_action \plustree} % reset
700\defcsname\??graphiclines t\endcsname{\d_grph_line_offset \strutht}
701\defcsname\??graphiclines b\endcsname{\d_grph_line_offset-\strutdp\c_grph_line_action\plusone}
702\defcsname\??graphiclines T\endcsname{\d_grph_line_offset .75\strutht}
703\defcsname\??graphiclines B\endcsname{\d_grph_line_offset-.25\strutdp\c_grph_line_action\plusone}
704
705\def\grph_line_inject_step#1%
706  {\ifcsname\??graphiclines#1\endcsname
707     \lastnamedcs
708   \orelse\ifchkdim#1\or
709      \d_grph_line_width#1\relax
710 % \orelse\ifchknum#1\or
711   \orelse\ifchkdim#1pt\or
712      \d_grph_line_width#1\d_grph_line_width % \dimexpr\mathmatrixparameter\c!rulethickness\relax
713   \else
714     \edef\m_rulecolor{#1}%
715   \fi}
716
717% \setupmathmatrix[rulethickness=3pt]
718
719\tolerant\permanent\protected\def\grph_line_inject
720  {\dontleavehmode
721   \iftrialtypesetting
722     \expandafter\gobbletwooptionals
723   \else
724     \expandafter\grph_line_inject_yes
725   \fi}
726
727\def\grph_line_inject_yes[#1]#*[#2]%
728  {\begingroup
729   \edef\m_rulecolor{\mathmatrixparameter\c!rulecolor}%
730   \d_grph_line_width{\mathmatrixparameter\c!rulethickness}%
731   \d_grph_line_offset\zeropoint
732   \c_grph_line_action\zerocount
733   \processcommacommand[#2]\grph_line_inject_step % use fast one
734   \ifcase\c_grph_line_action
735     \ifcstok{\begincsname\??graphiccolor#1\endcsname}\empty
736        \gletcsname\??graphiccolor#1\endcsname\m_rulecolor
737     \fi
738   \orelse\ifempty{#1}%
739     % ignore
740   \else
741     % we have to color the last node
742     \colo_helpers_direct_activate{\begincsname\??graphiccolor#1\endcsname}%
743     \gletcsname\??graphiccolor#1\endcsname\empty
744   \fi
745   \hpack \ifzeropt\d_grph_line_offset\else\s!yoffset\d_grph_line_offset\fi
746     {%\signalcharacter
747      \clf_linesegment
748        {#1}%
749        \c_math_eqalign_row
750        \c_math_eqalign_column
751        \c_grph_line_action
752        \d_grph_line_width}%
753   \endgroup}
754
755\let\graphicline\grph_line_inject
756
757\protect \endinput
758