summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/rules/rules-mkiv.tex
blob: a6d727f1f0f1948ad89a1fdb474132a719cdca6f (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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
% language=us runpath=texruns:manuals/rules

% author    : Hans Hagen
% copyright : ConTeXt Development Team
% license   : Creative Commons Attribution ShareAlike 4.0 International
% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
% origin    : the ConTeXt distribution
%
% comment   : Because this manual is distributed with TeX distributions it comes with a rather
%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
%             that they describe. Using parts of the content otherwise can therefore conflict
%             with existing functionality and we cannot be held responsible for that. Many of
%             the manuals contain characteristic graphics and personal notes or examples that
%             make no sense when used out-of-context.
%
% comment   : Some chapters might have been published in TugBoat, the NTG Maps, the ConTeXt
%             Group journal or otherwise. Thanks to the editors for corrections. Also thanks
%             to users for testing, feedback and corrections.

\setupbodyfont
  [dejavu,10pt]

\setuphead
  [section]
  [style=\bfb]

\setupwhitespace
  [big]

\setuplayout
  [header=15mm,
   topspace=15mm,
   footer=0mm,
   bottomspace=20mm,
   height=middle,
   backspace=20mm,
   cutspace=20mm,
   width=middle]

\usemodule[x][setups-basics]

\loadsetups[context-en]
\loadsetups[i-linefiller]

\startdocument

\startMPpage

    StartPage ;

        linecap := butt ;

        fill Page withcolor .25[yellow/4,green/2] ;

        path p ; p := (ulcorner Page ..  urcorner Page .. lrcorner Page) ;

        draw image (
            for i=1/200 step 1/200 until 1 :
                draw p scaled i dashed dashpattern (on 4 randomized 2 off 4 randomized 2) ;
            endfor ;
        ) withcolor white ;

        draw anchored.urt(
            textext("\ss RULES") xsized .5PaperWidth,
            urcorner Page shifted(-15mm,-20mm)
        ) withcolor white ;

        draw anchored.urt(
            textext("\ss HANS HAGEN") xsized .5PaperWidth,
            lrcorner Page shifted(-15mm,40mm)
        ) withcolor white ;

        draw anchored.urt(
            textext("\ss A CONTEXT MKIV MANUAL") xsized .5PaperWidth,
            lrcorner Page shifted(-15mm,20mm)
        ) withcolor white ;

        setbounds currentpicture to Page ;

    StopPage ;

\stopMPpage

\startsubject[title=Introduction]

This manual describes just one type of rules: those that somehow magically are
bound to the typeset text. We will mention a few mechanisms that relate to this
in the sense that they share some of the underlaying code and logic. The term
\quotation {rules} should be interpreted liberally as we can kick in some
\METAPOST\ which then can get us away from straight rules.

This manual will not be that extensive, after all these mechanisms are not that
complex to configure.

\stopsubject

\startsubject[title=Underlining and overstriking]

Already in \CONTEXT\ \MKII\ we had underlining available but with some
limitations. We could handle more than one word but at some point you hit the
limits of the engine. The \MKIV\ implementation is more flexible. In fact you can
underline a whole document (which was actually a request from a user). This
feature was also used by a collegue who was experimenting with texts for
dyslectic readers.

This mechanism is generic in the sense that a framework is provided to define
rules that run alongside text. Take this:

\setupbars[foregroundcolor=darkyellow,color=darkred]

\startbuffer
\underbars {drawing \underbar{bars} under words is a typewriter leftover}
\overstrikes {striking words makes them \overstrike {unreadable} but
sometimes even \overbar {top lines} come into view.}
\stopbuffer

\typebuffer

This shows up as:

\getbuffer

We can best explain what happens by looking at how these commands are
defined:

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

\definebar
  [understrike]
  [method=0,
   offset=1.375,
   rulethickness=2.5,
   continue=yes,
   order=background]

\definebar[overbars]    [overbar]    [continue=no]
\definebar[underbars]   [underbar]   [continue=no]
\definebar[overstrikes] [overstrike] [continue=no]
\definebar[understrikes][understrike][continue=no]
\stoptyping

The formal definitions of the commands are show in \definition [definebar, setupbar].

\showdefinition{definebar}
\showdefinition{setupbar}

The \type {dy} parameter specifies the shift up or down. The offset defines how
nested bars are shifted. The \type {method} determines centering of the bar: we
set it to zero when we want an overstrike. The \type {continue} parameter is
responsible for drawing over spaces and the \type {order} determines the layering.

The units are either hard coded values like points or relate to the font at the spot
of the bar. Here are some examples:

\startbuffer
\setupbars[unit=mm,rulethickness=1]     bar \underbar{foo} bar\quad
\setupbars[unit=ex,rulethickness=1]     bar \underbar{foo} bar\quad
\setupbars[unit=pt,rulethickness=1]     bar \underbar{foo} bar\quad
\setupbars[unit=pt,rulethickness=10pt]  bar \underbar{foo} bar
\stopbuffer

\typebuffer \blank \start \getbuffer \stop \blank

As if underlining wasn't already bad enough, of course at some point there came a
request for dashed lines.

\startbuffer
test \underrandoms{test me} and \underrandom{test} or \underrandom{grep}
test \underdashes {test me} and \underdash  {test} or \underdash  {grep}
test \underdots   {test me} and \underdot   {test} or \underdot   {grep}
\stopbuffer

\typebuffer

The above variants are predefined and render as:

\startlines
\tfb \getbuffer
\stoplines

A graphic is defined as follows. It boils down to drawing one or more shapes. In
this example we also force a specific boundingbox so that the result gets
positioned right.

\starttyping
\startuseMPgraphic{rules:under:...}
    draw
        ((0,RuleDepth) -- (RuleWidth,RuleDepth))
        shifted (0,RuleFactor*RuleOffset)
        withpen pencircle scaled RuleThickness
        withcolor RuleColor ;
    setbounds currentpicture to unitsquare xysized(RuleWidth,RuleHeight) ;
\stopuseMPgraphic
\stoptyping

The following variables are available:

\starttabulate[|T|||]
\BC variable      \BC type     \BC meaning                                 \NC \NR
\ML
\NC RuleDirection \NC string   \NC the direction of the line               \NC \NR
\NC RuleOption    \NC string   \NC whatever the caller finds useful        \NC \NR
\NC RuleWidth     \NC number   \NC the requested width of the rule         \NC \NR
\NC RuleHeight    \NC number   \NC the requested height of the rule        \NC \NR
\NC RuleDepth     \NC number   \NC the requested depth of the rule         \NC \NR
\NC RuleThickness \NC number   \NC the linewidth                           \NC \NR
\NC RuleFactor    \NC number   \NC the set factor (e.g. an \type {ex})     \NC \NR
\NC RuleOffset    \NC number   \NC an (optional) offset in case of nesting \NC \NR
\NC RuleColor     \NC color    \NC the color                               \NC \NR
\stoptabulate

The \type {RuleFactor} can be used as multiplier for the \type {RuleOffset}.
Later we will see an example of how to use the \type {RuleDirection} and \type
{RuleOption}.

The extra under commands are defined as follows. Watch the \type {mp} parameter:
it refers to a graphic.

\starttyping
\definebar
  [undergraphic]
  [mp=rules:under:dash,
   offset=-.2,
   order=background]

\definebar[underrandom] [undergraphic][mp=rules:under:random]
\definebar[underrandoms][underrandom] [continue=yes]

\definebar[underdash]   [undergraphic][mp=rules:under:dash]
\definebar[underdashes] [underdash]   [continue=yes]

\definebar[underdot]    [undergraphic][mp=rules:under:dots]
\definebar[underdots]   [underdot]    [continue=yes]
\stoptyping

A nasty side effect of the implementation is that because we look mostly at glyphs,
optionally separated by glue or kern some text might get unseen and therefore not
treated.

\startbuffer
\underbars{We see this \high{\tfxx ®} symbol \runninghbox to 1cm{\hss} often.}
\underbar {We see this \high{\tfxx ®} symbol \runninghbox to 1cm{\hss} often.}
\stopbuffer

\typebuffer

This gives:

\startlines
\getbuffer
\stoplines

A running box is seen as text. As you (probably) expect, a nested ornamental
rule is supported as well:

\startbuffer
\underbars
  {We see this \high{\tfxx\underdot{®}} symbol \runninghbox to 1cm{\hss} often.}
\underbar
  {We see this \high{\tfxx\underdot{®}} symbol \runninghbox to 1cm{\hss} often.}
\stopbuffer

\typebuffer

This time we get (you might need a magnifier to see it):

\startlines
\getbuffer
\stoplines

We end this section with an extreme example:

\startbuffer
\definebar
  [xbarone]
  [text=\lower\exheight\hbox{\darkred \infofont +},
   repeat=yes]
\definebar
  [xbartwo]
  [text=\lower\exheight\hbox{\darkblue\infofont +},
   repeat=yes,
   continue=yes]
\stopbuffer

\typebuffer \getbuffer

\startbuffer
Klein    : \xbarone{\samplefile   {klein}\removeunwantedspaces}\par
Sapolsky : \xbartwo{\samplefile{sapolsky}\removeunwantedspaces}\par
\stopbuffer

\typebuffer \getbuffer


\stopsubject

\startsubject[title=Shifting]

We mention shifting here because it shares code with the bars. There are two
shifts defined but you can define more:

\starttyping
\defineshift
  [shiftup]
  [method=0,
   dy=-1,
   unit=ex,
   continue=yes,
   style=\txx]

\defineshift
  [shiftdown]
  [method=1,
   dy=.3,
   unit=ex,
   continue=yes,
   style=\txx,
   color=]
\stoptyping

An example of using the commands defined this way is:

\startbuffer
Let's go \shiftup{up} and \shiftdown{down} a bit!
\stopbuffer

\typebuffer

or: \inlinebuffer\ Here we just shift words but you can shift more than that
although I haven't yet seen a useful example of that:

\startbuffer
We can \shiftup {\samplefile{tufte}} whole paragraphs if we really want.
\stopbuffer

\typebuffer

\getbuffer

The formal definitions are given in \definition[defineshift, setupshift,
startshift]. The \type {align} switch is there for directional (and testing)
purposes and is normally not used (or even useful in a line). The \type {dy}
is multiplied by the \type {factor} that itself can depend on the used font.

\showdefinition{defineshift}
\showdefinition{setupshift}
\showdefinition{startshift}

\stopsubject

\startsubject[title=Fillers]

The possibility of line fillers was mentioned by Mojca on the \CONTEXT\ mailing
list and it's actually not that hard to implement them. The only need I ever had
for it was to fill out lines on some legal form and that was actually just some
fun challenge in \MKII\ times. The code got lost and never made it into \CONTEXT.
This time it was added as a side effect of a thread at the tenth \CONTEXT\
meeting.

The ideas is to fill the rest of a line with some kind of (ornamental) rule. I'm
not sure what sense it makes, even in legal documents. If it is to prevent
additions then one should wonder if additions at the end of a (kind of arbitrary)
broken line is what we should be afraid of most. So, for now, let's consider it
an educational feature.

\startbuffer
\definelinefiller
  [filler-1]
  [height=.75\exheight,
   distance=.25\emwidth,
   rulethickness=.25\exheight,
   textcolor=darkyellow,
   before=\blank,
   after=\blank,
   color=darkred]

\startlinefiller[filler-1]
    \samplefile{ward}
\stoplinefiller
\stopbuffer

\typebuffer

Here we define a filler. As you can see, a rule gets added at the end of a
paragraph.

\getbuffer

\startbuffer
\startalign[flushleft,broad]
    \startlinefiller[filler-1]
        \samplefile{ward}
    \stoplinefiller
\stopalign
\stopbuffer

This time we don't justify:

\typebuffer

Now more lines get a rule appended:

\getbuffer

Before we continue it must be noted that the environment creates a paragraph. If
you don't want that you need to use \type {\setlinefiller} instead. Next we show
a \type {middle} alignment:

\startbuffer
\startalign[middle]
    \startlinefiller[filler-1]
        \samplefile{ward}
    \stoplinefiller
\stopalign
\stopbuffer

\getbuffer

\startbuffer
\startalign[middle]
    \startnarrower
        \startlinefiller[filler-1]
            \samplefile{ward}
        \stoplinefiller
    \stopnarrower
\stopalign
\stopbuffer

Let's add another level of complexity, left- and right skips:

\typebuffer

Here we get:

\getbuffer

The lines stay within the narrower boundaries but you can extend them
to the margins if you like:

\startbuffer
\startalign[middle]
    \startnarrower
        \startlinefiller[filler-1][scope=global]
            \samplefile{ward}
        \stoplinefiller
    \stopnarrower
\stopalign
\stopbuffer

\typebuffer

This looks like:

\getbuffer

You can also use a \type {left} or \type {right} scope, as in:

\startbuffer
\startalign[middle]
    \startnarrower
        \startlinefiller[filler-1][scope=right]
            \samplefile{ward}
        \stoplinefiller
    \stopnarrower
\stopalign
\stopbuffer

\typebuffer

Only the right rules extend into the margins.

\getbuffer

\startbuffer
\startalign[middle]
    \startnarrower
        \startlinefiller[filler-1][scope=right,location=right]
            \samplefile{ward}
        \stoplinefiller
    \stopnarrower
\stopalign
\stopbuffer

You can get rid of the left rules:

\typebuffer

So:

\getbuffer

Of course these rules are somewhat boring so let's now kick in some \METAPOST.

\startbuffer[mp]
\setuplinefiller
  [filler-1]
  [mp=rules:filler:demo,
  %threshold=.25\emwidth,
   color=darkred]

\startuseMPgraphic{rules:filler:demo}
    drawarrow
        if RuleDirection == "TRT" : reverse fi
            ((0,RuleHeight) -- (RuleWidth,RuleHeight))
        withpen
            pencircle scaled RuleThickness
        withcolor
            if RuleOption == "left" : complemented fi RuleColor ;
    setbounds currentpicture to
        unitsquare xysized(RuleWidth,RuleHeight) ;
\stopuseMPgraphic
\stopbuffer

\typebuffer[mp] \getbuffer[mp]

The previous example now looks like:

\getbuffer

\startbuffer
\startalign[middle,r2l]
    \startnarrower[4*middle]
        \startlinefiller[filler-1]  [scope=global]
            \samplefile{ward}
        \stoplinefiller
    \stopnarrower
\stopalign
\stopbuffer

This time we also change the direction and we can let the \METAPOST\ graphic
adapt to that by reverting the arrows.

\typebuffer

The direction \type {TRT} is \TEX\ speak for a right|-|to|-|left direction. We
use a latin script example for convenience.

\getbuffer

\startbuffer[mp]
\startuseMPgraphic{rules:filler:demo}
    drawarrow
        if RuleDirection == "TRT" : reverse fi
            if RuleOption == "right" : reverse fi
            ((0,RuleHeight) -- (RuleWidth,RuleHeight))
        withpen
            pencircle scaled RuleThickness
        withcolor
            if RuleOption == "left" : complemented fi RuleColor ;
    setbounds currentpicture to
        unitsquare xysized(RuleWidth,RuleHeight) ;
\stopuseMPgraphic
\stopbuffer

% \startbuffer
% \startnarrower[4*middle]
%     \startlinefiller[filler-1] [scope=global,align=middle]
%         \parindent   100pt
%         \parfillskip 100pt
%         \samplefile{ward}
%     \stoplinefiller
% \stopnarrower
% \stopbuffer

\startbuffer
\startnarrower[4*middle]
    \startlinefiller[filler-1] [scope=global,align={middle,r2l}]
        \parindent   100pt
        \parfillskip 100pt
        \samplefile{ward}
    \stoplinefiller
\stopnarrower
\stopbuffer

The next rendering shows what happens when we set \type {\parindent} and \type
{\parfillskip} to an excessive have a \type {100pt}.

\getbuffer[mp] \getbuffer

Here we have adapted the graphic a bit:

\starttyping
if RuleDirection == "TRT" : reverse fi
    if RuleOption == "right" : reverse fi
    ((0,RuleHeight) -- (RuleWidth,RuleHeight))
\stoptyping

\showdefinition{definelinefiller}
\showdefinition{setuplinefiller}

\stopsubject

% \startsubject[title=Backgrounds]
% \stopsubject

\startsubject[title=User rules]

Characters and rules are the only graphical elements that \TEX\ really knows
about. Even if you see images in a document, you should realize that they are
just blobs with dimensions and that the backend replaces such blobs by real
images.

The primitive operations for rules are \type {\hrule} and \type {\vrule} and the
main difference is to what way they adapt to their situation when no dimensions
are given and the mode change they trigger.

\startbuffer
hrule{\darkred   \hrule width 10cm height 3mm depth 2mm}\par
vrule{\darkyellow\vrule width 10cm height 3mm depth 2mm}\par
hrule{\darkred   \hrule width 10cm                     }\par
vrule{\darkyellow\vrule            height 3mm depth 2mm}\par

hrule{\darkred   \leaders\hrule height 1mm\relax\hfill}hrule\par
\stopbuffer

\typebuffer

When more text is to follow you should end a specification with \type {\relax} to
make sure that the scanner stops looking for more arguments. With \type {\leaders}
you can create flexible rules.

\startlinecorrection
\getbuffer
\stoplinecorrection

In \CONTEXT\ we also have so called frame rules:

\startbuffer
\color[darkred]{\frule
    width 10cm
    height 1cm
    line   1mm
\relax}
\stopbuffer

\typebuffer

This will produce a rectangle:

\startlinecorrection
\getbuffer
\stoplinecorrection

There are a few more keywords. Keep in mind that we actually have a new kind of
primitive here, so we follow the \TEX\ conventions of keywords.

\startbuffer
\ruledhbox\bgroup
    \darkgray
    \frule width 100mm height 10mm depth 8mm radius 2mm line 2pt type fill\relax
    \hskip-100mm
    \darkred
    \frule width 100mm height 10mm depth 8mm radius 2mm line 2pt\relax
    \hskip-100mm
    \hbox to 100mm{\white \bold \hfill some handy word with frames\hfill}%
\egroup
\stopbuffer

\typebuffer

Of course this is a rather low level way of doing frames and such, but when you
like that kind of low level programming you get the possibility here.

\startlinecorrection
\getbuffer
\stoplinecorrection

You can combine this with existing mechanisms. Take the following:

\startbuffer
\defineoverlay[normalframe]
  [\frule
     width \overlaywidth
     height\overlayheight
     line  \overlaylinewidth
  ]

\defineoverlay[ovalframe]
  [\frule
     width  \overlaywidth
     height \overlayheight
     line   \overlaylinewidth
     radius \overlayradius
  ]
\stopbuffer

\typebuffer \getbuffer

\startbuffer
\hbox \bgroup
    \framed                                  {test}\quad
    \framed[frame=off]                       {test}\quad
    \framed[background=normalframe,frame=off]{test}\quad
    \framed[background=normalframe,frame=off]{test}\quad
    \framed[corner=round]                    {test}\quad
    \framed[corner=round]                    {test}\quad
    \framed[background=ovalframe,frame=off]  {test}\quad
    \framed[background=ovalframe,frame=off]  {test}\quad
    \framed[background=ovalframe,frame=on]   {test}\quad
    \framed[background=ovalframe,frame=on]   {test}\quad
\egroup
\stopbuffer

This is a variant on the already available round corners:

\startlinecorrection
\getbuffer
\stoplinecorrection

The above result is accomplished with:

\typebuffer

Given the examples in the previous sections it will be no surprise that we
can also use \METAPOST.

\startbuffer
\startuseMPgraphic{demoshape:back}
    fill
        unitcircle xysized (RuleWidth,RuleHeight+RuleDepth)
        withcolor RuleColor ;
\stopuseMPgraphic

\startuseMPgraphic{demoshape:fore}
    draw
        unitcircle xysized (RuleWidth,RuleHeight+RuleDepth)
        withcolor RuleColor
        withpen pencircle scaled 4RuleThickness ;
\stopuseMPgraphic

\hbox\bgroup
    \darkgray \frule width 100mm height 10mm depth 8mm type mp line 2pt
        data {\includeMPgraphic{demoshape:back}}
    \relax
    \hskip-100mm
    \darkred \frule width 100mm height 10mm depth 8mm type mp line 2pt
        data {\includeMPgraphic{demoshape:fore}}
    \relax
    \hskip-100mm
    \hbox to 100mm{\white \bold \hfill some handy word with frames\hfill}
\egroup
\stopbuffer

\typebuffer

Or rendered:

\startlinecorrection
\getbuffer
\stoplinecorrection

The \type {\blackrule} command is the more high level way to inject a rule.

\startbuffer
\blackrule
  [width=10cm,
   height=1cm,
   depth=1cm,
   color=darkred]
\stopbuffer

\typebuffer

This produces a boring rule:

\startlinecorrection
\getbuffer
\stoplinecorrection

Again we can revert to \METAPOST:

\startbuffer
\blackrule
  [width=10cm,
   height=1cm,
   depth=1cm,
   color=darkred,
   type=mp,
   mp=demoshape:back]
\stopbuffer

\typebuffer

or:

\startlinecorrection
\getbuffer
\stoplinecorrection

The formal definition of this command is shown in \definition [setupblackrules,
blackrule].

\showdefinition{setupblackrules}
\showdefinition{blackrule}

\stopsubject

\startsubject[title=Hiding]

In education a to be filled in text is often represented by a gap in the running text
and the bar drawing mechanism supports this. THere is a predefined \type {\hiddenbar}
command:

\starttyping
\definebar
  [hiddenbar] [underbar]
  [continue=yes,empty=yes,
   left=\zwj,right=\zwj]
\stoptyping

\startbuffer
\samplefile{ward}\hiddenbar               {\color[red]{invisible}}
\samplefile{ward}\hiddenbar          {\quad\color[red]{invisible}\quad}
\samplefile{ward}\hiddenbar{\quad\quad\quad\color[red]{invisible}\quad\quad\quad}
\samplefile{ward}\hiddenbar               {\color[red]{invisible}\quad\quad\quad\quad\quad\quad}
\samplefile{ward}
\stopbuffer

\getbuffer

The previous text is generated with:

\typebuffer

Here is a variant that inserts spacing at the left and right edges. In this case
the spacing is kept at a linebreak:

\startbuffer
\definebar
  [widehiddenbar]
  [hiddenbar]
  [left={\quads[3]},
   right={\quads[3]}]

\widehiddenbar{invisible} \samplefile{weisman}
\widehiddenbar{invisible} \samplefile{weisman}
\widehiddenbar{invisible}
\stopbuffer

\typebuffer

\getbuffer

\stopsubject

\startsubject[title=Tabulate]

The previously discussed mechanism is also available in the tabulate mechanism.
We start with simple backgrounds:

\startbuffer
\starttabulate
    \NL[darkred]    foo \NC bar \NC \NR
    \NL[darkgreen]  foo \NC bar \NC \NR
    \NL[darkblue]   foo \NC \samplefile{tufte} \NC \NR
    \NL[darkgray]   foo \NC bar \NC \NR
    \NL[darkyellow] foo \NC bar \NC \NR
    \LL
\stoptabulate
\stopbuffer

\typebuffer

This comes out as:

{\startcolor[white]\getbuffer\stopcolor}

There are several two character commands that deal with this:

\starttabulate[|c|c|l|]
\BC command    \BC related to \BC effect \NC
\NC \type{\NL} \NC \type{\NC} \NC Normal with Line \NC \NR
\NC \type{\ND} \NC \type{\NC} \NC Normal with Default Line \NC \NR
\NC \type{\LB} \NC \type{\BC} \NC Bold   with Line \NC \NR
\NC \type{\DB} \NC \type{\BC} \NC Bold   with Default Line \NC \NR
\NC \type{\NF} \NC \type{\NC} \NC Normal with Filler \NC \NR
\NC \type{\NP} \NC \type{\NC} \NC Normal with Predefined Filler \NC \NR
\NC \type{\FB} \NC \type{\BC} \NC Bold   with Filler \NC \NR
\NC \type{\NA} \NC \type{\NC} \NC Normal with Auto Toggled Line \NC \NR
\NC \type{\BA} \NC \type{\BC} \NC Bold   with Auto Toggled Line \NC \NR
\stoptabulate

Before we show more, we set up tabulate:

\startbuffer[setup]
\setuptabulate
  [blank={small,samepage},
   headstyle=bold,
   rulecolor=darkred,
   rulethickness=1pt,
   background=foo,
   backgroundcolor=darkred,
   foregroundcolor=white]
\stopbuffer

\typebuffer[setup]

This time we don't set colors in the table itself:

\startbuffer
\starttabulate[|l|l|]
    \DB foos        \BC bars            \BC \NR
    \TB
    \NC foo foo foo \NC bar bar bar bar \NC \NR
    \NC foo foo foo \NC bar bar bar bar \NC \NR
    \NC foo foo foo \NC bar bar bar bar \NC \NR
    \NC foo foo foo \NC bar bar bar bar \NC \NR
    \LL
\stoptabulate
\stopbuffer

\typebuffer {\getbuffer[setup]\getbuffer}

Instead of coming up with a separate mechanism for hooking in \METAPOST\ we
use the linefiller mechanism. We use these graphics:

\startbuffer
\startuseMPgraphic{foo}
  fill unitsquare
    xyscaled (RuleWidth,RuleHeight+RuleDepth) enlarged (ExHeight/4,ExHeight/8)
    shifted  (-ExHeight/8,ExHeight/16)
    withcolor RuleColor ;
\stopuseMPgraphic

\startuseMPgraphic{bar}
  fill unitsquare
    xyscaled (RuleWidth,RuleHeight+RuleDepth) enlarged (ExHeight/4,ExHeight/8)
    shifted  (-ExHeight/8,ExHeight/16)
    randomized ExHeight
    withcolor RuleColor ;
\stopuseMPgraphic
\stopbuffer

\typebuffer \getbuffer

With these fillers:

\startbuffer
\definelinefiller[foo][mp=foo,color=darkgreen]
\definelinefiller[bar][mp=bar,color=darkred]
\stopbuffer

\typebuffer \getbuffer

An example of usage is:

\startbuffer
\linefillerhbox[foo] to 12cm{\hss\strut\white\bf FOO\hss} \blank
\linefillerhbox[bar] to 10cm{\hss\strut\white\bf BAR\hss} \blank
\linefillerhbox[foo] to  9cm{\hss\strut\white\bf FOO\hss} \blank
\linefillerhbox[bar] to 14cm{\hss\strut\white\bf BAR\hss}
\stopbuffer

\typebuffer \blank \getbuffer \blank

We can rely on the default:

\startbuffer
\starttabulate[|||]
    \PB foo         \BC bars            \BC \NR
    \NC foo foo foo \NC bar bar bar bar \NC \NR
    \NC foo foo foo \NC bar bar bar bar \NC \NR
    \NC foo foo foo \NC bar bar bar bar \NC \NR
    \NC foo foo foo \NC bar bar bar bar \NC \NR
\stoptabulate
\stopbuffer

\typebuffer \start\getbuffer[setup]\getbuffer\stop

or be explicit:

\startbuffer
\starttabulate[|||]
    \FB[bar] foos        \BC bars            \BC \NR
    \NC      foo foo foo \NC bar bar bar bar \NC \NR
    \NC      foo foo foo \NC bar bar bar bar \NC \NR
    \NC      foo foo foo \NC bar bar bar bar \NC \NR
    \NC      foo foo foo \NC bar bar bar bar \NC \NR
\stoptabulate
\stopbuffer

\typebuffer \start\getbuffer[setup]\getbuffer\stop

The auto variants will switch between colors:

\startbuffer
\setuptabulate[backgroundcolor:1=darkred]
\setuptabulate[backgroundcolor:2=darkgreen]
\setuptabulate[backgroundcolor:3=darkblue]

\starttabulate[|||]
    \BA foo foo foo \BC bar bar bar bar \NC \NR
    \BA foo foo foo \BC bar bar bar bar \NC \NR
    \BA foo foo foo \BC bar bar bar bar \NC \NR
    \BA foo foo foo \BC bar bar bar bar \NC \NR
    \BA foo foo foo \BC bar bar bar bar \NC \NR
    \BA foo foo foo \BC bar bar bar bar \NC \NR
\stoptabulate
\stopbuffer

\typebuffer \start\getbuffer[setup]\getbuffer\stop


\stopsubject

\stopdocument