math-acc.mkvi /size: 8170 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=math-acc,
3
%D version=2013.07.31,
4
%D title=\CONTEXT\ Math Macros,
5
%D subtitle=Accents,
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
/
Accents
}
15 16
% There are probably errors ... too distracted by amazing (piano) music videos running
17
% on top of scite ... so: experimental code.
18 19
\unprotect
20 21
% This module permits overloading of accents so that we can do fancy things. The
22
% implementation is similar to stackers. By default accenst are defined in a simple
23
% way. Contrary to extensibles accents cannot grow indefinitely. Alas the
24
% implementation of accents is different too, in the sense that they are
25
% prepositioned i.e. are already raised. (In my opinion for no real reason as they
26
% need to adapt anyway).
27
%
28
% $ \ruledhbox{$H$} \hat{H} \ruledhbox{$\widehat{H}$} \widehat{H} $
29
%
30
% One alternative is:
31
%
32
% \definemathoverextensible [top] [hoed] ["FE302]
33
% \definemathoverextensible [top] [slang] ["FE303]
34
%
35
% $ \hoed{H} \ruledhbox{$\hoed{H}$} \ruledhbox{$\hoed{\tf H}$} \slang{H} $
36
%
37
% But that nills the italic correction (and I'm in nood to mess with that again).
38
%
39
% \definemathaccents [myaccents] [color=darkred]
40
% \definemathtopaccent [myaccents] [mywidehat] ["0302]
41
%
42
% $ \hat{H} \widehat{H} \mywidehat{H} $
43 44
% A first variant (kept for educational purposed):
45
%
46
% \installcorenamespace{mathaccents}
47
%
48
% \installcommandhandler \??mathaccents {mathaccent} \??mathaccents
49
%
50
% \let\setupmathaccents\setupmathaccent
51
%
52
% \setupmathaccents
53
% [\c!top=,
54
% \c!bottom=,
55
% \c!mathstyle=,
56
% \c!color=,
57
% \c!command=\v!yes]
58
%
59
% \appendtoks
60
% \edef\p_top_bottom{\namedmathaccentparameter\currentmathaccent\c!top\namedmathaccentparameter\currentmathaccent\c!bottom}%
61
% \ifx\p_top_bottom\empty\else
62
% \edef\p_command{\mathaccentparameter\c!command}%
63
% \ifx\p_command\v!yes
64
% \setuevalue\currentmathaccent{\math_accent{\currentmathaccent}}%
65
% \fi
66
% \fi
67
% \to \everydefinemathaccent
68
%
69
% \def\math_accented_color_do_push{\pushcolor[\p_math_accent_color]}
70
% \let\math_accented_color_do_pop \popcolor
71
%
72
% \unexpanded\def\math_accent#1#2%
73
% {\begingroup
74
% \edef\currentmathaccent{#1}%
75
% \edef\p_math_accent_top {\mathaccentparameter\c!top}%
76
% \edef\p_math_accent_bottom{\mathaccentparameter\c!bottom}%
77
% \edef\p_math_accent_color {\mathaccentparameter\c!color}%
78
% \startusemathstyleparameter\mathaccentparameter
79
% \ifx\p_math_accented_color\empty
80
% \let\math_accented_color_do_pop\donothing
81
% \else
82
% \let\math_accented_color_do_pop\popcolor
83
% \math_accented_color_do_push
84
% \fi
85
% \ifx\p_math_accent_top\empty
86
% \ifx\p_math_accent_bottom\empty
87
% \else
88
% \Umathaccent bottom \fam\zerocount\p_math_accent_bottom
89
% \fi
90
% \else
91
% \ifx\p_math_accent_bottom\empty
92
% \Umathaccent \fam\zerocount\p_math_accent_top
93
% \else
94
% \Umathaccent both \fam\zerocount\p_math_accent_top
95
% \fam\zerocount\p_math_accent_bottom
96
% \fi
97
% \fi
98
% {\popcolor#2}%
99
% \stopusemathstyleparameter
100
% \endgroup}
101
%
102
% \definemathaccent [myaccents] [\c!color=red]
103
% \definemathaccent [mywidehat] [myaccents] [\c!top="0302]
104 105
\installcorenamespace
{
mathaccents
}
106 107
\installcommandhandler
\??mathaccents
{
mathaccents
}
\??mathaccents
108 109
\setupmathaccents
110
[
\c!top
=
,
111
\c!bottom
=
,
112
\c!mathstyle
=
,
113
\c!color
=
,
114
\c!command
=
\v!yes
]
115 116
\definemathaccents
117
[
\v!both
]
118 119
\definemathaccents
120
[
\v!top
]
121
[
\v!both
]
122 123
\definemathaccents
124
[
\v!bottom
]
125
[
\v!both
]
126 127
\unexpanded
\def
\definemathtopaccent
{
\dotripleempty
\math_accents_define_top
}
128
\unexpanded
\def
\definemathbottomaccent
{
\dotripleempty
\math_accents_define_bottom
}
129
\unexpanded
\def
\definemathdoubleaccent
{
\doquadrupleempty
\math_accents_define_double
}
130 131
\def
\math_accents_define_top
[#
1
][#
2
][#
3
]
% class name top
132
{
\ifthirdargument
133
\setuevalue
{
#
2
}{
\math_accents_make_double
{
#
1
}
\plusone
{
\number
#
3
}
\zerocount
}
%
134
\else
135
\setuevalue
{
#
1
}{
\math_accents_make_double
\noexpand
\currentmathaccents
\plusone
{
\number
#
2
}
\zerocount
}
%
136
\fi
}
137 138
\def
\math_accents_define_bottom
[#
1
][#
2
][#
3
]
% class name bottom
139
{
\ifthirdargument
140
\setuevalue
{
#
2
}{
\math_accents_make_double
{
#
1
}
\plustwo\zerocount
{
\number
#
3
}}
%
141
\else
142
\setuevalue
{
#
1
}{
\math_accents_make_double
\noexpand
\currentmathaccents
\plustwo\zerocount
{
\number
#
2
}}
%
143
\fi
}
144 145
\def
\math_accents_define_double
[#
1
][#
2
][#
3
][#
4
]
% class name top bottom
146
{
\iffourthargument
147
\setuevalue
{
#
2
}{
\math_accents_make_double
{
#
1
}
\plusthree
{
\number
#
3
}{
\number
#
4
}}
%
148
\else
149
\setuevalue
{
#
1
}{
\math_accents_make_double
\noexpand
\currentmathaccents
\plusthree
{
\number
#
2
}{
\number
#
3
}}
%
150
\fi
}
151 152
\def
\math_accents_color_push_yes
153
{
\pushcolor
[
\p_math_accent_color
]
%
154
\let
\math_accents_color_pop
\popcolor
}
155 156
\def
\math_accents_color_push_nop
157
{
\let
\math_accents_color_pop
\donothing
}
158 159
\unexpanded
\def
\math_accents_make_double
#
class
#
kind
#
top
#
bottom
#
content
%
160
{
\begingroup
161
\edef
\currentmathaccents
{
#
class
}
%
162
\edef
\p_math_accent_color
{
\mathaccentsparameter
\c!color
}
%
163
\startusemathstyleparameter
\mathaccentsparameter
164
\ifx
\p_math_accent_color
\empty
165
\math_accents_color_push_nop
166
\else
167
\math_accents_color_push_yes
168
\fi
169
\ifcase
#
kind
\or
170
\Umathaccent
\fam
\zerocount
#
top
171
\or
172
\Umathaccent
bottom
\fam
\zerocount
#
bottom
173
\or
174
\Umathaccent
both
\fam
\zerocount
#
top
175
\fam
\zerocount
#
bottom
176
\fi
177
{
\math_accents_color_pop
#
content
}
%
178
\stopusemathstyleparameter
179
\endgroup
}
180 181
%D Relative new:
182 183
\newconditional
\c_math_accents_auto_dotless
\settrue
\c_math_accents_auto_dotless
% cf opentype math
184 185
\let
\normalgrave
\grave
\unexpanded
\def
\dotlessgrave
#
1
{
\normalgrave
{
\mathdotless
#
1
}}
186
\let
\normalddot
\ddot
\unexpanded
\def
\dotlessddot
#
1
{
\normalddot
{
\mathdotless
#
1
}}
187
\let
\normalbar
\bar
\unexpanded
\def
\dotlessbar
#
1
{
\normalbar
{
\mathdotless
#
1
}}
188
\let
\normalacute
\acute
\unexpanded
\def
\dotlessacute
#
1
{
\normalacute
{
\mathdotless
#
1
}}
189
\let
\normalhat
\hat
\unexpanded
\def
\dotlesshat
#
1
{
\normalhat
{
\mathdotless
#
1
}}
190
\let
\normalcheck
\check
\unexpanded
\def
\dotlesscheck
#
1
{
\normalcheck
{
\mathdotless
#
1
}}
191
\let
\normalbreve
\breve
\unexpanded
\def
\dotlessbreve
#
1
{
\normalbreve
{
\mathdotless
#
1
}}
192
\let
\normaldot
\dot
\unexpanded
\def
\dotlessdot
#
1
{
\normaldot
{
\mathdotless
#
1
}}
193
\let
\normalring
\ring
\unexpanded
\def
\dotlessring
#
1
{
\normalring
{
\mathdotless
#
1
}}
194
\let
\normaltilde
\tilde
\unexpanded
\def
\dotlesstilde
#
1
{
\normaltilde
{
\mathdotless
#
1
}}
195
\let
\normaldddot
\dddot
\unexpanded
\def
\dotlessdddot
#
1
{
\normaldddot
{
\mathdotless
#
1
}}
196 197
\def
\math_accents_auto_dotless
#
1
#
2
%
198
{
\ifconditional
\c_math_accents_auto_dotless
\expandafter
#
2
\else\expandafter
#
1
\fi
}
199 200
\unexpanded
\def
\grave
{
\math_accents_auto_dotless
\normalgrave
\dotlessgrave
}
201
\unexpanded
\def
\ddot
{
\math_accents_auto_dotless
\normalddot
\dotlessddot
}
202
\unexpanded
\def
\bar
{
\math_accents_auto_dotless
\normalbar
\dotlessbar
}
203
\unexpanded
\def
\acute
{
\math_accents_auto_dotless
\normalacute
\dotlessacute
}
204
\unexpanded
\def
\hat
{
\math_accents_auto_dotless
\normalhat
\dotlesshat
}
205
\unexpanded
\def
\check
{
\math_accents_auto_dotless
\normalcheck
\dotlesscheck
}
206
\unexpanded
\def
\breve
{
\math_accents_auto_dotless
\normalbreve
\dotlessbreve
}
207
\unexpanded
\def
\dot
{
\math_accents_auto_dotless
\normaldot
\dotlessdot
}
208
\unexpanded
\def
\ring
{
\math_accents_auto_dotless
\normalring
\dotlessring
}
209
\unexpanded
\def
\tilde
{
\math_accents_auto_dotless
\normaltilde
\dotlesstilde
}
210
\unexpanded
\def
\dddot
{
\math_accents_auto_dotless
\normaldddot
\dotlessdddot
}
211 212
\let
\mathring
\ring
% for a while
213 214
\protect
\endinput
215