enco-ini.mkxl /size: 16 Kb    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=enco-ini,
3%D        version=2007.02.19, % 2000.12.27, % 1998.12.03,
4%D          title=\CONTEXT\ Encoding 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%D This is stripped down version of the original enco-ini.tex file. For more details
15%D you might want to study the \MKII\ file but since \LUATEX\ is unicode inside we
16%D need less code. When we moved to \LMTX\ again some disappeared and the composition
17%D macros were upgraded in the process.
18%D
19%D An historic note: When dealing with characters we have four cases to take into
20%D account when moving from \MKII\ to \MKIV:
21%D
22%D \starttabulate[|l|l|]
23%D     \NC \type {<byte 200>}   \NC ref to slot 200 in current font \NC \NR
24%D     \NC \type {\char 200}    \NC ref to slot 200 in current font \NC \NR
25%D     \NC \type {<active 200>} \NC can (e.g.) map to another slot in current font \NC \NR
26%D     \NC \type {\namedglyph}  \NC can map to some slot in some font \NC \NR
27%D \stoptabulate
28%D
29%D Using case 2 for special characters is doomed to fail because we are not going to
30%D intercept these on the fly as happens automatically with traditional font
31%D encoding handling. We could do that in a node pass but it's not worth the effort
32%D because we seldom use this case in a document source.
33
34\writestatus{loading}{ConTeXt Encoding Macros / Initialization}
35
36\unprotect
37
38%D This one is obsolete but maybe sometimes still used in styles:
39
40\immutable\let\defaultencoding\s!default
41
42%D \macros
43%D   {defineaccent, definecharacter, definecommand}
44%D
45%D Some of these are used at the \LUA\ end but the names will change.
46
47\installcorenamespace{accents}
48
49%D These might go away:
50
51\permanent\protected\def\defineaccent#1 #2 #3 %
52  {\dodefineaccentcommand{#1}%
53   \dodefineaccent{#1}{#2}{#3}}
54
55\permanent\protected\def\dodefineaccentcommand#1%
56  {\ifcsname\string#1\endcsname\else
57     \edefcsname\string#1\endcsname{\noexpand\dohandleaccent{\string#1}}%
58   \fi}
59
60\permanent\protected\def\dodefineaccent#1#2#3% no spaces, used low level
61  {\defcsname\??accents\string#1\string#2\empty\endcsname{#3}}
62
63\permanent\protected\def\dohandleaccent#1#2% expandable because we want them in the tuc file
64  {\csname\??accents
65     \ifcsname\??accents\string#1#2\empty\endcsname
66       \string#1#2\empty
67     \orelse\ifcsname\??accents\string#1\string#2\empty\endcsname
68       \string#1\string#2\empty
69     \else
70       \endcsname#2\csname\??accents % very dirty trick: ignore accent but keep char
71     \fi
72   \endcsname}
73
74\immutable\letvalue{\??accents}\empty
75
76%D Because now have this (\type {\chr} issues a one|-|time warning):
77
78\permanent\protected\def\dodefinecombine#1#2%
79  {\ifcsname\string#1\endcsname\else
80     \permanent\protected\defcsname with#1\endcsname##1{\chr{##1#2}}%
81   \fi}
82
83%D The following dirty trick is needed to catch \asciimath{\^{1/5}log}, although:
84%D do we?
85
86\permanent\protected\def\definecharacter#1 #2 %
87  {\doifelsenumber{\string#2}
88     {\edefcsname\string#1\endcsname{\Uchar#2}}
89     {\protected\defcsname\string#1\endcsname{#2}}}
90
91%D specials: \aa \ae \cc \i \ij \l \o \oe \sz \par
92%D SPECIALS: \AA \AE \CC \j \IJ \L \O \OE \SZ \par
93
94\permanent\protected\def\definecommand#1 #2 %
95  {\protected\defcsname\string#1\endcsname{#2}}
96
97\permanent\protected\def\dodefinecommand#1#2% \O \L \AE ...
98  {% not permanent as these are kind of obsolete
99   \frozen\protected\defcsname\string#1\endcsname{#2}}
100
101%D We set up some things in \LUA:
102
103\clf_defineaccents % one time
104
105%D This defined commands like \type {\withgrave} and \type {\withcaronbelow} and
106%D some of these have aliases. Below ee also alias the traditional one character
107%D accent commands.
108%D
109%D \starttabulate[||||]
110%D     \NC \getvalue{agrave}        \NC \withgrave       {a} \NC \`{a} \NC \NR
111%D     \NC \getvalue{aacute}        \NC \withacute       {a} \NC \'{a} \NC \NR
112%D     \NC \getvalue{acircumflex}   \NC \withcircumflex  {a} \NC \^{a} \NC \NR
113%D     \NC \getvalue{atilde}        \NC \withtilde       {a} \NC \~{a} \NC \NR
114%D     \NC \getvalue{amacron}       \NC \withmacron      {a} \NC \={a} \NC \NR
115%D     \NC \getvalue{ebreve}        \NC \withbreve       {e} \NC \u{e} \NC \NR
116%D     \NC \getvalue{cdotaccent}    \NC \withdot         {c} \NC \.{c} \NC \NR
117%D     \NC \getvalue{ediaeresis}    \NC \withdieresis    {e} \NC \"{e} \NC \NR
118%D     \NC \getvalue{uring}         \NC \withring        {u} \NC \r{u} \NC \NR
119%D     \NC \getvalue{uhungarumlaut} \NC \withhungarumlaut{u} \NC \H{u} \NC \NR
120%D     \NC \getvalue{ecaron}        \NC \withcaron       {e} \NC \v{e} \NC \NR
121%D     \NC \getvalue{ecedilla}      \NC \withcedilla     {e} \NC \c{e} \NC \NR
122%D     \NC \getvalue{eogonek}       \NC \withogonek      {e} \NC \k{e} \NC \NR
123%D \stoptabulate
124%D
125%D Now we alias these traditional shortcuts:
126
127\pushoverloadmode
128
129\suggestedalias \` \withgrave
130\suggestedalias \' \withacute
131\suggestedalias \^ \withcircumflex
132\suggestedalias \~ \withtilde
133\suggestedalias \= \withmacron
134\suggestedalias \u \withbreve
135\suggestedalias \. \withdot
136\suggestedalias \" \withdieresis
137\suggestedalias \r \withring
138\suggestedalias \H \withdoubleacute
139\suggestedalias \v \withcaron
140\suggestedalias \c \withcedilla
141\suggestedalias \k \withogonek
142\suggestedalias \d \withdotbelow
143
144\popoverloadmode
145
146% From \type {enco-com} we had these, maybe that's better:
147
148% \aliased\let\AE\AEligature   \aliased\let\ae\aeligature
149% \aliased\let\OE\OEligature   \aliased\let\oe\oeligature
150% \aliased\let\IJ\IJligature   \aliased\let\ij\ijligature
151% \aliased\let\AA\textAngstrom \aliased\let\aa\aring
152% \aliased\let\CC\Ccedilla     \aliased\let\cc\ccedilla
153% \aliased\let\L \Lslash       \aliased\let\l \lslash
154% \aliased\let\O \Oslash       \aliased\let\o \oslash
155% \aliased\let\SZ\Eszett       \aliased\let\sz\eszett    % \aliased\let\SS\Ssharp
156
157% %D \macros
158% %D   {everyuppercase, everylowercase, everysanitize}
159%
160% \newtoks \everyuppercase
161% \newtoks \everylowercase
162% \newtoks \everysanitize
163
164%D Accent handling (try to avoid this):
165
166% \buildtextaccent\greekdasia\greekalphamacron
167% \buildtextaccent\textacute q
168
169%D We can use offsets in \LMTX\ but even that makes no sense because we have
170%D a virtual feature already in \MKIV. These builders are depricated:
171
172\newbox\b_enco_accent
173
174\permanent\protected\def\buildmathaccent#1%
175  {\mathaccent#1 }
176
177\permanent\protected\def\buildtextaccent#1#2% we could do all at the lua end
178  {\dontleavehmode\begingroup               % but that's no fun (yet)
179   \setbox\scratchboxone\hbox{#1}% accent
180   \setbox\scratchboxtwo\hbox{#2}% character
181   \scratchheight\dimexpr\ht\scratchboxtwo-\ht\scratchboxone\relax
182   \scratchdepth \dimexpr\dp\scratchboxtwo-\dp\scratchboxone\relax
183   \scratchwidth \wd\scratchboxtwo
184   \hbox to \wd\ifdim\wd\scratchboxone>\wd\scratchboxtwo\scratchboxone\else\scratchboxtwo\fi\bgroup
185     \hss\box\scratchboxtwo\hss
186     \hskip-\scratchwidth
187     \hss
188     \ifdim\ht\scratchboxone>\exheight
189       % top accent
190       \raise\dimexpr\scratchheight+\exheight/3\relax
191     \else
192       \lower-\dimexpr\scratchdepth+\exheight/3\relax
193     \fi
194     \box\scratchboxone
195     \hss
196   \egroup
197   \endgroup}
198
199\permanent\protected\def\bottomaccent#1#2#3#4#5% down right slantcorrection accent char
200  {\dontleavehmode % why this align mess
201   \vtop
202     {\forgetall
203      \baselineskip\zeropoint
204      \lineskip#1%
205      \everycr\emptytoks
206      \tabskip\zeropoint
207      \lineskiplimit\zeropoint
208      \setbox0\hbox{#4}%
209      \halign
210        {##\crcr\hbox{#5}\crcr
211         \hidewidth
212         \hskip#2\wd0
213         \hskip-#3\slantperpoint % in plain 1ex * dimenless value
214         \vpack to .2\exheight{\box0\vss}\hidewidth
215         \crcr}}}
216
217\permanent\protected\def\buildtextmacron     {\bottomaccent{.25ex}{0}{15}{\textmacron}}
218\permanent\protected\def\buildtextbottomdot  {\bottomaccent{.25ex}{0}{5}{\textbottomdot}}
219\permanent\protected\def\buildtextcedilla    {\bottomaccent{0ex}{0}{5}{\textcedilla}}
220\permanent\protected\def\buildtextogonek     {\bottomaccent{-.1ex}{.5}{0}{\textogonek}}
221\permanent\protected\def\buildtextbottomcomma{\bottomaccent{.15ex}{0}{5}{\tx,}}
222
223\permanent\protected\def\topaccent#1#2#3#4#5% down right slantcorrection accent char
224  {\dontleavehmode
225   \bgroup
226     \setbox0\hbox{#4}%
227     \setbox2\hbox{#5}%
228     \hbox to \wd2 \bgroup
229        \hss\copy2\hss
230        \hskip-\wd2
231        \hss\hskip#2\wd0\hskip-#3\slantperpoint\raise#1\hbox{#4}\hss
232     \egroup
233   \egroup}
234
235\permanent\protected\def\buildtextgrave
236  {\topaccent{0pt}{0}{15}{\textgrave}} % e.g.
237
238\permanent\protected\def\definemathaccent#1 #2%
239  {\setvalue{#1}{\mathaccent#2 }}
240
241% from enco-def:
242
243% \aliased\let\i\dotlessi
244% \aliased\let\j\dotlessj
245
246% \aliased\let\P\paragraphmark \aliased\let\textP\paragraphmark % obsolete (surfaced in bibliographic files)
247% \aliased\let\S\sectionmark   \aliased\let\textS\sectionmark   % obsolete (surfaced in bibliographic files)
248
249\immutable\def\eszett  {ß} \immutable\def\Eszett  {SS} \permanent\def\Ssharp{SS}
250\immutable\def\lslash  {ł} \immutable\def\Lslash  {Ł}
251\immutable\def\dslash  {đ} \immutable\def\Dslash  {Đ}
252%immutable\def\oslash  {ø} %immutable\def\Oslash  {Ø} % clashes with math: use \Ostroke
253\immutable\def\dcroat  {đ} \immutable\def\Dcroat  {Đ}
254\immutable\def\kcedilla{ķ} \immutable\def\Kcedilla{Ķ}
255\immutable\def\lcedilla{ļ} \immutable\def\Lcedilla{Ļ}
256\immutable\def\ncedilla{ņ} \immutable\def\Ncedilla{Ņ}
257\immutable\def\rcedilla{ŗ} \immutable\def\Rcedilla{Ŗ}
258\immutable\def\aumlaut {ä} \immutable\def\Aumlaut {Ä}
259\immutable\def\eumlaut {ë} \immutable\def\Eumlaut {Ë}
260\immutable\def\iumlaut {ï} \immutable\def\Iumlaut {Ï}
261\immutable\def\oumlaut {ö} \immutable\def\Oumlaut {Ö}
262\immutable\def\uumlaut {ü} \immutable\def\Uumlaut {Ü}
263
264%D For old times sake we keep these (obsolete):
265
266\immutable\def\textflorin{ƒ} \immutable\def\florin  {ƒ}
267\immutable\def\pound     {£} \immutable\def\sterling{£}
268\immutable\def\promille  {} \immutable\def\permille{}
269
270%D These are kind of \TEX\ specific
271
272\pushoverloadmode
273
274\permanent\protected\def\ampersand{\mathortext\mathampersand\textampersand}
275
276\immutable\let\percent\textpercent
277\immutable\let\procent\textpercent
278\immutable\let\dollar \textdollar
279\immutable\let\hash   \texthash
280
281\popoverloadmode
282
283%D some more: what with freezing here?
284
285\ifdefined\softhyphen \else
286    \aliased\let\softhyphen\explicitdiscretionary
287\fi
288
289%D The softhyhen is never used but we keep the definition below:
290
291\aliased\let\hyphen \softhyphen % never used
292
293% But we ditch these:
294
295% \def\hyphen           {\softhyphen} % never used
296% \def\compoundwordmark {\hyphen}
297% \def\cwm              {\hyphen}
298% \def\nonbreakinghyphen{\hyphen}
299% \def\breakinghyphen   {\hyphen\prewordbreak}
300
301%D Quotes \unknown\ we keep these funny names because they indicate where we come
302%D from \unknown\ long long ago when we had no real useful names for them. Some
303%D ancient styles might still use them.
304
305\aliased\let\lowerleftsingleninequote \quotesinglebase % ‚
306\aliased\let\lowerleftdoubleninequote \quotedblbase    % „
307\aliased\let\lowerrightsingleninequote\quotesinglebase % ‚
308\aliased\let\lowerrightdoubleninequote\quotedblbase    % „
309
310\aliased\let\upperleftsingleninequote \quoteright      % ’
311\aliased\let\upperleftdoubleninequote \quotedblright   % ”
312\aliased\let\upperrightsingleninequote\quoteright      % ’
313\aliased\let\upperrightdoubleninequote\quotedblright   % ”
314
315\aliased\let\upperleftsinglesixquote  \quoteleft       % ‘
316\aliased\let\upperleftdoublesixquote  \quotedblleft    % “
317\aliased\let\upperrightsinglesixquote \quoteleft       % ‘
318\aliased\let\upperrightdoublesixquote \quotedblleft    % “
319
320\aliased\let\leftsubguillemot         \guilsingleleft  % ‹
321\aliased\let\rightsubguillemot        \guilsingleright % ›
322
323% Some left-overs that will go away!
324
325\permanent\protected\def\textblacksquare{\dontleavehmode\hpack{\vrule\s!width.3\s!em\s!height.4\s!em\s!depth-.1\s!em}}
326%permanent\protected\def\schwa          {\hbox{\rotate[\c!rotation=180,\c!location=\v!high]{\hbox{e}}}}
327\permanent\protected\def\schwagrave     {\buildtextgrave\schwa}
328
329\installcorenamespace{controlspace}
330
331\permanent\protected\def\fallbackcontrolspace % beware, current font, we also need to honor color
332  {\hbox to \interwordspace \bgroup
333     \hss
334     \ifcsname\??controlspace\number\interwordspace\endcsname
335       \csname\??controlspace\number\interwordspace\endcsname
336     \else
337       \enco_fast_control_space_define % only regular
338     \fi
339     \textcontrolspace
340     \hss
341   \egroup}
342
343\protected\def\enco_fast_control_space_define
344  {\scratchdimen\interwordspace
345   \definedfont[LMTypewriter-Regular at \the\dimexpr\currentfontbodyscale\dimexpr\fontbody]% see font-sym.mkiv
346   \gletcsname\??controlspace\number\scratchdimen\endcsname\lastrawfontcall}
347
348\permanent\protected\def\normalcontrolspace
349  {\iffontchar\font\numexpr\expandafter`\textcontrolspace\relax
350     \textcontrolspace
351   \else
352     \fallbackcontrolspace
353   \fi}
354
355\aliased\let\textvisiblespace\normalcontrolspace
356
357\permanent\protected\def\optionalcontrolspace
358  {\iffontchar\font\numexpr\expandafter`\textcontrolspace\relax
359     \textcontrolspace
360   \else
361     \asciispacechar % used for export !
362   \fi}
363
364%D A smaller and bolder variant, more like the math and monospaced ones.
365
366\permanent\protected\def\fakeunderscore
367  {\relax\ifmmode
368     \vrule\s!depth .12\fontexheight\mathstylefont\normalmathstyle\s!width \fontinterwordspace\mathstylefont\normalmathstyle\s!height\zeropoint\relax
369   \else
370     \dontleavehmode\hbox{\vrule\s!depth .12\fontexheight\font\s!width \fontinterwordspace\font\s!height\zeropoint}%
371   \fi}
372
373\permanent\protected\def\fakeunderscores{\enforced\let\_\fakeunderscore}
374\permanent\protected\def\textunderscores{\enforced\let\_\textunderscore}
375
376\textunderscores
377
378\ifdefined\mathunderscore \else \aliased\let\mathunderscore\fakeunderscore \fi
379\ifdefined\textunderscore \else \aliased\let\textunderscore\fakeunderscore \fi
380
381\permanent\protected\def\normalunderscore{\ifmmode\mathunderscore\else\textunderscore\fi}
382
383\pushoverloadmode
384    \enforced\let\_\normalunderscore
385\popoverloadmode
386
387%D To be sorted out:
388
389\pushoverloadmode
390
391\permanent\protected\def\textminus
392  {\char
393     \iffontchar\font"2012 "2012 \orelse % figuredash
394     \iffontchar\font"2013 "2013 \orelse % endash
395     \iffontchar\font"2212 "2212 \else   % math minus
396                           "002D \fi}    % hyphen
397
398\permanent\protected\def\textplus
399  {\char"002B } % plus
400
401\popoverloadmode
402
403%D Moved from core-mis:
404
405% \permanent\protected\def\celsius   #1{#1\mathematics{^\circ}C}
406% \permanent\protected\def\inch        {\mathematics{\prime\prime}} % was: \hbox{\rm\char125\relax}
407% \permanent\protected\def\fraction#1#2{\mathematics{#1\over#2}}
408
409\permanent\protected\def\celsius   #1{#1\iffontchar\font`℃℃\else\mathematics{^\circ}C\fi}   % 0x2103
410\permanent\protected\def\inch        {\iffontchar\font`″″\else\mathematics{\prime\prime}\fi} % 0x2103
411\permanent\protected\def\fraction#1#2{\mathematics{\Uabove exact .125\exheight {#1}{#2}}}
412
413%D \startbuffer
414%D \startlines
415%D     x\periods x
416%D     x\periods[10]x
417%D     x\periods[n=10,symbol={,}]x
418%D     x\periods[n=4,symbol={!!},width=1em]x
419%D     x\periods[n=4,symbol={!!},width=fit]x
420%D     x\periods[n=4,symbol={!!},width=fit,distance=1em]x
421%D     x\unknown x
422%D \stoplines
423%D \stopbuffer
424%D
425%D \typbuffer \getbuffer
426
427\installcorenamespace {periods}
428
429\installsetuponlycommandhandler \??periods {periods}
430
431\setupperiods
432  [\c!n=3,
433   \c!width=.5\emwidth, % can also be \v!fit
434   \c!distance=.25\emwidth,
435   \c!symbol=.]
436
437\permanent\protected\def\periods
438  {\dontleavehmode
439   \hbox\bgroup
440   \doifelsenextoptional\enco_periods_yes\enco_periods_nop}
441
442\protected\def\enco_periods_yes[#1]%
443  {\doifelseassignment{#1}
444     {\setupcurrentperiods[#1]%
445      \scratchcounter\periodsparameter\c!n}
446     {\doifelsenothing{#1}
447        {\scratchcounter\periodsparameter\c!n}%
448        {\scratchcounter#1}}%
449   \enco_periods_finish}
450
451\protected\def\enco_periods_nop
452  {\scratchcounter\periodsparameter\c!n
453   \enco_periods_finish}
454
455\protected\def\enco_periods_finish
456  {\edef\p_width{\periodsparameter\c!width}%
457   \ifx\p_width\v!fit
458     \enco_periods_finish_fit
459   \else
460     \enco_periods_finish_width
461   \fi
462   \egroup}
463
464\protected\def\enco_periods_finish_width
465  {\setbox\scratchbox\hbox to \p_width
466     {\hss\periodsparameter\c!symbol\hss}%
467   \dorecurse\scratchcounter{\copy\scratchbox}}
468
469\protected\def\enco_periods_finish_fit
470  {\edef\p_symbol{\periodsparameter\c!symbol}%
471   \scratchdistance\periodsparameter\c!distance
472   \hskip\scratchdistance
473   \dorecurse\scratchcounter{\p_symbol\hskip\scratchdistance}}
474
475\permanent\protected\def\unknown
476  {\dontleavehmode
477   \hbox\bgroup
478   \enco_periods_nop}
479
480%D Left-overs:
481
482\appendtoks
483    \enforced\let\buildtextaccent\secondoftwoarguments
484\to \everysimplifycommands
485
486%D See enco-ini.mkivc for a definition of the obsolete \type {\t}.
487
488\protect \endinput
489