summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/math-del.mkiv
blob: be78b581f4ff36294dfa928c260a12891cde8a22 (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
%D \module
%D   [       file=math-del,
%D        version=2007.07.19,
%D          title=\CONTEXT\ Math Macros,
%D       subtitle=Delimiters,
%D         author=Hans Hagen,
%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 / Delimiters}

\unprotect

%D Old code that will be redone:
%D
%D \macros
%D   {checkdelimiters, fakeleftdelimiter, fakerightdelimiter}
%D
%D Handy for non matching situations (as with mathml):
%D
%D \starttyping
%D \checkdelimiters{... bla bla ...}
%D \fakeleftdelimiter
%D  ... bla bla ...
%D \fakerightdelimiter
%D \stoptyping

% Actually we can do better now with lua hacks.

\newcount\c_math_delimiter_nesting

\def\leftfakedelimiter {\advance\c_math_delimiter_nesting\minusone\gobbleoneargument}
\def\rightfakedelimiter{\advance\c_math_delimiter_nesting\plusone \gobbleoneargument}

\def\checkdelimiters#1%
  {\c_math_delimiter_nesting\zerocount
   \setbox\scratchbox\hbox\bgroup
     \let\left \leftfakedelimiter
     \let\right\rightfakedelimiter
     \normalstartimath#1\expandafter\normalstopimath\expandafter
   \egroup
   \expandafter\c_math_delimiter_nesting\the\c_math_delimiter_nesting\relax}

\def\fakeleftdelimiter {\ifnum\c_math_delimiter_nesting>\zerocount\left .\fi}
\def\fakerightdelimiter{\ifnum\c_math_delimiter_nesting<\zerocount\right.\fi}

%D The following macros are used in the MathML interpreter, so
%D there is a good change of them never being documented for
%D other usage.

\let\normalordelimiter\secondoftwoarguments
\let\normalorfiller   \firstoftwoarguments

\unexpanded\def\enabledelimiter {\let\normalordelimiter\secondoftwoarguments}
\unexpanded\def\disabledelimiter{\let\normalordelimiter\firstoftwoarguments}

\unexpanded\def\enablefiller    {\let\normalorfiller\secondoftwoarguments}
\unexpanded\def\disablefiller   {\let\normalorfiller\firstoftwoarguments}

% \def\mathopnolimits#1{\mathop{\mr\mathrm#1}\nolimits} % was \rm, which follows text fonts (used in mml parser)
% \def\mathopdolimits#1{\mathop{\mr\mathrm#1}}          % was \rm, which follows text fonts (used in mml parser)

\def\mathopnolimits#1{\mathop{\mathrm#1}\nolimits} % was \rm, which follows text fonts (used in mml parser, check!)
\def\mathopdolimits#1{\mathop{\mathrm#1}}          % was \rm, which follows text fonts (used in mml parser, check!)

% A new experiment:

\installcorenamespace {mathextensible}

\installcommandhandler \??mathextensible {mathextensible} \??mathextensible

\let\setupmathextensibles\setupmathextensible

\setupmathextensibles
  [\c!symbol=0,
   \c!command=\v!yes,
   \c!factor=1.5,
   \c!height=\exheight,
   \c!depth=\exheight]

\appendtoks
    \edef\p_command{\mathextensibleparameter\c!command}%
    \ifx\p_command\v!yes
        \setuevalue\currentmathextensible{\math_fenced_extensible[\currentmathextensible]}%
    \fi
\to \everydefinemathextensible

\unexpanded\def\math_fenced_extensible
  {\dodoubleempty\math_fenced_extensible_indeed}

\unexpanded\def\math_fenced_extensible_indeed[#1][#2]%
  {\mathop{%
     \edef\currentmathextensible{#1}%
     \edef\p_factor{\mathextensibleparameter\c!factor}%
     \ifsecondargument
       \doifassignmentelse{#2}
         {\setupcurrentmathextensible[#2]}%
         {\edef\p_factor{#2}}%
     \fi
     \Uvextensible
        axis   % can be an option
        height \p_factor\dimexpr\mathextensibleparameter\c!height\relax
        depth  \p_factor\dimexpr\mathextensibleparameter\c!depth\relax
        \Udelimiter\zerocount\zerocount\mathextensibleparameter\c!symbol
     \relax}%
   }

\let\mathextensible\math_fenced_extensible

% \startformula
%     \integral[factor=3] \frac{1}{2}
%     \integral[5] \frac{1}{2}
% \stopformula

\definemathextensible[integral][\c!symbol="222B]

\protect \endinput