lang-ini.mkxl /size: 30 Kb    last modification: 2024-01-16 09:02
1%D \module
2%D   [       file=lang-ini,
3%D        version=1996.01.25,
4%D          title=\CONTEXT\ Language Macros,
5%D       subtitle=Initialization,
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% \cldcontext{languages.numbers[tex.count.mainlanguagenumber]}
15
16%D This module implements multi||language support of \CONTEXT, which should not be
17%D confused with the multi||lingual interface. This support will be extended when
18%D needed. Properties of languages are defined in \TEX\ files as well as \LUA\
19%D files.
20
21\writestatus{loading}{ConTeXt Language Macros / Initialization}
22
23\registerctxluafile{lang-ini}{autosuffix}
24\registerctxluafile{lang-def}{}
25\registerctxluafile{lang-cnt}{}
26
27\unprotect
28
29\ifdefined\nonfrenchspacing\else \let\nonfrenchspacing\relax \fi
30\ifdefined\frenchspacing   \else \let\frenchspacing   \relax \fi
31
32%D When loading hyphenation patterns, \TEX\ assign a number to each loaded table,
33%D starting with~0. Switching to a specific table is done by assigning the relevant
34%D number to the predefined \COUNTER\ \type {\language}. However, in \MKIV\ a lot
35%D of management is delegated to \LUA.
36
37%D We keep track of the last loaded patterns by means of a pseudo \COUNTER. This
38%D just one of those situations in which we don't want to spent a real one. Language
39%D zero has no patterns, first of all because I like to start numbering at one. It
40%D may come in handy for special purposes as well.
41
42\normallanguage\zerocount
43
44%D \macros
45%D   {currentlanguage, setupcurrentlanguage}
46%D
47%D Instead of numbers,we are going to use symbolic names for the languages. The
48%D current langage is saved in the macro \type {\currentlanguage}. The setup macro
49%D is mainly used for cosmetic purposes.
50%D
51%D \starttyping
52%D \dorecurse{3}
53%D   {\language[nl]
54%D    \startmode[*en] english \stopmode
55%D    \startmode[*nl] dutch   \stopmode
56%D    \language[en]
57%D    \startmode[*en] english \stopmode
58%D    \startmode[*nl] dutch   \stopmode}
59%D \stoptyping
60
61\mutable\lettonothing\askedlanguage
62\mutable\lettonothing\currentlanguage
63\mutable\lettonothing\currentmainlanguage
64
65%D \macros
66%D   {defaultlanguage,languageparameter,specificlanguageparameter}
67%D
68%D We don't use the commandhandler here (yet) because we have a rather special
69%D fallback mechanism so quite some compatibility testing is needed.
70
71\installcorenamespace{language}
72\installcorenamespace{languagelinked}
73
74\mutable\def\currentusedlanguage{\currentlanguage} % no \cdef
75
76\permanent\def\defaultlanguage#1%
77  {\ifcsname\??language#1\s!default\endcsname
78     \expandafter\defaultlanguage\lastnamedcs
79   \else
80     #1%
81   \fi}
82
83\permanent\def\languageparameter#1%
84  {\ifcsname\??language\currentlanguage#1\endcsname
85     \lastnamedcs
86   \orelse\ifcsname\??language\currentlanguage\s!default\endcsname
87     \expandafter\specificlanguageparameter\lastnamedcs{#1}%
88   \orelse\ifcsname\??language\s!default#1\endcsname
89     \lastnamedcs
90   \fi}
91
92\permanent\def\specificlanguageparameter#1#2%
93  {\ifcsname\??language#1#2\endcsname
94     \lastnamedcs
95   \orelse\ifcsname\??language#1\s!default\endcsname
96     \expandafter\specificlanguageparameter\lastnamedcs{#2}%
97   \orelse\ifcsname\??language\s!default#2\endcsname
98     \lastnamedcs
99   \fi}
100
101\permanent\def\mainlanguageparameter#1%
102  {\ifcsname\??language\currentmainlanguage#1\endcsname
103     \lastnamedcs
104   \orelse\ifcsname\??language\currentmainlanguage\s!default\endcsname
105     \expandafter\specificlanguageparameter\lastnamedcs{#1}%
106   \orelse\ifcsname\??language\s!default#1\endcsname
107     \lastnamedcs
108   \fi}
109
110\aliased\let\usedlanguageparameter\languageparameter
111
112\permanent\def\askedlanguageparameter#1% assumes \currentusedlanguage being set
113  {\ifcsname\??language\currentusedlanguage#1\endcsname
114     \lastnamedcs
115   \orelse\ifcsname\??language\currentusedlanguage\s!default\endcsname
116     \expandafter\specificlanguageparameter\lastnamedcs{#1}%
117   \orelse\ifcsname\??language\s!default#1\endcsname
118     \lastnamedcs
119   \fi}
120
121\permanent\protected\def\setusedlanguage#1%
122  {\cdef\currentusedlanguage{\reallanguagetag{#1}}%
123   \ifempty\currentusedlanguage
124     \let\currentusedlanguage  \currentlanguage
125     \enforced\let\usedlanguageparameter\languageparameter
126   \orelse\ifx\currentusedlanguage\v!global
127     \let\currentusedlanguage  \currentmainlanguage
128     \enforced\let\usedlanguageparameter\mainlanguageparameter
129   \orelse\ifx\currentusedlanguage\v!local
130     \let\currentusedlanguage  \currentlanguage
131     \enforced\let\usedlanguageparameter\languageparameter
132   \else
133     \enforced\let\usedlanguageparameter\askedlanguageparameter
134   \fi}
135
136\permanent\protected\def\setupcurrentlanguage[#1]%
137  {\setcurrentlanguage\currentmainlanguage{#1}}
138
139\permanent\protected\def\setcurrentlanguage#1#2% sets modes: **id (currentmain) *id (current)
140  {\edef\p_askedlanguage{#1}% otherwise clash with \askedlanguage
141   \ifempty\p_askedlanguage \else
142     \ifempty\currentmainlanguage\else\resetsystemmode{\systemmodeprefix\currentmainlanguage}\fi
143     \let\currentmainlanguage\p_askedlanguage
144     \setsystemmode{\systemmodeprefix\currentmainlanguage}%
145   \fi
146   \edef\p_askedlanguage{#2}%
147   \ifempty\p_askedlanguage \else
148     \ifempty\currentlanguage\else\resetsystemmode\currentlanguage\fi
149     \let\currentlanguage\p_askedlanguage
150     \setsystemmode\currentlanguage
151   \fi}
152
153%D The internal macros will be defined later.
154
155%D \macros
156%D   {installlanguage}
157%D
158%D Hyphenation patterns can only be loaded when the format file is prepared. The
159%D next macro takes care of this loading. A language is specified with
160%D
161%D \showsetup{installlanguage}
162%D
163%D When \type {state} equals \type {start}, both patterns and additional hyphenation
164%D specifications are loaded. These files are seached for in the patterns path
165%D have names like \type {lang-nl.lua}.
166%D
167%D The \type {spacing} variable specifies how the spaces after punctuation has to be
168%D handled. English is by tradition more tolerant to inter||sentence spacing than
169%D other languages.
170%D
171%D This macro also defines \type {\identifier} as a shortcut switch to the language.
172%D Furthermore the command defined as being language specific, are executed. With
173%D \type {default} we can default to another language (patterns) at format
174%D generation time. Patterns are loaded at runtime.
175
176\newtoks \everysetuplanguage
177
178\aliased\let\installedlanguages\clf_installedlanguages % no need for \clf_
179
180\permanent\protected\def\doifelselanguage#1%
181  {\ifcsname\??language#1\c!state\endcsname
182     \expandafter\firstoftwoarguments
183   \else
184     \expandafter\secondoftwoarguments
185   \fi}
186
187\aliased\let\doiflanguageelse\doifelselanguage
188
189\permanent\def\reallanguagetag#1%
190  {\ifcsname\??languagelinked#1\endcsname\lastnamedcs\else#1\fi}
191
192% \language[#1] gave unwanted side effect of loading language specifics
193
194\mutable\lettonothing\currentsetuplanguage
195
196\permanent\tolerant\protected\def\installlanguage[#1]#*[#S#2]%
197  {\ifhastok={#2}%
198     \doifelselanguage{#1}
199       {\getparameters[\??language#1][#2]}
200       {\defcsname\??languagelinked#1\endcsname{#1}%
201        \getparameters[\??language#1][\c!state=\v!start,#2]%
202        \lang_basics_install_indeed{#1}{#1}}%
203     \cdef\currentsetuplanguage{#1}%
204     \clf_definelanguage{#1}{\specificlanguageparameter{#1}\s!default}%
205     \expand\everysetuplanguage
206   \else
207     \defcsname\??languagelinked#1\endcsname{#2}%
208     \clf_setlanguagesynonym{#1}{#2}%
209     \lang_basics_install_indeed{#1}{#2}%
210  \fi}
211
212\def\lang_basics_install_indeed#1#2%
213  {\ifcstok{\specificlanguageparameter{#1}\c!define}\v!no\orelse\ifcsname#1\endcsname\else
214     \frozen\instance\protected\defcsname#1\endcsname{\lang_basics_set_current[#2]}%
215   \fi}
216
217%D When the second argument is a language identifier, a synonym is created. This
218%D feature is present because we used dutch mnemonics in the dutch version, but
219%D nowadays conform a standard.
220
221\permanent\protected\def\doifelsepatterns#1%
222  {\begingroup % will change
223   \lang_basics_set_current[#1]%
224   \ifnum\normallanguage>\zerocount
225     \endgroup\expandafter\firstoftwoarguments
226   \else
227     \endgroup\expandafter\secondoftwoarguments
228   \fi}
229
230\aliased\let\doifpatternselse\doifelsepatterns
231
232%D \macros
233%D   {setuplanguage}
234%D
235%D Quick and dirty, but useful:
236%D
237%D \showsetup{setuplanguage}
238%D
239%D Beware, this command can only be used when a language is installed.
240
241\ifdefined\lang_basics_synchronize \else
242    \let\lang_basics_synchronize\relax % be nice for setups till we have one
243\fi
244
245\installmacrostack\currentlanguage
246
247\permanent\tolerant\protected\def\setuplanguage[#S#1]#*[#S#2]%
248  {\ifarguments
249     % only synchronize
250   \or
251     \let\currentsetuplanguage\currentlanguage
252     \getparameters[\??language\currentsetuplanguage][#1]%
253     \expand\everysetuplanguage
254   \or
255     \push_macro_currentlanguage % can be default
256     \cdef\currentsetuplanguage{\reallanguagetag{#1}}%
257     \getparameters[\??language\currentsetuplanguage][#2]%
258     \expand\everysetuplanguage
259     \pop_macro_currentlanguage
260   \fi
261   \lang_basics_synchronize}
262
263\appendtoks
264    \clf_unloadlanguage{\currentsetuplanguage}%
265\to \everysetuplanguage
266
267\setuplanguage
268  [\s!default]
269  [\s!patterns=,
270   \s!goodies=,
271   \s!lefthyphenmin=2,
272   \s!righthyphenmin=2,
273   \s!lefthyphenchar=-1,
274   \s!righthyphenchar=45,
275   \s!explicitlefthyphenchar=\languageparameter\s!lefthyphenchar,
276   \s!explicitrighthyphenchar=\languageparameter\s!righthyphenchar,
277   % used in compound i.e. interfaced with c! and can be anything so no numbers
278   \c!lefthyphen=,
279   \c!righthyphen=-,
280   \c!hyphen=-,
281   \c!spacing=\v!packed,
282   \c!compoundhyphen=\compoundhyphen,
283   \c!rightcompoundhyphen=\compoundhyphen,
284   \c!leftcompoundhyphen=,
285   \c!midsentence=---,
286   \c!leftsentence=---,
287   \c!rightsentence=---,
288   \c!leftsubsentence=---,
289   \c!rightsubsentence=---,
290   \c!leftquote=\upperleftsinglesixquote,
291   \c!rightquote=\upperrightsingleninequote,
292   \c!leftquotation=\upperleftdoublesixquote,
293   \c!rightquotation=\upperrightdoubleninequote,
294   \c!leftspeech=\languageparameter\c!leftquotation,
295   \c!middlespeech=,
296   \c!rightspeech=\languageparameter\c!rightquotation,
297   \c!limittext=\unknown,
298   \c!time={h,:,m},
299   \c!date={\v!year,\ ,\v!month,\ ,\v!day},
300   \c!text=Ag,
301   \c!font=] % \v!auto : experimental !
302
303% to be tested:
304%
305% \setuplanguage
306%   [\s!default]
307%   [\c!righthyphenchar="AD]
308
309%D The values \type {leftsentence} and \type {rightsentence} can be (and are) used
310%D to implement automatic subsentence boundary glyphs, like in {\fr |<|french
311%D guillemots|>|} or {\de |<|german guillemots|>|} or {\nl |<|dutch dashes|>|} like
312%D situations. Furthermore \type {leftquotation} and \type {leftquote} come into
313%D view \quotation {when we quote} or \quote {quote} something.
314
315%D \macros
316%D  {currentdatespecification, currenttimespecification}
317%D
318%D Just to make things easy we can ask for the current date specification by saying:
319
320\permanent\def\currentdatespecification{\languageparameter\c!date}
321\permanent\def\currenttimespecification{\languageparameter\c!time}
322
323%D Carefull reading of these macros shows that it's legal to say
324%D
325%D \starttyping
326%D \installlanguage [du] [de]
327%D \stoptyping
328
329%D \macros
330%D   {language,mainlanguage}
331%D
332%D Switching to another language (actually another hyphenation pattern) is done
333%D with:
334%D
335%D \starttyping
336%D \language[identifier]
337%D \stoptyping
338%D
339%D or with \type {\identifier}. Just to be compatible with \PLAIN\ \TEX, we still
340%D support the original meaning, so
341%D
342%D \starttyping
343%D \language=1
344%D \stoptyping
345%D
346%D is a valid operation, where the relation between number and language depends on
347%D the order in installing languages.
348%D
349%D \showsetup{language}
350%D \showsetup{mainlanguage}
351%D
352%D Both commands take a predefined language identifier as argument. We can use \type
353%D {\mainlanguage[identifier]} for setting the (indeed) main language. This is the
354%D language used for translating labels like {\em figure} and {\em table}. The main
355%D language defaults to the current language.
356
357\newtoks \everylanguage
358
359\installcorenamespace{languagenumbers}
360
361\appendtoks
362    % we need to reassign the number because new patterns can be defined later on
363    % so let's hope not that many \setups happen during a run
364    \gletcsname\??languagenumbers\currentlanguage\endcsname\undefined
365\to \everysetuplanguage
366
367\def\lang_basics_synchronize_yes
368  {\zerocount % see below
369   \global\expandafter\chardef\csname\??languagenumbers\currentlanguage\endcsname
370      \clf_languagenumber
371        {\currentlanguage}%
372        {\defaultlanguage\currentlanguage}%
373        {\languageparameter\s!patterns}%
374        {\languageparameter\s!goodies}%
375        {\languageparameter\c!factor}%
376      \relax
377   \normallanguage\csname\??languagenumbers\currentlanguage\endcsname}
378
379\let\lang_basics_synchronize_nop\zerocount % not loaded anyway
380
381\letcsname\??languagenumbers\endcsname\lang_basics_synchronize_nop % initime
382
383\appendtoks
384    \letcsname\??languagenumbers\endcsname\lang_basics_synchronize_yes % runtime
385\to \everydump
386
387\def\lang_basics_synchronize
388  {\normallanguage\csname\??languagenumbers
389     \ifcsname\??languagenumbers\currentlanguage\endcsname
390       \currentlanguage
391     \fi
392   \endcsname
393   \relax
394   \expand\everylanguage
395   \relax}
396
397\newinteger\hyphenstate
398\newinteger\hyphenminoffset
399
400% This is the old implementation: a hack that sets the min values, because we want
401% to keep the language set:
402%
403% \protected\def\nohyphens % nicer for url's
404%   {\ifrelax\dohyphens
405%      \protected\edef\dohyphens
406%        {\hyphenminoffset\the\hyphenminoffset\relax
407%         \lang_basics_synchronize_min_max}%
408%    \fi
409%    \hyphenminoffset\plusthousand
410%    \lang_basics_synchronize_min_max}
411%
412% \let\dohyphens\relax
413
414% But this one is nicer because we do keep the language set as well as don't mess
415% with the min values (it's more efficient too). We might get some more bits in
416% this mode (engine specific).
417
418\exhyphenchar 45 % to permit breaking at explicit hyphens
419
420% \uchyph\plusone :
421
422% \chardef \completehyphenationcode \numexpr
423\permanent \integerdef \completehyphenationcode \numexpr
424    \normalhyphenationcode            % \discretionary
425  + \automatichyphenationcode         % -
426  + \explicithyphenationcode          % \-
427  + \syllablehyphenationcode          % pattern driven
428  + \uppercasehyphenationcode         % replaces \uchyph
429  + \compoundhyphenationcode          % replaces \compoundhyphenmode
430  % \strictstarthyphenationcode       % replaces \hyphenationbounds (strict = original tex)
431  % \strictendhyphenationcode         % replaces \hyphenationbounds (strict = original tex)
432  + \automaticpenaltyhyphenationcode  % replaces \hyphenpenaltymode (otherwise use \exhyphenpenalty)
433  + \explicitpenaltyhyphenationcode   % replaces \hyphenpenaltymode (otherwise use \exhyphenpenalty)
434  + \permitgluehyphenationcode        % turn glue into kern in \discretionary
435  + \permitallhyphenationcode         % okay, let's be even more tolerant
436  + \permitmathreplacehyphenationcode % and again we're more permissive
437  + \forcehandlerhyphenationcode      % kick in the handler (could be an option)
438  + \feedbackcompoundhyphenationcode  % feedback compound snippets
439  + \ignoreboundshyphenationcode      % just in case we have hyphens at the edges
440  + \collapsehyphenationcode          % collapse -- and ---
441\relax
442
443\permanent \integerdef \partialhyphenationcode \numexpr
444    \ignoreboundshyphenationcode      % just in case we have hyphens at the edges
445% + \explicithyphenationcode          % \-
446  + \collapsehyphenationcode          % collapse -- and ---
447\relax
448
449\hccode"002D "002D % hyphen
450\hccode"00B7 "00B7 % centered text period (used in some languages)
451
452\permanent\protected\def\keephyphensequences
453  {\hccode"2010 \zerocount
454   \hccode"2013 \zerocount
455   \hccode"2014 \zerocount}
456
457\permanent\protected\def\collapsehyphensequences
458  {\hccode"2010 "2010\relax
459   \hccode"2013 "2013\relax
460   \hccode"2014 "2014\relax}
461
462\collapsehyphensequences
463
464% maybe a (un)setter for handlers
465
466\permanent\protected\def\dohyphens{\hyphenationmode\completehyphenationcode}
467\permanent\protected\def\nohyphens{\hyphenationmode\partialhyphenationcode}
468
469% \permanent\protected\def\dohyphens
470%   {\ifbitwiseand\hyphenationmode\collapsehyphenationcode
471%      \hyphenationmode\completehyphenationcode
472%    \else
473%      \hyphenationmode\numexpr\completehyphenationcode-\collapsehyphenationcode\relax
474%    \fi}
475
476% \permanent\protected\def\nohyphens
477%   {\ifbitwiseand\hyphenationmode\collapsehyphenationcode
478%      \hyphenationmode\partialhyphenationcode
479%    \else
480%      \hyphenationmode\numexpr\partialhyphenationcode-\collapsehyphenationcode\relax
481%    \fi}
482
483\permanent\protected\def\dohyphencollapsing{\hyphenationmode\bitwiseflip\hyphenationmode \collapsehyphenationcode}
484\permanent\protected\def\nohyphencollapsing{\hyphenationmode\bitwiseflip\hyphenationmode-\collapsehyphenationcode}
485
486\permanent\protected\def\doexplicithyphens{\hyphenationmode\bitwiseflip\hyphenationmode \explicithyphenationcode}
487\permanent\protected\def\noexplicithyphens{\hyphenationmode\bitwiseflip\hyphenationmode-\explicithyphenationcode}
488
489\permanent\protected\def\usehyphensparameter#1%
490  {\ifcstok{#1\c!hyphens}\v!no
491     \ifbitwiseand\hyphenationmode\collapsehyphenationcode
492       \nohyphens
493     \else
494       \nohyphens
495       \nohyphencollapsing
496     \fi
497   \fi}
498
499\dohyphens
500
501%D The rest stays the same as in mkiv:
502
503\permanent\protected\def\lesshyphens
504  {\advanceby\hyphenminoffset\plusone
505   \lang_basics_synchronize_min_max}
506
507\permanent\protected\def\morehyphens
508  {\ifcase\hyphenminoffset \else
509     \advanceby\hyphenminoffset\minusone
510   \fi
511   \lang_basics_synchronize_min_max}
512
513% \protected\def\lang_basics_synchronize_min_max % maybe store this at the lua end
514%   {% these values are stored along with glyph nodes
515%    \lefthyphenmin \numexpr0\languageparameter\s!lefthyphenmin +\hyphenminoffset\relax
516%    \righthyphenmin\numexpr0\languageparameter\s!righthyphenmin+\hyphenminoffset\relax
517%    \hyphenationmin\numexpr0\languageparameter\s!hyphenmin\relax
518%    % these values are stored with the language (global!)
519%    \prehyphenchar \languageparameter\s!righthyphenchar\relax
520%    \posthyphenchar\languageparameter\s!lefthyphenchar \relax}
521
522\protected\def\lang_basics_synchronize_min_max % maybe store this at the lua end
523  {% these values are stored along with glyph nodes
524   \lefthyphenmin \numexpr0\languageparameter\s!lefthyphenmin +\hyphenminoffset\relax
525   \righthyphenmin\numexpr0\languageparameter\s!righthyphenmin+\hyphenminoffset\relax
526   \hyphenationmin\numexpr0\languageparameter\s!hyphenmin\relax
527   % these values are stored with the language (global!)
528   \prehyphenchar   \languageparameter\s!righthyphenchar\relax
529   \posthyphenchar  \languageparameter\s!lefthyphenchar \relax
530   \preexhyphenchar \languageparameter\s!explicitrighthyphenchar\relax
531   \postexhyphenchar\languageparameter\s!explicitlefthyphenchar \relax}
532
533\appendtoks
534    \lang_basics_synchronize_min_max % todo: also sync when already in language
535\to \everylanguage
536
537\permanent\protected\def\unhyphenated
538  {\groupedcommand{\lefthyphenmin\maxdimen}\donothing}
539
540% \appendtoks
541%     \setups[\languageparameter\c!setups]%
542% \to \everylanguage
543
544%D You can setup the default language to reset settings.
545
546\mutable\lettonothing\currentlanguagesetups
547
548\appendtoks
549    \edef\currentlanguagesetups{\languageparameter\c!setups}%
550    \ifempty\currentlanguagesetups \else
551        \setups[\currentlanguagesetups]%
552    \fi
553\to \everylanguage
554
555% new
556
557\appendtoks
558    \usebidiparameter\languageparameter
559\to \everylanguage
560
561% this will move to core-spa !
562
563\appendtoks
564    \ifcstok{\languageparameter\c!spacing}\v!broad
565      \nonfrenchspacing
566    \else
567      \frenchspacing
568    \fi
569\to \everylanguage
570
571% \mainlanguage[nl] \setuplanguage[nl][lefthyphen=,righthyphen=?]
572%
573% \dorecurse{100}{dit is toch wel een heel\normalhyphendiscretionary lang\normalhyphendiscretionary woord \recurselevel\ }
574% \dorecurse{100}{dit is toch wel een heellangwoord \recurselevel\ }
575
576% new experimental feature
577
578\permanent\protected\def\setuplanguages
579  {\setuplanguage[\s!default]}
580
581% \setuplanguages[\c!font=\v!auto]
582% \setuplanguage[\s!default][\c!font=\v!auto]
583% \setuplanguage[nl][\c!font=\v!auto]
584
585\appendtoks
586    \edef\p_language_font{\languageparameter\c!font}%
587    \ifempty\p_language_font
588    \orelse\ifx\p_language_font\v!auto
589      \doaddfeature\currentlanguage
590    \else
591      \doaddfeature\p_language_font
592    \fi
593\to \everylanguage
594
595%D Fast switcher
596
597\def\lang_basics_switch_asked
598  {\ifcsname\??languagelinked\askedlanguage\endcsname
599     \edef\askedlanguage{\lastnamedcs}%
600     \ifx\currentlanguage\askedlanguage \else
601       \setcurrentlanguage\currentmainlanguage\askedlanguage
602       \lang_basics_synchronize
603     \fi
604   \fi}
605
606\permanent\protected\def\uselanguageparameter#1%
607  {\edef\askedlanguage{#1\c!language}%
608   \ifempty\askedlanguage\else\lang_basics_switch_asked\fi}
609
610\permanent\protected\def\douselanguageparameter#1% fast setter
611  {\edef\askedlanguage{#1}%
612   \ifempty\askedlanguage\else\lang_basics_switch_asked\fi}
613
614\protected\def\lang_basics_set_current[#1]%
615  {\edef\askedlanguage{#1}%
616   \ifempty\askedlanguage\else\lang_basics_switch_asked\fi}
617
618\pushoverloadmode
619
620    \permanent\protected\def\language
621      {\doifelsenextoptionalcs\lang_basics_set_current\normallanguage}
622
623    \aliased\let\setlanguage\language % we make these synonyms
624
625    \aliased\let\patterns\gobbleoneargument
626
627\popoverloadmode
628
629\newinteger\mainlanguagenumber
630
631%D Beware: you might need to use \type {\dontleavehmode} outside and|/|or \type {\par}
632%D inside the group!
633
634\permanent\protected\def\startlanguage
635  {\begingroup\language}
636
637\permanent\let\stoplanguage\endgroup
638
639\permanent\protected\def\mainlanguage[#1]%
640  {\edef\askedlanguage{#1}%
641   \ifempty\askedlanguage
642   \orelse\ifcsname\??languagelinked\askedlanguage\endcsname
643    %\edef\askedlanguage{\csname\??languagelinked\askedlanguage\endcsname}%
644     \edef\askedlanguage{\lastnamedcs}%
645     \ifx\currentlanguage\askedlanguage
646       \ifx\currentmainlanguage\askedlanguage \else
647         \setcurrentlanguage\askedlanguage\askedlanguage
648         \lang_basics_synchronize
649       \fi
650     \else
651       \setcurrentlanguage\askedlanguage\askedlanguage
652       \lang_basics_synchronize
653     \fi
654   \fi
655   \mainlanguagenumber\normallanguage}
656
657\appendtoks
658    \normallanguage\mainlanguagenumber
659\to \everybeforepagebody
660
661%D Used at all?
662
663\permanent\def\splitsequence#1#2% append periods etc
664  {\ifcstok{#1}\v!no
665     #2%
666   \orelse\ifcstok{#1}\v!yes
667      \languageparameter\c!limittext
668   \else
669     #1%
670   \fi}
671
672\permanent\def\splitsymbol#1%
673  {\splitsequence{#1}{\languageparameter\c!limittext}}
674
675%D Just like with subsentence boundary symbols, quotes placement depends on the
676%D current language, therefore we show the defaults here.
677%D
678%D \def\ShowLanguageValues [#1] [#2] #3 #4
679%D   {\blank
680%D    \startlinecorrection
681%D    \vbox\bgroup
682%D    \language[#1]
683%D    \midaligned{\bf#2 subsentence symbol and quotes}
684%D    \framed[width=\hsize,frame=off,topframe=on,bottomframe=on,offset=.5ex]
685%D      {\hfil\quotation{#3 #4}\hfil\quote{#2}\hfil
686%D       \startsubsentence\startsubsentence#3\stopsubsentence#4\stopsubsentence\hfil}
687%D    \egroup
688%D    \stoplinecorrection
689%D    \blank}
690%D
691%D \ShowLanguageValues [af] [afrikaans]  afrikaanse ...
692%D \ShowLanguageValues [ca] [catalan]    catalan ...
693%D \ShowLanguageValues [cs] [czech]      tjechisch tex
694%D \ShowLanguageValues [cs] [slovak]     slowaakse ...
695%D \ShowLanguageValues [da] [danish]     deense ...
696%D \ShowLanguageValues [de] [german]     duitse degelijkheid
697%D \ShowLanguageValues [en] [english]    engelse humor
698%D \ShowLanguageValues [et] [estonian]   ...
699%D \ShowLanguageValues [fi] [finnish]    finse ...
700%D \ShowLanguageValues [fr] [french]     franse slag
701%D \ShowLanguageValues [it] [italian]    italiaanse ...
702%D \ShowLanguageValues [la] [latin]      latijnse missen
703%D \ShowLanguageValues [nl] [dutch]      nederlandse zuinigheid
704%D \ShowLanguageValues [nb] [bokmal]     noorse zalm
705%D \ShowLanguageValues [nn] [nnynorsk]   noorse zalm
706%D \ShowLanguageValues [pl] [polish]     poolse vlag
707%D \ShowLanguageValues [pt] [portuguese] portugese ...
708%D \ShowLanguageValues [es] [spanish]    spaans benauwd
709%D \ShowLanguageValues [sv] [swedish]    zweedse ...
710%D \ShowLanguageValues [tr] [turkish]    turks fruit
711
712%D We support a lot of languages. These are specified and loaded in separate files,
713%D according to their roots. Here we only take care of (postponed) setting of the
714%D current language.
715%D
716%D \unprotect
717%D \placetable{The germanic languages (\type{lang-ger})}
718%D \starttable[||||]
719%D \HL
720%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
721%D \HL
722%D \NC \s!nl        \NC dutch        \NC germanic  \NC\FR
723%D \NC \s!en        \NC english      \NC germanic  \NC\MR
724%D \NC \s!de        \NC german       \NC germanic  \NC\MR
725%D \NC \s!da        \NC danish       \NC germanic  \NC\MR
726%D \NC \s!sv        \NC swedish      \NC germanic  \NC\MR
727%D \NC \s!af        \NC afrikaans    \NC germanic  \NC\MR
728%D \NC \s!nb        \NC bokmal       \NC germanic  \NC\LR
729%D \NC \s!nn        \NC nynorsk      \NC germanic  \NC\LR
730%D \HL
731%D \stoptable
732%D \protect
733%D
734%D \unprotect
735%D \placetable{The italic languages (\type{lang-ita})}
736%D \starttable[||||]
737%D \HL
738%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
739%D \HL
740%D \NC \s!fr        \NC french       \NC italic    \NC\FR
741%D \NC \s!ca        \NC catalan      \NC italic    \NC\MR
742%D \NC \s!es        \NC spanish      \NC italic    \NC\MR
743%D \NC \s!it        \NC italian      \NC italic    \NC\MR
744%D \NC \s!la        \NC latin        \NC italic    \NC\MR
745%D \NC \s!pt        \NC portuguese   \NC italic    \NC\LR
746%D \HL
747%D \stoptable
748%D \protect
749%D
750%D \unprotect
751%D \placetable{The slavic languages (\type{lang-sla})}
752%D \starttable[||||]
753%D \HL
754%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
755%D \HL
756%D \NC \s!pl        \NC polish       \NC slavic    \NC\FR
757%D \NC \s!cs        \NC czech        \NC slavic    \NC\MR
758%D \NC \s!sk        \NC slavik       \NC slavic    \NC\LR
759%D \HL
760%D \stoptable
761%D \protect
762%D \unprotect
763%D
764%D \placetable{The altaic languages (\type{lang-alt})}
765%D \starttable[||||]
766%D \HL
767%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
768%D \HL
769%D \NC \s!tr        \NC turkish      \NC altaic    \NC\SR
770%D \HL
771%D \stoptable
772%D
773%D \placetable{The uralic languages (\type{lang-ura})}
774%D \starttable[||||]
775%D \HL
776%D \NC \bf mnemonic \NC \bf language \NC \bf group \NC\SR
777%D \HL
778%D \NC \s!fi        \NC finnish      \NC uralic    \NC\SR
779%D \HL
780%D \stoptable
781%D \protect
782
783\permanent\protected\def\nopatterns{\normallanguage\minusone}
784
785%D We default to the language belonging to the interface. This is one of the few
786%D places outside the interface modules where \type {\startinterface} is used.
787
788\setupcurrentlanguage[\s!en]
789
790\permanent\protected\def\initializemainlanguage
791  {\mainlanguage[\currentlanguage]%
792   \showmessage\m!languages9\currentlanguage}
793
794%D New:
795
796\permanent\let\stopexceptions\relax
797
798\tolerant\permanent\protected\def\startexceptions[#1]#:#2\stopexceptions
799  {\begingroup
800   \edef\askedlanguage{\reallanguagetag{#1}}%
801   \ifempty\askedlanguage
802     \let\askedlanguage\currentlanguage
803   \fi
804   \clf_setlanguageexceptions{\askedlanguage}{#2}%
805   \endgroup}
806
807\permanent\let\stoppatterns\relax
808
809\tolerant\permanent\protected\def\startpatterns[#1]#:#2\stoppatterns
810  {\begingroup
811   \edef\askedlanguage{\reallanguagetag{#1}}%
812   \ifempty\askedlanguage
813     \let\askedlanguage\currentlanguage
814   \fi
815   \clf_setlanguagepatterns{\askedlanguage}{#2}%
816   \endgroup}
817
818
819\pushoverloadmode
820
821\permanent\protected\def\hyphenation{\clf_setlanguageexceptions{\currentlanguage}}
822\permanent\protected\def\patterns   {\clf_setlanguagepatterns  {\currentlanguage}}
823
824\popoverloadmode
825
826%D New:
827
828\permanent\protected\def\traceddiscretionary#1#%
829  {\dontleavehmode\lang_basics_traced_discretionary{#1}}
830
831\protected\def\lang_basics_traced_discretionary#1#2#3#4%
832  {\normaldiscretionary#1{\darkred#2}{\darkgreen#3}{\darkblue#4}}
833
834\def\lang_basics_trace_discretionary_yes{\enforced\let\discretionary\traceddiscretionary} % indirect because of overload
835\def\lang_basics_trace_discretionary_nop{\enforced\let\discretionary\normaldiscretionary} % indirect because of overload
836
837
838\installtextracker
839  {discretionaries}
840  {\lang_basics_trace_discretionary_yes}
841  {\lang_basics_trace_discretionary_nop}
842
843\permanent\protected\def\samplediscretionary
844  {\traceddiscretionary
845     {pre\clf_currentprehyphenchar}%
846     {\clf_currentposthyphenchar post}%
847     {replace}}
848
849%D A typical \LMTX\ feature:
850%D
851%D \starttyping
852%D whatever\par
853%D {\nokerning whatever}\par
854%D efficient ff fi\par
855%D {\noligaturing efficient ff fi}\par
856%D {\nokerning\noligaturing efficient ff fi}\par
857%D {e{\noligaturing ffi}cient}\par
858%D {ef{\noleftligaturing f}icient ff fi}\par
859%D {ef{\norightligaturing f}icient ff fi}\par
860%D \stoptyping
861
862\immutable\integerdef\nokerningcode   \numexpr\noleftkernglyphoptioncode        +\norightkernglyphoptioncode           \relax
863\immutable\integerdef\noligaturingcode\numexpr\noleftligatureglyphoptioncode    +\norightligatureglyphoptioncode       \relax
864\immutable\integerdef\noitalicscode   \numexpr\noitaliccorrectionglyphoptioncode+\nozeroitaliccorrectionglyphoptioncode\relax
865
866\permanent\protected\def\nokerning         {\bitwiseflip\glyphoptions\nokerningcode}
867\permanent\protected\def\noligaturing      {\bitwiseflip\glyphoptions\noligaturingcode}
868\permanent\protected\def\noitaliccorrection{\bitwiseflip\glyphoptions\noitalicscode}
869
870\permanent\protected\def\noleftkerning     {\bitwiseflip\glyphoptions\noleftkernglyphoptioncode}
871\permanent\protected\def\noleftligaturing  {\bitwiseflip\glyphoptions\noleftligatureglyphoptioncode}
872\permanent\protected\def\norightkerning    {\bitwiseflip\glyphoptions\norightkernglyphoptioncode}
873\permanent\protected\def\norightligaturing {\bitwiseflip\glyphoptions\norightligatureglyphoptioncode}
874
875\bitwiseflip\glyphoptions\nozeroitaliccorrectionglyphoptioncode % for the moment default avoid the side effect
876
877%D Also \LMTX:
878
879% \startlanguageoptions[de]
880%     Zapf|innovation
881% \stoplanguageoptions
882
883\permanent\let\stoplanguageoptions\relax
884
885\permanent\protected\def\startlanguageoptions
886  {\begingroup
887   \catcode`|\othercatcode
888   \lang_startlanguageoptions}
889
890\tolerant\def\lang_startlanguageoptions[#1]#:#2\stoplanguageoptions
891  {\edef\askedlanguage{\reallanguagetag{#1}}%
892   \ifempty\askedlanguage
893     \let\askedlanguage\currentlanguage
894   \fi
895   \clf_setlanguageoptions{\askedlanguage}{#2}%
896   \endgroup}
897
898% \startluacode
899%     table.save("oeps-fixes.llg", {
900%         name    = "demo",
901%         options = {
902%             { patterns = { fio  = "f|io" }, words = [[ fioot fiots ]] },
903%             { patterns = { fio  = "t|h"  }, words = [[ this that ]]   },
904%         },
905%     })
906% \stopluacode
907%
908% \setuplanguage[en][goodies={oeps-fixes.llg}] \setupbodyfont[ebgaramond]
909%
910% \starttext
911%     fiets fiots fiats fioot this that
912% \stoptext
913
914\protect \endinput
915