math-ini.mkxl /size: 97 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=math-ini,
3
%D version=2008.01.02,
4
%D title=\CONTEXT\ Math Macros,
5
%D subtitle=Initializations,
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
/
Initializations
}
15 16
% todo: hpack as we skip math anyway
17
%
18
% todo: 0x2061 : function application
19
% todo: 0x2062 : invisible times
20
% todo: 0x2063 : invisible comma
21 22
% a bit tricky way to set ... no (pseudo) registers but math hash values:
23
%
24
% \normalexpanded{\Umathlimitabovevgap\displaystyle=40\dimexpr\the\Umathlimitabovevgap\displaystyle\relax}
25 26
% Todo in luatex maincontrol.w: also accept a number here:
27
%
28
% case set_math_param_cmd:
29
% p = cur_chr;
30
% get_token();
31
% if (cur_cmd != math_style_cmd) {
32
%
33
% plus two new math styles: larger/smaller
34
%
35
% \unexpanded\def\Umathshow#1%
36
% {\hbox{\infofont(\string#1:\the#1\textstyle,\the#1\scriptstyle,\the#1\scriptscriptstyle)}}
37 38
%D This module provides namespaces for math fonts, thereby permitting mixed usage of
39
%D math fonts. Although not strictly needed, we also provide a family name mapping
40
%D mechanism as used in the (original) AMS math definition files, but here these
41
%D names can recursively be remapped and if needed, dynamically be changed. We've
42
%D tried to minimize the number of definition commands and use plain \TEX\
43
%D definitions as fallback. We've tried to follow a couple of conventions from plain
44
%D and AMS math in order to achieve backward compatinility. We also kept an eye on
45
%D future usage of these modules in the perspective of MathML and unicode fonts.
46 47
%D There is a subtle issue with grouping: the \type {\begingroup} method will not
48
%D restore a changed mathstyle so best avoid that one. However, there are cases where
49
%D we really need to use such grouping.
50 51
% Weird, these fail, maybe amp is solved in a later state from char noads (needs a
52
% fix in luatex):
53
%
54
% $\char"26$
55
% $\a$
56
% $\string&$
57 58
% mathop applied to characters centers it vertically
59 60
\unprotect
61 62
%D We move these definitions into the format:
63 64
% test [[\char948 \cldcontext{utf.char(948)}]]
65
% test $[[\char948 \cldcontext{utf.char(948)}]]$
66 67
\registerctxluafile
{
math
-
ini
}{}
68
\registerctxluafile
{
math
-
dim
}{}
69
\registerctxluafile
{
math
-
act
}{}
70
\registerctxluafile
{
math
-
ext
}{}
71
\registerctxluafile
{
math
-
vfu
}{}
72
\registerctxluafile
{
math
-
ttv
}{}
73
\registerctxluafile
{
math
-
map
}{
optimize
}
74
\registerctxluafile
{
math
-
ren
}{}
75
\registerctxluafile
{
math
-
noa
}{
optimize
}
76
\registerctxluafile
{
math
-
tag
}{}
77
\registerctxluafile
{
math
-
fbk
}{}
78
\registerctxluafile
{
math
-
dir
}{}
79
\registerctxluafile
{
math
-
spa
}{}
80 81
%D A starter:
82
%D
83
%D \startbuffer
84
%D \mathsurround 10pt
85
%D \mathsurroundskip30pt
86
%D x $x + \ruledhbox{$x$} + x$ x
87
%D \stopbuffer
88
%D
89
%D \typebuffer
90
%D
91
%D \start \blank \getbuffer \blank \stop
92 93
\newcount
\mathnestinglevel
94 95
\appendtoks
96
\advance
\mathnestinglevel
\plusone
97
\to
\everymathematics
98 99
%D A few compatibility helpers:
100 101
\def
\Umathbotaccent
{
\Umathaccent
\s!bottom
}
102
\def
\Umathtopaccent
{
\Umathaccent
\s!top
}
103
\def
\Umathaccents
{
\Umathaccent
\s!both
}
104 105
\ifdefined
\Umathcharclass
\else
106
\def\Umathcharclass
{
\numexpr
\cldcontext{
tex
.
getmathcode
(
token
.
scan_int
(
)
)
[
1
]
}
\relax
}
107
\def\Umathcharfam
{
\numexpr
\cldcontext{
tex
.
getmathcode
(
token
.
scan_int
(
)
)
[
2
]
}
\relax
}
108
\def\Umathcharslot
{
\numexpr
\cldcontext{
tex
.
getmathcode
(
token
.
scan_int
(
)
)
[
3
]
}
\relax
}
109
\fi
110 111
%D The attributes that we will use (todo: pack some into one but uglier code):
112 113
\definesystemattribute
[
mathalphabet
]
[
public
]
114
\definesystemattribute
[
mathsize
]
[
public
]
115
\definesystemattribute
[
mathpunctuation
][
public
]
116
\definesystemattribute
[
mathgreek
]
[
public
]
% will become generic
117
\definesystemattribute
[
mathalternate
]
[
public
]
118
\definesystemattribute
[
mathrendering
]
[
public
]
119
\definesystemattribute
[
mathcategory
]
[
public
]
120
\definesystemattribute
[
mathmode
]
[
public
]
121
\definesystemattribute
[
mathitalics
]
[
public
]
122
\definesystemattribute
[
mathkernpairs
]
[
public
]
123
\definesystemattribute
[
mathbidi
]
[
public
]
124
\definesystemattribute
[
mathdomain
]
[
public
]
125
\definesystemattribute
[
mathcollapsing
]
[
public
]
126
\definesystemattribute
[
mathunstack
]
[
public
]
127 128
\definesystemattribute
[
displaymath
]
[
public
]
129 130
\mathflattenmode
3
1
131 132
\ifdefined
\ordlimits\else
133
\let\ordlimits\limits
134
\fi
135 136
\appendtoks
137
\c_attr_mathmode
\plusone
138
\to
\everydisplay
139 140
\appendtoks
141
\c_attr_mathmode
\plusone
142
\c_attr_displaymath
\plusone
143
\to
\everybeforedisplayformula
144 145
\setnewconstant
\defaultmathfamily
\zerocount
% 255
146 147
\unexpanded
\def
\resetmathattributes
{
\clf_resetmathattributes
}
148 149
% handy
150 151
\newconditional\indisplaymath
152 153
\appendtoks
154
\setfalse\indisplaymath
155
\to
\everymath
156 157
\appendtoks
158
\settrue\indisplaymath
159
\to
\everydisplay
160 161
\def
\inlineordisplaymath
{
\ifconditional
\indisplaymath
\expandafter
\secondoftwoarguments
\else\expandafter
\firstoftwoarguments
\fi
}
162 163
\unexpanded
\def
\forcedisplaymath
164
{
\ifmmode
165
\displaystyle
166
\settrue\indisplaymath
167
\fi
}
168 169
\unexpanded
\def
\startforceddisplaymath
170
{
\startimath
171
\displaystyle
172
\begingroup
173
\settrue\indisplaymath
}
174 175
\unexpanded
\def
\stopforceddisplaymath
176
{
\endgroup
177
\stopimath
}
178 179
\unexpanded
\def
\startpickupmath
% for the moment private
180
{
\ifconditional
\indisplaymath
181
\startforceddisplaymath
182
\let
\stoppickupmath\stopforceddisplaymath
183
\else
184
\startimath
185
\let
\stoppickupmath\stopimath
186
\fi
}
187 188
\let
\stoppickupmath
\relax
189 190
% \unexpanded\def\rawmathcharacter#1% slow but only for tracing
191
% {\begingroup
192
% \ifmmode
193
% \resetmathattributes\Uchar#1%
194
% \else
195
% \startimath\resetmathattributes\Uchar#1\stopimath
196
% \fi
197
% \endgroup}
198 199
\unexpanded
\def
\rawmathematics
#
1
% slow but only for tracing
200
{
\begingroup
201
\ifmmode
202
\clf_resetmathattributes
#
1
%
203
\else
204
\startimath
\clf_resetmathattributes
#
1
\stopimath
205
\fi
206
\endgroup
}
207 208
%D Some measures (maybe spac-mth):
209 210
% \def\mathskipsmall {\mskip\thinmuskip}
211
% \def\mathskipmedium{\mskip\medmuskip}
212
% \def\mathskipbig {\mskip\thickmuskip}
213 214
%D \macros
215
%D {setupmathematics}
216
%D
217
%D Configuration for integrals. (If needed we can speed this up and make it
218
%D installable; no processaction is needed then).
219 220
\installcorenamespace
{
mathematics
}
221 222
\installswitchcommandhandler
\??mathematics
{
mathematics
}
\??mathematics
223 224
\unexpanded
\def
\startmathematics
% no grouping, if ever then also an optional second
225
{
\doifelsenextoptionalcs
\math_mathematics_start_yes
\math_mathematics_start_nop
}
226 227
\installmacrostack
\currentmathematics
228 229
\unexpanded
\def
\math_mathematics_start_yes
[#
1
]
%
230
{
\push_macro_currentmathematics
231
\edef
\currentmathematics
{
#
1
}
% check for valid
232
\the
\everyswitchmathematics
}
233 234
\unexpanded
\def
\math_mathematics_start_nop
235
{
\push_macro_currentmathematics
236
\let
\currentmathematics
\empty
237
\the
\everyswitchmathematics
}
238 239
\unexpanded
\def
\stopmathematics
240
{
\pop_macro_currentmathematics
241
\the
\everyswitchmathematics
}
242 243
\definemathematics
[
\v!default
]
% not needed, but nicer when nesting back to normal
244 245
% Now we redefine \type {\mathematics} and \type {\m}:
246 247
\unexpanded
\def
\mathematics
248
{
\doifelsenextoptionalcs
\math_m_yes
\math_m_nop
}
249 250
\def
\math_m_yes
251
{
\relax
252
\ifmmode
253
\expandafter
\math_m_yes_math
254
\else
255
\expandafter
\math_m_yes_text
256
\fi
}
257 258
\def
\math_m_yes_math
[#
1
]#
2
%
259
{
#
2
}
260 261
% \def\math_m_yes_text[#1]%
262
% {\begingroup
263
% \doifassignmentelse{#1}%
264
% {\setupcurrentmathematics[#1]}%
265
% {\edef\currentmathematics{#1}}% check for valid
266
% \edef\p_openup{\mathematicsparameter\c!openup}%
267
% \ifx\p_openup\v!yes
268
% \expandafter\math_m_yes_text_openedup
269
% \else
270
% \expandafter\math_m_yes_text_normal
271
% \fi}
272 273
\def
\math_m_yes_text
[#
1
]
%
274
{
\begingroup
275
\ifcondition
\validassignment
{
#
1
}
%
276
\setupcurrentmathematics
[#
1
]
%
277
\else
278
\edef
\currentmathematics
{
#
1
}
% check for valid
279
\fi
280
\edef
\p_openup
{
\mathematicsparameter
\c!openup
}
%
281
\ifx
\p_openup
\v!yes
282
\expandafter
\math_m_yes_text_openedup
283
\else
284
\expandafter
\math_m_yes_text_normal
285
\fi
}
286 287
\def
\math_m_yes_text_openedup
#
1
%
288
{
\setbox
\scratchbox
\hbox
\bgroup
289
\the
\everyswitchmathematics
\relax
290
\normalstartimath
291
#
1
%
292
\normalstopimath
293
\egroup
294
\ifdim
\ht
\scratchbox
>
\strutht
295
\math_inline_openup_start_yes
296
\orelse\ifdim\dp
\scratchbox
>
\strutdp
297
\math_inline_openup_start_yes
298
\else
299
\math_inline_openup_start_nop
300
\fi
301
\unhbox
\scratchbox
% \normalstartimath#1\normalstopimath
302
\math_inline_openup_stop
303
\endgroup
}
304 305
\def
\math_m_yes_text_normal
#
1
%
306
{
\the
\everyswitchmathematics
\relax
307
\normalstartimath
308
#
1
%
309
\normalstopimath
310
\endgroup
}
311 312
\def
\math_m_nop
#
1
%
313
{
\relax
314
\ifmmode
315
#
1
%
316
\else
317
\normalstartimath
318
#
1
%
319
\normalstopimath
320
\fi
}
321 322
\let
\m
\mathematics
323
\let
\math\mathematics
324 325
% e.g.: \definemathematics[i:mp][setups=i:tight,openup=yes]
326 327
\newmuskip
\defaultthickmuskip
\defaultthickmuskip
5
mu
plus
5
mu
328
\newmuskip
\defaultmedmuskip
\defaultmedmuskip
4
mu
plus
2
mu
minus
4
mu
329
\newmuskip
\defaultthinmuskip
\defaultthinmuskip
3
mu
330 331
\newmuskip
\halfthickmuskip
\halfthickmuskip
2
.
5
mu
plus
2
.
5
mu
332
\newmuskip
\halfmedmuskip
\halfmedmuskip
2
.
0
mu
plus
1
.
0
mu
minus
2
.
0
mu
333
\newmuskip
\halfthinmuskip
\halfthinmuskip
1
.
5
mu
334 335
\newcount
\defaultrelpenalty
\defaultrelpenalty
5
0
0
336
\newcount
\defaultbinoppenalty
\defaultbinoppenalty
7
0
0
337
\newcount
\defaultprerelpenalty
\defaultprerelpenalty
-
1
0
0
338
\newcount
\defaultprebinoppenalty
\defaultprebinoppenalty
-
1
0
0
339 340
% we need to control these otherwise:
341
%
342
% \prerelpenalty \defaultprerelpenalty
343
% \prebinoppenalty\defaultprebinoppenalty
344 345
\startsetups
math
:
spacing
:
default
346
\thickmuskip
\defaultthickmuskip
347
\medmuskip
\defaultmedmuskip
348
\thinmuskip
\defaultthinmuskip
349
\relpenalty
\defaultrelpenalty
350
\binoppenalty
\defaultbinoppenalty
351
\prebinoppenalty
\maxdimen
352
\prerelpenalty
\maxdimen
353
\stopsetups
354 355
\startsetups
math
:
spacing
:
split
356
\thickmuskip
\defaultthickmuskip
357
\medmuskip
\defaultmedmuskip
358
\thinmuskip
\defaultthinmuskip
359
\relpenalty
\defaultrelpenalty
360
\binoppenalty
\defaultbinoppenalty
361
\prebinoppenalty
\defaultprebinoppenalty
362
\prerelpenalty
\defaultprerelpenalty
363
\stopsetups
364 365
\startsetups
math
:
spacing
:
half
366
\thickmuskip
\halfthickmuskip
367
\medmuskip
\halfmedmuskip
368
\thinmuskip
\halfthinmuskip
369
\relpenalty
\defaultrelpenalty
370
\binoppenalty
\defaultbinoppenalty
371
\prebinoppenalty
\maxdimen
372
\prerelpenalty
\maxdimen
373
\stopsetups
374 375
\startsetups
math
:
spacing
:
tight
376
\ifcase
\raggedstatus
377
\thickmuskip
\halfthickmuskip
378
\medmuskip
\halfmedmuskip
379
\thinmuskip
\halfthinmuskip
380
\else
381
\thickmuskip
1
\halfthickmuskip
382
\medmuskip
1
\halfmedmuskip
383
\thinmuskip
1
\halfthinmuskip
384
\fi
385
\relpenalty
\defaultrelpenalty
386
\binoppenalty
\maxdimen
387
\prebinoppenalty
\maxdimen
388
\prerelpenalty
\maxdimen
389
\stopsetups
390 391
\startsetups
math
:
spacing
:
fixed
392
\ifcase
\raggedstatus
393
\thickmuskip
\halfthickmuskip
394
\medmuskip
\halfmedmuskip
395
\thinmuskip
\halfthinmuskip
396
\else
397
\thickmuskip
1
\halfthickmuskip
398
\medmuskip
1
\halfmedmuskip
399
\thinmuskip
1
\halfthinmuskip
400
\fi
401
\relpenalty
\maxdimen
402
\binoppenalty
\maxdimen
403
\prebinoppenalty
\maxdimen
404
\prerelpenalty
\maxdimen
405
\stopsetups
406 407
% \dorecurse{80}{test \m[i:tight]{\red \fakeformula} test }
408 409
\definemathematics
[
i
:
default
][
\c!setups
=
math
:
spacing
:
equal
]
410
\definemathematics
[
i
:
half
]
[
\c!setups
=
math
:
spacing
:
half
]
411
\definemathematics
[
i
:
tight
]
[
\c!setups
=
math
:
spacing
:
tight
]
412
\definemathematics
[
i
:
fixed
]
[
\c!setups
=
math
:
spacing
:
fixed
]
413 414
% Normally the next is applied to only one character.
415
%
416
% $ABC$ $\cal ABC$ $\mathaltcal ABC$
417 418
% todo: only in mmode
419
% these commands are semi-public but should not be used directly (lua names wil change)
420 421
\unexpanded
\def
\math_set_attribute
#
1
#
2
{
\ifmmode
\clf_setmathattribute
{
#
1
}{
#
2
}
\fi
}
422
\unexpanded
\def
\math_set_alphabet
#
1
{
\ifmmode
\clf_setmathalphabet
{
#
1
}
\fi
}
423
\unexpanded
\def
\math_set_font_style
#
1
{
\ifmmode
\clf_setmathstyle
{
#
1
}
\fi
}
424
\unexpanded
\def
\math_set_font_alternate
#
1
{
\ifmmode
\clf_setmathalternate
\defaultmathfamily
{
#
1
}
\fi
}
425 426
\installcorenamespace
{
mathstylealternative
}
% might become a setuphandler
427 428
\unexpanded
\def
\math_set_font_style_alternate
#
1
%
429
{
\ifcsname
\??mathstylealternative
\fontclass
:
#
1
\endcsname
430
\expandafter
\math_set_font_alternate
\lastnamedcs
431
\orelse\ifcsname
\??mathstylealternative
#
1
\endcsname
432
\expandafter
\math_set_font_alternate
\lastnamedcs
433
\fi
}
434 435
\unexpanded
\def
\setupmathrendering
% the name might change
436
{
\dodoubleargument
\math_setup_rendering
}
437 438
\def
\math_setup_rendering
[#
1
][#
2
]
%
439
{
\ifsecondargument
440
\getparameters
[
\??mathstylealternative
#
1
:
][#
2
]
%
441
\else
442
\getparameters
[
\??mathstylealternative
][#
1
]
%
443
\fi
}
444 445
\appendtoks
446
\edef
\p_stylealternative
{
\mathematicsparameter
\c!stylealternative
}
%
447
\ifempty
\p_stylealternative
\else
448
\clf_presetmathalternate
\defaultmathfamily
{
\p_stylealternative
}
%
449
\fi
450
\to
\everymathematics
451 452
% if there were many features we could have a feature pass over math nodes but it makes no
453
% sense now so we have commands to deal with it
454 455
% \enabletrackers[math.alternates]
456
% \setupbodyfont[lucidaot]
457
%
458
% \startTEXpage
459
% \setupmathematics[stylealternative={reset}]$x+\mathcal A$\par
460
% \setupmathematics[stylealternative={reset,calligraphic}]$x+\mathcal A$\par
461
% \setupmathematics[stylealternative={reset,italic}]$x+\mathcal A$\par
462
% \setupmathematics[stylealternative={reset,calligraphic,italic}]$x+\mathcal A$
463
% \stopTEXpage
464 465
\unexpanded
\def
\mathaltcalligraphic
{
\math_set_font_alternate
{
calligraphic
}
\cal
}
% set via goody file
466
\unexpanded
\def
\mathaltitalic
{
\math_set_font_alternate
{
italic
}}
% set via goody file
467
\unexpanded
\def
\mathslashedzero
{
\begingroup
\math_set_font_alternate
{
zero
}
\endgroup
}
% set via goody file or automatic
468
\unexpanded
\def
\mathdotless
{
\math_set_font_alternate
{
dotless
}}
% set via goody file or automatic
469
\unexpanded
\def
\mathdotlessi
{
\begingroup
\mathdotless
i
\endgroup
}
470
\unexpanded
\def
\mathdotlessj
{
\begingroup
\mathdotless
j
\endgroup
}
471 472
\let
\mathaltcal
\mathaltcalligraphic
473
\let
\mathaltit
\mathaltitalic
474 475
%let\textslashedzero\slashedzero \unexpanded\def\autoslashedzero{\mathortext\mathslashedzero\textslashedzero}
476
\let
\textdotlessi
\dotlessi
\unexpanded
\def
\autodotlessi
{
\mathortext
\mathdotlessi
\textdotlessi
}
477
\let
\textdotlessj
\dotlessj
\unexpanded
\def
\autodotlessj
{
\mathortext
\mathdotlessj
\textdotlessj
}
478 479
\appendtoks
480
%let\slashedzero\autoslashedzero
481
\let
\dotlessi
\autodotlessi
482
\let
\dotlessj
\autodotlessj
483
\to
\everymathematics
484 485
\let
\setmathattribute
\math_set_attribute
486
\let
\setmathalphabet
\math_set_alphabet
487
\let
\setmathfontstyle
\math_set_font_style
488
\let
\setmathfontalternate
\math_set_font_alternate
489
\let
\setmathfontalternative
\math_set_font_alternate
490
\let
\setmathfontstylealternate
\math_set_font_style_alternate
491
\let
\setmathfontstylealternative
\math_set_font_style_alternate
492 493
\let
\mathalternate
\math_set_font_alternate
494 495
\unexpanded
\def
\mathupright
{
\math_set_attribute
\s!regular\s!tf
\math_set_font_style_alternate
\s!tf
}
496
\unexpanded
\def
\mathitalic
{
\math_set_attribute
\s!regular\s!it
\math_set_font_style_alternate
\s!it
}
497
\unexpanded
\def
\mathscript
{
\math_set_alphabet
\s!script
\math_set_font_style_alternate
\s!script
}
498
\unexpanded
\def
\mathfraktur
{
\math_set_alphabet
\s!fraktur
\math_set_font_style_alternate
\s!fraktur
}
499
\unexpanded
\def
\mathblackboard
{
\math_set_alphabet
\s!blackboard
\math_set_font_style_alternate
\s!blackboard
}
500 501
\unexpanded
\def
\mathrm
{
\math_set_attribute
\s!rm\s!tf
\math_set_font_style_alternate
\s!tf
}
502
\unexpanded
\def
\mathss
{
\math_set_attribute
\s!ss\s!tf
\math_set_font_style_alternate
\s!tf
}
503
\unexpanded
\def
\mathtt
{
\math_set_attribute
\s!tt\s!tf
\math_set_font_style_alternate
\s!tf
}
504 505
\unexpanded
\def
\mathtf
{
\math_set_font_style
\s!tf
\math_set_font_style_alternate
\s!tf
}
506
\unexpanded
\def
\mathsl
{
\math_set_font_style
\s!it
\math_set_font_style_alternate
\s!it
}
% no sl
507
\unexpanded
\def
\mathit
{
\math_set_font_style
\s!it
\math_set_font_style_alternate
\s!it
}
508 509
\unexpanded
\def
\mathbf
{
\math_set_font_style
\s!bf
\math_set_font_style_alternate
\s!bf
}
510
\unexpanded
\def
\mathbs
{
\math_set_font_style
\s!bi
\math_set_font_style_alternate
\s!bi
}
% no sl
511
\unexpanded
\def
\mathbi
{
\math_set_font_style
\s!bi
\math_set_font_style_alternate
\s!bi
}
512 513
\let
\mathdefault\mathitalic
514 515
\appendtoks
516
\edef
\p_default
{
\mathematicsparameter
\c!default
}
%
517
\ifx
\p_default
\v!normal
518
\let
\mathdefault\mathupright
519
\else
520
\let
\mathdefault\mathitalic
521
\fi
522
\to
\everysetupmathematics
523 524
\setupmathematics
525
[
\c!default
=
\v!italic
]
526 527
\let
\tfmath
\mathtf
% maybe a grouped command
528
\let
\slmath
\mathsl
529
\let
\itmath
\mathit
530 531
\let
\bfmath
\mathbf
532
\let
\bsmath
\mathbs
533
\let
\bimath
\mathbi
534 535
\let
\Bbb
\mathblackboard
536 537
\unexpanded
\def
\frak
{
\ifmmode
\expandafter
\mathfraktur
\fi
}
538
\unexpanded
\def
\cal
{
\ifmmode
\expandafter
\mathscript
\fi
}
539
\unexpanded
\def
\bbd
{
\ifmmode
\expandafter
\mathblackboard
\fi
}
540
\unexpanded
\def
\blackboard
{
\ifmmode
\expandafter
\mathblackboard
\fi
}
541
\unexpanded
\def
\fraktur
{
\ifmmode
\expandafter
\mathfraktur
\fi
}
542
\unexpanded
\def
\gothic
{
\ifmmode
\expandafter
\mathfraktur
\fi
}
543 544
\unexpanded
\def
\mathcal
#
1
{{
\mathscript
#
1
}}
% for AMS compatibility
545
\unexpanded
\def
\mathfrak
#
1
{{
\mathfraktur
#
1
}}
% for AMS compatibility
546
\unexpanded
\def
\mathbb
#
1
{{
\mathblackboard
#
1
}}
% for AMS compatibility
547 548
\ifdefined
\normaltf
\else\let
\normaltf
\tf
\fi
\unexpanded
\def
\tf
{
\ifmmode
\mathtf
\else
\normaltf
\fi
}
549
\ifdefined
\normalbf
\else\let
\normalbf
\bf
\fi
\unexpanded
\def
\bf
{
\ifmmode
\mathbf
\else
\normalbf
\fi
}
550
\ifdefined
\normalit
\else\let
\normalit
\it
\fi
\unexpanded
\def
\it
{
\ifmmode
\mathit
\else
\normalit
\fi
}
551
\ifdefined
\normalsl
\else\let
\normalsl
\sl
\fi
\unexpanded
\def
\sl
{
\ifmmode
\mathsl
\else
\normalsl
\fi
}
552
\ifdefined
\normalbi
\else\let
\normalbi
\bi
\fi
\unexpanded
\def
\bi
{
\ifmmode
\mathbi
\else
\normalbi
\fi
}
553
\ifdefined
\normalbs
\else\let
\normalbs
\bs
\fi
\unexpanded
\def
\bs
{
\ifmmode
\mathbs
\else
\normalbs
\fi
}
554 555
\unexpanded
\def
\rm
{
\ifmmode
\mathrm
\else
\normalrm
\fi
}
556
\unexpanded
\def
\ss
{
\ifmmode
\mathss
\else
\normalss
\fi
}
557
\unexpanded
\def
\tt
{
\ifmmode
\mathtt
\else
\normaltt
\fi
}
558 559
\ifdefined
\mr
\else
\let
\mr
\relax
\fi
560
\ifdefined
\mb
\else
\let
\mb
\relax
\fi
561 562
% 1: $\setmathattribute{ss}{bf}3$
563
% 2: $\setmathattribute{ss}{bf}\setmathfontstylealternate{bf}3$
564
% 3: $\setmathattribute{ss}{bf}\setmathfontstyle{bf}3$
565
% 4: $\setmathattribute{ss}{bf}\setmathfontstyle{bf}\setmathfontstylealternate{bf}3$
566
% 5: $e=mc^2 \quad \mb e=mc^2$
567 568
\prependtoks
569
\mathdefault
570
\to
\everymathematics
571 572
%D We could set the rendering attribute at the \LUA\ end but as there can be many
573
%D small math snippets we keep track of the state at the \TEX\ end (mapping is
574
%D export safe).
575
%D
576
%D \starttyping
577
%D \startformula
578
%D \reals {\mathbf R} \utfchar{"0211D} \utfchar{"1D411}
579
%D \stopformula
580
%D
581
%D \setupmathematics
582
%D [symbolset=blackboard-to-bold]
583
%D
584
%D \startformula
585
%D \reals {\mathbf R} \utfchar{"0211D} \utfchar{"1D411}
586
%D \stopformula
587
%D \stoptyping
588 589
\newcount
\c_math_renderings_attribute
590 591
\appendtoks
592
\c_math_renderings_attribute
\clf_mathrenderset
{
\mathematicsparameter
\c!symbolset
}
\relax
593
\to
\everysetupmathematics
% only in mathematics
594 595
\appendtoks
596
\ifcase
\c_math_renderings_attribute
\else
597
\c_attr_mathrendering
\c_math_renderings_attribute
598
\fi
599
\to
\everymathematics
600 601
\setupmathematics
602
[
\c!symbolset
=]
603 604
%D \macros
605
%D {boldsymbol}
606
%D
607
%D To be done.
608 609
\let
\mathboldsymbol
\relax
% yet unsupported, will be
610 611
\unexpanded
\def
\boldsymbol
612
{
\mathortext
\mathboldsymbol
\bold
}
613 614
%D Helpers
615 616
\def
\utfmathclass
#
1
{
\clf_utfmathclass
{
#
1
}}
617
\def
\utfmathstretch
#
1
{
\clf_utfmathstretch
{
#
1
}}
618
\def
\utfmathcommand
#
1
{
\clf_utfmathcommand
{
#
1
}}
619
\def
\utfmathfiller
#
1
{
\clf_utfmathfiller
{
#
1
}}
620 621
\def
\utfmathcommandabove
#
1
{
\clf_utfmathcommandabove
{
#
1
}}
622
\def
\utfmathcommandbelow
#
1
{
\clf_utfmathcommandbelow
{
#
1
}}
623
\def
\utfmathcommandfiller
#
1
{
\clf_utfmathcommandfiller
{
#
1
}}
624 625
\unexpanded
\def
\doifelseutfmathaccent
#
1
{
\clf_doifelseutfmathaccent
{
#
1
}}
626
\unexpanded
\def
\doifelseutfmathabove
#
1
{
\clf_doifelseutfmathabove
{
#
1
}}
627
\unexpanded
\def
\doifelseutfmathbelow
#
1
{
\clf_doifelseutfmathbelow
{
#
1
}}
628
\unexpanded
\def
\doifelseutfmathfiller
#
1
{
\clf_doifelseutfmathfiller
{
#
1
}}
629
\unexpanded
\def
\doifelseutfmathlimop
#
1
{
\clf_doifelseutfmathlimop
{
#
1
}}
630 631
\let
\doifutfmathaccentelse
\doifelseutfmathaccent
632
\let
\doifutfmathaboveelse
\doifelseutfmathabove
633
\let
\doifutfmathbelowelse
\doifelseutfmathbelow
634
\let
\doifutfmathfillerelse
\doifelseutfmathfiller
635
\let
\doifutfmathlimopelse
\doifelseutfmathlimop
636 637
%D Not used that much:
638 639
\installcorenamespace
{
mathcodecommand
}
640 641
\unexpanded
\def
\mathlimop
#
1
{
\mathop
{
#
1
}}
%no \limits
642
\unexpanded
\def
\mathbox
#
1
{
\dontleavehmode
\hbox\Ustartmath\mathsurround
\zeropoint
#
1
\Ustopmath
}
643
\unexpanded
\def
\mathnolop
#
1
{
\mathop
{
#
1
}
\nolimits
}
644 645
\let
\mathnothing\firstofoneunexpanded
646
\let
\mathalpha
\firstofoneunexpanded
647 648
\setnewconstant
\mathordcode
\zerocount
\letvalue
{
\??mathcodecommand
ord
}
\mathord
649
\setnewconstant
\mathopcode
\plusone
\letvalue
{
\??mathcodecommand
op
}
\mathop
650
\setnewconstant
\mathbincode
\plustwo
\letvalue
{
\??mathcodecommand
bin
}
\mathbin
651
\setnewconstant
\mathrelcode
\plusthree
\letvalue
{
\??mathcodecommand
rel
}
\mathrel
652
\setnewconstant
\mathopencode
\plusfour
\letvalue
{
\??mathcodecommand
open
}
\mathopen
653
\setnewconstant
\mathclosecode
\plusfive
\letvalue
{
\??mathcodecommand
close
}
\mathclose
654
\setnewconstant
\mathpunctcode
\plussix
\letvalue
{
\??mathcodecommand
punct
}
\mathpunct
655
\setnewconstant
\mathalphacode
\plusseven
\letvalue
{
\??mathcodecommand
alpha
}
\mathalpha
656
\setnewconstant
\mathinnercode
\zerocount
\letvalue
{
\??mathcodecommand
inner
}
\mathinner
657
\setnewconstant
\mathnothingcode
\zerocount
\letvalue
{
\??mathcodecommand
nothing
}
\mathnothing
658
\setnewconstant
\mathlimopcode
\plusone
\letvalue
{
\??mathcodecommand
limop
}
\mathlimop
659
\setnewconstant
\mathnolopcode
\plusone
\letvalue
{
\??mathcodecommand
nolop
}
\mathnolop
660
\setnewconstant
\mathboxcode
\zerocount
\letvalue
{
\??mathcodecommand
box
}
\mathbox
661
\setnewconstant
\mathchoicecode
\zerocount
%letvalue{\??mathcodecommand choice}\mathnothing
662 663
\setnewconstant
\mathaccentcode
\pluseight
664
\setnewconstant
\mathradicalcode
\plusnine
665 666
\def
\mathcodenumber
#
1
{
\the\csname
math
#
1
code
\endcsname
}
667
\unexpanded
\def
\mathcodecommand
#
1
{
\csname
\??mathcodecommand
#
1
\endcsname
}
668 669
% \startlines
670
% $\mathopnolimits{\rm d}x$
671
% $\mathopnolimits{\kern\zeropoint \rm d}x$
672
% $\mathcodecommand{nolop}{\rm d}x$
673
% $\mathcodecommand{nolop}{\kern\zeropoint\rm d}x$
674
% \blank
675
% $\mathcodecommand{nolop}{\mr d}x$
676
% $\mathcodecommand{nolop}{\kern\zeropoint\mr d}x$
677
% $\mathop{\kern\zeropoint\mr d}x$
678
% $\mathopnolimits{\kern\zeropoint d}x$
679
% \stoplines
680 681
\installcorenamespace
{
mathcommand
}
682 683
\unexpanded
\def
\definemathcommand
684
{
\dotripleempty
\math_define_command
}
685 686
\def
\math_define_command
[#
1
][#
2
][#
3
]#
4
% command class args meaning
687
{
\ifthirdargument
688
\edef
\nofmathcommandarguments
{
#
3
}
%
689
\ifx
\nofmathcommandarguments
\v!one
690
\setuvalue
{
\??mathcommand
#
1
}
##
1
{
\mathcodecommand
{
#
2
}{
#
4
{
##
1
}}}
%
691
\orelse\ifx
\nofmathcommandarguments
\v!two
692
\setuvalue
{
\??mathcommand
#
1
}
##
1
##
2
{
\mathcodecommand
{
#
2
}{
#
4
{
##
1
}{
##
2
}}}
%
693
\else
694
\setuvalue
{
\??mathcommand
#
1
}{
\mathcodecommand
{
#
2
}{
#
4
}}
%
695
\fi
696
\orelse
\ifsecondargument
697
\setuvalue
{
\??mathcommand
#
1
}{
\mathcodecommand
{
#
2
}{
#
4
}}
%
698
\else
699
\setuvalue
{
\??mathcommand
#
1
}{
\mathcodecommand
{
nothing
}{
#
4
}}
%
700
\fi
701
\letcsnamecsname
\csname
#
1
\endcsname\csname
\??mathcommand
#
1
\endcsname
}
702 703
\unexpanded
\def
\mathcommand
#
1
%
704
{
\begincsname
\??mathcommand
#
1
\endcsname
}
705 706
%D Let's define a few comands here:
707 708
%definemathcommand [mathstrut] {\vphantom{(}}
709
%definemathcommand [joinrel] {\mathrel{\mkern-3mu}}
710
\definemathcommand
[
joinrel
]
[
rel
]
{
\mkern
-
3
mu
}
711 712
\chardef
\c_math_strut
"
2
8
713 714
\unexpanded
\def
\math_strut_htdp
#
1
%
715
{
\s!height
\fontcharht
#
1
\c_math_strut
716
\s!depth
\fontchardp
#
1
\c_math_strut
}
717 718
\unexpanded
\def
\math_strut_normal
719
{
\vrule
720
\s!width
\zeropoint
721
\normalexpanded
{
\math_strut_htdp
{
\mathstylefont
\normalmathstyle
}}
%
722
\relax
}
723 724
\unexpanded
\def
\math_strut_visual
725
{
\hskip
-
.
0
1
\emwidth
726
\vrule
727
\s!width
.
0
2
\emwidth
728
\normalexpanded
{
\math_strut_htdp
{
\mathstylefont
\normalmathstyle
}}
%
729
\relax
730
\hskip
-
.
0
1
\emwidth
}
731 732
\unexpanded
\def
\showmathstruts
% let's not overload \math_strut_normal
733
{
\let
\math_strut
\math_strut_visual
}
734 735
\let
\math_strut
\math_strut_normal
736 737
% \unexpanded\def\mathstrut{\mathcodecommand{nothing}{\math_strut}}
738 739
\definemathcommand
[
mathstrut
]
{
\math_strut
}
740 741
%D We could have a arg variant \unknown\ but not now.
742 743
\unexpanded
\def
\mathopwithlimits
#
1
#
2
{
\mathop
{
#
1
{
#
2
}}
\limits
}
744
\unexpanded
\def
\stackrel
#
1
#
2
{
\mathrel
{
\mathop
{
#
2
}
\limits
^
{
#
1
}}}
745 746
%D Moved from font-ini.mkiv:
747
%D
748
%D \macros
749
%D {mf,mbox,enablembox,mathop}
750
%D
751
%D Todo:
752 753
\unexpanded
\def
\mf
754
{
\begincsname
\fontalternative
\endcsname
}
755 756
% \let\normalmathop\mathop % already defined
757 758
% no longer needed as we no longer switch fonts
759
%
760
% \unexpanded\def\mathop
761
% {\normalmathop
762
% \bgroup
763
% % no: \let\rm\mf
764
% \afterassignment\math_op\let\nexttoken=}
765
%
766
% \def\math_op{\ifx\nexttoken\bgroup\else\nexttoken\egroup\fi}
767 768
% this one too: \letvalue{\??mathcodecommand op}\mathop ?
769 770
\unexpanded
\def
\normalmbox
771
{
\normalhbox
\bgroup
772
\usemathematicsstyleandcolor
\c!textstyle\c!textcolor
% new
773
\dowithnextboxcs
\math_mbox_finish
\normalhbox
}
774 775
\def
\math_mbox_finish
776
{
\flushnextbox
777
\egroup
}
778 779
\unexpanded
\def
\mbox
% we cannot add \dontleavehmode ... else no \setbox0\mbox possible
780
{
\ifmmode
\normalmbox
\else\normalhbox\fi
}
781 782
\unexpanded
\def
\enablembox
783
{
\toksapp
\everymathematics
{
\math_enable_mbox
}}
784 785
\def
\math_enable_mbox
786
{
\let\hbox
\mbox
}
787 788
\unexpanded
\def
\snappedmath
#
1
% sort of \struttedbox
789
{
\dontleavehmode
790
\begingroup
791
\setbox
\scratchbox
\normalhbox
\bgroup
792
\startimath
#
1
\stopimath
793
\egroup
794
\ht
\scratchbox\strutht
795
\dp
\scratchbox\strutdp
796
\box
\scratchbox
797
\endgroup
}
798 799
\unexpanded
\def
\mtext
#
1
%
800
{
\text
{
\usemathematicsstyleandcolor
\c!textstyle\c!textcolor
#
1
}}
801 802
%D The next hack is needed needed for sine, cosine etc.
803 804
\let
\mathfunction\firstofoneunexpanded
805 806
\let
\math_tags_function
\firstofoneunexpanded
807
\let
\math_tags_functionlabeltext
\mathlabeltext
808 809
\let
\math_tags_mo
\firstofoneunexpanded
810
\let
\math_tags_mi
\firstofoneunexpanded
811 812
\unexpanded
\def
\math_tags_mn
#
1
{
\begingroup
\mathupright
\math_set_o_both
#
1
\endgroup
}
813
\unexpanded
\def
\math_tags_ms
#
1
{
\begingroup
\mathupright
\math_set_p_both
#
1
\endgroup
}
814 815
% Once this is stable we can store the number at the tex end which is
816
% faster. Functions getnumbers >= 1000.
817 818
% \setupmathematics[functionstyle=normal] % will give ligatures and kerning
819 820
\setupmathematics
821
[
\c!textstyle
=
,
% rm ss etc i.e. known alternatives, otherwise math
822
\c!textcolor
=
,
823
\c!functionstyle
=
,
% rm ss etc i.e. known alternatives, otherwise math
824
\c!functioncolor
=]
825 826
\unexpanded
\def
\math_mfunction_styled
827
{
\begingroup
828
\usemathematicscolorparameter
\c!functioncolor
829
\edef
\p_functionstyle
{
\mathematicsparameter
\c!functionstyle
}
%
830
\ifempty
\p_functionstyle
831
\expandafter
\math_mfunction_styled_none
832
\orelse\ifcsname
\??alternativestyle
\p_functionstyle
\endcsname
833
\doubleexpandafter
\math_mfunction_styled_text
834
\else
835
\doubleexpandafter
\math_mfunction_styled_math
836
\fi
}
837 838
\unexpanded
\def
\math_mfunction_styled_text
#
1
%
839
%{\mathoptext{\csname\??alternativestyle\p_functionstyle\endcsname#1}%
840
{
\expandafter
\mathoptext
\expandafter
{
\lastnamedcs
#
1
}
%
841
\endgroup
}
842 843
\unexpanded
\def
\math_mfunction_styled_math
#
1
%
844
{
\p_functionstyle
845
#
1
%
846
\endgroup
}
847 848
\unexpanded
\def
\math_mfunction_styled_none
#
1
%
849
{
\mathupright
850
#
1
%
851
\endgroup
}
852 853
\unexpanded
\def
\mfunction
#
1
%
854
{
\begingroup
855
\math_tags_mfunctiontxt
{
#
1
}
\c_apply_function
856
\math_mfunction_styled
{
#
1
}
%
857
\endgroup
}
858 859
\unexpanded
\def
\mfunctionlabeltext
#
1
%
860
{
\begingroup
861
\math_tags_mfunctionlab
{
#
1
}
\c_apply_function
862
\math_mfunction_styled
{
\mathlabeltext
{
#
1
}}
%
863
\endgroup
}
864 865
\let
\math_tags_mfunctiontxt
\gobbletwoarguments
866
\let
\math_tags_mfunctionlab
\gobbletwoarguments
867 868
\unexpanded
\def
\math_tags_mo_indeed
#
1
{
\begingroup
\c_attr_mathcategory
\plusone
#
1
\endgroup
}
869
\unexpanded
\def
\math_tags_mi_indeed
#
1
{
\begingroup
\c_attr_mathcategory
\plustwo
#
1
\endgroup
}
870
\unexpanded
\def
\math_tags_mn_indeed
#
1
{
\begingroup
\mathupright
\c_attr_mathcategory
\plusthree
\math_set_o_both
#
1
\endgroup
}
871
\unexpanded
\def
\math_tags_ms_indeed
#
1
{
\begingroup
\mathupright
\c_attr_mathcategory
\plusfour
\math_set_p_both
#
1
\endgroup
}
% todo: mathoptext
872 873
\newconditional
\c_apply_function
874 875
\unexpanded
\def
\math_tags_apply
#
1
#
2
%
876
{
\begingroup
877
\settrue
\c_apply_function
878
#
1
%
879
\endgroup
880
\begingroup
881
% todo: auto ()
882
#
2
%
883
\endgroup
}
884 885
\appendtoks
886
\let
\math_tags_mfunctiontxt
\clf_tagmfunctiontxt
887
\let
\math_tags_mfunctionlab
\clf_tagmfunctionlab
888
\let
\math_tags_mo
\math_tags_mo_indeed
889
\let
\math_tags_mi
\math_tags_mi_indeed
890
\let
\math_tags_mn
\math_tags_mn_indeed
891
\let
\math_tags_ms
\math_tags_ms_indeed
892
\to
\everyenableelements
893 894
\appendtoks
895
\let
\mo
\math_tags_mo
896
\let
\mi
\math_tags_mi
897
\let
\mn
\math_tags_mn
898
\let
\ms
\math_tags_ms
899
\let
\apply
\math_tags_apply
900
\to
\everymathematics
901 902
% \def\mlimitsfunction #1{\mathlimopcomm{{\mr#1}}
903
% \def\mnolimitsfunction#1{\mathnolopcomm{{\mr#1}}
904 905
% %D Taco posted this solution as response to a mail by Olivier, so let's integrate
906
% %D it here.
907
%
908
% \def\currentmscaledstyle{rm} % will be plugged into the typeface text=ss option
909
%
910
% \unexpanded\def\math_function_style_opnolimits #1{\mathop{\mscaledtext{#1}}\nolimits}
911
% \unexpanded\def\math_function_style_mfunction #1{\mscaledtext{\math_tags_function{#1}}}
912
% \unexpanded\def\math_function_style_mfunctionlabeltext#1{\mscaledtext{\math_tags_functionlabeltext{#1}}}
913
%
914
% \unexpanded\def\setmathfunctionstyle#1% rm ss tt (can be made faster if needed)
915
% {\doifsomething{#1}
916
% {\def\currentmscaledstyle{#1}%
917
% \let\mathopnolimits \math_function_style_opnolimits
918
% \let\mfunction \math_function_style_mfunction
919
% \let\mfunctionlabeltext\math_function_style_mfunctionlabeltext}}
920 921
\def
\currentmscaledstyle
{
rm
}
% will be plugged into the typeface text=ss option
922 923
\unexpanded
\def
\mscaledtext
#
1
%
924
{
\mathchoice
925
{
\hbox
{
\csname
\currentmscaledstyle
\endcsname
\tf
#
1
}}
926
{
\hbox
{
\csname
\currentmscaledstyle
\endcsname
\tf
#
1
}}
927
{
\hbox
{
\csname
\currentmscaledstyle
\endcsname
\tfx
#
1
}}
928
{
\hbox
{
\csname
\currentmscaledstyle
\endcsname
\tfxx
#
1
}}}
929 930
\unexpanded
\def
\setmathfunctionstyle
#
1
%
931
{
\setupmathematics
[
\c!functionstyle
=#
1
]
}
% for old times sake
932 933
%D Usage:
934
%D
935
%D \starttyping
936
%D \setmathfunctionstyle\fontstyle % or {rm} or {ss} or ..
937
%D \rm test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
938
%D \ss test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
939
%D \tt test $\sin{(x^{\sin(x^{\sin(x)})})}$ test
940
%D \stoptyping
941 942
%D \macros
943
%D {nonknuthmode, donknuthmode}
944
%D
945
%D The underscore is frequently used in manuals but unfortunately \TEX\ prefers
946
%D it to be a math specific character. And since computer modern fonts didn't
947
%D have an underscore, one had to use commands to fake one. Nowadays we do
948
%D have underscores in latin modern, and since all other fonts have them, we
949
%D decided to get away from the restriction to use the underscore character in
950
%D text mode.
951
%D
952
%D \starttyping
953
%D \def\test#1{#1}
954
%D
955
%D \nonknuthmode $x_2$ x_2 \test{$x_2$} \test{x_2}
956
%D
957
%D \donknuthmode $x_2$ x_2 \test{$x_2$} \test{x_2}
958
%D \stoptyping
959
%D
960
%D The result is as expected: the first line typesets ok, while the second
961
%D one triggers an error message.
962 963
\setnewconstant
\activemathcharcode
"
8
0
0
0
964 965
\newtoks
\activatedmathcharacters
966 967
\unexpanded
\def
\activatemathcharacter
#
1
%
968
{
\appendtoks
969
\global\mathcode
#
1
=
\activemathcharcode
970
\to
\activatedmathcharacters
}
971 972
\def
\activatemathcharacters
973
{
\the
\activatedmathcharacters
}
974 975
% beware, not runtime, so has to happen at format generation
976 977
\activatemathcharacter
\circumflexasciicode
978
\activatemathcharacter
\underscoreasciicode
979
\activatemathcharacter
\ampersandasciicode
980 981
\appendtoks
982
\edef
\p_ampersand
{
\mathematicsparameter
\s!ampersand
}
%
983
\ifx
\p_ampersand
\v!normal
984
\let
\specialmathaligntab
\normalmathaligntab
985
\else
986
\let
\specialmathaligntab
\mathampersand
987
\fi
988
\to
\everysetupmathematics
989 990
%D A simplified version of this code is:
991
%D
992
%D \starttyping
993
%D \catcode"26=12
994
%D
995
%D \bgroup
996
%D \global\mathcode"26="8000
997
%D
998
%D \catcode"26=4
999
%D
1000
%D \xdef\normalmathaligntab{&}
1001
%D
1002
%D \catcode"26=13
1003
%D
1004
%D \global\everymath{\def&{\normalmathaligntab}}
1005
%D \egroup
1006
%D \stoptyping
1007
%D
1008
%D The following works okay:
1009
%D
1010
%D \starttyping
1011
%D A & B
1012
%D \stoptyping
1013
%D
1014
%D As does:
1015
%D
1016
%D \starttyping
1017
%D $A \Umathchar"2"0"26 B$
1018
%D \stoptyping
1019
%D
1020
%D But the next code:
1021
%D
1022
%D \starttyping
1023
%D $A \char"26 B$
1024
%D \stoptyping
1025
%D
1026
%D fails with: \type{Misplaced alignment tab character &} and here is the
1027
%D reason.
1028
%D
1029
%D When we have a letter or other category a check happens for an active
1030
%D character and when it has one then it gets expanded and fed back into the
1031
%D scanner (sort of).
1032
%D
1033
%D A \type {\char} is also fed back as raw character and again when it's letter
1034
%D of other goes through the same process.
1035
%D
1036
%D This means that we cannot have a definition like:
1037
%D
1038
%D \starttyping
1039
%D \def\AND{\char"26\relax}
1040
%D \stoptyping
1041
%D
1042
%D that can be used in math mode, which is why the cweb macros do:
1043
%D
1044
%D \starttyping
1045
%D \def\AND{\def\AND{\mathchar"2026\relax}\AND}
1046
%D \stoptyping
1047
%D
1048
%D Maybe we need an option to treat chars like chars.
1049 1050
% \activatemathcharacter\primeasciicode
1051 1052
% not used:
1053
%
1054
% \mathcode\spaceasciicode\activemathcharcode
1055
%
1056
% not used:
1057
%
1058
% \bgroup
1059
% \catcode\underscoreasciicode\activecatcode
1060
% \doglobal\appendtoks
1061
% \mathcode\underscoreasciicode\activemathcharcode
1062
% \let_\activemathunderscore
1063
% \to \everymathematics
1064
% \egroup
1065 1066
% Here follows some plain legacy: primes.
1067
%
1068
% The \let\prime\math_prime_indeed might become an obsolete as we have \doubleprime
1069
% and \tripleprime and collapsing can nicely handle the script then.
1070
%
1071
% Collapsing to 0x2033 and 0x2034 happens elsewhere.
1072
%
1073
% \switchtobodyfont[modern]
1074
% \switchtobodyfont[cambria]
1075
% \switchtobodyfont[xits]
1076
% \switchtobodyfont[minion]
1077
% \setupbodyfont[dejavu]
1078
%
1079
% \startbuffer
1080
% \def\SampleLine#1{%
1081
% \NC#1
1082
% \NC\switchtobodyfont[#1]$f^2$ % 1
1083
% \NC\switchtobodyfont[#1]$f\prime^2$ % 2
1084
% \NC\switchtobodyfont[#1]$f\prime\prime^2$ % 3
1085
% \NC\switchtobodyfont[#1]$f\prime\prime\prime^2$ % 4
1086
% \NC\switchtobodyfont[#1]$f{\prime}^2$ % 5
1087
% \NC\switchtobodyfont[#1]$f{\prime\prime}^2$ % 6
1088
% \NC\switchtobodyfont[#1]$f{\prime\prime\prime}^2$ % 7
1089
% \NC\switchtobodyfont[#1]$f'(x)$ % 8
1090
% \NC\switchtobodyfont[#1]$f''(x)$ % 9
1091
% \NC\switchtobodyfont[#1]$f'''(x)$ % 10
1092
% \NC\NR
1093
% }
1094
%
1095
% \starttabulate[|Tl|Tc|Tc|Tc|Tc|Tc|Tc|Tc|Tc|Tc|Tc|]
1096
% \NC\NC1\NC2\NC3\NC4\NC5\NC6\NC7\NC8\NC9\NC10\NC\NR
1097
% \SampleLine{modern}
1098
% \SampleLine{cambria}
1099
% \SampleLine{xits}
1100
% \SampleLine{minion}
1101
% \stoptabulate
1102
% \stopbuffer
1103
%
1104
% \typebuffer \getbuffer
1105 1106
% most math fonts have messed up primes, just test this: $\prime^{\prime^{\prime}}$
1107 1108
{
\catcode
\circumflexasciicode\othercatcode
\glet
\othercircumflextoken
^
}
1109
{
\catcode
\circumflexasciicode\superscriptcatcode
\glet
\superscriptcircumflextoken
^
}
1110 1111
\ifdefined
\prime
\else
1112
\Umathchardef
\prime
"
0
"
0
"
2
0
3
2
1113
\fi
1114 1115
% \let\math_prime_indeed_normal\prime
1116
%
1117
% \appendtoks
1118
% \let\math_prime_indeed_normal\prime % gets defined later
1119
% \let\mathfontprime\prime % for tracing
1120
% \let\prime\math_prime_indeed % so this is needed
1121
% \to \everydump
1122
%
1123
% \unexpanded\def\math_prime_indeed
1124
% {\iffontchar\textfont\zerocount"FE325\relax
1125
% ^\bgroup
1126
% \expandafter\math_prime_indeed_virtual % virtual mess (using funny signal)
1127
% \else
1128
% % \expandafter\math_prime_indeed_normal % gets collapsed
1129
% \expandafter\math_prime_indeed_crapped % gets collapsed
1130
% \fi}
1131
%
1132
% \def\math_prime_indeed_crapped
1133
% {{^{\math_prime_indeed_normal}}}
1134
%
1135
% % \let\prime\math_prime_indeed
1136
%
1137
% \def\math_prime_indeed_virtual
1138
% {\math_prime_indeed_normal
1139
% \futurelet\nexttoken\math_prime_indeed_choice}
1140
%
1141
% \installcorenamespace{mathprime}
1142
%
1143
% \def\math_prime_indeed_choice
1144
% {\csname\??mathprime
1145
% \ifx '\nexttoken a\else
1146
% \ifx \math_prime_indeed_normal\nexttoken a\else
1147
% \ifx \prime\nexttoken a\else
1148
% \ifx\superscriptcircumflextoken\nexttoken b\else
1149
% \ifx\othercircumflextoken \nexttoken b\else
1150
% c\fi\fi\fi\fi\fi
1151
% \endcsname}
1152
%
1153
% \setvalue{\??mathprime a}#1{\math_prime_indeed_virtual}
1154
% \setvalue{\??mathprime b}#1#2{#2\egroup}
1155
% \setvalue{\??mathprime c}{\egroup}
1156
%
1157
% \let\activemathprime\math_prime_indeed
1158
%
1159
% \bgroup
1160
%
1161
% \catcode\primeasciicode\activecatcode
1162
%
1163
% \global\everymathematics\expandafter{\the\everymathematics\let'\math_prime_indeed} % todo: do this at the lua end
1164
%
1165
% \egroup
1166 1167
% $\char26$ gives an error because it expands to an active character that
1168
% then becomes an & which is then seen as an alignment character; anyway,
1169
% even when we switch like this the diufferen tmeaning only happens when
1170
% we're in math mode which can be delayed till we're in a cell
1171 1172
\bgroup
1173 1174
\catcode
\underscoreasciicode\activecatcode
1175
\catcode
\circumflexasciicode\activecatcode
1176
\catcode
\ampersandasciicode
\activecatcode
1177 1178
\glet
\specialmathaligntab
\normalmathaligntab
1179 1180
\unexpanded
\gdef
\obeymathcatcodes
1181
{
\let
_
\normalsubscript
1182
\let
^
\normalsuperscript
1183
\def
&
\specialmathaligntab
1184
}
1185 1186
\doglobal
\appendtoks
1187
\let
_
\normalsubscript
1188
\let
^
\normalsuperscript
1189
\let
&
\specialmathaligntab
1190
\to
\everymathematics
1191 1192
% \unexpanded\gdef\normalmathampersands
1193
% {\let\specialmathaligntab\mathampersand}
1194 1195
\egroup
1196 1197
\newtoks
\everydonknuthmode
1198
\newtoks
\everynonknuthmode
1199 1200
\newconditional
\knuthmode
1201 1202
\let
\nonknuthmode
\relax
% no longer needed in MkIV
1203
\let
\donknuthmode
\relax
% no longer needed in MkIV
1204 1205
% \def\nonknuthmode
1206
% {\pushcatcodetable
1207
% \setcatcodetable\ctxcatcodes
1208
% \the\everynonknuthmode
1209
% \let\nonknuthmode\relax
1210
% \popcatcodetable}
1211
%
1212
% \def\donknuthmode
1213
% {\pushcatcodetable
1214
% \setcatcodetable\ctxcatcodes
1215
% \the\everydonknuthmode
1216
% \popcatcodetable}
1217
%
1218
% \bgroup
1219
%
1220
% \catcode\underscoreasciicode\activecatcode
1221
% \catcode\circumflexasciicode\activecatcode
1222
% \catcode\ampersandasciicode \activecatcode
1223
%
1224
% \global \everynonknuthmode {\appendtoks
1225
% \let_\normalsubscript
1226
% \let^\normalsuperscript
1227
% \let&\normalmathaligntab % use \def when it's \aligntab
1228
% \to \everymathematics}
1229
%
1230
% \egroup
1231
%
1232
% \appendtoks
1233
% \setfalse\knuthmode
1234
% \catcode\underscoreasciicode\othercatcode
1235
% \catcode\circumflexasciicode\othercatcode
1236
% \catcode\ampersandasciicode \othercatcode
1237
% \to \everynonknuthmode
1238
%
1239
% \appendtoks
1240
% \settrue\knuthmode
1241
% \catcode\underscoreasciicode\subscriptcatcode
1242
% \catcode\circumflexasciicode\superscriptcatcode
1243
% \catcode\ampersandasciicode \alignmentcatcode
1244
% \to \everydonknuthmode
1245
%
1246
% \appendtoks
1247
% \startextendcatcodetable\ctxcatcodes
1248
% \catcode\underscoreasciicode\othercatcode
1249
% \catcode\circumflexasciicode\othercatcode
1250
% \catcode\ampersandasciicode \othercatcode
1251
% \stopextendcatcodetable
1252
% \to \everynonknuthmode
1253
%
1254
% \appendtoks
1255
% \startextendcatcodetable\ctxcatcodes
1256
% \catcode\underscoreasciicode\subscriptcatcode
1257
% \catcode\circumflexasciicode\superscriptcatcode
1258
% \catcode\ampersandasciicode \alignmentcatcode
1259
% \stopextendcatcodetable
1260
% \to \everydonknuthmode
1261 1262
%D Even more drastic (this code will move as nonknuthmode is default now)
1263 1264
% \unexpanded\def\enableasciimode
1265
% {\ctxlua{resolvers.macros.enablecomment()}%
1266
% \glet\enableasciimode\relax}
1267
%
1268
% \unexpanded\def\asciimode
1269
% {\catcodetable\txtcatcodes
1270
% \enableasciimode
1271
% \nonknuthmode}
1272
%
1273
% \unexpanded\def\startasciimode
1274
% {\pushcatcodetable
1275
% \catcodetable\txtcatcodes
1276
% \enableasciimode
1277
% \nonknuthmode}
1278
%
1279
% \unexpanded\def\stopasciimode
1280
% {\popcatcodetable
1281
% \ifconditional\knuthmode\else\donknuthmode\fi}
1282 1283
\unexpanded
\def
\enableasciimode
1284
{
\clf_enableasciimode
}
% relaxes itself
1285 1286
\unexpanded
\def
\asciimode
1287
{
\catcodetable
\txtcatcodes
1288
\clf_enableasciimode
}
1289 1290
\unexpanded
\def
\startasciimode
1291
{
\pushcatcodetable
1292
\catcodetable
\txtcatcodes
1293
\clf_enableasciimode
}
1294 1295
\unexpanded
\def
\stopasciimode
1296
{
\popcatcodetable
}
1297 1298
%D Needed for unicode:
1299 1300
\def
\nulloperator
{
\mathortext
{
\mathop
{
\emptyhbox
}}{
\emptyhbox
}}
1301 1302
%D Memory saver:
1303 1304
\def
\math_basics_check_compact
1305
{
\doifelse
{
\mathematicsparameter
\c!compact
}
\v!yes
1306
\enabledirectives\disabledirectives
[
math
.
virtual
.
optional
]
}
1307 1308
\appendtoks
1309
\ifempty
\currentmathematics
1310
\math_basics_check_compact
% less tracing
1311
\fi
1312
\to
\everysetupmathematics
1313 1314
\setupmathematics
1315
[
\c!compact
=
\v!no
]
1316 1317
% \enabletrackers[typesetters.directions.math]
1318 1319
%D Right||to||left typesetting in math is supported by the \type {align} parameter
1320
%D with as option the \type {bidi} parameter. Of course support for special symbols
1321
%D like square roots depends on the font as well. We probably need to mirror a few
1322
%D more characters.
1323
%D
1324
%D \startbuffer
1325
%D \removeunwantedspaces
1326
%D \m{ ( 1 = 1) }\quad
1327
%D \m{ (123 = 123) }\quad
1328
%D \m{ a ( 1 = 1) b }\quad
1329
%D \m{ a (123 = 123) b }\quad
1330
%D \m{ x = 123 y + (1 / \sqrt {x}) }
1331
%D \stopbuffer
1332
%D
1333
%D \typebuffer
1334
%D
1335
%D \starttabulate[|T|T||]
1336
%D \HL
1337
%D \NC align \NC bidi \NC \NC \NR
1338
%D \HL
1339
%D \NC l2r \NC no \NC \setupmathematics[bidi=no] \getbuffer \NC \NR
1340
%D \NC l2r \NC yes \NC \setupmathematics[bidi=yes] \getbuffer \NC \NR
1341
%D \NC r2l \NC no \NC \setupmathematics[align=r2l,bidi=no] \getbuffer \NC \NR
1342
%D \NC r2l \NC yes \NC \setupmathematics[align=r2l,bidi=yes] \getbuffer \NC \NR
1343
%D \HL
1344
%D \stoptabulate
1345 1346
% We will use proper constants when we go numbers instead of XXX.
1347 1348
\newconditional
\c_math_right_to_left
1349 1350
\installcorenamespace
{
mathaligndirection
}
1351 1352
\setvalue
{
\??mathaligndirection
r
2
l
}{
\settrue
\c_math_right_to_left
}
1353
\setvalue
{
\??mathaligndirection\v!righttoleft
}{
\settrue
\c_math_right_to_left
}
1354 1355
\appendtoks
1356
\ifcsname
\??mathaligndirection
\mathematicsparameter
\c!align
\endcsname
1357
\lastnamedcs
1358
\else
1359
\setfalse
\c_math_right_to_left
1360
\fi
1361
\to
\everyswitchmathematics
1362 1363
\unexpanded
\def
\math_basics_synchronize_direction
1364
{
\mathdirection
\ifconditional
\c_math_right_to_left
\directionrighttoleft
\else
\directionlefttoright
\fi
}
1365 1366
% Not \everymathematics as it comes too late and I'm not in the mood for a mixed mode
1367
% kludge now (should be a property of beginmath nodes and passed to callbacks).
1368 1369
\appendtoks
1370
\math_basics_synchronize_direction
1371
\to
\everyswitchmathematics
1372 1373
% experimental (needed for an article)
1374 1375
\installcorenamespace
{
mathbidi
}
1376 1377
\newcount
\c_math_bidi
1378 1379
\def
\math_bidi_enable
{
\clf_setmathdirection
\plusone
\relax
\c_math_bidi
\plusone
}
1380
\def
\math_bidi_disable
{
\clf_setmathdirection
\zerocount
\relax
\c_math_bidi
\attributeunsetvalue
}
1381 1382
\letvalue
{
\??mathbidi\v!yes
}
\math_bidi_enable
1383
\letvalue
{
\??mathbidi\v!no
}
\math_bidi_disable
1384 1385
\appendtoks
1386
\edef
\p_bidi
{
\mathematicsparameter
\c!bidi
}
% still needed ?
1387
\ifcsname
\??mathbidi
\p_bidi
\endcsname\lastnamedcs\else
\math_bidi_disable
\fi
1388
\to
\everysetupmathematics
1389 1390
\appendtoks
1391
\c_attr_mathbidi
\ifconditional
\c_math_right_to_left
\c_math_bidi
\else
\attributeunsetvalue
\fi
1392
\to
\everyswitchmathematics
1393 1394
%D Delayed: greek.
1395
%D
1396
%D \starttyping
1397
%D \usetypescript[cambria]\setupbodyfont[cambria]
1398
%D \startTEXpage
1399
%D $\alpha \mathgreekupright \alpha \mathgreekitalic \alpha$
1400
%D \stopTEXpage
1401
%D \stoptyping
1402 1403
% [lc uc] normal (upright) = 2, italic = 3, none = 0/1
1404 1405
% We can move the setting to the lua end and use abstract numbers instead
1406
% if funny ones here.
1407 1408
\installcorenamespace
{
mathgreek
}
1409 1410
\newconstant
\c_math_greek_attribute
1411 1412
\setvalue
{
\??mathgreek\v!none
}{
1
}
1413
\setvalue
{
\??mathgreek\v!normal
}{
2
}
1414
\setvalue
{
\??mathgreek\v!italic
}{
3
}
1415 1416
% \appendtoks
1417
% \edef\p_sygreek{\mathematicsparameter\s!sygreek}%
1418
% \edef\p_lcgreek{\mathematicsparameter\s!lcgreek}%
1419
% \edef\p_ucgreek{\mathematicsparameter\s!ucgreek}%
1420
% \c_math_greek_attribute"% hex digits
1421
% \csname\??mathgreek\ifcsname\??mathgreek\p_sygreek\endcsname\p_sygreek\else\v!none\fi\endcsname
1422
% \csname\??mathgreek\ifcsname\??mathgreek\p_lcgreek\endcsname\p_lcgreek\else\v!none\fi\endcsname
1423
% \csname\??mathgreek\ifcsname\??mathgreek\p_ucgreek\endcsname\p_ucgreek\else\v!none\fi\endcsname
1424
% \relax
1425
% \ifcase\c_math_greek_attribute
1426
% \c_math_greek_attribute\attributeunsetvalue
1427
% \fi
1428
% \to \everyswitchmathematics
1429 1430
\appendtoks
1431
\edef
\p_sygreek
{
\mathematicsparameter
\s!sygreek
}
% still needed ?
1432
\edef
\p_lcgreek
{
\mathematicsparameter
\s!lcgreek
}
% still needed ?
1433
\edef
\p_ucgreek
{
\mathematicsparameter
\s!ucgreek
}
% still needed ?
1434
\c_math_greek_attribute
"
% hex digits
1435
\ifcsname
\??mathgreek
\p_sygreek
\endcsname\lastnamedcs\else
1
\fi
1436
\ifcsname
\??mathgreek
\p_lcgreek
\endcsname\lastnamedcs\else
1
\fi
1437
\ifcsname
\??mathgreek
\p_ucgreek
\endcsname\lastnamedcs\else
1
\fi
1438
\relax
1439
\ifcase
\c_math_greek_attribute
1440
\c_math_greek_attribute
\attributeunsetvalue
1441
\fi
1442
\to
\everyswitchmathematics
1443 1444
% only used local
1445 1446
\unexpanded
\def
\mathgreekupright
{
\c_attr_mathgreek
"
2
2
2
\relax
}
1447
\unexpanded
\def
\mathgreekitalic
{
\c_attr_mathgreek
"
3
3
3
\relax
}
1448
\unexpanded
\def
\mathgreekdefault
{
\c_attr_mathgreek
"
0
0
0
\relax
}
1449 1450
\let
\mathgreeknormal
\mathgreekupright
1451
\let
\mathgreeknone
\mathgreekdefault
1452 1453
\appendtoks
1454
\c_attr_mathgreek
\c_math_greek_attribute
1455
\to
\everymathematics
1456 1457
\setupmathematics
1458
[
\s!sygreek
=
\v!normal
,
1459
\s!lcgreek
=
\v!italic
,
1460
\s!ucgreek
=
\v!normal
]
% was: none
1461 1462
%D Math collapsing (ligatures)
1463 1464
\installcorenamespace
{
mathcollapsing
}
1465 1466
\setnewconstant
\c_math_collapsing_attribute
\attributeunsetvalue
1467 1468
\letvalue
{
\??mathcollapsing
1
}
\plusone
% specials
1469
\letvalue
{
\??mathcollapsing
2
}
\plustwo
% specials + mathlist
1470
\letvalue
{
\??mathcollapsing
3
}
\plusthree
% mathlist + specials
1471
\letvalue
{
\??mathcollapsing\v!none
}
\attributeunsetvalue
1472
\letvalue
{
\??mathcollapsing\v!reset
}
\attributeunsetvalue
1473 1474
\def
\math_collapsing_initialize
1475
{
\ifnum
\c_math_collapsing_attribute
=
\attributeunsetvalue
\else
1476
\clf_initializemathcollapsing
% one time
1477
\glet
\math_collapsing_initialize
\relax
1478
\fi
}
1479 1480
\appendtoks
1481
\edef
\p_collapsing
{
\mathematicsparameter
\s!collapsing
}
%
1482
\c_math_collapsing_attribute
1483
\ifcsname
\??mathcollapsing
\p_collapsing
\endcsname\lastnamedcs\else
\attributeunsetvalue
\fi
1484
\relax
1485
\to
\everyswitchmathematics
% only in mathematics
1486 1487
\appendtoks
1488
\math_collapsing_initialize
1489
\c_attr_mathcollapsing
\c_math_collapsing_attribute
1490
\to
\everymathematics
1491 1492
\setupmathematics
1493
[
\s!collapsing
=
1
]
% so that we at least do primes
1494 1495
%D Math italics (experiment)
1496 1497
%D We need keys but what names to use and because we have hardcoded solution
1498
%D we can stick to numbers.
1499 1500
\installcorenamespace
{
mathitalics
}
1501 1502
\setnewconstant
\c_math_italics_attribute
\attributeunsetvalue
1503 1504
\letvalue
{
\??mathitalics
1
}
\plusone
% fontitalics
1505
\letvalue
{
\??mathitalics
2
}
\plustwo
% fontdata
1506
\letvalue
{
\??mathitalics
3
}
\plusthree
% quad based
1507
\letvalue
{
\??mathitalics
4
}
\plusfour
% combination of 1 and 3
1508
\letvalue
{
\??mathitalics\v!none
}
\attributeunsetvalue
1509
\letvalue
{
\??mathitalics\v!reset
}
\attributeunsetvalue
1510 1511
\def
\math_italics_initialize
1512
{
\ifnum
\c_math_italics_attribute
=
\attributeunsetvalue
\else
1513
\clf_initializemathitalics
% one time
1514
\glet
\math_italics_initialize
\relax
1515
\fi
}
1516 1517
\appendtoks
1518
\edef
\p_italics
{
\mathematicsparameter
\s!italics
}
%
1519
\c_math_italics_attribute
1520
\ifcsname
\??mathitalics
\p_italics
\endcsname\lastnamedcs\else
\attributeunsetvalue
\fi
1521
\relax
1522
% \math_italics_initialize
1523
\to
\everyswitchmathematics
% only in mathematics
1524 1525
\appendtoks
1526
\math_italics_initialize
1527
\c_attr_mathitalics
\c_math_italics_attribute
1528
\to
\everymathematics
1529 1530
% \setupmathematics % done later
1531
% [\s!italics=3] % 4 is probably better
1532 1533
% looks nicer but can generate bogus csnames
1534
%
1535
% \setvalue{\??mathitalics1}{\math_italics_initialize\c_math_italics_attribute\plusone } % fontitalics
1536
% \setvalue{\??mathitalics2}{\math_italics_initialize\c_math_italics_attribute\plustwo } % fontdata
1537
% \setvalue{\??mathitalics3}{\math_italics_initialize\c_math_italics_attribute\plusthree} % quad based
1538
% \setvalue{\??mathitalics4}{\math_italics_initialize\c_math_italics_attribute\plusfour } % combination of 1 and 3
1539
%
1540
% \appendtoks
1541
% \c_math_italics_attribute\attributeunsetvalue
1542
% \csname\??mathitalics\mathematicsparameter\s!italics\endcsname
1543
% \to \everyswitchmathematics % only in mathematics
1544 1545
%D Math kerns (experiment)
1546 1547
\installcorenamespace
{
mathkernpairs
}
1548 1549
\setnewconstant
\c_math_kernpairs_attribute
\attributeunsetvalue
% no real need for an extra constant
1550 1551
\def
\math_kernpairs_initialize
1552
{
\ifnum
\c_math_kernpairs_attribute
=
\attributeunsetvalue
\else
1553
\clf_initializemathkernpairs
% one time
1554
\glet
\math_kernpairs_initialize
\relax
1555
\fi
}
1556 1557
\appendtoks
1558
\edef
\p_kernpairs
{
\mathematicsparameter
\s!kernpairs
}
%
1559
\c_math_kernpairs_attribute
\ifx
\p_kernpairs
\v!yes
\plusone
\else
\attributeunsetvalue
\fi\relax
1560
\to
\everyswitchmathematics
% only in mathematics
1561 1562
\appendtoks
1563
\math_kernpairs_initialize
1564
\c_attr_mathkernpairs
\c_math_kernpairs_attribute
1565
\to
\everymathematics
1566 1567
\setupmathematics
1568
[
\s!kernpairs
=
\v!no
]
1569 1570
%D \macros
1571
%D {enablemathpunctuation,disablemathpunctuation}
1572
%D
1573
%D \startbuffer
1574
%D \enablemathpunctuation$(1,2) (1, 2) (1{,}2) \hbox{foo, not bar}$
1575
%D \stopbuffer
1576
%D
1577
%D \typebuffer
1578
%D
1579
%D \blank{\getbuffer}\blank
1580 1581
% \newconditional\automathpunctuation
1582
%
1583
% \unexpanded\def\enablemathpunctuation {\settrue \automathpunctuation}
1584
% \unexpanded\def\disablemathpunctuation{\setfalse\automathpunctuation}
1585
%
1586
% \appendtoks
1587
% \doifelse{\mathematicsparameter\v!autopunctuation}\v!yes\settrue\setfalse\automathpunctuation
1588
% \to \everyswitchmathematics
1589
%
1590
% \setupmathematics
1591
% [\v!autopunctuation=\v!no]
1592
%
1593
% \def\math_punctuation_next{\ifx\nexttoken\blankspace\signalcharacter\fi}
1594
%
1595
% \unexpanded\def\math_punctuation_comma {\textcomma \futurelet\nexttoken\math_punctuation_next}
1596
% \unexpanded\def\math_punctuation_period{\textperiod\futurelet\nexttoken\math_punctuation_next}
1597
%
1598
% \setnewconstant\c_math_comma "002C
1599
% \setnewconstant\c_math_period "002E
1600
% \setnewconstant\c_math_special"8000
1601
%
1602
% \bgroup
1603
%
1604
% \catcode\c_math_comma \activecatcode
1605
% \catcode\c_math_period\activecatcode
1606
%
1607
% \unexpanded\gdef\math_punctuation_initialize_indeed
1608
% {\mathcode\c_math_comma \c_math_special
1609
% \mathcode\c_math_period\c_math_special
1610
% \let,\math_punctuation_comma
1611
% \let.\math_punctuation_period
1612
% \c_attr_mathpunctuation\plustwo}
1613
%
1614
% \unexpanded\gdef\math_punctuation_initialize_yes
1615
% {\c_attr_mathpunctuation\plustwo}
1616
%
1617
% \unexpanded\gdef\math_punctuation_initialize_nop
1618
% {\c_attr_mathpunctuation\plusone}
1619
%
1620
% \egroup
1621
%
1622
% \appendtoks
1623
% \ifconditional\automathpunctuation
1624
% \math_punctuation_initialize_indeed
1625
% \math_punctuation_initialize_yes
1626
% \let\enablemathpunctuation \math_punctuation_initialize_yes
1627
% \let\disablemathpunctuation\math_punctuation_initialize_nop
1628
% \fi
1629
% \to \everymathematics
1630 1631
% Later I will look again into a \LUATEX\ based solution. It only makes sense
1632
% to delegate to \LUA\ when we have more variants and need analysis (experimental
1633
% trickery removed for a while).
1634 1635
% \def\math_punctuation_comma_next {\ifx\nexttoken\blankspace\mathpunct\else\mathord\fi{\textcomma }}
1636
% \def\math_punctuation_period_next{\ifx\nexttoken\blankspace\mathpunct\else\mathord\fi{\textperiod}}
1637
%
1638
% \unexpanded\def\math_punctuation_nop_comma {\mathpunct{\textcomma}}
1639
% \unexpanded\def\math_punctuation_nop_period{\mathord{\textperiod}}
1640
%
1641
% \unexpanded\def\math_punctuation_all_comma {\futurelet\nexttoken\math_punctuation_comma_next}
1642
% \unexpanded\def\math_punctuation_all_period{\futurelet\nexttoken\math_punctuation_period_next}
1643
%
1644
% \let\math_punctuation_yes_comma \math_punctuation_all_comma
1645
% \let\math_punctuation_yes_period\math_punctuation_nop_period
1646
%
1647
% The next one is more efficient as it produces more flat noad lists for numbers.
1648 1649
\setnewconstant
\c_math_comma
"
0
0
2
C
1650
\setnewconstant
\c_math_period
"
0
0
2
E
1651
%setnewconstant\c_math_colon "003A
1652
\setnewconstant
\c_math_semicolon
"
0
0
3
B
1653
\setnewconstant
\c_math_special
"
8
0
0
0
1654 1655
% todo: use \Umathclass\c_math_comma\mathpunctcode etc for temporary switching
1656 1657
\def
\math_set_o_comma
{
\Umathcode
\c_math_comma
\mathordcode
\zerocount
\c_math_comma
}
1658
\def
\math_set_p_comma
{
\Umathcode
\c_math_comma
\mathpunctcode\zerocount
\c_math_comma
}
1659
\def
\math_set_o_period
{
\Umathcode
\c_math_period
\mathordcode
\zerocount
\c_math_period
}
1660
\def
\math_set_p_period
{
\Umathcode
\c_math_period
\mathpunctcode\zerocount
\c_math_period
}
1661
\def
\math_set_o_semicolon
{
\Umathcode
\c_math_semicolon
\mathordcode
\zerocount
\c_math_semicolon
}
1662
\def
\math_set_p_semicolon
{
\Umathcode
\c_math_semicolon
\mathpunctcode\zerocount
\c_math_semicolon
}
1663 1664
\edef
\math_set_o_both
{
\math_set_o_period
\math_set_o_comma
}
1665
\edef
\math_set_p_both
{
\math_set_p_period
\math_set_p_comma
}
1666 1667
\unexpanded
\def
\math_punctuation_nop_comma
{
\begingroup
\math_set_p_comma
,
\endgroup
}
1668
\unexpanded
\def
\math_punctuation_nop_period
{
\begingroup
\math_set_o_period
.
\endgroup
}
1669
\unexpanded
\def
\math_punctuation_nop_semicolon
{
\begingroup
\math_set_p_semicolon
;
\endgroup
}
1670 1671
% todo: use new lookahead stuff
1672 1673
\unexpanded
\def
\math_punctuation_all_comma
{
\futurelet
\nexttoken
\math_punctuation_comma_next
}
1674
\unexpanded
\def
\math_punctuation_all_period
{
\futurelet
\nexttoken
\math_punctuation_period_next
}
1675
\unexpanded
\def
\math_punctuation_all_semicolon
{
\futurelet
\nexttoken
\math_punctuation_semicolon_next
}
1676 1677
\let
\math_punctuation_yes_comma
\math_punctuation_all_comma
1678
\let
\math_punctuation_yes_period
\math_punctuation_nop_period
1679
\let
\math_punctuation_yes_semicolon
\math_punctuation_all_semicolon
1680 1681
\def
\math_punctuation_comma_next
{
\begingroup\Umathcode
\c_math_comma
\ifx
\nexttoken
\blankspace
\mathordcode
\else
\mathordcode
\fi
\zerocount
\c_math_comma
,
\endgroup
}
1682
\def
\math_punctuation_period_next
{
\begingroup\Umathcode
\c_math_period
\ifx
\nexttoken
\blankspace
\mathordcode
\else
\mathordcode
\fi
\zerocount
\c_math_period
.
\endgroup
}
1683
\def
\math_punctuation_semicolon_next
{
\begingroup\Umathcode
\c_math_semicolon
\ifx
\nexttoken
\blankspace
\mathordcode
\else
\mathordcode
\fi
\zerocount
\c_math_semicolon
;
\endgroup
}
1684 1685
\installcorenamespace
{
mathautopunctuation
}
1686 1687
\bgroup
1688 1689
\catcode
\c_math_comma
\activecatcode
1690
\catcode
\c_math_period
\activecatcode
1691
\catcode
\c_math_semicolon
\activecatcode
1692 1693
\setgvalue
{
\??mathautopunctuation\v!no
}
%
1694
{
\let
,
\math_punctuation_nop_comma
1695
\let
.
\math_punctuation_nop_period
1696
\let
;
\math_punctuation_nop_semicolon
}
1697 1698
% more efficient list:
1699
%
1700
% \setgvalue{\??mathautopunctuation\v!no}%
1701
% {\Umathcode\c_math_period\mathordcode \zerocount\c_math_period
1702
% \Umathcode\c_math_comma \mathpunctcode\zerocount\c_math_comma }
1703 1704
\setgvalue
{
\??mathautopunctuation\v!yes
}
%
1705
{
\let
,
\math_punctuation_yes_comma
1706
\let
.
\math_punctuation_yes_period
1707
\let
;
\math_punctuation_nop_semicolon
}
1708 1709
\setgvalue
{
\??mathautopunctuation\v!all
}
%
1710
{
\let
,
\math_punctuation_all_comma
1711
\let
.
\math_punctuation_all_period
1712
\let
;
\math_punctuation_nop_semicolon
}
1713 1714
\setgvalue
{
\??mathautopunctuation
comma
}
%
1715
{
\let
,
\math_punctuation_yes_comma
1716
\let
.
\math_punctuation_yes_period
1717
\let
;
\math_punctuation_nop_semicolon
}
1718 1719
\setgvalue
{
\??mathautopunctuation\v!yes
\string
,
semicolon
}
%
1720
{
\let
,
\math_punctuation_yes_comma
1721
\let
.
\math_punctuation_yes_period
1722
\let
;
\math_punctuation_yes_semicolon
}
1723 1724
\setgvalue
{
\??mathautopunctuation
comma
\string
,
semicolon
}
%
1725
{
\let
,
\math_punctuation_yes_comma
1726
\let
.
\math_punctuation_yes_period
1727
\let
;
\math_punctuation_yes_semicolon
}
1728 1729
\setgvalue
{
\??mathautopunctuation\v!all
\string
,
semicolon
}
%
1730
{
\let
,
\math_punctuation_all_comma
1731
\let
.
\math_punctuation_all_period
1732
\let
;
\math_punctuation_all_semicolon
}
1733 1734
\egroup
1735 1736
% \appendtoks
1737
% \global\mathcode\c_math_comma \c_math_special
1738
% \global\mathcode\c_math_period \c_math_special
1739
% \global\mathcode\c_math_semicolon\c_math_special
1740
% \to \everyjob
1741 1742
% \activatemathcharacter\c_math_comma
1743
% \activatemathcharacter\c_math_period
1744
% \activatemathcharacter\c_math_semicolon
1745 1746
\appendtoks
1747
\mathcode
\c_math_comma
\c_math_special
1748
\mathcode
\c_math_period
\c_math_special
1749
\mathcode
\c_math_semicolon
\c_math_special
1750
\begincsname
\??mathautopunctuation
\mathematicsparameter
\v!autopunctuation
\endcsname
1751
\to
\everymathematics
1752 1753
\appendtoks
1754
\ifcsname
\??mathautopunctuation
\mathematicsparameter
\v!autopunctuation
\endcsname
\else
1755
\letmathematicsparameter
\v!autopunctuation\v!no
1756
\fi
1757
\to
\everysetupmathematics
1758 1759
\def
\enablemathpunctuation
{
\csname
\??mathautopunctuation\v!no
\endcsname
}
1760
\def
\disablemathpunctuation
{
\csname
\??mathautopunctuation\v!yes
\endcsname
}
1761 1762
\setupmathematics
1763
[
\v!autopunctuation
=
\v!no
]
% no | yes | all | comma | yes,semicolon | all,semicolon
1764 1765
%D The consequences of setting this are as follows:
1766
%D
1767
%D \def\TestA#1#2#3%
1768
%D {\ifnum#1=0 \type{#2}\else\setupmathematics[autopunctuation={#2}]$#3$\fi}
1769
%D \def\TestB#1#2%
1770
%D {\NC \TestA{#1}{no} {#2}
1771
%D \NC \TestA{#1}{yes} {#2}
1772
%D \NC \TestA{#1}{yes,semicolon}{#2}
1773
%D \NC \TestA{#1}{all} {#2}
1774
%D \NC \TestA{#1}{all,semicolon}{#2}
1775
%D \NC \NR}
1776
%D \starttabulate[|c|c|c|c|c|]
1777
%D \TestB{0}{}
1778
%D \TestB{1}{(1,2)=(1, 2)}
1779
%D \TestB{1}{(1.2)=(1. 2)}
1780
%D \TestB{1}{(1;2)=(1; 2)}
1781
%D \stoptabulate
1782 1783
%D \macros
1784
%D {mathstyle}
1785
%D
1786
%D If one want to be sure that something is typeset in the appropriate style, \type
1787
%D {\mathstyle} can be used:
1788
%D
1789
%D \starttyping
1790
%D \mathstyle{something}
1791
%D \stoptyping
1792 1793
% \def\mathstyle#1%
1794
% {\mathchoice
1795
% {\displaystyle #1}%
1796
% {\textstyle #1}%
1797
% {\scriptstyle #1}%
1798
% {\scriptscriptstyle#1}}
1799
%
1800
% We now have a primitive operation for this. As the macro overloads a new
1801
% primitive introduced in \LUATEX, we need to use \type {\normalmathstyle} when we
1802
% consult the current math style.
1803
%
1804
% \let \mathstyle \Ustack % spoils cramped
1805
%
1806
% \let \mathstyle \firstofoneargument
1807
%
1808
% 0 = display
1809
% 1 = crampeddisplay
1810
% 2 = text
1811
% 3 = crampedtext
1812
% 4 = script
1813
% 5 = crampedscript
1814
% 6 = scriptscript
1815
% 7 = crampedscriptscript
1816 1817
\def
\uncramped
#
1
%
1818
{{
\ifmathstyle
1819
\or
\displaystyle
\or
1820
\or
\textstyle
\or
1821
\or
\scriptstyle
\or
1822
\or
\scriptscriptstyle
\fi
1823
#
1
}}
1824 1825
\def
\cramped
#
1
%
1826
{{
\ifmathstyle
1827
\crampeddisplaystyle
\or
\or
% 0 -> 1
1828
\crampedtextstyle
\or
\or
% 2 -> 3
1829
\crampedscriptstyle
\or
\or
% 4 -> 5
1830
\crampedscriptscriptstyle
\fi
% 6 -> 7
1831
#
1
}}
1832 1833
\def
\triggermathstyle
#
1
{
\Ustyle\numexpr
#
1
\relax
}
1834
%def\mathstyletrigger#1{\numexpr#1\relax}
1835
\let
\mathstyletrigger
\firstofoneargument
1836 1837
\def
\triggeredmathstyleparameter
#
1
% to bypass the relax
1838
{
\ifcase
\numexpr\normalmathstyle\relax
1839
#
1
\displaystyle
\or
% 0
1840
#
1
\crampeddisplaystyle
\or
% 1
1841
#
1
\textstyle
\or
% 2
1842
#
1
\crampedtextstyle
\or
% 3
1843
#
1
\scriptstyle
\or
% 4
1844
#
1
\crampedscriptstyle
\or
% 5
1845
#
1
\scriptscriptstyle
\or
% 6
1846
#
1
\crampedscriptscriptstyle
\else
1847
% error
1848
\fi
}
1849 1850
\def
\mathstylefont
#
1
% #1 is number (\normalmathstyle)
1851
{
\ifcase
\numexpr
#
1
\relax
1852
\textfont
\or
1853
\textfont
\or
1854
\textfont
\or
1855
\textfont
\or
1856
\scriptfont
\or
1857
\scriptfont
\or
1858
\scriptscriptfont
\or
1859
\scriptscriptfont
\else
1860
\textfont
1861
\fi\fam
}
% was \zerocount
1862 1863
\def
\somemathstylefont
#
1
% #1 is number (\normalmathstyle)
1864
{
\ifcase
\numexpr
#
1
\relax
1865
\textfont
\or
1866
\textfont
\or
1867
\textfont
\or
1868
\textfont
\or
1869
\scriptfont
\or
1870
\scriptfont
\or
1871
\scriptscriptfont
\or
1872
\scriptscriptfont
\else
1873
\textfont
1874
\fi
}
1875 1876
\def
\mathsmallstylefont
#
1
% #1 is number (\normalmathstyle)
1877
{
\ifcase
\numexpr
#
1
\relax
1878
\scriptfont
\or
1879
\scriptfont
\or
1880
\scriptfont
\or
1881
\scriptfont
\or
1882
\scriptscriptfont
\or
1883
\scriptscriptfont
\or
1884
\scriptscriptfont
\or
1885
\scriptscriptfont
\else
1886
\scriptfont
1887
\fi\fam
}
% was \zerocount
1888 1889
\def
\mathstyleface
#
1
% #1 is number (\normalmathstyle)
1890
{
\ifcase
\numexpr
#
1
\relax
1891
\textface
\or
1892
\textface
\or
1893
\textface
\or
1894
\textface
\or
1895
\scriptface
\or
1896
\scriptface
\or
1897
\scriptscriptface
\or
1898
\scriptscriptface
\else
1899
\textface
1900
\fi
}
1901 1902
\def
\mathsmallstyleface
#
1
% #1 is number (\normalmathstyle)
1903
{
\ifcase
\numexpr
#
1
\relax
1904
\scriptface
\or
1905
\scriptface
\or
1906
\scriptface
\or
1907
\scriptface
\or
1908
\scriptscriptface
\or
1909
\scriptscriptface
\or
1910
\scriptscriptface
\or
1911
\scriptscriptface
\else
1912
\scriptface
1913
\fi
}
1914 1915
\def
\mathstylecommand
#
1
#
2
#
3
%
1916
{
\ifcase
\numexpr\normalmathstyle\relax
1917
\expandafter
#
1
\or
1918
\expandafter
#
1
\or
1919
\expandafter
#
1
\or
1920
\expandafter
#
1
\or
1921
\expandafter
#
2
\or
1922
\expandafter
#
2
\or
1923
\expandafter
#
3
\or
1924
\expandafter
#
3
\else
1925
\expandafter
#
1
\fi
}
1926 1927
% \def\textstyleface#1% #1 is number (\normalmathstyle)
1928
% {\ifcase\numexpr#1\relax
1929
% \tf \or
1930
% \tf \or
1931
% \tf \or
1932
% \tf \or
1933
% \tfx \or
1934
% \tfx \or
1935
% \tfxx \or
1936
% \tfxx \else
1937
% \tf
1938
% \fi}
1939 1940
\unexpanded
\def
\verbosemathstyle
#
1
% #1 is number (\normalmathstyle)
1941
{{
\normalexpanded
{
\relax
\darkgray
\ttxx
[
\number
#
1
:
\ifcase
\numexpr
#
1
\relax
1942
display
\or
% 0
1943
crampeddisplay
\or
% 1
1944
text
\or
% 2
1945
crampedtext
\or
% 3
1946
script
\or
% 4
1947
crampedscript
\or
% 5
1948
scriptscript
\or
% 6
1949
crampedscriptscript
\else
% 7
1950
unknown
\fi
]
}}}
1951 1952
\unexpanded
\def
\showmathstyle
{
\verbosemathstyle
\normalmathstyle
}
1953 1954
%D Handy too:
1955 1956
\def
\mathcharwd
{
\fontcharwd
\mathstylefont
\normalmathstyle
}
1957
\def
\mathcharht
{
\fontcharht
\mathstylefont
\normalmathstyle
}
1958
\def
\mathchardp
{
\fontchardp
\mathstylefont
\normalmathstyle
}
1959 1960
%D Some dimension fun:
1961 1962
\let
\mathexheight
\exheight
% also in math-ini.mkiv
1963
\def
\mathemwidth
{
\Umathquad\normalmathstyle
}
% also in math-ini.mkiv
1964 1965
%D A plain inheritance:
1966 1967
\def
\mathpalette
#
1
#
2
%
1968
{
\mathchoice
1969
{
#
1
\displaystyle
{
#
2
}}
%
1970
{
#
1
\textstyle
{
#
2
}}
%
1971
{
#
1
\scriptstyle
{
#
2
}}
%
1972
{
#
1
\scriptscriptstyle
{
#
2
}}}
1973 1974
%D Often we can use:
1975
%D
1976
%D \startbuffer
1977
%D $x^{\mathstylehbox{x^{\mathstylehbox{x}}}}$
1978
%D \stopbuffer
1979
%D
1980
%D \typebuffer \getbuffer
1981 1982
% to be tested: {#1} but it could have side effects
1983 1984
% \unexpanded\def\mathstylehbox#1% sensitive for: a \over b => {a\over b} or \frac{a}{b}
1985
% {\normalexpanded{\hbox\bgroup
1986
% \startimath\triggermathstyle\normalmathstyle}\mathsurround\zeropoint#1\stopimath\egroup}
1987 1988
\unexpanded
\def
\mathstylehbox
#
1
#
% sensitive for: a \over b => {a\over b} or \frac{a}{b}
1989
{
\math_style_hbox
{
#
1
}}
1990 1991
\unexpanded
\def
\math_style_hbox
#
1
#
2
% sensitive for: a \over b => {a\over b} or \frac{a}{b}
1992
{
\normalexpanded
{
\hbox
#
1
\bgroup
1993
\startimath\triggermathstyle
\normalmathstyle
}
\mathsurround
\zeropoint
#
2
\stopimath
\egroup
}
1994 1995
\unexpanded
\def
\mathstylevbox
#
1
%
1996
{
\normalexpanded
{
\vbox
\bgroup
1997
\startimath\triggermathstyle
\normalmathstyle
}
\mathsurround
\zeropoint
#
1
\stopimath
\egroup
}
1998 1999
\unexpanded
\def
\mathstylevcenter
#
1
%
2000
{
\normalexpanded
{
\vcenter
\bgroup
2001
\startimath\triggermathstyle
\normalmathstyle
}
\mathsurround
\zeropoint
#
1
\stopimath
\egroup
}
2002 2003
\unexpanded
\def
\mathstylevcenteredhbox
#
1
%
2004
{
\normalexpanded
{
\vcenter
\bgroup
\hbox
\bgroup
2005
\startimath\triggermathstyle
\normalmathstyle
}
\mathsurround
\zeropoint
#
1
\stopimath
\egroup\egroup
}
2006 2007
\unexpanded
\def
\mathstylevcenteredvbox
#
1
%
2008
{
\normalexpanded
{
\vcenter
\bgroup
\vbox
\bgroup
2009
\startimath\triggermathstyle
\normalmathstyle
}
\mathsurround
\zeropoint
#
1
\stopimath
\egroup\egroup
}
2010 2011
\unexpanded
\def
\setmathsmalltextbox
#
1
#
2
#
%
2012
{
\normalizebodyfontsize
\m_math_text_choice_face
{
\mathsmallstyleface
\normalmathstyle
}
%
2013
\setbox
#
1
#
2
\bgroup
2014
\font_basics_switchtobodyfont
\m_math_text_choice_face
2015
\let
\next
}
2016 2017
\unexpanded
\def
\setmathtextbox
#
1
#
2
#
%
2018
{
\normalizebodyfontsize
\m_math_text_choice_face
{
\mathstyleface
\normalmathstyle
}
%
2019
\setbox
#
1
#
2
\bgroup
2020
\font_basics_switchtobodyfont
\m_math_text_choice_face
2021
\let
\next
}
2022 2023
%D Here is the new mechanism ... it might replace some of the above but we will do
2024
%D that stepwise. Keep in mind that cramped only affects superscripts and even then,
2025
%D only when in a smaller size than normal.
2026
%D
2027
%D \def\TestMe#1%
2028
%D {\NC \ttbf #1
2029
%D \NC \ruledhbox{$\setupmathstyle[#1]x + x_j^2 + x_i^{e^2} + \frac{1}{x}$}
2030
%D \NC \ruledhbox{$\setupmathstyle[#1,small]x + x_j^2 + x_i^{e^2} + \frac{1}{x}$}
2031
%D \NC \NR}
2032
%D
2033
%D \starttabulate[|l|r|l|]
2034
%D \HL
2035
%D \NC \NC \NC \ttbf ...,small \NC \NR
2036
%D \HL
2037
%D \TestMe{text} \TestMe{text,cramped}
2038
%D \TestMe{script} \TestMe{script,cramped}
2039
%D \TestMe{scriptscript} \TestMe{scriptscript,cramped}
2040
%D \TestMe{display} \TestMe{display,cramped}
2041
%D \HL
2042
%D \stoptabulate
2043 2044
\def
\triggerdisplaystyle
2045
{
\ifmathstyle
2046
\displaystyle
\or
2047
\crampeddisplaystyle
\or
2048
\displaystyle
\or
2049
\crampeddisplaystyle
\or
2050
\displaystyle
\or
2051
\crampeddisplaystyle
\or
2052
\displaystyle
\or
2053
\crampeddisplaystyle
\or
2054
\fi
}
2055 2056
\def
\triggertextstyle
2057
{
\ifmathstyle
2058
\textstyle
\or
2059
\crampedtextstyle
\or
2060
\textstyle
\or
2061
\crampedtextstyle
\or
2062
\textstyle
\or
2063
\crampedtextstyle
\or
2064
\textstyle
\or
2065
\crampedtextstyle
\else
2066
\fi
}
2067 2068
\def
\triggerscriptstyle
2069
{
\ifmathstyle
2070
\scriptstyle
\or
2071
\crampedscriptstyle
\or
2072
\scriptstyle
\or
2073
\crampedscriptstyle
\or
2074
\scriptstyle
\or
2075
\crampedscriptstyle
\or
2076
\scriptstyle
\or
2077
\crampedscriptstyle
\or
2078
\fi
}
2079 2080
\def
\triggerscriptscriptstyle
2081
{
\ifmathstyle
2082
\scriptscriptstyle
\or
2083
\crampedscriptscriptstyle
\or
2084
\scriptscriptstyle
\or
2085
\crampedscriptscriptstyle
\or
2086
\scriptscriptstyle
\or
2087
\crampedscriptscriptstyle
\or
2088
\scriptscriptstyle
\or
2089
\crampedscriptscriptstyle
\or
2090
\fi
}
2091 2092
\def
\triggeruncrampedstyle
2093
{
\ifmathstyle
2094
\or
\displaystyle
\or
2095
\or
\textstyle
\or
2096
\or
\scriptstyle
\or
2097
\or
\scriptscriptstyle
\fi
}
2098 2099
\def
\triggercrampedstyle
2100
{
\ifmathstyle
2101
\crampeddisplaystyle
\or
\or
2102
\crampedtextstyle
\or
\or
2103
\crampedscriptstyle
\or
\or
2104
\crampedscriptscriptstyle
\fi
}
2105 2106
\def
\triggersmallstyle
2107
{
\ifmathstyle
2108
\scriptstyle
\or
2109
\crampedscriptstyle
\or
2110
\scriptstyle
\or
2111
\crampedscriptstyle
\or
2112
\scriptscriptstyle
\or
2113
\crampedscriptscriptstyle
\or
2114
\scriptscriptstyle
\or
2115
\crampedscriptscriptstyle
\or
2116
\fi
}
2117 2118
\def
\triggeruncrampedsmallstyle
2119
{
\ifmathstyle
2120
\scriptstyle
\or
2121
\scriptstyle
\or
2122
\scriptstyle
\or
2123
\scriptstyle
\or
2124
\scriptscriptstyle
\or
2125
\scriptscriptstyle
\or
2126
\scriptscriptstyle
\or
2127
\scriptscriptstyle
\or
2128
\fi
}
2129 2130
\def
\triggercrampedsmallstyle
2131
{
\ifmathstyle
2132
\crampedscriptstyle
\or
2133
\crampedscriptstyle
\or
2134
\crampedscriptstyle
\or
2135
\crampedscriptstyle
\or
2136
\crampedscriptscriptstyle
\or
2137
\crampedscriptscriptstyle
\or
2138
\crampedscriptscriptstyle
\or
2139
\crampedscriptscriptstyle
\or
2140
\fi
}
2141 2142
\def
\triggerbigstyle
2143
{
\ifmathstyle
2144
\displaystyle
\or
2145
\crampeddisplaystyle
\or
2146
\textstyle
\or
2147
\crampedtextstyle
\or
2148
\textstyle
\or
2149
\crampedtextstyle
\or
2150
\scriptstyle
\or
2151
\crampedscriptstyle
\or
2152
\fi
}
2153 2154
\def
\triggeruncrampedbigstyle
2155
{
\ifmathstyle
2156
\displaystyle
\or
2157
\displaystyle
\or
2158
\textstyle
\or
2159
\textstyle
\or
2160
\textstyle
\or
2161
\textstyle
\or
2162
\scriptstyle
\or
2163
\scriptstyle
\or
2164
\fi
}
2165 2166
\def
\triggercrampedbigstyle
2167
{
\ifmathstyle
2168
\crampeddisplaystyle
\or
2169
\crampeddisplaystyle
\or
2170
\crampedtextstyle
\or
2171
\crampedtextstyle
\or
2172
\crampedtextstyle
\or
2173
\crampedtextstyle
\or
2174
\crampedscriptstyle
\or
2175
\crampedscriptstyle
\or
2176
\fi
}
2177 2178
\newcount
\c_math_saved_style
2179 2180
\unexpanded
\def
\pushmathstyle
% assumes begingroup .. endgroup
2181
{
\c_math_saved_style
\mathstyle
}
2182 2183
\unexpanded
\def
\popmathstyle
2184
{
\ifnum
\mathstyle
=
\c_math_saved_style
\else
2185
\triggermathstyle
\c_math_saved_style
2186
\fi
}
2187 2188
\installcorenamespace
{
mathstylecommand
}
2189
\installcorenamespace
{
mathstylecache
}
2190 2191
\newconstant
\c_math_styles_state_style
2192
\newconstant
\c_math_styles_state_cramped
2193
\newconstant
\c_math_styles_state_size
2194 2195
\def
\math_style_add_to_cache_choice
{
%
2196
\ifcase
\c_math_styles_state_size
2197
\ifcase
\c_math_styles_state_style
2198
\ifcase
\c_math_styles_state_cramped
2199
\relax
\or
2200
\noexpand
\triggeruncrampedstyle
\or
2201
\noexpand
\triggercrampedstyle
\fi
2202
\or\ifcase
\c_math_styles_state_cramped
2203
\noexpand
\triggerdisplaystyle
\or
2204
\displaystyle
\or
2205
\crampeddisplaystyle
\fi
2206
\or\ifcase
\c_math_styles_state_cramped
2207
\noexpand
\triggertextstyle
\or
2208
\textstyle
\or
2209
\crampedtextstyle
\fi
2210
\or\ifcase
\c_math_styles_state_cramped
2211
\noexpand
\triggerscriptstyle
\or
2212
\scriptstyle
\or
2213
\crampedscriptstyle
\fi
2214
\or\ifcase
\c_math_styles_state_cramped
2215
\noexpand
\triggerscriptscriptstyle
\or
2216
\scriptscriptstyle
\or
2217
\crampedscriptscriptstyle
\fi
2218
\fi
2219
\or
% small
2220
\ifcase
\c_math_styles_state_style
2221
\ifcase
\c_math_styles_state_cramped
2222
\noexpand
\triggersmallstyle
\or
2223
\noexpand
\triggeruncrampedsmallstyle
\or
2224
\noexpand
\triggercrampedsmallstyle
\fi
2225
\or\ifcase
\c_math_styles_state_cramped
2226
\noexpand
\triggerscriptstyle
\or
2227
\scriptstyle
\or
2228
\crampedscriptstyle
\fi
2229
\or\ifcase
\c_math_styles_state_cramped
2230
\noexpand
\triggerscriptstyle
\or
2231
\scriptstyle
\or
2232
\crampedscriptstyle
\fi
2233
\or\ifcase
\c_math_styles_state_cramped
2234
\noexpand
\triggerscriptscriptstyle
\or
2235
\scriptscriptstyle
\or
2236
\crampedscriptscriptstyle
\fi
2237
\or\ifcase
\c_math_styles_state_cramped
2238
\noexpand
\triggerscriptscriptstyle
\or
2239
\scriptscriptstyle
\or
2240
\crampedscriptscriptstyle
\fi
2241
\fi
2242
\or
% large
2243
\ifcase
\c_math_styles_state_style
2244
\ifcase
\c_math_styles_state_cramped
2245
\noexpand
\triggerbigstyle
\or
2246
\noexpand
\triggeruncrampedbigstyle
\or
2247
\noexpand
\triggercrampedbigstyle
\fi
2248
\or\ifcase
\c_math_styles_state_cramped
2249
\noexpand
\triggerdisplaystyle
\or
2250
\displaystyle
\or
2251
\crampeddisplaystyle
\fi
2252
\or\ifcase
\c_math_styles_state_cramped
2253
\noexpand
\triggertextstyle
\or
2254
\textstyle
\or
2255
\crampedtextstyle
\fi
2256
\or\ifcase
\c_math_styles_state_cramped
2257
\noexpand
\triggertextstyle
\or
2258
\textstyle
\or
2259
\crampedtextstyle
\fi
2260
\or\ifcase
\c_math_styles_state_cramped
2261
\noexpand
\triggerscriptstyle
\or
2262
\scriptstyle
\or
2263
\crampedscriptstyle
\fi
2264
\fi
2265
\fi
2266
}
2267 2268
\unexpanded
\def
\math_style_set
#
1
%
2269
{
\edef
\m_math_style_asked
{
#
1
}
%
2270
\ifempty
\m_math_style_asked
\else
2271
\math_style_set_indeed
2272
\fi
}
2273 2274
\let
\setmathstyle
\math_style_set
2275 2276
\def
\installmathstyle
#
1
#
2
%
2277
{
\ifcsname
\??mathstylecommand
#
1
\endcsname
\else
2278
\setvalue
{
\??mathstylecommand
#
1
}{
#
2
}
%
2279
\fi
}
2280 2281
\def
\math_style_collect
#
1
%
2282
{
\csname
\??mathstylecommand
#
1
\endcsname
}
2283 2284
\setvalue
{
\??mathstylecommand\s!display
}{
\c_math_styles_state_style
\plusone
}
2285
\setvalue
{
\??mathstylecommand\s!text
}{
\c_math_styles_state_style
\plustwo
}
2286
\setvalue
{
\??mathstylecommand\s!script
}{
\c_math_styles_state_style
\plusthree
}
2287
\setvalue
{
\??mathstylecommand\s!scriptscript
}{
\c_math_styles_state_style
\plusfour
}
2288 2289
\setvalue
{
\??mathstylecommand\s!uncramped
}{
\c_math_styles_state_cramped
\plusone
}
2290
\setvalue
{
\??mathstylecommand\s!cramped
}{
\c_math_styles_state_cramped
\plustwo
}
2291
\setvalue
{
\??mathstylecommand\v!normal
}{
\c_math_styles_state_cramped
\plusone
}
2292
\setvalue
{
\??mathstylecommand\v!packed
}{
\c_math_styles_state_cramped
\plustwo
}
2293 2294
\setvalue
{
\??mathstylecommand\v!small
}{
\c_math_styles_state_size
\plusone
}
2295
\setvalue
{
\??mathstylecommand\v!big
}{
\c_math_styles_state_size
\plustwo
}
2296 2297
\unexpanded
\def
\setupmathstyle
[#
1
]
%
2298
{
\edef
\m_math_style_asked
{
#
1
}
%
2299
\ifempty
\m_math_style_asked
\else
2300
\math_style_set_indeed
2301
\fi
}
2302 2303
\unexpanded
\def
\usemathstyleparameter
#
1
% faster local variant
2304
{
\edef
\m_math_style_asked
{
#
1
\c!mathstyle
}
%
2305
\ifempty
\m_math_style_asked
\else
2306
\math_style_set_indeed
2307
\fi
}
2308 2309
%D \startbuffer
2310
%D \definemathstyle[mystyle][scriptscript]
2311
%D
2312
%D $text\startmathstyle[mystyle]scriptscript\stopmathstyle text$
2313
%D \stopbuffer
2314
%D
2315
%D \typebuffer \blank \start \getbuffer \stop \blank
2316 2317
\installcorenamespace
{
mathstyle
}
2318 2319
\unexpanded
\def
\definemathstyle
2320
{
\dodoubleargument
\math_style_define
}
2321 2322
\def
\math_style_define
[#
1
][#
2
]
%
2323
{
\c_math_styles_state_style
\zerocount
2324
\c_math_styles_state_cramped
\zerocount
2325
\c_math_styles_state_size
\zerocount
2326
\rawprocesscommacommand
[#
2
]
\math_style_collect
2327
\expandafter\let\csname
\??mathstyle
#
1
\normalexpanded
{
\endcsname
\math_style_add_to_cache_choice
}}
2328 2329
% \def\math_style_set_indeed
2330
% {\csname\??mathstyle
2331
% \ifcsname\??mathstyle\m_math_style_asked\endcsname
2332
% \m_math_style_asked
2333
% \else
2334
% \??mathstyle
2335
% \fi
2336
% \endcsname}
2337
%
2338
% \setvalue{\??mathstyle\??mathstyle}%
2339
% {\csname\??mathstylecache
2340
% \ifcsname\??mathstylecache\m_math_style_asked\endcsname
2341
% \m_math_style_asked
2342
% \else
2343
% \??mathstylecache
2344
% \fi
2345
% \endcsname}
2346
%
2347
% \setvalue{\??mathstylecache\??mathstylecache}%
2348
% {\c_math_styles_state_style \zerocount
2349
% \c_math_styles_state_cramped\zerocount
2350
% \c_math_styles_state_size \zerocount
2351
% \rawprocesscommacommand[\m_math_style_asked]\math_style_collect
2352
% \expandafter\glet\csname\??mathstylecache\m_math_style_asked\normalexpanded{\endcsname\math_style_add_to_cache_choice}%
2353
% \csname\??mathstylecache\m_math_style_asked\endcsname}
2354 2355
\def
\math_style_set_indeed
2356
{
\ifcsname
\??mathstyle
\m_math_style_asked
\endcsname
2357
\lastnamedcs
2358
\else
2359
\math_style_set_mathstyle_mathstyle
2360
\fi
}
2361 2362
\def
\math_style_set_mathstyle_mathstyle
2363
{
\ifcsname
\??mathstylecache
\m_math_style_asked
\endcsname
2364
\lastnamedcs
2365
\else
2366
\math_style_set_mathstyle_mathstylecache
2367
\fi
}
2368 2369
\def
\math_style_set_mathstyle_mathstylecache
2370
{
\c_math_styles_state_style
\zerocount
2371
\c_math_styles_state_cramped
\zerocount
2372
\c_math_styles_state_size
\zerocount
2373
\rawprocesscommacommand
[
\m_math_style_asked
]
\math_style_collect
2374
\expandafter
\glet
\csname
\??mathstylecache
\m_math_style_asked
\normalexpanded
{
\endcsname
\math_style_add_to_cache_choice
}
%
2375
\csname
\??mathstylecache
\m_math_style_asked
\endcsname
}
2376 2377
\letvalue
{
\??mathstyle
\??mathstyle
}
\math_style_set_mathstyle_mathstyle
% still needed?
2378
\letvalue
{
\??mathstylecache\??mathstylecache
}
\math_style_set_mathstyle_mathstylecache
% still needed?
2379 2380
%D \startbuffer
2381
%D $x\begingroup\setupmathstyle[script]x\endgroup x$
2382
%D $x{\setupmathstyle[script]x}x$
2383
%D $x\startmathstyle[script]x\stopmathstyle x$
2384
%D \stopbuffer
2385
%D
2386
%D \typebuffer \getbuffer
2387 2388
\unexpanded
\def
\startmathstyle
[#
1
]
%
2389
{
\edef
\m_math_style_asked
{
#
1
}
%
2390
\ifempty
\m_math_style_asked
2391
\let
\stopmathstyle
\relax
2392
\else
2393
\bgroup
2394
\math_style_set_indeed
2395
\let
\stopmathstyle
\egroup
2396
\fi
}
2397 2398
\let
\stopmathstyle
\relax
2399 2400
\unexpanded
\def
\startusemathstyleparameter
#
1
%
2401
{
\edef
\m_math_style_asked
{
#
1
\c!mathstyle
}
%
2402
\ifempty
\m_math_style_asked
2403
\let
\stopusemathstyleparameter
\relax
2404
\else
2405
\bgroup
2406
\math_style_set_indeed
2407
\let
\stopusemathstyleparameter
\egroup
2408
\fi
}
2409 2410
\let
\stopusemathstyleparameter
\relax
2411 2412
%D Something similar can be used in the (re|)|definition of \type {\text}. This
2413
%D version is a variation on the one in the math module (see \type{m-math} and|/|or
2414
%D \type {m-newmat}).
2415 2416
\let
\m_math_text_choice_face
\relax
2417 2418
% if needed we can get rid of the normalize (predo in font code)
2419 2420
% \def\math_text_choice_font#1#2#%
2421
% {\normalizebodyfontsize\m_math_text_choice_face{\mathstyleface\normalmathstyle}%
2422
% \hbox#2\bgroup
2423
% \font_basics_switchtobodyfont\m_math_text_choice_face
2424
% #1%
2425
% \let\next}
2426 2427
% \def\math_text_choice_word#1#2#%
2428
% {\normalizebodyfontsize\m_math_text_choice_face{\mathstyleface\normalmathstyle}%
2429
% \hbox#2\bgroup
2430
% \font_basics_switchtobodyfont\m_math_text_choice_face
2431
% #1%
2432
% \nospacing % \normalnospaces\plusone
2433
% \let\next}
2434 2435
%D We accept a low level box specification so that one can make helpers:
2436
%D
2437
%D \startbuffer
2438
%D \startformula
2439
%D \startalign[m=2,align={middle}]
2440
%D \NC \text to 6cm{One\hfill} \NC a = 1 \NR
2441
%D \NC \text to 6cm{One Two\hfill} \NC b = 2 \NR
2442
%D \NC \text to 6cm{One Two Three\hfill} \NC c = 3 \NR
2443
%D \stopalign
2444
%D \stopformula
2445
%D \stopbuffer
2446
%D
2447
%D \typebuffer \getbuffer
2448 2449
\def
\math_text_choice_font
#
1
#
2
#
%
2450
{
\normalizebodyfontsize
\m_math_text_choice_face
{
\mathstyleface
\normalmathstyle
}
%
2451
\hbox
#
2
\bgroup
2452
\bgroup
2453
\aftergroup\hss
2454
\aftergroup
\egroup
2455
\hss
2456
\font_basics_switchtobodyfont
\m_math_text_choice_face
2457
#
1
%
2458
\let
\next
}
2459 2460
\def
\math_text_choice_word
#
1
#
2
#
%
2461
{
\normalizebodyfontsize
\m_math_text_choice_face
{
\mathstyleface
\normalmathstyle
}
%
2462
\hbox
#
2
\bgroup
2463
\bgroup
2464
\aftergroup\hss
2465
\aftergroup
\egroup
2466
\hss
2467
\font_basics_switchtobodyfont
\m_math_text_choice_face
2468
#
1
%
2469
\nospacing
% \normalnospaces\plusone
2470
\let
\next
}
2471 2472
% \ruledhbox{$\mathtext{abc ffi}$}
2473
% \ruledhbox{$\mathword{abc ffi}$}
2474 2475
% I need to decide:
2476
%
2477
%mathscriptboxmode \zerocount % no kerning
2478
%mathscriptboxmode \plusone % lists
2479
\mathscriptboxmode
\plustwo
% lists and boxes
2480
\mathscriptcharmode
\plusone
% lists and boxes
2481
%mathscriptboxmode \plusthree % lists and boxes with \boundary=1 (also for testing and demo)
2482
\mathrulethicknessmode
\plusone
% adaptive
2483 2484
\unexpanded
\def
\mathtext
{
\mathortext
{
\math_text_choice_font
\relax
}
\hbox
}
2485
\unexpanded
\def
\mathword
{
\mathortext
{
\math_text_choice_word
\relax
}
\hbox
}
2486 2487
\unexpanded
\def
\mathtexttf
{
\mathortext
{
\math_text_choice_font
\tf
}
\hbox
}
2488
\unexpanded
\def
\mathtextit
{
\mathortext
{
\math_text_choice_font
\it
}
\hbox
}
2489
\unexpanded
\def
\mathtextsl
{
\mathortext
{
\math_text_choice_font
\sl
}
\hbox
}
2490
\unexpanded
\def
\mathtextbf
{
\mathortext
{
\math_text_choice_font
\bf
}
\hbox
}
2491
\unexpanded
\def
\mathtextbi
{
\mathortext
{
\math_text_choice_font
\bi
}
\hbox
}
2492
\unexpanded
\def
\mathtextbs
{
\mathortext
{
\math_text_choice_font
\bs
}
\hbox
}
2493 2494
\unexpanded
\def
\mathwordtf
{
\mathortext
{
\math_text_choice_word
\tf
}
\hbox
}
2495
\unexpanded
\def
\mathwordit
{
\mathortext
{
\math_text_choice_word
\it
}
\hbox
}
2496
\unexpanded
\def
\mathwordsl
{
\mathortext
{
\math_text_choice_word
\sl
}
\hbox
}
2497
\unexpanded
\def
\mathwordbf
{
\mathortext
{
\math_text_choice_word
\bf
}
\hbox
}
2498
\unexpanded
\def
\mathwordbi
{
\mathortext
{
\math_text_choice_word
\bi
}
\hbox
}
2499
\unexpanded
\def
\mathwordbs
{
\mathortext
{
\math_text_choice_word
\bs
}
\hbox
}
2500 2501
%D Safeguard against redefinitions:
2502 2503
\appendtoks
2504
\let
\_
\normalunderscore
% is textunderscore or fakeunderscore
2505
\to
\everymathematics
2506 2507
%D Because we may overload \type {\text} in other (structuring) macros, we say:
2508 2509
\appendtoks
\let
\text
\mathtext
\to
\everymathematics
2510 2511
%D The next code is derived from plain \TEX. The names will change!
2512 2513
\newcount
\interdisplaylinepenalty
\interdisplaylinepenalty
\plushundred
2514 2515
% Actually, not using an if saves one macro so there is no penalty
2516
% for splitting up this macro.
2517
%
2518
% \newif\ifdt@p
2519
%
2520
% \def\displ@y
2521
% {\global\dt@ptrue
2522
% \math_openup\displayopenupvalue % was \openup\jot
2523
% \everycr
2524
% {\noalign
2525
% {\ifdt@p
2526
% \global\dt@pfalse
2527
% \ifdim\prevdepth>-\thousandpoint
2528
% \vskip-\lineskiplimit
2529
% \vskip\normallineskiplimit
2530
% \fi
2531
% \else
2532
% \penalty\interdisplaylinepenalty
2533
% \fi}}}
2534 2535
\newtoks
\mathdisplayaligntweaks
2536 2537
% this can become an option:
2538 2539
\unexpanded
\def
\math_display_align_hack
% I don't like the global, maybe we should push and pop
2540
{
\glet
\math_display_align_hack_indeed
\math_display_align_hack_remove_skip
2541
\math_openup
\displayopenupvalue
% was \math_openup\jot
2542
\everycr
{
\noalign
{
\math_display_align_hack_indeed
}}}
2543 2544
\def
\math_display_align_hack_remove_skip
2545
{
\ifdim
\prevdepth
>
-
\thousandpoint
2546
\vskip\dimexpr
-
\lineskiplimit
+
\normallineskiplimit
\relax
2547
\fi
2548
\glet
\math_display_align_hack_indeed
\math_display_align_hack_insert_penalty
}
2549 2550
\def
\math_display_align_hack_insert_penalty
2551
{
\penalty
\interdisplaylinepenalty
}
2552 2553
\appendtoks
2554
\math_display_align_hack
2555
\to
\mathdisplayaligntweaks
2556 2557
%D Text in math:
2558 2559
\unexpanded
\def
\mathortext
2560
{
\ifmmode
2561
\expandafter
\firstoftwoarguments
2562
\else
2563
\expandafter
\secondoftwoarguments
2564
\fi
}
2565 2566
% \defineactivecharacter _ {\mathortext{_}{\_}} text_text $a^2$
2567 2568
% force text mode, will be overloaded later
2569 2570
\ifdefined
\text
\else
\let
\text
\hbox
\fi
2571 2572
% \unexpanded\def\mathoptext#1{\mathop{\text{#1}}}
2573 2574
\unexpanded
\def
\mathoptext
2575
{
\normalizebodyfontsize
\m_math_text_choice_face
{
\mathstyleface
\normalmathstyle
}
%
2576
%\showmathstyle
2577
\dowithnextbox
2578
{
\mathop
{
\box
\nextbox
}}
%
2579
\hbox
\bgroup
\font_basics_switchtobodyfont
\m_math_text_choice_face
\let
\next
}
2580 2581
% new:
2582 2583
% \startsetups math:morespacing
2584
% \Umathordordspacing\textstyle 1mu plus .5mu minus .25mu\relax
2585
% \stopsetups
2586
%
2587
% \setupmathematics
2588
% [setups=math:morespacing]
2589 2590
\appendtoks
2591
\edef
\p_setups
{
\mathematicsparameter
\c!setups
}
%
2592
\ifempty
\p_setups
\else
2593
\directsetup
\p_setups
2594
\fi
2595
\to
\everyswitchmathematics
2596 2597
% new:
2598 2599
\unexpanded
\def
\smallmathsymbol
#
1
%
2600
{
\mathematics
{
\mathbin
{
\normalexpanded
{
\raise
.
1
5
\exheight
\hbox
{
\normalstartimath
2601
\triggermathstyle
{
\the\numexpr\normalmathstyle
+
2
\relax
}
#
1
%
2602
\normalstopimath
}}}}}
2603 2604
% this should be a primitive:
2605 2606
\def
\mathextensiblecode
#
1
#
2
{
\clf_extensiblecode
\numexpr
#
1
\relax\numexpr
#
2
\relax
}
2607
\def
\mathhorizontalcode
#
1
#
2
{
\clf_horizontalcode
\numexpr
#
1
\relax\numexpr
#
2
\relax
}
2608 2609
% experimental:
2610 2611
%D \starttyping
2612
%D \enabletrackers[math.openedup]
2613
%D
2614
%D \dorecurse{10}{\dorecurse{#1}{whatever }}
2615
%D
2616
%D \startitemize[packed]
2617
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2618
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2619
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2620
%D \stopitemize
2621
%D \startitemize[packed,columns]
2622
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2623
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2624
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2625
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2626
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2627
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2628
%D \stopitemize
2629
%D
2630
%D \dorecurse{5}{\dorecurse{#1}{whatever }\openedupimath{\frac{1}{2}} }
2631
%D
2632
%D \startitemize[packed,columns]
2633
%D \startitem whatever \openedupimath{1+2} whatever
2634
%D \startitem whatever \openedupimath{1+2} whatever
2635
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2636
%D \startitem whatever \openedupimath{1+2} whatever
2637
%D \startitem whatever \openedupimath{1+2} whatever
2638
%D \stopitemize
2639
%D
2640
%D \dorecurse{5}{\dorecurse{#1}{whatever }\openedupimath{1+2} }
2641
%D
2642
%D \startitemize[packed]
2643
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2644
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2645
%D \startitem whatever \openedupimath{\frac{1}{2}} whatever
2646
%D \stopitemize
2647
%D
2648
%D \dorecurse{10}{whatever }
2649
%D \dorecurse {5}{\dorecurse{#1}{whatever }\openedupimath{\frac{1}{2}} }
2650
%D \dorecurse{10}{whatever }
2651
%D \stoptyping
2652 2653
\def
\m_math_inline_openup_ht
{
\dimexpr
\ifinsidecolumns
\strutdp
\else
\lineheight
\fi
/
\plusfour
\relax
}
2654
\def
\m_math_inline_openup_dp
{
\dimexpr
\ifinsidecolumns
\strutdp
\else
\lineheight
\fi
/
\plusfour
\relax
}
2655 2656
% \def\m_math_inline_openup_ht{\dimexpr\lineheight/\ifinsidecolumns\pluseight\else\plusfour\fi\relax}
2657
% \def\m_math_inline_openup_dp{\dimexpr\lineheight/\ifinsidecolumns\pluseight\else\plusfour\fi\relax}
2658 2659
\installtextracker
2660
{
math
.
openedup
}
2661
{
\let
\math_inline_openup_start_yes
\math_inline_openup_traced_start
}
2662
{
\let
\math_inline_openup_start_yes
\math_inline_openup_normal_start
}
2663 2664
\unexpanded
\def
\math_inline_openup_normal_start
2665
{
\scratchheight
\dimexpr\ht
\scratchbox
+
\m_math_inline_openup_ht
\relax
2666
\scratchdepth
\dimexpr\dp
\scratchbox
+
\m_math_inline_openup_dp
\relax
2667
\vrule
\s!width
\zeropoint
\s!height
\scratchheight
\s!depth
\scratchdepth
\relax
2668
\begingroup
2669
\let
\math_inline_openup_stop
\math_inline_openup_normal_stop
}
2670 2671
\unexpanded
\def
\math_inline_openup_normal_stop
2672
{
\endgroup
2673
\vrule
\s!width
\zeropoint
\s!height
\scratchheight
\s!depth
\scratchdepth
\relax
}
2674 2675
\unexpanded
\def
\math_inline_openup_traced_start
2676
{
\scratchtopoffset
\ht
\scratchbox
2677
\scratchbottomoffset
\dp
\scratchbox
2678
\scratchheight
\dimexpr
\scratchtopoffset
+
\m_math_inline_openup_ht
\relax
2679
\scratchdepth
\dimexpr
\scratchbottomoffset
+
\m_math_inline_openup_dp
\relax
2680
\vrule
\s!width
\zeropoint
\s!height
\scratchheight
\s!depth
\scratchdepth
\relax
2681
\begingroup
2682
\dofastcoloractivation
{
darkred
}
%
2683
\vrule
\s!width
\emwidth
\s!height
\scratchheight
\s!depth
-
\scratchtopoffset
\relax
2684
\endgroup
2685
\kern
-
\emwidth
2686
\begingroup
2687
\let
\math_inline_openup_stop
\math_inline_openup_traced_stop
}
2688 2689
\unexpanded
\def
\math_inline_openup_traced_stop
2690
{
\endgroup
2691
\kern
-
\emwidth
2692
\begingroup
2693
\dofastcoloractivation
{
darkblue
}
%
2694
\vrule
\s!width
\emwidth
\s!height
-
\scratchbottomoffset
\s!depth
\scratchdepth
\relax
2695
\endgroup
2696
\vrule
\s!width
\zeropoint
\s!height
\scratchheight
\s!depth
\scratchdepth
\relax
}
2697 2698
\let
\math_inline_openup_start_yes
\math_inline_openup_normal_start
2699
\let
\math_inline_openup_stop
\relax
2700 2701
\def
\math_inline_openup_start_nop
2702
{
\let
\math_inline_openup_stop
\relax
}
2703 2704
\unexpanded
\def
\openedupimath
2705
{
\dontleavehmode
2706
\begingroup
2707
\ifmmode
2708
\expandafter
\openedupimath_math
2709
\else
2710
\expandafter
\openedupimath_text
2711
\fi
}
2712 2713
\unexpanded
\def
\openedupimath_math
#
1
%
2714
{
\setbox
\scratchbox\mathstylehbox
{
#
1
}
%
2715
\ifdim
\ht
\scratchbox
>
\strutht
2716
\math_inline_openup_start_yes
2717
\orelse\ifdim\dp
\scratchbox
>
\strutdp
2718
\math_inline_openup_start_yes
2719
\else
2720
\math_inline_openup_start_nop
2721
\fi
2722
#
1
%
2723
\math_inline_openup_stop
2724
\endgroup
}
2725 2726
\unexpanded
\def
\openedupimath_text
#
1
%
2727
{
\setbox
\scratchbox
\hbox
{
\startimath
#
1
\stopimath
}
%
2728
\ifdim
\ht
\scratchbox
>
\strutht
2729
\math_inline_openup_start_yes
2730
\orelse\ifdim\dp
\scratchbox
>
\strutdp
2731
\math_inline_openup_start_yes
2732
\else
2733
\math_inline_openup_start_nop
2734
\fi
2735
\startimath
2736
#
1
%
2737
\stopimath
2738
\math_inline_openup_stop
2739
\endgroup
}
2740 2741
% Also handy, especially for units:
2742
%
2743
% 0x002B=plus 0x2212=minus 0x2013=endash
2744 2745
\unexpanded
\def
\mathplus
{
+
}
2746
\unexpanded
\def
\mathminus
{
\ifmmode
\else\iffontchar\font
`
−−
\else
\fi\fi
}
2747
\unexpanded
\def
\mathplusminus
{
±
}
2748 2749
%D The \type {\displaywidth} is only known inside a display formula, so we need to catch
2750
%D it when still zero.
2751 2752
\def
\checkeddisplaywidth
% hsize if zero
2753
{
\dimexpr
2754
\ifzeropt
\displaywidth
2755
\hsize
2756
\else
2757
\displaywidth
2758
\fi
2759
\relax
}
2760 2761
\def
\maximizeddisplaywidth
% larger than zero but within hsize
2762
{
\dimexpr
2763
\ifzeropt
\displaywidth
2764
\hsize
2765
\orelse\ifdim\displaywidth
>
\hsize
2766
\hsize
2767
\else
2768
\displaywidth
2769
\fi
2770
\relax
}
2771 2772
%D Experiment: (todo: same switch as italic, using \type {\everyswitchmathematics}).
2773 2774
\newcount
\c_math_domain_attribute
2775 2776
\def
\math_domain_initialize
2777
{
\ifnum
\c_math_domain_attribute
=
\attributeunsetvalue
\else
2778
\clf_initializemathdomain
% one time
2779
\glet
\math_domain_initialize
\relax
2780
\fi
}
2781 2782
\appendtoks
2783
\edef
\p_domain
{
\mathematicsparameter
\c!domain
}
%
2784
\ifempty
\p_domain
2785
\c_math_domain_attribute
\attributeunsetvalue
2786
\else
2787
\c_math_domain_attribute
\clf_getmathdomain
\p_domain
\relax
2788
\math_domain_initialize
2789
\fi
2790
\to
\everyswitchmathematics
% only in mathematics
2791 2792
\appendtoks
2793
\c_attr_mathdomain
\c_math_domain_attribute
2794
\to
\everymathematics
2795 2796
\setupmathematics
2797
[
\s!italics
=
3
]
% for the moment only this one makes sense .. still experimental
2798 2799
%D For special purposed we set this one:
2800 2801
\installcorenamespace
{
mathrules
}
2802 2803
\unexpanded
\def
\enablemathrules
{
\letgvalue
{
\??mathrules
\fontclass
}
\plusone
}
2804 2805
\appendtoks
2806
\mathrulesmode\ifcsname
\??mathrules
\fontclass
\endcsname
2807
\lastnamedcs
2808
\else
2809
\zerocount
2810
\fi
2811
\mathrulesfam
\zerocount
2812
\to
\everymathematics
2813 2814
%D Maybe:
2815 2816
% \starttabulate[|||c|c|]
2817
% \BC positive \BC negative \BC text \BC math \NC \NR
2818
% \NC \tex {f1} \tex {hairspace} \tex{,} \NC \tex {b1} \tex {neghairspace} \NC {\darkred\vl}\f1{\darkblue\vl} \NC ${\darkred\vl}\f1{\darkblue\vl}$ \NC \NR
2819
% \NC \tex {f2} \tex {thinspace} \tex{:} \NC \tex {b2} \tex {negthinspace} \tex{!} \NC {\darkred\vl}\f2{\darkblue\vl} \NC ${\darkred\vl}\f2{\darkblue\vl}$ \NC \NR
2820
% \NC \tex {f3} \tex {medspace} \tex{;} \NC \tex {b3} \tex {negmedspace} \NC {\darkred\vl}\f3{\darkblue\vl} \NC ${\darkred\vl}\f3{\darkblue\vl}$ \NC \NR
2821
% \NC \tex {f4} \tex {thickspace} \NC \tex {b4} \tex {negthickspace} \NC {\darkred\vl}\f4{\darkblue\vl} \NC ${\darkred\vl}\f4{\darkblue\vl}$ \NC \NR
2822
% \NC \tex {f5} \tex {enspace} \NC \tex {b5} \NC {\darkred\vl}\f5{\darkblue\vl} \NC ${\darkred\vl}\f5{\darkblue\vl}$ \NC \NR
2823
% \NC \tex {f6} \tex {emspace} \NC \tex {b6} \NC {\darkred\vl}\f6{\darkblue\vl} \NC ${\darkred\vl}\f6{\darkblue\vl}$ \NC \NR
2824
% \stoptabulate
2825 2826
% \unexpanded\def\negenspace{\kern-.5\emwidth}
2827
% \unexpanded\def\negemspace{\kern- \emwidth}
2828
%
2829
% \unexpanded\def\math_f#1%
2830
% {\ifcase#1\or
2831
% \hairspace
2832
% \or
2833
% \thinspace
2834
% \or
2835
% \medspace
2836
% \or
2837
% \thickspace
2838
% \or
2839
% \enspace
2840
% \or
2841
% \emspace
2842
% \fi}
2843
%
2844
% \unexpanded\def\math_b#1%
2845
% {\ifcase#1\or
2846
% \neghairspace
2847
% \or
2848
% \negthinspace
2849
% \or
2850
% \negmedspace
2851
% \or
2852
% \negthickspace
2853
% \or
2854
% \negenspace
2855
% \or
2856
% \negemspace
2857
% \fi}
2858
%
2859
% \appendtoks
2860
% \let\f\math_f
2861
% \let\b\math_b
2862
% \to \everymathematics
2863 2864
%D Experiment
2865 2866
\unexpanded
\def
\math_scripts_stack
2867
{
\c_attr_mathunstack
\attributeunsetvalue
}
2868 2869
\unexpanded
\def
\math_scripts_unstack
2870
{
\clf_enablescriptunstacking
2871
\c_attr_mathunstack
\plusone
}
2872 2873
\appendtoks
2874
\let
\stackscripts
\math_scripts_stack
2875
\let
\unstackscripts
\math_scripts_unstack
2876
\to
\everymathematics
2877 2878
%D Expensive (tracing and inject) but a primitive (using factors) is tricky as we
2879
%D want this frozen support.
2880 2881
% \def\math_openup_parameter#1#2%
2882
% {\ifzeropt#1\displaystyle \orelse\ifdim#1\displaystyle =\maxdimen\else\frozen#1\displaystyle #2#1\displaystyle \fi
2883
% \ifzeropt#1\crampeddisplaystyle \orelse\ifdim#1\crampeddisplaystyle =\maxdimen\else\frozen#1\crampeddisplaystyle #2#1\crampeddisplaystyle \fi
2884
% \ifzeropt#1\textstyle \orelse\ifdim#1\textstyle =\maxdimen\else\frozen#1\textstyle #2#1\textstyle \fi
2885
% \ifzeropt#1\crampedtextstyle \orelse\ifdim#1\crampedtextstyle =\maxdimen\else\frozen#1\crampedtextstyle #2#1\crampedtextstyle \fi
2886
% \ifzeropt#1\scriptstyle \orelse\ifdim#1\scriptstyle =\maxdimen\else\frozen#1\scriptstyle #2#1\scriptstyle \fi
2887
% \ifzeropt#1\crampedscriptstyle \orelse\ifdim#1\crampedscriptstyle =\maxdimen\else\frozen#1\crampedscriptstyle #2#1\crampedscriptstyle \fi
2888
% \ifzeropt#1\scriptscriptstyle \orelse\ifdim#1\scriptscriptstyle =\maxdimen\else\frozen#1\scriptscriptstyle #2#1\scriptscriptstyle \fi
2889
% \ifzeropt#1\crampedscriptscriptstyle\orelse\ifdim#1\crampedscriptscriptstyle=\maxdimen\else\frozen#1\crampedscriptscriptstyle#2#1\crampedscriptscriptstyle\fi}
2890 2891
% \def\mdim#1#2%
2892
% {\ifcase\ifzeropt#1#2\plusone\orelse\ifdim#1#2=\maxdimen\plusone\else\zerocount\fi}
2893
%
2894
% \def\mdim
2895
% {\afterassignment\mmdim\scratchdimen}
2896
%
2897
% \def\mmdim
2898
% {\ifcase\ifzeropt\scratchdimen\plusone\orelse\ifdim\scratchdimen=\maxdimen\plusone\else\zerocount\fi}
2899
%
2900
% \def\math_openup_parameter#1#2%
2901
% {\ifcondition\mdim#1\displaystyle \frozen#1\displaystyle #2\dimexpr#1\displaystyle \relax\fi
2902
% \ifcondition\mdim#1\crampeddisplaystyle \frozen#1\crampeddisplaystyle #2\dimexpr#1\crampeddisplaystyle \relax\fi
2903
% \ifcondition\mdim#1\textstyle \frozen#1\textstyle #2\dimexpr#1\textstyle \relax\fi
2904
% \ifcondition\mdim#1\crampedtextstyle \frozen#1\crampedtextstyle #2\dimexpr#1\crampedtextstyle \relax\fi
2905
% \ifcondition\mdim#1\scriptstyle \frozen#1\scriptstyle #2\dimexpr#1\scriptstyle \relax\fi
2906
% \ifcondition\mdim#1\crampedscriptstyle \frozen#1\crampedscriptstyle #2\dimexpr#1\crampedscriptstyle \relax\fi
2907
% \ifcondition\mdim#1\scriptscriptstyle \frozen#1\scriptscriptstyle #2\dimexpr#1\scriptscriptstyle \relax\fi
2908
% \ifcondition\mdim#1\crampedscriptscriptstyle\frozen#1\crampedscriptscriptstyle#2\dimexpr#1\crampedscriptscriptstyle\relax\fi}
2909 2910
% \ifmathparameter : 0=zero, 1=set, 2=unset (les stracing clutter this way)
2911 2912
%D New stuff:
2913
%D
2914
%D \starttyping
2915
%D $\mathopenupparameter\Umathradicalvgap{10.5}\sqrt[3]{x}$
2916
%D \stoptyping
2917 2918
\unexpanded
\def
\mathopenupparameter
#
1
#
2
%
2919
{
\ifmathparameter
#
1
\displaystyle
\or\frozen
#
1
\displaystyle
#
2
#
1
\displaystyle
\fi
2920
\ifmathparameter
#
1
\crampeddisplaystyle
\or\frozen
#
1
\crampeddisplaystyle
#
2
#
1
\crampeddisplaystyle
\fi
2921
\ifmathparameter
#
1
\textstyle
\or\frozen
#
1
\textstyle
#
2
#
1
\textstyle
\fi
2922
\ifmathparameter
#
1
\crampedtextstyle
\or\frozen
#
1
\crampedtextstyle
#
2
#
1
\crampedtextstyle
\fi
2923
\ifmathparameter
#
1
\scriptstyle
\or\frozen
#
1
\scriptstyle
#
2
#
1
\scriptstyle
\fi
2924
\ifmathparameter
#
1
\crampedscriptstyle
\or\frozen
#
1
\crampedscriptstyle
#
2
#
1
\crampedscriptstyle
\fi
2925
\ifmathparameter
#
1
\scriptscriptstyle
\or\frozen
#
1
\scriptscriptstyle
#
2
#
1
\scriptscriptstyle
\fi
2926
\ifmathparameter
#
1
\crampedscriptscriptstyle\or\frozen
#
1
\crampedscriptscriptstyle
#
2
#
1
\crampedscriptscriptstyle\fi
}
2927 2928
%D New stuff:
2929
%D
2930
%D \startbuffer
2931
%D $x\mathopen {!}+123+\mathclose {!}x$
2932
%D $x\tomathopen ! +123+\tomathclose ! x$
2933
%D $x\mathclose {!}+123+\mathopen {!}x$
2934
%D $x\tomathclose ! +123+\tomathopen ! x$
2935
%D $x ! +123+ ! x$
2936
%D \stopbuffer
2937
%D
2938
%D \typebuffer
2939
%D
2940
%D \startlines
2941
%D \getbuffer
2942
%D \stoplines
2943 2944
\unexpanded
\def
\tomathord
{
\Umathclass
\zerocount
}
2945
\unexpanded
\def
\tomathop
{
\Umathclass
\plusone
}
% \mathinfix
2946
\unexpanded
\def
\tomathbin
{
\Umathclass
\plustwo
}
2947
\unexpanded
\def
\tomathrel
{
\Umathclass
\plusthree
}
2948
\unexpanded
\def
\tomathopen
{
\Umathclass
\plusfour
}
% \mathprefix
2949
\unexpanded
\def
\tomathclose
{
\Umathclass
\plusfive
}
% \mathsuffix
2950
\unexpanded
\def
\tomathpunct
{
\Umathclass
\plussix
}
2951 2952
%D Prescripts. These work in \CONTEXT\ because we have the super- and subscript
2953
%D triggers enabled as active characters but when we would have
2954
%D
2955
%D \starttyping
2956
%D \catcode\underscoreasciicode\subscriptcatcode
2957
%D \catcode\circumflexasciicode\superscriptcatcode
2958
%D \stoptyping
2959
%D
2960
%D we also need the next line to disable character escaping via \type {^} in
2961
%D math mode:
2962
%D
2963
%D \startbuffer
2964
%D \blank \hbox{
2965
%D \ruledhbox{${\tf X} ^1 _2 ^^3 __4$}
2966
%D \ruledhbox{${\tf X} ^1 $}
2967
%D \ruledhbox{${\tf X} _2 $}
2968
%D \ruledhbox{${\tf X} ^^3 $}
2969
%D \ruledhbox{${\tf X} __4$}
2970
%D \ruledhbox{${\tf X} ^1 _2 $}
2971
%D \ruledhbox{${\tf X} ^1 ^^3 $}
2972
%D \ruledhbox{${\tf X} ^1 __4$}
2973
%D \ruledhbox{${\tf X} _2 ^^3 $}
2974
%D \ruledhbox{${\tf X} _2 __4$}
2975
%D \ruledhbox{${\tf X} ^1 _2 ^^3 $}
2976
%D \ruledhbox{${\tf X} ^1 _2 __4$}
2977
%D \ruledhbox{${\tf X} _2 ^^3 $}
2978
%D \ruledhbox{${\tf X} _2 ^^3 __4$}
2979
%D \ruledhbox{${\tf X} ^^3 __4$}
2980
%D } \blank
2981
%D
2982
%D \typebuffer \getbuffer
2983 2984
\normalsupmarkmode
\plusone
% 2 also disable ^[^+] in text mode
2985 2986
\protect
\endinput
2987 2988
% % not used (yet)
2989
%
2990
% \newtoks \everystartimath
2991
% \newtoks \everystopimath
2992
%
2993
% \unexpanded\def\startimath{\Ustartmath\the\everystartimath}
2994
% \unexpanded\def\stopimath {\the\everystopimath\Ustopmath}
2995
%
2996
% \unexpanded\def\m%
2997
% {\relax
2998
% \ifmmode\expandafter\math_m_stay\else\expandafter\math_m_math\fi}
2999
%
3000
% \unexpanded\def\math_m_math#1%
3001
% {\startimath#1\stopimath}
3002
%
3003
% \let\math_m_stay\firstofoneargument
3004