lang-hyp.mkiv /size: 9562 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=lang-ini,
3
%D version=2014.08.10,
4
%D title=\CONTEXT\ Language Macros,
5
%D subtitle=Experimental Patterns,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
%D This is an experimental module. We often have to deal with titles
15
%D that have conflicting demands:
16
%D
17
%D \startitemize
18
%D \startitem They go into a dedicated space (often a graphic). \stopitem
19
%D \startitem The words cannot be hyphenated. \stopitem
20
%D \startitem But as an escape they can get hyphenated. \stopitem
21
%D \startitem In that case we want at least an extra word on the last line. \stopitem
22
%D \stopitemize
23
%D
24
%D These and maybe more cases can be dealt with using dedicated hyphenation
25
%D mechanisms. At he same time we want to experiment with more extensive patterns
26
%D as discussed in {\em TUGboat, Volume 27 (2006), No. 2—Proceedings of EuroTEX2006}.
27 28
% lua: 5.341 5.354
29
% tex: 5.174 5.262
30 31
\writestatus
{
loading
}{
ConTeXt
Language
Macros
/
Initialization
}
32 33
\registerctxluafile
{
lang
-
dis
}{}
34
\registerctxluafile
{
lang
-
hyp
}{}
35 36
\unprotect
37 38
\definesystemattribute
[
hyphenation
][
public
]
39 40
%D After a decade of playing with these things in \LUATEX|/|\MKIV\ it's time to
41
%D finish the way we deal with discretionaries. Apart from the fact that they play a
42
%D role in hyphenation they also need to be dealt with in fonts. Flattening, cleanup
43
%D and such are now more or less default in \CONTEXT\ so we can simplify some of the
44
%D code. We also use the new penalty mechanism.
45 46
\newcount\compoundhyphenpenalty
47 48
\automatichyphenmode
\plusone
49
\hyphenpenaltymode
\plusfour
50 51
\hyphenpenalty
5
0
% hyphenator
52
\automatichyphenpenalty
5
0
% -
53
\explicithyphenpenalty
5
0
% \-
54
\compoundhyphenpenalty
5
0
55
\exceptionpenalty
1
0
0
0
56 57
%D This command can change! At some point we will keep the setting with the
58
%D paragraph and then the \type {\par} can go.
59 60
% \unexpanded\def\atleastoneword#1%
61
% {\begingroup
62
% \enabledirectives[hyphenators.method=traditional]%
63
% \enabledirectives[hyphenators.rightwordsmin=1]%
64
% \lefthyphenmin \plusfour
65
% \righthyphenmin\plusfour
66
% #1\par
67
% \disabledirectives[hyphenators.rightwordsmin]%
68
% \enabledirectives[hyphenators.method]%
69
% \endgroup}
70 71
% \exhyphenchar \hyphenasciicode
72
% \preexhyphenchar \lessthanasciicode
73
% \postexhyphenchar\morethanasciicode
74 75
%D Here is the real way:
76 77
\installcorenamespace
{
hyphenation
}
78
\installcorenamespace
{
hyphenationfeatures
}
79 80
\installparameterhandler
\??hyphenation
{
hyphenation
}
81
\installsetuphandler
\??hyphenation
{
hyphenation
}
82 83
\setuphyphenation
84
[
\c!method
=
\s!default
,
85
\s!righthyphenchar
=
0
,
% number tzt g: etc
86
\s!lefthyphenchar
=
0
]
% number
87 88
\appendtoks
89
\clf_sethyphenationmethod
{
\hyphenationparameter
\c!method
}
%
90
\to
\everysetuphyphenation
91 92
%D These are mostly meant for manuals:
93 94
\unexpanded
\def
\starthyphenation
[#
1
]
%
95
{
\begingroup
96
\clf_pushhyphenation
{
#
1
}}
97 98
\unexpanded
\def
\stophyphenation
99
{
\ifhmode
\par\fi
100
\clf_pophyphenation
101
\endgroup
}
102 103
% This is a global setting, so we need to disable it when needed. However, as
104
% we are (hopefully) compatible and attribute driven one can also just keep it
105
% enabled.
106
%
107
% \setuphyphenation
108
% [\c!method=\s!traditional] % no translations
109 110
\unexpanded
\def
\definehyphenationfeatures
111
{
\dodoubleargument
\lang_hyphenation_define_features
}
112 113
\unexpanded
\def
\lang_hyphenation_define_features
[#
1
][#
2
]
%
114
{
\begingroup
115
\letdummyparameter
\c!characters
\empty
% maybe \s!
116
\letdummyparameter
\c!hyphens
\empty
% maybe \s!
117
\letdummyparameter
\c!joiners
\empty
% maybe \s!
118
\letdummyparameter
\c!rightwords
\zerocount
% maybe \s!
119
\letdummyparameter
\s!lefthyphenmin
\zerocount
120
\letdummyparameter
\s!righthyphenmin
\zerocount
121
\letdummyparameter
\s!hyphenmin
\zerocount
122
\letdummyparameter
\s!lefthyphenchar
\zerocount
123
\letdummyparameter
\s!righthyphenchar
\zerocount
124
\letdummyparameter
\c!alternative
\empty
125
\letdummyparameter
\c!rightedge
\empty
126
\letdummyparameter
\c!rightchars
\empty
127
\getdummyparameters
[#
2
]
%
128
\clf_definehyphenationfeatures
129
{
#
1
}
%
130
{
131
characters
{
\dummyparameter
\c!characters
}
%
132
hyphens
{
\dummyparameter
\c!hyphens
}
%
133
joiners
{
\dummyparameter
\c!joiners
}
%
134
rightwordmin
\numexpr
\dummyparameter
\c!rightwords
\relax
135
rightchars
{
\dummyparameter
\c!rightchars
}
%
136
charmin
\numexpr
\dummyparameter
\s!hyphenmin
\relax
137
leftcharmin
\numexpr
\dummyparameter
\s!lefthyphenmin
\relax
138
rightcharmin
\numexpr
\dummyparameter
\s!righthyphenmin
\relax
139
leftchar
\numexpr
\dummyparameter
\s!lefthyphenchar
\relax
140
rightchar
\numexpr
\dummyparameter
\s!righthyphenchar
\relax
141
alternative
{
\dummyparameter
\c!alternative
}
%
142
rightedge
{
\dummyparameter
\c!rightedge
}
%
143
% autohyphen {\dummyparameter\c!autohyphen}
144
% hyphenonly {\dummyparameter\c!hyphenonly}
145
}
%
146
\relax
147
\endgroup
}
148 149
\unexpanded
\def
\sethyphenationfeatures
[#
1
]
%
150
{
\clf_sethyphenationfeatures
{
#
1
}}
151 152
\unexpanded
\def
\resethyphenationfeatures
153
{
\hyphenationattribute
\attributeunsetvalue
}
154 155
\resethyphenationfeatures
156 157
% todo: \start ... \stop too
158 159
\unexpanded
\def
\registerhyphenationpattern
160
{
\dodoubleempty
\lang_hyphenation_register_pattern
}
161 162
\def
\lang_hyphenation_register_pattern
[#
1
][#
2
]
%
163
{
\clf_registerhyphenationpattern
\ifsecondargument
{
#
1
}{
#
2
}
\else
{
\currentlanguage
}{
#
1
}
\fi
\s!true
\relax
}
164 165
\unexpanded
\def
\unregisterhyphenationpattern
166
{
\dodoubleempty
\lang_hyphenation_unregister_pattern
}
167 168
\def
\lang_hyphenation_unregister_pattern
[#
1
][#
2
]
%
169
{
\clf_registerhyphenationpattern
\ifsecondargument
{
#
1
}{
#
2
}
\else
{
\currentlanguage
}{
#
1
}
\fi
\s!false
\relax
}
170 171
\unexpanded
\def
\registerhyphenationexception
172
{
\dodoubleempty
\lang_hyphenation_register_exception
}
173 174
\def
\lang_hyphenation_register_exception
[#
1
][#
2
]
%
175
{
\clf_registerhyphenationexception
\ifsecondargument
{
#
1
}{
#
2
}
\else
{
\currentlanguage
}{
#
1
}
\fi\relax
}
176 177
\unexpanded
\def
\showhyphenationtrace
178
{
\dodoubleempty
\lang_hyphenation_show_trace
}
179 180
\def
\lang_hyphenation_show_trace
[#
1
][#
2
]
%
181
{
\begingroup
182
\tt
183
\clf_showhyphenationtrace
\ifsecondargument
{
#
1
}{
#
2
}
\else
{
\currentlanguage
}{
#
1
}
\fi\relax
184
\endgroup
}
185 186
% For old times sake:
187 188
\unexpanded
\def
\atleastoneword
#
1
%
189
{
\begingroup
190
\starthyphenation
[
traditional
]
% this might become default or a faster switch
191
\sethyphenationfeatures
[
words
]
%
192
#
1
\par
193
\stophyphenation
194
\endgroup
}
195 196
%D For me:
197 198
\unexpanded
\def
\showdiscretionaries
199
{
\clf_showdiscretionaries
}
200 201
%D These are (at least now) not cummulative:
202 203
\definehyphenationfeatures
% just an example
204
[
fences
]
205
[
\c!characters
=
{
[]()
}
]
206 207
\definehyphenationfeatures
208
[
words
]
209
[
\c!rightwords
=
1
,
210
\s!lefthyphenmin
=
4
,
211
\s!righthyphenmin
=
4
]
212 213
\definehyphenationfeatures
214
[
default
]
215
[
%c!rightedge=\v!tex,
216
\c!hyphens
=
\v!yes
,
217
\c!joiners
=
\v!yes
]
218 219
\definehyphenationfeatures
220
[
strict
]
221
[
\c!rightedge
=
\s!tex
]
222 223
% \sethyphenationfeatures
224
% [fences]
225 226
% \sethyphenationfeatures
227
% [default,fences]
228 229
% \setuphyphenation % will be default
230
% [method=expanded]
231 232
\protect
\endinput
233 234
% \starttext
235
%
236
% \enabledirectives[hyphenators.method=traditional]
237
%
238
% % \dorecurse{1000}{\input tufte \par}
239
%
240
% \setupalign[verytolerant,flushleft]
241
% \setuplayout[width=140pt] \showframe
242
%
243
% longword longword long word longword longwordword \blank
244
%
245
% \enabledirectives[hyphenators.rightwordsmin=1]
246
%
247
% longword longword long word longword longwordword\blank
248
%
249
% \disabledirectives[hyphenators.rightwordsmin]
250
%
251
% longword longword long word longword longwordword\blank
252
%
253
% \atleastoneword{longword longword long word longword longwordword}
254
%
255
% \enabledirectives[hyphenators.method=traditional]
256
%
257
% \stoptext
258 259
% \startluacode
260
% -- e1ë/e=e reëel re-eel
261
% -- a1atje./a=t,1,3 omaatje oma-tje
262
% -- schif1f/ff=f,5,2 Schiffahrt Schiff-fahrt
263
%
264
% languages.hyphenators.traditional.registerpattern("en","a1b", { start = 1, length = 2, before = "CD", after = "EF" } )
265
% languages.hyphenators.traditional.registerpattern("en","e1ë", { start = 1, length = 2, before = "e", after = "e" } )
266
% languages.hyphenators.traditional.registerpattern("en","oo1ë", { start = 2, length = 2, before = "o", after = "e" } )
267
% languages.hyphenators.traditional.registerpattern("en","qqxc9xkqq",{ start = 3, length = 4, before = "ab", after = "cd" } ) -- replacement start length
268
%
269
% -- print("reëel", injecthyphens(dictionaries.nl,"reëel", 2,2))
270
% -- print("reeëel", injecthyphens(dictionaries.nl,"reeëel", 2,2))
271
% -- print("rooëel", injecthyphens(dictionaries.nl,"rooëel", 2,2))
272
% -- print( "QXcXkQ", injecthyphens(dictionaries.de, "QXcXkQ", 2,2))
273
% -- print( "QQXcXkQQ", injecthyphens(dictionaries.de, "QQXcXkQQ", 2,2))
274
% -- print( "QQQXcXkQQQ", injecthyphens(dictionaries.de, "QQQXcXkQQQ", 2,2))
275
% -- print("QQQQXcXkQQQQ",injecthyphens(dictionaries.de,"QQQQXcXkQQQQ",2,2))
276
% --
277
% -- print( "QQXcXkQQ QQXcXkQQ", injecthyphens(dictionaries.de, "QQXcXkQQ QQXcXkQQ", 2,2))
278
% \stopluacode
279
%
280
% \starttext
281
%
282
% \blank
283
%
284
% xreëel rooëel \par xxabxx xxxabxxx \par
285
%
286
% \hsize1mm \lefthyphenmin2 \righthyphenmin2
287
%
288
% \blank Capacity \blank capacity \blank xyabxy \blank xreëel \blank rooëel \blank
289
%
290
% xy\discretionary{CD}{EF}{ab}xy % xxacceedxxx
291
%
292
% \stoptext
293