summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/enco-ini.mkiv
blob: a942d5110967c8bbe22c2f9ddc888ea34b474792 (plain)
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
%D \module
%D   [       file=enco-ini,
%D        version=2007.02.19, % 2000.12.27, % 1998.12.03,
%D          title=\CONTEXT\ Encoding Macros,
%D       subtitle=Initialization,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D This is stripped down version of th eoriginal enco-ini.tex
%D file. For more details you might want to study the \MKII\ file
%D but since \LUATEX\ is unicode inside we need less code.

% When dealing with characters we have four cases to take into account
% when moving from mkii to mkiv:

% 1. <byte 200>   => ref to slot 200 in current font
% 2. \char 200    => ref to slot 200 in current font
% 3. <active 200> => can (e.g.) map to another slot in current font
% 4. \namedglyph  => can map to some slot in some font

% Using case 2 for special characters is doomed to fail because we are not going
% to intercept these on the fly as happens automatically with traditional font
% encoding handling. We could do that in a node pass but it's not worth the effort
% because we seldom use this case in a document source.

% We can consider using utf as internal format for mkii. The main reason for not
% doing this before was that it was slow. On the other hand, it would make dealing
% with utility files easier. However, we've now kind of frozen mkii.

\writestatus{loading}{ConTeXt Encoding Macros / Initialization}

\unprotect

%D Obsolete (but sometimes used in styles)

\let\defaultencoding\s!default

%D \macros
%D   {defineaccent, definecharacter, definecommand}

\unexpanded\def\dodefineaccentcommand#1%
  {\setevalue{\string#1}{\noexpand\dohandleaccent{\string#1}}}

\unexpanded\def\dodefineaccent#1#2#3% no spaces, used low level
  {\setvalue{\??ac\string#1\string#2\empty}{#3}}

\unexpanded\def\defineaccent#1 #2 #3 %
  {\dodefineaccentcommand{#1}%
   \dodefineaccent{#1}{#2}{#3}}

\def\dohandleaccent#1#2%
  {\ifcsname\??ac\string#1#2\empty\endcsname
     \csname\??ac\string#1#2\empty\endcsname
   \else\ifcsname\??ac\string#1\string#2\empty\endcsname
     \csname\??ac\string#1\string#2\empty\endcsname
   \fi\fi}

\unexpanded\def\definecharacter#1 #2 %
  {\doifnumberelse{\string#2}
     {\setevalue{\string#1}{\utfchar{#2}}} % or {\expandafter\chardef\csname#1\endcsname#2\relax}
     {\setuvalue{\string#1}{#2}}}

\unexpanded\def\definecommand#1 #2 %
  {\setuvalue{\string#1}{#2}}

%D \macros
%D   {everyuppercase, everylowercase, everysanitize}

\newtoks \everyuppercase
\newtoks \everylowercase
\newtoks \everysanitize

%D Accent handling (try to avoid this):

\newbox\accenttestbox % no longer global so we could use \scratchbox

\def\buildmathaccent#1%
  {\mathaccent#1 }

\unexpanded\def\buildtextaccent#1#2% we could do all at the lua end
  {\begingroup                     % but that's no fun (yet)
   \setbox\accenttestbox\hbox{#1}%
   \scratchcounter\cldcontext{nodes.firstcharinbox(\number\accenttestbox)}\relax
   \ifcase\scratchcounter\else\accent\scratchcounter\fi
   \relax#2%
   \endgroup}

\unexpanded\def\bottomaccent#1#2#3#4#5% down right slantcorrection accent char
  {\dontleavehmode % why this align mess
   \vtop
     {\forgetall
      \baselineskip\zeropoint
      \lineskip#1%
      \everycr\emptytoks
      \tabskip\zeropoint
      \lineskiplimit\zeropoint
      \setbox0\hbox{#4}%
      \halign
        {##\crcr\hbox{#5}\crcr
         \hidewidth
         \hskip#2\wd0
         \hskip-#3\slantperpoint % in plain 1ex * dimenless value
         \vbox to .2ex{\box0\vss}\hidewidth
         \crcr}}}

\unexpanded\def\buildtextmacron     {\bottomaccent{.25ex}{0}{15}{\textmacron}}
\unexpanded\def\buildtextbottomdot  {\bottomaccent{.25ex}{0}{5}{\textbottomdot}}
\unexpanded\def\buildtextcedilla    {\bottomaccent{0ex}{0}{5}{\textcedilla}}
\unexpanded\def\buildtextogonek     {\bottomaccent{-.1ex}{.5}{0}{\textogonek}}
\unexpanded\def\buildtextbottomcomma{\bottomaccent{.15ex}{0}{5}{\tx,}}

\let\d\buildtextbottomdot

\unexpanded\def\topaccent#1#2#3#4#5% down right slantcorrection accent char
  {\dontleavehmode
   \bgroup
     \setbox0\hbox{#4}%
     \setbox2\hbox{#5}%
     \hbox to \wd2 \bgroup
        \hss\copy2\hss
        \hskip-\wd2
        \hss\hskip#2\wd0\hskip-#3\slantperpoint\raise#1\hbox{#4}\hss
     \egroup
   \egroup}

\def\buildtextgrave{\topaccent{0pt}{0}{15}{\textgrave}} % e.g.

\unexpanded\def\definemathaccent#1 #2%
  {\setvalue{#1}{\mathaccent#2 }}

%D Math (will move):

\definemathaccent acute     \mathacute
\definemathaccent grave     \mathgrave
\definemathaccent ddot      \mathddot
\definemathaccent tilde     \mathtilde
\definemathaccent bar       \mathbar
\definemathaccent breve     \mathbreve
\definemathaccent check     \mathcheck
\definemathaccent hat       \mathhat
\definemathaccent vec       \mathvec
\definemathaccent dot       \mathdot
\definemathaccent widetilde \mathwidetilde
\definemathaccent widehat   \mathwidehat

% from enco-com:

\def\AA{Å}  \def\aa{å}
\def\AE{Æ}  \def\ae{æ}
\def\CC{Ç}  \def\cc{ç}
\def \L{Ł}  \def \l{ł}
\def \O{Ø}  \def \o{ø}
\def\OE{Œ}  \def\oe{œ}
\def\SZ{SS} \def\sz{ß} \def\SS{ß}
\def\IJ{IJ}  \def\ij{ij}

% from enco-def:

\def\i{ı}
\def\j{ȷ}

\def\S{§} \def\textS {§} % obsolete (surfaced in bibliographic files)
\def\P{¶} \def\textP {¶} % obsolete (surfaced in bibliographic files)

\def\eszett  {ß} \def\Eszett  {SS} \def\Ssharp{SS}
\def\lslash  {ł} \def\Lslash  {Ł}
\def\dslash  {đ} \def\Dslash  {Đ}
\def\oslash  {ø} \def\Oslash  {Ø}
\def\dcroat  {đ} \def\Dcroat  {Đ}
\def\kcedilla{ķ} \def\Kcedilla{Ķ}
\def\lcedilla{ļ} \def\Lcedilla{Ļ}
\def\ncedilla{ņ} \def\Ncedilla{Ņ}
\def\rcedilla{ŗ} \def\Rcedilla{Ŗ}
\def\aumlaut {ä} \def\Aumlaut {Ä}
\def\eumlaut {ë} \def\Eumlaut {Ë}
\def\iumlaut {ï} \def\Iumlaut {Ï}
\def\oumlaut {ö} \def\Oumlaut {Ö}
\def\uumlaut {ü} \def\Uumlaut {Ü}

% for old times sake (obsolete)

\def\textflorin{ƒ} \def\florin  {ƒ}
\def\pound     {£} \def\sterling{£}
\def\promille  {‰} \def\permille{‰}

% tex specific (obsolete)

\def\procent   {\percent}
\def\dollar    {\textdollar}
\def\permine   {\fakepermine}

% some more

\def\hyphen           {\softhyphen}
\def\compoundwordmark {\hyphen}
\def\cwm              {\hyphen}
\def\nonbreakinghyphen{\hyphen}
\def\breakinghyphen   {\hyphen\prewordbreak}

% quotes

\def\lowerleftsingleninequote  {\quotesinglebase}
\def\lowerleftdoubleninequote  {\quotedblbase}
\def\lowerrightsingleninequote {\quotesinglebase}
\def\lowerrightdoubleninequote {\quotedblbase}

\def\upperleftsingleninequote  {\quoteright}
\def\upperleftdoubleninequote  {\quotedblright}
\def\upperrightsingleninequote {\quoteright}
\def\upperrightdoubleninequote {\quotedblright}

\def\upperleftsinglesixquote   {\quoteleft}
\def\upperleftdoublesixquote   {\quotedblleft}
\def\upperrightsinglesixquote  {\quoteleft}
\def\upperrightdoublesixquote  {\quotedblleft}

\def\leftsubguillemot          {\guilsingleleft}
\def\rightsubguillemot         {\guilsingleright}

% left-overs (some day in private unicode space, so that we can roundtrip)

\unexpanded\def\textblacksquare   {\dontleavehmode\hbox{\vrule\!!width.3\s!em\!!height.4\s!em\!!depth-.1\s!em}}
\unexpanded\def\schwa             {\hbox{\rotate[\c!rotation=180,\c!location=\v!high]{\hbox{e}}}}
\unexpanded\def\schwagrave        {\buildtextgrave\schwa}

\chardef\textcontrolspace"2423

\unexpanded\def\fallbackcontrolspace
 %{\getglyph{ComputerModernMono}\textcontrolspace}
  {\getglyph{LMTypewriter-Regular}\textcontrolspace}

\unexpanded\def\normalcontrolspace
  {\iffontchar\font\textcontrolspace
     \textcontrolspace
   \else
     \fallbackcontrolspace
   \fi}

\let\textvisiblespace\normalcontrolspace

\unexpanded\def\fastcontrolspace % no glyph resolving after first (use grouped)
  {\dofastcontrolspace}

\def\dofastcontrolspace
  {\iffontchar\font\textcontrolspace
     \nofastfallbackcontrolspace
   \else
     \dofastfallbackcontrolspace
   \fi
   \dofastcontrolspace}

\newbox\controlspacebox

\def\nofastfallbackcontrolspace
  {\let\dofastcontrolspace\textcontrolspace}

\def\dofastfallbackcontrolspace
  {\setbox\controlspacebox\hbox{\space}%
   \setbox\controlspacebox\hbox to \wd\controlspacebox{\hss\fallbackcontrolspace\hss}%
   \let\dofastcontrolspace\flushcontrolspacebox}

\def\flushcontrolspacebox
  {\copy\controlspacebox}

% a few defaults (\<whatever>{}), we really need the verbose \empty as it will be
% stringified .. anyhow, we define this at the lua end now but keep it here as a
% reference
%
% \defineaccent ^ {\empty} {\textcircumflex}
% \defineaccent ` {\empty} {\textgrave}
% \defineaccent ~ {\empty} {\texttilde}
% \defineaccent " {\empty} {\textdiaeresis}
% \defineaccent ' {\empty} {\textacute}
% \defineaccent . {\empty} {\textdotaccent}
% \defineaccent = {\empty} {\textmacron}
% \defineaccent c {\empty} {\textcedilla}
% \defineaccent H {\empty} {\texthungarumlaut}
% \defineaccent k {\empty} {\textogonek}
% \defineaccent r {\empty} {\textring}
% \defineaccent u {\empty} {\textbreve}
% \defineaccent v {\empty} {\textcaron}

\ctxlua{characters.tex.defineaccents()}

% from enco-mis:

\def\fakepercent
  {\mathematics{\normalsuperscript{\scriptscriptstyle0}\kern-.25em/\kern-.2em\normalsubscript{\scriptscriptstyle0}}}

\def\fakeperthousand
  {\mathematics{\normalsuperscript{\scriptscriptstyle0}\kern-.25em/\kern-.2em\normalsubscript{\scriptscriptstyle00}}}

\def\fakepermine
  {\dontleavehmode
   \bgroup
   \setbox\scratchbox\hbox
     {\mathematics{+}}%
   \hbox to \wd\scratchbox
     {\hss
      \mathematics{\normalsuperscript{\scriptscriptstyle-}\kern-.4em/\kern-.3em\normalsubscript{\scriptscriptstyle-}}%
      \hss}%
   \egroup}

%D A smaller and bolder variant, more like the math and monospaced ones.

\def\fakeunderscore
  {\relax\ifmmode
     \vrule\!!depth .12\fontexheight\mathstylefont\normalmathstyle\!!width \fontinterwordspace\mathstylefont\normalmathstyle\!!height\zeropoint\relax
   \else
     \dontleavehmode\hbox{\vrule\!!depth .12\fontexheight\font\!!width \fontinterwordspace\font\!!height\zeropoint}%
   \fi}

\def\fakeunderscores{\let\_\fakeunderscore}
\def\textunderscores{\let\_\textunderscore}

\textunderscores

\ifx\mathunderscore\undefined \let\mathunderscore\fakeunderscore \fi
\ifx\textunderscore\undefined \let\textunderscore\fakeunderscore \fi

\unexpanded\def\normalunderscore{\ifmmode\mathunderscore\else\textunderscore\fi}

\let\_\normalunderscore

%D To be sorted out:

\unexpanded\def\textminus
  {\char  \iffontchar\font"2012 "2012 % figuredash
     \else\iffontchar\font"2013 "2013 % endash
     \else\iffontchar\font"2212 "2212 % math minus
                                "002D % hyphen
     \fi\fi\fi}

\unexpanded\def\textplus
  {\char"002B } % plus

%D Moved from core-mis:

\unexpanded\def\celsius   #1{#1\mathematics{^\circ}C}
\unexpanded\def\inch        {\mathematics{\prime\prime}} % was: \hbox{\rm\char125\relax}
\unexpanded\def\fraction#1#2{\mathematics{#1\over#2}}

\def\periodswidth  {.5em}
\def\periodsdefault{3}    % was 5, but now it's like \unknown

\unexpanded\def\periods
  {\dosingleempty\doperiods}

% \def\doperiods[#1]% todo: also n=,width= or maybe just #1,#2
%   {\dontleavehmode
%    \begingroup
%    \scratchdimen\periodswidth
%    \hbox to \iffirstargument#1\else\periodsdefault\fi \scratchdimen
%      {\leaders\hbox to \scratchdimen{\hss.\hss}\hss}%
%    \endgroup}
%
% better for export:

\unexpanded\def\doperiods[#1]% todo: also n=,width= or maybe just #1,#2
  {\dontleavehmode
   \hbox\bgroup
   \setbox\scratchbox\hbox to \periodswidth{\hss.\hss}%
   \dorecurse{\iffirstargument#1\else\periodsdefault\fi}{\copy\scratchbox}%
   \egroup}

\unexpanded\def\unknown
  {\periods\relax} % relax prevents lookahead for []

% Example by Wolfgang Schuster on the context list:
%
% \unexpanded\def\fourdots{{\def\periodswidth{.3em}\periods[4]}}
%
% Hello\fourdots\ World\fourdots \par Hello\fourdots\ World.

\protect \endinput