strc-mat.mkiv /size: 39 Kb    last modification: 2023-12-21 09:44
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   \ifx\p_spaceafter\v!none
627     % nothing
628   \else
629     \directvspacing\p_spaceafter
630   \fi}
631
632\setvalue{\??mathdisplayspacemodel\v!before:2}% old
633  {\ifx\p_spacebefore\v!none
634     % nothing
635   \else
636     \directvspacing\p_spacebefore
637   \fi
638   \prevdepth-\maxdimen} % texbook pagina 79-80
639
640\setvalue{\??mathdisplayspacemodel\v!after:2}% old
641  {\prevdepth\lineheight
642   \ifx\p_spaceafter\v!none
643     % nothing
644   \else
645     \directvspacing\p_spaceafter
646   \fi}
647
648\setvalue{\??mathdisplayspacemodel\v!before:3}%
649  {% not ok, try \stopformula\par\startformula vs \stopformula\startformula
650   \let\m_spacebefore\empty
651   \ifvmode
652     \ifdim\lastskip>\zeropoint\else
653       \ifdim\prevdepth<\zeropoint\else
654         \ifdim\prevdepth<\strutdp
655           % maybe add a tracing option here
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       % nothing
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 % \directvspacing\v!depth
686   \ifx\p_spaceafter\v!none
687     % nothing
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  {% not ok, try \stopformula\par\startformula vs \stopformula\startformula
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         % nothing
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 % \directvspacing\v!depth
723   \fi
724   \ifx\p_spaceafter\v!none
725     % nothing
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% \newtoks\everybeforedisplay
738% \appendtoks\page_sides_check_floats_indeed\to\everybeforedisplay
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} % probably needs more
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  %\setlocalhsize
772  %\displaywidth\localhsize
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} % new, else overfull in itemize
784
785\unexpanded\def\strc_formulas_start_formula#1%
786  {\dodoubleempty\strc_formulas_start_formula_indeed[#1]}
787
788% \newskip\formulastrutht
789% \newskip\formulastrutdp
790
791%D \startbuffer
792%D \startformula[9pt] x = 1 \stopformula
793%D \startformula[7pt] x = 1 \stopformula
794%D \stopbuffer
795%D
796%D \typebuffer \getbuffer
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% when we have 1.0.6 we wil use \mathpenaltiesmode
832%
833% \prebinoppenalty -100
834% \prerelpenalty   -100
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   % \mathpenaltiesmode \zerocount
847     \clf_setmathpenalties\zerocount
848     \clf_resetmathhang
849   \else
850   % \mathpenaltiesmode \plusone
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  %\c!interlinespace=1.5\lineheight,
869   \c!interlinespace=,
870   \c!hang=\v!none]
871
872% for the moment (when testing) we use a penalty 1
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]% setting leftskip adaption is slow !
883  {\ifhmode
884     \par
885   \fi
886   \bgroup % HERE
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}% this is new, so that we can also set the grid
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% tagging of formulanumbers is not ok (we get two display maths blobs)
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 % in case it hasn't happened yet
938   \strc_formulas_flush_number % in case we are in native mode
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   % added for side floats
948   \hangindent\zeropoint % added for side floats
949   \setfalse\c_strc_formulas_handle_number
950   \the\everyresetformulas
951   \dorechecknextindentation} % here ?
952
953% experiment:
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% \unexpanded\def\switchtoformulabodyfont
968%   {\switchtobodyfont}
969
970\setuvalue{\v!formula}{\dosingleempty\strc_formulas_formula}
971
972\def\strc_formulas_formula[#1]#2% todo: tagged
973  {\begingroup
974   \edef\p_direct{#1}%
975   \ifx\p_direct\empty \else
976     \rawprocesscommalist[\p_direct]\strc_formulas_option
977   \fi
978   % not : \def\strc_formulas_formula[##1]##2{\mathematics{##2}}%
979   \useformulastyleandcolor\c!style\c!color
980   \mathematics{#2}%
981   \endgroup}
982
983%D \starttyping
984%D % test \par       % no preceding hlist
985%D % $$x$$           % preceding hlist
986%D % \noindent $$x$$ % no preceding hlist
987%D \startformula x \stopformula % now has \noindent (in mkii we messed with baselineskip)
988%D \stoptyping
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 % prevents that tex injects empty line (when using native display mechanism)
1000     \Ucheckedstartdisplaymath
1001     \the\everydisplay % new (probably too much)
1002   \or
1003     \setbox\b_strc_formulas_content\hbox\bgroup
1004     \normalUstartmath
1005     \displaystyle
1006     \the\everydisplay % new (probably too much)
1007   \else
1008     \expandafter\startinnermath
1009   \fi
1010   \begingroup} % less interference with upcoming a \over b
1011
1012\unexpanded\def\stopdisplaymath
1013  {\endgroup    % less interference with upcoming a \over b
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% already defined
1027%
1028% \let\startinnermath\empty
1029% \let\stopinnermath \empty
1030
1031% \defineformulaalternative[multi][\begindmath][\enddmath]
1032%
1033% \fakewords{20}{40}\epar
1034% \placeformula {a} $$              \fakespacingformula $$
1035% \fakewords{20}{40}\epar
1036% \placeformula {b} \startformule   \fakespacingformula \stopformule
1037% \placeformula {b} \startformule   \fakespacingformula \stopformule
1038% \fakewords{20}{40}\epar
1039% \placeformula {c} \startmdformule \fakespacingformula \stopmdformule
1040% \placeformula {c} \startmdformule \fakespacingformula \stopmdformule
1041% \fakewords{20}{40}\epar
1042% \placeformula {d} \startmpformule \fakespacingformula \stopmpformule
1043% \placeformula {d} \startmpformule \fakespacingformula \stopmpformule
1044% \fakewords{20}{40}\epar
1045% \placeformula {e} \startsdformule \fakespacingformula \stopsdformule
1046% \placeformula {e} \startsdformule \fakespacingformula \stopsdformule
1047% \fakewords{20}{40}\epar
1048% \placeformula {f} \startspformule \fakespacingformula \stopspformule
1049% \placeformula {f} \startspformule \fakespacingformula \stopspformule
1050% \fakewords{20}{40}
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 % to be checked
1064   \global\setfalse\c_strc_formulas_inside_formulas_sub
1065   \dorechecknextindentation} % here ?
1066
1067%D Named subformulas (to be redone)
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%D Experimental goodie:
1080%D
1081%D \startbuffer
1082%D \placelist[formula][criterium=text] \blank[2*big]
1083%D \placenamedformula[one]{first}  \startformula a = 1 \stopformula \endgraf
1084%D \placeformula                   \startformula a = 2 \stopformula \endgraf
1085%D \placenamedformula     {second} \startformula a = 3 \stopformula \endgraf
1086%D \stopbuffer
1087%D
1088%D \typebuffer \getbuffer
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  %\Ustartmath
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  %\Ustopmath
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% preroll
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    % added for side floats
1136   \hangindent\zeropoint} % added for side floats
1137
1138% place
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 % \relax % new 29/8/2010
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} % for the moment
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} % [ref]{}
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} % [ref]$$ [ref]\start
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% \let\startplaceformula\placeformula
1194% \let\stopplaceformula \relax
1195
1196% \startplaceformula                 \startformula e=mc^2 \stopformula \stopplaceformula
1197% \startplaceformula[-]              \startformula e=mc^2 \stopformula \stopplaceformula
1198% \startplaceformula[x]              \startformula e=mc^2 \stopformula \stopplaceformula
1199% \startplaceformula[reference=foo]  \startformula e=mc^2 \stopformula \stopplaceformula
1200% \startplaceformula[title=whatever] \startformula e=mc^2 \stopformula \stopplaceformula
1201% \startplaceformula[suffix=x]       \startformula e=mc^2 \stopformula \stopplaceformula
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  %\doifelsenextbgroup\strc_formulas_place_yes\strc_formulas_place_nop} % [ref]{}
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} % [ref]{}
1251
1252\def\strc_formulas_stop_place
1253  {\relax
1254   \endgroup}
1255
1256% to be checked
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     % nothing
1267   \or
1268     \glet\strc_formulas_place_number\relax
1269     \expandafter\strc_formulas_number % hm, looks ahead for []
1270   \or
1271     % nothing
1272   \or
1273     \glet\strc_formulas_place_number\relax
1274     \expandafter\strc_formulas_number % hm, looks ahead for []
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        % nothing to be done
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% todo
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 % \relax % this will become a key/value so that we can do bookmarks
1319
1320\unexpanded\def\setformulalistentry#1%
1321  {\gdef\namedformulaentry{#1}}
1322
1323\protect \endinput
1324
1325% \abovedisplayshortskip0pt \belowdisplayshortskip0pt \abovedisplayskip0pt \belowdisplayskip0pt \forgetall
1326%
1327% test       \par                      $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1328% test       \par                      $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1329% test plus  \par \prevdepth \maxdimen $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1330% test minus \par \prevdepth-\maxdimen $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1331%
1332% \parskip\baselineskip
1333%
1334% test       \par                      $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1335% test       \par                      $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1336% test plus  \par \prevdepth \maxdimen $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1337% test minus \par \prevdepth-\maxdimen $$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx$$ \par test \par
1338