rules-mkiv.tex /size: 30 Kb    last modification: 2023-12-21 09:43
1% language=us runpath=texruns:manuals/rules
2
3% author    : Hans Hagen
4% copyright : ConTeXt Development Team
5% license   : Creative Commons Attribution ShareAlike 4.0 International
6% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
7% origin    : the ConTeXt distribution
8%
9% comment   : Because this manual is distributed with TeX distributions it comes with a rather
10%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
11%             that they describe. Using parts of the content otherwise can therefore conflict
12%             with existing functionality and we cannot be held responsible for that. Many of
13%             the manuals contain characteristic graphics and personal notes or examples that
14%             make no sense when used out-of-context.
15%
16% comment   : Some chapters might have been published in TugBoat, the NTG Maps, the ConTeXt
17%             Group journal or otherwise. Thanks to the editors for corrections. Also thanks
18%             to users for testing, feedback and corrections.
19
20\setupbodyfont
21  [dejavu,10pt]
22
23\setuphead
24  [section]
25  [style=\bfb]
26
27\setupwhitespace
28  [big]
29
30\setuplayout
31  [header=15mm,
32   topspace=15mm,
33   footer=0mm,
34   bottomspace=20mm,
35   height=middle,
36   backspace=20mm,
37   cutspace=20mm,
38   width=middle]
39
40\usemodule[x][setups-basics]
41
42\loadsetups[context-en]
43\loadsetups[i-linefiller]
44
45\startdocument
46
47\startMPpage
48
49    StartPage ;
50
51        linecap := butt ;
52
53        fill Page withcolor .25[yellow/4,green/2] ;
54
55        path p ; p := (ulcorner Page ..  urcorner Page .. lrcorner Page) ;
56
57        draw image (
58            for i=1/200 step 1/200 until 1 :
59                draw p scaled i dashed dashpattern (on 4 randomized 2 off 4 randomized 2) ;
60            endfor ;
61        ) withcolor white ;
62
63        draw anchored.urt(
64            textext("\ss RULES") xsized .5PaperWidth,
65            urcorner Page shifted(-15mm,-20mm)
66        ) withcolor white ;
67
68        draw anchored.urt(
69            textext("\ss HANS HAGEN") xsized .5PaperWidth,
70            lrcorner Page shifted(-15mm,40mm)
71        ) withcolor white ;
72
73        draw anchored.urt(
74            textext("\ss A CONTEXT MKIV MANUAL") xsized .5PaperWidth,
75            lrcorner Page shifted(-15mm,20mm)
76        ) withcolor white ;
77
78        setbounds currentpicture to Page ;
79
80    StopPage ;
81
82\stopMPpage
83
84\startsubject[title=Introduction]
85
86This manual describes just one type of rules: those that somehow magically are
87bound to the typeset text. We will mention a few mechanisms that relate to this
88in the sense that they share some of the underlaying code and logic. The term
89\quotation {rules} should be interpreted liberally as we can kick in some
90\METAPOST\ which then can get us away from straight rules.
91
92This manual will not be that extensive, after all these mechanisms are not that
93complex to configure.
94
95\stopsubject
96
97\startsubject[title=Underlining and overstriking]
98
99Already in \CONTEXT\ \MKII\ we had underlining available but with some
100limitations. We could handle more than one word but at some point you hit the
101limits of the engine. The \MKIV\ implementation is more flexible. In fact you can
102underline a whole document (which was actually a request from a user). This
103feature was also used by a collegue who was experimenting with texts for
104dyslectic readers.
105
106This mechanism is generic in the sense that a framework is provided to define
107rules that run alongside text. Take this:
108
109\setupbars[foregroundcolor=darkyellow,color=darkred]
110
111\startbuffer
112\underbars {drawing \underbar{bars} under words is a typewriter leftover}
113\overstrikes {striking words makes them \overstrike {unreadable} but
114sometimes even \overbar {top lines} come into view.}
115\stopbuffer
116
117\typebuffer
118
119This shows up as:
120
121\getbuffer
122
123We can best explain what happens by looking at how these commands are
124defined:
125
126\starttyping
127\definebar[overbar]   [method=1,dy=0.4, offset=1.8, continue=yes]
128\definebar[underbar]  [method=1,dy=-0.4,offset=-0.3,continue=yes]
129\definebar[overstrike][method=0,dy=0.4, offset=0.5, continue=yes]
130
131\definebar
132  [understrike]
133  [method=0,
134   offset=1.375,
135   rulethickness=2.5,
136   continue=yes,
137   order=background]
138
139\definebar[overbars]    [overbar]    [continue=no]
140\definebar[underbars]   [underbar]   [continue=no]
141\definebar[overstrikes] [overstrike] [continue=no]
142\definebar[understrikes][understrike][continue=no]
143\stoptyping
144
145The formal definitions of the commands are show in \definition [definebar, setupbar].
146
147\showdefinition{definebar}
148\showdefinition{setupbar}
149
150The \type {dy} parameter specifies the shift up or down. The offset defines how
151nested bars are shifted. The \type {method} determines centering of the bar: we
152set it to zero when we want an overstrike. The \type {continue} parameter is
153responsible for drawing over spaces and the \type {order} determines the layering.
154
155The units are either hard coded values like points or relate to the font at the spot
156of the bar. Here are some examples:
157
158\startbuffer
159\setupbars[unit=mm,rulethickness=1]     bar \underbar{foo} bar\quad
160\setupbars[unit=ex,rulethickness=1]     bar \underbar{foo} bar\quad
161\setupbars[unit=pt,rulethickness=1]     bar \underbar{foo} bar\quad
162\setupbars[unit=pt,rulethickness=10pt]  bar \underbar{foo} bar
163\stopbuffer
164
165\typebuffer \blank \start \getbuffer \stop \blank
166
167As if underlining wasn't already bad enough, of course at some point there came a
168request for dashed lines.
169
170\startbuffer
171test \underrandoms{test me} and \underrandom{test} or \underrandom{grep}
172test \underdashes {test me} and \underdash  {test} or \underdash  {grep}
173test \underdots   {test me} and \underdot   {test} or \underdot   {grep}
174\stopbuffer
175
176\typebuffer
177
178The above variants are predefined and render as:
179
180\startlines
181\tfb \getbuffer
182\stoplines
183
184A graphic is defined as follows. It boils down to drawing one or more shapes. In
185this example we also force a specific boundingbox so that the result gets
186positioned right.
187
188\starttyping
189\startuseMPgraphic{rules:under:...}
190    draw
191        ((0,RuleDepth) -- (RuleWidth,RuleDepth))
192        shifted (0,RuleFactor*RuleOffset)
193        withpen pencircle scaled RuleThickness
194        withcolor RuleColor ;
195    setbounds currentpicture to unitsquare xysized(RuleWidth,RuleHeight) ;
196\stopuseMPgraphic
197\stoptyping
198
199The following variables are available:
200
201\starttabulate[|T|||]
202\BC variable      \BC type     \BC meaning                                 \NC \NR
203\ML
204\NC RuleDirection \NC string   \NC the direction of the line               \NC \NR
205\NC RuleOption    \NC string   \NC whatever the caller finds useful        \NC \NR
206\NC RuleWidth     \NC number   \NC the requested width of the rule         \NC \NR
207\NC RuleHeight    \NC number   \NC the requested height of the rule        \NC \NR
208\NC RuleDepth     \NC number   \NC the requested depth of the rule         \NC \NR
209\NC RuleThickness \NC number   \NC the linewidth                           \NC \NR
210\NC RuleFactor    \NC number   \NC the set factor (e.g. an \type {ex})     \NC \NR
211\NC RuleOffset    \NC number   \NC an (optional) offset in case of nesting \NC \NR
212\NC RuleColor     \NC color    \NC the color                               \NC \NR
213\stoptabulate
214
215The \type {RuleFactor} can be used as multiplier for the \type {RuleOffset}.
216Later we will see an example of how to use the \type {RuleDirection} and \type
217{RuleOption}.
218
219The extra under commands are defined as follows. Watch the \type {mp} parameter:
220it refers to a graphic.
221
222\starttyping
223\definebar
224  [undergraphic]
225  [mp=rules:under:dash,
226   offset=-.2,
227   order=background]
228
229\definebar[underrandom] [undergraphic][mp=rules:under:random]
230\definebar[underrandoms][underrandom] [continue=yes]
231
232\definebar[underdash]   [undergraphic][mp=rules:under:dash]
233\definebar[underdashes] [underdash]   [continue=yes]
234
235\definebar[underdot]    [undergraphic][mp=rules:under:dots]
236\definebar[underdots]   [underdot]    [continue=yes]
237\stoptyping
238
239A nasty side effect of the implementation is that because we look mostly at glyphs,
240optionally separated by glue or kern some text might get unseen and therefore not
241treated.
242
243\startbuffer
244\underbars{We see this \high{\tfxx ®} symbol \runninghbox to 1cm{\hss} often.}
245\underbar {We see this \high{\tfxx ®} symbol \runninghbox to 1cm{\hss} often.}
246\stopbuffer
247
248\typebuffer
249
250This gives:
251
252\startlines
253\getbuffer
254\stoplines
255
256A running box is seen as text. As you (probably) expect, a nested ornamental
257rule is supported as well:
258
259\startbuffer
260\underbars
261  {We see this \high{\tfxx\underdot{®}} symbol \runninghbox to 1cm{\hss} often.}
262\underbar
263  {We see this \high{\tfxx\underdot{®}} symbol \runninghbox to 1cm{\hss} often.}
264\stopbuffer
265
266\typebuffer
267
268This time we get (you might need a magnifier to see it):
269
270\startlines
271\getbuffer
272\stoplines
273
274We end this section with an extreme example:
275
276\startbuffer
277\definebar
278  [xbarone]
279  [text=\lower\exheight\hbox{\darkred \infofont +},
280   repeat=yes]
281\definebar
282  [xbartwo]
283  [text=\lower\exheight\hbox{\darkblue\infofont +},
284   repeat=yes,
285   continue=yes]
286\stopbuffer
287
288\typebuffer \getbuffer
289
290\startbuffer
291Klein    : \xbarone{\samplefile   {klein}\removeunwantedspaces}\par
292Sapolsky : \xbartwo{\samplefile{sapolsky}\removeunwantedspaces}\par
293\stopbuffer
294
295\typebuffer \getbuffer
296
297As a reminder that one can keep things simple, here are a few more examples that
298use defaults (and no colors):
299
300\startbuffer
301\underbar {\underbar {\samplefile{ward}}}\blank
302\underbar {\underdot {\samplefile{ward}}}\blank
303\underbar {\underdot {\samplefile{ward}}}\blank
304\underdot {\underbar {\samplefile{ward}}}\blank
305\underbars{\underdot {\samplefile{ward}}}\blank
306\underbar {\underdots{\samplefile{ward}}}\blank
307\underdots{\underdots{\samplefile{ward}}}\blank
308\stopbuffer
309
310\typebuffer {\setupbars[foregroundcolor=,color=]\getbuffer}
311
312\stopsubject
313
314\startsubject[title=Shifting]
315
316We mention shifting here because it shares code with the bars. There are two
317shifts defined but you can define more:
318
319\starttyping
320\defineshift
321  [shiftup]
322  [method=0,
323   dy=-1,
324   unit=ex,
325   continue=yes,
326   style=\txx]
327
328\defineshift
329  [shiftdown]
330  [method=1,
331   dy=.3,
332   unit=ex,
333   continue=yes,
334   style=\txx,
335   color=]
336\stoptyping
337
338An example of using the commands defined this way is:
339
340\startbuffer
341Let's go \shiftup{up} and \shiftdown{down} a bit!
342\stopbuffer
343
344\typebuffer
345
346or: \inlinebuffer\ Here we just shift words but you can shift more than that
347although I haven't yet seen a useful example of that:
348
349\startbuffer
350We can \shiftup {\samplefile{tufte}} whole paragraphs if we really want.
351\stopbuffer
352
353\typebuffer
354
355\getbuffer
356
357The formal definitions are given in \definition[defineshift, setupshift,
358startshift]. The \type {align} switch is there for directional (and testing)
359purposes and is normally not used (or even useful in a line). The \type {dy}
360is multiplied by the \type {factor} that itself can depend on the used font.
361
362\showdefinition{defineshift}
363\showdefinition{setupshift}
364\showdefinition{startshift}
365
366\stopsubject
367
368\startsubject[title=Fillers]
369
370The possibility of line fillers was mentioned by Mojca on the \CONTEXT\ mailing
371list and it's actually not that hard to implement them. The only need I ever had
372for it was to fill out lines on some legal form and that was actually just some
373fun challenge in \MKII\ times. The code got lost and never made it into \CONTEXT.
374This time it was added as a side effect of a thread at the tenth \CONTEXT\
375meeting.
376
377The ideas is to fill the rest of a line with some kind of (ornamental) rule. I'm
378not sure what sense it makes, even in legal documents. If it is to prevent
379additions then one should wonder if additions at the end of a (kind of arbitrary)
380broken line is what we should be afraid of most. So, for now, let's consider it
381an educational feature.
382
383\startbuffer
384\definelinefiller
385  [filler-1]
386  [height=.75\exheight,
387   distance=.25\emwidth,
388   rulethickness=.25\exheight,
389   textcolor=darkyellow,
390   before=\blank,
391   after=\blank,
392   color=darkred]
393
394\startlinefiller[filler-1]
395    \samplefile{ward}
396\stoplinefiller
397\stopbuffer
398
399\typebuffer
400
401Here we define a filler. As you can see, a rule gets added at the end of a
402paragraph.
403
404\getbuffer
405
406\startbuffer
407\startalign[flushleft,broad]
408    \startlinefiller[filler-1]
409        \samplefile{ward}
410    \stoplinefiller
411\stopalign
412\stopbuffer
413
414This time we don't justify:
415
416\typebuffer
417
418Now more lines get a rule appended:
419
420\getbuffer
421
422Before we continue it must be noted that the environment creates a paragraph. If
423you don't want that you need to use \type {\setlinefiller} instead. Next we show
424a \type {middle} alignment:
425
426\startbuffer
427\startalign[middle]
428    \startlinefiller[filler-1]
429        \samplefile{ward}
430    \stoplinefiller
431\stopalign
432\stopbuffer
433
434\getbuffer
435
436\startbuffer
437\startalign[middle]
438    \startnarrower
439        \startlinefiller[filler-1]
440            \samplefile{ward}
441        \stoplinefiller
442    \stopnarrower
443\stopalign
444\stopbuffer
445
446Let's add another level of complexity, left- and right skips:
447
448\typebuffer
449
450Here we get:
451
452\getbuffer
453
454The lines stay within the narrower boundaries but you can extend them
455to the margins if you like:
456
457\startbuffer
458\startalign[middle]
459    \startnarrower
460        \startlinefiller[filler-1][scope=global]
461            \samplefile{ward}
462        \stoplinefiller
463    \stopnarrower
464\stopalign
465\stopbuffer
466
467\typebuffer
468
469This looks like:
470
471\getbuffer
472
473You can also use a \type {left} or \type {right} scope, as in:
474
475\startbuffer
476\startalign[middle]
477    \startnarrower
478        \startlinefiller[filler-1][scope=right]
479            \samplefile{ward}
480        \stoplinefiller
481    \stopnarrower
482\stopalign
483\stopbuffer
484
485\typebuffer
486
487Only the right rules extend into the margins.
488
489\getbuffer
490
491\startbuffer
492\startalign[middle]
493    \startnarrower
494        \startlinefiller[filler-1][scope=right,location=right]
495            \samplefile{ward}
496        \stoplinefiller
497    \stopnarrower
498\stopalign
499\stopbuffer
500
501You can get rid of the left rules:
502
503\typebuffer
504
505So:
506
507\getbuffer
508
509Of course these rules are somewhat boring so let's now kick in some \METAPOST.
510
511\startbuffer[mp]
512\setuplinefiller
513  [filler-1]
514  [mp=rules:filler:demo,
515  %threshold=.25\emwidth,
516   color=darkred]
517
518\startuseMPgraphic{rules:filler:demo}
519    drawarrow
520        if RuleDirection == "TRT" : reverse fi
521            ((0,RuleHeight) -- (RuleWidth,RuleHeight))
522        withpen
523            pencircle scaled RuleThickness
524        withcolor
525            if RuleOption == "left" : complemented fi RuleColor ;
526    setbounds currentpicture to
527        unitsquare xysized(RuleWidth,RuleHeight) ;
528\stopuseMPgraphic
529\stopbuffer
530
531\typebuffer[mp] \getbuffer[mp]
532
533The previous example now looks like:
534
535\getbuffer
536
537\startbuffer
538\startalign[middle,r2l]
539    \startnarrower[4*middle]
540        \startlinefiller[filler-1]  [scope=global]
541            \samplefile{ward}
542        \stoplinefiller
543    \stopnarrower
544\stopalign
545\stopbuffer
546
547This time we also change the direction and we can let the \METAPOST\ graphic
548adapt to that by reverting the arrows.
549
550\typebuffer
551
552The direction \type {TRT} is \TEX\ speak for a right|-|to|-|left direction. We
553use a latin script example for convenience.
554
555\getbuffer
556
557\startbuffer[mp]
558\startuseMPgraphic{rules:filler:demo}
559    drawarrow
560        if RuleDirection == "TRT" : reverse fi
561            if RuleOption == "right" : reverse fi
562            ((0,RuleHeight) -- (RuleWidth,RuleHeight))
563        withpen
564            pencircle scaled RuleThickness
565        withcolor
566            if RuleOption == "left" : complemented fi RuleColor ;
567    setbounds currentpicture to
568        unitsquare xysized(RuleWidth,RuleHeight) ;
569\stopuseMPgraphic
570\stopbuffer
571
572% \startbuffer
573% \startnarrower[4*middle]
574%     \startlinefiller[filler-1] [scope=global,align=middle]
575%         \parindent   100pt
576%         \parfillskip 100pt
577%         \samplefile{ward}
578%     \stoplinefiller
579% \stopnarrower
580% \stopbuffer
581
582\startbuffer
583\startnarrower[4*middle]
584    \startlinefiller[filler-1] [scope=global,align={middle,r2l}]
585        \parindent   100pt
586        \parfillskip 100pt
587        \samplefile{ward}
588    \stoplinefiller
589\stopnarrower
590\stopbuffer
591
592The next rendering shows what happens when we set \type {\parindent} and \type
593{\parfillskip} to an excessive have a \type {100pt}.
594
595\getbuffer[mp] \getbuffer
596
597Here we have adapted the graphic a bit:
598
599\starttyping
600if RuleDirection == "TRT" : reverse fi
601    if RuleOption == "right" : reverse fi
602    ((0,RuleHeight) -- (RuleWidth,RuleHeight))
603\stoptyping
604
605\showdefinition{definelinefiller}
606\showdefinition{setuplinefiller}
607
608\stopsubject
609
610% \startsubject[title=Backgrounds]
611% \stopsubject
612
613\startsubject[title=User rules]
614
615Characters and rules are the only graphical elements that \TEX\ really knows
616about. Even if you see images in a document, you should realize that they are
617just blobs with dimensions and that the backend replaces such blobs by real
618images.
619
620The primitive operations for rules are \type {\hrule} and \type {\vrule} and the
621main difference is to what way they adapt to their situation when no dimensions
622are given and the mode change they trigger.
623
624\startbuffer
625hrule{\darkred   \hrule width 10cm height 3mm depth 2mm}\par
626vrule{\darkyellow\vrule width 10cm height 3mm depth 2mm}\par
627hrule{\darkred   \hrule width 10cm                     }\par
628vrule{\darkyellow\vrule            height 3mm depth 2mm}\par
629
630hrule{\darkred   \leaders\hrule height 1mm\relax\hfill}hrule\par
631\stopbuffer
632
633\typebuffer
634
635When more text is to follow you should end a specification with \type {\relax} to
636make sure that the scanner stops looking for more arguments. With \type {\leaders}
637you can create flexible rules.
638
639\startlinecorrection
640\getbuffer
641\stoplinecorrection
642
643In \CONTEXT\ we also have so called frame rules:
644
645\startbuffer
646\color[darkred]{\frule
647    width 10cm
648    height 1cm
649    line   1mm
650\relax}
651\stopbuffer
652
653\typebuffer
654
655This will produce a rectangle:
656
657\startlinecorrection
658\getbuffer
659\stoplinecorrection
660
661There are a few more keywords. Keep in mind that we actually have a new kind of
662primitive here, so we follow the \TEX\ conventions of keywords.
663
664\startbuffer
665\ruledhbox\bgroup
666    \darkgray
667    \frule width 100mm height 10mm depth 8mm radius 2mm line 2pt type fill\relax
668    \hskip-100mm
669    \darkred
670    \frule width 100mm height 10mm depth 8mm radius 2mm line 2pt\relax
671    \hskip-100mm
672    \hbox to 100mm{\white \bold \hfill some handy word with frames\hfill}%
673\egroup
674\stopbuffer
675
676\typebuffer
677
678Of course this is a rather low level way of doing frames and such, but when you
679like that kind of low level programming you get the possibility here.
680
681\startlinecorrection
682\getbuffer
683\stoplinecorrection
684
685You can combine this with existing mechanisms. Take the following:
686
687\startbuffer
688\defineoverlay[normalframe]
689  [\frule
690     width \overlaywidth
691     height\overlayheight
692     line  \overlaylinewidth
693  ]
694
695\defineoverlay[ovalframe]
696  [\frule
697     width  \overlaywidth
698     height \overlayheight
699     line   \overlaylinewidth
700     radius \overlayradius
701  ]
702\stopbuffer
703
704\typebuffer \getbuffer
705
706\startbuffer
707\hbox \bgroup
708    \framed                                  {test}\quad
709    \framed[frame=off]                       {test}\quad
710    \framed[background=normalframe,frame=off]{test}\quad
711    \framed[background=normalframe,frame=off]{test}\quad
712    \framed[corner=round]                    {test}\quad
713    \framed[corner=round]                    {test}\quad
714    \framed[background=ovalframe,frame=off]  {test}\quad
715    \framed[background=ovalframe,frame=off]  {test}\quad
716    \framed[background=ovalframe,frame=on]   {test}\quad
717    \framed[background=ovalframe,frame=on]   {test}\quad
718\egroup
719\stopbuffer
720
721This is a variant on the already available round corners:
722
723\startlinecorrection
724\getbuffer
725\stoplinecorrection
726
727The above result is accomplished with:
728
729\typebuffer
730
731Given the examples in the previous sections it will be no surprise that we
732can also use \METAPOST.
733
734\startbuffer
735\startuseMPgraphic{demoshape:back}
736    fill
737        unitcircle xysized (RuleWidth,RuleHeight+RuleDepth)
738        withcolor RuleColor ;
739\stopuseMPgraphic
740
741\startuseMPgraphic{demoshape:fore}
742    draw
743        unitcircle xysized (RuleWidth,RuleHeight+RuleDepth)
744        withcolor RuleColor
745        withpen pencircle scaled 4RuleThickness ;
746\stopuseMPgraphic
747
748\hbox\bgroup
749    \darkgray \frule width 100mm height 10mm depth 8mm type mp line 2pt
750        data {\includeMPgraphic{demoshape:back}}
751    \relax
752    \hskip-100mm
753    \darkred \frule width 100mm height 10mm depth 8mm type mp line 2pt
754        data {\includeMPgraphic{demoshape:fore}}
755    \relax
756    \hskip-100mm
757    \hbox to 100mm{\white \bold \hfill some handy word with frames\hfill}
758\egroup
759\stopbuffer
760
761\typebuffer
762
763Or rendered:
764
765\startlinecorrection
766\getbuffer
767\stoplinecorrection
768
769% \frule
770%     width  10cm
771%     height  2cm
772%     depth   1cm
773%     line    1pt
774%     radius  3mm
775% \relax x
776
777The primitive \type {\leaders} can also be used with these \type {\frule}s so
778here is an example with and without:
779
780\startbuffer
781test \leaders \hrule height 1mm \hfill test \par
782test \leaders \frule height 6mm depth 3mm radius 1mm\hfill test \par
783\stopbuffer
784
785\typebuffer
786
787As you can see, the leader basically stretches the rule. That operation happens
788in the backend code; the frontend is only interested in the height and depth
789while the width is glue that can stretch.
790
791\startlinecorrection
792\getbuffer
793\stoplinecorrection
794
795Here are two more:
796
797\startbuffer
798\startuseMPgraphic{demoleader}
799    fill
800        unitcircle xysized (RuleWidth,RuleHeight+RuleDepth)
801        withcolor RuleColor ;
802\stopuseMPgraphic
803
804test {\red \leaders \frule
805    height 6mm
806    depth  3mm
807    type    mp
808    data    {\includeMPgraphic{demoleader}}
809\hfill} test
810\stopbuffer
811
812\typebuffer
813
814\startlinecorrection
815\getbuffer
816\stoplinecorrection
817
818And:
819
820\startbuffer
821\startuseMPgraphic{demoleader}
822    drawdblarrow (0,RuleHeight) -- (RuleWidth,RuleHeight)
823        withpen pencircle scaled  RuleThickness
824        withcolor RuleColor ;
825\stopuseMPgraphic
826
827test {\red \leaders \frule
828    height  1mm % we need at least some dimensions
829    type    mp
830    line    1mm
831    data    {\includeMPgraphic{demoleader}}
832\hfill} test
833\stopbuffer
834
835\typebuffer
836
837\startlinecorrection
838\getbuffer
839\stoplinecorrection
840
841The combination of \TEX\ and \METAPOST\ driven by \LUA\ (which is hidden from the
842user here) is quite powerful and has a pretty good performance too.
843
844The \type {\blackrule} command is the more high level way to inject a rule.
845
846\startbuffer
847\blackrule
848  [width=10cm,
849   height=1cm,
850   depth=1cm,
851   color=darkred]
852\stopbuffer
853
854\typebuffer
855
856This produces a boring rule:
857
858\startlinecorrection
859\getbuffer
860\stoplinecorrection
861
862Again we can revert to \METAPOST:
863
864\startbuffer
865\blackrule
866  [width=10cm,
867   height=1cm,
868   depth=1cm,
869   color=darkred,
870   type=mp,
871   mp=demoshape:back]
872\stopbuffer
873
874\typebuffer
875
876or:
877
878\startlinecorrection
879\getbuffer
880\stoplinecorrection
881
882The formal definition of this command is shown in \definition [setupblackrules,
883blackrule].
884
885\showdefinition{setupblackrules}
886\showdefinition{blackrule}
887
888\stopsubject
889
890\startsubject[title=Hiding]
891
892In education a to be filled in text is often represented by a gap in the running text
893and the bar drawing mechanism supports this. THere is a predefined \type {\hiddenbar}
894command:
895
896\starttyping
897\definebar
898  [hiddenbar] [underbar]
899  [continue=yes,empty=yes,
900   left=\zwj,right=\zwj]
901\stoptyping
902
903\startbuffer
904\samplefile{ward}\hiddenbar               {\color[red]{invisible}}
905\samplefile{ward}\hiddenbar          {\quad\color[red]{invisible}\quad}
906\samplefile{ward}\hiddenbar{\quad\quad\quad\color[red]{invisible}\quad\quad\quad}
907\samplefile{ward}\hiddenbar               {\color[red]{invisible}\quad\quad\quad\quad\quad\quad}
908\samplefile{ward}
909\stopbuffer
910
911\getbuffer
912
913The previous text is generated with:
914
915\typebuffer
916
917Here is a variant that inserts spacing at the left and right edges. In this case
918the spacing is kept at a linebreak:
919
920\startbuffer
921\definebar
922  [widehiddenbar]
923  [hiddenbar]
924  [left={\quads[3]},
925   right={\quads[3]}]
926
927\widehiddenbar{invisible} \samplefile{weisman}
928\widehiddenbar{invisible} \samplefile{weisman}
929\widehiddenbar{invisible}
930\stopbuffer
931
932\typebuffer
933
934\getbuffer
935
936\stopsubject
937
938\startsubject[title=Tabulate]
939
940The previously discussed mechanism is also available in the tabulate mechanism.
941We start with simple backgrounds:
942
943\startbuffer
944\starttabulate
945    \NL[darkred]    foo \NC bar \NC \NR
946    \NL[darkgreen]  foo \NC bar \NC \NR
947    \NL[darkblue]   foo \NC \samplefile{tufte} \NC \NR
948    \NL[darkgray]   foo \NC bar \NC \NR
949    \NL[darkyellow] foo \NC bar \NC \NR
950    \LL
951\stoptabulate
952\stopbuffer
953
954\typebuffer
955
956This comes out as:
957
958{\startcolor[white]\getbuffer\stopcolor}
959
960There are several two character commands that deal with this:
961
962\starttabulate[|c|c|l|]
963\BC command    \BC related to \BC effect \NC
964\NC \type{\NL} \NC \type{\NC} \NC Normal with Line \NC \NR
965\NC \type{\ND} \NC \type{\NC} \NC Normal with Default Line \NC \NR
966\NC \type{\LB} \NC \type{\BC} \NC Bold   with Line \NC \NR
967\NC \type{\DB} \NC \type{\BC} \NC Bold   with Default Line \NC \NR
968\NC \type{\NF} \NC \type{\NC} \NC Normal with Filler \NC \NR
969\NC \type{\NP} \NC \type{\NC} \NC Normal with Predefined Filler \NC \NR
970\NC \type{\FB} \NC \type{\BC} \NC Bold   with Filler \NC \NR
971\NC \type{\NA} \NC \type{\NC} \NC Normal with Auto Toggled Line \NC \NR
972\NC \type{\BA} \NC \type{\BC} \NC Bold   with Auto Toggled Line \NC \NR
973\stoptabulate
974
975Before we show more, we set up tabulate:
976
977\startbuffer[setup]
978\setuptabulate
979  [blank={small,samepage},
980   headstyle=bold,
981   rulecolor=darkred,
982   rulethickness=1pt,
983   background=foo,
984   backgroundcolor=darkred,
985   foregroundcolor=white]
986\stopbuffer
987
988\typebuffer[setup]
989
990This time we don't set colors in the table itself:
991
992\startbuffer
993\starttabulate[|l|l|]
994    \DB foos        \BC bars            \BC \NR
995    \TB
996    \NC foo foo foo \NC bar bar bar bar \NC \NR
997    \NC foo foo foo \NC bar bar bar bar \NC \NR
998    \NC foo foo foo \NC bar bar bar bar \NC \NR
999    \NC foo foo foo \NC bar bar bar bar \NC \NR
1000    \LL
1001\stoptabulate
1002\stopbuffer
1003
1004\typebuffer {\getbuffer[setup]\getbuffer}
1005
1006Instead of coming up with a separate mechanism for hooking in \METAPOST\ we
1007use the linefiller mechanism. We use these graphics:
1008
1009\startbuffer
1010\startuseMPgraphic{foo}
1011  fill unitsquare
1012    xyscaled (RuleWidth,RuleHeight+RuleDepth) enlarged (ExHeight/4,ExHeight/8)
1013    shifted  (-ExHeight/8,ExHeight/16)
1014    withcolor RuleColor ;
1015\stopuseMPgraphic
1016
1017\startuseMPgraphic{bar}
1018  fill unitsquare
1019    xyscaled (RuleWidth,RuleHeight+RuleDepth) enlarged (ExHeight/4,ExHeight/8)
1020    shifted  (-ExHeight/8,ExHeight/16)
1021    randomized ExHeight
1022    withcolor RuleColor ;
1023\stopuseMPgraphic
1024\stopbuffer
1025
1026\typebuffer \getbuffer
1027
1028With these fillers:
1029
1030\startbuffer
1031\definelinefiller[foo][mp=foo,color=darkgreen]
1032\definelinefiller[bar][mp=bar,color=darkred]
1033\stopbuffer
1034
1035\typebuffer \getbuffer
1036
1037An example of usage is:
1038
1039\startbuffer
1040\linefillerhbox[foo] to 12cm{\hss\strut\white\bf FOO\hss} \blank
1041\linefillerhbox[bar] to 10cm{\hss\strut\white\bf BAR\hss} \blank
1042\linefillerhbox[foo] to  9cm{\hss\strut\white\bf FOO\hss} \blank
1043\linefillerhbox[bar] to 14cm{\hss\strut\white\bf BAR\hss}
1044\stopbuffer
1045
1046\typebuffer \blank \getbuffer \blank
1047
1048We can rely on the default:
1049
1050\startbuffer
1051\starttabulate[|||]
1052    \PB foo         \BC bars            \BC \NR
1053    \NC foo foo foo \NC bar bar bar bar \NC \NR
1054    \NC foo foo foo \NC bar bar bar bar \NC \NR
1055    \NC foo foo foo \NC bar bar bar bar \NC \NR
1056    \NC foo foo foo \NC bar bar bar bar \NC \NR
1057\stoptabulate
1058\stopbuffer
1059
1060\typebuffer \start\getbuffer[setup]\getbuffer\stop
1061
1062or be explicit:
1063
1064\startbuffer
1065\starttabulate[|||]
1066    \FB[bar] foos        \BC bars            \BC \NR
1067    \NC      foo foo foo \NC bar bar bar bar \NC \NR
1068    \NC      foo foo foo \NC bar bar bar bar \NC \NR
1069    \NC      foo foo foo \NC bar bar bar bar \NC \NR
1070    \NC      foo foo foo \NC bar bar bar bar \NC \NR
1071\stoptabulate
1072\stopbuffer
1073
1074\typebuffer \start\getbuffer[setup]\getbuffer\stop
1075
1076The auto variants will switch between colors:
1077
1078\startbuffer
1079\setuptabulate[backgroundcolor:1=darkred]
1080\setuptabulate[backgroundcolor:2=darkgreen]
1081\setuptabulate[backgroundcolor:3=darkblue]
1082
1083\starttabulate[|||]
1084    \BA foo foo foo \BC bar bar bar bar \NC \NR
1085    \BA foo foo foo \BC bar bar bar bar \NC \NR
1086    \BA foo foo foo \BC bar bar bar bar \NC \NR
1087    \BA foo foo foo \BC bar bar bar bar \NC \NR
1088    \BA foo foo foo \BC bar bar bar bar \NC \NR
1089    \BA foo foo foo \BC bar bar bar bar \NC \NR
1090\stoptabulate
1091\stopbuffer
1092
1093\typebuffer \start\getbuffer[setup]\getbuffer\stop
1094
1095\stopsubject
1096
1097\startsubject[title=Framing]
1098
1099The \TEX\ engine only has text and rules and all things other graphic has to come
1100from elsewhere. However, as \quote {elsewhere} is rather integrated in \CONTEXT\
1101users won't notice this limitation. It does however means that for historic
1102reasons we have some interesting low level phenomena. One of the oldest commands
1103in \CONTEXT\ is \type {\framed} which as the name indicates can draw a frame
1104around something. This command is demonstrated in many places so here we stick to
1105some remarks about the rules. Watch the following:
1106
1107\startbuffer
1108\definecolor[t-one][r=.6,t=.5,a=1]
1109\definecolor[t-two][g=.6,t=.5,a=1]
1110\stopbuffer
1111
1112\typebuffer \getbuffer
1113
1114\startbuffer
1115\startoverlay
1116  {\framed
1117    [framecolor=t-one,rulethickness=3mm,offset=3mm,frame=closed]
1118    {Just a bit of text!}}
1119  {\framed
1120    [framecolor=t-two,rulethickness=3mm,offset=8mm,frame=on]
1121    {Just a bit of text!}}
1122\stopoverlay
1123\stopbuffer
1124
1125\typebuffer
1126
1127When you look closely you will notice the difference: check out the corners.
1128
1129\startlinecorrection
1130\getbuffer
1131\stoplinecorrection
1132
1133The normal rule drawing happens with overlaps and the reason for that is that
1134\TEX\ can only draw vertical and horizontal rules. We can of course avoid overlap
1135but quite often (and certainly in the past) viewers would show small white
1136stripes due to rounding errors and rendering artifacts. So, overlaps were a safe
1137bet. However, as nowadays we have better control over the backend the additional
1138\type {closed} option will draw the path as one.
1139
1140\startbuffer
1141\dontleavehmode
1142\framed
1143  [width=4cm,height=15mm,rulethickness=3mm,framecolor=t-one,frame=off,
1144   rightframe=on,leftframe=on,topframe=on,bottomframe=on]
1145  {one}\quad
1146\framed
1147  [width=4cm,height=15mm,rulethickness=3mm,framecolor=t-two,frame=off,
1148  rightframe=small,leftframe=small,topframe=small,bottomframe=small]
1149  {two}\quad
1150\framed
1151  [width=4cm,height=15mm,rulethickness=3mm,framecolor=t-two,frame=off,
1152  rightframe=small,leftframe=small,topframe=small,bottomframe=on]
1153  {three}
1154\stopbuffer
1155
1156\typebuffer
1157
1158This example shows another variant of frames, probably unknown (and not needed)
1159to many users:
1160
1161\startlinecorrection
1162\getbuffer
1163\stoplinecorrection
1164
1165\stopsubject
1166
1167\startsubject[title=Examples]
1168
1169There are quite some examples in the test suite, mailing list archive and wiki,
1170so here only a few are given for you to run:
1171
1172% example by WS on the list:
1173
1174\starttyping
1175\definefiller
1176   [dots]
1177   [left=\dontleavehmode,
1178    right=\hskip\zeropoint\par]
1179
1180\samplefile{knuth} \dorecurse{5}{\filler[dots]}
1181\samplefile{knuth} \dorecurse{5}{\hairline}
1182\samplefile{knuth} \thinrules[n=5]
1183\stoptyping
1184
1185All of these produce the text plus some visual cure where to fill in
1186something.
1187
1188\stopsubject
1189
1190\stopdocument
1191