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}{}
17
18
19
20
21
22\unprotect
23
24\setupformulas
25 [
26
27
28
29
30
31
32
33
34
35 \c!grid=\v!math,
36 \c!location=\v!right,
37 \c!left=(,
38 \c!right=),
39 \c!expansion=\v!yes,
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,
49 \c!distance=2\emwidth]
50
51\setupformulaframed
52 [
53
54
55 \c!offset=.5\exheight]
56
57\ifdefined\matheqnogapstep
58
59
60 \matheqnogapstep\zerocount
61\else
62
63 \setupformulas[\c!distance=\emwidth]
64\fi
65
66
67
68
69
70
71
72
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\setupsubformulas
117 [\c!indentnext=\formulaparameter\c!indentnext]
118
119\definecounter
120 [\v!formula]
121
122\defineconversionset
123 [\v!formula]
124 [numbers,characters]
125
126\installcounterassociation{formula} \registerformulacounter\v!formula
127
128\appendtoks
129 \synchronizeformulacounters
130\to \everysetupformula
131
132
133
134
135
136\setupformulas
137 [\c!numberconversionset=\v!formula]
138
139\appendtoks
140 \normalexpanded{\definelist[\currentformula]}
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
151\let\strc_formulas_stop_formula \relax
152
153\unexpanded\def\defineformulaalternative
154 {\dotripleargument\strc_formulas_define_alternative}
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
161
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
195\to \everyresetformulas
196
197
198
199\unexpanded\def\strc_formulas_store_number#1#2#3#4#5
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,
207 \c!reference=#1,
208 \c!title=\namedformulaentry,
209 \c!list=\currentplaceformulalist,
210 \c!bookmark=\currentplaceformulabookmark]
211 [#2]
212 \glet\namedformulaentry\empty
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
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
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
256 {\strc_formulas_check_reference\c_strc_formulas_number_mode\currentformulasreference}
257
258\def\strc_formulas_handle_sub_number_indeed
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
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
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
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
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
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
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
450 \ifconditional\c_strc_formulas_inside_formulas_sub
451
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
460 \or
461 \strc_formulas_handle_numbering
462 \fi
463 \or
464 \strc_formulas_handle_numbering
465 \or
466
467 \or
468 \strc_formulas_handle_numbering
469 \fi
470 \fi
471
472 \ifconditional\c_strc_formulas_inside_formulas_sub
473 \ifcase\c_strc_formulas_sub_number_mode
474 \strc_formulas_handle_sub_numbering
475 \or
476 \strc_formulas_handle_sub_numbering
477 \or
478
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
488 {\let\currentlistentrynumber \structurelistgenericnumber
489 \let\currentlistentrytitle \structurelistgenerictitle
490 \let\currentlistentrypagenumber\structurelistpagenumber
491 \strc_lists_apply_renderingsetup}
492
493\newif\ifinformula
494
495
496
497
498
499
500
501
502
503
504
505\pushoverloadmode
506
507\let\reqno\eqno
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544\abovedisplayskip \zeropoint
545\abovedisplayshortskip \zeropoint
546\belowdisplayskip \zeropoint
547\belowdisplayshortskip \zeropoint
548
549\predisplaypenalty \zerocount
550\postdisplaypenalty \zerocount
551\mathdisplayskipmode \plusthree
552
553
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
570\newconstant\c_strc_formulas_space_model
571
572\newconstant\c_strc_math_vertical
573
574\c_strc_formulas_mode \plustwo
575\c_strc_formulas_space_model\plusthree
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
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}
618 {\ifx\p_spacebefore\v!none
619
620 \else
621 \directvspacing\p_spacebefore
622 \fi}
623
624\setvalue{\??mathdisplayspacemodel\v!after:1}
625 {\prevdepth .5\strutdp
626 \ifx\p_spaceafter\v!none
627
628 \else
629 \directvspacing\p_spaceafter
630 \fi}
631
632\setvalue{\??mathdisplayspacemodel\v!before:2}
633 {\ifx\p_spacebefore\v!none
634
635 \else
636 \directvspacing\p_spacebefore
637 \fi
638 \prevdepth\maxdimen}
639
640\setvalue{\??mathdisplayspacemodel\v!after:2}
641 {\prevdepth\lineheight
642 \ifx\p_spaceafter\v!none
643
644 \else
645 \directvspacing\p_spaceafter
646 \fi}
647
648\setvalue{\??mathdisplayspacemodel\v!before:3}
649 {
650 \let\m_spacebefore\empty
651 \ifvmode
652 \ifdim\lastskip>\zeropoint\else
653 \ifdim\prevdepth<\zeropoint\else
654 \ifdim\prevdepth<\strutdp
655
656 \ifgridsnapping
657 \let\m_spacebefore\v!depth
658 \else
659 \edef\m_spacebefore{\the\dimexpr\strutdp\prevdepth\relax}
660 \fi
661 \fi
662 \fi
663 \fi
664 \nointerlineskip
665 \fi
666 \ifx\m_spacebefore\empty
667 \ifx\p_spacebefore\v!none
668
669 \else\ifx\p_spacebefore\empty
670 \directvspacing\currentvspacing
671 \else
672 \directvspacing\p_spacebefore
673 \fi\fi
674 \else
675 \ifx\p_spacebefore\v!none
676 \directvspacing\m_spacebefore
677 \else\ifx\p_spacebefore\empty
678 \directvspacing{\m_spacebefore,\currentvspacing}
679 \else
680 \directvspacing{\m_spacebefore,\p_spacebefore}
681 \fi\fi
682 \fi}
683
684\setvalue{\??mathdisplayspacemodel\v!after:3}
685 {\prevdepth\strutdp
686 \ifx\p_spaceafter\v!none
687
688 \else\ifx\p_spaceafter\empty
689 \directvspacing\currentvspacing
690 \else
691 \directvspacing\p_spaceafter
692 \fi\fi}
693
694\newconditional\c_math_model_four_indeed
695
696\setvalue{\??mathdisplayspacemodel\v!before:4}
697 {
698 \ifvmode
699 \ifinner
700 \csname\??mathdisplayspacemodel\v!before:3\endcsname
701 \else
702 \settrue\c_math_model_four_indeed
703 \forcestrutdepth
704 \nointerlineskip
705 \ifx\p_spacebefore\v!none
706
707 \else\ifx\p_spacebefore\empty
708 \directvspacing\currentvspacing
709 \else
710 \directvspacing\p_spacebefore
711 \fi\fi
712 \fi
713 \else
714 \csname\??mathdisplayspacemodel\v!before:3\endcsname
715 \fi}
716
717\setvalue{\??mathdisplayspacemodel\v!after:4}
718 {\ifconditional\c_math_model_four_indeed
719 \setfalse\c_math_model_four_indeed
720 \forcestrutdepth
721 \else
722 \prevdepth\strutdp
723 \fi
724 \ifx\p_spaceafter\v!none
725
726 \else\ifx\p_spaceafter\empty
727 \directvspacing\currentvspacing
728 \else
729 \directvspacing\p_spaceafter
730 \fi\fi}
731
732\unexpanded\def\setdisplaymathspacemodel[#1]
733 {\ifcsname\??mathdisplayspacemodel\v!before:\number#1\endcsname
734 \c_strc_formulas_space_model#1\relax
735 \fi}
736
737
738
739
740\unexpanded\def\beforedisplayspace
741 {\ifhmode
742 \par
743 \fi
744 \ifvmode
745 \edef\p_spacebefore{\formulaparameter\c!spacebefore}
746 \begincsname\??mathdisplayspacemodel\v!before:\number\c_strc_formulas_space_model\endcsname
747 \fi
748 \ifhmode
749 \par
750 \fi
751 \page_sides_check_floats_indeed}
752
753\unexpanded\def\afterdisplayspace
754 {\ifhmode
755 \par
756 \fi
757 \ifvmode
758 \edef\p_spaceafter{\formulaparameter\c!spaceafter}
759 \begincsname\??mathdisplayspacemodel\v!after:\number\c_strc_formulas_space_model\endcsname
760 \fi
761 \ifhmode
762 \par
763 \fi}
764
765\unexpanded\def\setdisplaydimensions
766 {\displayindent\dimexpr
767 \d_strc_formulas_display_skip_left
768 \d_strc_formulas_display_margin_left
769 \relax
770 \displaywidth\d_strc_formulas_display_width
771
772
773 \ifdim\hangindent>\zeropoint
774 \advance\displayindent\hangindent
775 \else
776 \advance\displaywidth\hangindent
777 \fi
778 \advance\displaywidth\dimexpr
779 \displayindent
780 \d_strc_formulas_display_skip_right
781 \d_strc_formulas_display_margin_right
782 \relax
783 \hsize\displaywidth}
784
785\unexpanded\def\strc_formulas_start_formula#1
786 {\dodoubleempty\strc_formulas_start_formula_indeed[#1]}
787
788
789
790
791
792
793
794
795
796
797
798\setvalue{\??formulaoption\v!packed}
799 {\c_strc_formulas_space_model\zerocount}
800
801\setvalue{\??formulaoption\v!tight}
802 {\settrue\c_strc_formulas_tight}
803
804\setvalue{\??formulaoption\v!middle}
805 {\d_strc_formulas_display_skip_left \zeropoint
806 \d_strc_formulas_display_skip_right\zeropoint}
807
808\setvalue{\??formulaoption\v!depth}
809 {\c_strc_formulas_space_model\plusfour}
810
811\setvalue{\??formulaoption\v!line}
812 {\ifgridsnapping
813 \setformulaparameter\c!grid{\v!math:\v!line}
814 \fi}
815
816\setvalue{\??formulaoption\v!halfline}
817 {\ifgridsnapping
818 \setformulaparameter\c!grid{\v!math:\v!halfline}
819 \fi}
820
821\setvalue{\??formulaoption\v!line}
822 {\ifgridsnapping
823 \setformulaparameter\c!grid{\v!math:\v!line}
824 \fi}
825
826\setvalue{\??formulaoption\v!halfline}
827 {\ifgridsnapping
828 \setformulaparameter\c!grid{\v!math:\v!halfline}
829 \fi}
830
831
832
833
834
835
836\def\strc_math_set_split
837 {\edef\p_split{\formulaparameter\c!split}
838 \ifx\p_split\v!yes
839 \global\c_strc_math_vertical\plusone
840 \else\ifx\p_split\v!page
841 \global\c_strc_math_vertical\plustwo
842 \else
843 \global\c_strc_math_vertical\zerocount
844 \fi\fi
845 \ifcase\c_strc_math_vertical
846
847 \clf_setmathpenalties\zerocount
848 \clf_resetmathhang
849 \else
850
851 \clf_setmathpenalties\plusone
852 \edef\p_hang{\formulaparameter\c!hang}
853 \ifx\p_hang\v!none
854 \global\setfalse\c_strc_math_indent
855 \clf_resetmathhang
856 \else
857 \global\settrue\c_strc_math_indent
858 \clf_setmathhang {
859 method {\p_hang}
860 distance \formulaparameter\c!distance
861 }
862 \fi
863 \fi}
864
865\setupformula
866 [\c!split=\v!no,
867 \c!distance=\zeropoint,
868
869 \c!interlinespace=,
870 \c!hang=\v!none]
871
872
873
874\unexpanded\def\strc_math_align_here{\ifmmode\penalty\plusone\fi}
875\unexpanded\def\strc_math_break_here{\ifmmode\hfill\break \fi}
876
877\appendtoks
878 \let\alignhere\strc_math_align_here
879 \let\breakhere\strc_math_break_here
880\to \everymathematics
881
882\unexpanded\def\strc_formulas_start_formula_indeed[#1][#2]
883 {\ifhmode
884 \par
885 \fi
886 \bgroup
887 \iftrialtypesetting\else
888 \global\advance\c_strc_formulas_n\plusone
889 \fi
890 \def\currentformula{#1}
891 \strc_math_set_split
892 \dostarttaggedchained\t!formula\currentformula\??formula
893 \setfalse\c_strc_formulas_tight
894 \d_strc_formulas_display_skip_left \leftskip
895 \d_strc_formulas_display_skip_right \rightskip
896 \d_strc_formulas_display_width \formulaparameter\c!width\relax
897 \d_strc_formulas_display_margin_left \formulaparameter\c!leftmargin\relax
898 \d_strc_formulas_display_margin_right\formulaparameter\c!rightmargin\relax
899 \ifsecondargument
900 \doifelseassignment{#2}
901 {\setupcurrentformula[#2]
902 \edef\p_option{\formulaparameter\c!option}}
903 {\edef\p_option{\formulaparameter\c!option}
904 \edef\p_option{\ifx\p_option\empty\else\p_option,\fi#2}}
905 \else
906 \edef\p_option{\formulaparameter\c!option}
907 \fi
908 \ifx\p_option\empty \else
909 \rawprocesscommacommand[\p_option]\strc_formulas_option
910 \fi
911 \edef\p_margin{\formulaparameter\c!margin}
912 \ifx\p_margin\empty \else
913 \dosetleftskipadaption\p_margin
914 \d_strc_formulas_display_margin_left\leftskipadaption
915 \fi
916 \let\strc_formulas_start_formula\strc_formulas_start_formula_nested
917 \strc_formulas_forget_display_skips
918 \the\everybeforedisplayformula
919 \csname\e!start\formulaparameter\c!alternative\v!formula\endcsname}
920
921\unexpanded\def\strc_formulas_start_formula_nested#1
922 {\bgroup
923 \let\strc_formulas_stop_formula\strc_formulas_stop_formula_nested
924 \dostarttagged\t!subformula\empty}
925
926\unexpanded\def\strc_formulas_stop_formula_nested
927 {\dostoptagged
928 \egroup}
929
930
931
932\newcount\c_strc_formulas_n
933
934\ifdefined\dotagregisterformula \else \let\dotagregisterformula\gobbleoneargument \fi
935
936\unexpanded\def\strc_formulas_stop_formula
937 {\strc_formulas_place_number
938 \strc_formulas_flush_number
939 \dostarttagged\t!formulacontent\empty
940 \dotagregisterformula\c_strc_formulas_n
941 \csname\e!stop\formulaparameter\c!alternative\v!formula\endcsname
942 \dostoptagged
943 \dostoptagged
944 \nonoindentation
945 \useindentnextparameter\formulaparameter
946 \egroup
947 \hangafter\minusone
948 \hangindent\zeropoint
949 \setfalse\c_strc_formulas_handle_number
950 \the\everyresetformulas
951 \dorechecknextindentation}
952
953
954
955\def\strc_formulas_set_grid_snapping
956 {\edef\p_grid{\formulaparameter\c!grid}
957 \ifx\p_grid\empty \else
958 \spac_grids_snap_value_auto\p_grid
959 \fi}
960
961\appendtoks
962 \ifgridsnapping
963 \strc_formulas_set_grid_snapping
964 \fi
965\to \everybeforedisplayformula
966
967
968
969
970\setuvalue{\v!formula}{\dosingleempty\strc_formulas_formula}
971
972\def\strc_formulas_formula[#1]#2
973 {\begingroup
974 \edef\p_direct{#1}
975 \ifx\p_direct\empty \else
976 \rawprocesscommalist[\p_direct]\strc_formulas_option
977 \fi
978
979 \useformulastyleandcolor\c!style\c!color
980 \mathematics{#2}
981 \endgroup}
982
983
984
985
986
987
988
989
990\unexpanded\def\startdisplaymath
991 {\ifhmode
992 \par
993 \fi
994 \bgroup
995 \informulatrue
996 \beforedisplayspace
997 \setdisplaydimensions
998 \ifcase\c_strc_formulas_mode
999 \noindent
1000 \Ucheckedstartdisplaymath
1001 \the\everydisplay
1002 \or
1003 \setbox\b_strc_formulas_content\hbox\bgroup
1004 \normalUstartmath
1005 \displaystyle
1006 \the\everydisplay
1007 \else
1008 \expandafter\startinnermath
1009 \fi
1010 \begingroup}
1011
1012\unexpanded\def\stopdisplaymath
1013 {\endgroup
1014 \ifcase\c_strc_formulas_mode
1015 \Ucheckedstopdisplaymath
1016 \or
1017 \normalUstopmath
1018 \egroup
1019 \strc_formulas_flush_content_and_number
1020 \else
1021 \expandafter\stopinnermath
1022 \fi
1023 \afterdisplayspace
1024 \egroup}
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052\unexpanded\def\startsubformulas
1053 {\dosingleempty\strc_formulas_start_sub_formulas}
1054
1055\def\strc_formulas_start_sub_formulas[#1]
1056 {\edef\currentsubformulasreference{#1}
1057 \global\settrue\c_strc_formulas_inside_formulas_sub
1058 \strc_formulas_handle_sub_number}
1059
1060\unexpanded\def\stopsubformulas
1061 {\nonoindentation
1062 \useindentnextparameter\subformulaparameter
1063 \the\everyresetformulas
1064 \global\setfalse\c_strc_formulas_inside_formulas_sub
1065 \dorechecknextindentation}
1066
1067
1068
1069\unexpanded\def\startnamedsubformulas
1070 {\dosingleempty\strc_formulas_start_named_sub_formulas}
1071
1072\def\strc_formulas_start_named_sub_formulas[#1]#2
1073 {\setformulalistentry{#2}
1074 \startsubformulas[#1]}
1075
1076\unexpanded\def\stopnamedsubformulas
1077 {\stopsubformulas}
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090\unexpanded\def\startformulas
1091 {\dosingleempty\strc_formulas_start_formulas}
1092
1093\expandafter\let\csname\e!stop\v!formulas\endcsname\relax
1094
1095\unexpanded\def\strc_formulas_nested_formula_start
1096 {\hbox to \displaywidth \bgroup
1097 \hsize\displaywidth
1098 \hss
1099
1100 \dostarttagged\t!formulacontent\empty
1101 \csname\e!start\formulaparameter\c!alternative\v!formula\endcsname}
1102
1103\unexpanded\def\strc_formulas_nested_formula_stop
1104 {\csname\e!stop\formulaparameter\c!alternative\v!formula\endcsname
1105 \dostoptagged
1106
1107 \hss
1108 \egroup
1109 \hss}
1110
1111\normalexpanded{\def\noexpand\strc_formulas_start_formulas[#1]#2\csname\e!stop\v!formulas\endcsname}
1112 {\startformula
1113 \dostarttagged\t!formulaset\empty
1114 \global\settrue\c_strc_formulas_inside_formulas
1115 \edef\currentformulasreference{#1}
1116 \strc_formulas_handle_number
1117 \let\currentformula\empty
1118 \strc_formulas_forget_display_skips
1119 \unexpanded\def\startformula
1120 {\advance\scratchcounter\plusone
1121 \expandafter\gobbleuntil\csname\e!stop\v!formula\endcsname}
1122 \scratchcounter\zerocount
1123 #2
1124 \hbox to \displaywidth \bgroup
1125 \divide\displaywidth\scratchcounter
1126 \hss
1127 \let\startformula\strc_formulas_nested_formula_start
1128 \let\stopformula \strc_formulas_nested_formula_stop
1129 #2
1130 \egroup
1131 \global\setfalse\c_strc_formulas_inside_formulas
1132 \dostoptagged
1133 \stopformula
1134 \the\everyresetformulas
1135 \hangafter\minusone
1136 \hangindent\zeropoint}
1137
1138
1139
1140\def\m_strc_formulas_flag_inhibit{}
1141\def\m_strc_formulas_flag_force {}
1142
1143\def\strc_formulas_check_reference#1#2
1144 {#1\unless\ifx\namedformulaentry\empty
1145 \plusthree
1146 \else\ifx#2\empty
1147 \zerocount
1148 \else\ifx#2\m_strc_formulas_flag_force
1149 \plusone
1150 \else\ifx#2\m_strc_formulas_flag_inhibit
1151 \plustwo
1152 \else
1153 \plusthree
1154 \fi\fi\fi\fi}
1155
1156\unexpanded\def\formulanumber
1157 {\strc_formulas_number}
1158
1159\unexpanded\def\strc_formulas_number
1160 {\dosingleempty\strc_formulas_number_again}
1161
1162\unexpanded\def\strc_formulas_number_again[#1]
1163 {\def\currentformulareference{#1}
1164 \strc_formulas_place_number_in_box}
1165
1166\unexpanded\def\placeformula
1167 {\global\settrue\c_strc_formulas_inside_place
1168 \dosingleempty\strc_formulas_place}
1169
1170\unexpanded\def\placesubformula
1171 {\global\settrue\c_strc_formulas_inside_place_sub
1172 \dosingleempty\strc_formulas_place}
1173
1174\unexpanded\def\strc_formulas_place[#1]
1175 {\def\currentplaceformulareference{#1}
1176 \let\currentplaceformulasuffix\empty
1177 \doifelsenextbgroup\strc_formulas_place_yes\strc_formulas_place_nop}
1178
1179\unexpanded\def\strc_formulas_place_yes#1
1180 {\def\currentplaceformulasuffix{#1}
1181 \strc_formulas_place_nop}
1182
1183\unexpanded\def\strc_formulas_place_nop
1184 {\doifelsenextchar$\strc_formulas_place_pickup\strc_formulas_place_indeed}
1185
1186\unexpanded\def\strc_formulas_place_indeed
1187 {\strc_formulas_place_numbering}
1188
1189\unexpanded\def\strc_formulas_place_pickup$$#1$$
1190 {\strc_formulas_place_numbering
1191 \strc_formulas_start_formula{}#1\strc_formulas_stop_formula}
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203\unexpanded\def\startplaceformula{\dosingleempty\strc_formulas_start_place}
1204\unexpanded\def\stopplaceformula {\strc_formulas_stop_place}
1205
1206\let\currentplaceformulareference\empty
1207\let\currentplaceformulasuffix \empty
1208
1209\def\strc_formulas_start_place
1210 {\begingroup
1211 \global\settrue\c_strc_formulas_inside_place
1212 \iffirstargument
1213 \expandafter\strc_formulas_start_place_yes
1214 \else
1215 \expandafter\strc_formulas_start_place_nop
1216 \fi}
1217
1218\def\strc_formulas_start_place_yes[#1]
1219 {\doifassignmentelse{#1}\strc_formulas_start_place_parameters\strc_formulas_start_place_reference[#1]}
1220
1221\def\strc_formulas_start_place_nop[#1]
1222 {\let\currentplaceformulareference\empty
1223 \let\currentplaceformulasuffix \empty
1224 \strc_formulas_place_nop}
1225
1226\def\strc_formulas_start_place_reference[#1]
1227 {\edef\currentplaceformulareference{#1}
1228 \let\currentplaceformulasuffix\empty
1229
1230 \strc_formulas_place_nop}
1231
1232\let\currentplaceformulabookmark\empty
1233\let\currentplaceformulalist \empty
1234
1235\def\strc_formulas_start_place_parameters[#1]
1236 {\letdummyparameter\c!title \empty
1237 \letdummyparameter\c!reference\empty
1238 \letdummyparameter\c!bookmark \empty
1239 \letdummyparameter\c!list \empty
1240 \letdummyparameter\c!suffix \empty
1241 \getdummyparameters[#1]
1242 \edef\currentplaceformulatitle {\dummyparameter\c!title}
1243 \edef\currentplaceformulareference{\dummyparameter\c!reference}
1244 \edef\currentplaceformulalist {\dummyparameter\c!list}
1245 \edef\currentplaceformulabookmark {\dummyparameter\c!bookmark}
1246 \edef\currentplaceformulasuffix {\dummyparameter\c!suffix}
1247 \ifx\currentplaceformulatitle\empty\else
1248 \normalexpanded{\setformulalistentry{\currentplaceformulatitle}}
1249 \fi
1250 \doifelsenextbgroup\strc_formulas_place_yes\strc_formulas_place_nop}
1251
1252\def\strc_formulas_stop_place
1253 {\relax
1254 \endgroup}
1255
1256
1257
1258\let\strc_formulas_place_number \relax
1259\let\strc_formulas_place_number_nested\gobbletwoarguments
1260
1261\def\strc_formulas_place_number_nested_indeed#1#2
1262 {\def\currentnestedformulareference{#1}
1263 \def\currentnestedformulasuffix{#2}
1264 \strc_formulas_check_reference\c_strc_formulas_nested_number_mode\currentnestedformulareference
1265 \ifcase\c_strc_formulas_nested_number_mode
1266
1267 \or
1268 \glet\strc_formulas_place_number\relax
1269 \expandafter\strc_formulas_number
1270 \or
1271
1272 \or
1273 \glet\strc_formulas_place_number\relax
1274 \expandafter\strc_formulas_number
1275 \fi}
1276
1277\def\strc_formulas_place_number_indeed
1278 {\strc_formulas_place_number_in_box}
1279
1280\def\strc_formulas_place_number_in_box
1281 {\dostarttagged\t!formulacaption\empty
1282 \global\setbox\b_strc_formulas_number\naturalhbox{\strc_formulas_number_indeed}
1283 \dostoptagged}
1284
1285\def\strc_formulas_flush_number
1286 {\ifcase\c_strc_formulas_mode
1287 \ifzeropt\wd\b_strc_formulas_number
1288
1289 \else
1290 \ifx\p_location\v!left
1291 \math_native_leqno{\box\b_strc_formulas_number}
1292 \else
1293 \math_native_reqno{\box\b_strc_formulas_number}
1294 \fi
1295 \fi
1296 \fi}
1297
1298
1299
1300\unexpanded\def\placenamedformula
1301 {\dosingleempty\strc_formulase_place_named}
1302
1303\unexpanded\def\strc_formulase_place_named
1304 {\iffirstargument
1305 \expandafter\strc_formulase_place_named_yes
1306 \else
1307 \expandafter\strc_formulase_place_named_nop
1308 \fi}
1309
1310\def\strc_formulase_place_named_yes[#1]#2
1311 {\setformulalistentry{#2}
1312 \placeformula[#1]}
1313
1314\def\strc_formulase_place_named_nop[#1]#2
1315 {\setformulalistentry{#2}
1316 \placeformula}
1317
1318\let\namedformulaentry\empty
1319
1320\unexpanded\def\setformulalistentry#1
1321 {\gdef\namedformulaentry{#1}}
1322
1323\protect \endinput
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338 |