strc-mat.mkiv /size: 40 Kb    last modification: 2021-10-28 13:50
1
%D \module
2
%D [ file=strc-mat,
3
%D version=2008.10.20,
4
%D title=\CONTEXT\ Structure Macros,
5
%D subtitle=Math Numbering,
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
Structure
Macros
/
Math
Numbering
}
15 16
\registerctxluafile
{
strc
-
mat
}
{
}
17 18
% -- we have potential for captions
19
% -- this module will use the commandhandler
20
% -- key/value pairs will be added (I have no time now)
21 22
\unprotect
23 24
\setupformulas
25
[
%\c!way=,
26
%\c!blockway=,
27
%\c!sectionnumber=,
28
%\c!conversion=\v!numbers,
29
%\c!numberstyle=,
30
%\c!numbercolor=,
31
%\c!numbercommand=,
32
%\c!margin=,
33
%\c!align=,
34
%\c!separator=,
35
\c!grid
=
\v!math
,
36
\c!location
=
\v!right
,
37
\c!left
=
(
,
38
\c!right
=
)
,
39
\c!expansion
=
\v!yes
,
% maybe automatically
40
\c!spacebefore
=
\v!big
,
41
\c!spaceafter
=
\formulaparameter
\c!spacebefore
,
42
\c!width
=
\hsize
,
43
\c!leftmargin
=
\zeropoint
,
44
\c!rightmargin
=
\zeropoint
,
45
\c!indentnext
=
\v!no
,
46
\c!alternative
=
\s!default
,
47
\c!strut
=
\v!no
,
48
\c!numberstrut
=
\v!yes
,
% \v!no \v!yes \v!always
49
\c!distance
=
2
\emwidth
]
50 51
\setupformulaframed
52
[
%c!location=<auto set>,
53
%c!width=<auto set>,
54
%c!align=<auto set>,
55
\c!offset
=
.
5
\exheight
]
56 57
\ifdefined
\matheqnogapstep
58
% we're ok, now we have that quad in the distance which is
59
% more consistent and not depending on the text font in math
60
\matheqnogapstep
\zerocount
61
\else
62
% we will keep this for a while
63
\setupformulas
[
\c!distance
=
\emwidth
]
64
\fi
65 66
% \ifdefined\mathdisplayskipmode
67
% \mathdisplayskipmode\plustwo % only when not zero / needs adapted space handler
68
% \fi
69 70
% \mathdisplayskipmode\plusthree
71
%
72
% \hbox\bgroup
73
% \setbox0\vbox\bgroup
74
% xxxxxxxxx\par
75
% \vskip-\baselineskip
76
% $$a^2_2$$\par
77
% xxxxxxxxx\par
78
% \egroup
79
% \box0
80
% \vbox\bgroup
81
% xxxxxxxxx\par
82
% \vskip-\baselineskip
83
% $$a^2$$\par
84
% xxxxxxxxx\par
85
% \egroup
86
% \vbox\bgroup
87
% xxxxxxxxx
88
% \vskip-\baselineskip
89
% $$a_2$$
90
% xxxxxxxxx
91
% \egroup
92
% \egroup
93
%
94
% \hbox\bgroup
95
% \setbox0\vbox\bgroup
96
% xxxxxxxxx\par
97
% \ctxlua{tex.prevdepth=-1000 *65536}
98
% $$a^2_2$$\par
99
% xxxxxxxxx\par
100
% \egroup
101
% \box0
102
% \vbox\bgroup
103
% xxxxxxxxx\par
104
% \ctxlua{tex.prevdepth=-1000 *65536}
105
% $$a^2$$\par
106
% xxxxxxxxx\par
107
% \egroup
108
% \vbox\bgroup
109
% xxxxxxxxx
110
% \ctxlua{tex.prevdepth=-1000 *65536}
111
% $$a_2$$
112
% xxxxxxxxx
113
% \egroup
114
% \egroup
115 116
\setupsubformulas
% subformulas could be last in chain
117
[
\c!indentnext
=
\formulaparameter
\c!indentnext
]
118 119
\definecounter
% one ?
120
[
\v!formula
]
121 122
\defineconversionset
123
[
\v!formula
]
124
[
numbers
,
characters
]
% no \v! ?
125 126
\installcounterassociation
{
formula
}
\registerformulacounter
\v!formula
% currently we only have one
127 128
\appendtoks
129
\synchronizeformulacounters
130
\to
\everysetupformula
131 132
% \appendtoks
133
% \synchronizeformulacounters
134
% \to \everydefineformula
135 136
\setupformulas
137
[
\c!numberconversionset
=
\v!formula
]
% why forgotten
138 139
\appendtoks
140
\normalexpanded
{
\definelist
[
\currentformula
]
}
% is expansion needed?
141
\setuevalue
{
\e!start
\currentformula
\v!formula
}
{
\strc_formulas_start_formula
{
\currentformula
}
}
%
142
\setuevalue
{
\e!stop
\currentformula
\v!formula
}
{
\strc_formulas_stop_formula
}
%
143
\to
\everydefineformula
144 145
\definelist
[
\v!formula
]
146 147
\setuvalue
{
\e!start
\v!formula
}
{
\strc_formulas_start_formula
{
}
}
148
\setuvalue
{
\e!stop
\v!formula
}
{
\strc_formulas_stop_formula
}
149 150
\let
\strc_formulas_start_formula
\relax
% defined later
151
\let
\strc_formulas_stop_formula
\relax
% defined later
152 153
\unexpanded
\def
\defineformulaalternative
% this might change ... start and stop can become keys
154
{
\dotripleargument
\strc_formulas_define_alternative
}
% to the general define .. s!startcommand
155 156
\def
\strc_formulas_define_alternative
[
#
1
]
[
#
2
]
[
#
3
]
%
157
{
\setvalue
{
\e!start
#
1
\v!formula
}
{
#
2
}
%
158
\setvalue
{
\e!stop
#
1
\v!formula
}
{
#
3
}
}
159 160
% sp = single line paragraph sd = single line display
161
% mp = multi line paragraph md = multy line display
162 163
\defineformulaalternative
[
\s!default
]
[
\startdisplaymath
]
[
\stopdisplaymath
]
164
\defineformulaalternative
[
\s!single
]
[
\startdisplaymath
]
[
\stopdisplaymath
]
165
\defineformulaalternative
[
\s!multi
]
[
\startdisplaymath
]
[
\stopdisplaymath
]
166 167
\defineformula
168
[
sp
]
169
[
\c!spacebefore
=
\v!none
,
170
\c!spaceafter
=
\v!none
,
171
\c!indentnext
=
\v!no
,
172
\c!alternative
=
\s!single
]
173 174
\defineformula
175
[
sd
]
176
[
\c!spacebefore
=
\v!none
,
177
\c!spaceafter
=
\v!none
,
178
\c!indentnext
=
\v!yes
,
179
\c!alternative
=
\s!single
]
180 181
\defineformula
182
[
mp
]
183
[
\c!indentnext
=
\v!no
,
184
\c!alternative
=
\s!multi
]
185 186
\defineformula
187
[
md
]
188
[
\c!indentnext
=
\v!yes
,
189
\c!alternative
=
\s!multi
]
190 191
\newtoks
\everyresetformulas
192 193
\appendtoks
194
\let
\currentformula
\empty
% to be checked:
195
\to
\everyresetformulas
196 197
% implementation
198 199
\unexpanded
\def
\strc_formulas_store_number
#
1
#
2
#
3
#
4
#
5
% ref, todo:str, \sync % todo: title etc (like float)
200
{
\settrue
\c_strc_formulas_handle_number
201
\strc_counters_register_component
202
{
formula
}
%
203
\setupcurrentformula
\formulaparameter
\detokenizedformulaparameter
204
\relax
\relax
\relax
205
[
\c!name
=
\v!formula
,
\s!counter
=
\v!formula
,
%
206
\s!hascaption
=
\v!yes
,
\s!hastitle
=
\v!yes
,
\s!hasnumber
=
\v!yes
,
%\s!haslevel=#6,%
207
\c!reference
=
#
1
,
%
208
\c!title
=
\namedformulaentry
,
%
209
\c!list
=
\currentplaceformulalist
,
%
210
\c!bookmark
=
\currentplaceformulabookmark
]
%
211
[
#
2
]
%
212
\glet
\namedformulaentry
\empty
% \relax
213
\glet
#
3
\m_strc_counters_last_registered_index
214
\glet
#
4
\m_strc_counters_last_registered_synchronize
215
\glet
#
5
\m_strc_counters_last_registered_attribute
}
216 217
% modes: 0=unset, 1=forced, 2=none, 3=reference
218 219
\newconstant
\c_strc_formulas_place_number_mode
220
\newconstant
\c_strc_formulas_number_mode
221
\newconstant
\c_strc_formulas_sub_number_mode
222
\newconstant
\c_strc_formulas_nested_number_mode
223 224
\appendtoks
225
\c_strc_formulas_place_number_mode
\zerocount
226
\c_strc_formulas_number_mode
\zerocount
227
\c_strc_formulas_sub_number_mode
\zerocount
228
\c_strc_formulas_nested_number_mode
\zerocount
229
\to
\everyresetformulas
230 231
\newconditional
\c_strc_formulas_handle_number
232
\newconditional
\c_strc_formulas_inside_place
233
\newconditional
\c_strc_formulas_inside_place_sub
234
\newconditional
\c_strc_formulas_inside_formulas
235
\newconditional
\c_strc_formulas_inside_formulas_sub
236 237
\appendtoks
238
\global
\setfalse
\c_strc_formulas_inside_place
239
\global
\setfalse
\c_strc_formulas_inside_place_sub
240
\to
\everyresetformulas
241 242
\def
\strc_formulas_place_number_noneed
243
{
\doif
{
\formulaparameter
\c!numberstrut
}
\v!always
\strut
}
244 245
\def
\strc_formulas_place_numbering
% place formula
246
{
\settrue
\c_strc_formulas_handle_number
247
\strc_formulas_check_reference
\c_strc_formulas_place_number_mode
\currentplaceformulareference
248
\ifnum
\c_strc_formulas_place_number_mode
=
\plustwo
249
\glet
\strc_formulas_place_number
\strc_formulas_place_number_noneed
250
\else
251
\glet
\strc_formulas_place_number
\strc_formulas_place_number_indeed
252
\fi
253
\glet
\strc_formulas_place_number_nested
\strc_formulas_place_number_nested_indeed
}
254 255
\def
\strc_formulas_handle_number
% formulas
256
{
\strc_formulas_check_reference
\c_strc_formulas_number_mode
\currentformulasreference
}
257 258
\def
\strc_formulas_handle_sub_number_indeed
% sub formulas
259
{
\strc_formulas_check_reference
\c_strc_formulas_sub_number_mode
\currentsubformulasreference
260
\strc_counters_increment
\v!formula
261
\strc_formulas_store_number
262
\currentsubformulasreference
263
\empty
264
\currentsubformulasnumber
265
\currentsubformulassynchronize
266
\currentsubformulasattribute
}
267 268
\def
\strc_formulas_handle_sub_number
% sub formulas
269
{
\iftrialtypesetting
270
\strc_counters_save
\v!formula
271
\strc_formulas_handle_sub_number_indeed
272
\strc_counters_restore
\v!formula
273
\else
274
\strc_formulas_handle_sub_number_indeed
275
\fi
}
276 277
\let
\strc_formulas_reference_trace
\relax
278
\let
\strc_formulas_reference_show
\relax
279 280
\unexpanded
\def
\placecurrentformulanumber
281
{
\begingroup
282
\rm
% determines the distance and main font
283
\edef
\p_location
{
\formulaparameter
\c!location
}
%
284
\ifx
\p_location
\v!right
285
\hskip
\formulaparameter
\c!distance
286
\fi
287
\begingroup
288
\useformulastyleandcolor
\c!numberstyle
\c!numbercolor
289
\formulaparameter
\c!numbercommand
290
{
\edef
\p_strut
{
\formulaparameter
\c!numberstrut
}
%
291
\ifx
\p_strut
\v!always
292
\strut
293
\else
\ifx
\p_strut
\v!yes
294
\strut
295
\fi
\fi
296
\formulaparameter
\c!left
297
\namedtaggedlabeltexts
298
\t!formulalabel
\v!formula
299
\t!formulanumber
\v!formula
300
{
\ignorespaces
\strc_formulas_place_current_number
\removeunwantedspaces
}
%
301
\formulaparameter
\c!right
}
%
302
\endgroup
303
\ifx
\p_location
\v!left
304
\hskip
\formulaparameter
\c!distance
305
\fi
306
\endgroup
}
307 308
\unexpanded
\def
\strc_formulas_place_current_number
309
{
\ifx
\namedformulaentry
\empty
310
\strc_formulas_handle_current_references
311
\labeltexts
\currentformula
{
\convertedcounter
[
\v!formula
]
[
]
}
%
312
\else
313
\expandafter
% hm, the next one reset \namedformulaentry
314
\strc_formulas_handle_current_references
315
\namedformulaentry
316
\fi
}
317 318
\def
\theformuladestinationattribute
#
1
%
319
{
\iflocation
\ifx
#
1
\relax
\else
\ifx
#
1
\empty
\else
320
\c_attr_destination
#
1
%
321
\glet
#
1
\relax
322
\fi
\fi
\fi
}
323 324
\let
\currentplaceformulaattribute
\relax
325
\let
\currentformulaattribute
\relax
326
\let
\currentsubformulaattribute
\relax
327
\let
\currentformulasattribute
\relax
328 329
\let
\currentplaceformulanumber
\relax
330
\let
\currentformulanumber
\relax
331
\let
\currentsubformulanumber
\relax
332
\let
\currentformulasnumber
\relax
333 334
\let
\currentformulasreference
\empty
335
\let
\currentformulareference
\empty
336
\let
\currentsubformulareference
\empty
337
\let
\currentnestedformulareference
\empty
338 339
\appendtoks
340
\glet
\currentformulasreference
\empty
341
\glet
\currentformulareference
\empty
342
\glet
\currentsubformulareference
\empty
343
\glet
\currentnestedformulareference
\empty
344
\to
\everyresetformulas
345 346
\let
\currentformulassuffix
\empty
347
\let
\currentformulasuffix
\empty
348
\let
\currentsubformulasuffix
\empty
349
\let
\currentnestedformulasuffix
\empty
350 351
\appendtoks
352
\glet
\currentformulassuffix
\empty
353
\glet
\currentformulasuffix
\empty
354
\glet
\currentsubformulasuffix
\empty
355
\glet
\currentnestedformulasuffix
\empty
356
\to
\everyresetformulas
357 358
\let
\currentplaceformulasynchronize
\relax
359
\let
\currentformulasynchronize
\relax
360
\let
\currentsubformulasynchronize
\relax
361
\let
\currentformulassynchronize
\relax
362 363
\appendtoks
364
\glet
\currentplaceformulasynchronize
\relax
365
\glet
\currentformulassynchronize
\relax
366
\glet
\currentsubformulassynchronize
\relax
367
\glet
\currentnestedformulasynchronize
\relax
368
\to
\everyresetformulas
369 370
% currently we do the number, some day we will do the (sub) formula
371 372
\def
\strc_formulas_handle_current_references
373
{
\strc_formulas_reference_show
374
\ifnum
\c_strc_formulas_place_number_mode
=
\plusthree
375
\strc_formulas_store_number
376
\currentplaceformulareference
377
\empty
378
\currentplaceformulanumber
379
\currentplaceformulasynchronize
380
\currentplaceformulaattribute
381
\currentplaceformulasynchronize
382
\glet
\currentplaceformulasynchronize
\relax
383
\theformuladestinationattribute
\currentplaceformulaattribute
384
\fi
385
\ifnum
\c_strc_formulas_number_mode
=
\plusthree
386
\strc_formulas_store_number
387
\currentformulasreference
388
\empty
389
\currentformulasnumber
390
\currentformulassynchronize
391
\currentformulasattribute
392
\currentformulassynchronize
393
\glet
\currentformulassynchronize
\relax
394
\theformuladestinationattribute
\currentformulasattribute
395
\fi
396
\ifnum
\c_strc_formulas_sub_number_mode
=
\plusthree
397
\currentsubformulassynchronize
398
\glet
\currentsubformulassynchronize
\relax
399
\fi
400
\ifnum
\c_strc_formulas_nested_number_mode
=
\plusthree
401
\strc_formulas_store_number
402
\currentnestedformulareference
403
\empty
404
\currentnestedformulanumber
405
\currentnestedformulasynchronize
406
\currentnestedformulaattribute
407
\currentnestedformulasynchronize
408
\glet
\currentnestedformulasynchronize
\relax
409
\theformuladestinationattribute
\currentnestedformulaattribute
410
\fi
}
411 412
% needs checking ... too many:
413 414
\def
\strc_formulas_handle_numbering_indeed
415
{
\ifx
\namedformulaentry
\empty
416
\strc_counters_increment
\v!formula
417
\doiftext
\currentplaceformulasuffix
{
\strc_counters_setown_sub
\v!formula
\plustwo
\currentplaceformulasuffix
}
%
418
\fi
419
\placecurrentformulanumber
}
420 421
\def
\strc_formulas_handle_numbering
422
{
\iftrialtypesetting
423
\strc_counters_save
\v!formula
424
\strc_formulas_handle_numbering_indeed
425
\strc_counters_restore
\v!formula
426
\else
427
\strc_formulas_handle_numbering_indeed
428
\fi
}
429 430
\def
\strc_formulas_handle_sub_numbering_indeed
431
{
\let
\strc_formulas_handle_sub_numbering
\relax
% else error: see math/numbering-001.tex
432
\doifelsetext
\currentsubformulasuffix
433
{
\strc_counters_setown_sub
\v!formula
\plustwo
\currentsubformulasuffix
}
434
{
\strc_counters_increment_sub
\v!formula
\plustwo
}
%
435
\placecurrentformulanumber
}
436 437
\def
\strc_formulas_handle_sub_numbering
438
{
\iftrialtypesetting
439
\strc_counters_save
\v!formula
440
\strc_formulas_handle_sub_numbering_indeed
441
\strc_counters_restore
\v!formula
442
\else
443
\strc_formulas_handle_sub_numbering_indeed
444
\fi
}
445 446
\def
\strc_formulas_number_indeed
447
{
\ifconditional
\c_strc_formulas_handle_number
448
\hbox
\bgroup
449
% main counter
450
\ifconditional
\c_strc_formulas_inside_formulas_sub
451
% nothing
452
\else
453
\ifcase
\c_strc_formulas_number_mode
454
\ifcase
\c_strc_formulas_place_number_mode
455
\strc_formulas_handle_numbering
456
\or
457
\strc_formulas_handle_numbering
458
\or
459
% nothing
460
\or
461
\strc_formulas_handle_numbering
462
\fi
463
\or
464
\strc_formulas_handle_numbering
465
\or
466
% nothing
467
\or
468
\strc_formulas_handle_numbering
469
\fi
470
\fi
471
% subcounter
472
\ifconditional
\c_strc_formulas_inside_formulas_sub
473
\ifcase
\c_strc_formulas_sub_number_mode
474
\strc_formulas_handle_sub_numbering
% was nothing
475
\or
476
\strc_formulas_handle_sub_numbering
477
\or
478
% nothing
479
\or
480
\strc_formulas_handle_sub_numbering
481
\fi
482
\fi
483
\strc_formulas_reference_trace
484
\egroup
485
\fi
}
486 487
\installstructurelistprocessor
\v!formula
% to be checked ...
488
{
\let
\currentlistentrynumber
\structurelistgenericnumber
489
\let
\currentlistentrytitle
\structurelistgenerictitle
490
\let
\currentlistentrypagenumber
\structurelistpagenumber
491
\strc_lists_apply_renderingsetup
}
492 493
\newif
\ifinformula
494 495
%D We need a hook into the plain math alignment macros
496
%D
497
%D \starttyping
498
%D \displaylines
499
%D \eqalignno
500
%D \eqalignno
501
%D \stoptyping
502
%D
503
%D Otherwise we get a missing \type {$$} error reported.
504 505
\pushoverloadmode
506 507
\let
\reqno
\eqno
% no longer valid as we just nil it
508 509
\let
\math_native_leqno
\leqno
510
\let
\math_native_reqno
\reqno
511 512
\unexpanded
\def
\normaleqno
#
1
{
\writestatus
\m!system
{
no
native
(
l
)
eqno
equation
number
support
}
}
513 514
\let
\normalleqno
\normaleqno
515
\let
\normalreqno
\normaleqno
516 517
\let
\leqno
\normaleqno
518
\let
\reqno
\normaleqno
519
\let
\eqno
\normaleqno
520 521
\popoverloadmode
522 523
%D \macros
524
%D {startsubformulas}
525 526
% \placeformula
527
% \startsubformulas[Maxwell]
528
% \startformulas
529
% \startformula \startalign
530
% \NC \nabla\cdot\bf E \NC = \frac{\rho}{\varepsilon_0} \NR[Maxwell 1]
531
% \NC \nabla\times\bf E \NC = - \frac{\partial\bf B}{\partial t} \NR[Maxwell II]
532
% \stopalign \stopformula
533
% \startformula \startalign
534
% \NC \nabla\cdot \bf B \NC = 0 \NR[Maxwell III]
535
% \NC \nabla\times\bf B \NC = \mu_0{\bf j}+\varepsilon_0\mu_0\frac{\partial\bf E}{\partial t} \NR[Maxwell IV]
536
% \stopalign \stopformula
537
% \stopformulas
538
% \stopsubformulas
539
%
540
% Maxwell : \in [Maxwell] and II : \in [Maxwell II]
541 542
%D Tricky stuff:
543 544
\abovedisplayskip
\zeropoint
545
\abovedisplayshortskip
\zeropoint
% evt. 0pt minus 3pt
546
\belowdisplayskip
\zeropoint
547
\belowdisplayshortskip
\zeropoint
% evt. 0pt minus 3pt
548 549
\predisplaypenalty
\zerocount
550
\postdisplaypenalty
\zerocount
% -5000 goes wrong, see penalty at \section
551
\mathdisplayskipmode
\plusthree
% because align also adds
552 553
% \predisplaygapfactor \zerocount % default is 2000
554 555
\unexpanded
\def
\strc_formulas_forget_display_skips
556
{
\mathdisplayskipmode
\plusthree
557
\abovedisplayskip
\zeropoint
558
\belowdisplayskip
\zeropoint
559
\abovedisplayshortskip
\zeropoint
560
\belowdisplayshortskip
\zeropoint
}
561 562
\newdimen
\d_strc_formulas_display_skip_left
563
\newdimen
\d_strc_formulas_display_skip_right
564
\newdimen
\d_strc_formulas_display_margin_left
565
\newdimen
\d_strc_formulas_display_margin_right
566
\newdimen
\d_strc_formulas_display_pre_threshold
567
\newdimen
\d_strc_formulas_display_width
568 569
\newconstant
\c_strc_formulas_mode
% this will go away
570
\newconstant
\c_strc_formulas_space_model
571 572
\newconstant
\c_strc_math_vertical
% experiment
573 574
\c_strc_formulas_mode
\plustwo
% 0=native 1=simple (old) 2=align (new)
575
\c_strc_formulas_space_model
\plusthree
% replaces \plusone, we might use \plusfour in the future
576 577
\newconditional
\c_strc_formulas_tight
578 579
\newbox
\b_strc_formulas_number
580
\newbox
\b_strc_formulas_content
581 582
\def
\strc_formulas_flush_content_and_number
583
{
\noindentation
584
% \dontleavehmode
585
\kern
\d_strc_formulas_display_margin_left
586
\ifcase
\wd
\b_strc_formulas_number
587
\hbox
to
\displaywidth
\bgroup
588
\hfill
589
\box
\b_strc_formulas_content
590
\hfill
591
\egroup
592
\else
\ifdim
\dimexpr
\wd
\b_strc_formulas_content
+
\wd
\b_strc_formulas_number
\relax
>
\displaywidth
593
\vbox
\bgroup
594
\hsize
\displaywidth
595
\box
\b_strc_formulas_content
596
\par
597
\ifx
\p_location
\v!left
598
\box
\b_strc_formulas_number
\hfill
599
\else
600
\hfill
\box
\b_strc_formulas_number
601
\fi
602
\egroup
603
\else
604
\hbox
to
\displaywidth
\bgroup
605
\ifx
\p_location
\v!left
606
\rlap
{
\box
\b_strc_formulas_number
}
%
607
\hfill
\box
\b_strc_formulas_content
\hfill
608
\else
609
\hfill
\box
\b_strc_formulas_content
\hfill
610
\llap
{
\box
\b_strc_formulas_number
}
%
611
\fi
612
\egroup
613
\fi
\fi
}
614 615
\installcorenamespace
{
mathdisplayspacemodel
}
616 617
\setvalue
{
\??mathdisplayspacemodel
\v!before
:
1
}
% old
618
{
\ifx
\p_spacebefore
\v!none
619
% nothing
620
\else
621
\directvspacing
\p_spacebefore
622
\fi
}
623 624
\setvalue
{
\??mathdisplayspacemodel
\v!after
:
1
}
% old
625
{
\prevdepth
.
5
\strutdp
626
\edef
\p_spaceafter
{
\formulaparameter
\c!spaceafter
}
%
627
\ifx
\p_spaceafter
\v!none
628
% nothing
629
\else
630
\directvspacing
\p_spaceafter
631
\fi
}
632 633
\setvalue
{
\??mathdisplayspacemodel
\v!before
:
2
}
% old
634
{
\ifx
\p_spacebefore
\v!none
635
% nothing
636
\else
637
\directvspacing
\p_spacebefore
638
\fi
639
\prevdepth
-
\maxdimen
}
% texbook pagina 79-80
640 641
\setvalue
{
\??mathdisplayspacemodel
\v!after
:
2
}
% old
642
{
\prevdepth
\lineheight
643
\edef
\p_spaceafter
{
\formulaparameter
\c!spaceafter
}
%
644
\ifx
\p_spaceafter
\v!none
645
% nothing
646
\else
647
\directvspacing
\p_spaceafter
648
\fi
}
649 650
\setvalue
{
\??mathdisplayspacemodel
\v!before
:
3
}
%
651
{
% not ok, try \stopformula\par\startformula vs \stopformula\startformula
652
\let
\m_spacebefore
\empty
653
\ifvmode
654
\ifdim
\lastskip
>
\zeropoint
\else
655
\ifdim
\prevdepth
<
\zeropoint
\else
656
\ifdim
\prevdepth
<
\strutdp
657
% maybe add a tracing option here
658
\ifgridsnapping
659
\let
\m_spacebefore
\v!depth
660
\else
661
\edef
\m_spacebefore
{
\the
\dimexpr
\strutdp
-
\prevdepth
\relax
}
%
662
\fi
663
\fi
664
\fi
665
\fi
666
\nointerlineskip
667
\fi
668
\ifx
\m_spacebefore
\empty
669
\ifx
\p_spacebefore
\v!none
670
% nothing
671
\else
\ifx
\p_spacebefore
\empty
672
\directvspacing
\currentvspacing
673
\else
674
\directvspacing
{
\p_spacebefore
,
\the
\scratchdimen
}
%
675
\fi
\fi
676
\else
677
\ifx
\p_spacebefore
\v!none
678
\directvspacing
{
\m_spacebefore
}
%
679
\else
\ifx
\p_spacebefore
\empty
680
\directvspacing
{
\m_spacebefore
,
\currentvspacing
}
%
681
\else
682
\directvspacing
{
\m_spacebefore
,
\p_spacebefore
}
%
683
\fi
\fi
684
\fi
}
685 686
\setvalue
{
\??mathdisplayspacemodel
\v!after
:
3
}
%
687
{
\prevdepth
\strutdp
% \directvspacing\v!depth
688
\ifx
\p_spaceafter
\v!none
689
% nothing
690
\else
\ifx
\p_spaceafter
\empty
691
\directvspacing
\currentvspacing
692
\else
693
\directvspacing
\p_spaceafter
694
\fi
\fi
}
695 696
\newconditional
\c_math_model_four_indeed
697 698
\setvalue
{
\??mathdisplayspacemodel
\v!before
:
4
}
%
699
{
% not ok, try \stopformula\par\startformula vs \stopformula\startformula
700
\ifvmode
701
\ifinner
702
\csname
\??mathdisplayspacemodel
\v!before
:
3
\endcsname
703
\else
704
\settrue
\c_math_model_four_indeed
705
\forcestrutdepth
706
\nointerlineskip
707
\ifx
\p_spacebefore
\v!none
708
% nothing
709
\else
\ifx
\p_spacebefore
\empty
710
\directvspacing
\currentvspacing
711
\else
712
\directvspacing
{
\p_spacebefore
,
\the
\scratchdimen
}
%
713
\fi
\fi
714
\fi
715
\else
716
\csname
\??mathdisplayspacemodel
\v!before
:
3
\endcsname
717
\fi
}
718 719
\setvalue
{
\??mathdisplayspacemodel
\v!after
:
4
}
%
720
{
\ifconditional
\c_math_model_four_indeed
721
\setfalse
\c_math_model_four_indeed
722
\forcestrutdepth
723
\else
724
\prevdepth
\strutdp
% \directvspacing\v!depth
725
\fi
726
\ifx
\p_spaceafter
\v!none
727
% nothing
728
\else
\ifx
\p_spaceafter
\empty
729
\directvspacing
\currentvspacing
730
\else
731
\directvspacing
\p_spaceafter
732
\fi
\fi
}
733 734
\unexpanded
\def
\setdisplaymathspacemodel
[
#
1
]
%
735
{
\ifcsname
\??mathdisplayspacemodel
\v!before
:
\number
#
1
\endcsname
736
\c_strc_formulas_space_model
#
1
\relax
737
\fi
}
738 739
% \newtoks\everybeforedisplay
740
% \appendtoks\page_sides_check_floats_indeed\to\everybeforedisplay
741 742
\unexpanded
\def
\beforedisplayspace
743
{
\ifhmode
744
\par
745
\fi
746
\ifvmode
747
\edef
\p_spacebefore
{
\formulaparameter
\c!spacebefore
}
%
748
\begincsname
\??mathdisplayspacemodel
\v!before
:
\number
\c_strc_formulas_space_model
\endcsname
749
\fi
750
\ifhmode
751
\par
752
\fi
753
\page_sides_check_floats_indeed
}
% probably needs more
754 755
\unexpanded
\def
\afterdisplayspace
756
{
\ifhmode
757
\par
758
\fi
759
\ifvmode
760
\edef
\p_spaceafter
{
\formulaparameter
\c!spaceafter
}
%
761
\begincsname
\??mathdisplayspacemodel
\v!after
:
\number
\c_strc_formulas_space_model
\endcsname
762
\fi
763
\ifhmode
764
\par
765
\fi
}
766 767
\unexpanded
\def
\setdisplaydimensions
768
{
\displayindent
\dimexpr
769
\d_strc_formulas_display_skip_left
770
+
\d_strc_formulas_display_margin_left
771
\relax
772
\displaywidth
\d_strc_formulas_display_width
773
%\setlocalhsize
774
%\displaywidth\localhsize
775
\ifdim
\hangindent
>
\zeropoint
776
\advance
\displayindent
\hangindent
777
\else
778
\advance
\displaywidth
\hangindent
779
\fi
780
\advance
\displaywidth
\dimexpr
781
-
\displayindent
782
-
\d_strc_formulas_display_skip_right
783
-
\d_strc_formulas_display_margin_right
784
\relax
785
\hsize
\displaywidth
}
% new, else overfull in itemize
786 787
\unexpanded
\def
\strc_formulas_start_formula
#
1
%
788
{
\dodoubleempty
\strc_formulas_start_formula_indeed
[
#
1
]
}
789 790
% \newskip\formulastrutht
791
% \newskip\formulastrutdp
792 793
%D \startbuffer
794
%D \startformula[9pt] x = 1 \stopformula
795
%D \startformula[7pt] x = 1 \stopformula
796
%D \stopbuffer
797
%D
798
%D \typebuffer \getbuffer
799 800
\setvalue
{
\??formulaoption
\v!packed
}
%
801
{
\c_strc_formulas_space_model
\zerocount
}
802 803
\setvalue
{
\??formulaoption
\v!tight
}
%
804
{
\settrue
\c_strc_formulas_tight
}
805 806
\setvalue
{
\??formulaoption
\v!middle
}
%
807
{
\d_strc_formulas_display_skip_left
\zeropoint
808
\d_strc_formulas_display_skip_right
\zeropoint
}
809 810
\setvalue
{
\??formulaoption
\v!depth
}
%
811
{
\c_strc_formulas_space_model
\plusfour
}
812 813
\setvalue
{
\??formulaoption
\v!line
}
%
814
{
\ifgridsnapping
815
\setformulaparameter
\c!grid
{
\v!math
:
\v!line
}
%
816
\fi
}
817 818
\setvalue
{
\??formulaoption
\v!halfline
}
%
819
{
\ifgridsnapping
820
\setformulaparameter
\c!grid
{
\v!math
:
\v!halfline
}
%
821
\fi
}
822 823
\setvalue
{
\??formulaoption
-
\v!line
}
%
824
{
\ifgridsnapping
825
\setformulaparameter
\c!grid
{
\v!math
:
-
\v!line
}
%
826
\fi
}
827 828
\setvalue
{
\??formulaoption
-
\v!halfline
}
%
829
{
\ifgridsnapping
830
\setformulaparameter
\c!grid
{
\v!math
:
-
\v!halfline
}
%
831
\fi
}
832 833
% when we have 1.0.6 we wil use \mathpenaltiesmode
834
%
835
% \prebinoppenalty -100
836
% \prerelpenalty -100
837 838
\def
\strc_math_set_split
839
{
\edef
\p_split
{
\formulaparameter
\c!split
}
%
840
\ifx
\p_split
\v!yes
841
\global
\c_strc_math_vertical
\plusone
842
\else
\ifx
\p_split
\v!page
843
\global
\c_strc_math_vertical
\plustwo
844
\else
845
\global
\c_strc_math_vertical
\zerocount
846
\fi
\fi
847
\ifcase
\c_strc_math_vertical
848
% \mathpenaltiesmode \zerocount
849
\clf_setmathpenalties
\zerocount
850
\clf_resetmathhang
851
\else
852
% \mathpenaltiesmode \plusone
853
\clf_setmathpenalties
\plusone
854
\edef
\p_hang
{
\formulaparameter
\c!hang
}
%
855
\ifx
\p_hang
\v!none
856
\global
\setfalse
\c_strc_math_indent
857
\clf_resetmathhang
858
\else
859
\global
\settrue
\c_strc_math_indent
860
\clf_setmathhang
{
%
861
method
{
\p_hang
}
%
862
distance
\formulaparameter
\c!distance
863
}
%
864
\fi
865
\fi
}
866 867
\setupformula
868
[
\c!split
=
\v!no
,
869
\c!distance
=
\zeropoint
,
870
%\c!interlinespace=1.5\lineheight,
871
\c!interlinespace
=
,
872
\c!hang
=
\v!none
]
873 874
% for the moment (when testing) we use a penalty 1
875 876
\unexpanded
\def
\strc_math_align_here
{
\ifmmode
\penalty
\plusone
\fi
}
%
877
\unexpanded
\def
\strc_math_break_here
{
\ifmmode
\hfill
\break
\fi
}
%
878 879
\appendtoks
880
\let
\alignhere
\strc_math_align_here
881
\let
\breakhere
\strc_math_break_here
882
\to
\everymathematics
883 884
\unexpanded
\def
\strc_formulas_start_formula_indeed
[
#
1
]
[
#
2
]
% setting leftskip adaption is slow !
885
{
\ifhmode
886
\par
887
\fi
888
\bgroup
% HERE
889
\iftrialtypesetting
\else
890
\global
\advance
\c_strc_formulas_n
\plusone
891
\fi
892
\def
\currentformula
{
#
1
}
%
893
\strc_math_set_split
894
\dostarttaggedchained
\t!formula
\currentformula
\??formula
895
\setfalse
\c_strc_formulas_tight
896
\d_strc_formulas_display_skip_left
\leftskip
897
\d_strc_formulas_display_skip_right
\rightskip
898
\d_strc_formulas_display_width
\formulaparameter
\c!width
\relax
899
\d_strc_formulas_display_margin_left
\formulaparameter
\c!leftmargin
\relax
900
\d_strc_formulas_display_margin_right
\formulaparameter
\c!rightmargin
\relax
901
\ifsecondargument
902
\doifelseassignment
{
#
2
}
% this is new, so that we can also set the grid
903
{
\setupcurrentformula
[
#
2
]
%
904
\edef
\p_option
{
\formulaparameter
\c!option
}
}
%
905
{
\edef
\p_option
{
\formulaparameter
\c!option
}
%
906
\edef
\p_option
{
\ifx
\p_option
\empty
\else
\p_option
,
\fi
#
2
}
}
%
907
\else
908
\edef
\p_option
{
\formulaparameter
\c!option
}
%
909
\fi
910
\ifx
\p_option
\empty
\else
911
\rawprocesscommacommand
[
\p_option
]
\strc_formulas_option
912
\fi
913
\edef
\p_margin
{
\formulaparameter
\c!margin
}
%
914
\ifx
\p_margin
\empty
\else
915
\dosetleftskipadaption
\p_margin
916
\d_strc_formulas_display_margin_left
\leftskipadaption
917
\fi
918
\let
\strc_formulas_start_formula
\strc_formulas_start_formula_nested
919
\strc_formulas_forget_display_skips
920
\the
\everybeforedisplayformula
921
\csname
\e!start
\formulaparameter
\c!alternative
\v!formula
\endcsname
}
922 923
\unexpanded
\def
\strc_formulas_start_formula_nested
#
1
%
924
{
\bgroup
925
\let
\strc_formulas_stop_formula
\strc_formulas_stop_formula_nested
926
\dostarttagged
\t!subformula
\empty
}
927 928
\unexpanded
\def
\strc_formulas_stop_formula_nested
929
{
\dostoptagged
930
\egroup
}
931 932
% tagging of formulanumbers is not ok (we get two display maths blobs)
933 934
\newcount
\c_strc_formulas_n
935 936
\ifdefined
\dotagregisterformula
\else
\let
\dotagregisterformula
\gobbleoneargument
\fi
937 938
\unexpanded
\def
\strc_formulas_stop_formula
939
{
\strc_formulas_place_number
% in case it hasn't happened yet
940
\strc_formulas_flush_number
% in case we are in native mode
941
\dostarttagged
\t!formulacontent
\empty
942
\dotagregisterformula
\c_strc_formulas_n
943
\csname
\e!stop
\formulaparameter
\c!alternative
\v!formula
\endcsname
944
\dostoptagged
945
\dostoptagged
946
\nonoindentation
947
\useindentnextparameter
\formulaparameter
948
\egroup
949
\hangafter
\minusone
% added for side floats
950
\hangindent
\zeropoint
% added for side floats
951
\setfalse
\c_strc_formulas_handle_number
952
\the
\everyresetformulas
953
\dorechecknextindentation
}
% here ?
954 955
% experiment:
956 957
\def
\strc_formulas_set_grid_snapping
958
{
\edef
\p_grid
{
\formulaparameter
\c!grid
}
%
959
\ifx
\p_grid
\empty
\else
960
\spac_grids_snap_value_auto
\p_grid
961
\fi
}
962 963
\appendtoks
964
\ifgridsnapping
965
\strc_formulas_set_grid_snapping
966
\fi
967
\to
\everybeforedisplayformula
968 969
% \unexpanded\def\switchtoformulabodyfont
970
% {\switchtobodyfont}
971 972
\setuvalue
{
\v!formula
}
{
\dosingleempty
\strc_formulas_formula
}
973 974
\def
\strc_formulas_formula
[
#
1
]
#
2
% todo: tagged
975
{
\begingroup
976
\edef
\p_direct
{
#
1
}
%
977
\ifx
\p_direct
\empty
\else
978
\rawprocesscommalist
[
\p_direct
]
\strc_formulas_option
979
\fi
980
% not : \def\strc_formulas_formula[##1]##2{\mathematics{##2}}%
981
\mathematics
{
#
2
}
%
982
\endgroup
}
983 984
%D \starttyping
985
%D % test \par % no preceding hlist
986
%D % $$x$$ % preceding hlist
987
%D % \noindent $$x$$ % no preceding hlist
988
%D \startformula x \stopformula % now has \noindent (in mkii we messed with baselineskip)
989
%D \stoptyping
990 991
\unexpanded
\def
\startdisplaymath
992
{
\ifhmode
993
\par
994
\fi
995
\bgroup
996
\informulatrue
997
\beforedisplayspace
998
\setdisplaydimensions
999
\ifcase
\c_strc_formulas_mode
1000
\noindent
% prevents that tex injects empty line (when using native display mechanism)
1001
\Ucheckedstartdisplaymath
1002
\the
\everydisplay
% new (probably too much)
1003
\or
1004
\setbox
\b_strc_formulas_content
\hbox
\bgroup
1005
\normalUstartmath
1006
\displaystyle
1007
\the
\everydisplay
% new (probably too much)
1008
\else
1009
\expandafter
\startinnermath
1010
\fi
1011
\begingroup
}
% less interference with upcoming a \over b
1012 1013
\unexpanded
\def
\stopdisplaymath
1014
{
\endgroup
% less interference with upcoming a \over b
1015
\ifcase
\c_strc_formulas_mode
1016
\Ucheckedstopdisplaymath
1017
\or
1018
\normalUstopmath
1019
\egroup
1020
\strc_formulas_flush_content_and_number
1021
\else
1022
\expandafter
\stopinnermath
1023
\fi
1024
\afterdisplayspace
1025
\egroup
}
1026 1027
% already defined
1028
%
1029
% \let\startinnermath\empty
1030
% \let\stopinnermath \empty
1031 1032
% \defineformulaalternative[multi][\begindmath][\enddmath]
1033
%
1034
% \fakewords{20}{40}\epar
1035
% \placeformula {a} $$ \fakespacingformula $$
1036
% \fakewords{20}{40}\epar
1037
% \placeformula {b} \startformule \fakespacingformula \stopformule
1038
% \placeformula {b} \startformule \fakespacingformula \stopformule
1039
% \fakewords{20}{40}\epar
1040
% \placeformula {c} \startmdformule \fakespacingformula \stopmdformule
1041
% \placeformula {c} \startmdformule \fakespacingformula \stopmdformule
1042
% \fakewords{20}{40}\epar
1043
% \placeformula {d} \startmpformule \fakespacingformula \stopmpformule
1044
% \placeformula {d} \startmpformule \fakespacingformula \stopmpformule
1045
% \fakewords{20}{40}\epar
1046
% \placeformula {e} \startsdformule \fakespacingformula \stopsdformule
1047
% \placeformula {e} \startsdformule \fakespacingformula \stopsdformule
1048
% \fakewords{20}{40}\epar
1049
% \placeformula {f} \startspformule \fakespacingformula \stopspformule
1050
% \placeformula {f} \startspformule \fakespacingformula \stopspformule
1051
% \fakewords{20}{40}
1052 1053
\unexpanded
\def
\startsubformulas
1054
{
\dosingleempty
\strc_formulas_start_sub_formulas
}
1055 1056
\def
\strc_formulas_start_sub_formulas
[
#
1
]
%
1057
{
\edef
\currentsubformulasreference
{
#
1
}
%
1058
\global
\settrue
\c_strc_formulas_inside_formulas_sub
1059
\strc_formulas_handle_sub_number
}
1060 1061
\unexpanded
\def
\stopsubformulas
1062
{
\nonoindentation
1063
\useindentnextparameter
\subformulaparameter
1064
\the
\everyresetformulas
% to be checked
1065
\global
\setfalse
\c_strc_formulas_inside_formulas_sub
1066
\dorechecknextindentation
}
% here ?
1067 1068
%D Named subformulas (to be redone)
1069 1070
\unexpanded
\def
\startnamedsubformulas
1071
{
\dosingleempty
\strc_formulas_start_named_sub_formulas
}
1072 1073
\def
\strc_formulas_start_named_sub_formulas
[
#
1
]
#
2
%
1074
{
\setformulalistentry
{
#
2
}
%
1075
\startsubformulas
[
#
1
]
}
1076 1077
\unexpanded
\def
\stopnamedsubformulas
1078
{
\stopsubformulas
}
1079 1080
%D Experimental goodie:
1081
%D
1082
%D \startbuffer
1083
%D \placelist[formula][criterium=text] \blank[2*big]
1084
%D \placenamedformula[one]{first} \startformula a = 1 \stopformula \endgraf
1085
%D \placeformula \startformula a = 2 \stopformula \endgraf
1086
%D \placenamedformula {second} \startformula a = 3 \stopformula \endgraf
1087
%D \stopbuffer
1088
%D
1089
%D \typebuffer \getbuffer
1090 1091
\unexpanded
\def
\startformulas
1092
{
\dosingleempty
\strc_formulas_start_formulas
}
1093 1094
\expandafter
\let
\csname
\e!stop
\v!formulas
\endcsname
\relax
1095 1096
\unexpanded
\def
\strc_formulas_nested_formula_start
1097
{
\hbox
to
\displaywidth
\bgroup
1098
\hsize
\displaywidth
1099
\hss
1100
%\Ustartmath
1101
\dostarttagged
\t!formulacontent
\empty
1102
\csname
\e!start
\formulaparameter
\c!alternative
\v!formula
\endcsname
}
1103 1104
\unexpanded
\def
\strc_formulas_nested_formula_stop
1105
{
\csname
\e!stop
\formulaparameter
\c!alternative
\v!formula
\endcsname
1106
\dostoptagged
1107
%\Ustopmath
1108
\hss
1109
\egroup
1110
\hss
}
1111 1112
\normalexpanded
{
\def
\noexpand
\strc_formulas_start_formulas
[
#
1
]
#
2
\csname
\e!stop
\v!formulas
\endcsname
}
%
1113
{
\startformula
1114
\dostarttagged
\t!formulaset
\empty
1115
\global
\settrue
\c_strc_formulas_inside_formulas
1116
\edef
\currentformulasreference
{
#
1
}
%
1117
\strc_formulas_handle_number
1118
\let
\currentformula
\empty
1119
\strc_formulas_forget_display_skips
1120
\unexpanded
\def
\startformula
1121
{
\advance
\scratchcounter
\plusone
1122
\expandafter
\gobbleuntil
\csname
\e!stop
\v!formula
\endcsname
}
%
1123
\scratchcounter
\zerocount
1124
#
2
% preroll
1125
\hbox
to
\displaywidth
\bgroup
1126
\divide
\displaywidth
\scratchcounter
1127
\hss
1128
\let
\startformula
\strc_formulas_nested_formula_start
1129
\let
\stopformula
\strc_formulas_nested_formula_stop
1130
#
2
%
1131
\egroup
1132
\global
\setfalse
\c_strc_formulas_inside_formulas
1133
\dostoptagged
1134
\stopformula
1135
\the
\everyresetformulas
1136
\hangafter
\minusone
% added for side floats
1137
\hangindent
\zeropoint
}
% added for side floats
1138 1139
% place
1140 1141
\def
\m_strc_formulas_flag_inhibit
{
-
}
1142
\def
\m_strc_formulas_flag_force
{
+
}
1143 1144
\def
\strc_formulas_check_reference
#
1
#
2
%
1145
{
#
1
\unless
\ifx
\namedformulaentry
\empty
% \relax % new 29/8/2010
1146
\plusthree
1147
\else
\ifx
#
2
\empty
1148
\zerocount
1149
\else
\ifx
#
2
\m_strc_formulas_flag_force
1150
\plusone
1151
\else
\ifx
#
2
\m_strc_formulas_flag_inhibit
1152
\plustwo
1153
\else
1154
\plusthree
1155
\fi
\fi
\fi
\fi
}
1156 1157
\unexpanded
\def
\formulanumber
1158
{
\strc_formulas_number
}
% for the moment
1159 1160
\unexpanded
\def
\strc_formulas_number
1161
{
\dosingleempty
\strc_formulas_number_again
}
1162 1163
\unexpanded
\def
\strc_formulas_number_again
[
#
1
]
%
1164
{
\def
\currentformulareference
{
#
1
}
%
1165
\strc_formulas_place_number_in_box
}
1166 1167
\unexpanded
\def
\placeformula
1168
{
\global
\settrue
\c_strc_formulas_inside_place
1169
\dosingleempty
\strc_formulas_place
}
1170 1171
\unexpanded
\def
\placesubformula
1172
{
\global
\settrue
\c_strc_formulas_inside_place_sub
1173
\dosingleempty
\strc_formulas_place
}
1174 1175
\unexpanded
\def
\strc_formulas_place
[
#
1
]
%
1176
{
\def
\currentplaceformulareference
{
#
1
}
%
1177
\let
\currentplaceformulasuffix
\empty
1178
\doifelsenextbgroup
\strc_formulas_place_yes
\strc_formulas_place_nop
}
% [ref]{}
1179 1180
\unexpanded
\def
\strc_formulas_place_yes
#
1
%
1181
{
\def
\currentplaceformulasuffix
{
#
1
}
%
1182
\strc_formulas_place_nop
}
1183 1184
\unexpanded
\def
\strc_formulas_place_nop
1185
{
\doifelsenextchar
$
\strc_formulas_place_pickup
\strc_formulas_place_indeed
}
% [ref]$$ [ref]\start
1186 1187
\unexpanded
\def
\strc_formulas_place_indeed
1188
{
\strc_formulas_place_numbering
}
1189 1190
\unexpanded
\def
\strc_formulas_place_pickup
$
$
#
1
$
$
%
1191
{
\strc_formulas_place_numbering
1192
\strc_formulas_start_formula
{
}
#
1
\strc_formulas_stop_formula
}
1193 1194
% \let\startplaceformula\placeformula
1195
% \let\stopplaceformula \relax
1196 1197
% \startplaceformula \startformula e=mc^2 \stopformula \stopplaceformula
1198
% \startplaceformula[-] \startformula e=mc^2 \stopformula \stopplaceformula
1199
% \startplaceformula[x] \startformula e=mc^2 \stopformula \stopplaceformula
1200
% \startplaceformula[reference=foo] \startformula e=mc^2 \stopformula \stopplaceformula
1201
% \startplaceformula[title=whatever] \startformula e=mc^2 \stopformula \stopplaceformula
1202
% \startplaceformula[suffix=x] \startformula e=mc^2 \stopformula \stopplaceformula
1203 1204
\unexpanded
\def
\startplaceformula
{
\dosingleempty
\strc_formulas_start_place
}
1205
\unexpanded
\def
\stopplaceformula
{
\strc_formulas_stop_place
}
1206 1207
\let
\currentplaceformulareference
\empty
1208
\let
\currentplaceformulasuffix
\empty
1209 1210
\def
\strc_formulas_start_place
1211
{
\begingroup
1212
\global
\settrue
\c_strc_formulas_inside_place
1213
\iffirstargument
1214
\expandafter
\strc_formulas_start_place_yes
1215
\else
1216
\expandafter
\strc_formulas_start_place_nop
1217
\fi
}
1218 1219
\def
\strc_formulas_start_place_yes
[
#
1
]
%
1220
{
\doifassignmentelse
{
#
1
}
\strc_formulas_start_place_parameters
\strc_formulas_start_place_reference
[
#
1
]
}
1221 1222
\def
\strc_formulas_start_place_nop
[
#
1
]
%
1223
{
\let
\currentplaceformulareference
\empty
1224
\let
\currentplaceformulasuffix
\empty
1225
\strc_formulas_place_nop
}
1226 1227
\def
\strc_formulas_start_place_reference
[
#
1
]
%
1228
{
\edef
\currentplaceformulareference
{
#
1
}
%
1229
\let
\currentplaceformulasuffix
\empty
1230
%\doifelsenextbgroup\strc_formulas_place_yes\strc_formulas_place_nop} % [ref]{}
1231
\strc_formulas_place_nop
}
1232 1233
\let
\currentplaceformulabookmark
\empty
1234
\let
\currentplaceformulalist
\empty
1235 1236
\def
\strc_formulas_start_place_parameters
[
#
1
]
%
1237
{
\letdummyparameter
\c!title
\empty
1238
\letdummyparameter
\c!reference
\empty
1239
\letdummyparameter
\c!bookmark
\empty
1240
\letdummyparameter
\c!list
\empty
1241
\letdummyparameter
\c!suffix
\empty
1242
\getdummyparameters
[
#
1
]
%
1243
\edef
\currentplaceformulatitle
{
\dummyparameter
\c!title
}
%
1244
\edef
\currentplaceformulareference
{
\dummyparameter
\c!reference
}
%
1245
\edef
\currentplaceformulalist
{
\dummyparameter
\c!list
}
%
1246
\edef
\currentplaceformulabookmark
{
\dummyparameter
\c!bookmark
}
%
1247
\edef
\currentplaceformulasuffix
{
\dummyparameter
\c!suffix
}
%
1248
\ifx
\currentplaceformulatitle
\empty
\else
1249
\normalexpanded
{
\setformulalistentry
{
\currentplaceformulatitle
}
}
%
1250
\fi
1251
\doifelsenextbgroup
\strc_formulas_place_yes
\strc_formulas_place_nop
}
% [ref]{}
1252 1253
\def
\strc_formulas_stop_place
1254
{
\relax
1255
\endgroup
}
1256 1257
% to be checked
1258 1259
\let
\strc_formulas_place_number
\relax
1260
\let
\strc_formulas_place_number_nested
\gobbletwoarguments
1261 1262
\def
\strc_formulas_place_number_nested_indeed
#
1
#
2
%
1263
{
\def
\currentnestedformulareference
{
#
1
}
%
1264
\def
\currentnestedformulasuffix
{
#
2
}
%
1265
\strc_formulas_check_reference
\c_strc_formulas_nested_number_mode
\currentnestedformulareference
1266
\ifcase
\c_strc_formulas_nested_number_mode
1267
% nothing
1268
\or
1269
\glet
\strc_formulas_place_number
\relax
1270
\expandafter
\strc_formulas_number
% hm, looks ahead for []
1271
\or
1272
% nothing
1273
\or
1274
\glet
\strc_formulas_place_number
\relax
1275
\expandafter
\strc_formulas_number
% hm, looks ahead for []
1276
\fi
}
1277 1278
\def
\strc_formulas_place_number_indeed
1279
{
\strc_formulas_place_number_in_box
}
1280 1281
\def
\strc_formulas_place_number_in_box
1282
{
\dostarttagged
\t!formulacaption
\empty
1283
\global
\setbox
\b_strc_formulas_number
\naturalhbox
{
\strc_formulas_number_indeed
}
%
1284
\dostoptagged
}
1285 1286
\def
\strc_formulas_flush_number
1287
{
\ifcase
\c_strc_formulas_mode
1288
\ifzeropt
\wd
\b_strc_formulas_number
1289
% nothing to be done
1290
\else
1291
\ifx
\p_location
\v!left
1292
\math_native_leqno
{
\box
\b_strc_formulas_number
}
%
1293
\else
1294
\math_native_reqno
{
\box
\b_strc_formulas_number
}
%
1295
\fi
1296
\fi
1297
\fi
}
1298 1299
% todo
1300 1301
\unexpanded
\def
\placenamedformula
1302
{
\dosingleempty
\strc_formulase_place_named
}
1303 1304
\unexpanded
\def
\strc_formulase_place_named
1305
{
\iffirstargument
1306
\expandafter
\strc_formulase_place_named_yes
1307
\else
1308
\expandafter
\strc_formulase_place_named_nop
1309
\fi
}
1310 1311
\def
\strc_formulase_place_named_yes
[
#
1
]
#
2
%
1312
{
\setformulalistentry
{
#
2
}
%
1313
\placeformula
[
#
1
]
}
1314 1315
\def
\strc_formulase_place_named_nop
[
#
1
]
#
2
%
1316
{
\setformulalistentry
{
#
2
}
%
1317
\placeformula
}
1318 1319
\let
\namedformulaentry
\empty
% \relax % this will become a key/value so that we can do bookmarks
1320 1321
\unexpanded
\def
\setformulalistentry
#
1
%
1322
{
\gdef
\namedformulaentry
{
#
1
}
}
1323 1324
\protect
\endinput
1325 1326
% \abovedisplayshortskip0pt \belowdisplayshortskip0pt \abovedisplayskip0pt \belowdisplayskip0pt \forgetall
1327
%
1328
% test \par $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1329
% test \par $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1330
% test plus \par \prevdepth \maxdimen $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1331
% test minus \par \prevdepth-\maxdimen $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1332
%
1333
% \parskip\baselineskip
1334
%
1335
% test \par $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1336
% test \par $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1337
% test plus \par \prevdepth \maxdimen $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1338
% test minus \par \prevdepth-\maxdimen $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1339