math-lop.mkxl /size: 13 Kb    last modification: 2025-02-21 11:03
1%D \module
2%D   [       file=math-lop,
3%D        version=2022.02.10,
4%D          title=\CONTEXT\ Math Macros,
5%D       subtitle=Large operators,
6%D         author={Hans Hagen & Mikael Sundqvist},
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\writestatus{loading}{ConTeXt Math Macros / Large Operators}
15
16% $\textstyle        \Uoperator          \Udelimiter "0 \fam "222B {t} {b} {x}$\blank
17% $\textstyle        \Uoperator          \Udelimiter "0 \fam "222B {t} {b} {\frac{1}{x}}$\blank
18% $\displaystyle x + \Uoperator          \Udelimiter "0 \fam "222B {t} {b} {\frac{1}{x}}$\blank
19% $              x + \Uoperator nolimits \Udelimiter "0 \fam "222B {t} {b} {\frac{1}{x}}$\blank
20% $              x + \Uoperator limits   \Udelimiter "0 \fam "222B {t} {b} {\frac{1}{x}}$\blank
21
22\unprotect
23
24\installcorenamespace{mathoperators}
25\installcorenamespace{mathoperatormethod}
26
27\mathlimitsmode\plusone % make long script look right ... font dependent!
28
29\installcommandhandler \??mathoperators {mathoperator} \??mathoperators
30
31\setupmathoperator
32  [\c!left=\zerocount,
33   \c!mathclass=\mathoperatorcode,
34   \c!bottomcolor=\mathoperatorparameter\c!numbercolor,
35   \c!topcolor=\mathoperatorparameter\c!numbercolor,
36   \c!textcolor=\mathoperatorparameter\c!color,
37   \c!numbercolor=\mathoperatorparameter\c!color,
38   \c!symbolcolor=\mathoperatorparameter\c!color]
39
40\aliased\let\setupmathoperators\setupmathoperator
41
42\appendtoks
43    % todo: only define when there's left or right
44    \protected\instance\edefcsname\currentmathoperator\endcsname{\math_operator{\currentmathoperator}}%
45    % todo: under definition control
46    \protected\instance\edefcsname\e!start\currentmathoperator\endcsname{\math_operator_start{\currentmathoperator}}%
47    \protected\instance\edefcsname\e!stop \currentmathoperator\endcsname{\math_operator_stop}%
48\to \everydefinemathoperator
49
50% more generic:
51
52\defcsname\??mathoperatormethod\v!horizontal\endcsname{nolimits }
53\defcsname\??mathoperatormethod\v!vertical  \endcsname{limits }
54
55% The ones we wlready had:
56
57\letcsname\??mathoperatormethod    \v!auto\endcsname\empty
58\letcsname\??mathoperatormethod autolimits\endcsname\empty
59\letcsname\??mathoperatormethod   nolimits\expandafter\endcsname\csname\??mathoperatormethod\v!horizontal\endcsname
60\letcsname\??mathoperatormethod     limits\expandafter\endcsname\csname\??mathoperatormethod\v!vertical  \endcsname
61
62%D With the auto option DisplayOperatorMinHeight will kick in unless we explicitly set the size or
63%D use the start|-|stop variant (which will size automatically). The default of this font parameter
64%D are a bit on the small size which doesn't work well with fonts other than Latin Modern that has
65%D a large one. Keep in mind that we have e.g. integrals as operators and not fixed characters.
66
67\installlocalcurrenthandler\??mathoperators {mathoperator}
68
69\protected\def\math_operator_common#1#2%
70  {\setlocalmathoperatorcurrent{#1}% \edef\currentmathoperator{#1}%
71   \setupcurrentmathoperator[#2]%
72   \scratchclass\mathcodechecked{\mathoperatorparameter\c!mathclass}\relax
73   \Uoperator
74     \usedcolorparameterattributes{\mathoperatorparameter\c!symbolcolor}%
75     \begincsname\??mathoperatormethod\mathoperatorparameter\c!method\endcsname
76     \ifchkdimension\mathoperatorparameter\c!size\or
77       \s!depth \lastchkdimension
78       \s!height\lastchkdimension
79       \s!axis   % variants
80       \s!noaxis % extensibles (assumes also axis)
81       \s!exact  % make sure we don't overshoot when there are no variants and extensibles
82     \orelse\ifcstok{\mathoperatorparameter\c!size}\v!auto
83       \s!auto
84     \fi
85     \s!class \scratchclass
86   % \s!attr \indexofregister \c_attr_mathsize \attributeunsetvalue
87     % todo: find a way to pick up or pass sup/sub to here
88     \Umathchar \scratchclass \fam \mathoperatorparameter\c!left
89     {\edef\m_operator_text{\mathoperatorparameter\c!top}%
90      \ifempty\m_operator_text\else
91         \mathstrut % todo: make option
92         \usemathoperatorcolorparameter\c!topcolor
93         \m_operator_text
94      \fi}%
95     {\edef\m_operator_text{\mathoperatorparameter\c!bottom}%
96      \ifempty\m_operator_text\else
97         \mathstrut % todo: make option
98         \usemathoperatorcolorparameter\c!bottomcolor
99         \m_operator_text
100      \fi}%
101    \usemathoperatorcolorparameter\c!textcolor}
102
103\tolerant\protected\def\math_operator#1#*[#S#2]#*#:#=% mandate braces
104  {\math_operator_common{#1}{#2}#3\Uright \s!rightclass \mathintegralcode .}
105
106\tolerant\protected\def\math_operator_start#1#*[#S#2]%
107  {\math_operator_common{#1}{#2}}
108
109\protected\def\math_operator_stop
110  {\Uright \s!rightclass \mathintegralcode .}
111% {\Uright \s!rightclass \mathintegralcode \Umathchar\zerocount \fam \zerocount }
112
113% \def\math_operator_default_size % is now the auto option
114%   {\ifconditional\indisplaymath\ifcase\Umathoperatorsize=\maxdimen\else
115%      \Umathoperatorsize\displaystyle
116%    \fi\fi}
117
118% TODO: Add 4 (inherited) classes and then define them automatically from char-def
119% instead.
120
121\definemathoperator [integrals]
122\definemathoperator [summations]
123\definemathoperator [products]
124\definemathoperator [operators]
125
126\setupmathoperators [summations] [\c!size=\v!auto]
127\setupmathoperators [products]   [\c!size=\v!auto]
128\setupmathoperators [operators]  [\c!size=\v!auto]
129
130\setupmathoperators [integrals]
131  [\c!size=\v!auto,
132   \c!mathclass=\mathintegralcode,
133   \c!method=\mathematicsparameter\c!integral] % cf Mikael's wish
134
135\setupmathematics[\c!integral=nolimits]
136
137\definemathoperator [integral]    [integrals]  [\c!left="222B] % these might go unless we decide
138\definemathoperator [iintegral]   [integrals]  [\c!left="222C] % to have verbose parents but who
139\definemathoperator [iiintegral]  [integrals]  [\c!left="222D] % will use them
140\definemathoperator [iiiintegral] [integrals]  [\c!left="2A0C]
141
142\definemathoperator [int]        [integrals]  [\c!left="222B] %                          INTEGRAL
143\definemathoperator [iint]       [integrals]  [\c!left="222C] %                DOUBLE    INTEGRAL
144\definemathoperator [iiint]      [integrals]  [\c!left="222D] %                TRIPLE    INTEGRAL
145\definemathoperator [iiiint]     [integrals]  [\c!left="2A0C] %                QUADRUPLE INTEGRAL OPERATOR
146\definemathoperator [oint]       [integrals]  [\c!left="222E] %                CONTOUR   INTEGRAL
147\definemathoperator [oiint]      [integrals]  [\c!left="222F] %                SURFACE   INTEGRAL
148\definemathoperator [oiiint]     [integrals]  [\c!left="2230] %                VOLUME    INTEGRAL
149\definemathoperator [intc]       [integrals]  [\c!left="2231] %      CLOCKWISE           INTEGRAL
150\definemathoperator [ointc]      [integrals]  [\c!left="2232] %      CLOCKWISE CONTOUR   INTEGRAL
151\definemathoperator [aointc]     [integrals]  [\c!left="2233] % ANTI CLOCKWISE CONTOUR   INTEGRAL
152
153\definemathoperator [sumint]                [integrals]  [\c!left="2A0B] % Integral with sum
154\definemathoperator [barint]                [integrals]  [\c!left="2A0D] % Integral with bar
155\definemathoperator [doublebarint]          [integrals]  [\c!left="2A0E] % Integral with double bar
156\definemathoperator [slashint]              [integrals]  [\c!left="2A0F] % Integral with slash
157\definemathoperator [aodownintc]            [integrals]  [\c!left="2A11]
158\definemathoperator [rectangularpoleintc]   [integrals]  [\c!left="2A12]
159\definemathoperator [semicirclepoleintc]    [integrals]  [\c!left="2A13]
160\definemathoperator [circlepoleoutsideintc] [integrals]  [\c!left="2A14]
161\definemathoperator [circlepoleinsideintc]  [integrals]  [\c!left="2A15]
162\definemathoperator [squareintc]            [integrals]  [\c!left="2A16]
163\definemathoperator [hookleftarrowint]      [integrals]  [\c!left="2A17]
164\definemathoperator [timesint]              [integrals]  [\c!left="2A18]
165\definemathoperator [capint]                [integrals]  [\c!left="2A19]
166\definemathoperator [cupint]                [integrals]  [\c!left="2A1A]
167\definemathoperator [upperint]              [integrals]  [\c!left="2A1B]
168\definemathoperator [lowerint]              [integrals]  [\c!left="2A1C]
169
170\definemathoperator [sum]           [summations] [\c!left="2211] % N-ARY SUMMATION
171\definemathoperator [blackboardsum] [summations] [\c!left="2140] % blackboard summation
172\definemathoperator [modtwosum]     [summations] [\c!left="2A0A] % modulo two summation
173
174
175\definemathoperator [prod]       [products]   [\c!left="220F] % N-ARY PRODUCT
176\definemathoperator [coprod]     [products]   [\c!left="2210] % N-ARY COPRODUCT
177
178% todo: middles too
179
180\definemathoperator [bigwedge]   [operators]  [\c!left="22C0] %  N-ARY LOGICAL AND
181\definemathoperator [bigvee]     [operators]  [\c!left="22C1] %  N-ARY LOGICAL OR
182\definemathoperator [bigcap]     [operators]  [\c!left="22C2] %  N-ARY LOGICAL INTERSECTION
183\definemathoperator [bigcup]     [operators]  [\c!left="22C3] %  N-ARY         UNION
184\definemathoperator [bigodot]    [operators]  [\c!left="2A00] %  N-ARY CIRCLED DOT          OPERATOR
185\definemathoperator [bigoplus]   [operators]  [\c!left="2A01] %  N-ARY CIRCLED PLUS         OPERATOR
186\definemathoperator [bigotimes]  [operators]  [\c!left="2A02] %  N-ARY CIRCLED TIMES        OPERATOR
187\definemathoperator [bigudot]    [operators]  [\c!left="2A03] %  N-ARY         UNION        OPERATOR WITH DOT
188\definemathoperator [biguplus]   [operators]  [\c!left="2A04] %  N-ARY         UNION        OPERATOR WITH PLUS
189\definemathoperator [bigsqcap]   [operators]  [\c!left="2A05] %  N-ARY SQUARE  INTERSECTION OPERATOR
190\definemathoperator [bigsqcup]   [operators]  [\c!left="2A06] %  N-ARY SQUARE  UNION        OPERATOR
191\definemathoperator [bigtimes]   [operators]  [\c!left="2A09] %  N-ARY         TIMES        OPERATOR
192
193\definemathoperator [leftouterjoin]     [operators]  [\c!left="27D5] % left outer join
194\definemathoperator [rightouterjoin]    [operators]  [\c!left="27D6] % right outer join
195\definemathoperator [fullouterjoin]     [operators]  [\c!left="27D7] % full outer join
196\definemathoperator [bigbottom]         [operators]  [\c!left="27D8] % big bottom
197\definemathoperator [bigtop]            [operators]  [\c!left="27D9] % big top
198\definemathoperator [bigsolidus]        [operators]  [\c!left="29F8] % big solidus
199\definemathoperator [bigreversesolidus] [operators]  [\c!left="29F9] % big reverse solidus
200\definemathoperator [bigdoublewedge]    [operators]  [\c!left="2A07] % big double wedge
201\definemathoperator [bigdoublevee]      [operators]  [\c!left="2A08] % big double vee
202
203
204%D \im{∫_ 2 \neq ∑_3 \neq ∑^3 \neq ∏_4^5 \neq ∏_4}\blank
205%D \dm{∫_ 2 \neq ∑_3 \neq ∑^3 \neq ∏_4^5 \neq ∏_4}\blank
206
207% \amcode`∫ \activecatcode \letcharcode`∫ \int
208% \amcode`∑ \activecatcode \letcharcode`∑ \sum
209% \amcode`∏ \activecatcode \letcharcode`∏ \prod
210
211\permanent\protected\def\registermathsymbolcommand
212  {\afterassignment\math_register_symbol_command\scratchcounter}
213
214\def\math_register_symbol_command
215  {\amcode\scratchcounter\activecatcode
216   \letcharcode\scratchcounter}
217
218\registermathsymbolcommand "222B \int
219\registermathsymbolcommand "222C \iint
220\registermathsymbolcommand "222D \iiint
221\registermathsymbolcommand "2A0C \iiiint
222\registermathsymbolcommand "222E \oint
223\registermathsymbolcommand "222F \oiint
224\registermathsymbolcommand "2230 \oiiint
225\registermathsymbolcommand "2231 \intc
226\registermathsymbolcommand "2232 \ointc
227\registermathsymbolcommand "2233 \aointc
228
229\registermathsymbolcommand "2A0B \sumint
230\registermathsymbolcommand "2A0D \barint
231\registermathsymbolcommand "2A0E \doublebarint
232\registermathsymbolcommand "2A0F \slashint
233\registermathsymbolcommand "2A11 \aodownintc
234\registermathsymbolcommand "2A12 \rectangularpoleintc
235\registermathsymbolcommand "2A13 \semicirclepoleintc
236\registermathsymbolcommand "2A14 \circlepoleoutsideintc
237\registermathsymbolcommand "2A15 \circlepoleinsideintc
238\registermathsymbolcommand "2A16 \squareintc
239\registermathsymbolcommand "2A17 \hookleftarrowint
240\registermathsymbolcommand "2A18 \timesint
241\registermathsymbolcommand "2A19 \capint
242\registermathsymbolcommand "2A1A \cupint
243\registermathsymbolcommand "2A1B \upperint
244\registermathsymbolcommand "2A1C \lowerint
245
246\registermathsymbolcommand "2211 \sum
247\registermathsymbolcommand "2140 \blackboardsum
248\registermathsymbolcommand "2A0A \modtwosum
249
250\registermathsymbolcommand "220F \prod
251\registermathsymbolcommand "2210 \coprod
252
253\registermathsymbolcommand "22C0 \bigwedge
254\registermathsymbolcommand "22C1 \bigvee
255\registermathsymbolcommand "22C2 \bigcap
256\registermathsymbolcommand "22C3 \bigcup
257\registermathsymbolcommand "2A00 \bigodot
258\registermathsymbolcommand "2A01 \bigoplus
259\registermathsymbolcommand "2A02 \bigotimes
260\registermathsymbolcommand "2A03 \bigudot
261\registermathsymbolcommand "2A04 \biguplus
262\registermathsymbolcommand "2A05 \bigsqcap
263\registermathsymbolcommand "2A06 \bigsqcup
264\registermathsymbolcommand "2A09 \bigtimes
265
266\registermathsymbolcommand "27D5 \leftouterjoin
267\registermathsymbolcommand "27D6 \rightouterjoin
268\registermathsymbolcommand "27D7 \fullouterjoin
269\registermathsymbolcommand "27D8 \bigbottom
270\registermathsymbolcommand "27D9 \bigtop
271\registermathsymbolcommand "29F8 \bigsolidus
272\registermathsymbolcommand "29F9 \bigreversesolidus
273\registermathsymbolcommand "2A07 \bigdoublewedge
274\registermathsymbolcommand "2A08 \bigdoublevee
275
276\protect \endinput
277