math-ali.mkiv /size: 52 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=math-ali,
3
%D version=2008.10.20,
4
%D title=\CONTEXT\ Math Macros,
5
%D subtitle=Math Alignments,
6
%D author={Hans Hagen, Taco Hoekwater \& Aditya Mahajan},
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
/
Math
Alignments
}
15 16
\unprotect
17 18
%D The code here has been moved from other files. Beware: the \MKII\ and \MKIV\ code
19
%D is not gathered in files with the same name. In the meantime this code has been
20
%D adapted to \MKIV\ but more is possible. The code is somewhat complicated by the
21
%D fact that alignments are tricky with rspect to tagging.
22 23
% export:
24
%
25
% alignment : ok
26
% cases :
27
% matrix : ok
28
% substack :
29 30
%D \macros
31
%D {definemathalignment, setupmathalignment, startmathalignment}
32
%D
33
%D Modules may provide additional alignment features. The following mechanisms are
34
%D provided by the core.
35 36
\newtoks
\t_math_align_a
37
\newtoks
\t_math_align_b
38
\newtoks
\t_math_align_c
39 40
\newskip
\d_math_eqalign_distance
41 42
\unexpanded
\def
\math_eqalign_distance
43
{
\relax
44
\ifdim
\d_math_eqalign_distance
>
\zeropoint
45
% \hskip\d_math_eqalign_distance
46
\tabskip
\d_math_eqalign_distance
47
\fi
48
\mathalignmentparameter
\c!separator
49
\relax
}
50 51
\def
\displayopenupvalue
{
.
2
5
\bodyfontsize
}
52 53
% \def\math_build_eqalign
54
% {\scratchtoks\emptytoks
55
% \d_math_eqalign_distance\mathalignmentparameter\c!distance
56
% \scratchcounterone\mathalignmentparameter\c!m
57
% \scratchcountertwo\mathalignmentparameter\c!n
58
% \normalexpanded{\scratchtoks{\the\scratchtoks\the\t_math_align_a}}%
59
% \scratchcounter\plusone
60
% \dorecurse{\numexpr\scratchcounterone*\scratchcountertwo-\plusone\relax}
61
% {\ifnum\scratchcounter=\scratchcountertwo
62
% \scratchcounter\plusone
63
% \scratchtoks\expandafter{\the\scratchtoks\math_eqalign_distance}%
64
% \else
65
% \advance\scratchcounter\plusone
66
% \fi
67
% \normalexpanded{\scratchtoks{\the\scratchtoks\the\t_math_align_b}}}%
68
% \normalexpanded{\scratchtoks{\the\scratchtoks\the\t_math_align_c}}}
69 70
\def
\math_build_eqalign
71
{
\scratchtoks
\emptytoks
72
\d_math_eqalign_distance
\mathalignmentparameter
\c!distance
\relax
73
\scratchcounterone
\mathalignmentparameter
\c!m
74
\scratchcountertwo
\mathalignmentparameter
\c!n
75
\etoksapp
\scratchtoks
{
\the
\t_math_align_a
}
%
76
\scratchcounter
\plusone
77
\dorecurse
{
\numexpr
\scratchcounterone
*
\scratchcountertwo
-
\plusone
\relax
}
78
{
\ifnum
\scratchcounter
=
\scratchcountertwo
79
\scratchcounter
\plusone
80
\etoksapp
\scratchtoks
{
\math_eqalign_distance
}
%
81
\else
82
\advance
\scratchcounter
\plusone
83
\fi
84
\etoksapp
\scratchtoks
{
\the
\t_math_align_b
}}
%
85
\etoksapp
\scratchtoks
{
\the
\t_math_align_c
}}
86 87
\def
\math_math_in_eqalign
#
1
%
88
{
\startforceddisplaymath
89
\tabskip
\zeropoint
90
\everycr
\emptytoks
91
{{}
#
1
{}}
%
92
\stopforceddisplaymath
}
93 94
\def
\math_text_in_eqalign
#
1
%
95
{
\startimath
96
\tabskip
\zeropoint
97
\everycr
\emptytoks
98
#
1
%
99
\stopimath
}
100 101
\def
\eqalign
#
1
% why no halign here, probably because of displaywidth
102
{
\emptyhbox
103
\mskip\thinmuskip
104
\vcenter
105
{
\math_openup
\displayopenupvalue
% was: \openup\jot
106
\mathsurround
\zeropoint
107
\ialign
{
%
108
\strut
109
\hfil
110
\startforceddisplaymath
{
\alignmark\alignmark
}
\stopforceddisplaymath
111
\aligntab
112
\startforceddisplaymath
{{}
\alignmark\alignmark
{}}
\stopforceddisplaymath
113
\hfil\crcr
114
#
1
\crcr
}
%
115
}
%
116
\mskip\thinmuskip
}
117 118
% preamble is scanned for tabskips so we need the span to prevent an error message
119 120
\setnewconstant
\eqalignmode
\plusone
121 122
% use zeroskipplusfill
123 124
\def
\math_prepare_r_eqalign_no
125
{
\t_math_align_a
126
{
\strut
127
\tabskip
\zeropoint
128
\alignmark\alignmark
% for picking up the number
129
\aligntab
130
\math_first_in_eqalign
131
\hfil
132
\math_left_of_eqalign
133
\span
134
\math_math_in_eqalign
{
\alignmark\alignmark
}
%
135
\math_right_of_eqalign
136
\tabskip
\zeropoint
}
%
137
\t_math_align_b
138
{
\aligntab
139
\math_next_in_eqalign
140
\math_left_of_eqalign
141
\span
142
\math_math_in_eqalign
{
\alignmark\alignmark
}
%
143
\math_right_of_eqalign
144
\tabskip
\zeropoint
}
%
145
\ifnum
\mathraggedstatus
=
\plusone
146
\t_math_align_c
147
{
\hfil
148
\aligntab
149
\span
150
\math_text_in_eqalign
{
\alignmark\alignmark
}
%
151
\tabskip
\zeropoint
}
%
152
\else\ifnum
\mathraggedstatus
=
\plusthree
153
\t_math_align_c
154
{
\hfil
155
\tabskip
\zeropoint
\s!plus
1
\s!fill
156
\aligntab
157
\span
158
\math_text_in_eqalign
{
\alignmark\alignmark
}
%
159
\tabskip
\zeropoint
}
%
160
\else
161
\t_math_align_c
162
{
\hfil
163
\tabskip
\centering
164
\aligntab
165
\span
166
\llap
{
\math_text_in_eqalign
{
\alignmark\alignmark
}}
%
167
\tabskip
\zeropoint
}
%
168
\fi\fi
169
\math_build_eqalign
170
\the
\mathdisplayaligntweaks
171
\tabskip
\centering
}
172 173
\def
\math_prepare_l_eqalign_no
% \checkeddisplaymath
174
{
\t_math_align_a
175
{
\strut
176
\tabskip
\zeropoint
177
\alignmark\alignmark
% for picking up the number
178
\aligntab
179
\math_first_in_eqalign
180
\hfil
181
\math_left_of_eqalign
182
\span
183
\math_math_in_eqalign
{
\alignmark\alignmark
}
%
184
\math_right_of_eqalign
185
\tabskip
\zeropoint
}
%
186
\t_math_align_b
187
{
\aligntab
188
\math_next_in_eqalign
189
\math_left_of_eqalign
190
\span
191
\math_math_in_eqalign
{
\alignmark\alignmark
}
%
192
\math_right_of_eqalign
193
\tabskip
\zeropoint
}
%
194
\ifnum
\mathraggedstatus
=
\plusone
195
\t_math_align_c
196
{
\hfil
197
\aligntab
198
\kern
-
\displaywidth
199
\span
200
\rlap
{
\math_text_in_eqalign
{
\alignmark\alignmark
}}
%
201
\tabskip\displaywidth
}
%
202
\else\ifnum
\mathraggedstatus
=
\plusthree
203
\t_math_align_c
204
{
\hfil
205
\tabskip
\zeropoint
\s!plus
1
\s!fill
206
\aligntab
207
\kern
-
\displaywidth
208
\span
209
\math_rlap
{
\math_text_in_eqalign
{
\alignmark\alignmark
}}
%
210
\tabskip\displaywidth
}
%
211
\else
212
\t_math_align_c
213
{
\hfil
214
\tabskip
\centering
215
\aligntab
216
\kern
-
\displaywidth
217
\span
218
\rlap
{
\math_text_in_eqalign
{
\alignmark\alignmark
}}
%
219
\tabskip\displaywidth
}
%
220
\fi\fi
221
\math_build_eqalign
222
\the
\mathdisplayaligntweaks
223
\tabskip
\centering
}
224 225
\def
\math_halign_checked
226
{
\halign
\ifcase
\eqalignmode
\or
to
\checkeddisplaywidth
\fi
}
227 228
\def
\math_both_eqalign_no_normal
#
1
#
2
%
229
{
\ifmmode
230
\the
\mathdisplayaligntweaks
231
\vcenter
\bgroup
232
\let
\math_finish_eqalign_no
\egroup
233
\else
234
\let
\math_finish_eqalign_no
\relax
235
\fi
236
#
1
%
237
\math_halign_checked
\expandafter
\bgroup
\the
\scratchtoks
\crcr
#
2
\crcr
\egroup
238
\math_finish_eqalign_no
}
239 240
\installcorenamespace
{
mathalignlocation
}
241 242
\setvalue
{
\??mathalignlocation\v!top
}{
\let
\math_alignment_halign_method
\halign\tpack
}
243
\setvalue
{
\??mathalignlocation\v!bottom
}{
\let
\math_alignment_halign_method
\halign\vpack
}
244
\setvalue
{
\??mathalignlocation\v!center
}{
\let
\math_alignment_halign_method
\halign\vcenter
}
245 246
\def
\math_both_eqalign_no_aligned
#
1
%
247
{
\let
\math_alignment_halign_method
\math_halign_checked
248
\ifmmode
249
\the
\mathdisplayaligntweaks
250
\global
\mathnumberstatus
\plusone
251
\ifcase
\mathraggedstatus
252
\def
\math_finish_eqalign_no
{
\crcr
\egroup
}
%
253
\else
% we're in a mathbox
254
\ifcsname
\??mathalignlocation
\mathalignmentparameter
\c!location
\endcsname
255
\lastnamedcs
% top|bottom|center as suggested by HM
256
\else
257
\vcenter
258
\fi
259
\bgroup
260
\def
\math_finish_eqalign_no
{
\crcr
\egroup\egroup
}
%
261
\fi
262
\fi
263
#
1
%
264
\math_alignment_halign_method
\expandafter
\bgroup
\the
\scratchtoks
\crcr
}
265 266
\def
\math_rlap
#
1
%
267
{
\setbox
\scratchbox
\hbox
{
#
1
}
%
268
\ifdim
\wd
\scratchbox
>
\d_math_number_correction
269
\global
\d_math_number_correction
\wd
\scratchbox
270
\fi
271
\box
\scratchbox
272
\global
\mathnumberstatus
\plustwo
}
273 274
\def
\math_handle_eqalign_no_r_normal
{
\math_both_eqalign_no_normal
\math_prepare_r_eqalign_no
}
275
\def
\math_handle_eqalign_no_l_normal
{
\math_both_eqalign_no_normal
\math_prepare_l_eqalign_no
}
276
\def
\math_handle_eqalign_no_r_aligned
{
\math_both_eqalign_no_aligned
\math_prepare_r_eqalign_no
}
277
\def
\math_handle_eqalign_no_l_aligned
{
\math_both_eqalign_no_aligned
\math_prepare_l_eqalign_no
}
278
\def
\math_finish_eqalign_no
{
\crcr
\egroup
}
279 280
\let
\reqalignno
\relax
281
\let
\leqalignno
\relax
282
\let
\eqalignno
\relax
283 284
%D Here we implement the user interface part. We start with basic math alignments:
285 286
\newcount
\c_math_eqalign_column
287
\newconditional
\c_math_eqalign_first
288 289
\newtoks
\everymathalignment
290
\newtoks
\everymathalignmentdone
291 292
\def
\math_alignment_NN
293
{
\dodirectdoubleempty
\math_alignment_NN_indeed
}
294 295
\def
\math_alignment_NN_indeed
[#
1
][#
2
]
%
296
{
\aligntab
297
\strc_formulas_place_number_nested
{
#
1
}{
#
2
}}
298 299
\def
\math_alignment_NR
300
{
\dodirectdoubleempty
\math_alignment_NR_indeed
}
301 302
\def
\math_alignment_NR_indeed
[#
1
][#
2
]
%
303
{
\aligntab
304
\dostoptagged
% finish cell
305
\strc_formulas_place_number_nested
{
#
1
}{
#
2
}
%
306
\math_number_right_of_eqalign
307
\global
\settrue
\c_math_eqalign_first
308
\crcr
309
\dostoptagged
}
% finish row
310 311
\def
\math_alignment_NC
312
{
\relax
313
\ifconditional
\c_math_eqalign_first
314
\ifx
\p_math_alignment_number
\v!auto
315
\strc_formulas_place_number_nested
{
+
}{}
%
316
\fi
317
\global
\setfalse
\c_math_eqalign_first
318
\fi
319
\math_number_left_of_eqalign
320
\aligntab
}
321 322
\def
\math_alignment_EQ
323
{
\NC
=
}
324 325
\installmacrostack
\NC
% maybe more to shared table definitions
326
\installmacrostack
\NN
% maybe more to shared table definitions
327
\installmacrostack
\EQ
% maybe more to shared table definitions
328
\installmacrostack
\NR
% maybe more to shared table definitions
329
\installmacrostack
\BC
% maybe more to shared table definitions
330
\installmacrostack
\EC
% maybe more to shared table definitions
331 332
\appendtoks
333
\push_macro_NC
334
\push_macro_NN
335
\push_macro_EQ
336
\push_macro_NR
337
\let
\NC
\math_alignment_NC
338
\let
\NN
\math_alignment_NN
339
\let
\EQ
\math_alignment_EQ
340
\let
\NR
\math_alignment_NR
341
\global
\settrue
\c_math_eqalign_first
342
\to
\everymathalignment
343 344
\appendtoks
345
\pop_macro_NR
346
\pop_macro_EQ
347
\pop_macro_NN
348
\pop_macro_NC
349
\to
\everymathalignmentdone
350 351
\let
\math_alignment_snap_start
\relax
352
\let
\math_alignment_snap_stop
\relax
353 354
% % experimental:
355
%
356
% \def\math_alignment_snap_start
357
% {\ifgridsnapping
358
% \edef\p_math_alignment_grid{\mathalignmentparameter\c!grid}%
359
% \ifx\p_math_alignment_grid\v!no\else
360
% \snaptogrid[\p_math_alignment_grid]\vbox\bgroup
361
% \fi
362
% \fi}
363
%
364
% \def\math_alignment_snap_stop
365
% {\ifgridsnapping
366
% \ifx\p_math_alignment_grid\v!no\else
367
% \egroup
368
% \fi
369
% \fi}
370
%
371
% % doesn't work well, so:
372 373
\let
\math_alignment_snap_start
\relax
374
\let
\math_alignment_snap_stop
\relax
375 376
% end of experimental
377 378
\newconditional
\c_math_alignment_auto_number
379 380
\unexpanded
\def
\math_alignment_start
#
1
%
381
{
\edef
\currentmathalignment
{
#
1
}
%
382
\dosingleempty
\math_alignment_start_indeed
}
383 384
\def
\math_alignment_start_indeed
[#
1
]
%
385
{
% \begingroup not permitted ($$...assignments...\halign... )
386
\iffirstargument
387
\setupmathalignment
[
\currentmathalignment
][#
1
]
% bad! ungrouped
388
\fi
389
\math_alignment_snap_start
390
\the
\everymathalignment
391
\c_math_eqalign_column
\zerocount
392
\edef
\p_math_alignment_number
{
\mathalignmentparameter
\c!number
}
%
393
\processcommacommand
394
[
\mathalignmentparameter
\c!align
]
%
395
{
\advance
\c_math_eqalign_column
\plusone
\math_eqalign_set_column
}
% takes argument
396
\global
\c_math_eqalign_column
\plusone
397
\dostarttagged
\t!math
\empty
398
\dostarttagged
\t!mathtable
\currentmathalignment
399
\numberedeqalign
}
400 401
\def
\math_alignment_stop
402
{
\math_finish_eqalign_no
403
\dostoptagged
404
\dostoptagged
405
\the
\everymathalignmentdone
406
\math_alignment_snap_stop
}
407 408
\installcorenamespace
{
mathalignment
}
409
\installcorenamespace
{
mathalignmentvariant
}
410 411
\installcommandhandler
\??mathalignment
{
mathalignment
}
\??mathalignment
412 413
\appendtoks
414
\setuevalue
{
\e!start
\currentmathalignment
}{
\math_alignment_start
{
\currentmathalignment
}}
%
415
\setvalue
{
\e!stop
\currentmathalignment
}{
\math_alignment_stop
}
%
416
\to
\everydefinemathalignment
417 418
\setupmathalignment
419
[
\c!n
=
2
,
420
\c!m
=
1
,
421
\c!distance
=
\emwidth
,
422
\c!grid
=
\v!math
]
423 424
\definemathalignment
[
align
]
% default case (this is what amstex users expect)
425
\definemathalignment
[
\v!mathalignment
]
% prefered case (this is cleaner, less clashing)
426 427
% special case.. in case one mistypes ..
428 429
\ifdefined
\startalignment
430 431
\let
\align_math_normal_start
\startalign
432
\let
\align_math_normal_stop
\stopalign
433 434
\let
\align_text_normal_start
\startalignment
435
\let
\align_text_normal_stop
\stopalignment
436 437
\unexpanded
\def
\startalign
438
{
\ifmmode
439
\let
\stopalign
\align_math_normal_stop
% cannot be an unexpanded def ... lookahead in align
440
\expandafter
\align_math_normal_start
441
\else
\ifinformula
442
\let
\stopalign
\align_math_normal_stop
443
\doubleexpandafter
\align_math_normal_start
444
\else
445
\let
\stopalign
\align_text_normal_stop
446
\doubleexpandafter
\align_text_normal_start
447
\fi\fi
}
448 449
\let
\stopalign
\relax
450 451
\unexpanded
\def
\startalignment
452
{
\ifmmode
453
\let
\stopalignment
\align_math_normal_stop
% cannot be an unexpanded def ... lookahead in align
454
\expandafter
\align_math_normal_start
455
\else
\ifinformula
456
\let
\stopalignment
\align_math_normal_stop
% cannot be an unexpanded def ... lookahead in align
457
\doubleexpandafter
\align_math_normal_start
458
\else
459
\let
\stopalignment
\align_text_normal_stop
460
\doubleexpandafter
\align_text_normal_start
461
\fi\fi
}
462 463
\let
\stopalignment
\relax
464 465
\fi
466 467
%
468 469
\unexpanded
\def
\numberedeqalign
470
{
\doifelse
{
\formulaparameter
\c!location
}
\v!left
471
\math_handle_eqalign_no_l_aligned
472
\math_handle_eqalign_no_r_aligned
}
473 474
\def
\math_first_in_eqalign
475
{
\global
\c_math_eqalign_column
\plusone
476
\dostarttagged
\t!mathtablerow
\empty
477
\dostarttagged
\t!mathtablecell
\empty
}
478 479
\def
\math_next_in_eqalign
480
{
\global\advance
\c_math_eqalign_column
\plusone
481
\dostoptagged
% finish cell
482
\dostarttagged
\t!mathtablecell
\empty
}
483 484
\def
\math_left_of_eqalign
485
{
\ifcsname
\??mathalignmentvariant
\number
\c_math_eqalign_column
\endcsname
486
\ifcase
\lastnamedcs
\or
\relax
\or
\hfill
\or
\hfill
\fi
487
\fi
}
488 489
\def
\math_right_of_eqalign
490
{
\ifcsname
\??mathalignmentvariant
\number
\c_math_eqalign_column
\endcsname
491
\ifcase
\lastnamedcs
\or
\hfill
\or
\relax
\or
\hfill
\fi
492
\fi
}
493 494
\newconditional
\c_math_alignment_local_number
% not used but when true puts in front (todo)
495 496
\def
\math_number_right_of_eqalign
497
{
\ifcase
\wd
\b_strc_formulas_number
\else
498
\ifconditional
\c_math_alignment_local_number
499
\ifcase
\c_strc_math_number_location
\or\or
500
\box
\b_strc_formulas_number
501
\fi
502
\else
503
\box
\b_strc_formulas_number
504
\fi
505
\fi
}
506 507
\def
\math_number_left_of_eqalign
508
{
\ifcase
\wd
\b_strc_formulas_number
\else
509
\ifconditional
\c_math_alignment_local_number
510
\ifcase
\c_strc_math_number_location
\or
511
\box
\b_strc_formulas_number
512
\fi
513
\fi
514
\fi
}
515 516
% \def\math_eqalign_set_column#1% we could just add to the preamble (as with other alignments)
517
% {\expandafter\let\csname\??mathalignmentvariant\number\c_math_eqalign_column\expandafter\endcsname
518
% \csname\??mathalignmentvariant\ifcsname\??mathalignmentvariant#1\endcsname#1\else\v!normal\fi\endcsname}
519 520
\def
\math_eqalign_set_column
#
1
% we could just add to the preamble (as with other alignments)
521
{
\expandafter\chardef\csname
\??mathalignmentvariant
\number
\c_math_eqalign_column
\expandafter\expandafter\expandafter\endcsname
522
\ifcsname
\??mathalignmentvariant
#
1
\endcsname\lastnamedcs\else
\zerocount
\fi\relax
}
523 524
\letvalue
{
\??mathalignmentvariant\v!normal
}
\zerocount
525
\letvalue
{
\??mathalignmentvariant\v!left
}
\plusone
526
\letvalue
{
\??mathalignmentvariant\v!right
}
\plustwo
527
\letvalue
{
\??mathalignmentvariant\v!middle
}
\plusthree
528 529
\def
\math_align_NR_generic
[#
1
][#
2
]
%
530
{
\strc_formulas_place_number_nested
{
#
1
}{
#
2
}
\crcr
}
531 532
%D \starttyping
533
%D \placeformula[eqn0]\startformula \startalign[n=1] a\NR \stopalign \stopformula See \in[eqn0]
534
%D \placeformula[eqn1]\startformula \startalign[n=1] a\NR \stopalign \stopformula See \in[eqn1]
535
%D \placeformula \startformula \startalign[n=1] a\NR[eqn2] \stopalign \stopformula See \in[eqn2]
536
%D \placeformula[eqn3]\startformula \startalign[n=1] a\NR[+] \stopalign \stopformula See \in[eqn3]
537
%D \stoptyping
538 539
%D \startbuffer
540
%D \placeformula \startformula \eqalignno {
541
%D a &= b & \formulanumber \cr
542
%D c &= d \cr
543
%D &= e \cr
544
%D &= f & \formulanumber
545
%D } \stopformula
546
%D \stopbuffer
547
%D
548
%D \typebuffer \getbuffer
549
%D
550
%D \startbuffer
551
%D \placeformula \startformula \startalign
552
%D \NC a \EQ b \NR[+]
553
%D \NC c \EQ d \NR
554
%D \NC \EQ f \NR[for:demo-a-1]
555
%D \NC \EQ g \NR[for:demo-a-2][a]
556
%D \NC \EQ h \NR[for:demo-a-3][b]
557
%D \NC \EQ i \NR
558
%D \stopalign \stopformula
559
%D \stopbuffer
560
%D
561
%D \typebuffer \getbuffer
562
%D
563
%D \startbuffer
564
%D \placeformula \startformula \startalign
565
%D \NC a \EQ b \NR[+]
566
%D \NC c \EQ d \NR
567
%D \NC \EQ f \NR
568
%D \NC \EQ g \NR
569
%D \NC \EQ h \NR
570
%D \NC \EQ i \NR[+]
571
%D \stopalign \stopformula
572
%D \stopbuffer
573
%D
574
%D \typebuffer \getbuffer
575
%D
576
%D \startbuffer
577
%D \placeformula \startformula \startalign
578
%D \NC a \NC \eq b \NR[+]
579
%D \NC c \NC \neq d \NR
580
%D \NC \NC \neq f \NR[for:demo-b-1]
581
%D \NC \NC \geq g \NR[for:demo-b-2][a]
582
%D \NC \NC \leq h \NR[for:demo-b-3][b]
583
%D \NC \NC \neq i \NR
584
%D \stopalign \stopformula
585
%D \stopbuffer
586
%D
587
%D \typebuffer \getbuffer
588
%D
589
%D \startbuffer
590
%D \placeformula \startformula \startalign[n=3,align={left,middle,right}]
591
%D \NC l \NC = \NC r \NR
592
%D \NC left \NC = \NC right \NR
593
%D \stopalign \stopformula
594
%D \stopbuffer
595
%D
596
%D \typebuffer \getbuffer
597
%D
598
%D \startbuffer
599
%D \placeformula \startformula \startalign[n=3,align={right,middle,left}]
600
%D \NC l \NC = \NC r \NR
601
%D \NC left \NC = \NC right \NR
602
%D \stopalign \stopformula
603
%D \stopbuffer
604
%D
605
%D \typebuffer \getbuffer
606
%D
607
%D \startbuffer
608
%D \placeformula \startformula \startalign[n=3,align={middle,middle,middle}]
609
%D \NC l \NC = \NC r \NR
610
%D \NC left \NC = \NC right \NR
611
%D \stopalign \stopformula
612
%D \stopbuffer
613
%D
614
%D \typebuffer \getbuffer
615
%D
616
%D \startbuffer
617
%D \placeformula
618
%D \startformula
619
%D \startalign[n=3,align={middle,middle,middle}]
620
%D \NC a \NC = \NC b \NR[+]
621
%D \NC 2a \NC = \NC 2b \NR
622
%D \stopalign
623
%D \stopformula
624
%D \stopbuffer
625
%D
626
%D \typebuffer \getbuffer
627
%D
628
%D \startbuffer
629
%D \placeformula
630
%D \startformulas
631
%D \setupmathalignment[n=3,align={middle,middle,middle}]%
632
%D \startformula
633
%D \startalign
634
%D \NC a \NC = \NC b \NR[+]
635
%D \NC 2a \NC = \NC 2b \NR
636
%D \stopalign
637
%D \stopformula
638
%D \startformula
639
%D \startalign
640
%D \NC a \NC = \NC b \NR[+]
641
%D \NC 2a \NC = \NC 2b \NR
642
%D \stopalign
643
%D \stopformula
644
%D \stopformulas
645
%D \stopbuffer
646
%D
647
%D \typebuffer \getbuffer
648
%D
649
%D \startbuffer
650
%D \placeformula
651
%D \startformulas
652
%D \dorecurse{5}{\startformula
653
%D \startalign[n=3,align={middle,middle,middle}]
654
%D \NC a \NC = \NC b \NR[+]
655
%D \NC 2a \NC = \NC 2b \NR
656
%D \stopalign
657
%D \stopformula}
658
%D \stopformulas
659
%D \stopbuffer
660
%D
661
%D \typebuffer \getbuffer
662 663
%D \macros
664
%D {definemathcases, setupmathcases, startmathcases}
665
%D
666
%D Another wish \unknown
667 668
\installcorenamespace
{
mathcases
}
669 670
\installcommandhandler
\??mathcases
{
mathcases
}
\??mathcases
671 672
\setupmathcases
673
[
\c!distance
=
\emwidth
,
674
\c!strut
=
\v!yes
,
% new
675
\c!numberdistance
=
2
.
5
\emwidth
,
676
\c!left
=
{
\left
\{
\mskip\thinmuskip
}
,
677
\c!right
=
{
\right
.
}
]
678 679
\appendtoks
680
\setuevalue
{
\e!start
\currentmathcases
}{
\math_cases_start
{
\currentmathcases
}}
%
681
\setvalue
{
\e!stop
\currentmathcases
}{
\math_cases_stop
}
%
682
\to
\everydefinemathcases
683 684
\unexpanded
\def
\math_cases_start
#
1
%
685
{
\begingroup
686
\edef
\currentmathcases
{
#
1
}
%
687
\dosingleempty
\math_cases_start_indeed
}
688 689
\def
\math_cases_NC_zero
690
{
\math_cases_NC
}
691 692
\def
\math_cases_MC_zero
693
{
\math_cases_NC
694
\ifmmode
\else
695
\startimath
696
\let
\math_cases_end_math
\stopimath
697
\fi
}
698 699
\let
\math_cases_end_math
\relax
700 701
\def
\math_cases_NR_zero
702
{
\unskip
703
\math_cases_end_math
704
\aligntab
705
\glet
\math_cases_NC
\math_cases_NC_first
706
\dodirectdoubleempty
\math_cases_NR
}
707 708
\def
\math_cases_NC_first
709
{
\glet
\math_cases_NC
\math_cases_NC_second
}
710 711
\def
\math_cases_NC_second
712
{
\math_cases_end_math
\aligntab
}
713 714
\let
\math_cases_NR
\math_align_NR_generic
715 716
\installmacrostack
\math_cases_NC
717 718
\unexpanded
\def
\math_cases_start_indeed
[#
1
]
%
719
{
\iffirstargument
720
\setupcurrentmathcases
[#
1
]
%
721
\fi
722
\edef
\p_strut
{
\mathcasesparameter
\c!strut
}
%
723
\ifx
\p_strut
\v!yes
724
\let
\math_cases_strut
\strut
725
\else
726
\let
\math_cases_strut
\relax
727
\fi
728
\mathcasesparameter
\c!left
729
\vcenter
\bgroup
730
\push_macro_math_cases_NC
731
\let
\endmath
\relax
732
\let
\NC
\math_cases_NC_zero
733
\let
\MC
\math_cases_MC_zero
734
\let
\NR
\math_cases_NR_zero
735
\glet
\math_cases_NC
\math_cases_NC_first
736
\normalbaselines
737
\mathsurround
\zeropoint
738
\everycr
\emptytoks
739
\tabskip
\zeropoint
740
\global
\c_math_eqalign_column
\plusone
741
\halign
\bgroup
742
\startimath
743
\mathcasesparameter
\c!style
744
\alignmark\alignmark
745
\stopimath
746
\hfil
747
\aligntab
748
\hskip
\mathcasesparameter
\c!distance
\relax
749
\pop_macro_math_cases_NC
750
\math_cases_strut
% looks better
751
\alignmark\alignmark
752
\hfil
753
\aligntab
754
\hskip
\mathcasesparameter
\c!numberdistance
\relax
755
\let
\formuladistance
\!!zeropoint
756
\span
\math_text_in_eqalign
{
\alignmark\alignmark
}
%
757
\crcr
}
% todo: number
758 759
\def
\math_cases_stop
760
{
\crcr
761
\egroup
762
\popmacro
\math_cases_NC
763
\egroup
764
\mathcasesparameter
\c!right
765
\endgroup
}
766 767
\definemathcases
[
cases
]
768
\definemathcases
[
\v!mathcases
]
769 770
%D \startbuffer
771
%D \placeformula \startformula \startcases
772
%D \NC 2 \NC $ y > 0 $ \NR
773
%D \NC 7 \NC $ x = 7 $ \NR[+]
774
%D \NC 4 \NC otherwise \NR
775
%D \stopcases \stopformula
776
%D \stopbuffer
777
%D
778
%D \typebuffer \getbuffer
779
%D
780
%D \startbuffer
781
%D \placeformula \startformula x \startcases
782
%D \NC 2 \NC $ y > 0 $ \NR[+]
783
%D \NC 7 \NC $ x = 7 $ \NR
784
%D \NC 4 \NC otherwise \NR
785
%D \stopcases \stopformula
786
%D \stopbuffer
787
%D
788
%D \typebuffer \getbuffer
789
%D
790
%D \startbuffer
791
%D \placeformula \startformula \startcases
792
%D \NC 2 \NC $ y > 0 $ \NR
793
%D \NC 7 \NC $ x = 7 $ \NR
794
%D \NC 4 \NC otherwise \NR
795
%D \stopcases \stopformula
796
%D \stopbuffer
797
%D
798
%D \typebuffer \getbuffer
799
%D
800
%D \startbuffer
801
%D \placeformula \startformula x \startcases
802
%D \NC 2 \NC $ y > 0 $ \NR
803
%D \NC 7 \NC $ x = 7 $ \NR
804
%D \NC 4 \NC otherwise \NR
805
%D \stopcases \stopformula
806
%D \stopbuffer
807
%D
808
%D \typebuffer \getbuffer
809 810
%D \macros
811
%D {definemathmatrix, setupmathmatrix, startmathmatrix}
812
%D
813
%D Yet another one \unknown. This time we implement the lot a bit
814
%D different which is a side effect of getting the tagging right. In
815
%D retrospect the main alignment could be done this way but \unknown
816 817
\installcorenamespace
{
mathmatrix
}
818 819
\installcommandhandler
\??mathmatrix
{
mathmatrix
}
\??mathmatrix
820 821
\setupmathmatrix
822
[
\c!distance
=
\emwidth
,
823
\c!left
=
,
824
\c!right
=
,
825
\c!align
=
\v!middle
]
826 827
\appendtoks
828
\setuevalue
{
\e!start
\currentmathmatrix
}{
\math_matrix_start
{
\currentmathmatrix
}}
%
829
\setvalue
{
\e!stop
\currentmathmatrix
}{
\math_matrix_stop
}
% no u else lookahead problem
830
\to
\everydefinemathmatrix
831 832
\def
\math_matrix_start_table
833
{
\global
\c_math_eqalign_column
\zerocount
834
\dostarttagged
\t!math
\empty
835
\dostarttagged
\t!mathtable
\empty
}
836 837
\def
\math_matrix_stop_table
838
{
\dostoptagged
839
\dostoptagged
}
840 841
\def
\math_matrix_start_row
842
{
\noalign
{
\global
\c_math_eqalign_column
\zerocount
}
%
843
\dostarttagged
\t!mathtablerow
\empty
}
844 845
\def
\math_matrix_stop_row
846
{
\dostoptagged
}
847 848
\unexpanded
\def
\math_matrix_start_cell
849
{
\dostarttagged
\t!mathtablecell
\empty
850
\hss
851
\math_left_of_eqalign
852
\startimath
853
\math_matrix_set_style
854
\tabskip
\zeropoint
855
\everycr
\emptytoks
}
856 857
\unexpanded
\def
\math_matrix_stop_cell
858
{
\stopimath
859
\math_right_of_eqalign
860
\hss
861
\dostoptagged
}
862 863
% We could construct a preamble with alignment and such embedded but the number
864
% of matrices with many rows is normally so low that it doesn't pay of at all.
865 866
\unexpanded
\def
\math_matrix_distance
867
{
\relax
868
\ifdim
\d_math_eqalign_distance
>
\zeropoint
869
\hskip
\d_math_eqalign_distance
870
\fi
871
\relax
}
872 873
\def
\math_matrix_preamble
874
{
\math_matrix_strut
875
\global\advance
\c_math_eqalign_column
\plusone
876
\math_matrix_start_cell
877
\alignmark\alignmark
878
\math_matrix_stop_cell
879
\aligntab
880
\aligntab
881
\math_matrix_distance
882
\global\advance
\c_math_eqalign_column
\plusone
883
\math_matrix_start_cell
884
\alignmark\alignmark
885
\math_matrix_stop_cell
}
886 887
\newconditional
\c_math_matrix_first
888 889
\def
\math_matrix_NR
890
{
\aligntab\omit
891
\math_matrix_stop_row
892
\math_matrix_pickup
893
\crcr
894
\math_matrix_start_row
}
895 896
\def
\math_matrix_NC
897
{
\ifconditional
\c_math_matrix_first
898
\expandafter
\math_matrix_NC_yes
899
\else
900
\expandafter
\math_matrix_NC_nop
901
\fi
}
902 903
\def
\math_matrix_pickup
{
\global
\settrue
\c_math_matrix_first
}
904
\def
\math_matrix_NC_yes
{
\global
\setfalse
\c_math_matrix_first
}
905
\def
\math_matrix_NC_nop
{
\aligntab
}
% avoids lookahead
906 907
% \def\math_matrix_stop_wrapup
908
% {\crcr
909
% \strut
910
% \crcr
911
% \noalign{\vskip-\struthtdp}}
912 913
\def
\math_matrix_start_processing
914
{
\dontleavehmode
915
\bgroup
916
\tabskip
\zeropoint
917
\math_matrix_pickup
918
\let
\NR
\math_matrix_NR
919
\let
\NC
\math_matrix_NC
920
\let
\MC
\math_matrix_NC
921
%
922
\let
\endmath
\relax
923
%
924
\setbox
\nextbox
\vbox
\bgroup
925
\math_matrix_start_table
926
\halign
\bgroup
927
% preamble
928
\span
\math_matrix_preamble
929
% done
930
\crcr
931
\math_matrix_start_row
}
932 933
\def
\math_matrix_stop_processing
934
{
%\math_matrix_stop_wrapup % optional
935
\math_matrix_stop_row
936
\egroup
937
\math_matrix_stop_table
938
\egroup
939
\mathmatrixleft
940
\math_matrix_finish_nextbox
941
\mathmatrixright
942
\egroup
}
943 944
\let
\math_matrix_strut
\strut
945
\let
\math_matrix_set_style
\relax
946 947
\def
\math_matrix_check_settings
948
{
\edef
\p_strut
{
\mathmatrixparameter
\c!strut
}
%
949
\ifx
\p_strut
\v!no
950
\let
\math_matrix_strut
\relax
951
\else
952
\let
\math_matrix_strut
\strut
953
\ifx
\p_strut
\v!yes
\else
954
\spacing
\p_strut
955
\fi
956
\fi
957
\d_math_eqalign_distance
\mathmatrixparameter
\c!distance
\relax
958
\edef
\math_matrix_set_style
{
\mathmatrixparameter
\c!style
}}
959 960
\def
\math_matrix_set_defaults
961
{
\normalbaselines
% hm, spacing ?
962
\mathsurround
\zeropoint
963
\tabskip
\zeropoint
}
964 965
\def
\math_matrix_set_columns_step
966
{
\advance
\c_math_eqalign_column
\plusone
967
%\c_math_matrix_columns\c_math_eqalign_column
968
\math_eqalign_set_column
}
969 970
\def
\math_matrix_set_columns
971
{
\c_math_eqalign_column
\zerocount
972
\rawprocesscommacommand
[
\mathmatrixparameter
\c!align
]
\math_matrix_set_columns_step
}
973 974
\newcount
\c_math_eqalign_column_saved
975
\newcount
\c_math_eqalign_first_saved
976 977
% \installglobalmacrostack\c_math_matrix_first
978 979
\unexpanded
\def
\math_matrix_start
#
1
%
980
{
\begingroup
981
\globalpushmacro
\c_math_matrix_first
% hm, does that work?
982
\c_math_eqalign_column_saved
\c_math_eqalign_column
983
\c_math_eqalign_first_saved
\c_math_eqalign_first
984
\edef
\currentmathmatrix
{
#
1
}
%
985
\dosingleempty
\math_matrix_start_indeed
}
986 987
\unexpanded
\def
\math_matrix_start_indeed
[#
1
]
%
988
{
\iffirstargument
989
\setupcurrentmathmatrix
[#
1
]
%
990
\fi
991
\math_matrix_check_settings
992
\math_matrix_set_defaults
993
\math_matrix_set_columns
994
\math_matrix_start_processing
}
995 996
\def
\math_matrix_stop
997
{
\math_matrix_stop_processing
998
\global
\c_math_eqalign_first
\c_math_eqalign_first_saved
999
\global
\c_math_eqalign_column
\c_math_eqalign_column_saved
1000
\globalpopmacro
\c_math_matrix_first
1001
\endgroup
}
1002 1003
% vcenter:
1004
%
1005
% delta = (height(v) + depth(v))/2
1006
% axis = math_axis_size(cur_size)
1007
% height(v) = delta + axis
1008
% depth(v) = delta - axis
1009 1010
\installcorenamespace
{
mathmatrixalignlocation
}
1011 1012
\let
\mathmatrixleft
\empty
% experimental hook
1013
\let
\mathmatrixright
\empty
% experimental hook
1014 1015
\setvalue
{
\??mathmatrixalignlocation\v!top
}{
\raise\dimexpr
(
\nextboxdp
-
\nextboxht
)
/
2
+
\mathaxisheight
\mathstyle\relax
}
1016
\setvalue
{
\??mathmatrixalignlocation\v!high
}{
\raise\dimexpr
(
\nextboxdp
-
\nextboxht
)
/
2
\relax
}
1017
\setvalue
{
\??mathmatrixalignlocation\v!center
}{
\relax
}
1018
\setvalue
{
\??mathmatrixalignlocation\v!lohi
}
{
\relax
}
1019
\setvalue
{
\??mathmatrixalignlocation\v!normal
}{
\relax
}
1020
\setvalue
{
\??mathmatrixalignlocation\v!bottom
}{
\lower\dimexpr
(
\nextboxdp
-
\nextboxht
)
/
2
+
\mathaxisheight
\mathstyle\relax
}
1021
\setvalue
{
\??mathmatrixalignlocation\v!low
}{
\lower\dimexpr
(
\nextboxdp
-
\nextboxht
)
/
2
\relax
}
1022 1023
\def
\math_matrix_finish_nextbox
1024
{
\begincsname
\??mathmatrixalignlocation
\mathmatrixparameter
\c!location
\endcsname\hbox
\bgroup
1025
\normalstartimath
1026
\mathmatrixparameter
\c!left
1027
\vcenter
{
\box
\nextbox
}
%
1028
\mathmatrixparameter
\c!right
1029
\normalstopimath
1030
\egroup
}
1031 1032
\definemathmatrix
[
matrix
]
1033
\definemathmatrix
[
\v!mathmatrix
]
1034 1035
%D \startbuffer
1036
%D \placeformula \startformula[-] \startmatrix
1037
%D \NC 1 \NC x \NC a \NR
1038
%D \NC 2 \NC y \NC b \NR
1039
%D \NC 3 \NC z \NC c \NR
1040
%D \stopmatrix \stopformula
1041
%D \stopbuffer
1042
%D
1043
%D \typebuffer \getbuffer
1044
%D
1045
%D \definemathmatrix[bmatrix][left={\left[\mskip\thinmuskip},right={\mskip\thinmuskip\right]},strut=1.25]
1046
%D
1047
%D \startbuffer
1048
%D \placeformula \startformula[-] \startbmatrix
1049
%D \NC 1 \NC x \NC a \NR
1050
%D \NC 2 \NC y \NC b \NR
1051
%D \NC 3 \NC z \NC c \NR
1052
%D \stopbmatrix \stopformula
1053
%D \stopbuffer
1054
%D
1055
%D \typebuffer \getbuffer
1056
%D
1057
%D Taco added some code (dedicated to Aditya Mahajan) that gives more
1058
%D control over aligments:
1059 1060
%D \startbuffer
1061
%D \startformula
1062
%D \startmatrix
1063
%D \NC a + x \NC = \NC a + d \NR
1064
%D \NC y \NC = \NC d \NR
1065
%D \stopmatrix
1066
%D \stopformula
1067
%D \stopbuffer
1068
%D
1069
%D \typebuffer \getbuffer
1070 1071
%D \startbuffer
1072
%D \startformula
1073
%D \startmatrix [distance=3pt,align={right,left}]
1074
%D \NC a + x \NC = a + d \NR
1075
%D \NC y \NC = d \NR
1076
%D \stopmatrix
1077
%D \stopformula
1078
%D \stopbuffer
1079
%D
1080
%D \typebuffer \getbuffer
1081 1082
%D \startbuffer
1083
%D \startformula
1084
%D \startmatrix [left=\left(,right=\right)]
1085
%D \NC a + x \NR
1086
%D \NC y \NR
1087
%D \stopmatrix
1088
%D \stopformula
1089
%D \stopbuffer
1090
%D
1091
%D \typebuffer \getbuffer
1092
%D
1093
%D A bit more complex code:
1094
%D
1095
%D \startbuffer
1096
%D \startformula
1097
%D \text{Let }{\cal R} = \bigcup_{P_{X_1},P_{X_2}}
1098
%D \left\{ (R_1, R_2) :
1099
%D \startmatrix[distance=1em,align={left,left,right}]
1100
%D \NC R_1 \NC < I(X_1 ; Y \mid X_2) \NC R_1 \NR
1101
%D \NC \hfill Q_2 \NC < I(X_2 ; Y \mid X_1) \NC R_2 \NR
1102
%D \NC R_1 + R_2 \NC < I(X_1 ; Y) \NC R_1 + R_2 \NR
1103
%D \stopmatrix
1104
%D \right\}
1105
%D \stopformula
1106
%D \stopbuffer
1107
%D
1108
%D \typebuffer \getbuffer
1109 1110
%D \macros
1111
%D {startmatrices}
1112
%D
1113
%D Just a handy keystroke safer:
1114 1115
\unexpanded
\def
\startmatrices
1116
{
\begingroup
1117
\setupmathmatrix
}
1118 1119
\unexpanded
\def
\stopmatrices
1120
{
\endgroup
}
1121 1122
%D \startbuffer
1123
%D \startformula
1124
%D \startmatrix[left={\left(},right={\right)}]
1125
%D \NC A \NC B \NR \NC C \NC D \NR
1126
%D \stopmatrix
1127
%D =
1128
%D \startmatrix[left={\left(},right={\right)},location=low]
1129
%D \NC A \NC B \NR \NC C \NC D \NR
1130
%D \stopmatrix
1131
%D =
1132
%D \startmatrix[left={\left(},right={\right)},location=high]
1133
%D \NC A \NC B \NR \NC C \NC D \NR
1134
%D \stopmatrix
1135
%D \stopformula
1136
%D \stopbuffer
1137
%D
1138
%D \typebuffer \getbuffer
1139
%D
1140
%D \startbuffer
1141
%D \startformula
1142
%D \startmatrices[left={\left(},right={\right)}]
1143
%D \startmatrix
1144
%D \NC A \NC B \NR \NC C \NC D \NR
1145
%D \stopmatrix
1146
%D =
1147
%D \startmatrix[location=bottom]
1148
%D \NC A \NC B \NR \NC C \NC D \NR
1149
%D \stopmatrix
1150
%D =
1151
%D \startmatrix[location=top]
1152
%D \NC A \NC B \NR \NC C \NC D \NR
1153
%D \stopmatrix
1154
%D \stopmatrices
1155
%D \stopformula
1156
%D \stopbuffer
1157
%D
1158
%D \typebuffer % does not run well: \getbuffer
1159 1160
%D Handy for the \type {m-matrix} module:
1161 1162
\unexpanded
\def
\startnamedmatrix
1163
{
\dodoubleempty
\math_matrix_start_named
}
1164 1165
\def
\math_matrix_start_named
[#
1
][#
2
]
%
1166
{
\begingroup
1167
\edef
\currentmathmatrix
{
#
1
}
%
1168
\ifsecondargument
1169
\setupcurrentmathmatrix
[#
2
]
%
1170
\fi
1171
\math_matrix_start
\currentmathmatrix
}
1172 1173
\def
\stopnamedmatrix
1174
{
\math_matrix_stop
1175
\endgroup
}
1176 1177
%D The following code is derived from Aditya's simplematrix prototype but
1178
%D adapted to regular mathmatrices (which saves some code so it can go into
1179
%D the core):
1180 1181
\def
\math_matrix_simple_row
#
1
%
1182
{
\rawprocesscommalist
[#
1
]
\math_matrix_simple_col
1183
\toksapp
\scratchtoks
{
\NR
}}
1184 1185
\def
\math_matrix_simple_col
#
1
%
1186
{
\toksapp
\scratchtoks
{
\NC
#
1
}}
1187 1188
\unexpanded
\def
\math_matrix_simple
[#
1
][#
2
]#
3
%
1189
{
\begingroup
1190
\edef
\currentmathmatrix
{
#
1
}
%
1191
\ifsecondargument
1192
\setupcurrentmathmatrix
[#
2
]
%
1193
\fi
1194
\scratchtoks
\emptytoks
1195
\processlist
[]
;
\math_matrix_simple_row
[#
3
]
%
1196
\math_matrix_start
\currentmathmatrix
1197
\the
\scratchtoks
1198
\math_matrix_stop
1199
\endgroup
}
1200 1201
%D We hook it into the normal mathmatrix code:
1202 1203
\appendtoks
1204
\edef
\p_simplecommand
{
\mathmatrixparameter
\c!simplecommand
}
%
1205
\ifx
\p_simplecommand
\empty
\else
1206
\setuevalue
{
\p_simplecommand
}{
\dodoubleempty
\math_matrix_simple
[
\currentmathmatrix
]
}
%
1207
\fi
1208
\to
\everydefinemathmatrix
1209 1210
%D And predefine some matrices:
1211 1212
\definemathmatrix
[
matrix
:
parentheses
][
\c!left
=
{
\left
(
\mskip\thinmuskip
}
,
\c!right
=
{
\mskip\thinmuskip\right
)
}
,
\c!align
=
\v!middle
]
1213
\definemathmatrix
[
matrix
:
brackets
]
[
\c!left
=
{
\left
[
\mskip\thinmuskip
}
,
\c!right
=
{
\mskip\thinmuskip\right
]
}
,
\c!align
=
\v!middle
]
1214
\definemathmatrix
[
matrix
:
bars
]
[
\c!left
=
{
\left
|
\mskip\thinmuskip
}
,
\c!right
=
{
\mskip\thinmuskip\right
|
}
,
\c!align
=
\v!middle
]
1215 1216
\definemathmatrix
[
thematrix
][
matrix
:
parentheses
][
\c!simplecommand
=
thematrix
]
1217 1218
%D \startbuffer
1219
%D \startformula
1220
%D \thematrix{1,2,3,4;5,6,7,8;9,10,11,12}
1221
%D \stopformula
1222
%D \stopbuffer
1223
%D
1224
%D \typebuffer \getbuffer
1225
%D
1226
%D \startbuffer
1227
%D \startformula
1228
%D \startthematrix
1229
%D \NC 1\NC 2\NC 3\NC 4\NR
1230
%D \NC 5\NC 6\NC 7\NC 8\NR
1231
%D \NC 9\NC10\NC11\NC12\NR
1232
%D \stopthematrix
1233
%D \stopformula
1234
%D \stopbuffer
1235
%D
1236
%D \typebuffer \getbuffer
1237 1238
%D \macros
1239
%D {startintertext}
1240
%D
1241
%D Preliminary feature:
1242
%D
1243
%D {\em example code}
1244
%D
1245
%D The intertext commands have to be expandable (in aligment lookahead) so
1246
%D we cannot use \type {\unexpanded}.
1247 1248
\def
\startintertext
#
1
\stopintertext
1249
{
\noalign
{
\math_intertext
{
#
1
}}}
1250 1251
\let
\stopintertext
\relax
1252 1253
\def
\intertext
#
1
%
1254
{
\noalign
{
\math_intertext
{
#
1
}}}
1255 1256
\unexpanded
\def
\math_intertext
#
1
%
1257
{
\penalty\postdisplaypenalty
1258
\afterdisplayspace
1259
\vbox
{
\forgetall
\noindent
#
1
\par
}
%
1260
\penalty\predisplaypenalty
1261
\beforedisplayspace
}
1262 1263
%D \macros
1264
%D {substack}
1265
%D
1266
%D Preliminary code:
1267
%D
1268
%D \startbuffer
1269
%D \startformula
1270
%D \sum_{%
1271
%D \startsubstack
1272
%D i = 1 \NR
1273
%D i \neq n \NR
1274
%D i \neq m
1275
%D \stopsubstack
1276
%D }a_i
1277
%D \stopformula
1278
%D \stopbuffer
1279
%D
1280
%D \getbuffer which was typed as \typebuffer
1281
%D
1282
%D Notice that these macros give the correct spacing for
1283
%D subscripts. Compare for example
1284
%D
1285
%D \startbuffer
1286
%D \startformula
1287
%D \sum_{\startsubstack a \NR b \NR \stopsubstack}
1288
%D \text{ and }
1289
%D \sum_{\scriptstyle a \atop \scriptstyle}
1290
%D \stopformula
1291
%D \stopbuffer
1292
%D
1293
%D \typebuffer which gives \getbuffer
1294 1295
% no tagging yet : how is it supposed to be coded?
1296 1297
\unexpanded
\def
\startsubstack
1298
{
\begingroup
1299
\vcenter
\bgroup
1300
\baselineskip
\mathstacktotal
1301
\lineskip
\mathstackvgap
1302
\lineskiplimit\lineskip
1303
\mathsurround
\zeropoint
1304
\everycr
\emptytoks
1305
\let
\NC
\relax
1306
\let
\MC
\relax
1307
\let
\NR
\crcr
1308
\halign
\bgroup
\hfil
\normalstartimath
\scriptstyle\alignmark\alignmark
\normalstopimath
\hfil\crcr
}
1309 1310
\def
\stopsubstack
% todo: \unexpanded and delayed
1311
{
\crcr
1312
\egroup
1313
\egroup
1314
\endgroup
}
1315 1316
% %D \macros
1317
% %D {bordermatrix}
1318
% %D
1319
% %D In \PLAIN\ \TEX\ the width of a parenthesis is stored in
1320
% %D the \DIMENSION\ \type{\mathparentwd}. This value is derived from
1321
% %D the width of \type{\tenrm B}, so let's take care of it now:
1322
%
1323
% \ifx\mathparentwd\undefined \newdimen\mathparentwd \fi
1324
%
1325
% \let\normalbordermatrix\bordermatrix % move that code to here instead
1326
%
1327
% \unexpanded\def\bordermatrix
1328
% {\begingroup
1329
% \setbox\scratchbox\hbox{\mr\char"239C}%
1330
% \global\mathparentwd\wd\scratchbox
1331
% \endgroup
1332
% \normalbordermatrix}
1333
%
1334
% \def\bordermatrix
1335
% {\begingroup
1336
% \mr
1337
% \global\mathparentwd\fontcharwd\font"239C\relax
1338
% \endgroup
1339
% \normalbordermatrix}
1340 1341
%D \macros{overset, underset}
1342
%D
1343
%D The macros \type{\overset} and \type{\underset} are provided by
1344
%D \AMS\ packages in \LATEX. These macro allows you to place a symbol
1345
%D above or below another symbol, irrespective of whether the other
1346
%D symbol is a relation or something else, and without influencing the
1347
%D spacing. For most cases there is a better way to do such things
1348
%D (declaring a math command with limop option, or using accents), but
1349
%D occasionally these macros can be useful, for example:
1350
%D
1351
%D \startbuffer
1352
%D \startformula
1353
%D \overset{*}{X} \underset{*}{X}
1354
%D \stopformula
1355
%D \stopbuffer
1356
%D \typebuffer \getbuffer
1357
%D
1358
%D Use these macros sparingly. Remember, \TEX\ was designed for
1359
%D mathematics, so there is usually a proper method for typesetting
1360
%D common math notation.
1361
%D
1362
%D These macros are a cleaner version of \type {\binrel@} and
1363
%D \type {\binrel@@} macros in \AMSTEX\ packages.
1364 1365
\def
\math_binrel_apply
#
1
%
1366
{
\begingroup
1367
\setbox
\scratchbox
\hbox
1368
{
\thinmuskip
0
mu
1369
\medmuskip
-
1
mu
1370
\thickmuskip
-
1
mu
1371
\setbox
\scratchbox
\hbox
{
\normalstartimath
#
1
\mathsurround
\zeropoint
\normalstopimath
}
%
1372
\kern
-
\wd
\scratchbox
1373
\normalstartimath
{}
#
1
{}
\mathsurround
\zeropoint
\normalstopimath
}
%
1374
\ifdim
\wd
\scratchbox
<
\zeropoint
1375
\endgroup
1376
\expandafter\mathbin
1377
\else\ifdim\wd
\scratchbox
>
\zeropoint
1378
\endgroup
1379
\doubleexpandafter
\mathrel
1380
\else
1381
\endgroup
1382
\doubleexpandafter\firstofoneargument
1383
\fi\fi
}
1384 1385
\unexpanded
\def
\overset
#
1
#
2
%
1386
{
\math_binrel_apply
{
#
2
}{
\mathop
{
\kern
\zeropoint
#
2
}
\limits
\normalsuperscript
{
#
1
}}}
1387 1388
\unexpanded
\def
\underset
#
1
#
2
%
1389
{
\math_binrel_apply
{
#
2
}{
\mathop
{
\kern
\zeropoint
#
2
}
\limits
\normalsubscript
{
#
1
}}}
1390 1391
%D The following code comes from \type {math-str.mkiv}.
1392
%D
1393
%D Here we implement a basic math alignment mechanism. Numbers are also handled. The macros
1394
%D \type {\startinnermath} and \type {\stopinnermath} can be overloaded in specialized
1395
%D modules.
1396 1397
\installcorenamespace
{
mathinnerstart
}
1398
\installcorenamespace
{
mathinnerstop
}
1399 1400
% \unexpanded\def\startinnermath{\csname\??mathinnerstart\formulaparameter\c!align\endcsname}
1401
% \unexpanded\def\stopinnermath {\csname\??mathinnerstop \formulaparameter\c!align\endcsname}
1402 1403
\unexpanded
\def
\startinnermath
{
\expandnamespaceparameter
\??mathinnerstart
\formulaparameter
\c!align\v!normal
}
1404
\unexpanded
\def
\stopinnermath
{
\expandnamespaceparameter
\??mathinnerstop
\formulaparameter
\c!align\v!normal
}
1405 1406
\unexpanded
\def
\mathinnerstrut
1407
{
\doif
{
\formulaparameter
\c!strut
}
\v!yes
\strut
}
1408 1409
\unexpanded
\def
\defineinnermathhandler
#
1
#
2
#
3
%
1410
{
\setvalue
{
\??mathinnerstart
#
1
}{
#
2
}
%
1411
\setvalue
{
\??mathinnerstop
#
1
}{
#
3
}}
1412 1413
\installtextracker
1414
{
formulas
.
boxes
}
1415
{
\let
\math_hbox
\ruledhbox
}
1416
{
\let
\math_hbox
\hbox
}
1417 1418
\let
\math_hbox
\hbox
1419 1420
\newconstant
\mathraggedstatus
% normal left center right
1421
\newconstant
\mathnumberstatus
% nothing normal shift_right
1422 1423
\newdimen
\d_math_number_correction
1424 1425
\def
\math_box_llapped_math_no
1426
{
\ifcase
\mathraggedstatus
\or
1427
\box
\b_strc_formulas_number
1428
\or
1429
\llap
{
\box
\b_strc_formulas_number
}
%
1430
\or
1431
\llap
{
\box
\b_strc_formulas_number
}
%
1432
\fi
}
1433 1434
\def
\math_box_rlapped_math_no
1435
{
\ifcase
\mathraggedstatus
\or
1436
\rlap
{
\box
\b_strc_formulas_number
}
%
1437
\or
1438
\rlap
{
\box
\b_strc_formulas_number
}
%
1439
\or
1440
\box
\b_strc_formulas_number
1441
\fi
}
1442 1443
\newconditional
\c_strc_math_has_number
1444
\newconditional
\c_strc_math_display_overflow
1445
\newconstant
\c_strc_math_number_location
1446
\newdimen
\d_strc_math_number_width
1447
\newdimen
\d_strc_math_display_width
1448
\newbox
\b_strc_math_display
1449
\newconstant
\c_strc_formulas_frame_mode
1450
\newdimen
\d_strc_math_indent
1451
\newconditional
\c_strc_math_indent
1452 1453
\let
\d_strc_math_framed_width
\displaywidth
1454 1455
\setvalue
{
\??formulaoption\v!frame
}
%
1456
{
\edef
\p_frame
{
\formulaparameter
\c!frame
}
%
1457
\ifx
\p_frame
\v!number
1458
\c_strc_formulas_frame_mode
\plustwo
% inside frame
1459
\else
1460
\c_strc_formulas_frame_mode
\plusone
% outside frame
1461
\fi
}
1462 1463
% mode: 0=no frame | 1=number inside frame | 2=number outside frame
1464 1465
\def
\strc_math_flush_aligned
1466
{
\ifcase
\c_strc_math_vertical
1467
\ifcase
\mathraggedstatus
\or\hfill\or\hfill\fi
1468
\box
\b_strc_math_display
1469
\ifcase
\mathraggedstatus
\or\or\hfill\or\hfill\fi
1470
\else
1471
\ifconditional
\c_strc_math_indent
1472
\ifzeropt
\d_strc_math_indent
\else
1473
\hangafter
\plusone
1474
\hangindent
\d_strc_math_indent
1475
\fi
1476
\fi
1477
\edef
\p_interlinespace
{
\formulaparameter
\c!interlinespace
}
%
1478
\ifx
\p_interlinespace
\empty
\else\baselineskip
\p_interlinespace
\fi
1479
\global
\d_strc_math_indent
\zeropoint
1480
\ifcase
\mathraggedstatus
\or
\raggedleft
\or
\raggedcenter
\or
\raggedright
\fi
1481
\unhbox
\b_strc_math_display
1482
\fi
}
1483 1484
\def
\strc_math_flush_box_normal
1485
{
\ifcase
\c_strc_math_vertical
1486
\hbox
to
\displaywidth
\bgroup
1487
\strc_math_flush_aligned
1488
\egroup
1489
\else
1490
\strc_math_flush_aligned
1491
\fi
}
1492 1493
\def
\strc_math_flush_box_framed_common
1494
{
\setformulaframedparameter
\c!align
{
\formulaparameter
\c!align
}
%
1495
\letformulaframedparameter
\c!strut\v!no
1496
\d_framed_formula
\ht
\b_strc_math_display
1497
\ifcase
\mathraggedstatus
\or\hfill\or\hfill
\fi
1498
\inheritedformulaframedframed
{
\box
\b_strc_math_display
}
%
1499
\ifcase
\mathraggedstatus
\or
\or\hfill\or\hfill\fi
}
1500 1501
% \def\strc_math_flush_box_framed_inline
1502
% {\letformulaframedparameter\c!location\empty
1503
% \letformulaframedparameter\c!width\displaywidth
1504
% \strc_math_flush_box_framed_common}
1505 1506
\def
\strc_math_flush_box_framed_display
1507
{
\let
\currentformulaframed
\currentformula
1508
\letformulaframedparameter
\c!location\v!formula
1509
\setformulaframedparameter
\c!width
{
\d_strc_math_framed_width
}
%
1510
\strc_math_flush_box_framed_common
}
1511 1512
\def
\strc_math_flush_box_framed_fit_inline
1513
{
\let
\currentformulaframed
\currentformula
1514
\letformulaframedparameter
\c!location
\empty
1515
\letformulaframedparameter
\c!width\v!fit
1516
\strc_math_flush_box_framed_common
}
1517 1518
\def
\strc_math_flush_box_framed_fit_display
1519
{
\let
\currentformulaframed
\currentformula
1520
\letformulaframedparameter
\c!location\v!formula
1521
\letformulaframedparameter
\c!width\v!fit
1522
\strc_math_flush_box_framed_common
}
1523 1524
% combiners
1525 1526
\def
\strc_math_flush_box
1527
{
\ifcase
\c_strc_formulas_frame_mode
1528
\strc_math_flush_box_normal
1529
\else
1530
\strc_math_flush_box_framed_display
1531
\fi
}
1532 1533
\def
\strc_math_number_right_normal
1534
{
\strc_math_flush_aligned
1535
\hss
% hss makes room for number
1536
\math_box_llapped_math_no
}
1537 1538
\def
\strc_math_number_left_normal
1539
{
\math_box_rlapped_math_no
1540
\strc_math_flush_aligned
1541
\hss
}
% hss makes room for number
1542 1543
\def
\strc_math_number_right_normal_outside
1544
{
\ifconditional
\c_strc_formulas_tight
1545
\strc_math_flush_box_framed_fit_display
1546
\else
1547
\strc_math_flush_box_framed_display
1548
\fi
1549
\hss
% hss makes room for number
1550
\math_box_llapped_math_no
}
1551 1552
\def
\strc_math_number_left_normal_outside
1553
{
\math_box_rlapped_math_no
1554
\hss
% hss makes room for number
1555
\ifconditional
\c_strc_formulas_tight
1556
\strc_math_flush_box_framed_fit_display
1557
\else
1558
\strc_math_flush_box_framed_display
1559
\fi
}
1560 1561
\def
\strc_math_number_right_normal_inside
1562
{
\setbox
\b_strc_math_display
\hpack
to
\dimexpr\displaywidth
-
\d_framed_locator_lo
-
\d_framed_locator_ro
\relax
\bgroup
1563
\strc_math_flush_aligned
1564
\hss
1565
\math_box_llapped_math_no
1566
\egroup
1567
\strc_math_flush_box_framed_fit_inline
}
1568 1569
\def
\strc_math_number_left_normal_inside
1570
{
\setbox
\b_strc_math_display
\hpack
to
\dimexpr\displaywidth
-
\d_framed_locator_lo
-
\d_framed_locator_ro
\relax
\bgroup
1571
\math_box_rlapped_math_no
1572
\hss
1573
\strc_math_flush_aligned
1574
\egroup
1575
\strc_math_flush_box_framed_fit_inline
}
1576 1577
\def
\strc_math_number_right_overflow
1578
{
\vpack
\bgroup
1579
\strc_math_flush_box
1580
\par
1581
\hpack
to
\displaywidth
\bgroup
1582
\hss
1583
\math_box_llapped_math_no
1584
\egroup
1585
\egroup
}
1586 1587
\def
\strc_math_number_left_overflow
1588
{
\vpack
\bgroup
1589
\hpack
to
\displaywidth
\bgroup
1590
\math_box_rlapped_math_no
1591
\hss
1592
\egroup
1593
\strc_math_flush_box
1594
\egroup
}
1595 1596
\def
\strc_math_number_right_overflow_outside
1597
{
\vpack
\bgroup
1598
\strc_math_flush_box_framed_fit_inline
1599
% \hskip\zeropoint % nicely breaks the line without introducing funny vertical spacing ... why o why
1600
\hpack
to
\displaywidth
\bgroup
1601
\hss
1602
\math_box_llapped_math_no
1603
\egroup
1604
\egroup
}
1605 1606
\def
\strc_math_number_left_overflow_outside
1607
{
\vpack
\bgroup
1608
\hpack
to
\dimexpr\displaywidth
-
\d_framed_locator_lo
\relax
\bgroup
1609
\math_box_rlapped_math_no
1610
\hss
1611
\egroup
1612
\hskip
\zeropoint
% nicely breaks the line without introducing funny vertical spacing ... why o why
1613
\strc_math_flush_box_framed_fit_inline
1614
\egroup
}
1615 1616
\def
\strc_math_number_right_overflow_inside
1617
{
\setbox
\b_strc_math_display
\vpack
\bgroup
1618
\box
\b_strc_math_display
1619
\hpack
to
\displaywidth
\bgroup
1620
\hss
1621
\math_box_llapped_math_no
1622
\hskip
\d_framed_locator_ro
1623
\egroup
1624
\egroup
1625
\strc_math_flush_box_framed_fit_inline
}
1626 1627
\def
\strc_math_number_left_overflow_inside
1628
{
\setbox
\b_strc_math_display
\vpack
\bgroup
1629
\hpack
to
\displaywidth
\bgroup
1630
% \hskip\d_framed_locator_lo
1631
\math_box_rlapped_math_no
1632
\hss
1633
\egroup
1634
\box
\b_strc_math_display
1635
\egroup
1636
\strc_math_flush_box_framed_fit_inline
}
1637 1638
% checkers
1639 1640
\def
\strc_math_number_check
1641
{
\d_strc_math_display_width
\wd
\b_strc_math_display
1642
\ifconditional
\c_strc_formulas_tight
1643
\ifdim
\d_strc_math_display_width
>
\displaywidth
1644
\settrue
\c_strc_math_display_overflow
1645
\else
1646
\displaywidth
\d_strc_math_display_width
1647
\setfalse
\c_strc_math_display_overflow
1648
\fi
1649
\else
1650
\ifdim
\d_strc_math_display_width
>
\displaywidth
1651
\settrue
\c_strc_math_display_overflow
1652
\else
1653
\setfalse
\c_strc_math_display_overflow
1654
\fi
1655
\fi
}
1656 1657
\def
\strc_math_number_check_outside
1658
{
\d_strc_math_display_width
\naturalwd
\b_strc_math_display
1659
\ifdim
\dimexpr
\d_strc_math_display_width
+
\d_framed_locator_lo
+
\d_framed_locator_ro
\relax
>
\displaywidth
1660
\settrue
\c_strc_math_display_overflow
1661
\else
1662
\setfalse
\c_strc_math_display_overflow
1663
\fi
1664
% still ok?
1665
\ifnum
\mathraggedstatus
=
\plustwo
1666
\edef
\d_strc_math_framed_width
{
\the\dimexpr\displaywidth
-
2
\wd
\b_strc_formulas_number
\relax
}
%
1667
\else
1668
\edef
\d_strc_math_framed_width
{
\the\dimexpr\displaywidth
-
\wd
\b_strc_formulas_number
\relax
}
%
1669
\fi
}
1670 1671
\let
\strc_math_number_check_inside
\strc_math_number_check_outside
1672 1673
% offsets
1674 1675
\def
\strc_math_number_check_offsets
1676
{
\begingroup
1677
\setbox
\scratchbox
\hbox
1678
{
\inheritedformulaframedframed
1679
{
\pack_framed_locator_set_lo
\pack_framed_locator_set_ro
}}
%
1680
\endgroup
}
1681 1682
% tracing
1683 1684
\def
\strc_math_traced_state_yes
1685
{
\llap
{
\setbox
\scratchbox
\hbox
{
\infofont
1686
\ifcase
\mathraggedstatus
unset
\or
right
\or
middle
\or
left
\fi
1687
\space
1688
\ifcase
\c_strc_formulas_frame_mode
no
\or
out
\or
in
\fi
1689
\space
1690
\ifconditional
\c_strc_math_display_overflow
overflow
\else
fit
\fi
1691
\quad
}
\ht
\scratchbox
\zeropoint
\dp
\scratchbox
\zeropoint
\box
\scratchbox
}}
1692 1693
\let
\strc_math_traced_state
\relax
1694 1695
\installtextracker
1696
{
formulas
.
framed
}
1697
{
\let
\strc_math_traced_state
\strc_math_traced_state_yes
}
1698
{
\let
\strc_math_traced_state
\relax
}
1699 1700
% packaging
1701 1702
\unexpanded
\def
\strc_math_box_start
#
1
%
1703
{
\hsize\displaywidth
% \checkeddisplaymath
1704
\global
\mathnumberstatus
\plusone
1705
\mathraggedstatus
#
1
\relax
1706
%
1707
\global
\d_math_number_correction
\zeropoint
1708
%
1709
\edef
\p_location
{
\formulaparameter
\c!location
}
%
1710
\useformulacolorparameter
\c!color
1711
\c_strc_math_number_location
\ifx
\p_location
\v!left
\plusone
\else\ifx
\p_location
\v!right
\plustwo
\else
\zerocount
\fi\fi
1712
%
1713
%\strc_formulas_place_number % not here as we can have inner alignment numbers
1714
\dontcomplain
1715
\setbox
\b_strc_math_display
\math_hbox
\bgroup
% \checkeddisplaymath
1716
\mathinnerstrut
1717
\startforceddisplaymath
}
1718 1719
\def
\strc_math_flush_number_no
1720
{
\ifcase
\c_strc_math_vertical
1721
\ifconditional
\c_strc_math_display_overflow
1722
\ifcase
\c_strc_formulas_frame_mode
1723
\strc_math_flush_box_normal
1724
\else
1725
\strc_math_flush_box_framed_fit_inline
1726
\fi
1727
\else
1728
\ifcase
\c_strc_formulas_frame_mode
1729
%\ifconditional\c_strc_formulas_tight
1730
% \strc_math_flush_box_normal
1731
%\else
1732
\strc_math_flush_box_normal
1733
%\fi
1734
\else
1735
\ifconditional
\c_strc_formulas_tight
1736
\strc_math_flush_box_framed_fit_inline
1737
\else
1738
\strc_math_flush_box_framed_display
1739
\fi
1740
\fi
1741
\fi
1742
\else
1743
\strc_math_flush_box
1744
\fi
}
1745 1746
\def
\strc_math_flush_number_left
1747
{
\ifcase
\c_strc_math_vertical
1748
\ifconditional
\c_strc_math_display_overflow
1749
\ifcase
\c_strc_formulas_frame_mode
1750
\strc_math_number_left_overflow
1751
\or
1752
\strc_math_number_left_overflow_outside
1753
\or
1754
\strc_math_number_left_overflow_inside
1755
\fi
1756
\else
1757
\ifcase
\c_strc_formulas_frame_mode
1758
\strc_math_number_left_normal
1759
\or
1760
\strc_math_number_left_normal_outside
1761
\or
1762
\strc_math_number_left_normal_inside
1763
\fi
1764
\fi
1765
\else
1766
\box
\b_strc_formulas_number
1767
\hfill
1768
\strc_math_flush_aligned
1769
\fi
}
1770 1771
\def
\strc_math_flush_number_right
1772
{
\ifcase
\c_strc_math_vertical
1773
\ifconditional
\c_strc_math_display_overflow
1774
\ifcase
\c_strc_formulas_frame_mode
1775
\strc_math_number_right_overflow
1776
\or
1777
\strc_math_number_right_overflow_outside
1778
\or
1779
\strc_math_number_right_overflow_inside
1780
\fi
1781
\else
1782
\ifcase
\c_strc_formulas_frame_mode
1783
\strc_math_number_right_normal
1784
\or
1785
\strc_math_number_right_normal_outside
1786
\or
1787
\strc_math_number_right_normal_inside
1788
\fi
1789
\fi
1790
\else
1791
\strc_math_flush_aligned
1792
\hfill
1793
\box
\b_strc_formulas_number
1794
\fi
}
1795 1796
\unexpanded
\def
\strc_math_box_stop
1797
{
\stopforceddisplaymath
1798
\egroup
1799
% check number
1800
\d_strc_math_number_width
\wd
\b_strc_formulas_number
1801
%
1802
\ifcase
\mathnumberstatus
1803
\setfalse
\c_strc_math_has_number
1804
\or
\ifzeropt
\d_strc_math_number_width
1805
\setfalse
\c_strc_math_has_number
1806
\else
1807
\settrue
\c_strc_math_has_number
1808
\fi\fi
1809
% preroll left and right offsets
1810
\ifcase
\c_strc_formulas_frame_mode
1811
% no frame
1812
\else
1813
\strc_math_number_check_offsets
1814
\fi
1815
\ifcase
\c_strc_formulas_frame_mode
1816
\strc_math_number_check
1817
\or
1818
\strc_math_number_check_outside
1819
\else
1820
\strc_math_number_check_inside
1821
\fi
1822
\noindent
% \noindentation % not \dontleavehmode
1823
\hskip
\d_strc_formulas_display_margin_left
% was kern but that doesn't indent
1824
\strc_math_traced_state
1825
\ifcase
\c_strc_math_vertical
1826
\hbox
to
\displaywidth
\bgroup
1827
\or
1828
\vbox
\bgroup
\hsize\displaywidth
1829
\or
1830
\bgroup
\hsize\displaywidth
1831
\fi
1832
\ifcase
\mathnumberstatus
1833
\strc_math_flush_box
1834
\or
% status 1
1835
\ifcase
\c_strc_math_number_location
1836
\strc_math_flush_box
1837
\or
% number left
1838
\ifzeropt
\wd
\b_strc_formulas_number
1839
\strc_math_flush_number_no
1840
\else
1841
\strc_math_flush_number_left
1842
\fi
1843
\else
% number right
1844
\ifzeropt
\wd
\b_strc_formulas_number
1845
\strc_math_flush_number_no
1846
\else
1847
\strc_math_flush_number_right
1848
\fi
1849
\fi
1850
\or
% status 2
1851
\hskip
\d_math_number_correction
% probably no longer used
1852
\strc_math_flush_box
1853
\hss
1854
\else
1855
\strc_math_flush_box
1856
\fi
1857
\ifcase
\c_strc_math_vertical
1858
\or
1859
\or
1860
\par
1861
\fi
1862
\egroup
}
1863 1864
\defineinnermathhandler
\v!left
{
\strc_math_box_start
\plusone
}{
\strc_math_box_stop
}
1865
\defineinnermathhandler
\v!middle
{
\strc_math_box_start
\plustwo
}{
\strc_math_box_stop
}
1866
\defineinnermathhandler
\v!right
{
\strc_math_box_start
\plusthree
}{
\strc_math_box_stop
}
1867
\defineinnermathhandler
\v!flushleft
{
\strc_math_box_start
\plusthree
}{
\strc_math_box_stop
}
1868
\defineinnermathhandler
\v!center
{
\strc_math_box_start
\plustwo
}{
\strc_math_box_stop
}
1869
\defineinnermathhandler
\v!flushright
{
\strc_math_box_start
\plusone
}{
\strc_math_box_stop
}
1870
\defineinnermathhandler
\v!normal
{
\strc_math_box_start
\plustwo
}{
\strc_math_box_stop
}
1871 1872
%D Some inline math tweak.
1873 1874
\appendtoks
1875
\ifcase
\mathnestinglevel
\or
1876
% 4=disable 6=only when no spaces
1877
\mathsurroundskip
\mathematicsparameter
\c!textdistance
\relax
1878
\ifzeropt
\mathsurroundskip
1879
\ifzeropt
\gluestretch\mathsurroundskip
1880
\ifzeropt
\glueshrink\mathsurroundskip
1881
\mathsurroundmode
\plussix
1882
\else
1883
\mathsurroundskip
\zeropoint
1884
\mathsurroundmode
\plusfour
1885
\fi
1886
\else
1887
\mathsurroundmode
\plussix
1888
\fi
1889
\else
1890
\mathsurroundmode
\plussix
1891
\fi
1892
\else
1893
\mathsurroundmode
\plusfour
1894
\mathsurroundskip
\zeropoint
1895
\fi
1896
\to
\everymathematics
1897 1898
\setupmathematics
1899
[
\c!textdistance
=
\zeropoint
]
1900 1901
%D This is an experiment. No fancy spacing and alignments here. If we ever
1902
%D go that route it might result in incompatible rendering.
1903 1904
\unexpanded
\def
\startsplitformula
1905
{
\ifhmode
1906
\par
1907
\fi
1908
\begingroup
1909
\beforedisplayspace
1910
% subset of \everydisplay:
1911
\c_attr_mathmode
\plusone
1912
\settrue
\indisplaymath
1913
% end of subset
1914
\informulatrue
}
1915 1916
\unexpanded
\def
\stopsplitformula
1917
{
\afterdisplayspace
1918
\endgroup
}
1919 1920
\protect
\endinput
1921 1922
% \placeformula \startformula[-] \startmatrix
1923
% \NC 1 \NC x \NC a \NR
1924
% \NC 2 \NC y \NC b \NR
1925
% \NC 3 \NC z \NC c \NR
1926
% \stopmatrix \stopformula
1927 1928
% \definemathmatrix[bordermatrix][left={\left[\mskip\thinmuskip},right={\mskip\thinmuskip\right]}]
1929 1930
% \placeformula \startformula[-] \startbordermatrix
1931
% \NC 1 \NC x \NC a \NR
1932
% \NC 2 \NC y \NC b \NR
1933
% \NC 3 \NC z \NC c \NR
1934
% \stopbordermatrix \stopformula
1935