math-del.mkiv /size: 5684 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=math-del,
3
%D version=2007.07.19,
4
%D title=\CONTEXT\ Math Macros,
5
%D subtitle=Delimiters,
6
%D author=Hans Hagen,
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
/
Delimiters
}
15 16
\unprotect
17 18
%D Old code that will be redone:
19
%D
20
%D \macros
21
%D {checkdelimiters, fakeleftdelimiter, fakerightdelimiter}
22
%D
23
%D Handy for non matching situations (as with mathml):
24
%D
25
%D \starttyping
26
%D \checkdelimiters{... bla bla ...}
27
%D \fakeleftdelimiter
28
%D ... bla bla ...
29
%D \fakerightdelimiter
30
%D \stoptyping
31 32
% Actually we can do better now with lua hacks.
33 34
\newcount
\c_math_delimiter_nesting
35 36
\def
\leftfakedelimiter
{
\advance
\c_math_delimiter_nesting
\minusone
\gobbleoneargument
}
37
\def
\rightfakedelimiter
{
\advance
\c_math_delimiter_nesting
\plusone
\gobbleoneargument
}
38 39
\def
\checkdelimiters
#
1
%
40
{
\c_math_delimiter_nesting
\zerocount
41
\setbox
\scratchbox
\hbox
\bgroup
42
\let\left
\leftfakedelimiter
43
\let\right
\rightfakedelimiter
44
\normalstartimath
#
1
\expandafter
\normalstopimath
\expandafter
45
\egroup
46
\expandafter
\c_math_delimiter_nesting
\the
\c_math_delimiter_nesting
\relax
}
47 48
\def
\fakeleftdelimiter
{
\ifnum
\c_math_delimiter_nesting
>
\zerocount
\left
.
\fi
}
49
\def
\fakerightdelimiter
{
\ifnum
\c_math_delimiter_nesting
<
\zerocount
\right
.
\fi
}
50 51
%D The following macros are used in the MathML interpreter, so
52
%D there is a good change of them never being documented for
53
%D other usage.
54 55
\let
\normalordelimiter
\secondoftwoarguments
56
\let
\normalorfiller
\firstoftwoarguments
57 58
\unexpanded
\def
\enabledelimiter
{
\let
\normalordelimiter
\secondoftwoarguments
}
59
\unexpanded
\def
\disabledelimiter
{
\let
\normalordelimiter
\firstoftwoarguments
}
60 61
\unexpanded
\def
\enablefiller
{
\let
\normalorfiller
\secondoftwoarguments
}
62
\unexpanded
\def
\disablefiller
{
\let
\normalorfiller
\firstoftwoarguments
}
63 64
% \def\mathopnolimits#1{\mathop{\mr\mathrm#1}\nolimits} % was \rm, which follows text fonts (used in mml parser)
65
% \def\mathopdolimits#1{\mathop{\mr\mathrm#1}} % was \rm, which follows text fonts (used in mml parser)
66 67
\def
\mathopnolimits
#
1
{
\mathop
{
\mathrm
#
1
}
\nolimits
}
% was \rm, which follows text fonts (used in mml parser, check!)
68
\def
\mathopdolimits
#
1
{
\mathop
{
\mathrm
#
1
}}
% was \rm, which follows text fonts (used in mml parser, check!)
69 70
% A new experiment:
71 72
% Hm, we already have \definemathextensible so we need to preserve that one. We now
73
% use \definemathdelimiter.
74 75
\installcorenamespace
{
mathdelimiter
}
76 77
\installcommandhandler
\??mathdelimiter
{
mathdelimiter
}
\??mathdelimiter
78 79
\let
\setupmathdelimiters
\setupmathdelimiter
80 81
\setupmathdelimiters
82
[
\c!symbol
=
0
,
83
\c!command
=
\v!yes
,
84
\c!factor
=
1
.
5
,
85
\c!axis
=
\v!yes
,
86
% \c!exact=\v!yes
87
\c!height
=
\exheight
,
88
\c!depth
=
\exheight
]
89 90
\appendtoks
91
\edef
\p_command
{
\mathdelimiterparameter
\c!command
}
%
92
\ifx
\p_command
\v!yes
93
\setuevalue
\currentmathdelimiter
{
\math_fenced_extensible
[
\currentmathdelimiter
]
}
%
94
\fi
95
\to
\everydefinemathdelimiter
96 97
\unexpanded
\def
\math_fenced_extensible
98
{
\dodoubleempty
\math_fenced_extensible_indeed
}
99 100
\unexpanded
\def
\math_fenced_extensible_indeed
[#
1
][#
2
]
%
101
{
\mathop
102
{
\edef
\currentmathdelimiter
{
#
1
}
%
103
\edef
\p_factor
{
\mathdelimiterparameter
\c!factor
}
%
104
\ifsecondargument
105
\doifassignmentelse
{
#
2
}
106
{
\setupcurrentmathdelimiter
[#
2
]
%
107
\edef
\p_factor
{
\mathdelimiterparameter
\c!factor
}}
%
108
{
\edef
\p_factor
{
#
2
}}
%
109
\else
110
\edef
\p_factor
{
\mathdelimiterparameter
\c!factor
}
%
111
\fi
112
\edef
\p_exact
{
\mathdelimiterparameter
\c!exact
}
%
113
\edef
\p_axis
{
\mathdelimiterparameter
\c!axis
}
%
114
\edef
\p_leftoffset
{
\mathdelimiterparameter
\c!leftoffset
}
%
115
\edef
\p_rightoffset
{
\mathdelimiterparameter
\c!rightoffset
}
%
116
\ifx
\p_leftoffset
\empty
\else
117
\mskip
\p_leftoffset
118
\fi
119
\Uvextensible
120
\ifx
\p_exact
\v!yes
exact
\fi
121
\ifx
\p_axis
\v!yes
axis
\fi
122
height
\p_factor
\dimexpr
\mathdelimiterparameter
\c!height
\relax
123
depth
\p_factor
\dimexpr
\mathdelimiterparameter
\c!depth
\relax
124
\Udelimiter
\zerocount\zerocount
\mathdelimiterparameter
\c!symbol
125
\relax
126
\ifx
\p_rightoffset
\empty
\else
127
\mskip
\p_rightoffset
128
\fi
}}
129 130
\let
\mathdelimiter
\math_fenced_extensible
131 132
\definemathdelimiter
[
integral
][
\c!symbol
="
2
2
2
B
]
133 134
% \setupmathdelimiter[integral][rightoffset=-3mu,exact=yes,factor=2]
135
%
136
% \let\inlineint \int
137
% \let\displayint\integral
138
%
139
% \unexpanded\def\int{\ifmmode\inlineordisplaymath\inlineint\displayint\else\normalint\fi}
140
%
141
% \startlines
142
% \ruledhbox{$\integral f\frac{1}{2}$}
143
% \ruledhbox{$\integral[factor=1] f\frac{1}{2}$}
144
% \ruledhbox{$\integral[factor=3] f\frac{1}{2}$}
145
% \ruledhbox{$\int f\frac{1}{2}$}
146
% \stoplines
147 148
\unexpanded
\def
\autointegral
#
1
#
2
#
3
%
149
{
\ifmmode
150
\setbox
\nextbox\mathstylehbox
{
#
3
}
%
151
\scratchdimen
\ifdim
\nextboxht
>
\nextboxdp\nextboxht
\else
\nextboxdp
\fi
152
\mathlimop
{
%
153
\Uvextensible
154
height
\scratchdimen
155
depth
\scratchdimen
156
exact
%
157
axis
%
158
\Udelimiter
\plusfour
\zerocount
"
2
2
2
B
%
159
}
%
160
\limits
% nolimits needs more work: kerning and so
161
\normalsuperscript
{
#
1
}
%
162
\normalsubscript
{
#
2
}
%
163
\box
\nextbox
164
\else
165
\char
"
2
2
2
B
\relax
166
\fi
}
167 168
% \startformula
169
% a =
170
% \autointegral{t}{b}1 +
171
% \autointegral{t}{b}{\frac{\frac{3}{4}}{\frac{1}{2}}} +
172
% \autointegral{t}{b}{\frac{\frac{\frac{\frac{1}{2}}{2}}{2}}{2}}
173
% \stopformula
174 175
\protect
\endinput
176