summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/math-del.mklx
blob: d046a0912683d0ece79271c01359be8e0a735a27 (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
%D \module
%D   [       file=math-del,
%D        version=2022.07.29,
%D          title=\CONTEXT\ Math Macros,
%D       subtitle=delimiteds,
%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 / Delimited}

\unprotect

%D This is a variant on radicals but in the end it was better to just define a new
%D environment for this. This is because we don't have the rule and we want a
%D different control over the spacing. We also don't want the degree.

% Todo: also add the mp plugin here but that more fun stuff for later (when we pick
% up school math).

\installcorenamespace{mathdelimited}
\installcorenamespace{mathdelimitedalternative}

\installcommandhandler \??mathdelimited {mathdelimited} \??mathdelimited

\setupmathdelimited
  [\c!alternative=\v!normal,
   \c!mpoffset=.25\exheight,
   \c!topoffset=\zeropoint,
   \c!bottomoffset=\zeropoint,
   \c!height=\zeropoint,
   \c!depth=\zeropoint,
   \c!strut=\v!height,
   \c!source=\zerocount,
   \c!left=\zerocount,
   \c!right=\zerocount,
   \c!leftmargin=\zeropoint,
   \c!rightmargin=\zeropoint]

\appendtoks
    \frozen\protected\instance\edefcsname\currentmathdelimited\endcsname{\math_delimited_handle{\currentmathdelimited}}
\to \everydefinemathdelimited

\mutable\let\currentmathdelimited\empty

\tolerant\protected\def\math_delimited_handle#tag#*[#settings]#:#body%
  {\begingroup
   \edef\currentmathdelimited{#tag}%
   \setupcurrentmathdelimited[#settings]%
   \math_delimited_alternative{%
     \begincsname\??mathwhateverstrut\mathdelimitedparameter\c!strut\endcsname
     \scratchdimen\mathdelimitedparameter\c!leftmargin \relax\ifzeropt\scratchdimen\else\kern\scratchdimen\fi
     #body%
     \scratchdimen\mathdelimitedparameter\c!rightmargin\relax\ifzeropt\scratchdimen\else\kern\scratchdimen\fi
   }%
   \endgroup}

\def\math_delimited_alternative{\csname\??mathdelimitedalternative\mathdelimitedparameter\c!alternative\endcsname}

\protected\def\math_delimited_common
  {\Udelimited
     \s!height\dimexpr\mathdelimitedparameter\c!height+\mathdelimitedparameter\c!topoffset\relax
     \s!depth \dimexpr\mathdelimitedparameter\c!depth+\mathdelimitedparameter\c!bottomoffset\relax
     \s!source\numexpr\namedboxanchor{\mathdelimitedparameter\c!source}\relax
     \s!style \normalmathstyle
     \zerocount \mathdelimitedparameter\c!left
     \zerocount \mathdelimitedparameter\c!right
  \relax}

\defcsname\??mathdelimitedalternative\v!default\endcsname %  #body%
  {\math_delimited_common} % {#body}}

\defcsname\??mathdelimitedalternative\v!normal\endcsname#body%
  {\edef\p_color{\mathdelimitedparameter\c!color}%
   \ifempty\p_color
     \math_delimited_common{#body}% {} really needed as \rootdelimited expands first
   \else
     \pushcolor[\p_color]%
     \math_delimited_common
     {\popcolor#body}%
   \fi}

% todo:
%
% \setupmathdelimited
%   [topoffset=.2\exheight]
%
% \definemathdelimited
%   [fourier]
%   [rule=no,
%    left=\zerocount,
%    right="FE944] % 46 48
%
% $ \autofences \fourier{(z+\frac12)} + \courier{(z+\frac12)} + \xourier{(z+\frac12)} $

\protect \endinput