lang-hyp.mkxl /size: 9221 b    last modification: 2021-10-28 13:51
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 that have
15%D 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}{autosuffix}
34\registerctxluafile{lang-hyp}{autosuffix}
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% \ifcase\contextlmtxmode
49%     \hyphenpenaltymode\plusfour
50%     \automatichyphenmode\plusone
51% \fi
52
53\hyphenpenalty            50 % hyphenator
54\automatichyphenpenalty   50 % -
55\explicithyphenpenalty    50 % \-
56\compoundhyphenpenalty    50
57\exceptionpenalty       1000
58
59%D This command can change! At some point we will keep the setting with the
60%D paragraph and then the \type {\par} can go.
61
62\installcorenamespace{hyphenation}
63\installcorenamespace{hyphenationfeatures}
64
65\installparameterhandler     \??hyphenation {hyphenation}
66\installrootparameterhandler \??hyphenation {hyphenation}
67\installsetuphandler         \??hyphenation {hyphenation}
68
69% \installbasicsetuphandler  \??hyphenation {hyphenation}
70
71\setuphyphenation
72  [\c!method=\s!default,
73   \c!hyphens=\v!yes,
74   \s!righthyphenchar=0, % number tzt g: etc
75   \s!lefthyphenchar=0]  % number
76
77\appendtoks
78 % \edef\p_hyphens{\roothyphenationparameter\c!hyphens}%
79   \edef\p_hyphens{\hyphenationparameter\c!hyphens}%
80   \ifx\p_hyphens\v!no
81     \nohyphencollapsing
82   \else
83     \dohyphencollapsing
84   \fi
85\to \everysetuphyphenation
86
87\appendtoks
88    \clf_sethyphenationmethod{\hyphenationparameter\c!method}%
89\to \everysetuphyphenation
90
91%D These are mostly meant for manuals:
92
93\permanent\protected\def\starthyphenation[#1]%
94  {\begingroup
95   \clf_pushhyphenation{#1}}
96
97\permanent\protected\def\stophyphenation
98  {\ifhmode\par\fi
99   \clf_pophyphenation
100   \endgroup}
101
102% This is a global setting, so we need to disable it when needed. However, as
103% we are (hopefully) compatible and attribute driven one can also just keep it
104% enabled.
105%
106% \setuphyphenation
107%   [\c!method=\s!traditional] % no translations
108
109\permanent\tolerant\protected\def\definehyphenationfeatures[#1]#*[#2]%
110  {\begingroup
111   \letdummyparameter\c!characters     \empty     % maybe \s!characters
112   \letdummyparameter\c!hyphens        \empty     % maybe \s!hyphens
113   \letdummyparameter\c!joiners        \empty     % maybe \s!joiners
114   \letdummyparameter\c!rightwords     \zerocount % maybe \s!rightwords
115   \letdummyparameter\s!lefthyphenmin  \zerocount
116   \letdummyparameter\s!righthyphenmin \zerocount
117   \letdummyparameter\s!hyphenmin      \zerocount
118   \letdummyparameter\s!lefthyphenchar \zerocount
119   \letdummyparameter\s!righthyphenchar\zerocount
120   \letdummyparameter\c!alternative    \empty
121   \letdummyparameter\c!rightedge      \empty
122   \letdummyparameter\c!rightchars     \empty
123   \getdummyparameters[#2]%
124   \clf_definehyphenationfeatures
125      {#1}%
126      {
127        characters   {\dummyparameter\c!characters}%
128        hyphens      {\dummyparameter\c!hyphens}%
129        joiners      {\dummyparameter\c!joiners}%
130        rightwordmin \numexpr\dummyparameter\c!rightwords\relax
131        rightchars   {\dummyparameter\c!rightchars}%
132        charmin      \numexpr\dummyparameter\s!hyphenmin\relax
133        leftcharmin  \numexpr\dummyparameter\s!lefthyphenmin\relax
134        rightcharmin \numexpr\dummyparameter\s!righthyphenmin\relax
135        leftchar     \numexpr\dummyparameter\s!lefthyphenchar\relax
136        rightchar    \numexpr\dummyparameter\s!righthyphenchar\relax
137        alternative  {\dummyparameter\c!alternative}%
138        rightedge    {\dummyparameter\c!rightedge}%
139      % autohyphen   {\dummyparameter\c!autohyphen}
140      % hyphenonly   {\dummyparameter\c!hyphenonly}
141      }%
142   \relax
143   \endgroup}
144
145\permanent\protected\def\sethyphenationfeatures[#1]%
146  {\clf_sethyphenationfeatures{#1}}
147
148\permanent\protected\def\resethyphenationfeatures
149  {\attribute\hyphenationattribute\attributeunsetvalue}
150
151\resethyphenationfeatures
152
153% todo: \start ... \stop too
154
155\permanent\tolerant\protected\def\registerhyphenationpattern[#1]#*[#2]%
156  {\clf_registerhyphenationpattern\ifparameter#2\or{#1}{#2}\else{\currentlanguage}{#1}\fi\s!true\relax}
157
158\permanent\tolerant\protected\def\unregisterhyphenationpattern[#1]#*[#2]%
159  {\clf_registerhyphenationpattern\ifparameter#2\or{#1}{#2}\else{\currentlanguage}{#1}\fi\s!false\relax}
160
161\permanent\tolerant\protected\def\registerhyphenationexception[#1]#*[#2]%
162  {\clf_registerhyphenationexception\ifparameter#2\or{#1}{#2}\else{\currentlanguage}{#1}\fi\relax}
163
164\permanent\tolerant\protected\def\showhyphenationtrace[#1]#*[#2]%
165  {\begingroup
166   \tt
167   \clf_showhyphenationtrace\ifparameter#2\or{#1}{#2}\else{\currentlanguage}{#1}\fi\relax
168   \endgroup}
169
170% For old times sake:
171
172\permanent\protected\def\atleastoneword#1%
173  {\begingroup
174   \starthyphenation[traditional]% this might become default or a faster switch
175   \sethyphenationfeatures[words]%
176   #1\par
177   \stophyphenation
178   \endgroup}
179
180%D For me:
181
182\permanent\protected\def\showdiscretionaries
183  {\clf_showdiscretionaries}
184
185%D These are (at least now) not cummulative:
186
187\definehyphenationfeatures % just an example
188  [fences]
189  [\c!characters={[]()}]
190
191\definehyphenationfeatures
192  [words]
193  [\c!rightwords=1,
194   \s!lefthyphenmin=4,
195   \s!righthyphenmin=4]
196
197\definehyphenationfeatures
198  [default]
199  [%c!rightedge=\v!tex,
200   \c!hyphens=\v!yes,
201   \c!joiners=\v!yes]
202
203\definehyphenationfeatures
204  [strict]
205  [\c!rightedge=\s!tex]
206
207% \sethyphenationfeatures
208%   [fences]
209
210% \sethyphenationfeatures
211%   [default,fences]
212
213\protect \endinput
214
215% \starttext
216%
217% \enabledirectives[hyphenators.method=traditional]
218%
219% % \dorecurse{1000}{\input tufte \par}
220%
221% \setupalign[verytolerant,flushleft]
222% \setuplayout[width=140pt] \showframe
223%
224% longword longword long word longword longwordword \blank
225%
226% \enabledirectives[hyphenators.rightwordsmin=1]
227%
228% longword longword long word longword longwordword\blank
229%
230% \disabledirectives[hyphenators.rightwordsmin]
231%
232% longword longword long word longword longwordword\blank
233%
234% \atleastoneword{longword longword long word longword longwordword}
235%
236% \enabledirectives[hyphenators.method=traditional]
237%
238% \stoptext
239
240% \startluacode
241%     -- e1ë/e=e             reëel      re-eel
242%     -- a1atje./a=t,1,3     omaatje    oma-tje
243%     -- schif1f/ff=f,5,2    Schiffahrt Schiff-fahrt
244%
245%     languages.hyphenators.traditional.registerpattern("en","a1b",      { start = 1, length = 2, before = "CD", after = "EF"  } )
246%     languages.hyphenators.traditional.registerpattern("en","e1ë",      { start = 1, length = 2, before = "e",  after = "e"  } )
247%     languages.hyphenators.traditional.registerpattern("en","oo1ë",     { start = 2, length = 2, before = "o",  after = "e"  } )
248%     languages.hyphenators.traditional.registerpattern("en","qqxc9xkqq",{ start = 3, length = 4, before = "ab", after = "cd" } ) -- replacement start length
249%
250%     --  print("reëel",       injecthyphens(dictionaries.nl,"reëel",       2,2))
251%     --  print("reeëel",      injecthyphens(dictionaries.nl,"reeëel",      2,2))
252%     --  print("rooëel",      injecthyphens(dictionaries.nl,"rooëel",      2,2))
253%     --  print(   "QXcXkQ",   injecthyphens(dictionaries.de,   "QXcXkQ",   2,2))
254%     --  print(  "QQXcXkQQ",  injecthyphens(dictionaries.de,  "QQXcXkQQ",  2,2))
255%     --  print( "QQQXcXkQQQ", injecthyphens(dictionaries.de, "QQQXcXkQQQ", 2,2))
256%     --  print("QQQQXcXkQQQQ",injecthyphens(dictionaries.de,"QQQQXcXkQQQQ",2,2))
257%     --
258%     --  print(  "QQXcXkQQ QQXcXkQQ",  injecthyphens(dictionaries.de,  "QQXcXkQQ QQXcXkQQ",  2,2))
259% \stopluacode
260%
261% \starttext
262%
263% \blank
264%
265% xreëel rooëel \par xxabxx xxxabxxx \par
266%
267% \hsize1mm \lefthyphenmin2 \righthyphenmin2
268%
269% \blank Capacity \blank capacity \blank xyabxy \blank xreëel \blank rooëel \blank
270%
271% xy\discretionary{CD}{EF}{ab}xy % xxacceedxxx
272%
273% \stoptext
274