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