summaryrefslogtreecommitdiff
path: root/tex/context/base/supp-lan.tex
blob: 83c0a49fd5585fd5c800c9ac99cf5171068ab879 (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
%D \module
%D   [       file=supp-lan,
%D        version=1997.03.20,
%D          title=\CONTEXT\ Support Macros,
%D       subtitle=Language Options,
%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 licen-en.pdf for 
%C details. 

%D \gdef\starttest%
%D   {\blanko
%D    \noindent
%D    \halign\bgroup\tt##\hskip2em&##\hskip2em&##\cr}
%D
%D \gdef\stoptest%
%D   {\egroup
%D    \blanko}
%D
%D \gdef\test#1%
%D   {\convertargument#1\to\ascii\ascii&\hyphenatedword{#1}&#1\cr}

%D One of \TEX's strong points in building paragraphs is the way
%D hyphenations are handled. Although for real good hyphenation
%D of non||english languages some extensions to the program are
%D needed, fairly good results can be reached with the standard
%D mechanisms and an additional macro, at least in Dutch.

\unprotect

\writestatus{loading}{Context Support Macros / Language Options}

%D \CONTEXT\ originates in the wish to typeset educational
%D materials, especially in a technical environment. In
%D production oriented environments, a lot of compound words
%D are used. Because the Dutch language poses no limits on
%D combining words, we often favor putting dashes between those
%D words, because it facilitates reading, at least for those
%D who are not that accustomed to it.
%D
%D In \TEX\ compound words, separated by a hyphen, are not
%D hyphenated at all. In spite of the multiple pass paragraph
%D typesetting this can lead to parts of words sticking into
%D the margin. The solution lays in saying
%D \type{spoelwater||terugwinunit} instead of
%D \type{spoelwater-terugwinunit}. By using a one character
%D command like \type{|}, delimited by the same character
%D \type{|}, we get ourselves both a decent visualization (in
%D \TEXEDIT\ and colored verbatim we color these commands
%D yellow) and an efficient way of combining words.
%D
%D The sequence \type{||} simply leads to two words connected by
%D a hyphen. Because we want to distinguish such a hyphen from
%D the one inserted when \TEX\ hyphenates a word, we use a bit
%D longer one.
%D
%D \hyphenation {spoel-wa-ter te-rug-win-unit}
%D
%D \starttest
%D \test {spoelwater||terugwinunit}
%D \stoptest
%D
%D As we already said, the \type{|} is a command. This commands
%D accepts an optional argument before it's delimiter, which is
%D also a \type{|}.
%D
%D \hyphenation {po-ly-meer che-mie}
%D
%D \starttest
%D \test {polymeer|*|chemie}
%D \stoptest
%D
%D Arguments like \type{*} are not interpreted and inserted
%D directly, in contrary to arguments like:
%D
%D \starttest
%D \test {polymeer|~|chemie}
%D \test {|(|polymeer|)|chemie}
%D \test {polymeer|(|chemie|)| }
%D \stoptest
%D
%D Although such situations seldom occur |<|we typeset thousands
%D of pages before we encountered one that forced us to enhance
%D this mechanism|>| we also have to take care of comma's.
%D
%D \hyphenation {uit-stel-len}
%D
%D \starttest
%D \test {op||, in|| en uitstellen}
%D \stoptest
%D
%D The next special case (concerning quotes) was brought to my
%D attention by Piet Tutelaers, one of the driving forces
%D behind rebuilding hyphenation patterns for the dutch
%D language.\voetnoot{In 1996 the spelling of the dutch
%D language has been slightly reformed which made this topic
%D actual again.} We'll also take care of this case.
%D
%D \starttest
%D \test {AOW|'|er}
%D \test {cd|'|tje}
%D \test {ex|-|PTT|'|er}
%D \test {rock|-|'n|-|roller}
%D \stoptest
%D
%D Tobias Burnus pointed out that I should also support
%D something like
%D
%D \starttest
%D \test {well|_|known}
%D \stoptest
%D 
%D to strees the compoundness of hyphenated words. 
%D
%D Of course we also have to take care of the special case: 
%D
%D \starttest
%D \test {text||color and ||font}
%D \stoptest

%D \macros
%D   {installdiscretionaries}
%D
%D The mechanism described here is one of the older inner parts
%D of \CONTEXT. The most recent extensions concerns some
%D special cases as well as the possibility to install other
%D characters as delimiters. The prefered way of specifying
%D compound words is using \type{||}, which is installed by:
%D
%D \starttypen
%D \installdiscretionaries || -
%D \stoptypen
%D
%D Some alternative definitions are:
%D
%D \startbuffer
%D \installdiscretionaries ** -
%D \installdiscretionaries ++ -
%D \installdiscretionaries // -
%D \installdiscretionaries ~~ -
%D \stopbuffer
%D
%D \typebuffer
%D
%D after which we can say:
%D
%D \bgroup
%D \haalbuffer
%D \starttest
%D \test {test**test**test}
%D \test {test++test++test}
%D \test {test//test//test}
%D \test {test~~test~~test}
%D \stoptest
%D \egroup

%D \macros
%D   {compoundhyphen,
%D    beginofsubsentence,endofsubsentence}
%D   {}
%D
%D Now let's go to the macros. First we define some variables.
%D In the main \CONTEXT\ modules these can be tuned by a setup
%D command. Watch the (maybe) better looking compound hyphen.

\def\compoundhyphen     {{-}\kern-.25ex{-}}
\def\beginofsubsentence {---}
\def\endofsubsentence   {---}

%D The last two variables are needed for subsentences
%D |<|like this one|>| which we did not yet mention.
%D
%D We want to enable breaking but at the same time don't want
%D compound characters like |-| or || to be separated from the
%D words. \TEX\ hackers will recognise the next two macro's:

\def\prewordbreak  {\penalty10000\hskip0pt\relax}
\def\postwordbreak {\penalty0\prewordbreak}

%D We first show the original implementation, which only
%D supports \type{|} as command and delimiter. Before
%D activating \type{|} we save it's value:
%D
%D \starttypen
%D \edef\domathmodediscretionary{\string|}
%D \stoptypen
%D
%D after which we're ready to define it's meaning to:
%D
%D \starttypen
%D \catcode`\|=\@@active
%D
%D \unexpanded\def|%
%D   {\ifmmode
%D      \expandafter\domathmodediscretionary
%D    \else
%D      \expandafter\dotextmodediscretionary
%D    \fi}
%D \stoptypen
%D
%D We need a two stage \type{\futurelet} because we want to
%D look ahead for both the compound character definition and
%D the (optional) comma that follows it, and because we want to
%D prevent that \TEX\ puts this comma on the next line. We use
%D \type{\next} for easy and fast checking of the argument, we
%D save this argument (which can consist of more tokens) and
%D also save the character following the \type{|#1|} in
%D \type{\nextnext}.
%D
%D \starttypen
%D \def\dotextmodediscretionary%
%D   {\bgroup
%D    \futurelet\next\dodotextmodediscretionary}
%D
%D \def\dodotextmodediscretionary#1|%
%D   {\def\betweendiscretionaries{#1}%
%D    \futurelet\nextnext\dododotextmodediscretionary}
%D \stoptypen
%D
%D The main macro consists of quite some \type{\ifx} tests
%D while \type{\checkafterdiscretionary} handles the commas.
%D We show the simplified version here:
%D
%D \starttypen
%D \def\dododotextmodediscretionary%
%D   {\let\nextnextnext=\egroup
%D    \ifx     |\next
%D      \checkafterdiscretionary
%D      \prewordbreak\hbox{\compoundhyphen\nextnext}\allowbreak
%D    \else\ifx=\next
%D      \prewordbreak\compoundhyphen
%D    \else\ifx~\next
%D      \discretionary{-}{}{\thinspace}\postwordbreak
%D    \else\ifx(\next
%D      \prewordbreak\discretionary{}{(-}{(}\prewordbreak
%D    \else\ifx)\next
%D      \prewordbreak\discretionary{-)}{}{)}\prewordbreak
%D    \else\ifx'\next
%D      \prewordbreak\discretionary{-}{}{'}\postwordbreak
%D    \else
%D      \checkafterdiscretionary
%D      \prewordbreak\hbox{\betweendiscretionaries\nextnext}\allowbreak
%D    \fi\fi\fi\fi\fi\fi
%D    \nextnextnext}
%D
%D \def\checkafterdiscretionary%
%D   {\ifx,\nextnext
%D      \def\nextnextnext{\afterassignment\egroup\let\next=}%
%D    \else
%D      \let\nextnext=\relax
%D    \fi}
%D \stoptypen
%D 
%D Handling \type{(} and \type{)} is a a bit special, because
%D \TEX\ sees them as decent hyphenation points, according to
%D their \type{\lccode} being non||zero. For the same reason,
%D later on in this module we cannot manipulate the
%D \type{\lccode} but take the \type{\uccode}.

%D The most recent implementation is more advanced. As
%D demonstrated we can install delimiters, like:
%D
%D \starttypen
%D \installdiscretionaries || \compoundhyphen
%D \stoptypen
%D
%D This time we have to use a bit more clever way of saving the
%D math mode specification of the character we're going to
%D make active. We also save the user supplied compound hyphen.
%D We show the a bit more traditional implementation first.
%D
%D \starttypen
%D \def\installdiscretionaries#1%
%D   {\catcode`#1\@@other
%D    \expandafter\doinstalldiscretionaries\string#1}
%D
%D \def\doinstalldiscretionaries#1%
%D   {\setvalue{mathmodediscretionary#1}{#1}%
%D    \catcode`#1\@@active
%D    \dodoinstalldiscretionaries}
%D
%D \def\dodoinstalldiscretionaries#1#2%
%D   {\setvalue{textmodediscretionary\string#1}{#2}%
%D    \unexpanded\def#1{\discretionarycommand#1}}
%D \stoptypen
%D
%D A bit more \CATCODE\ and character trickery enables us to
%D discard the two intermediate steps. This trick originates
%D on page~394 of the \TEX book, in the appendix full of
%D dirty tricks. The second argument has now become redundant,
%D but I decided to reserve it for future use. At least it
%D remembers us of the symmetry.

\beginTEX

\def\installdiscretionaries#1#2#3% 
  {\convertargument#1\to\ascii
   \setevalue{mathmodediscretionary\string#1}{\ascii}% 
   \setvalue{textmodediscretionary\string#1}{#3}%
   \catcode`#1=\@@active
   \scratchcounter=\the\uccode`~
   \uccode`~=`#1
   \uppercase{\unexpanded\def~{\discretionarycommand~}}%
   \uccode`~=\scratchcounter}

\endTEX

\beginETEX \detokenize

\def\installdiscretionaries#1#2#3% 
  {\setevalue{mathmodediscretionary\string#1}{\detokenize{#1}}% 
   \setvalue{textmodediscretionary\string#1}{#3}%
   \catcode`#1=\@@active
   \scratchcounter=\the\uccode`~
   \uccode`~=`#1
   \uppercase{\unexpanded\def~{\discretionarycommand~}}%
   \uccode`~=\scratchcounter}

\endETEX

\def\dohandlemathmodebar#1%
  {\getvalue{mathmodediscretionary\string#1}}

\def\discretionarycommand%
  {\relax\ifmmode
     \expandafter\dohandlemathmodebar
   \else
     \expandafter\dotextmodediscretionary
   \fi}

%D The next piece of code is a torture test for this previous
%D macro. The \type {\relax} before the \type {\ifmmode} is
%D needed because of the alignment scanner (in \ETEX\ this 
%D problem is not present because there a protected macro is 
%D not expanded. Thanks to Tobias Burnus for providing this 
%D example. 
%D 
%D \startformule
%D   \left|f(x_n)-{1\over2}\right| = 
%D      {\cases{|{1\over2}-x_n| &for $0\le x_n < {1\over2}$\cr
%D              |x_n-{1\over2}| &for ${1\over2}<x_n\le1$   \cr}}
%D \stopformule

%D \macros 
%D   {defineactivecharacter}
%D
%D In \type {lang-ger.tex} we define some language specific 
%D commands for german input, like:
%D 
%D \starttyping
%D \startlanguagespecifics[de]
%D   \installcompoundcharacter "a {\moveaccent{-.1ex}\"a\midworddiscretionary}
%D \stoplanguagespecifics 
%D \stoptyping
%D 
%D Occasionally we have to redefine such an active character, 
%D like in:
%D 
%D \starttyping
%D \startencoding[pdfdoc]
%D   \startlanguagespecifics[de]
%D     \defineactivecharacter " {\"}
%D   \stoplanguagespecifics
%D \stopencoding
%D \stoptyping
%D 
%D Here is the command we used:

\def\defineactivecharacter #1 #2%
  {\catcode`#1=\@@active
   \scratchcounter=\the\uccode`~
   \uccode`~=`#1\relax
   \def\next{#2}%
   \uppercase{\let~\next}%
   \uccode`~=\scratchcounter}

%D Although adapting character codes and making characters
%D active can interfere with other features of macropackages,
%D normally there should be no problems with things like:
%D
%D \starttypen
%D \installdiscretionary || +
%D \installdiscretionary ++ =
%D \stoptypen
%D
%D The real work is done by the next set of macros. We have
%D to use a double \type{\futurelet} because we have to take
%D following characters into account.

\def\dotextmodediscretionary#1%
  {\bgroup
   \def\dodotextmodediscretionary##1#1%
     {\def\betweendiscretionary{##1}%
      \futurelet\nextnext\dododotextmodediscretionary}%
   \let\discretionarycommand=#1%
   \def\textmodediscretionary{\getvalue{textmodediscretionary\string#1}}%
   \futurelet\next\dodotextmodediscretionary}

\def\dododotextmodediscretionary%
  {\let\nextnextnext=\egroup
   \ifx\discretionarycommand\next
     \checkafterdiscretionary
     \bgroup
       \checkbeforediscretionary
       \prewordbreak\hbox{\textmodediscretionary\nextnext}\allowbreak
     \egroup
   \else\ifx=\next
     \prewordbreak\textmodediscretionary
   \else\ifx~\next
     \prewordbreak\discretionary{-}{}{\thinspace}\postwordbreak
   \else\ifx_\next
     \prewordbreak\discretionary{\textmodediscretionary}
       {\textmodediscretionary}{\textmodediscretionary}\prewordbreak
   \else\ifx(\next
     \ifdim\lastskip>\!!zeropoint\relax
       (\prewordbreak
     \else
       \prewordbreak\discretionary{}{(-}{(}\prewordbreak
     \fi
   \else\ifx)\next
     \ifx\nextnext\blankspace
       \prewordbreak)\relax
     \else
       \prewordbreak\discretionary{-)}{}{)}\prewordbreak
     \fi
   \else\ifx'\next
     \prewordbreak\discretionary{-}{}{'}\postwordbreak
   \else\ifx<\next
     \beginofsubsentence\prewordbreak\beginofsubsentencespacing
   \else\ifnum\uccode`>=\nextuccode
     \endofsubsentencespacing\prewordbreak\endofsubsentence
   \else
     \checkafterdiscretionary
     \bgroup
       \checkbeforediscretionary
      %\prewordbreak\hbox{\betweendiscretionary\nextnext}\allowbreak
       \prewordbreak
       \discretionary{\hbox{\betweendiscretionary}}{}{\hbox{\betweendiscretionary}}%
       \postwordbreak
     \egroup
   \fi\fi\fi\fi\fi\fi\fi\fi\fi
   \nextnextnext}

\def\checkbeforediscretionary%
  {\setbox0=\lastbox
   \ifdim\wd0=\!!zeropoint
     \let\postwordbreak=\prewordbreak
   \fi
   \box0\relax}

\def\checkafterdiscretionary%
  {\ifx,\nextnext
     \def\nextnextnext{\afterassignment\egroup\let\next=}%
   \else
     \let\nextnext=\relax
   \fi}

%D The macro \type{\checkbeforediscretionary} takes care of 
%D loners like \type{||word}, while it counterpart 
%D \type{\checkafterdiscretionary} is responsible for handling 
%D the comma. 

%D \macros
%D   {beginofsubsentencespacing,endofsubsentencespacing}
%D 
%D In the previous macros we provided two hooks which can be 
%D used to support nested sub||sentences. In \CONTEXT\ these 
%D hooks are used to insert a small space when needed. 

\let\beginofsubsentencespacing=\relax
\let\endofsubsentencespacing  =\relax

%D Before we show some more tricky alternative, we first install
%D the mechanism:

\installdiscretionaries || \compoundhyphen

%D \macros 
%D   {fakecompoundhyphen}
%D
%D In headers and footers as well as in active pieces of text 
%D we need a dirty hack. Try to imagine what is needed to 
%D savely break the next text across a line and at the same 
%D time make the words interactive. 
%D
%D \starttypen
%D \goto{Some||Long||Word}
%D \stoptypen

\def\currentspaceskip%
  {\fontdimen2\font\!!plus\fontdimen3\font\!!minus\fontdimen4\font\relax}

\def\fakecompoundhyphen%
  {\def|##1|{\compoundhyphen\nobreak\hskip-\currentspaceskip\allowbreak}}

%D One of the drawbacks of this mechanism is that characters can
%D be made active afterwards. The next alternative can be used
%D in such situations.  This time we don't compare the arguments
%D directly but use the \type{\uccode}'s instead. \TEX\
%D initializes these codes of the alphabetics glyphs to their
%D uppercase counterparts. Normally the other characters remain
%D zero. If so, we can use the \type{\uccode} as a signal.

%D \macros
%D   {enableactivediscretionaries}
%D
%D The more advanced mechanism is activated by calling:
%D
%D \starttypen
%D \enableactivediscretionaries
%D \stoptypen
%D
%D which is defined as:

\def\enableactivediscretionaries%
  {\uccode`'=`'\relax \uccode`~=`~\relax \uccode`_=`_\relax
   \uccode`(=`(\relax \uccode`)=`)\relax \uccode`==`=\relax
   \uccode`<=`<\relax \uccode`>=`>\relax
   \let\dotextmodediscretionary     = \activedotextmodediscretionary
   \let\dododotextmodediscretionary = \activedododotextmodediscretionary}

%D We only have to redefine two macros. While saving the
%D \type{\uccode} in a macro we have to take care of empty
%D arguments, like in \type{||}.

\def\activedotextmodediscretionary#1%
  {\bgroup
   \def\dodotextmodediscretionary##1#1%
     {\def\betweendiscretionary{##1}%
      \def\nextuccode####1####2\relax%
        {\ifcat\noexpand####1\noexpand\relax
           \edef\nextuccode{0}%
         \else
           \edef\nextuccode{\the\uccode`####1}%
         \fi}%
      \nextuccode##1@\relax
      \futurelet\nextnext\dododotextmodediscretionary}%
   \let\discretionarycommand=#1%
   \def\textmodediscretionary{\getvalue{textmodediscretionary\string#1}}%
   \futurelet\next\dodotextmodediscretionary}

%D This time we use \type{\ifnum}:

\def\activedododotextmodediscretionary%
  {\let\nextnextnext=\egroup
   \ifx\discretionarycommand\next
     \checkafterdiscretionary
     \bgroup
       \checkbeforediscretionary
       \prewordbreak\hbox{\textmodediscretionary\nextnext}\allowbreak
     \egroup
   \else\ifnum\uccode`==\nextuccode
     \prewordbreak\textmodediscretionary
   \else\ifnum\uccode`~=\nextuccode
     \prewordbreak\discretionary{-}{}{\thinspace}\postwordbreak
   \else\ifnum\uccode`_=\nextuccode
     \prewordbreak\discretionary{\textmodediscretionary} 
       {\textmodediscretionary}{\textmodediscretionary}\prewordbreak
   \else\ifnum\uccode`(=\nextuccode
     \ifdim\lastskip>\!!zeropoint\relax
       (\prewordbreak
     \else
       \prewordbreak\discretionary{}{(-}{(}\prewordbreak
     \fi
   \else\ifnum\uccode`)=\nextuccode
     \ifx\nextnext\blankspace
       \prewordbreak)\relax
     \else
       \prewordbreak\discretionary{-)}{}{)}\prewordbreak
     \fi
   \else\ifnum\uccode`'=\nextuccode
     \prewordbreak\discretionary{-}{}{'}\postwordbreak
   \else\ifnum\uccode`<=\nextuccode
     \beginofsubsentence\prewordbreak\beginofsubsentencespacing
   \else\ifnum\uccode`>=\nextuccode
     \endofsubsentencespacing\prewordbreak\endofsubsentence
   \else 
     \checkafterdiscretionary
     \bgroup
       \checkbeforediscretionary
      %\prewordbreak\hbox{\betweendiscretionary\nextnext}\allowbreak
       \prewordbreak
       \discretionary{\hbox{\betweendiscretionary}}{}{\hbox{\betweendiscretionary}}%
       \postwordbreak
     \egroup
   \fi\fi\fi\fi\fi\fi\fi\fi\fi
   \nextnextnext}

%D Now we can safely do things like: \enableactivediscretionaries
%D
%D \starttypen
%D \catcode`<=\@@active  \def<{hello there}
%D \catcode`>=\@@active  \def>{hello there}
%D \catcode`(=\@@active  \def({hello there}
%D \catcode`)=\@@active  \def){hello there}
%D \stoptypen
%D
%D In normal day||to||day production of texts this kind of
%D activation is seldom used.\voetnoot{In the \CONTEXT\ manual
%D the \type{<} and \type{>} are made active and used for some
%D cross||reference trickery.} If so, we have to take care of
%D the math mode explicitly, just like we did when making
%D \type{|} active. It can be confusing too, especially when we
%D load macropackages afterwards that make use of \type{<} in
%D \type{\ifnum} or \type{\ifdim} statements.

%D \macros
%D   {installcompoundcharacter}
%D
%D When Tobias Burnus started translating the dutch manual of
%D \PPCHTEX\ into german, he suggested to let \CONTEXT\ support
%D the \type{german.sty} method of handling compound
%D characters, especially the umlaut. This package is meant for
%D use with \PLAIN\ \TEX\ as well as \LATEX. 
%D 
%D I decided to implement compound character support as
%D versatile as possible. As a result one can define his own
%D compound character support, like: 
%D 
%D \starttypen
%D \installcompoundcharacter "a {\"a}
%D \installcompoundcharacter "e {\"e}
%D \installcompoundcharacter "i {\"i}
%D \installcompoundcharacter "u {\"u}
%D \installcompoundcharacter "o {\"o}
%D \installcompoundcharacter "s {\SS} 
%D \stoptypen
%D
%D or even 
%D 
%D \starttypen
%D \installcompoundcharacter "ck {\discretionary {k-}{k}{ck}}
%D \installcompoundcharacter "ff {\discretionary{ff-}{f}{ff}}
%D \stoptypen
%D 
%D The support is not limited to alphabetic characters, so the 
%D next definition is also valid. 
%D 
%D \starttypen
%D \installcompoundcharacter ". {.\doifnextcharelse{\spacetoken}{}{\kern.125em}}
%D \stoptypen
%D 
%D The implementation looks familiar and uses the same tricks as
%D mentioned earlier in this module. We take care of two 
%D arguments, which complicates things a bit.  

\def\@nc@{@nc@} % normal character 
\def\@cc@{@cc@} % compound character 
\def\@cs@{@cs@} % compound characters 

\def\installcompoundcharacter #1#2#3 #4% {{#4}} keeps move local
  {\setvalue{\@nc@\string#1}{\char`#1}%
   \def\!!stringa{#3}%
   \ifx\!!stringa\empty
     \setvalue{\@cc@\string#1\string#2}{{#4}}% 
   \else
     \setvalue{\@cs@\string#1\string#2\string#3}{{#4}}%
   \fi
   \catcode`#1=\@@active
   \scratchcounter=\the\uccode`~
   \uccode`~=`#1
   \uppercase{\unexpanded\def~{\handlecompoundcharacter~}}%
   \uccode`~=\scratchcounter}

%D In handling the compound characters we have to take care of
%D \type{\bgroup} and \type{\egroup} tokens, so we end up with
%D a multi||step interpretation macro. We look ahead for a
%D \type{\bgroup}, \type{\egroup} or \type{\blankspace}. Being
%D no user of this mechanism, the credits for testing them goes
%D to Tobias Burnus, the first german user of \CONTEXT.
%D
%D We define these macros as \type{\long} because we can
%D expect \type{\par} tokens. We need to look into the future
%D with \type{\futurelet} to prevent spaces from
%D disappearing.

\def\handlecompoundcharacter#1%
  {\def\dohandlecompoundcharacter%
     {\ifx\next\bgroup
       %\def\next{\dodohandlecompoundcharacter#1}%    % handle "{ee} -> \"ee
       %\let\next\relax                               % forget "{ee} -> ee
        \def\next{\handlecompoundcharacterone#1}%     % ignore "{ee} -> "ee
      \else\ifx\next\egroup
        \let\next\relax
      \else\ifx\next\blankspace
       %\let\next\relax
        \def\next{\getvalue{\@nc@\string#1}}% better 
      \else
        \def\next{\dodohandlecompoundcharacter#1}%
      \fi\fi\fi
      \next}%
   \futurelet\next\dohandlecompoundcharacter}

\def\dodohandlecompoundcharacter#1#2%
  {\def\dododohandlecompoundcharacter% Keep it here and 
     {\ifx\next\bgroup               % preserve spaces!
        \def\next{\handlecompoundcharacterone#1#2}%
      \else\ifx\next\egroup
        \def\next{\handlecompoundcharacterone#1#2}%
      \else\ifx\next\blankspace
        \def\next{\handlecompoundcharacterone#1#2}%
      \else
        \def\next{\handlecompoundcharactertwo#1#2}%
      \fi\fi\fi
      \next}%
   \futurelet\next\dododohandlecompoundcharacter}

%D Besides taken care of the grouping and space tokens, we have
%D to deal with three situations. First we look if the next
%D character equals the first one, if so, then we just insert
%D the original. Next we look if indeed a compound character is
%D defined. We either execute the compound character or just
%D insert the first. So we have
%D
%D \starttypen
%D <key><key>  <key><known>  <key><unknown>  
%D \stoptypen
%D
%D In later modules we will see how these commands are used.

\beginTEX

\long\def\handlecompoundcharacterone#1#2%
  {\ifx#1#2%
     \def\next{\getvalue{\@nc@\string#1}\getvalue{\@nc@\string#2}}%
   \else\expandafter\ifx\csname\@cc@\string#1\string#2\endcsname\relax
     \def\next{\getvalue{\@nc@\string#1}#2}%
   \else
     \def\next{\getvalue{\@cc@\string#1\string#2}}%
   \fi\fi
   \next}

\long\def\handlecompoundcharactertwo#1#2#3%
  {\ifx#1#2%
     \def\next{\getvalue{\@nc@\string#1}\getvalue{\@nc@\string#2}#3}%
   \else\@EA\ifx\csname\@cs@\string#1\string#2\string#3\endcsname\relax
     \expandafter\ifx\csname\@cc@\string#1\string#2\endcsname\relax
       \def\next{\getvalue{\@nc@\string#1}#2#3}%
     \else
       \def\next{\getvalue{\@cc@\string#1\string#2}#3}%
     \fi
   \else
     \def\next{\getvalue{\@cs@\string#1\string#2\string#3}}%
   \fi\fi
   \next}

\endTEX

\beginETEX \ifcsname

\long\def\handlecompoundcharacterone#1#2%
  {\ifx#1#2%
     \def\next{\getvalue{\@nc@\string#1}\getvalue{\@nc@\string#2}}%
   \else\ifcsname\@cc@\string#1\string#2\endcsname
     \def\next{\getvalue{\@cc@\string#1\string#2}}%
   \else
     \def\next{\getvalue{\@nc@\string#1}#2}%
   \fi\fi
   \next}

\long\def\handlecompoundcharactertwo#1#2#3%
  {\ifx#1#2%
     \def\next{\getvalue{\@nc@\string#1}\getvalue{\@nc@\string#2}#3}%
   \else\ifcsname\@cs@\string#1\string#2\string#3\endcsname
     \def\next{\getvalue{\@cs@\string#1\string#2\string#3}}%
   \else\ifcsname\@cc@\string#1\string#2\endcsname
     \def\next{\getvalue{\@cc@\string#1\string#2}#3}%
   \else
     \def\next{\getvalue{\@nc@\string#1}#2#3}%
   \fi\fi\fi
   \next}

\endETEX

%D \macros
%D  {midworddiscretionary}
%D
%D If needed, one can add a discretionary hyphen using \type
%D {\midworddiscretionary}. This macro does the same as 
%D \PLAIN\ \TEX's \type {\-}, but, like the ones implemented 
%D earlier, this one also looks ahead for spaces and grouping
%D tokens. 
 
\def\domidworddiscretionary%
  {\ifx\next\blankspace\else
   \ifx\next\bgroup    \else
   \ifx\next\egroup    \else
     \discretionary{-}{}{}%
   \fi\fi\fi}

\def\midworddiscretionary%
  {\futurelet\next\domidworddiscretionary}

%D \macros 
%D   {hyphenatedurl}
%D 
%D For those who want to put full \URL's in a text, we offer 
%D 
%D \startbuffer
%D \hyphenatedurl{http://optimist.optimist/optimist/optimist.optimist#optimist}
%D \stopbuffer
%D 
%D \typebuffer
%D 
%D which breaks at the appropriate places. Watch the \type{#}
%D hack. 
%D
%D When passed as argument, lik ein \type {\goto}, one needs 
%D to substitute a \type {\\} for each \type{#}.
%D
%D \startbuffer
%D \hyphenatedurl{http://this.is.a.rather/strange/reference#indeed}
%D \stopbuffer
%D
%D \typebuffer

\ifx\\\undefined \let\\\crlf \fi

\chardef\urlsplitmode=1 

% 0 => don't split 
% 1 => . : na, rest voor
% 2 => alles na
% 3 => alles voor

\unexpanded\def\hyphenatedurl#1%
  {\bgroup
   \obeyhyphens
   \def\splitbefore##1%
     {\setbox\scratchbox=\hbox{##1{}{}}%
      \ifcase\urlsplitmode 
        \box\scratchbox
      \or 
        \postwordbreak\box\scratchbox\prewordbreak
      \or
        \prewordbreak\discretionary{\box\scratchbox}{}{\box\scratchbox}\prewordbreak
      \else
        \postwordbreak\box\scratchbox\prewordbreak
      \fi}%
   \def\splitafter##1%
     {\ifcase\urlsplitmode
        ##1%
      \or
        \prewordbreak\discretionary{##1}{}{##1}\prewordbreak
      \or
        \prewordbreak\discretionary{##1}{}{##1}\prewordbreak
      \else
        \prewordbreak\discretionary{}{##1}{##1}\prewordbreak
      \fi}% 
   \def\flushurl%
     {\savedurl\let\savedurl\empty}%
   \def\\%
     {\spliturl\#}%
   \let~\~%
   \let\savedurl\empty
   \handletokens#1\with\scanurl
   \egroup}

\bgroup
\catcode`\#=12\gdef\hashletter        {#}
\catcode`\_=12\gdef\underscoreletter  {_}
\catcode`\~=12\gdef\tildeletter       {~}
\catcode`\%=12\gdef\percentletter     {%}
\catcode`\?=12\gdef\questionmarkletter{?}
\catcode`\@=12\gdef\atletter          {@}
\egroup

\def\scanurl#1%
  {\ifx#1\~%
     \flushurl\splitbefore{\~{}}%
   \else\ifx#1\#%
     \flushurl\splitbefore\#%
   \else\ifx#1\&%
     \flushurl\splitbefore\&%
   \else\ifx#1\%%
     \flushurl\splitbefore\%%
   \else\ifx#1\_%
     \flushurl\splitbefore\_%
   \else\if\noexpand#1\relax
     #1%
   \else\ifnum\catcode`#1=8
     \flushurl\splitbefore\_%
   \else\ifnum\catcode`#1=6
     \flushurl\splitbefore\#%
   \else\if#1\tildeletter
     \flushurl\splitbefore\~%
   \else\if#1\percentletter
     \flushurl\splitbefore\%%   
   \else\if#1\underscoreletter
     \flushurl\splitbefore\_%   
   \else\if#1\questionmarkletter
     \flushurl\splitafter\questionmarkletter
   \else\if#1\atletter
     \flushurl\splitafter\atletter
   \else\if#1+%
     \flushurl\splitafter+%
   \else\if#1:%
     \flushurl\splitafter:%
   \else\if#1.%
     \flushurl\splitafter.%
   \else\if#1/%
     \edef\savedurl{\savedurl/}%
   \else
     \ifx\savedurl\empty\else
       \splitbefore\savedurl
       \let\savedurl\empty
     \fi
     #1%
   \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}

%D \macros
%D   {hyphenatedfile}
%D
%D For the moment we treat filenames in a similar way, 
%D
%D \starttypen
%D \hyphenatedfile{here/there/filename.suffix}
%D \stoptypen

\let\hyphenatedfile\hyphenatedurl

\protect

\endinput