1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Structure Macros Math Numbering}
15
16\registerctxluafile{strcmat}{autosuffix}
17
18
19
20
21
22\unprotect
23
24\setupformulas
25 [
26
27
28
29
30
31
32
33
34
35 \c!snap=\v!no,
36 \c!snapstep=\v!medium,
37 \c!grid=\v!math,
38 \c!location=\v!right,
39 \c!left=(,
40 \c!right=),
41 \c!expansion=\v!yes,
42 \c!spacebefore=\v!big,
43 \c!spaceafter=\formulaparameter\c!spacebefore,
44 \c!spaceinbetween=\v!quarterline,
45 \c!width=\hsize,
46 \c!margin=\zeropoint,
47 \c!leftmargin=\formulaparameter\c!margin,
48 \c!rightmargin=\formulaparameter\c!margin,
49 \c!indentnext=\v!no,
50 \c!alternative=\s!default,
51 \c!strut=\v!yes,
52 \c!numberstrut=\v!yes,
53 \c!margindistance=\zeropoint,
54 \c!leftmargindistance=\formulaparameter\c!margindistance,
55 \c!rightmargindistance=\formulaparameter\c!margindistance,
56 \c!numberthreshold=\emwidth,
57 \c!numberdistance=2\emwidth]
58
59
60
61
62
63
64
65
66\setupformulaframed
67 [
68
69
70 \c!offset=.5\exheight]
71
72\matheqnogapstep\zerocount
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120\setupsubformulas
121 [\c!indentnext=\formulaparameter\c!indentnext]
122
123\definecounter
124 [\v!formula]
125
126\defineconversionset
127 [\v!formula]
128 [numbers,characters]
129
130\installcounterassociation{formula} \registerformulacounter\v!formula
131
132\appendtoks
133 \synchronizeformulacounters
134\to \everysetupformula
135
136
137
138
139
140\setupformulas
141 [\c!numberconversionset=\v!formula]
142
143\appendtoks
144 \normalexpanded{\definelist[\currentformula]}
145 \frozen\instance\protected\edefcsname\e!start\currentformula\v!formula\endcsname{\strc_formulas_start_formula{\currentformula}}
146 \frozen\instance\protected\edefcsname\e!stop \currentformula\v!formula\endcsname{\strc_formulas_stop_formula}
147\to \everydefineformula
148
149\definelist[\v!formula]
150
151\permanent\protected\defcsname\e!start\v!formula\endcsname{\strc_formulas_start_formula{}}
152\permanent\protected\defcsname\e!stop \v!formula\endcsname{\strc_formulas_stop_formula}
153
154\permanent\protected\def\startnamedformula[#1]
155 {\strc_formulas_start_formula{#1}}
156
157\permanent\protected\def\stopnamedformula
158 {\strc_formulas_stop_formula}
159
160\let\strc_formulas_start_formula\relax
161\let\strc_formulas_stop_formula \relax
162
163\permanent\tolerant\protected\def\defineformulaalternative[#1]#*[#2]#*[#3]
164 {\frozen\instance\protected\defcsname\e!start#1\v!formula\endcsname{#2}
165 \frozen\instance\protected\defcsname\e!stop #1\v!formula\endcsname{#3}}
166
167
168
169
170\defineformulaalternative[\s!default][\startdisplaymath][\stopdisplaymath]
171\defineformulaalternative[\s!single] [\startdisplaymath][\stopdisplaymath]
172\defineformulaalternative[\s!multi] [\startdisplaymath][\stopdisplaymath]
173
174\defineformula
175 [sp]
176 [\c!spacebefore=\v!none,
177 \c!spaceafter=\v!none,
178 \c!indentnext=\v!no,
179 \c!alternative=\s!single]
180
181\defineformula
182 [sd]
183 [\c!spacebefore=\v!none,
184 \c!spaceafter=\v!none,
185 \c!indentnext=\v!yes,
186 \c!alternative=\s!single]
187
188\defineformula
189 [mp]
190 [\c!indentnext=\v!no,
191 \c!alternative=\s!multi]
192
193\defineformula
194 [md]
195 [\c!indentnext=\v!yes,
196 \c!alternative=\s!multi]
197
198\newtoks\everyresetformulas
199
200\appendtoks
201 \lettonothing\currentformula
202\to \everyresetformulas
203
204
205
206\protected\def\strc_formulas_store_number#1#2#3#4#5#6
207 {\c_strc_formulas_handle_number\conditionaltrue
208 \strc_counters_register_component
209 {formula}
210 \setupcurrentformula \formulaparameter \detokenizedformulaparameter
211 \relax \relax \relax
212 [\c!name=\v!formula,\s!counter=\v!formula,
213 \s!hascaption=\v!yes,
214 \s!hastitle=\v!yes,
215 \s!hasnumber=\ifempty\namedformulaentry\v!yes\else\v!no\fi,
216 \s!haslevel=#6,
217 \c!reference=#1,
218 \c!title=\namedformulaentry,
219 \c!list=\currentplaceformulalist,
220 \c!bookmark=\currentplaceformulabookmark]
221 [#2]
222 \glettonothing\namedformulaentry
223 \glet#3\m_strc_counters_last_registered_index
224 \glet#4\m_strc_counters_last_registered_synchronize
225 \glet#5\m_strc_counters_last_registered_attribute}
226
227
228
229\newconstant\c_strc_formulas_place_number_mode
230\newconstant\c_strc_formulas_number_mode
231\newconstant\c_strc_formulas_sub_number_mode
232\newconstant\c_strc_formulas_nested_number_mode
233\newconstant\c_strc_formulas_counter_level
234
235\let\strc_formulas_show_modes \relax
236\let\strc_formulas_show_references\relax
237
238\installtextracker
239 {math.numbering}
240 {\let\strc_formulas_show_modes \strc_formulas_show_modes_indeed
241 \let\strc_formulas_show_references\strc_formulas_show_references_indeed}
242 {\let\strc_formulas_show_modes \relax
243 \let\strc_formulas_show_references\relax}
244
245\def\strc_formulas_mode_row#1#2#3#4
246 {\NC #1
247 \NC \ifcase#2\relax unset\or forced\or none\or reference\fi
248 \NC #3
249 \NC #4
250 \NC \NR}
251
252\protected\def\strc_formulas_show_modes_indeed
253 {\rlap{\enspace\vcenter to \zeropoint{\vss\ruledvcenter{
254 \forgetall\smallinfofont\setupinterlinespace
255 \starttabulate[llll]
256 \strc_formulas_mode_row{place} \c_strc_formulas_place_number_mode \currentplaceformulareference \currentplaceformulasuffix
257 \strc_formulas_mode_row{main} \c_strc_formulas_number_mode \currentformulareference \currentformulasuffix
258 \strc_formulas_mode_row{sub} \c_strc_formulas_sub_number_mode \currentsubformulareference \currentsubformulasuffix
259 \strc_formulas_mode_row{nested} \c_strc_formulas_nested_number_mode \currentnestedformulareference \currentnestedformulasuffix
260 \stoptabulate
261 \vss}}}}
262
263\protected\def\strc_formulas_show_references_indeed
264 {\llap{\vcenter to \zeropoint{\vss\ruledvcenter{
265 \forgetall\smallinfofont\setupinterlinespace
266 \starttabulate[llll]
267 \NC place\NC
268 \ifnum\c_strc_formulas_place_number_mode=\plusthree
269 \ifconditional\c_strc_formulas_referenced
270 \textminus
271 \else
272 \textplus
273 \fi
274 \else
275 \textminus
276 \fi
277 \NC \NR
278 \NC formulas\NC
279 \ifnum\c_strc_formulas_number_mode=\plusthree
280 \textplus
281 \else
282 \textminus
283 \fi
284 \NC \NR
285 \NC nested\NC
286 \ifnum\c_strc_formulas_nested_number_mode=\plusthree
287 \textplus
288 \else
289 \textminus
290 \fi
291 \NC \NR
292 \stoptabulate
293 \vss}}}\enspace}
294
295\appendtoks
296 \c_strc_formulas_place_number_mode \zerocount
297 \c_strc_formulas_number_mode \zerocount
298 \c_strc_formulas_sub_number_mode \zerocount
299 \c_strc_formulas_nested_number_mode\zerocount
300\to \everyresetformulas
301
302\newconditional\c_strc_formulas_handle_number
303\newconditional\c_strc_formulas_inside_place
304\newconditional\c_strc_formulas_inside_place_sub
305\newconditional\c_strc_formulas_inside_formulas
306\newconditional\c_strc_formulas_inside_formulas_sub
307\newconditional\c_strc_formulas_incremented
308\newconditional\c_strc_formulas_referenced
309
310\appendtoks
311 \global\c_strc_formulas_inside_place \conditionalfalse
312 \global\c_strc_formulas_inside_place_sub\conditionalfalse
313\to \everyresetformulas
314
315\def\strc_formulas_place_number_noneed
316 {\ifcstok{\formulaparameter\c!numberstrut}\v!always
317 \strut
318 \fi}
319
320\def\strc_formulas_place_numbering
321 {\c_strc_formulas_handle_number\conditionaltrue
322 \strc_formulas_check_reference\c_strc_formulas_place_number_mode\currentplaceformulareference
323 \ifnum\c_strc_formulas_place_number_mode=\plustwo
324 \glet\strc_formulas_place_number\strc_formulas_place_number_noneed
325 \else
326 \glet\strc_formulas_place_number\strc_formulas_place_number_indeed
327 \fi
328 \glet\strc_formulas_place_number_nested\strc_formulas_place_number_nested_indeed}
329
330\def\strc_formulas_handle_number
331 {\strc_formulas_check_reference\c_strc_formulas_number_mode\currentformulasreference}
332
333\def\strc_formulas_handle_sub_number_indeed
334 {\strc_formulas_check_reference\c_strc_formulas_sub_number_mode\currentsubformulasreference
335 \strc_counters_increment\v!formula
336 \strc_formulas_store_number
337 \currentsubformulasreference
338 \empty
339 \currentsubformulasnumber
340 \currentsubformulassynchronize
341 \currentsubformulasattribute
342 \plustwo}
343
344\def\strc_formulas_handle_sub_number
345 {\iftrialtypesetting
346 \strc_counters_save\v!formula
347 \strc_formulas_handle_sub_number_indeed
348 \strc_counters_restore\v!formula
349 \else
350 \strc_formulas_handle_sub_number_indeed
351 \fi}
352
353\let\strc_formulas_reference_trace\relax
354\let\strc_formulas_reference_show \relax
355
356\permanent\protected\def\placecurrentformulanumber
357 {\begingroup
358 \rm
359 \edef\p_location{\formulaparameter\c!location}
360 \ifx\p_location\v!atrightmargin
361 \ifzeropt\s_strc_formulas_margin_right
362 \let\p_location\v!right
363 \fi
364 \orelse\ifx\p_location\v!atleftmargin
365 \ifzeropt\s_strc_formulas_margin_left
366 \let\p_location\v!left
367 \fi
368 \fi
369 \strc_formulas_show_references
370 \ifx\p_location\v!right
371 \strc_formulas_add_distance\plusone\v!left\formulaparameter
372 \fi
373 \begingroup
374 \useformulastyleandcolor\c!numberstyle\c!numbercolor
375 \formulaparameter\c!numbercommand
376 {\edef\p_strut{\formulaparameter\c!numberstrut}
377 \ifx\p_strut\v!always
378 \strut
379 \orelse\ifx\p_strut\v!yes
380 \strut
381 \fi
382 \formulaparameter\c!left
383 \namedtaggedlabeltexts
384 \t!formulalabel \v!formula
385 \t!formulanumber\v!formula
386 {\ignorespaces\strc_formulas_place_current_number\removeunwantedspaces}
387 \formulaparameter\c!right}
388 \endgroup
389 \ifx\p_location\v!left
390 \strc_formulas_add_distance\plusone\v!right\formulaparameter
391 \fi
392 \strc_formulas_show_modes
393 \endgroup}
394
395\protected\def\strc_formulas_place_current_number
396 {\ifempty\namedformulaentry
397 \begingroup
398 \strc_formulas_handle_current_references
399 \labeltexts\currentformula{\convertedcounter[\v!formula][]}
400 \endgroup
401 \else
402 \expandafter
403 \strc_formulas_handle_current_references
404 \namedformulaentry
405 \fi}
406
407\permanent\def\theformuladestinationattribute#1
408 {\iflocation\ifx#1\relax\orelse\ifempty#1\else
409 \c_attr_destination#1
410 \glet#1\relax
411 \fi\fi}
412
413\mutable\let\currentplaceformulaattribute\relax
414\mutable\let\currentformulaattribute \relax
415\mutable\let\currentsubformulaattribute \relax
416\mutable\let\currentformulasattribute \relax
417
418\mutable\let\currentplaceformulanumber\relax
419\mutable\let\currentformulanumber \relax
420\mutable\let\currentsubformulanumber \relax
421\mutable\let\currentformulasnumber \relax
422
423\mutable\lettonothing\currentformulasreference
424\mutable\lettonothing\currentformulareference
425\mutable\lettonothing\currentsubformulareference
426\mutable\lettonothing\currentnestedformulanumber
427\mutable\lettonothing\currentnestedformulareference
428\mutable\lettonothing\currentnestedformulaattribute
429
430\appendtoks
431 \glettonothing\currentformulasreference
432 \glettonothing\currentformulareference
433 \glettonothing\currentsubformulareference
434 \glettonothing\currentnestedformulareference
435\to \everyresetformulas
436
437\mutable\lettonothing\currentformulassuffix
438\mutable\lettonothing\currentformulasuffix
439\mutable\lettonothing\currentsubformulasuffix
440\mutable\lettonothing\currentnestedformulasuffix
441
442\appendtoks
443 \glettonothing\currentformulassuffix
444 \glettonothing\currentformulasuffix
445 \glettonothing\currentsubformulasuffix
446 \glettonothing\currentnestedformulasuffix
447\to \everyresetformulas
448
449\mutable\let\currentplaceformulasynchronize \relax
450\mutable\let\currentformulassynchronize \relax
451\mutable\let\currentsubformulasynchronize \relax
452\mutable\let\currentnestedformulasynchronize\relax
453
454\appendtoks
455 \glet\currentplaceformulasynchronize \relax
456 \glet\currentformulassynchronize \relax
457 \glet\currentsubformulassynchronize \relax
458 \glet\currentnestedformulasynchronize\relax
459\to \everyresetformulas
460
461\mutable\lettonothing\currentsubformulasattribute
462\mutable\lettonothing\currentsubformulasnumber
463\mutable\lettonothing\currentsubformulasreference
464\mutable\lettonothing\currentsubformulassynchronize
465
466\c_strc_formulas_counter_level\plusone
467
468\def\strc_formulas_handle_current_references
469 {\strc_formulas_reference_show
470 \ifnum\c_strc_formulas_place_number_mode=\plusthree
471 \ifconditional\c_strc_formulas_referenced
472 \else
473 \strc_formulas_store_number
474 \currentplaceformulareference
475 \empty
476 \currentplaceformulanumber
477 \currentplaceformulasynchronize
478 \currentplaceformulaattribute
479 \c_strc_formulas_counter_level
480 \currentplaceformulasynchronize
481 \glet\currentplaceformulasynchronize\relax
482 \theformuladestinationattribute\currentplaceformulaattribute
483 \global\c_strc_formulas_referenced\conditionaltrue
484 \fi
485 \fi
486 \ifnum\c_strc_formulas_number_mode=\plusthree
487 \strc_formulas_store_number
488 \currentformulasreference
489 \empty
490 \currentformulasnumber
491 \currentformulassynchronize
492 \currentformulasattribute
493 \plustwo
494 \currentformulassynchronize
495 \glet\currentformulassynchronize\relax
496 \theformuladestinationattribute\currentformulasattribute
497 \fi
498 \ifnum\c_strc_formulas_sub_number_mode=\plusthree
499 \currentsubformulassynchronize
500 \glet\currentsubformulassynchronize\relax
501 \fi
502 \ifnum\c_strc_formulas_nested_number_mode=\plusthree
503 \strc_formulas_store_number
504 \currentnestedformulareference
505 \empty
506 \currentnestedformulanumber
507 \currentnestedformulasynchronize
508 \currentnestedformulaattribute
509 \plustwo
510 \currentnestedformulasynchronize
511 \glet\currentnestedformulasynchronize\relax
512 \theformuladestinationattribute\currentnestedformulaattribute
513 \fi}
514
515\def\strc_formulas_handle_numbering_indeed
516 {\ifempty\namedformulaentry
517 \iftext\currentnestedformulasuffix
518 \ifconditional\c_strc_formulas_incremented\else
519 \strc_counters_increment\v!formula
520 \fi
521 \global\c_strc_formulas_incremented\conditionaltrue
522 \ifcstok{}\currentnestedformulasuffix
523 \strc_counters_increment_sub\v!formula\plustwo
524 \else
525 \strc_counters_setown_sub\v!formula\plustwo\currentnestedformulasuffix
526 \fi
527 \else
528 \ifempty\currentplaceformulasuffix\else
529 \let\currentnestedformulasuffix \currentplaceformulasuffix
530 \let\currentnestedformulareference\currentplaceformulareference
531 \strc_formulas_place_number_nested_check
532 \fi
533 \strc_counters_increment\v!formula
534 \fi
535 \fi
536 \glettonothing\currentplaceformulasuffix
537 \glettonothing\currentnestedformulasuffix
538 \placecurrentformulanumber}
539
540\def\strc_formulas_handle_numbering
541 {\iftrialtypesetting
542 \strc_counters_save\v!formula
543 \strc_formulas_handle_numbering_indeed
544 \strc_counters_restore\v!formula
545 \else
546 \strc_formulas_handle_numbering_indeed
547 \fi}
548
549\def\strc_formulas_handle_sub_numbering_indeed
550 {\let\strc_formulas_handle_sub_numbering\relax
551 \iftext\currentnestedformulasuffix
552 \strc_counters_setown_sub\v!formula\plustwo\currentnestedformulasuffix
553 \else
554 \strc_counters_increment_sub\v!formula\plustwo
555 \fi
556 \glettonothing\currentplaceformulasuffix
557 \glettonothing\currentnestedformulasuffix
558 \placecurrentformulanumber}
559
560\def\strc_formulas_handle_sub_numbering
561 {\iftrialtypesetting
562 \strc_counters_save\v!formula
563 \strc_formulas_handle_sub_numbering_indeed
564 \strc_counters_restore\v!formula
565 \else
566 \strc_formulas_handle_sub_numbering_indeed
567 \fi}
568
569\def\strc_formulas_number_indeed
570 {\ifconditional\c_strc_formulas_handle_number
571 \hbox\bgroup
572
573 \ifconditional\c_strc_formulas_inside_formulas_sub
574
575 \else
576 \ifcase\c_strc_formulas_number_mode
577 \ifcase\c_strc_formulas_place_number_mode
578 \strc_formulas_handle_numbering
579 \or
580 \strc_formulas_handle_numbering
581 \or
582
583 \or
584 \strc_formulas_handle_numbering
585 \fi
586 \or
587 \strc_formulas_handle_numbering
588 \or
589
590 \or
591 \strc_formulas_handle_numbering
592 \fi
593 \fi
594
595 \ifconditional\c_strc_formulas_inside_formulas_sub
596 \ifcase\c_strc_formulas_sub_number_mode
597 \strc_formulas_handle_sub_numbering
598 \or
599 \strc_formulas_handle_sub_numbering
600 \or
601
602 \or
603 \strc_formulas_handle_sub_numbering
604 \fi
605 \fi
606 \strc_formulas_reference_trace
607 \egroup
608 \fi}
609
610\installstructurelistprocessor\v!formula
611 {\let\currentlistentrynumber \structurelistgenericnumber
612 \let\currentlistentrytitle \structurelistgenerictitle
613 \let\currentlistentrypagenumber\structurelistpagenumber
614 \strc_lists_apply_renderingsetup}
615
616\newif\ifinformula
617
618
619
620
621
622
623
624
625
626\pushoverloadmode
627
628 \permanent\protected\def\normaleqno#1{\writestatus\m!system{no native (lr)eqno equation number support}}
629
630 \aliased\let\normalleqno\normaleqno
631 \aliased\let\normalreqno\normaleqno
632 \aliased\let\normaleqno \normaleqno
633
634 \aliased\let\leqno \normaleqno
635 \aliased\let\reqno \normaleqno
636 \aliased\let\eqno \normaleqno
637
638\popoverloadmode
639
640
641
642\abovedisplayskip \zeroskip
643\abovedisplayshortskip \zeroskip
644\belowdisplayskip \zeroskip
645\belowdisplayshortskip \zeroskip
646
647\predisplaypenalty \zerocount
648\postdisplaypenalty \zerocount
649\mathdisplayskipmode \plusthree
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666\mathdisplayskipmode \plusthree
667\abovedisplayskip \zeroskip
668\belowdisplayskip \zeroskip
669\abovedisplayshortskip\zeroskip
670\belowdisplayshortskip\zeroskip
671
672\newdimension\d_strc_formulas_display_width
673
674
675
676
677
678
679
680
681
682
683
684\newconditional\c_strc_math_split_mode
685
686\newconditional\c_strc_formulas_tight
687\newconditional\c_strc_formulas_packed
688\newconditional\c_strc_formulas_depth
689\newbox \b_strc_formulas_number
690\newdimen \d_strc_formulas_number
691
692\def\strc_formulas_display_space_before_normal
693 {
694 \lettonothing\m_spacebefore
695 \ifvmode
696 \ifdim\lastskip>\zeropoint\else
697 \ifdim\prevdepth<\zeropoint\else
698 \ifdim\prevdepth<\strutdp
699
700 \ifgridsnapping
701
702 \checkprevdepth
703 \else
704 \edef\m_spacebefore{\todimension{\strutdp\prevdepth}}
705 \fi
706 \fi
707 \fi
708 \fi
709 \nointerlineskip
710 \fi
711 \whitespace
712 \ifempty\m_spacebefore
713 \ifx\p_spacebefore\v!none
714
715 \orelse\ifempty\p_spacebefore
716 \directvspacing\currentvspacing
717 \else
718 \directvspacing\p_spacebefore
719 \fi
720 \else
721 \ifx\p_spacebefore\v!none
722 \directvspacing{\m_spacebefore}
723 \orelse\ifempty\p_spacebefore
724 \directvspacing{\m_spacebefore,\currentvspacing}
725 \else
726 \directvspacing{\m_spacebefore,\p_spacebefore}
727 \fi
728 \fi}
729
730\def\strc_formulas_display_space_after_common
731 {\whitespace
732 \ifx\p_spaceafter\v!none
733
734 \orelse\ifempty\p_spaceafter
735 \directvspacing\currentvspacing
736 \else
737 \directvspacing\p_spaceafter
738 \fi}
739
740\def\strc_formulas_display_space_after_normal
741 {\prevdepth\strutdp
742 \strc_formulas_display_space_after_common}
743
744\def\strc_formulas_display_space_before_depth
745 {
746 \ifvmode
747 \ifinner
748 \strc_formulas_display_space_before_normal
749 \c_strc_formulas_depth\conditionalfalse
750 \else
751 \forcestrutdepth
752 \nointerlineskip
753 \ifx\p_spacebefore\v!none
754
755 \orelse\ifempty\p_spacebefore
756 \directvspacing\currentvspacing
757 \else
758 \directvspacing\p_spacebefore
759 \fi
760 \fi
761 \else
762 \strc_formulas_display_space_before_normal
763 \fi}
764
765\def\strc_formulas_display_space_after_depth
766 {\ifconditional\c_strc_formulas_depth
767 \forcestrutdepth
768 \strc_formulas_display_space_after_common
769 \else
770 \strc_formulas_display_space_after_depth_normal
771 \fi}
772
773\def\strc_formulas_display_space_before
774 {\ifconditional\c_strc_formulas_depth
775 \strc_formulas_display_space_before_depth
776 \else
777 \strc_formulas_display_space_before_normal
778 \fi}
779
780\lettonothing\strc_math_qed_indeed
781
782\def\strc_formulas_display_space_after
783 {\par
784 \strc_math_qed_indeed
785 \ifconditional\c_strc_formulas_depth
786 \strc_formulas_display_space_after_depth
787 \else
788 \strc_formulas_display_space_after_normal
789 \fi}
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808\newconditional\c_strc_math_qed
809
810\permanent\protected\def\strc_math_qed
811 {\global\c_strc_math_qed\conditionaltrue}
812
813\appendtoks
814 \global\c_strc_math_qed\conditionalfalse
815 \aliased\let\qed\strc_math_qed
816\to \everybeforedisplayformula
817
818\permanent\protected\def\strc_math_qed_indeed
819 {\ifconditional\c_strc_math_qed
820 \ifconditional\csname\??constructionclosesymbol\currentconstruction\endcsname
821 \blank[\v!samepage]
822 \strut\strc_constructions_close_symbol_place
823 \par
824 \fi
825 \fi}
826
827\permanent\tolerant\protected\def\qedhere[#1]
828 {\ifconditional\csname\??constructionclosesymbol\currentconstruction\endcsname
829 \global\csname\??constructionclosesymbol\currentconstruction\endcsname\conditionalfalse
830 \edef\p_strc_constructions_closesymbol{\constructionparameter\c!closesymbol}
831 \ifempty\p_strc_constructions_closesymbol \else
832 \normalexpanded
833 {\texthere[\ifparameter#1\or#1\else\v!right\fi]}
834 {\p_strc_constructions_closesymbol}
835 \fi
836 \fi}
837
838\definesymbol[mathqed][â–¡]
839
840
841\permanent\protected\def\mathqed{\textmathematics{\symbol{mathqed}}}
842
843
844
845
846
847
848\permanent\protected\def\beforedisplayspace
849 {\ifhmode
850 \par
851 \fi
852 \ifvmode
853 \ifconditional\c_strc_formulas_packed
854 \lettonothing\p_spacebefore
855 \else
856 \edef\p_spacebefore{\formulaparameter\c!spacebefore}
857 \fi
858
859 \strc_formulas_display_space_before
860 \fi
861 \ifhmode
862 \par
863 \fi
864 \page_sides_check_floats_indeed}
865
866\permanent\protected\def\afterdisplayspace
867 {\ifhmode
868 \par
869 \fi
870 \ifvmode
871 \ifconditional\c_strc_formulas_packed
872 \lettonothing\p_spaceafter
873 \else
874 \edef\p_spaceafter{\formulaparameter\c!spaceafter}
875 \fi
876
877 \strc_formulas_display_space_after
878 \fi
879 \ifhmode
880 \par
881 \fi}
882
883\ifdefined\setdisplaydimensions \else
884 \let\setdisplaydimensions\relax
885\fi
886
887
888
889
890
891
892
893
894
895
896
897
898
899\def\strc_formulas_add_distance_normal#1#2#3
900 {\kern{#3\c!numberdistance}}
901
902\def\strc_formulas_add_distance_traced#1#2#3
903 {\begingroup
904 \scratchdimenone{#3\c!numberdistance}
905 \scratchdimentwo\ifconditional\c_strc_formulas_tight{\formulaparameter\c!numberthreshold}\else\zeropoint\fi\relax
906 \scratchdimenthree.5\exheight
907 \ifcase\scratchdimentwo\else\ifx#2\v!left
908 \darkred
909 \kern\scratchdimentwo
910 \vrule
911 \s!height\scratchdimenthree
912 \s!depth \scratchdimenthree
913 \s!width \scratchdimentwo
914 \fi\fi
915 \ifcase\scratchdimenone\else
916 \ifcase#1\or\darkgreen\else\darkblue\fi
917 \vrule
918 \s!height\scratchdimenthree
919 \s!depth \scratchdimenthree
920 \s!width \scratchdimenone
921 \fi
922 \ifcase\scratchdimentwo\else\ifx#2\v!right
923 \darkred
924 \vrule
925 \s!height\scratchdimenthree
926 \s!depth \scratchdimenthree
927 \s!width \scratchdimentwo
928 \kern\scratchdimentwo
929 \fi\fi
930 \endgroup}
931
932\installtextracker
933 {math.numberdistance}
934 {\let\strc_formulas_add_distance\strc_formulas_add_distance_traced}
935 {\let\strc_formulas_add_distance\strc_formulas_add_distance_normal}
936
937\let\strc_formulas_add_distance \strc_formulas_add_distance_normal
938
939\defcsname\??formulaoption\v!packed\endcsname
940 {\c_strc_formulas_packed\conditionaltrue}
941
942\defcsname\??formulaoption\v!tight\endcsname
943 {\c_strc_formulas_tight\conditionaltrue}
944
945\defcsname\??formulaoption\v!middle\endcsname
946 {}
947
948\defcsname\??formulaoption\v!depth\endcsname
949 {\c_strc_formulas_depth\conditionaltrue}
950
951\defcsname\??formulaoption\v!line\endcsname
952 {\ifgridsnapping
953 \setformulaparameter\c!grid{\v!math:\v!line}
954 \fi}
955
956\defcsname\??formulaoption\v!halfline\endcsname
957 {\ifgridsnapping
958 \setformulaparameter\c!grid{\v!math:\v!halfline}
959 \fi}
960
961\defcsname\??formulaoption\v!line\endcsname
962 {\ifgridsnapping
963 \setformulaparameter\c!grid{\v!math:\v!line}
964 \fi}
965
966\defcsname\??formulaoption\v!halfline\endcsname
967 {\ifgridsnapping
968 \setformulaparameter\c!grid{\v!math:\v!halfline}
969 \fi}
970
971\def\strc_math_set_split
972 {\ifcstok{\formulaparameter\c!split}\v!line
973 \global\c_strc_math_split_mode\conditionalfalse
974 \else
975 \global\c_strc_math_split_mode\conditionaltrue
976 \fi
977 \mathpenaltiesmode\plusone
978 \global\d_strc_math_indent\zeropoint}
979
980\def\strc_math_set_number_location
981 {\ifcstok{\formulaparameter\c!numberlocation}\v!overlay
982 \c_strc_formulas_overlay_number\conditionaltrue
983 \else
984 \c_strc_formulas_overlay_number\conditionalfalse
985 \fi
986 \ifcstok{\formulaparameter\c!numbermethod}\v!down
987 \c_math_align_overflow_mode\conditionaltrue
988 \else
989 \c_math_align_overflow_mode\conditionalfalse
990 \fi}
991
992\setupformula
993 [\c!split=\v!yes,
994 \c!numberlocation=,
995 \c!textdistance=\zeropoint,
996
997 \c!interlinespace=\ifgridsnapping\zeropoint\else1.125\lineheight\fi,
998 \c!textmargin=2\emwidth,
999 \c!numbermethod=\v!down]
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016\def\strc_math_pickup_again
1017
1018 {\mathatom \s!class \mathbegincode{}\noatomruling}
1019
1020
1021
1022\defineboundary[mathalign]
1023\defineboundary[mathinject]
1024
1025\newconditional\c_strc_math_trace_hang
1026\newdimension \d_strc_math_hang_state
1027
1028\installtextracker
1029 {math.autohang}
1030 {\c_strc_math_trace_hang\conditionaltrue}
1031 {\c_strc_math_trace_hang\conditionalfalse}
1032
1033\newconditional\c_strc_math_aligned_here
1034
1035\def\strc_math_trace_okay#1#2
1036 {\mathghost{\llap{\backgroundline[#1]{\white\tttf#2}}}}
1037
1038\protected\def\strc_math_align_here
1039 {\ifmmode
1040 \global\c_strc_math_aligned_here\conditionaltrue
1041
1042
1043 \ifconditional\c_strc_math_trace_hang
1044 \strc_math_trace_okay{darkred}{A}
1045 \fi
1046 \boundary\c_bndr_mathalign
1047 \fi}
1048
1049\newboundary\c_bndr_skiphere
1050
1051\tolerant\protected\def\strc_math_skip_here[#1]
1052 {
1053 \ifconditional\c_strc_math_trace_hang
1054 \strc_math_trace_okay{darkblue}{S #1}
1055 \fi
1056 \scratchdimen{\formulaparameter\c!textmargin}
1057 \ifchkdimension#1\or
1058 \d_strc_math_hang_state\lastchkdimension
1059 \orelse\ifchknum#1\or
1060 \d_strc_math_hang_state#1\scratchdimen
1061 \orelse\iftok{#1}{}
1062 \advanceby\d_strc_math_hang_state\scratchdimen
1063 \orelse\iftok{#1}{}
1064 \advanceby\d_strc_math_hang_state\scratchdimen
1065 \else
1066 \d_strc_math_hang_state\scratchdimen
1067 \fi
1068 \boundary\c_bndr_skiphere
1069 \kern\d_strc_math_hang_state
1070 \strc_math_pickup_again}
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085\definelocalboxes
1086 [\v!lefttext]
1087 [\c!command=\localmarginlefttext\zeropoint,
1088 \c!repeat=\v!no,
1089 \c!distance=\zeropoint,
1090 \c!location=\v!middle]
1091
1092\definelocalboxes
1093 [\v!righttext]
1094 [\c!command=\localmarginrighttext\zeropoint,
1095 \c!repeat=\v!no,
1096 \c!distance=\zeropoint,
1097 \c!location=\v!middle]
1098
1099\installcorenamespace{mathtexthere}
1100\installcorenamespace{mathbreakhere}
1101
1102\def\strc_math_text_here_right#1
1103 {\localbox[\v!righttext]{\llap{#1}}}
1104
1105\def\strc_math_text_here_left#1
1106 {\localbox[\v!lefttext]{\rlap{\kern\leftskip#1}}}
1107
1108\def\strc_math_text_here_before#1
1109 {\vadjust pre \bgroup
1110 \hbox to \d_strc_formulas_display_width \bgroup
1111 \strut
1112 \kern\leftskip
1113 #1\hss
1114 \kern\rightskip
1115 \strut
1116 \egroup
1117 \egroup}
1118
1119\def\strc_math_text_here_after#1
1120 {\vadjust \bgroup
1121 \hbox to \d_strc_formulas_display_width \bgroup
1122 \strut
1123 \kern\leftskip
1124 #1\hss
1125 \kern\rightskip
1126 \strut
1127 \egroup
1128 \egroup}
1129
1130\permanent\protected\def\strc_math_text_here_inbetween#1
1131 {\begingroup
1132 \breakhere
1133
1134 \setbox\scratchboxone\vbox{\forgetall#1}
1135 \scratchcounter\boxlines\scratchboxone
1136 \localcontrolledrepeat\scratchcounter
1137 {\boundary\c_bndr_mathinject
1138 \setbox\scratchboxtwo\hbox{\setstrut\strut\boxline\scratchboxone\currentloopiterator}
1139 \box\scratchboxtwo
1140 \ifnum\currentloopiterator<\scratchcounter
1141 \vadjust depth after \thousandpoint{\strut\vskip\struthtdp}
1142 \fi
1143 \breakhere}
1144 \endgroup}
1145
1146\letcsname\??mathtexthere\v!left \endcsname\strc_math_text_here_left
1147\letcsname\??mathtexthere\v!right \endcsname\strc_math_text_here_right
1148\letcsname\??mathtexthere\v!before \endcsname\strc_math_text_here_before
1149\letcsname\??mathtexthere\v!after \endcsname\strc_math_text_here_after
1150\letcsname\??mathtexthere\v!inbetween\endcsname\strc_math_text_here_inbetween
1151
1152\defcsname\??mathbreakhere\v!left\endcsname#1
1153 {\ifnum\lastboundary=\c_math_begin_boundary\else
1154 \strc_math_line_here
1155 \fi
1156 \strc_math_text_here_left{#1}
1157 \strc_math_pickup_again}
1158
1159\defcsname\??mathbreakhere\v!right\endcsname#1
1160 {\strc_math_text_here_right{#1}
1161 \strc_math_line_here
1162 \strc_math_pickup_again}
1163
1164\defcsname\??mathbreakhere\v!before\endcsname#1
1165 {\ifnum\lastboundary=\c_math_begin_boundary\else
1166 \strc_math_line_here
1167 \fi
1168 \strc_math_text_here_before{#1}
1169 \strc_math_pickup_again}
1170
1171\defcsname\??mathbreakhere\v!after\endcsname#1
1172 {\ifnum\lastboundary=\c_math_begin_boundary\else
1173 \strc_math_line_here
1174 \fi
1175 \strc_math_text_here_after{#1}
1176 \strc_math_pickup_again}
1177
1178\tolerant\protected\def\strc_math_break_here[#1]#:#*#=
1179 {\ifparameter#2\or
1180 \ifcsname\??mathbreakhere#1\endcsname
1181 \expandafter\lastnamedcs
1182 \else
1183 \csname\??mathbreakhere\v!after\expandafter\endcsname
1184 \fi{#2}
1185 \orelse\ifcstok{#1}\v!page
1186 \strc_math_page_here
1187 \orelse\ifcstok{#1}\v!samepage
1188 \strc_math_same_here
1189 \else
1190 \strc_math_line_here
1191 \fi}
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202\def\strc_math_text_here_export#1
1203 {\mtext{\nbsp#1\nbsp}\breakhere}
1204
1205\tolerant\protected\def\strc_math_text_here[#1]#:#*#=
1206 {\ifparameter#2\or
1207 \ifexporting
1208 \expandafter\strc_math_text_here_export
1209 \orelse\ifcsname\??mathtexthere#1\endcsname
1210 \expandafter\lastnamedcs
1211 \else
1212 \csname\??mathtexthere\v!after\expandafter\endcsname
1213 \fi{#2}
1214 \fi}
1215
1216\def\strc_math_break_here_indeed
1217 {\strut\break}
1218
1219\protected\def\strc_math_page_here
1220 {\ifmmode
1221 \ifconditional\c_strc_math_trace_hang
1222 \strc_math_trace_okay{darkyellow}{B P}
1223 \fi
1224 \strc_math_break_here_indeed
1225 \vadjust pre {\vfill\penalty100000}
1226 \strc_math_pickup_again
1227 \fi}
1228
1229\protected\def\strc_math_same_here
1230 {\ifmmode
1231 \ifconditional\c_strc_math_trace_hang
1232 \strc_math_trace_okay{darkyellow}{B S}
1233 \fi
1234 \strc_math_break_here_indeed
1235 \vadjust pre {\penalty\plustenthousand}
1236 \strc_math_pickup_again
1237 \fi}
1238
1239\protected\def\strc_math_line_here
1240 {\ifmmode
1241 \ifconditional\c_strc_math_trace_hang
1242 \strc_math_trace_okay{darkgreen}{B}
1243 \fi
1244 \strc_math_break_here_indeed
1245 \strc_math_pickup_again
1246 \fi}
1247
1248\ifdefined\alignhere \else \aliased\let\alignhere\relax \fi
1249\ifdefined\texthere \else \aliased\let\texthere \relax \fi
1250\ifdefined\skiphere \else \aliased\let\skiphere \relax \fi
1251\ifdefined\breakhere \else \aliased\let\breakhere\relax \fi
1252
1253\appendtoks
1254 \enforced\let\alignhere\strc_math_align_here
1255 \enforced\let\breakhere\strc_math_break_here
1256 \enforced\let\skiphere \strc_math_skip_here
1257 \enforced\let\texthere \strc_math_text_here
1258
1259\to \everymathematics
1260
1261\installcorenamespace{mathtextalign}
1262
1263\newconstant \c_strc_math_ragged_status
1264\newconstant \c_strc_math_split_status
1265\newconditional\c_strc_math_number_swapped
1266
1267\prependtoks
1268 \c_strc_math_ragged_status\plustwo
1269 \c_strc_math_split_status \zerocount
1270\to \everymathematics
1271
1272\prependtoks
1273
1274 \mathgluemode\ifcase\raggedstatus\plusthree\else\zerocount\fi
1275\to \everymathematics
1276
1277\defcsname\??mathtextalign\v!flushleft\endcsname
1278 {\raggedright
1279 \mathgluemode\plustwo
1280 \c_strc_math_ragged_status\plusone
1281 \c_strc_math_number_swapped\conditionalfalse
1282 \updateparagraphproperties}
1283
1284\defcsname\??mathtextalign\v!middle\endcsname
1285 {\raggedcenter
1286 \mathgluemode\plustwo
1287 \c_strc_math_ragged_status\plustwo
1288 \c_strc_math_number_swapped\conditionalfalse
1289 \updateparagraphproperties}
1290
1291\defcsname\??mathtextalign\v!flushright\endcsname
1292 {\raggedleft
1293 \mathgluemode\plustwo
1294 \c_strc_math_ragged_status\plusthree
1295 \c_strc_math_number_swapped\conditionalfalse
1296 \updateparagraphproperties}
1297
1298\defcsname\??mathtextalign\v!slanted\endcsname
1299 {\raggedslanted
1300
1301 \c_strc_math_ragged_status\plustwo
1302 \edef\p_distance{\formulaparameter\c!leftmargindistance}
1303 \parinitleftskip \ifx\p_distance\v!number\wd\b_strc_formulas_number\else{\p_distance}\fi
1304 \edef\p_distance{\formulaparameter\c!rightmargindistance}
1305 \parfillrightskip\ifx\p_distance\v!number\wd\b_strc_formulas_number\else{\p_distance}\fi
1306
1307
1308 \updateparagraphproperties}
1309
1310\def\strc_math_setup_align
1311 {\ifcsname\??mathtextalign\formulaparameter\c!align\endcsname
1312 \lastnamedcs\else\begincsname\??mathtextalign\v!middle\endcsname
1313 \math_check_limit_stretch
1314 \fi}
1315
1316\def\math_check_limit_stretch
1317 {\ifcstok{\mathematicsparameter\c!limitstretch}\v!yes
1318 \bitwiseflip\mathgluemode\plusfour
1319 \fi}
1320
1321\appendtoks
1322 \math_check_limit_stretch
1323\to \everymathematics
1324
1325
1326
1327\defcsname\??mathtextalign\v!flushleft:\v!auto\endcsname
1328 {\raggedright
1329 \mathgluemode\plustwo
1330 \c_strc_math_ragged_status\plusone
1331 \strc_math_analyze_box}
1332
1333\defcsname\??mathtextalign\v!middle:\v!auto\endcsname
1334 {\raggedright
1335 \mathgluemode\plustwo
1336 \c_strc_math_ragged_status\plustwo
1337 \strc_math_analyze_box}
1338
1339\defcsname\??mathtextalign\v!flushright:\v!auto\endcsname
1340 {\raggedright
1341 \mathgluemode\plustwo
1342 \c_strc_math_ragged_status\plusthree
1343 \strc_math_analyze_box}
1344
1345\defcsname\??mathtextalign\v!slanted:\v!auto\endcsname
1346 {\raggedright
1347 \mathgluemode\plustwo
1348 \c_strc_math_ragged_status\plustwo
1349 \strc_math_analyze_box}
1350
1351\def\strc_math_setup_align_auto
1352 {\ifcsname\??mathtextalign\formulaparameter\c!align:\v!auto\endcsname
1353 \lastnamedcs\else\begincsname\??mathtextalign\v!middle:\v!auto\endcsname
1354 \fi}
1355
1356\letcsname\??mathtextalign\v!right \expandafter\endcsname\csname\??mathtextalign\v!flushleft \endcsname
1357\letcsname\??mathtextalign\v!left \expandafter\endcsname\csname\??mathtextalign\v!flushright \endcsname
1358\letcsname\??mathtextalign\v!right:\v!auto\expandafter\endcsname\csname\??mathtextalign\v!flushleft :\v!auto\endcsname
1359\letcsname\??mathtextalign\v!left :\v!auto\expandafter\endcsname\csname\??mathtextalign\v!flushright:\v!auto\endcsname
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377\startsetups[math:penalties:\v!yes:\v!both]
1378 \shapingpenaltiesmode \zerocount
1379 \widowpenalties \plustwo \plustenthousand \plustwothousand
1380 \clubpenalties \plustwo \plustenthousand \plustwothousand
1381\stopsetups
1382
1383\startsetups[math:penalties:\v!yes:\v!first]
1384 \shapingpenaltiesmode \zerocount
1385 \widowpenalties \plusone \zerocount
1386 \clubpenalties \plustwo \plustenthousand \zerocount
1387\stopsetups
1388
1389\startsetups[math:penalties:\v!yes:\v!last]
1390 \shapingpenaltiesmode \zerocount
1391 \widowpenalties \plustwo \plustenthousand \zerocount
1392 \clubpenalties \plusone \zerocount
1393\stopsetups
1394
1395\startsetups[math:penalties:\v!yes:]
1396 \shapingpenaltiesmode \zerocount
1397 \widowpenalties \plustwo \plustwothousand \zerocount
1398 \clubpenalties \plustwo \plustwothousand \zerocount
1399\stopsetups
1400
1401\startsetups[math:penalties:\v!yes]
1402 \directsetup{math:penalties:\v!yes:\formulaparameter\c!splitmethod}
1403\stopsetups
1404
1405\startsetups[math:penalties:\v!no]
1406 \shapingpenaltiesmode \zerocount
1407 \widowpenalties \plusone \plusfivethousand
1408 \clubpenalties \plusone \plusfivethousand
1409\stopsetups
1410
1411\setupformula
1412 [\c!penalties=math:penalties:\formulaparameter\c!split]
1413
1414\def\strc_math_setup_penalties
1415 {\linebreakpasses\zerocount
1416 \directsetup{\formulaparameter\c!penalties}}
1417
1418
1419
1420\appendtoks
1421 \global\d_strc_math_indent \zeropoint
1422 \global\c_strc_math_n_of_lines \zerocount
1423 \global\d_strc_math_first_height\zeropoint
1424 \global\d_strc_math_first_left \zeropoint
1425 \global\d_strc_math_first_right \zeropoint
1426 \global\d_strc_math_last_left \zeropoint
1427 \global\d_strc_math_last_right \zeropoint
1428 \global\d_strc_math_last_depth \zeropoint
1429 \global\d_strc_math_max_right \zeropoint
1430 \global\d_strc_math_max_left \zeropoint
1431 \global\d_math_strc_hangindent \zeropoint
1432 \global\c_math_strc_hangafter \zeropoint
1433 \global\d_strc_math_left_shift \zeropoint
1434 \global\d_strc_math_right_shift \zeropoint
1435\to \everyresetformulas
1436
1437\newbox\b_strc_math_display
1438
1439\newgluespec\s_strc_formulas_margin_left
1440\newgluespec\s_strc_formulas_margin_right
1441
1442\def\strc_formulas_set_paragraph
1443 {
1444
1445
1446 \d_strc_formulas_display_width{\formulaparameter\c!width}
1447 \edef\p_margin{\formulaparameter\c!leftmargin}
1448 \ifempty\p_margin \else
1449 \doadaptleftskip\p_margin
1450 \fi
1451 \edef\p_margin{\formulaparameter\c!rightmargin}
1452 \ifempty\p_margin \else
1453 \doadaptrightskip\p_margin
1454 \fi
1455 \s_strc_formulas_margin_left \leftskip
1456 \s_strc_formulas_margin_right\rightskip
1457 \ifchkdimexpr\formulaparameter\c!interlinespace\or\baselineskip\lastchkdimension\fi
1458 \global\c_strc_math_aligned_here\conditionalfalse
1459 \strc_math_setup_penalties
1460 \hsize\d_strc_formulas_display_width}
1461
1462\def\strc_math_analyze_box
1463 {\clf_handlemathhang
1464 stage \plusone
1465 alignstate \c_strc_math_ragged_status
1466 box \b_strc_math_display
1467 distance {\formulaparameter\c!textdistance}
1468 leftmargin {\s_strc_formulas_margin_left}
1469 rightmargin {\s_strc_formulas_margin_right}
1470 \relax
1471
1472 \setbox\b_strc_math_display\vbox\bgroup
1473
1474
1475 \strc_formulas_trigger_side_box
1476 \ifconditional\c_strc_math_aligned_here
1477 \ifzeropt\d_strc_math_indent\else
1478 \advanceby\leftskip\d_strc_math_indent
1479 \hskip\d_strc_math_indent
1480 \fi
1481 \else
1482 \strc_math_setup_align
1483 \fi
1484
1485 \strc_math_setup_penalties
1486 \ifhbox\b_strc_math_display\unhbox\else\box\fi\b_strc_math_display
1487 \egroup
1488 \clf_handlemathhang
1489 stage \ifconditional\c_strc_math_aligned_here \plustwo \else \plusthree \fi
1490
1491
1492
1493 \relax
1494
1495 \begingroup
1496 \edef\v_spac_whitespace_current{\formulaparameter\c!spaceinbetween}
1497 \spac_whitespace_setup
1498 \clf_handlemathhang
1499 stage \plusfour
1500 inbetween 1\parskip
1501 height \strutht
1502 depth \strutdp
1503 \relax
1504 \endgroup}
1505
1506\let\strc_math_inject_show_margins_here\relax
1507
1508\integerdef\c_strc_math_positioning\zerocount
1509
1510
1511
1512\newconditional\c_strc_math_ignore_number
1513
1514\fetchmodulecommand \showmathmargins \f!math_run
1515
1516\installtextracker
1517 {math.showmargins}
1518 {\def\strc_math_show_margins{\showmathmargins[\v!all]}
1519 \let\strc_math_flush_number_box\strc_math_flush_number_box_visual}
1520 {\let\strc_math_show_margins\relax
1521 \let\strc_math_flush_number_box\strc_math_flush_number_box_normal}
1522
1523\installtextracker
1524 {math.showmargins.less}
1525 {\def\strc_math_show_margins{\showmathmargins}
1526 \let\strc_math_flush_number_box\strc_math_flush_number_box_visual}
1527 {\let\strc_math_show_margins\relax
1528 \let\strc_math_flush_number_box\strc_math_flush_number_box_normal}
1529
1530\let\strc_math_show_margins\relax
1531
1532
1533
1534
1535
1536
1537
1538
1539\newdimen\d_strc_math_side_width
1540
1541\def\strc_formulas_check_side_box
1542 {\doifelsesidefloat
1543 {\d_strc_math_side_width\d_page_sides_width}
1544 {\d_strc_math_side_width\zeropoint}}
1545
1546\def\strc_formulas_start_side_box
1547 {\ifzeropt\d_strc_math_side_width\else
1548 \advanceby\d_strc_formulas_display_width\d_strc_math_side_width
1549 \ifnum\c_page_sides_checks_done<\plustwo
1550
1551 \vkern\strutht
1552 \fi
1553 \dontleavehmode\dbox
1554 \fi
1555 \bgroup}
1556
1557\def\strc_formulas_stop_side_box
1558 {\egroup}
1559
1560\def\strc_formulas_trigger_side_box
1561 {\ifzeropt\d_strc_math_side_width\else
1562 \advanceby\hsize\d_strc_math_side_width
1563 \forgeteverypar
1564 \dontleavehmode
1565 \fi}
1566
1567
1568
1569\tolerant\protected\def\strc_formulas_start_formula#1#:#*[#S#2]
1570 {\strc_formulas_check_side_box
1571 \ifhmode
1572 \par
1573 \fi
1574 \bgroup
1575 \iftrialtypesetting\else
1576 \global\advanceby\c_strc_formulas_n\plusone
1577 \fi
1578 \cdef\currentformula{#1}
1579 \usesetupsparameter\formulaparameter
1580 \dostarttaggedchained\t!formula\currentformula\currentformula\??formula
1581 \strc_math_set_options{#2}
1582 \strc_math_set_split
1583 \strc_math_set_number_location
1584 \strc_formulas_set_paragraph
1585 \let\strc_formulas_start_formula\strc_formulas_start_formula_nested
1586 \expand\everybeforedisplayformula
1587 \strc_math_setup_align
1588 \ifcstok{\formulaparameter\c!strut}\v!yes
1589 \let\strc_formulas_begstrut\begstrut
1590 \let\strc_formulas_endstrut\endstrut
1591 \else
1592 \let\strc_formulas_begstrut\relax
1593 \let\strc_formulas_endstrut\relax
1594 \fi
1595 \noindentation
1596 \csname\e!start\formulaparameter\c!alternative\v!formula\endcsname}
1597
1598\protected\def\strc_formulas_start_formula_nested#1
1599 {\bgroup
1600 \let\strc_formulas_stop_formula\strc_formulas_stop_formula_nested
1601 \dostarttaggednodetail\t!subformula}
1602
1603\protected\def\strc_formulas_stop_formula_nested
1604 {\dostoptagged
1605 \egroup}
1606
1607
1608
1609
1610
1611\newinteger\c_strc_formulas_n
1612
1613\ifdefined\dotagregisterformula \else \aliased\let\dotagregisterformula\gobbletwoarguments \fi
1614
1615\protected\def\strc_formulas_stop_formula
1616 {\strc_formulas_place_number
1617 \strc_formulas_flush_number
1618 \dostarttaggednodetail\t!formulacontent
1619 \dotagregisterformula{\number\c_strc_formulas_n}\!!zerocount
1620 \csname\e!stop\formulaparameter\c!alternative\v!formula\endcsname
1621 \dostoptagged
1622 \dostoptagged
1623 \nonoindentation
1624 \useindentnextparameter\formulaparameter
1625 \egroup
1626 \hangafter\minusone
1627 \hangindent\zeropoint
1628 \c_strc_formulas_handle_number\conditionalfalse
1629 \expand\everyresetformulas
1630 \dorechecknextindentation}
1631
1632
1633
1634\def\strc_formulas_set_grid_snapping
1635 {\edef\p_grid{\formulaparameter\c!grid}
1636 \ifempty\p_grid \else
1637 \spac_grids_snap_value_auto\p_grid
1638 \fi}
1639
1640\appendtoks
1641 \ifgridsnapping
1642 \strc_formulas_set_grid_snapping
1643 \fi
1644\to \everybeforedisplayformula
1645
1646\tolerant\permanent\protected\def\formula[#1]#:#2
1647 {\begingroup
1648 \ifparameters#1\else
1649 \rawprocesscommacommand[#1]\strc_formulas_option
1650 \fi
1651 \useformulastyleandcolor\c!style\c!color
1652 \mathematics{#2}
1653 \endgroup}
1654
1655\aliased\letcsname\v!formula\endcsname\formula
1656
1657
1658
1659
1660
1661
1662
1663
1664\let\strc_formulas_begstrut\relax
1665\let\strc_formulas_endstrut\relax
1666
1667\newboundary\c_math_begin_boundary
1668
1669\permanent\protected\def\startdisplaymath
1670 {\ifhmode
1671 \par
1672 \fi
1673 \bgroup
1674 \informulatrue
1675 \beforedisplayspace
1676 \startinnermath
1677 \ifrelax\strc_formulas_begstrut\else
1678 \strc_formulas_begstrut
1679 \boundary\c_math_begin_boundary
1680 \fi
1681 \begingroup}
1682
1683\permanent\protected\def\stopdisplaymath
1684 {\endgroup
1685
1686 \strc_formulas_endstrut
1687
1688 \stopinnermath
1689 \afterdisplayspace
1690 \egroup}
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737\tolerant\permanent\protected\def\startsubformulas[#1]
1738 {\edef\currentsubformulasreference{#1}
1739 \global\c_strc_formulas_inside_formulas_sub\conditionaltrue
1740 \strc_formulas_handle_sub_number}
1741
1742\permanent\protected\def\stopsubformulas
1743 {\nonoindentation
1744 \useindentnextparameter\subformulaparameter
1745 \expand\everyresetformulas
1746 \global\c_strc_formulas_inside_formulas_sub\conditionalfalse
1747 \dorechecknextindentation}
1748
1749
1750
1751\tolerant\permanent\protected\def\startnamedsubformulas[#1]#2
1752 {\setformulalistentry{#2}
1753 \startsubformulas[#1]}
1754
1755\permanent\protected\def\stopnamedsubformulas
1756 {\stopsubformulas}
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769\permanent\protected\def\startformulas{\strc_formulas_start_formulas}
1770
1771\permanent\letcsname\e!stop\v!formulas\endcsname\relax
1772
1773\tolerant\protected\def\strc_formulas_nested_formula_start[#S#1]
1774 {\begingroup
1775 \ifparameter#1\or
1776 \setupformula[\c!width=\d_strc_formulas_ width,#1]
1777 \d_strc_formulas_display_width{\formulaparameter\c!width}
1778 \fi
1779 \vcenter\bgroup
1780 \hsize\d_strc_formulas_display_width
1781 \raggedcenter
1782 \dostarttaggednodetail\t!formulacontent
1783 \csname\e!start\formulaparameter\c!alternative\v!formula\endcsname}
1784
1785\protected\def\strc_formulas_nested_formula_stop
1786 {\csname\e!stop\formulaparameter\c!alternative\v!formula\endcsname
1787 \dostoptagged
1788 \egroup
1789 \hss
1790 \endgroup}
1791
1792\normalexpanded{\tolerant\def\noexpand\strc_formulas_start_formulas[#1]#:#2\csname\e!stop\v!formulas\endcsname}
1793 {\startformula
1794 \dostarttaggednodetail\t!formulaset
1795 \global\c_strc_formulas_inside_formulas\conditionaltrue
1796 \edef\currentformulasreference{#1}
1797 \strc_formulas_handle_number
1798 \lettonothing\currentformula
1799
1800 \enforced\protected\def\startformula
1801 {\advanceby\scratchcounter\plusone
1802 \expandafter\ignoreupto\csname\e!stop\v!formula\endcsname}
1803 \scratchcounter\zerocount
1804 #2
1805 \hbox to \d_strc_formulas_display_width \bgroup
1806 \ifcase\scratchcounter\else
1807 \divideby\d_strc_formulas_display_width\scratchcounter
1808 \fi
1809 \hss
1810 \enforced\let\startformula\strc_formulas_nested_formula_start
1811 \enforced\let\stopformula \strc_formulas_nested_formula_stop
1812 #2
1813 \egroup
1814 \global\c_strc_formulas_inside_formulas\conditionalfalse
1815 \dostoptagged
1816 \stopformula
1817 \expand\everyresetformulas
1818 \hangafter\minusone
1819 \hangindent\zeropoint}
1820
1821
1822
1823\def\m_strc_formulas_flag_inhibit{}
1824\def\m_strc_formulas_flag_force {}
1825
1826\def\strc_formulas_check_reference#1#2
1827 {#1\unless\ifempty\namedformulaentry
1828 \plusthree
1829 \orelse\ifempty#2
1830 \zerocount
1831 \orelse\ifx#2\m_strc_formulas_flag_force
1832 \plusone
1833 \orelse\ifx#2\m_strc_formulas_flag_inhibit
1834 \plustwo
1835 \else
1836 \plusthree
1837 \fi}
1838
1839\tolerant\permanent\protected\def\formulanumber[#1]
1840 {\def\currentformulareference{#1}
1841 \strc_formulas_place_number_in_box}
1842
1843\permanent\protected\def\placeformula {\global\c_strc_formulas_inside_place\conditionaltrue \strc_formulas_place}
1844\permanent\protected\def\placesubformula{\global\c_strc_formulas_inside_place_sub\conditionaltrue\strc_formulas_place}
1845
1846\tolerant\protected\def\strc_formulas_place[#1]
1847 {\xdef\currentplaceformulareference{#1}
1848 \glettonothing\currentplaceformulasuffix
1849 \glettonothing\currentnestedformulasuffix
1850 \global\c_strc_formulas_incremented\conditionalfalse
1851 \global\c_strc_formulas_referenced\conditionalfalse
1852 \global\c_strc_formulas_inside_place\conditionaltrue
1853 \doifelsenextbgroup\strc_formulas_place_yes\strc_formulas_place_nop}
1854
1855\protected\def\strc_formulas_place_yes#1
1856 {\xdef\currentplaceformulasuffix{#1}
1857 \strc_formulas_place_nop}
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871\protected\def\strc_formulas_place_nop
1872 {\strc_formulas_place_numbering}
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884\mutable\lettonothing\currentplaceformulatitle
1885\mutable\lettonothing\currentplaceformulareference
1886\mutable\lettonothing\currentplaceformulasuffix
1887\mutable\lettonothing\currentplaceformulabookmark
1888\mutable\lettonothing\currentplaceformulalist
1889
1890\permanent\tolerant\protected\def\startplaceformula[#S#1]
1891 {\begingroup
1892 \global\c_strc_formulas_incremented\conditionalfalse
1893 \global\c_strc_formulas_referenced\conditionalfalse
1894 \global\c_strc_formulas_inside_place\conditionaltrue
1895 \ifparameter#1\or
1896 \expandafter\strc_formulas_start_place_yes
1897 \else
1898 \expandafter\strc_formulas_start_place_nop
1899 \fi[#1]}
1900
1901\def\strc_formulas_start_place_nop[#S#1]
1902 {\glettonothing\currentplaceformulareference
1903 \glettonothing\currentplaceformulasuffix
1904 \strc_formulas_place_nop}
1905
1906\def\strc_formulas_start_place_yes[#S#1]
1907 {\doifassignmentelse{#1}
1908 {\strc_formulas_set_place_parameters{#1}
1909 \doifelsenextbgroup\strc_formulas_place_yes\strc_formulas_place_nop}
1910 {\xdef\currentplaceformulareference{#1}
1911 \glettonothing\currentplaceformulasuffix
1912 \strc_formulas_place_nop}}
1913
1914\def\strc_formulas_set_place_parameters#1
1915 {\resetdummyparameter\c!title
1916 \resetdummyparameter\c!reference
1917 \resetdummyparameter\c!bookmark
1918 \resetdummyparameter\c!list
1919 \resetdummyparameter\c!suffix
1920 \getdummyparameters[#1]
1921 \edef\currentplaceformulatitle {\dummyparameter\c!title}
1922 \edef\currentplaceformulareference{\dummyparameter\c!reference}
1923 \edef\currentplaceformulabookmark {\dummyparameter\c!bookmark}
1924 \edef\currentplaceformulalist {\dummyparameter\c!list}
1925 \edef\currentplaceformulasuffix {\dummyparameter\c!suffix}
1926 \ifempty\currentplaceformulatitle\else
1927 \normalexpanded{\setformulalistentry{\currentplaceformulatitle}}
1928 \fi}
1929
1930\permanent\protected\def\stopplaceformula
1931 {\relax
1932 \endgroup}
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961\newconditional \c_strc_formulas_in_sub
1962
1963\permanent\protected\def\startsubnumberinghere
1964 {\begingroup
1965 \c_strc_formulas_in_sub\conditionaltrue
1966 \strc_counters_increment\v!formula}
1967
1968\permanent\protected\def\stopsubnumberinghere
1969 {\c_strc_formulas_in_sub\conditionalfalse
1970 \endgroup}
1971
1972\permanent\tolerant\protected\def\numberhere[#1]
1973 {\begingroup
1974 \attribute\mathblobattribute\attributeunsetvalue
1975 \dostarttaggednodetail\t!formulacaption
1976 \global\c_strc_formulas_incremented\conditionalfalse
1977 \global\c_strc_formulas_referenced\conditionaltrue
1978 \global\c_strc_formulas_inside_place\conditionalfalse
1979 \global\c_strc_formulas_place_number_mode\zerocount
1980
1981 \glettonothing\currentplaceformulareference
1982 \glettonothing\currentplaceformulasuffix
1983
1984 \ifparameter#1\orelse\ifhastok={#1}
1985 \strc_formulas_set_place_parameters{#1}
1986 \else
1987 \xdef\currentplaceformulareference{#1}
1988 \fi
1989 \iftrialtypesetting
1990 \orelse\ifempty\currentplaceformulareference
1991 \else
1992 \global\c_strc_formulas_referenced\conditionalfalse
1993 \ifconditional\c_strc_formulas_in_sub
1994 \c_strc_formulas_counter_level\plustwo
1995 \fi
1996 \strc_formulas_check_reference
1997 \c_strc_formulas_place_number_mode
1998 \currentplaceformulareference
1999 \fi
2000 \texthere
2001 [\ifcstok{\formulaparameter\c!location}\v!left\v!left\else\v!right\fi]
2002 {\ifconditional\c_strc_formulas_in_sub
2003 \strc_formulas_handle_sub_numbering
2004 \else
2005 \strc_formulas_handle_numbering
2006 \fi}
2007 \dostoptagged
2008 \endgroup}
2009
2010
2011
2012\let\strc_formulas_place_number \relax
2013\let\strc_formulas_place_number_nested\gobbletwoarguments
2014
2015\def\strc_formulas_place_number_nested_indeed#1#2
2016 {\ifhastok={#1}
2017 \setupcurrentmathalignment[#1]
2018 \xdef\currentnestedformulareference{\mathalignmentparameter\c!reference}
2019 \xdef\currentnestedformulasuffix {\mathalignmentparameter\c!suffix}
2020 \global\d_math_eqalign_number_threshold\mathalignmentparameter\c!numberthreshold\relax
2021 \orelse\ifhastok{#1}
2022 \glettonothing\currentnestedformulareference
2023 \xdef\currentnestedformulasuffix {}
2024 \orelse\ifempty\currentplaceformulareference
2025 \xdef\currentnestedformulareference{#1}
2026 \xdef\currentnestedformulasuffix {#2}
2027 \else
2028 \glettonothing\currentnestedformulareference
2029 \xdef\currentnestedformulasuffix {#1}
2030 \fi
2031 \strc_formulas_place_number_nested_check}
2032
2033\def\strc_formulas_place_number_nested_check
2034 {\ifempty\currentnestedformulareference
2035 \ifempty\currentnestedformulasuffix \else
2036 \c_strc_formulas_nested_number_mode\plusthree
2037 \fi
2038 \else
2039 \strc_formulas_check_reference\c_strc_formulas_nested_number_mode\currentnestedformulareference
2040 \fi
2041 \ifcase\c_strc_formulas_nested_number_mode
2042
2043 \or
2044 \glet\strc_formulas_place_number\relax
2045 \strc_formulas_place_number_in_box
2046 \or
2047
2048 \or
2049 \glet\strc_formulas_place_number\relax
2050 \strc_formulas_place_number_in_box
2051 \fi}
2052
2053\def\strc_formulas_place_number_indeed
2054 {\strc_formulas_place_number_in_box}
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071\newconditional\c_strc_formulas_number_in_alignment
2072
2073\def\strc_formulas_place_number_in_box
2074 {\begingroup
2075 \ifconditional\c_strc_formulas_number_in_alignment
2076
2077 \else
2078 \attribute\mathblobattribute\attributeunsetvalue
2079 \fi
2080 \dostarttaggednodetail\t!formulacaption
2081 \glet\strc_formulas_place_number\relax
2082
2083 \global\setbox\b_strc_formulas_number\naturalhbox{\strc_formulas_number_indeed}
2084 \global\d_strc_formulas_number\wd\b_strc_formulas_number
2085 \dostoptagged
2086 \endgroup}
2087
2088\let\strc_formulas_flush_number\relax
2089
2090
2091
2092\permanent\tolerant\protected\def\placenamedformula[#1]
2093 {\ifarguments
2094 \expandafter\strc_formulas_place_named_nop
2095 \else
2096 \expandafter\strc_formulas_place_named_yes
2097 \fi[#1]}
2098
2099\def\strc_formulas_place_named_yes[#1]#2
2100 {\setformulalistentry{#2}
2101 \placeformula[#1]}
2102
2103\def\strc_formulas_place_named_nop[#1]#2
2104 {\setformulalistentry{#2}
2105 \placeformula}
2106
2107\def\strc_math_flush_aligned_boxed_direct_yes
2108 {\dontleavehmode
2109 \hskip\leftskip
2110 \box\b_strc_math_display
2111 \llap{\box\b_strc_formulas_number}}
2112
2113\def\strc_math_flush_aligned_boxed_direct_nop
2114 {\dontleavehmode
2115 \hskip\leftskip
2116 \box\b_strc_math_display}
2117
2118\mutable\lettonothing\namedformulaentry
2119
2120\permanent\protected\def\setformulalistentry#1
2121 {\xdef\namedformulaentry{#1}}
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140\definesystemattribute[mathsnap][public]
2141
2142\appendtoks
2143 \ifcstok{\formulaparameter\c!snap}\v!yes
2144 \setmathsnapping{\formulaparameter\c!snapstep}
2145 \else
2146 \setmathsnapping\v!reset
2147 \fi
2148\to \everysetupformula
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160\prependtoks
2161 \usebodyfontparameter\formulaparameter
2162\to \everymathematics
2163
2164\protect \endinput
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179 |