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
|
%D \module
%D [ file=lang-ini,
%D version=2014.08.10,
%D title=\CONTEXT\ Language Macros,
%D subtitle=Experimental Patterns,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
%D This is an experimental module. We often have to deal with titles
%D that have conflicting demands:
%D
%D \startitemize
%D \startitem They go into a dedicated space (often a graphic). \stopitem
%D \startitem The words cannot be hyphenated. \stopitem
%D \startitem But as an escape they can get hyphenated. \stopitem
%D \startitem In that case we want at least an extra word on the last line. \stopitem
%D \stopitemize
%D
%D These and maybe more cases can be dealt with using dedicated hyphenation
%D mechanisms. At he same time we want to experiment with more extensive patterns
%D as discussed in {\em TUGboat, Volume 27 (2006), No. 2—Proceedings of EuroTEX2006}.
% lua: 5.341 5.354
% tex: 5.174 5.262
\writestatus{loading}{ConTeXt Language Macros / Initialization}
\registerctxluafile{lang-dis}{1.001}
\registerctxluafile{lang-hyp}{1.001}
\unprotect
\definesystemattribute[hyphenation][public]
%D This command can change! At some point we will keep the setting with the
%D paragraph and then the \type {\par} can go.
% \unexpanded\def\atleastoneword#1%
% {\begingroup
% \enabledirectives[hyphenators.method=traditional]%
% \enabledirectives[hyphenators.rightwordsmin=1]%
% \lefthyphenmin \plusfour
% \righthyphenmin\plusfour
% #1\par
% \disabledirectives[hyphenators.rightwordsmin]%
% \enabledirectives[hyphenators.method]%
% \endgroup}
% \exhyphenchar \hyphenasciicode
% \preexhyphenchar \lessthanasciicode
% \postexhyphenchar\morethanasciicode
%D Here is the real way:
\installcorenamespace{hyphenation}
\installcorenamespace{hyphenationfeatures}
\installparameterhandler \??hyphenation {hyphenation}
\installsetuphandler \??hyphenation {hyphenation}
\setuphyphenation
[\c!method=\s!default,
\s!righthyphenchar=0, % number tzt g: etc
\s!lefthyphenchar=0] % number
\appendtoks
\clf_sethyphenationmethod{\hyphenationparameter\c!method}%
\to \everysetuphyphenation
%D These are mostly meant for manuals:
\unexpanded\def\starthyphenation[#1]%
{\begingroup
\clf_pushhyphenation{#1}}
\unexpanded\def\stophyphenation
{\ifhmode\par\fi
\clf_pophyphenation
\endgroup}
% This is a global setting, so we need to disable it when needed. However, as
% we are (hopefully) compatible and attribute driven one can also just keep it
% enabled.
%
% \setuphyphenation
% [\c!method=\s!traditional] % no translations
\unexpanded\def\definehyphenationfeatures
{\dodoubleargument\lang_hyphenation_define_features}
\unexpanded\def\lang_hyphenation_define_features[#1][#2]%
{\begingroup
\letdummyparameter\c!characters\empty % maybe \s!
\letdummyparameter\c!hyphens\empty % maybe \s!
\letdummyparameter\c!joiners\empty % maybe \s!
\letdummyparameter\c!rightwords\zerocount % maybe \s!
\letdummyparameter\s!lefthyphenmin\zerocount
\letdummyparameter\s!righthyphenmin\zerocount
\letdummyparameter\s!hyphenmin\zerocount
\letdummyparameter\s!lefthyphenchar\zerocount
\letdummyparameter\s!righthyphenchar\zerocount
\letdummyparameter\c!alternative\empty
\letdummyparameter\c!rightedge\empty
\letdummyparameter\c!rightchars\empty
\getdummyparameters[#2]%
\clf_definehyphenationfeatures
{#1}%
{
characters {\dummyparameter\c!characters}%
hyphens {\dummyparameter\c!hyphens}%
joiners {\dummyparameter\c!joiners}%
rightwordmin \numexpr\dummyparameter\c!rightwords\relax
rightchars {\dummyparameter\c!rightchars}%
charmin \numexpr\dummyparameter\s!hyphenmin\relax
leftcharmin \numexpr\dummyparameter\s!lefthyphenmin\relax
rightcharmin \numexpr\dummyparameter\s!righthyphenmin\relax
leftchar \numexpr\dummyparameter\s!lefthyphenchar\relax
rightchar \numexpr\dummyparameter\s!righthyphenchar\relax
alternative {\dummyparameter\c!alternative}%
rightedge {\dummyparameter\c!rightedge}%
}%
\relax
\endgroup}
\unexpanded\def\sethyphenationfeatures[#1]%
{\clf_sethyphenationfeatures{#1}}
\unexpanded\def\resethyphenationfeatures
{\hyphenationattribute\attributeunsetvalue}
\resethyphenationfeatures
% todo: \start ... \stop too
\unexpanded\def\registerhyphenationpattern
{\dodoubleempty\lang_hyphenation_register_pattern}
\def\lang_hyphenation_register_pattern[#1][#2]%
{\clf_registerhyphenationpattern\ifsecondargument{#1}{#2}\else{\currentlanguage}{#1}\fi\s!true\relax}
\unexpanded\def\unregisterhyphenationpattern
{\dodoubleempty\lang_hyphenation_unregister_pattern}
\def\lang_hyphenation_unregister_pattern[#1][#2]%
{\clf_registerhyphenationpattern\ifsecondargument{#1}{#2}\else{\currentlanguage}{#1}\fi\s!false\relax}
\unexpanded\def\registerhyphenationexception
{\dodoubleempty\lang_hyphenation_register_exception}
\def\lang_hyphenation_register_exception[#1][#2]%
{\clf_registerhyphenationexception\ifsecondargument{#1}{#2}\else{\currentlanguage}{#1}\fi\relax}
\unexpanded\def\showhyphenationtrace
{\dodoubleempty\lang_hyphenation_show_trace}
\def\lang_hyphenation_show_trace[#1][#2]%
{\begingroup
\tt
\clf_showhyphenationtrace\ifsecondargument{#1}{#2}\else{\currentlanguage}{#1}\fi\relax
\endgroup}
% For old times sake:
\unexpanded\def\atleastoneword#1%
{\begingroup
\starthyphenation[traditional]% this might become default or a faster switch
\sethyphenationfeatures[words]%
#1\par
\stophyphenation
\endgroup}
%D For me:
\unexpanded\def\showdiscretionaries
{\clf_showdiscretionaries}
%D These are (at least now) not cummulative:
\definehyphenationfeatures % just an example
[fences]
[\c!characters={[]()}]
\definehyphenationfeatures
[words]
[\c!rightwords=1,
\s!lefthyphenmin=4,
\s!righthyphenmin=4]
\definehyphenationfeatures
[default]
[%c!rightedge=\v!tex,
\c!hyphens=\v!yes,
\c!joiners=\v!yes]
\definehyphenationfeatures
[strict]
[\c!rightedge=\s!tex]
% \sethyphenationfeatures
% [fences]
% \sethyphenationfeatures
% [default,fences]
% \setuphyphenation % will be default
% [method=expanded]
\protect \endinput
% \starttext
%
% \enabledirectives[hyphenators.method=traditional]
%
% % \dorecurse{1000}{\input tufte \par}
%
% \setupalign[verytolerant,flushleft]
% \setuplayout[width=140pt] \showframe
%
% longword longword long word longword longwordword \blank
%
% \enabledirectives[hyphenators.rightwordsmin=1]
%
% longword longword long word longword longwordword\blank
%
% \disabledirectives[hyphenators.rightwordsmin]
%
% longword longword long word longword longwordword\blank
%
% \atleastoneword{longword longword long word longword longwordword}
%
% \enabledirectives[hyphenators.method=traditional]
%
% \stoptext
% \startluacode
% -- e1ë/e=e reëel re-eel
% -- a1atje./a=t,1,3 omaatje oma-tje
% -- schif1f/ff=f,5,2 Schiffahrt Schiff-fahrt
%
% languages.hyphenators.traditional.registerpattern("en","a1b", { start = 1, length = 2, before = "CD", after = "EF" } )
% languages.hyphenators.traditional.registerpattern("en","e1ë", { start = 1, length = 2, before = "e", after = "e" } )
% languages.hyphenators.traditional.registerpattern("en","oo1ë", { start = 2, length = 2, before = "o", after = "e" } )
% languages.hyphenators.traditional.registerpattern("en","qqxc9xkqq",{ start = 3, length = 4, before = "ab", after = "cd" } ) -- replacement start length
%
% -- print("reëel", injecthyphens(dictionaries.nl,"reëel", 2,2))
% -- print("reeëel", injecthyphens(dictionaries.nl,"reeëel", 2,2))
% -- print("rooëel", injecthyphens(dictionaries.nl,"rooëel", 2,2))
% -- print( "QXcXkQ", injecthyphens(dictionaries.de, "QXcXkQ", 2,2))
% -- print( "QQXcXkQQ", injecthyphens(dictionaries.de, "QQXcXkQQ", 2,2))
% -- print( "QQQXcXkQQQ", injecthyphens(dictionaries.de, "QQQXcXkQQQ", 2,2))
% -- print("QQQQXcXkQQQQ",injecthyphens(dictionaries.de,"QQQQXcXkQQQQ",2,2))
% --
% -- print( "QQXcXkQQ QQXcXkQQ", injecthyphens(dictionaries.de, "QQXcXkQQ QQXcXkQQ", 2,2))
% \stopluacode
%
% \starttext
%
% \blank
%
% xreëel rooëel \par xxabxx xxxabxxx \par
%
% \hsize1mm \lefthyphenmin2 \righthyphenmin2
%
% \blank Capacity \blank capacity \blank xyabxy \blank xreëel \blank rooëel \blank
%
% xy\discretionary{CD}{EF}{ab}xy % xxacceedxxx
%
% \stoptext
|