summaryrefslogtreecommitdiff
path: root/tex/context/base/math-ini.tex
blob: 1a86aeac42d212d3fe12063cc51758fbe7a67334 (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
%D \module
%D   [       file=math-ini,
%D        version=2001.04.12, 
%D          title=\CONTEXT\ Math Macros,
%D       subtitle=Basic Macros, 
%D         author={Hans Hagen \& Taco Hoekwater},
%D           date=\currentdate,
%D      copyright=\PRAGMA]
%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 module provides namespaces for math fonts, thereby
%D permitting mixed usage of math fonts. Although not strictly
%D needed, we also provide a family name mapping mechanism as
%D used in the (original) AMS math definition files, but here
%D these names can recursively be remapped and if needed,
%D dynamically be changed. We've tried to minimize the number
%D of definition commands and use plain \TEX\ definitions as
%D fallback. We've tried to follow a couple of conventions
%D from plain and AMS math in order to achieve backward
%D compatinility. We also kept an eye on future usage of these
%D modules in the perspective of MathML and unicode fonts. 

\unprotect

\def\@mt@{@mt@} % math token
\def\@mt@{@mc@} % math character 
\def\@mh@{@mh@} % math handler
\def\@mf@{@mf@} % math family
\def\@mc@{@mc@} % math class
\def\@ml@{@mc@} % math list 

\def\@@mathlimopcomm#1{\mathop{#1}\limits}
\def\@@mathnolopcomm#1{\mathop{#1}\nolimits}
\def\@@mathboxcomm  #1{\leavevmode\hbox{$\m@th#1$}}

\chardef\mathordcode    = 0  \let\mathordcomm     \mathord
\chardef\mathopcode     = 1  \let\mathopcomm      \mathop 
\chardef\mathbincode    = 2  \let\mathbincomm     \mathbin 
\chardef\mathrelcode    = 3  \let\mathrelcomm     \mathrel
\chardef\mathopencode   = 4  \let\mathopencomm    \mathopen 
\chardef\mathclosecode  = 5  \let\mathclosecomm   \mathclose 
\chardef\mathpunctcode  = 6  \let\mathpunctcomm   \mathpunct 
\chardef\mathalphacode  = 7  \let\mathalphacomm   \firstofoneargument
\chardef\mathinnercode  = 0  \let\mathinnercomm   \mathinner
\chardef\mathnothingcode= 0  \let\mathnothingcomm \firstofoneargument
\chardef\mathlimopcode  = 1  \let\mathlimopcomm   \@@mathlimopcomm  
\chardef\mathnolopcode  = 1  \let\mathnolopcomm   \@@mathnolopcomm  
\chardef\mathchoicecode = 0  \let\mathchoicecomm  \@@mathchoicecomm  
\chardef\mathboxcode    = 0  \let\mathboxcomm     \@@mathboxcomm  

\chardef\mathaccentcode = 8
\chardef\mathradicalcode= 9

\def\@@mathchoicecomm#1{[todo #1]}

\def\puremathcode#1{\the\csname math#1code\endcsname}
\def\puremathcomm#1{\csname     math#1comm\endcsname}

\newif\iftracemathcollection

\beginETEX \ifcsname

\def\dohandlemathtoken#1%
  {\csname\@mt@
     \ifcsname\@mt@\mathcollection#1\endcsname
       \mathcollection
     \else\ifcsname\@mt@\nomathcollection#1\endcsname
       \nomathcollection
     \fi\fi
   #1\endcsname}

\endETEX

\beginTEX 

\def\dohandlemathtoken#1%
  {\csname\@mt@
     \@EA\ifx\csname\@mt@\mathcollection#1\endcsname\relax
       \@EA\ifx\csname\@mt@\nomathcollection#1\endcsname\relax 
       \else
         \nomathcollection
       \fi
     \else
       \mathcollection
     \fi
   #1\endcsname}

\endTEX

\def\definefamilysynonym%
  {\dotripleempty\dodefinefamilysynonym}

\def\dodefinefamilysynonym[#1][#2][#3]% [mathcollection] [] []
  {\ifthirdargument
     \setvalue{\@mf@#1#2}{#3}%
   \else
     \setvalue{\@mf@  #1}{#2}%
   \fi}

\def\purefamily   #1{\csname    \truefamily{#1}\s!fam\endcsname}
\def\purefamilyhex#1{\csname hex\truefamily{#1}\s!fam\endcsname}

\beginETEX \ifcsname

\def\truefamily#1%
  {\ifcsname\@mf@\mathcollection#1\endcsname
     \@EA\truefamily\csname\@mf@\mathcollection#1\endcsname
   \else\ifcsname\@mf@#1\endcsname
     \@EA\truefamily\csname\@mf@#1\endcsname
   \else\ifcsname\@mf@\nomathcollection#1\endcsname
     \@EA\truefamily\csname\@mf@\nomathcollection#1\endcsname
   \else
     #1%
   \fi\fi\fi}

\endETEX

\beginTEX

\def\truefamily#1%
  {\@EA\ifx\csname\@mf@\mathcollection#1\endcsname\relax
     \@EA\ifx\csname\@mf@#1\endcsname\relax
       \@EA\ifx\csname\@mf@\nomathcollection#1\endcsname\relax
         #1%
       \else
         \@EA\truefamily\csname\@mf@\nomathcollection#1\endcsname
       \fi
     \else
       \@EA\truefamily\csname\@mf@#1\endcsname
     \fi
   \else
     \@EA\truefamily\csname\@mf@\mathcollection#1\endcsname
   \fi}

\endTEX

\newif\ifdynamicmathfamilies \dynamicmathfamiliesfalse % true ? 

\let\normalpurefamilyhex\purefamilyhex

% todo: reset collection (tok legen) en opnieuw laden met true 

\def\definemathsymbol%
  {\dosixtupleempty\dodefinemathsymbol}

\def\dodefinemathsymbol[#1][#2][#3][#4][#5][#6]%
  {\unexpanded\setgvalue{#1}{\dohandlemathtoken{#1}}%
   \ifdynamicmathfamilies \let\purefamilyhex\relax \fi
   \setevalue{\@mt@\mathcollection#1}%
     {\ifsixthargument
        \ifnum\puremathcode{#2}=\mathradicalcode
          \radical"%
        \else
          \delimiter"%
          \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
        \fi
        \purefamilyhex{#3}\uchexnumbers{#4}%
        \purefamilyhex{#5}\uchexnumbers{#6}\space
      \else\iffourthargument
        \ifnum\puremathcode{#2}=\mathaccentcode
          \mathaccent\else\mathchar
        \fi 
       "\ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
        \purefamilyhex{#3}\uchexnumbers{#4}\space
      \fi\fi}%
   \let\purefamilyhex\normalpurefamilyhex
   \tracemathsymbol{#1}}

\def\tracemathsymbol#1%
  {\iftracemathcollection
     {\endgraf
      \hbox{\tex{#1}~:~{\mathematics{\getvalue{#1}{}}}}
      \endgraf}%
   \fi}

\def\definemathcharacter%
  {\dosixtupleempty\dodefinemathcharacter}

\def\dodefinemathcharacter[#1][#2][#3][#4][#5][#6]%
  {\setmathtoks
   \ifdynamicmathfamilies \let\purefamilyhex\relax \fi
   \doifnumberelse{#1}
     {\scratchcounter=#1}
     {\scratchcounter=\@EA`\string#1}%
   \expanded
     {\appendtoks
        \ifsixthargument
          \delcode\the\scratchcounter="%
            \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
            \purefamilyhex{#3}\uchexnumbers{#4}%
            \purefamilyhex{#5}\uchexnumbers{#6}\space
        \else\iffourthargument
          \mathcode\the\scratchcounter="%
            \ifnum\puremathcode{#2}>7 0\else\puremathcode{#2}\fi
            \purefamilyhex{#3}\uchexnumbers{#4}\space
        \fi\fi
        \noexpand\to \noexpand\mathtoks}%
   \let\purefamilyhex\normalpurefamilyhex
   \tracemathcharacter{#1}}

\def\tracemathcharacter#1%
  {\iftracemathcollection
     {\endgraf
      \doifnumberelse{#1}
        {\hbox{\tttf\rawcharacter{#1}~:~{\mathematics{\rawcharacter{#1}}}}}
        {\hbox{\type{#1}~:~{\mathematics{#1}}}}
      \endgraf}%
   \fi}

\def\definemathcommand%
  {\dodoubleempty\dodefinemathcommand}

\def\dodefinemathcommand[#1][#2]#3%
  {\unexpanded\setgvalue{#1}{\dohandlemathtoken{#1}}%
   \ifsecondargument
     \setvalue{\@mt@\mathcollection#1}{\puremathcomm{#2}{#3}}%
   \else
     \setvalue{\@mt@\mathcollection#1}{\puremathcomm{nothing}{#3}}%
   \fi
   \tracemathcommand{#1}}

\def\tracemathcommand#1%
  {\iftracemathcollection
     \endgraf
     \hbox{\tex{#1}~:~{\mathematics{\getvalue{#1}{}}}}
     \endgraf
   \fi}

\def\startmathcollection[#1]%
  {\pushmacro\mathcollection
   \setmathcollection{#1}}

\def\setmathcollection#1%
  {\def\mathcollection{#1}%
   \doifundefined{\@ml@\mathcollection}
     {\expandafter\newtoks\csname\@ml@\mathcollection\endcsname}}

\def\stopmathcollection%
  {\popmacro\mathcollection}

\def\startrawmathcollection%
  {\pushmacro\iftracemathcollection
   \tracemathcollectionfalse
   \startmathcollection}

\def\stoprawmathcollection%
  {\popmacro\iftracemathcollection
   \stopmathcollection}

\newtoks\mathtoks

\def\setmathtoks%
  {\@EA\let\@EA\mathtoks\csname\@ml@\mathcollection\endcsname}

\def\currentmathcollection{\mathcollection}

\def\nomathcollection{\s!default}

\def\enablemathcollection[#1]%
  {\doifnot{#1}{\s!default}
     {\setmathcollection\s!default
      \the\csname\@ml@\mathcollection\endcsname}%
   \setmathcollection{#1}%
   \the\csname\@ml@\mathcollection\endcsname}

% hook 'm into the font mechanism 

\definefilesynonym[\f!mathprefix\s!default][\f!mathprefix tex]

\def\usemathcollection[#1]%
  {\doinputonce{\truefilename{\f!mathprefix#1}}%
   \setvalue{\@mc@\fontclass\@mc@}{#1}}

\def\autoenablemathcollection%
  {\doifdefinedelse{\@mc@\fontclass\@mc@}
     {\enablemathcollection[\getvalue{\@mc@\fontclass\@mc@}]}
     {\enablemathcollection[\s!default]}}

\appendtoks\autoenablemathcollection\to\mathstrategies

\edef\hexmrfam {0} \edef\hexbsfam {8}
\edef\hexmifam {1} \edef\hexbifam {9}
\edef\hexsyfam {2} \edef\hexscfam {A}
\edef\hexexfam {3} \edef\hextffam {B}
\edef\hexitfam {4} \edef\hexmafam {C}
\edef\hexslfam {5} \edef\hexmbfam {D}
\edef\hexbffam {6} \edef\hexmcfam {E}
\edef\hexnnfam {7} \edef\hexmdfam {F}

\definefamilysynonym [default] [letters]   [mr]
\definefamilysynonym [default] [operators] [sy]
\definefamilysynonym [default] [lcgreek]   [mi]
\definefamilysynonym [default] [ucgreek]   [mr]
\definefamilysynonym [default] [vargreek]  [mi]
\definefamilysynonym [default] [mitfamily] [mi]
\definefamilysynonym [default] [calfamily] [sy]

\definefamilysynonym [default] [0] [mr]
\definefamilysynonym [default] [1] [mi]
\definefamilysynonym [default] [2] [sy]
\definefamilysynonym [default] [3] [ex]

\enablemathcollection[default]

\usemathcollection[default]

\protect \endinput

\tracemathcollectiontrue 

                                               \input math-tex \page
\setupbodyfont[ams] \enablemathcollection[ams] \input math-ams \page
\setupbodyfont[lbr] \enablemathcollection[lbr] \input math-lbr \page
\setupbodyfont[eul] \enablemathcollection[eul] \input math-eul \stoptext


% to be checked

\def\defineactivecharacter #1 #2%
  {\scratchcounter=\the\uccode`~
   \expandafter\doifnumberelse\expandafter{\string#1}
     {\catcode #1=\@@active \uccode`~= #1\relax}
     {\catcode`#1=\@@active \uccode`~=`#1\relax}%
   \uppercase{\def\next{~}}%
  % unexpanded goes wrong in pdfdoc
  %\expandafter\unexpanded\expandafter\def\next{#2}%
  % better
  %\expandafter\def\next{#2}%
  % math aware
   \expandafter\def\next{\dohandleactivecharacter{#1}{#2}}% new
   \uccode`~=\scratchcounter}

\def\dohandleactivecharacter%
  {\ifmmode
     \expandafter\dohandleactivemathcharacter
   \else
     \expandafter\secondoftwoarguments
   \fi}

\let\dohandleactivemathcharacter\secondoftwoarguments

\def\dohandleactivemathcharacter#1#2%
  {\ifundefined{@ma@\string#1}
     \expandafter\firstofoneargument
   \else
     \getvalue{@ma@\string#1}%
     \expandafter\gobbleoneargument
   \fi{#2}}