summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/math-def.mkiv
blob: cc2a8fae6c5bc765c09cc2fdc020e5d968431d93 (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
381
382
383
384
385
386
%D \module
%D   [       file=math-tex,
%D        version=2001.04.12,
%D          title=\CONTEXT\ Math Macros,
%D       subtitle=Definitions,
%D         author={Hans Hagen, Taco Hoekwater \& Aditya Mahajan},
%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.

\writestatus{loading}{ConTeXt Math Macros / Definitions}

\unprotect

% this will be done at the lua end

\startluacode
    mathematics.define(\number\defaultmathfamily)
 -- mathematics.xml.registerentities()
\stopluacode

\activatemathcharacters

% will go to math-ext (if used at all)

\Umathchardef\braceld=0 \defaultmathfamily "FF07A
\Umathchardef\bracerd=0 \defaultmathfamily "FF07B
\Umathchardef\bracelu=0 \defaultmathfamily "FF07C
\Umathchardef\braceru=0 \defaultmathfamily "FF07D

% ctx specific

% \bgroup
% \catcode`|=\othercatcode
% \global\let\|=|
% \egroup

% The \mfunction macro is an alternative for \hbox with a
% controlable font switch.

\definemathcommand [arccos]  [nolop] {\mfunctionlabeltext{arccos}}
\definemathcommand [arcsin]  [nolop] {\mfunctionlabeltext{arcsin}}
\definemathcommand [arctan]  [nolop] {\mfunctionlabeltext{arctan}}
\definemathcommand [arg]     [nolop] {\mfunctionlabeltext{arg}}
\definemathcommand [cosh]    [nolop] {\mfunctionlabeltext{cosh}}
\definemathcommand [cos]     [nolop] {\mfunctionlabeltext{cos}}
\definemathcommand [coth]    [nolop] {\mfunctionlabeltext{coth}}
\definemathcommand [cot]     [nolop] {\mfunctionlabeltext{cot}}
\definemathcommand [csc]     [nolop] {\mfunctionlabeltext{csc}}
\definemathcommand [deg]     [nolop] {\mfunctionlabeltext{deg}}
\definemathcommand [det]     [limop] {\mfunctionlabeltext{det}}
\definemathcommand [dim]     [nolop] {\mfunctionlabeltext{dim}}
\definemathcommand [exp]     [nolop] {\mfunctionlabeltext{exp}}
\definemathcommand [gcd]     [limop] {\mfunctionlabeltext{gcd}}
\definemathcommand [hom]     [nolop] {\mfunctionlabeltext{hom}}
\definemathcommand [inf]     [limop] {\mfunctionlabeltext{inf}}
\definemathcommand [injlim]  [limop] {\mfunctionlabeltext{injlim}}
\definemathcommand [ker]     [nolop] {\mfunctionlabeltext{ker}}
\definemathcommand [lg]      [nolop] {\mfunctionlabeltext{lg}}
\definemathcommand [liminf]  [limop] {\mfunctionlabeltext{liminf}}
\definemathcommand [limsup]  [limop] {\mfunctionlabeltext{limsup}}
\definemathcommand [lim]     [limop] {\mfunctionlabeltext{lim}}
\definemathcommand [ln]      [nolop] {\mfunctionlabeltext{ln}}
\definemathcommand [log]     [nolop] {\mfunctionlabeltext{log}}
\definemathcommand [median]  [limop] {\mfunctionlabeltext{median}}
\definemathcommand [max]     [limop] {\mfunctionlabeltext{max}}
\definemathcommand [min]     [limop] {\mfunctionlabeltext{min}}
\definemathcommand [mod]     [limop] {\mfunctionlabeltext{mod}}
%definemathcommand [div]     [limop] {\mfunctionlabeltext{div}}                              % overloads \div symbol
\definemathcommand [projlim] [limop] {\mfunctionlabeltext{projlim}}
\definemathcommand [Pr]      [limop] {\mfunctionlabeltext{Pr}}
\definemathcommand [sec]     [nolop] {\mfunctionlabeltext{sec}}
\definemathcommand [sinh]    [nolop] {\mfunctionlabeltext{sinh}}
\definemathcommand [sin]     [nolop] {\mfunctionlabeltext{sin}}
\definemathcommand [sup]     [limop] {\mfunctionlabeltext{sup}}
\definemathcommand [tanh]    [nolop] {\mfunctionlabeltext{tanh}}
\definemathcommand [tan]     [nolop] {\mfunctionlabeltext{tan}}

% \definemathcommand [integers]      {{\mathblackboard Z}}
% \definemathcommand [reals]         {{\mathblackboard R}}
% \definemathcommand [rationals]     {{\mathblackboard Q}}
% \definemathcommand [naturalnumbers]{{\mathblackboard N}}
% \definemathcommand [complexes]     {{\mathblackboard C}}
% \definemathcommand [primes]        {{\mathblackboard P}}

\let\normalmatharg\arg % todo: maybe automatically

% using attributes

\setnewconstant\bigmathdelimitermethod\plusone

\def\plainbigdelimiters % traditional method
  {\bigmathdelimitermethod\plustwo}

\plainbigdelimiters % is default for the moment but not so nice

\def\doplainbigmath#1#2%
  {{\hbox{$%
      \nulldelimiterspace\zeropoint\relax
      \mathsurround\zeropoint
  $}}}

\def\doleftbigmath #1{\ifx#1\relax\else\left#1\expandafter\doleftbigmath \fi}
\def\dorightbigmath#1{\ifx#1\relax\else\right.\expandafter\dorightbigmath\fi}

\installcorenamespace{mathbig}

\unexpanded\def\choosemathbig#1#2% so we accent \big{||} as well
  {{\hbox{$%
      \ifcase\bigmathdelimitermethod
        \doleftbigmath#2\relax
        \dorightbigmath#2\relax
      \or
        \attribute\mathsizeattribute#1\relax
        \doleftbigmath#2\relax
        \dorightbigmath#2\relax
      \else
        \doleftbigmath#2\relax
        \vbox to\getvalue{\??mathbig\number#1}\bodyfontsize{}%
        \dorightbigmath#2\relax
      \fi
      \nulldelimiterspace\zeropoint\relax
      \mathsurround\zeropoint
  $}}}

\definemathcommand [big]  {\choosemathbig\plusone  } \setvalue{\??mathbig1}{0.85}
\definemathcommand [Big]  {\choosemathbig\plustwo  } \setvalue{\??mathbig2}{1.15}
\definemathcommand [bigg] {\choosemathbig\plusthree} \setvalue{\??mathbig3}{1.45}
\definemathcommand [Bigg] {\choosemathbig\plusfour } \setvalue{\??mathbig4}{1.75}

\definemathcommand [bigl]  [open]  [one] {\big}
\definemathcommand [bigm]  [rel]   [one] {\big}
\definemathcommand [bigr]  [close] [one] {\big}
\definemathcommand [Bigl]  [open]  [one] {\Big}
\definemathcommand [Bigm]  [rel]   [one] {\Big}
\definemathcommand [Bigr]  [close] [one] {\Big}
\definemathcommand [biggl] [open]  [one] {\bigg}
\definemathcommand [biggm] [rel]   [one] {\bigg}
\definemathcommand [biggr] [close] [one] {\bigg}
\definemathcommand [Biggl] [open]  [one] {\Bigg}
\definemathcommand [Biggm] [rel]   [one] {\Bigg}
\definemathcommand [Biggr] [close] [one] {\Bigg}

%D This needs checking:

\def\setoperatorlimits#1#2% operator limits
  {\savenormalmeaning{#1}%
   \def#1{\csname normal\strippedcsname#1\endcsname#2}}

\setoperatorlimits\int              \intlimits
\setoperatorlimits\iint             \intlimits
\setoperatorlimits\iiint            \intlimits
\setoperatorlimits\oint             \intlimits
\setoperatorlimits\oiint            \intlimits
\setoperatorlimits\oiiint           \intlimits
\setoperatorlimits\intclockwise     \intlimits
\setoperatorlimits\ointclockwise    \intlimits
\setoperatorlimits\ointctrclockwise \intlimits

%D This is a temporary hack until we figure out how to do this correctly,
%D preferably using math parameters but we can also consider doing some
%D node juggling here.

\unexpanded\def\implies  {\mathrel{\;\Longrightarrow\;}}
\unexpanded\def\impliedby{\mathrel{\;\Longleftarrow\;}}
\unexpanded\def\And      {\mathrel{\;\internalAnd\;}}
%unexpanded\def\iff      {\;\Longleftrightarrow\;}
\setuvalue          {iff}{\;\Longleftrightarrow\;} % nicer for if checker

% todo: virtual in math-vfu

% \definemathcommand [mapsto]         {\mapstochar\rightarrow}
% \definemathcommand [hookrightarrow] {\lhook\joinrel\rightarrow}
% \definemathcommand [hookleftarrow]  {\leftarrow\joinrel\rhook}
% \definemathcommand [bowtie]         {\mathrel\triangleright\joinrel\mathrel\triangleleft}
% \definemathcommand [models]         {\mathrel|\joinrel=}
% \definemathcommand [iff]            {\;\Longleftrightarrow\;}

% hm

% ldots = 2026
% vdots = 22EE
% cdots = 22EF
% ddots = 22F1
% udots = 22F0

% \def\PLAINldots{\ldotp\ldotp\ldotp}
% \def\PLAINcdots{\cdotp\cdotp\cdotp}

% \def\PLAINvdots
%   {\vbox{\baselineskip.4\bodyfontsize\lineskiplimit\zeropoint\kern.6\bodyfontsize\hbox{.}\hbox{.}\hbox{.}}}

% \def\PLAINddots
%   {\mkern1mu%
%    \raise.7\bodyfontsize\vbox{\kern.7\bodyfontsize\hbox{.}}%
%    \mkern2mu%
%    \raise.4\bodyfontsize\relax\hbox{.}%
%    \mkern2mu%
%    \raise.1\bodyfontsize\hbox{.}%
%    \mkern1mu}

% \definemathcommand [ldots] [inner]   {\PLAINldots}
% \definemathcommand [cdots] [inner]   {\PLAINcdots}
% \definemathcommand [vdots] [nothing] {\PLAINvdots}
% \definemathcommand [ddots] [inner]   {\PLAINddots}

%D \starttyping
%D $\sqrt[3]{10}$
%D \stoptyping

\def\rootradical{\Uroot \defaultmathfamily "221A } % can be done in char-def

\def\root#1\of{\rootradical{#1}} % #2

\unexpanded\def\sqrt{\doifnextoptionalelse\rootwithdegree\rootwithoutdegree}

\def\rootwithdegree   [#1]{\rootradical{#1}}
\def\rootwithoutdegree    {\rootradical  {}}

\definemathcommand [mathstrut] {\vphantom{(}}
\definemathcommand [joinrel]   {\mathrel{\mkern-3mu}}

\unexpanded\def\{{\mathortext\lbrace\letterleftbrace } % or maybe a chardef
\unexpanded\def\}{\mathortext\rbrace\letterrightbrace} % or maybe a chardef
\unexpanded\def\|{\mathortext\vert  \letterbar       } % or maybe a chardef

%D The following colon related definitions are provided by Aditya
%D Mahajan who derived them from \type {mathtools.sty} and \type
%D {colonequals.sty}.

%D \macros
%D   {centercolon, colonminus, minuscolon, colonequals, equalscolon,
%D    colonapprox, approxcolon, colonsim, simcolon, coloncolon,
%D    coloncolonminus, minuscoloncolon, coloncolonequals,
%D    equalscoloncolon, coloncolonapprox, approxcoloncolon,
%D    colonsim, simcoloncolon}
%D
%D In $a := b$ the colon is not vertically centered with the equal
%D to. Also the distance between colon and equal to is a bit large.
%D So, we define a vertically centered colon \tex {centercolon} and
%D a few macros for colon and double colon relation symbols.
%D
%D \startlines
%D \formula {A \centercolon       B}
%D \formula {A \colonminus        B}
%D \formula {A \minuscolon        B}
%D \formula {A \colonequals       B}
%D \formula {A \equalscolon       B}
%D \formula {A \colonapprox       B}
%D \formula {A \approxcolon       B}
%D \formula {A \colonsim          B}
%D \formula {A \simcolon          B}
%D \formula {A \coloncolon        B}
%D \formula {A \coloncolonminus   B}
%D \formula {A \minuscoloncolon   B}
%D \formula {A \coloncolonequals  B}
%D \formula {A \equalscoloncolon  B}
%D \formula {A \coloncolonapprox  B}
%D \formula {A \approxcoloncolon  B}
%D \formula {A \colonsim          B}
%D \formula {A \simcoloncolon     B}
%D \stoplines

%D The next macros take care of the space between the colon and the
%D relation symbol.

\definemathcommand  [colonsep]        {\mkern-1.2mu}
\definemathcommand  [doublecolonsep]  {\mkern-0.9mu}

%D Now we define all the colon relations .. needs checking with char-def.lua:

\definemathcommand [centercolon]      [rel] {\mathstylevcenteredhbox\colon}
\definemathcommand [colonminus]       [rel] {\centercolon\colonsep\mathrel{-}}
\definemathcommand [minuscolon]       [rel] {\mathrel{-}\colonsep\centercolon}
\definemathcommand [colonequals]      [rel] {\centercolon\colonsep=}
\definemathcommand [equalscolon]      [rel] {=\centercolon\colonsep}
\definemathcommand [colonapprox]      [rel] {\centercolon\colonsep\approx}
\definemathcommand [approxcolon]      [rel] {\approx\centercolon\colonsep}
\definemathcommand [colonsim]         [rel] {\centercolon\colonsep\sim}
\definemathcommand [simcolon]         [rel] {\sim\centercolon\colonsep}

\definemathcommand [coloncolon]       [rel] {\centercolon\doublecolonsep\centercolon}
\definemathcommand [coloncolonminus]  [rel] {\coloncolon\colonsep\mathrel{-}}
\definemathcommand [minuscoloncolon]  [rel] {\mathrel{-}\colonsep\coloncolon}
\definemathcommand [coloncolonequals] [rel] {\coloncolon\colonsep=}
\definemathcommand [equalscoloncolon] [rel] {=\coloncolon\colonsep}
\definemathcommand [coloncolonapprox] [rel] {\coloncolon\colonsep\approx}
\definemathcommand [approxcoloncolon] [rel] {\approx\coloncolon\colonsep}
\definemathcommand [colonsim]         [rel] {\coloncolon\colonsep\sim}
\definemathcommand [simcoloncolon]    [rel] {\sim\coloncolon\colonsep}

%D Goodies. We might move this elsewhere.

% Be careful in choosing what accents you take (the code below uses a
% combining one):
%
% \startbuffer
% % $\Umathaccent top        0 0 "20D7 {example}$
% % $\Umathaccent top  fixed 0 0 "20D7 {example}$
% $\Umathaccent              0 0 "20D7 {example}$
% $\Umathaccent        fixed 0 0 "20D7 {example}$
% $\Umathaccent bottom       0 0 "20D7 {example}$
% $\Umathaccent bottom fixed 0 0 "20D7 {example}$
% $\Umathaccent both         0 0 "20D7
%                            0 0 "20D7 {example}$
% $\Umathaccent both fixed   0 0 "20D7
%                    fixed   0 0 "20D7 {example}$
% $\Umathaccent both         0 0 "20D7
%                    fixed   0 0 "20D7 {example}$
% $\Umathaccent both fixed   0 0 "20D7
%                            0 0 "20D7 {example}$
% \stopbuffer
%
% \setupbodyfont[modern]  \getbuffer
% \setupbodyfont[xits]    \getbuffer
% \setupbodyfont[cambria] \getbuffer

\unexpanded\def\underleftarrow #1{\mathop{\Uunderdelimiter \defaultmathfamily "2190 {#1}}}
\unexpanded\def\overleftarrow  #1{\mathop{\Uoverdelimiter  \defaultmathfamily "2190 {#1}}}
\unexpanded\def\underrightarrow#1{\mathop{\Uunderdelimiter \defaultmathfamily "2192 {#1}}}
\unexpanded\def\overrightarrow #1{\mathop{\Uoverdelimiter  \defaultmathfamily "2192 {#1}}}

% watch out: here we have a class (zero):

\unexpanded\def\normaldoublebrace {\Umathaccents 0 \defaultmathfamily "23DE 0 \defaultmathfamily "23DF }
\unexpanded\def\normaldoubleparent{\Umathaccents 0 \defaultmathfamily "23DC 0 \defaultmathfamily "23DD }

% let's keep this

\def\Umathbotaccent{\Umathaccent \s!bottom }
\def\Umathaccents  {\Umathaccent \s!both   }

\let\normaloverbrace      \overbrace
\let\normalunderbrace     \underbrace
\let\normaloverparent     \overparent
\let\normalunderparent    \underparent
\let\normaloverbracket    \overbracket
\let\normalunderbracket   \underbracket
\let\normalunderleftarrow \underleftarrow
\let\normaloverleftarrow  \overleftarrow
\let\normalunderrightarrow\underrightarrow
\let\normaloverrightarrow \overrightarrow

\unexpanded\def\mathopwithlimits#1#2{\mathop{#1{#2}}\limits}
\unexpanded\def\stackrel        #1#2{\mathrel{\mathop{#2}\limits^{#1}}}

\unexpanded\def\overbrace      {\mathopwithlimits\normaloverbrace      }
\unexpanded\def\underbrace     {\mathopwithlimits\normalunderbrace     }
\unexpanded\def\doublebrace    {\mathopwithlimits\normaldoublebrace    }
\unexpanded\def\overparent     {\mathopwithlimits\normaloverparent     }
\unexpanded\def\underparent    {\mathopwithlimits\normalunderparent    }
\unexpanded\def\overbracket    {\mathopwithlimits\normaloverbracket    }
\unexpanded\def\underbracket   {\mathopwithlimits\normalunderbracket   }
\unexpanded\def\doubleparent   {\mathopwithlimits\normaldoubleparent   }
\unexpanded\def\underleftarrow {\mathopwithlimits\normalunderleftarrow }
\unexpanded\def\overleftarrow  {\mathopwithlimits\normaloverleftarrow  }
\unexpanded\def\underrightarrow{\mathopwithlimits\normalunderrightarrow}
\unexpanded\def\overrightarrow {\mathopwithlimits\normaloverrightarrow }

\let\lceil \lceiling
\let\rceil \rceiling

\let\normalsurd\surd

\unexpanded\def\surd{\normalsurd{}}

% Some special characters:

\unexpanded\def\nabla{∇} % this one adapts

%
% todo mathclass=punctuation ord

% \Umathcode"02C="6 \defaultmathfamily "02C
% \Umathcode"02E="0 \defaultmathfamily "02E

% tricky .. todo

% \appendtoks
%     \def\over{\primitive\over}%
% \to \everymathematics

\protect \endinput