math-lop.mkxl /size: 9 Kb    last modification: 2024-01-16 10:22
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
28
29\installcommandhandler \??mathoperators {mathoperator} \??mathoperators
30
31\setupmathoperator
32  [\c!left=\zerocount,
33   \c!mathclass=\mathoperatorcode]
34
35\aliased\let\setupmathoperators\setupmathoperator
36
37\appendtoks
38    % todo: only define when there's left or right
39    \protected\instance\edefcsname\currentmathoperator\endcsname{\math_operator{\currentmathoperator}}%
40    % todo: under definition control
41    \protected\instance\edefcsname\e!start\currentmathoperator\endcsname{\math_operator_start{\currentmathoperator}}%
42    \protected\instance\edefcsname\e!stop \currentmathoperator\endcsname{\math_operator_stop}%
43\to \everydefinemathoperator
44
45% more generic:
46
47\defcsname\??mathoperatormethod\v!horizontal\endcsname{nolimits }
48\defcsname\??mathoperatormethod\v!vertical  \endcsname{limits }
49
50% The ones we wlready had:
51
52\letcsname\??mathoperatormethod    \v!auto\endcsname\empty
53\letcsname\??mathoperatormethod autolimits\endcsname\empty
54\letcsname\??mathoperatormethod   nolimits\expandafter\endcsname\csname\??mathoperatormethod\v!horizontal\endcsname
55\letcsname\??mathoperatormethod     limits\expandafter\endcsname\csname\??mathoperatormethod\v!vertical  \endcsname
56
57%D With the auto option DisplayOperatorMinHeight will kick in unless we explicitly set the size or
58%D use the start|-|stop variant (which will size automatically). The default of this font parameter
59%D are a bit on the small size which doesn't work well with fonts other than Latin Modern that has
60%D a large one. Keep in mind that we have e.g. integrals as operators and not fixed characters.
61
62\installlocalcurrenthandler\??mathoperators {mathoperator}
63
64\protected\def\math_operator_operator#1#2%
65  {\setlocalmathoperatorcurrent{#1}% \edef\currentmathoperator{#1}%
66   \setupcurrentmathoperator[#2]%
67   \Uoperator
68     \usedcolorparameterattributes{\mathoperatorparameter\c!color}%
69     \begincsname\??mathoperatormethod\mathoperatorparameter\c!method\endcsname
70     \ifchkdimension\mathoperatorparameter\c!size\or
71       \s!depth \lastchkdimension
72       \s!height\lastchkdimension
73       \s!axis   % variants
74       \s!noaxis % extensibles (assumes also axis)
75       \s!exact  % make sure we don't overshoot when there are no variants and extensibles
76     \orelse\ifcstok{\mathoperatorparameter\c!size}\v!auto
77       \s!auto
78     \fi
79     \s!class \mathcodechecked{\mathoperatorparameter\c!mathclass} %
80     \s!attr \indexofregister \c_attr_mathsize \attributeunsetvalue
81     % todo: find a way to pick up or pass sup/sub to here
82     \Udelimiter \zerocount \fam \mathoperatorparameter\c!left
83     {\edef\m_operator_text{\mathoperatorparameter\c!top}%
84      \ifempty\m_operator_text\else
85         \mathstrut % todo: make option
86         \dousecolorparameter{\mathoperatorparameter\c!topcolor}
87         \m_operator_text
88      \fi}%
89     {\edef\m_operator_text{\mathoperatorparameter\c!bottom}%
90      \ifempty\m_operator_text\else
91         \mathstrut % todo: make option
92         \dousecolorparameter{\mathoperatorparameter\c!bottomcolor}
93         \m_operator_text
94      \fi}}
95
96\tolerant\protected\def\math_operator#1#*[#S#2]#*#:#=% mandate braces
97  {\math_operator_operator{#1}{#2}#3\Uright.}
98
99\tolerant\protected\def\math_operator_start#1#*[#S#2]%
100  {\math_operator_operator{#1}{#2}}
101
102\protected\def\math_operator_stop
103  {\Uright.}
104% {\Uright\Udelimiter\zerocount \fam \zerocount }
105
106% \def\math_operator_default_size % is now the auto option
107%   {\ifconditional\indisplaymath\ifcase\Umathoperatorsize=\maxdimen\else
108%      \Umathoperatorsize\displaystyle
109%    \fi\fi}
110
111% TODO: Add 4 (inherited) classes and then define them automatically from char-def
112% instead.
113
114\definemathoperator [integrals]
115\definemathoperator [summations]
116\definemathoperator [products]
117\definemathoperator [operators]
118
119\setupmathoperators [summations] [\c!size=\v!auto]
120\setupmathoperators [products]   [\c!size=\v!auto]
121\setupmathoperators [operators]  [\c!size=\v!auto]
122
123\setupmathoperators [integrals]
124  [\c!size=\v!auto,
125   \c!mathclass=\mathintegralcode,
126   \c!method=\mathematicsparameter\c!integral] % cf Mikael's wish
127
128\setupmathematics[\c!integral=nolimits]
129
130\definemathoperator [integral]    [integrals]  [\c!left="222B] % these might go unless we decide
131\definemathoperator [iintegral]   [integrals]  [\c!left="222C] % to have verbose parents but who
132\definemathoperator [iiintegral]  [integrals]  [\c!left="222D] % will use them
133\definemathoperator [iiiintegral] [integrals]  [\c!left="2A0C]
134
135\definemathoperator [int]        [integrals]  [\c!left="222B] %                          INTEGRAL
136\definemathoperator [iint]       [integrals]  [\c!left="222C] %                DOUBLE    INTEGRAL
137\definemathoperator [iiint]      [integrals]  [\c!left="222D] %                TRIPLE    INTEGRAL
138\definemathoperator [iiiint]     [integrals]  [\c!left="2A0C] %                QUADRUPLE INTEGRAL OPERATOR
139\definemathoperator [oint]       [integrals]  [\c!left="222E] %                CONTOUR   INTEGRAL
140\definemathoperator [oiint]      [integrals]  [\c!left="222F] %                SURFACE   INTEGRAL
141\definemathoperator [oiiint]     [integrals]  [\c!left="2230] %                VOLUME    INTEGRAL
142\definemathoperator [intc]       [integrals]  [\c!left="2231] %      CLOCKWISE           INTEGRAL
143\definemathoperator [ointc]      [integrals]  [\c!left="2232] %      CLOCKWISE CONTOUR   INTEGRAL
144\definemathoperator [aointc]     [integrals]  [\c!left="2233] % ANTI CLOCKWISE CONTOUR   INTEGRAL
145
146\definemathoperator [sumint]                [integrals]  [\c!left="2A0B] % Integral with sum
147\definemathoperator [barint]                [integrals]  [\c!left="2A0D] % Integral with bar
148\definemathoperator [doublebarint]          [integrals]  [\c!left="2A0E] % Integral with double bar
149\definemathoperator [slashint]              [integrals]  [\c!left="2A0F] % Integral with slash
150\definemathoperator [aodownintc]            [integrals]  [\c!left="2A11]
151\definemathoperator [rectangularpoleintc]   [integrals]  [\c!left="2A12]
152\definemathoperator [semicirclepoleintc]    [integrals]  [\c!left="2A13]
153\definemathoperator [circlepoleoutsideintc] [integrals]  [\c!left="2A14]
154\definemathoperator [circlepoleinsideintc]  [integrals]  [\c!left="2A15]
155\definemathoperator [squareintc]            [integrals]  [\c!left="2A16]
156\definemathoperator [hookleftarrowint]      [integrals]  [\c!left="2A17]
157\definemathoperator [timesint]              [integrals]  [\c!left="2A18]
158\definemathoperator [capint]                [integrals]  [\c!left="2A19]
159\definemathoperator [cupint]                [integrals]  [\c!left="2A1A]
160\definemathoperator [upperint]              [integrals]  [\c!left="2A1B]
161\definemathoperator [lowerint]              [integrals]  [\c!left="2A1C]
162
163\definemathoperator [sum]           [summations] [\c!left="2211] % N-ARY SUMMATION
164\definemathoperator [blackboardsum] [summations] [\c!left="2140] % blackboard summation
165\definemathoperator [modtwosum]     [summations] [\c!left="2A0A] % modulo two summation
166
167
168\definemathoperator [prod]       [products]   [\c!left="220F] % N-ARY PRODUCT
169\definemathoperator [coprod]     [products]   [\c!left="2210] % N-ARY COPRODUCT
170
171% todo: middles too
172
173\definemathoperator [bigwedge]   [operators]  [\c!left="22C0] %  N-ARY LOGICAL AND
174\definemathoperator [bigvee]     [operators]  [\c!left="22C1] %  N-ARY LOGICAL OR
175\definemathoperator [bigcap]     [operators]  [\c!left="22C2] %  N-ARY LOGICAL INTERSECTION
176\definemathoperator [bigcup]     [operators]  [\c!left="22C3] %  N-ARY         UNION
177\definemathoperator [bigodot]    [operators]  [\c!left="2A00] %  N-ARY CIRCLED DOT          OPERATOR
178\definemathoperator [bigoplus]   [operators]  [\c!left="2A01] %  N-ARY CIRCLED PLUS         OPERATOR
179\definemathoperator [bigotimes]  [operators]  [\c!left="2A02] %  N-ARY CIRCLED TIMES        OPERATOR
180\definemathoperator [bigudot]    [operators]  [\c!left="2A03] %  N-ARY         UNION        OPERATOR WITH DOT
181\definemathoperator [biguplus]   [operators]  [\c!left="2A04] %  N-ARY         UNION        OPERATOR WITH PLUS
182\definemathoperator [bigsqcap]   [operators]  [\c!left="2A05] %  N-ARY SQUARE  INTERSECTION OPERATOR
183\definemathoperator [bigsqcup]   [operators]  [\c!left="2A06] %  N-ARY SQUARE  UNION        OPERATOR
184\definemathoperator [bigtimes]   [operators]  [\c!left="2A09] %  N-ARY         TIMES        OPERATOR
185
186\definemathoperator [leftouterjoin]     [operators]  [\c!left="27D5] % left outer join
187\definemathoperator [rightouterjoin]    [operators]  [\c!left="27D6] % right outer join
188\definemathoperator [fullouterjoin]     [operators]  [\c!left="27D7] % full outer join
189\definemathoperator [bigbottom]         [operators]  [\c!left="27D8] % big bottom
190\definemathoperator [bigtop]            [operators]  [\c!left="27D9] % big top
191\definemathoperator [bigsolidus]        [operators]  [\c!left="29F8] % big solidus
192\definemathoperator [bigreversesolidus] [operators]  [\c!left="29F9] % big reverse solidus
193\definemathoperator [bigdoublewedge]    [operators]  [\c!left="2A07] % big double wedge
194\definemathoperator [bigdoublevee]      [operators]  [\c!left="2A08] % big double vee
195
196\protect \endinput
197