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
|
%% This is part of OpTeX project, see http://petr.olsak.net/optex
\_codedecl \langlist {Initialization of hypenation patterns <2020-03-10>} % preloaded in format
\_doc -----------------------------
The <iso-code> means a shortcut of language name (mostly by ISO 639-1).
The following control sequences are used for language switching:
\begitems
* `\_lan:<number>` expands to `<iso-code>` of the language.
The number is internal number of languages used as a value of
`\language` register.
* `\_ulan:<long-lang>` expands to `<iso-code>` too. This is transformation
from long name of language (lowercase letters) to <iso-code>.
* `\_<iso-code>Patt` (for example `\_csPatt`) is the language `<number>` declared by `\chardef`.
* `\<iso-code>lang`
(for example \`\enlang`, \`\cslang`, \`\sklang`, \`\delang`, \`\pllang`)
is language selector. It exists in two states
\begitems
* Initialization state: when `\<iso-code>lang` is used first then it
must load the patterns into memory using Lua code. If it is done then
the `\<iso-code>lang` re-defines itself to processing state.
* Processing state: it only sets `\language=\_<iso-code>Patt`, i.e it
selects the hyphenation patterns. It does a little more
language-dependent work, as mentioned below.
\enditems
* `\_langspecific:<isocode>` is processed by `\<iso-code>lang` and it
should include language-specific macros declared by user or macro designer.
\enditems
The USenglish patters are preloaded first:
\_cod -----------------------------
\_chardef\_enPatt=0
\_def\_pattlist{\_enPatt=0}
\_def\_langlist{en(USenglish)}
\_sdef{_lan:0}{en}
\_sdef{_ulan:usenglish}{en}
\_def\_enlang{\_uselang{en}\_enPatt23} % \lefthyph=2 \righthyph=3
\_def\enlang{\_enlang}
\_sdef{_langspecific:en}{\_nonfrenchspacing}
\_lefthyphenmin=2 \_righthyphenmin=3 % disallow x- or -xx breaks
\_input hyphen % en(USenglish) patterns from TeX82
\_doc -----------------------------
\`\_preplang` `<iso-code> <long-lang> <hyph-file-spec> <number> <pre-hyph><post-hyph>`
prepares the\nl `\<iso-code>lang` to its initialization state. Roughly
speaking, it does:
\begtt \catcode`\<=13
\chardef\_<iso-code>Patt = <number>
\def\_lan:<number> {<iso-code>}
\def\_ulan:<long-lang> {<iso-code>}
\def\_<iso-code>lang {%
\_loadpattrs <hyph-file-spec> <number> <long-lang> % loads patterns using Lua code
\gdef\_<iso-code>lang {\_uselang{<iso-code>}\_<iso-code>Patt <pre-hyph><post-hyph>}
\_<iso-code>lang % runs itself in processing state
}
\def\<iso-code>lang {\_<iso-code>lang} % public version \<iso-code>lang
\endtt
You can see that `\<iso-code>lang` runs \^`\_loadpattrs` and
\^`\_uselang` first (in initialization state) and it runs
only \^`\_uselang` when it is called again (in processing state).
\_cod -----------------------------
\_def\_preplang #1 #2 #3 #4 #5 {%
\_ea\_chardef \_csname _#1Patt\_endcsname=#4
\_sdef{_lan:#4}{#1}\_lowercase{\_sdef{_ulan:#2}}{#1}%
\_def\_next{\_ea\_noexpand\_csname _#1lang\_endcsname}%
\_ea\_edef \_csname _#1lang\_endcsname {%
\_noexpand\_loadpattrs #3 #4 #2 % loads patterns
\_gdef\_next{\_noexpand\_uselang{#1}\_csname _#1Patt\_endcsname #5}% re-defines itself
\_next % runs itself in processing state
}
\_addto\_langlist{ #1(#2)}%
\_sdef{#1lang\_ea}\_ea{\_csname _#1lang\_endcsname}% unprefixed \<isocode>lang
}
\_doc -----------------------------
\`\_loadpattrs` `<hyph-file-spec> <number> <long-lang>`
loads hyphenation patterns and hyphenation exceptions for given language
and registers them as `\language=<number>`.
The <hyph-file-spec> is a part of full file name wich is read:
`hyph-<hyph-file-spec>.tex`. The patterns and hyphenation exceptions
are saved here in UTF-8 encoding.
The <hyph-file-spec> should be a list of individual <hyph-file-spec>'s
separated by comma, see the language Serbian below for example.
\_cod -----------------------------
\_def\_loadpattrs#1 #2 #3 {%
\_wlog{Loading hyphenation #3: (#1) \_string\language=#2}%
\_begingroup\_setbox0=\_vbox{% we don't want spaces in horizontal mode
\_language=#2\_def\\{#3}%
\_let\patterns=\_patterns \_let\hyphenation=\_hyphenation \_def\message##1{}%
\_loadpattrsA #1,,%
}\_endgroup
}
\_def\_loadpattrsA #1,{\_ifx,#1,\_else
\_isfile {hyph-#1}\_iftrue \_opinput{hyph-#1}%
\_else \_opwarning{Hyph. patterns #1 for \\ not loaded, probably missing package}%
\_def\_opwarning##1{}\_fi
\_ea \_loadpattrsA \_fi
}
\_doc -----------------------------
\`\_uselang``{<iso-code>}\_<iso-code>Patt <pre-hyph><post-hyph>`\nl
sets `\language`, `\lefthyphenmin`, `\righthyphenmin` and runs
`\frenchspacing`. This default language-dependent settings
should be re-declared by `\_langspecific:<iso-code>` which is run
finally (it is `\relax` by default, only `\_langspecific:en` runs
\^`\nonfrenchspacing`).
\_cod -----------------------------
\_def\_uselang#1#2#3#4{\_language=#2\_lefthyphenmin=#3\_righthyphenmin=#4\_relax
\_frenchspacing % \nonfrenchspacing can be set in \cs{_langspecific:lan}
\_cs{_langspecific:#1}%
}
\_doc -----------------------------
The \`\uselanguage` `{<long-lang>}` is defined here
(for compatibility with e-plain users).
\_cod -----------------------------
\_def\_uselanguage#1{\_lowercase{\_cs{_\_cs{_ulan:#1}lang}}}
\_public \uselanguage ;
\_doc -----------------------------
The numbers for languages are declared as fixed constants (no
auto-generated). This concept is inspired from CSplain.
There are typical numbers of languages in CSplain: 5=Czech in IL2,
15=Czech in T1 and 115=Czech in Unicode. We keep these constants
but we load only Unicode patterns (greater than 100), of course.
\_cod -----------------------------
\_preplang enus USenglishmax en-us 100 23
\_preplang engb UKenglish en-gb 101 23
\_preplang it Italian it 102 22
\_preplang ia Interlingua ia 103 22
\_preplang id Indonesian id 104 22
\_preplang cs Czech cs 115 23
\_preplang sk Slovak sk 116 23
\_preplang de nGerman de-1996 121 22
\_preplang fr French fr 122 22
\_preplang pl Polish pl 123 22
\_preplang cy Welsh cy 124 23
\_preplang da Danish da 125 22
\_preplang es Spanish es 126 22
\_preplang sl Slovenian sl 128 22
\_preplang fi Finnish fi 129 22
\_preplang hu Hungarian hu 130 22
\_preplang tr Turkish tr 131 22
\_preplang et Estonian et 132 23
\_preplang eu Basque eu 133 22
\_preplang ga Irish ga 134 23
\_preplang nb Bokmal nb 135 22
\_preplang nn Nynorsk nn 136 22
\_preplang nl Dutch nl 137 22
\_preplang pt Portuguese pt 138 23
\_preplang ro Romanian ro 139 22
\_preplang hr Croatian hr 140 22
\_preplang zh Pinyin zh-latn-pinyin 141 11
\_preplang is Icelandic is 142 22
\_preplang hsb Uppersorbian hsb 143 22
\_preplang af Afrikaans af 144 12
\_preplang gl Galician gl 145 22
\_preplang kmr Kurmanji kmr 146 22
\_preplang tk Turkmen tk 147 22
\_preplang la Latin la 148 22
\_preplang lac classicLatin la-x-classic 149 22
\_preplang lal liturgicalLatin la-x-liturgic 150 22
\_preplang elm monoGreek el-monoton 201 11
\_preplang elp Greek el-polyton 202 11
\_preplang grc ancientGreek grc 203 11
\_preplang ca Catalan ca 204 22
\_preplang cop Coptic cop 205 11
\_preplang mn Mongolian mn-cyrl 206 22
\_preplang sa Sanskrit sa 207 13
\_preplang ru Russian ru 208 22
\_preplang uk Ukrainian uk 209 22
\_preplang hy Armenian hy 210 12
\_preplang as Assamese as 211 11
\_preplang hi Hindi hi 212 11
\_preplang kn Kannada kn 213 11
\_preplang lv Latvian lv 215 22
\_preplang lt Lithuanian lt 216 22
\_preplang ml Malayalam ml 217 11
\_preplang mr Marathi mr 218 11
\_preplang or Oriya or 219 11
\_preplang pa Panjabi pa 220 11
\_preplang ta Tamil ta 221 11
\_preplang te Telugu te 222 11
\_preplang be Belarusian be 223 22
\_preplang bg Bulgarian bg 224 22
\_preplang bn Bengali bn 225 11
\_preplang cu churchslavonic cu 226 12
\_preplang deo oldGerman de-1901 227 22
\_preplang gsw swissGerman de-ch-1901 228 22
\_preplang eo Esperanto eo 229 22
\_preplang fur Friulan fur 230 22
\_preplang gu Gujarati gu 231 11
\_preplang ka Georgian ka 232 12
\_preplang mk Macedonian mk 233 22
\_preplang oc Occitan oc 234 22
\_preplang pi Pali pi 235 12
\_preplang pms Piedmontese pms 236 22
\_preplang rm Romansh rm 237 22
\_preplang sr Serbian sh-cyrl,sh-latn 238 22
\_preplang sv Swedish sv 239 22
\_preplang th Thai th 240 23
\_preplang ethi Ethiopic mul-ethi 241 11
\_doc -----------------------------
The \`\langlist` includes names of all languages which are ready to load
and use their hyphenation patterns. This list is printed to terminal and
to log at ini\TeX/ state here. It can be used when processing document too.
\_cod -----------------------------
\_message{Language hyph.patterns ready to load: \_langlist.
Use \_string\<shortname>lang to initialize language,
\_string\cslang\_space for example}
\_public \langlist ;
\_endcode % ---------------------------------------------
Maybe, you need to do more language specific actions than just switching
hyphenation patterns. For example you need to load a specific font with a
specific script used in selected language, you can define a macros for
quotation marks depending on the language etc.
The example shows how to declare such language specific things.
\begtt
\def\langset #1 #2{\sdef{_langspecific:#1}{#2}}
\langset fr {... declare French quotation marks}
\langset de {... declare German quotation marks}
\langset gr {... switch to Greek fonts family}
... etc.
\endtt
Note that you need not to set language specific phrases (like `\today`)
by this code. Another concept is used for such tasks. See the
section~\ref[langphrases] for more details.
|