| 1 |
%% This is part of the OpTeX project, see http://petr.olsak.net/optex |
| 2 |
|
| 3 |
\_codedecl \langlist {Languages declaration <2025-05-12>} % preloaded in format |
| 4 |
|
| 5 |
\_doc ----------------------------- |
| 6 |
\`\_preplang` `<lang-id> <LongName> <lang-tag> <hyph-tag> <lr-hyph>` |
| 7 |
declares a new language. The parameters (separated by space) are |
| 8 |
\begitems |
| 9 |
* <lang-id>: language identifier. It should be derived from ISO 639-1 code |
| 10 |
but additional letters can be eventually added because <lang-id> must be used |
| 11 |
uniquely in the whole declaration list. The \^`\_preplang` macro creates |
| 12 |
the language switch `\_<lang-id>lang` and defines also `\<lang-id>lang` |
| 13 |
as a macro which expands to `\_<lang-id>lang`. For example, `\_preplang cs Czech ...` |
| 14 |
creates `\_cslang` as the language switch and defines |
| 15 |
`\def\cslang{\_cslang}`. |
| 16 |
* <LongName>: full name of the language. |
| 17 |
* <lang-tag>: language tag, which is used for setting language-dependent phrases |
| 18 |
and sorting data. If a language have two or more hyphenation |
| 19 |
patterns but a single phrases set, then we declare this language |
| 20 |
more than once with the same <lang-tag> but different <lang-hyph>. |
| 21 |
* <hyph-tag>: a part of the file name where the hyphenation patterns |
| 22 |
are prepared in Unicode. The full file name is `hyph-<hyph-tag>.tex`. |
| 23 |
If <hyph-tag> is `{}` then no hyphenation patterns are loaded. |
| 24 |
* <lr-hyph>: two digits, they denote `\lefthyphenmin` and |
| 25 |
`\righthyphenmin` values. |
| 26 |
\enditems |
| 27 |
\^`\_preplang` allocates a new internal number by \^`\newlanguage\_<lang-id>Patt` |
| 28 |
which will be bound to the hyphenation patterns. But the patterns nor other language |
| 29 |
data are not read at this moment. The `\_<lang-id>lang` is defined as \^`\_langinit`. |
| 30 |
When the `\_<lang-id>lang` switch is used firstly in a document then the language is |
| 31 |
initialized, i.e.\ hyphenation patterns and language-dependent data are read. |
| 32 |
The `\_<lang-id>lang` is re-defined itself after such initialization. |
| 33 |
\^`\_preplang` does also `\def\_ulan:<longname> {<lang-id>}`, this is needed |
| 34 |
for the \^`\uselanguage` macro. |
| 35 |
\_cod ----------------------------- |
| 36 |
|
| 37 |
\_def\_preplang #1 #2 #3 #4 #5#6{% lang-id LongName lang-tag hyph-tag lr-hyph |
| 38 |
\_ifcsname _#1lang\_endcsname \_else |
| 39 |
\_ea\_newlanguage\_csname _#1Patt\_endcsname |
| 40 |
\_xdef\_langlist{\_langlist\_space#1(#2)}% |
| 41 |
\_fi |
| 42 |
\_lowercase{\_sxdef{_ulan:#2}}{#1}% |
| 43 |
\_slet{_#1lang}{_relax}% |
| 44 |
\_sxdef {#1lang}{\_cs{_#1lang}}% |
| 45 |
\_sxdef {_#1lang}{\_noexpand\_langinit \_cs{_#1lang}#1(#2)#3[#4]#5#6}% |
| 46 |
} |
| 47 |
\_doc ----------------------------- |
| 48 |
The \^`\_preplang` macro adds `<lang-id>(<LongName>)` to the `\_langlist` macro |
| 49 |
which is accessible by \`\langlist`. It can be used for reporting declared |
| 50 |
languages. |
| 51 |
\_cod ----------------------------- |
| 52 |
|
| 53 |
\_def\langlist{\_langlist} |
| 54 |
\_def\_langlist{en(USEnglish)} |
| 55 |
|
| 56 |
\_doc ----------------------------- |
| 57 |
All languages with hyphenation patterns provided by \TeX/live are |
| 58 |
declared here. The language switches \`\cslang`, \`\sklang`, |
| 59 |
\`\delang`, \`\pllang` and many others are declared. |
| 60 |
You can declare more languages by \^`\_preplang` in your |
| 61 |
document, if you want.\nl |
| 62 |
The usage of \^`\_preplang` with <lang-id> already declared is allowed. |
| 63 |
The language is re-declared in this case. This can be used in your document |
| 64 |
before first usage of the `\<lang-id>lang` switch. |
| 65 |
\_cod ----------------------------- |
| 66 |
|
| 67 |
% lang-id LongName lang-tag hyph-tag lr-hyph |
| 68 |
\_preplang enus USenglishmax en en-us 23 |
| 69 |
% Europe: |
| 70 |
\_preplang engb UKenglish en en-gb 23 |
| 71 |
\_preplang be Belarusian be be 22 |
| 72 |
\_preplang bg Bulgarian bg bg 22 |
| 73 |
\_preplang ca Catalan ca ca 22 |
| 74 |
\_preplang hr Croatian hr hr 22 |
| 75 |
\_preplang cs Czech cs cs 23 |
| 76 |
\_preplang da Danish da da 22 |
| 77 |
\_preplang nl Dutch nl nl 22 |
| 78 |
\_preplang et Estonian et et 23 |
| 79 |
\_preplang fi Finnish fi fi 22 |
| 80 |
\_preplang fis schoolFinnish fi fi-x-school 11 |
| 81 |
\_preplang fr French fr fr 22 |
| 82 |
\_preplang de nGerman de de-1996 22 |
| 83 |
\_preplang deo oldGerman de de-1901 22 |
| 84 |
\_preplang gsw swissGerman de de-ch-1901 22 |
| 85 |
\_preplang elm monoGreek el el-monoton 11 |
| 86 |
\_preplang elp Greek el el-polyton 11 |
| 87 |
\_preplang grc ancientGreek grc grc 11 |
| 88 |
\_preplang hu Hungarian hu hu 22 |
| 89 |
\_preplang is Icelandic is is 22 |
| 90 |
\_preplang ga Irish ga ga 23 |
| 91 |
\_preplang it Italian it it 22 |
| 92 |
\_preplang la Latin la la 22 |
| 93 |
\_preplang lac classicLatin la la-x-classic 22 |
| 94 |
\_preplang lal liturgicalLatin la la-x-liturgic 22 |
| 95 |
\_preplang lv Latvian lv lv 22 |
| 96 |
\_preplang lt Lithuanian lt lt 22 |
| 97 |
\_preplang mk Macedonian mk mk 22 |
| 98 |
\_preplang pl Polish pl pl 22 |
| 99 |
\_preplang pt Portuguese pt pt 23 |
| 100 |
\_preplang ro Romanian ro ro 22 |
| 101 |
\_preplang rm Romansh rm rm 22 |
| 102 |
\_preplang ru Russian ru ru 22 |
| 103 |
\_preplang srl Serbian srlatn sh-latn 22 |
| 104 |
\_preplang src SerbianCyrl srcyrl sh-cyrl 22 |
| 105 |
\_preplang sk Slovak sk sk 23 |
| 106 |
\_preplang sl Slovenian sl sl 22 |
| 107 |
\_preplang es Spanish es es 22 |
| 108 |
\_preplang sv Swedish sv sv 22 |
| 109 |
\_preplang uk Ukrainian uk uk 22 |
| 110 |
\_preplang cy Welsh cy cy 23 |
| 111 |
% Others: |
| 112 |
\_preplang af Afrikaans af af 12 |
| 113 |
\_preplang hy Armenian hy hy 12 |
| 114 |
\_preplang as Assamese as as 11 |
| 115 |
\_preplang eu Basque eu eu 22 |
| 116 |
\_preplang bn Bengali bn bn 11 |
| 117 |
\_preplang nb Bokmal nb nb 22 |
| 118 |
\_preplang cop Coptic cop cop 11 |
| 119 |
\_preplang cu churchslavonic cu cu 12 |
| 120 |
\_preplang eo Esperanto eo eo 22 |
| 121 |
\_preplang ethi Ethiopic ethi mul-ethi 11 |
| 122 |
\_preplang fur Friulan fur fur 22 |
| 123 |
\_preplang gl Galician gl gl 22 |
| 124 |
\_preplang ka Georgian ka ka 12 |
| 125 |
\_preplang gu Gujarati gu gu 11 |
| 126 |
\_preplang hi Hindi hi hi 11 |
| 127 |
\_preplang id Indonesian id id 22 |
| 128 |
\_preplang ia Interlingua ia ia 22 |
| 129 |
\_preplang kn Kannada kn kn 11 |
| 130 |
\_preplang kmr Kurmanji kmr kmr 22 |
| 131 |
\_preplang ml Malayalam ml ml 11 |
| 132 |
\_preplang mr Marathi mr mr 11 |
| 133 |
\_preplang mn Mongolian mn mn-cyrl 22 |
| 134 |
\_preplang nn Nynorsk nn nn 22 |
| 135 |
\_preplang oc Occitan oc oc 22 |
| 136 |
\_preplang or Oriya or or 11 |
| 137 |
\_preplang pi Pali pi pi 12 |
| 138 |
\_preplang pa Panjabi pa pa 11 |
| 139 |
\_preplang pms Piedmontese pms pms 22 |
| 140 |
\_preplang zh Pinyin zh zh-latn-pinyin 11 |
| 141 |
\_preplang sa Sanskrit sa sa 13 |
| 142 |
\_preplang ta Tamil ta ta 11 |
| 143 |
\_preplang te Telugu te te 11 |
| 144 |
\_preplang th Thai th th 23 |
| 145 |
\_preplang tr Turkish tr tr 22 |
| 146 |
\_preplang tk Turkmen tk tk 22 |
| 147 |
\_preplang hsb Uppersorbian hsb hsb 22 |
| 148 |
|
| 149 |
\_preplang he Hebrew he {} 00 |
| 150 |
|
| 151 |
\_doc ----------------------------- |
| 152 |
\`\_preplangmore` `<lang-id><space>{<text>}` declares more activities |
| 153 |
of the language switch. The <text> is processed whenever |
| 154 |
`\_<lang-id>lang` is invoked. If \^`\_preplangmore` is not declared |
| 155 |
for given language then \`\_langdefault` is processed.\nl |
| 156 |
You can implement selecting a required script for given language, for |
| 157 |
example: |
| 158 |
\begtt |
| 159 |
\_preplangmore ru {\_frenchspacing \_setff{script=cyrl}\selectcyrlfont} |
| 160 |
\_addto\_langdefault {\_setff{}\selectlatnfont} |
| 161 |
\endtt |
| 162 |
The macros `\selectcyrlfont` and `\selectlatnfont` are not defined in |
| 163 |
\OpTeX/. If you follow this example, you have to define them after your |
| 164 |
decision what fonts will be used in your specific situation. |
| 165 |
\_cod ----------------------------- |
| 166 |
|
| 167 |
\_def\_preplangmore #1 #2{\_ea \_gdef \_csname _langspecific:#1\_endcsname{#2}} |
| 168 |
|
| 169 |
\_preplangmore en {\_nonfrenchspacing} |
| 170 |
\_preplangmore enus {\_nonfrenchspacing} |
| 171 |
\_def\_langdefault {\_frenchspacing} |
| 172 |
|
| 173 |
\_doc ----------------------------- |
| 174 |
The \`\_langreset` is processed before macros declared by \^`\_preplangmore` |
| 175 |
or before \^`\_langdefault`. If you set something for |
| 176 |
your language by \^`\_preplangmore` then use `\def\_langreset{<settings>}` |
| 177 |
in this code too in order to return default values for all other languages. |
| 178 |
See `cs` part of `lang-data.opm` file for an example. |
| 179 |
\_cod ----------------------------- |
| 180 |
|
| 181 |
\_def\_langreset {} |
| 182 |
|
| 183 |
\_doc ----------------------------- |
| 184 |
The default `\language=0` is US-English with original hyphenation patterns |
| 185 |
preloaded in the format (see the end of section~\ref[plain]). |
| 186 |
We define `\_enlang` and \`\enlang` switches. |
| 187 |
Note that if no language switch is used in the document then |
| 188 |
`\language=0` and US-English patterns are used, but \^`\nonfrenchspacing` |
| 189 |
isn't set. |
| 190 |
\_cod ----------------------------- |
| 191 |
|
| 192 |
\_chardef\_enPatt=0 |
| 193 |
\_sdef{_lan:0}{en} |
| 194 |
\_sdef{_ulan:usenglish}{en} |
| 195 |
\_def\_enlang{\_uselang{en}\_enPatt23} % \lefthyph=2 \righthyph=3 |
| 196 |
\_def\enlang{\_enlang} |
| 197 |
|
| 198 |
\_doc ----------------------------- |
| 199 |
The list of declared languages are reported during format generation. |
| 200 |
\_cod ----------------------------- |
| 201 |
|
| 202 |
\_message{Declared languages: \_langlist. |
| 203 |
Use \_string\<lang-id>lang to initialize language, |
| 204 |
\_string\cslang\_space for example.} |
| 205 |
|
| 206 |
\_doc ----------------------------- |
| 207 |
Each language switch `\_<lang-id>lang` defined by \^`\_preplang` has its initial state\nl |
| 208 |
\`\_langinit` `\<switch> <lang-id>(<LongName>)<lang-tag>[<hyph-tag>]<lr-hyph>`. |
| 209 |
The \^`\_langinit` macro does: |
| 210 |
\begitems |
| 211 |
* The internal language <number> is extracted from `\_the\_<lang-id>Patt`. |
| 212 |
* `\def \_lan:<number> {<lang-tag>}` for mapping from `\language` number to the <lang-tag>. |
| 213 |
* loads `hyph-<hyph-tag>.tex` file with hyphenation patterns when `\language=<number>`. |
| 214 |
* loads the part of `lang-data.opm` file with language-dependent phrases |
| 215 |
using \^`\_langinput`. |
| 216 |
* `\def \_<lang-id>lang {\_uselang{<lang-id>}\_<lang-id>Patt <lr-hyph>}`, |
| 217 |
i.e. the switch redefines itself for doing a \"normal job" when the |
| 218 |
language switch is used repeatedly. |
| 219 |
* Runs itself (i.e. `\_<lang-id>lang`) again for doing the \"normal job" firstly. |
| 220 |
\enditems |
| 221 |
\_cod ----------------------------- |
| 222 |
|
| 223 |
\_def\_langinit #1#2(#3)#4[#5]#6#7{% \_switch lang-id(LongName)lang-tag[hyph-file]lr-hyph |
| 224 |
\_sxdef{_lan:\_ea\_the\_csname _#2Patt\_endcsname}{#4}% |
| 225 |
\_begingroup \_setbox0=\_vbox{% we don't want spaces in horizontal mode |
| 226 |
\_setctable\_optexcatcodes |
| 227 |
% loading patterns: |
| 228 |
\_language=\cs{_#2Patt}\_relax |
| 229 |
\_ifx^#5^\_else |
| 230 |
\_wlog{Loading hyphenation for #3: \_string\language=\_the\_language\_space(#5)}% |
| 231 |
\_let\patterns=\_patterns \_let\hyphenation=\_hyphenation \_def\message##1{}% |
| 232 |
\_isfile {hyph-#5}\_iftrue \_input{hyph-#5}% |
| 233 |
\_else \_opwarning{No hyph. patterns #5 for #3, missing package?}\_fi |
| 234 |
\_fi |
| 235 |
% loading language data: |
| 236 |
\_langinput{#4}% |
| 237 |
}\_endgroup |
| 238 |
\xdef#1{\noexpand\_uselang{#2}\_csname _#2Patt\_endcsname #6#7}% |
| 239 |
#1% do language switch |
| 240 |
} |
| 241 |
|
| 242 |
\_doc ----------------------------- |
| 243 |
\`\_uselang``{<lang-id>}\_<lang-id>Patt <pre-hyph><post-hyph>` |
| 244 |
is used as \"normal job" of the switch. |
| 245 |
It sets `\language`, `\lefthyphenmin`, `\righthyphenmin`. |
| 246 |
Finally, it runs data from \^`\_preplangmore` or runs \^`\_langdefault`. |
| 247 |
\_cod ----------------------------- |
| 248 |
|
| 249 |
\_def\_uselang#1#2#3#4{\_language=#2\_lefthyphenmin=#3\_righthyphenmin=#4\_relax |
| 250 |
\_langreset \_def\_langreset{}\_trycs{_langspecific:#1}{\_langdefault}% |
| 251 |
} |
| 252 |
|
| 253 |
\_doc ----------------------------- |
| 254 |
The \`\uselanguage` `{<LongName>}` macro is defined here |
| 255 |
(for compatibility with e-plain users). Its parameter is case insensitive. |
| 256 |
\_cod ----------------------------- |
| 257 |
|
| 258 |
\_def\_uselanguage#1{\_def\_tmp{#1}\_lowercase{\_cs{_\_trycs{_ulan:#1}{0x}lang}}} |
| 259 |
\_sdef{_0xlang}{\_opwarning{\_string\uselanguage{\_tmp}: Unknown language name, ignored}} |
| 260 |
\_public \uselanguage ; |
| 261 |
|
| 262 |
\_doc ----------------------------- |
| 263 |
\secc [langdata] Data for various languages |
| 264 |
|
| 265 |
The \"language data" include declarations of |
| 266 |
rules for sorting (see section~\ref[makeindex]), |
| 267 |
language-dependent phrases and quotation marks (see section~\ref[langphrases]). |
| 268 |
The language data are collected in the single `lang-data.opm` file. |
| 269 |
Appropriate parts of this file is read by \^`\_langinput{<lang-tag>}`. |
| 270 |
First few lines of the file looks like: |
| 271 |
{\maxlines=47 \printdoc lang-data.opm }% |
| 272 |
There are analogical declaration for more languages here. Unfortunately, this |
| 273 |
file is far for completeness. I welcome you send me a part of declaration |
| 274 |
for your language. |
| 275 |
|
| 276 |
If your language is missing in this file then a warning is reported during |
| 277 |
language initialization. You can create your private declaration in your |
| 278 |
macros (analogical as in the `lang-data.opm` file |
| 279 |
but without the \^`\_langdata` prefix). |
| 280 |
Then you will want to remove the warning about missing data. This can be |
| 281 |
done by \`\nolanginput``{<lang-tag>}` given before initialization of your |
| 282 |
language. |
| 283 |
|
| 284 |
The whole file `lang-data.opm` is not preloaded in the format because |
| 285 |
I suppose a plenty languages here and I don't want to waste the \TeX/ memory |
| 286 |
by these declarations. Each part of this file prefixed by |
| 287 |
\`\_langdata` `<lang-tag> {<LongName>}` is read separately |
| 288 |
when \`\_langinput``{<lang-tag>}` is used. And it is used |
| 289 |
in the \^`\_langinit` macro (i.e.\ when the language is initialized), |
| 290 |
so the appropriate part of this file is read automatically on demand. |
| 291 |
|
| 292 |
If the part of the `lang-data.opm` concerned by <lang-tag> is read already |
| 293 |
then `\_li:<lang-tag>` is set to `R` and we don't read this part of the file again. |
| 294 |
\_cod ----------------------------- |
| 295 |
|
| 296 |
\_def\_langinput #1{% |
| 297 |
\_unless \_ifcsname _li:#1\_endcsname |
| 298 |
\_bgroup |
| 299 |
\_edef\_tmp{\_noexpand\_langdata #1 }\_everyeof\_ea{\_tmp{}}% |
| 300 |
\_long \_ea\_def \_ea\_tmp \_ea##\_ea1\_tmp{\_readlangdata{#1}}% |
| 301 |
\_globaldefs=1 |
| 302 |
\_ea\_tmp \_input{lang-data.opm}% |
| 303 |
\_ea\_glet \_csname _li:#1\_endcsname R% |
| 304 |
\_egroup |
| 305 |
\_fi |
| 306 |
} |
| 307 |
\_def\_readlangdata #1#2{% |
| 308 |
\_ifx^#2^\_opwarning{Missing data for language "#1" in lang-data.opm}% |
| 309 |
\_else \_wlog{Reading data for the language #2 (#1)}% |
| 310 |
\_fi |
| 311 |
} |
| 312 |
\_def\_langdata #1 #2{\_endinput} |
| 313 |
\_def\_nolanginput #1{\_ea\_glet \_csname _li:#1\_endcsname N} |
| 314 |
\_public \nolanginput ; |
| 315 |
|
| 316 |
\_doc ----------------------------- |
| 317 |
Data of two preferred languages are preloaded in the format: |
| 318 |
\_cod ----------------------------- |
| 319 |
|
| 320 |
\_langinput{en} \_langinput{cs} |
| 321 |
|
| 322 |
\_endcode |
| 323 |
|
| 324 |
2025-05-12 sr-latn -> sllatn, sr-cyrl -> srcyrl |
| 325 |
2022-10-11 \_langreset introduced |
| 326 |
2022-02-19 \_langinput moved here |
| 327 |
2022-02-17 released, original file was hyphen-lan.opm |