math-frc.mkxl /size: 28 Kb    last modification: 2025-02-21 11:03
1%D \module
2%D   [       file=math-frc,
3%D        version=2013.04.06, % 2007.07.19,
4%D          title=\CONTEXT\ Math Macros,
5%D       subtitle=Fractions,
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% todo : mathclass=\mathnothingcode, % todo also accept string
15
16\writestatus{loading}{ConTeXt Math Macros / Fractions}
17
18\unprotect
19
20%D This module is reimplemented in \MKIV\ style.
21
22\registerctxluafile{math-frc}{autosuffix}
23
24%D \macros
25%D   {frac, xfrac, xxfrac}
26%D
27%D This is another one Tobias asked for. It replaces the primitive \type {\over}. We
28%D also take the opportunity to handle math style restoring, which makes sure units
29%D and chemicals come out ok. The \type {\frac} macro kind of replaces the awkward
30%D \type {\over} primitive. Say that we have the following formulas:
31%D
32%D \startbuffer[sample]
33%D test $\frac  {1}{2}$ test $$1 + \frac  {1}{2} = 1.5$$
34%D test $\xfrac {1}{2}$ test $$1 + \xfrac {1}{2} = 1.5$$
35%D test $\xxfrac{1}{2}$ test $$1 + \xxfrac{1}{2} = 1.5$$
36%D \stopbuffer
37%D
38%D \typebuffer[sample]
39%D
40%D With the most straightforward definitions, we get:
41%D
42%D \startbuffer[code]
43%D \def\dofrac#1#2#3{\relax\mathematics{{{#1{#2}}\over{#1{#3}}}}}
44%D
45%D \def\frac  {\dofrac\mathstyle}
46%D \def\xfrac {\dofrac\scriptstyle}
47%D \def\xxfrac{\dofrac\scriptscriptstyle}
48%D \stopbuffer
49%D
50%D \typebuffer[code] \getbuffer[code,sample]
51%D
52%D Since this does not work well, we can try:
53%D
54%D \startbuffer[code]
55%D \def\xfrac #1#2{\hbox{$\dofrac\scriptstyle      {#1}{#2}$}}
56%D \def\xxfrac#1#2{\hbox{$\dofrac\scriptscriptstyle{#1}{#2}$}}
57%D \stopbuffer
58%D
59%D \typebuffer[code] \getbuffer[code,sample]
60%D
61%D This for sure looks better than:
62%D
63%D \startbuffer[code]
64%D \def\xfrac #1#2{{\scriptstyle      \dofrac\relax{#1}{#2}}}
65%D \def\xxfrac#1#2{{\scriptscriptstyle\dofrac\relax{#1}{#2}}}
66%D \stopbuffer
67%D
68%D \typebuffer[code] \getbuffer[code,sample]
69%D
70%D So we stick to the next definitions (watch the local overloading of
71%D \type {\xfrac}).
72%D
73%D In the meantime, in \LUATEX, we have better control over styles so the following
74%D macros are different from the \MKII\ ones.
75
76\installcorenamespace{mathfractions}
77\installcorenamespace{mathfractionstyle}
78\installcorenamespace{mathfractionalternative}
79
80\installcommandhandler \??mathfractions {mathfraction} \??mathfractions
81
82\aliased\let\setupmathfractions\setupmathfraction
83
84% color only applies to rule, use regular color for rest
85
86\integerdef\math_frac_no_delim "2E % or just \zerocount
87
88\setupmathfractions
89  [\c!mathstyle=,
90   \c!method=\v!vertical,
91   \c!mathnumeratorstyle=\mathfractionparameter\c!mathstyle,
92   \c!mathdenominatorstyle=\mathfractionparameter\c!mathstyle,
93   \c!mathmeaning=\currentglobalmathfraction,
94   \c!mathclass=\mathfractioncode,
95   \c!alternative=\v!inner,
96   \c!margin=\zeropoint,
97 % \c!rulethickness=.1\exheight, % was .25 for above / atop
98   \c!rulethickness=\v!font,
99   \c!left="2E,
100   \c!right="2E,
101   \c!middle="2F,
102   \c!color=,
103   \c!topcolor=\mathfractionparameter\c!textcolor,
104   \c!bottomcolor=\mathfractionparameter\c!textcolor,
105   \c!textcolor=\mathfractionparameter\c!color,
106   \c!symbolcolor=\mathfractionparameter\c!color,
107   \c!strut=\v!yes,
108   \c!topdistance=,
109   \c!bottomdistance=,
110   \c!source=\zerocount,
111   \c!hfactor=\plusfivehundred,% skewed
112   \c!vfactor=\plusonehundredtwentyfive,% skewed
113   \c!rule=\v!auto]
114
115%D We now default to nice bars:
116
117\integerdef\fractionbarextenderuc \privatecharactercode{fraction bar extender}
118
119\setupmathfractions
120  [\c!rule=\v!symbol,
121   \c!symbol=\fractionbarextenderuc]
122
123\appendtoks
124    \instance\frozen\protected\edefcsname\currentmathfraction\endcsname{\math_frac{\currentmathfraction}}%
125\to \everydefinemathfraction
126
127% Sometimes users want control over the distances:
128
129% So far for control.
130
131% no    : \ruledhbox{\m{\frac[strut=no]   {28}{8\times29}}} \par
132% tight : \ruledhbox{\m{\frac[strut=tight]{28}{8\times29}}} \par
133% yes   : \ruledhbox{\m{\frac[strut=yes]  {28}{8\times29}}} \par
134% math  : \ruledhbox{\m{\frac[strut=math] {28}{8\times29}}} \par
135% text  : \ruledhbox{\m{\frac[strut=text] {28}{8\times29}}} \par
136
137\installcorenamespace{mathfractionstrut}
138
139\def\math_frac_no_strut
140  {\enforced\let\m_fractions_strut_top\relax
141   \enforced\let\m_fractions_strut_bot\relax}
142
143\defcsname\??mathfractionstrut\v!yes\endcsname
144  {\enforced\let\m_fractions_strut_top\mathstrut
145   \enforced\let\m_fractions_strut_bot\mathstrut}
146
147\defcsname\??mathfractionstrut\v!math\endcsname
148  {\enforced\let\m_fractions_strut_top\mathstrut
149   \enforced\let\m_fractions_strut_bot\mathstrut}
150
151\letcsname\??mathfractionstrut\v!no\endcsname\math_frac_no_strut
152
153\defcsname\??mathfractionstrut\v!tight\endcsname
154  {\enforced\let\m_fractions_strut_top\mathdepthstrut
155   \enforced\let\m_fractions_strut_bot\mathheightstrut}
156
157\defcsname\??mathfractionstrut\v!text\endcsname
158  {\enforced\let\m_fractions_strut_top\strut
159   \enforced\let\m_fractions_strut_bot\strut}
160
161\math_frac_no_strut
162
163\newdimension\d_math_fraction_margin
164
165\def\math_fraction_margin_kern_indeed{\kern\d_math_fraction_margin}
166
167\let\math_fraction_margin_kern\relax
168
169%D \starttyping
170%D $\Uover{2}{3} ^4$ % double script error but no longer because we use the prescripts
171%D ${\over{2}{3}}^4$ % no issue anyway because we wrap in {} (goes unnoticed)
172%D $\frac {2}{3} ^4$ % we wrap in \mathfrac so we can also use prescripts
173%D \stoptyping
174
175\installlocalcurrenthandler\??mathfractions {mathfraction}
176
177\tolerant\protected\def\math_frac#1#*[#S#2]%%
178  {\beginmathgroup
179   %
180   \setlocalmathfractioncurrent{#1}% \edef\currentmathfraction{#1}%
181   %
182   \ifparameter#2\or\setupcurrentmathfraction[#2]\fi
183   %
184   \edef\p_math_fraction_fences{\mathfractionparameter\c!fences}%
185   \dostarttagged\t!mfractionstack{\mathfractionparameter\c!mathmeaning}%
186   %
187   \math_atom_by_parameter\mathfractionparameter\bgroup
188   \ifempty\p_math_fraction_fences \else
189     \math_fenced_fenced_start\p_math_fraction_fences
190   \fi
191   %
192   \d_math_fraction_margin{\mathfractionparameter\c!margin}%
193   \ifcase\d_math_fraction_margin
194      \let\math_fraction_margin_kern\relax
195   \else
196      \let\math_fraction_margin_kern\math_fraction_margin_kern_indeed
197   \fi
198   %
199   \edef\p_math_fractions_strut{\mathfractionparameter\c!strut}%
200   \ifcsname\??mathfractionstrut\p_math_fractions_strut\endcsname
201     \lastnamedcs
202   \else
203     \math_frac_no_strut
204   \fi
205   %
206   % This only adds a level of structure so that we don't get the everthing tagged
207   % fractionstack.
208   \dostarttagged\t!mfraction\currentglobalmathfraction
209   \expandnamespaceparameter\??mathfractionalternative\mathfractionparameter\c!alternative\v!inner}
210
211\protected\def\math_frac_wrapup
212  {\ifempty\p_math_fraction_fences \else
213     \math_fenced_fenced_stop\p_math_fraction_fences
214   \fi
215   \dostoptagged
216   \egroup
217   \dostoptagged
218   \endmathgroup}
219
220% Having a \withmarginornot{#1}{#2} makes not much sense nor do 4 tests or 4 redundant
221% kerns (longer node lists plus possible interference). A split in normal and margin
222% also makes testing easier. When left and right margins are needed we might merge the
223% variants again. After all, these are not real installers.
224%
225% The denominator is normally in cramped mode!
226%
227% See \MKIV\ for the old (more messy) implementation where we have to fight the over
228% related syntax (we now use a lmtx primitive).
229
230% timestamp: 01/2022 : (re)watching eNerdā“ - Time Capsule 2020 a.k.a. Farewell Party
231% for Normalcy (UHD) with the soekris/neumanns combination
232
233% Todo: \Umathfrac for all of them as we're keyword driven anyway.
234
235\installcorenamespace{fractionmethods}
236
237\defcsname\??fractionmethods\v!vertical  \v!no     \v!none\endcsname{\Uatop}
238\defcsname\??fractionmethods\v!vertical  \v!no            \endcsname{\Uatopwithdelims
239                                                                     \Umathchar\zerocount\fam\scratchcounterone
240                                                                     \Umathchar\zerocount\fam\scratchcountertwo}
241\defcsname\??fractionmethods\v!vertical  \v!yes    \v!none\endcsname{\Uabove}
242\defcsname\??fractionmethods\v!vertical  \v!yes           \endcsname{\Uabovewithdelims
243                                                                     \Umathchar\zerocount\fam\scratchcounterone
244                                                                     \Umathchar\zerocount\fam\scratchcountertwo}
245\defcsname\??fractionmethods\v!vertical  \v!hidden \v!none\endcsname{\Uabove}
246\defcsname\??fractionmethods\v!vertical  \v!hidden        \endcsname{\Uabovewithdelims
247                                                                     \Umathchar\zerocount\fam\scratchcounterone
248                                                                     \Umathchar\zerocount\fam\scratchcountertwo}
249\defcsname\??fractionmethods\v!vertical  \v!auto   \v!none\endcsname{\Uover}
250\defcsname\??fractionmethods\v!vertical  \v!auto          \endcsname{\Uoverwithdelims
251                                                                     \Umathchar\zerocount\fam\scratchcounterone
252                                                                     \Umathchar\zerocount\fam\scratchcountertwo}
253\defcsname\??fractionmethods\v!vertical  \v!symbol \v!none\endcsname{\Ustretched
254                                                                     \Umathchar\zerocount\fam\scratchcounterthree}
255\defcsname\??fractionmethods\v!vertical  \v!symbol        \endcsname{\Ustretchedwithdelims
256                                                                     \Umathchar\zerocount\fam\scratchcounterone
257                                                                     \Umathchar\zerocount\fam\scratchcountertwo
258                                                                     \Umathchar\zerocount\fam\scratchcounterthree}
259\defcsname\??fractionmethods\v!horizontal          \v!none\endcsname{\Uskewed
260                                                                     \Umathchar\zerocount\fam\scratchcounterthree
261                                                                     \s!hfactor {\mathfractionparameter\c!hfactor}}
262\defcsname\??fractionmethods\v!horizontal                 \endcsname{\Uskewedwithdelims
263                                                                     \Umathchar\zerocount\fam\scratchcounterone
264                                                                     \Umathchar\zerocount\fam\scratchcountertwo
265                                                                     \Umathchar\zerocount\fam\scratchcounterthree
266                                                                     \s!hfactor {\mathfractionparameter\c!hfactor}}
267\defcsname\??fractionmethods\v!line                \v!none\endcsname{\Uskewed
268                                                                     \Umathchar\zerocount\fam\scratchcounterthree
269                                                                     \s!noaxis \relaxedspace
270                                                                     \s!hfactor {\mathfractionparameter\c!hfactor}}
271\defcsname\??fractionmethods\v!line                       \endcsname{\Uskewedwithdelims
272                                                                     \Umathchar\zerocount\fam\scratchcounterone
273                                                                     \Umathchar\zerocount\fam\scratchcountertwo
274                                                                     \Umathchar\zerocount\fam\scratchcounterthree
275                                                                     \s!noaxis \relaxedspace
276                                                                     \s!hfactor {\mathfractionparameter\c!hfactor}}
277
278\def\math_frac_common
279  {\edef\p_method     {\mathfractionparameter\c!method}%
280   \edef\p_rule       {\mathfractionparameter\c!rule}%
281   \edef\p_thickness  {\mathfractionparameter\c!rulethickness}%
282   \scratchcounterone  \mathfractionparameter\c!left  \relax
283   \scratchcountertwo  \mathfractionparameter\c!right \relax
284   \scratchcounterthree
285      \ifx\p_method\v!horizontal
286        \mathfractionparameter\c!middle
287    % \orelse\ifx\p_method\v!mp
288    %   \mathfractionparameter\c!middle
289      \orelse\ifx\p_method\v!line
290        \mathfractionparameter\c!middle
291      \else
292        \mathfractionparameter\c!symbol
293      \fi
294   \relax
295   %
296   \ifcstok{\mathfractionparameter\c!mathstyle}\s!identity
297     \frozen\Umathnumeratorvariant  \allmathstyles\mathstylevariantidentity
298     \frozen\Umathdenominatorvariant\allmathstyles\mathstylevariantidentity
299     \resetmathfractionparameter\c!mathstyle
300   \fi
301   %
302   \ifcstok{\mathfractionparameter\c!plugin}\v!mp
303     \edef\p_mp{\mathfractionparameter\c!mp}%
304     \ifempty\p_mp\else
305       \clf_set_extensible_data
306           mp     {\p_mp}
307           left   \scratchcounterthree
308           right  \scratchcounterthree
309           middle \scratchcounterthree
310        \relax
311     \fi
312   \else
313     \lettonothing\p_mp
314   \fi
315   %
316   \ifcsname
317      \??fractionmethods
318      \p_method
319      \ifx\p_method\v!horizontal
320    % \orelse\ifx\p_method\v!mp
321      \orelse\ifx\p_method\v!line
322      \orelse\ifcsname\??fractionmethods\p_method\p_rule\endcsname % \v!vertical
323        \p_rule
324      \else
325        \v!auto
326      \fi
327      \ifnum\scratchcounterone=\math_frac_no_delim
328        \ifnum\scratchcountertwo=\math_frac_no_delim
329          \v!none
330        \fi
331      \fi
332   \endcsname \lastnamedcs \else \csname\??fractionmethods\v!vertical\v!auto\endcsname \fi
333   \usedsymbolcolorparameterattributes{\mathfractionparameter\c!symbolcolor}%
334   \s!thickness
335     \ifx\p_thickness\v!font
336       \zeropoint
337       \s!font\relaxedspace
338     \else
339       {\p_thickness}%
340     \fi
341   \s!class   \math_class_by_parameter\mathfractionparameter\c!mathclass
342   \s!vfactor {\mathfractionparameter\c!vfactor}%
343   \s!source  {\namedboxanchor{\mathfractionparameter\c!source}}%
344   \ifempty\p_mp\else
345     \s!usecallback\relaxedspace
346   \fi}
347
348\installcorenamespace{mathalignsimple} % this should move to math-ali
349
350\defcsname\??mathalignsimple\v!right     \endcsname#1{#1\hfill}
351\defcsname\??mathalignsimple\v!flushleft \endcsname#1{#1\hfill}
352\defcsname\??mathalignsimple\v!left      \endcsname#1{\hfill#1}
353\defcsname\??mathalignsimple\v!flushright\endcsname#1{\hfill#1}
354\defcsname\??mathalignsimple\v!middle    \endcsname#1{\hfill#1\hfill}
355
356\protected\def\math_frac_aligned_top{\begincsname\??mathalignsimple\mathfractionparameter\c!topalign   \endcsname}
357\protected\def\math_frac_aligned_bot{\begincsname\??mathalignsimple\mathfractionparameter\c!bottomalign\endcsname}
358
359% \protected\def\math_frac_aligned_top{\begincsname\??mathalignsimple\mathfractionparameter\c!align\endcsname}
360% \protected\def\math_frac_aligned_bot{\begincsname\??mathalignsimple\mathfractionparameter\c!align\endcsname}
361
362\protected\defcsname\??mathfractionalternative\v!inner\endcsname#1#2%
363  {%\beginmathgroup
364   \math_frac_common
365     {\usemathfractioncolorparameter\c!topcolor
366      \math_fraction_margin_kern
367      \usemathstyleparameter\mathfractionparameter\c!mathnumeratorstyle
368      \m_fractions_strut_top\math_frac_aligned_top{#1}%
369      \math_fraction_margin_kern}%
370     {\usemathfractioncolorparameter\c!bottomcolor
371      \math_fraction_margin_kern
372      \usemathstyleparameter\mathfractionparameter\c!mathdenominatorstyle
373      \m_fractions_strut_bot\math_frac_aligned_bot{#2}%
374      \math_fraction_margin_kern}%
375   %\endmathgroup
376   \math_frac_wrapup}
377
378\protected\defcsname\??mathfractionalternative\v!outer\endcsname#1#2%
379  {\beginmathgroup
380   \usemathstyleparameter\mathfractionparameter\c!mathstyle
381   \math_frac_common
382     {\usemathfractioncolorparameter\c!topcolor
383      \math_fraction_margin_kern
384      \m_fractions_strut_top\math_frac_aligned_top{#1}%
385      \math_fraction_margin_kern}%
386     {\usemathfractioncolorparameter\c!bottomcolor
387      \math_fraction_margin_kern
388      \m_fractions_strut_bot\math_frac_aligned_bot{#2}%
389      \math_fraction_margin_kern}%
390   \endmathgroup
391   \math_frac_wrapup}
392
393\protected\defcsname\??mathfractionalternative\v!both\endcsname#1#2%
394  {\beginmathgroup
395   \usemathstyleparameter\mathfractionparameter\c!mathstyle
396   \math_frac_common
397     {\usemathfractioncolorparameter\c!topcolor
398      \math_fraction_margin_kern
399      \usemathstyleparameter\mathfractionparameter\c!mathnumeratorstyle
400      \m_fractions_strut_top\math_frac_aligned_top{#1}%
401      \math_fraction_margin_kern}%
402     {\usemathfractioncolorparameter\c!bottomcolor
403      \math_fraction_margin_kern
404      \usemathstyleparameter\mathfractionparameter\c!mathdenominatorstyle
405      \m_fractions_strut_bot\math_frac_aligned_bot{#2}%
406      \math_fraction_margin_kern}%
407   \endmathgroup
408   \math_frac_wrapup}
409
410\nulldelimiterspace\zeropoint % was 1.2pt
411
412\definemathfraction[xfrac] [\c!alternative=\v!inner,\c!mathstyle=\s!script]
413\definemathfraction[xxfrac][\c!alternative=\v!inner,\c!mathstyle=\s!scriptscript]
414
415\aliased\let\normalxfrac\xfrac
416
417\permanent\protected\def\xfrac#1#2{\normalxfrac{\enforced\let\xfrac\xxfrac#1}{\enforced\let\xfrac\xxfrac#2}}
418
419%D Spacing (sensitive for definition of \triggermathstyle:
420
421\installcorenamespace{mathfractiondistance}
422
423\defcsname\??mathfractiondistance\v!none\endcsname
424  {\Umathfractionnumup    \allmathstyles\zeropoint
425   \Umathfractiondenomdown\allmathstyles\zeropoint}
426
427\defcsname\??mathfractiondistance\v!no\endcsname
428  {\Umathfractionnumup    \allmathstyles\zeropoint
429   \Umathfractiondenomdown\allmathstyles\zeropoint}
430
431\defcsname\??mathfractiondistance\v!overlay\endcsname
432  {\Umathfractionnumup    \allmathstyles\zeropoint
433   \Umathfractionnumvgap  \allmathstyles\zeropoint
434   \Umathfractiondenomvgap\allmathstyles\zeropoint
435   \Umathfractiondenomdown\allmathstyles\zeropoint}
436
437\defcsname\??mathfractiondistance\v!top\endcsname
438  {\Umathfractionnumvgap  \allmathstyles{\mathfractionparameter\c!topdistance}%
439   \relax}
440
441\defcsname\??mathfractiondistance\v!bottom\endcsname
442  {\Umathfractiondenomvgap\allmathstyles{\mathfractionparameter\c!bottomdistance}%
443   \relax}
444
445\defcsname\??mathfractiondistance\v!both\endcsname
446  {\Umathfractionnumvgap  \allmathstyles{\mathfractionparameter\c!topdistance}%
447   \Umathfractiondenomvgap\allmathstyles{\mathfractionparameter\c!bottomdistance}%
448   \relax}
449
450\setupmathfractions
451  [\c!distance=\v!none,
452   \c!topdistance=\zeropoint,
453   \c!bottomdistance=\zeropoint]
454
455% we need to keep it local, so not everybodyfont
456
457\appendtoks
458    \edef\p_distance{\rootmathfractionparameter\c!distance}%
459    \ifempty\p_distance\else
460        \begincsname\??mathfractiondistance\p_distance\endcsname
461    \fi
462\to \everymathematics
463
464% theshold is new!
465
466\let\math_fraction_set_threshold_inline \relax
467\let\math_fraction_set_threshold_display\relax
468
469\appendtoks
470    \math_fraction_set_threshold_inline
471    \math_fraction_set_threshold_display
472\to \everymathematics
473
474\appendtoks
475    \ifempty\currentmathfraction
476      \edef\p_threshold{\mathfractionparameter\c!inlinethreshold}%
477      \ifempty\p_threshold
478        \let\math_fraction_set_threshold_inline\math_fraction_set_threshold_inline_auto
479      \orelse\ifx\p_threshold\v!auto
480        \let\math_fraction_set_threshold_inline\math_fraction_set_threshold_inline_auto
481      \else
482        \let\math_fraction_set_threshold_inline\math_fraction_set_threshold_inline_ratio
483      \fi
484      \edef\p_threshold{\mathfractionparameter\c!displaythreshold}%
485      \ifempty\p_threshold
486        \let\math_fraction_set_threshold_display\math_fraction_set_threshold_display_auto
487      \orelse\ifx\p_threshold\v!auto
488        \let\math_fraction_set_threshold_display\math_fraction_set_threshold_display_auto
489      \else
490        \let\math_fraction_set_threshold_display\math_fraction_set_threshold_display_ratio
491      \fi
492    \fi
493\to \everysetupmathfraction
494
495\def\math_fraction_set_threshold_inline_auto
496   {\Umathfractiondelsize\allmathstyles\maxdimen}
497
498\def\math_fraction_set_threshold_display_auto
499   {\Umathfractiondelsize\alldisplaystyles\maxdimen}
500
501% \dimexpr#1*\plusthousand/\glyphscale\relax
502
503\def\math_fraction_set_threshold_inline_ratio % watch the reverse compensation
504  {\edef\p_threshold{\mathfractionparameter\c!inlinethreshold}%
505   \Umathfractiondelsize\alltextstyles        \p_threshold\glyphscaled\textface
506   \Umathfractiondelsize\allscriptstyles      \p_threshold\glyphscaled\scriptface
507   \Umathfractiondelsize\allscriptscriptstyles\p_threshold\glyphscaled\scriptscriptface}
508
509\def\math_fraction_set_threshold_display_ratio % watch the reverse compensation
510  {\edef\p_threshold{\mathfractionparameter\c!displaythreshold}%
511   \Umathfractiondelsize\alldisplaystyles\p_threshold\glyphscaled\textface}
512
513\setupmathfractions
514  [\c!inlinethreshold=1.2,      % no unit but fraction
515   \c!displaythreshold=\v!auto, % no unit but fraction
516   \c!threshold=.25\exheight]
517
518\appendtoks
519    \Umathskeweddelimitertolerance\allmathstyles\mathfractionparameter\c!threshold
520\to \everymathematics % else original lost: \to \everybodyfont
521
522%D \macros
523%D   {dfrac, tfrac, frac, dbinom, tbinom, binom}
524%D
525%D \startbuffer
526%D $\dfrac {1}{2} \tfrac {1}{2} \frac {1}{2}$
527%D $\dbinom{1}{2} \tbinom{1}{2} \binom{1}{2}$
528%D \stopbuffer
529%D
530%D \typebuffer
531%D \getbuffer
532
533% $$
534%     {{a}\over{b}} +
535%     {{a}\overwithdelims(){b}} +
536%     {{a}\atopwithdelims(){b}} +
537%     {{a}\abovewithdelims()\zeropoint{b}} +
538%     \left({{a}\over{b}}\right)
539% $$
540
541% \dorecurse {10} { % weird
542%     $$ {{a}\abovewithdelims()#1pt{b}} $$
543% }
544
545\definemathfraction[i:frac] [\c!alternative=\v!inner,\c!mathstyle=\v!small]
546\definemathfraction[i:tfrac][\c!alternative=\v!inner,\c!mathstyle=\s!script]
547\definemathfraction[i:sfrac][\c!alternative=\v!inner,\c!mathstyle=\s!scriptscript]
548\definemathfraction[i:dfrac][\c!alternative=\v!inner,\c!mathstyle=\s!display]
549
550\definemathfraction[d:frac] [\c!alternative=\v!inner,\c!mathstyle=\s!cramped]
551\definemathfraction[d:tfrac][\c!alternative=\v!inner,\c!mathstyle={\s!cramped,\s!script}]
552\definemathfraction[d:sfrac][\c!alternative=\v!inner,\c!mathstyle={\s!cramped,\s!scriptscript}]
553\definemathfraction[d:dfrac][\c!alternative=\v!both,\c!mathstyle=\s!display]
554
555%D \protected\def\ShowMathFractions#1#2%
556%D   {\dontleavehmode
557%D    \begingroup
558%D    \showmathstruts
559%D    \mathematics{x+\tfrac{#1}{#2}+1+\frac{#1}{#2}+2+\sfrac{#1}{#2}+g}%
560%D    \endgroup}
561%D
562%D The default \type {tfrac}, \type {frac} and \type \sfrac} look like this:
563%D
564%D \blank
565%D \ShowMathFractions{a}{a}\par
566%D \ShowMathFractions{1}{x}\par
567%D \ShowMathFractions{a}{b}\par
568%D \ShowMathFractions{1}{b}\par
569%D \blank
570
571%D There is no real need to support ams styling any longer so we removed the
572%D related code.
573
574\permanent\protected\def\frac {\csname\inlineordisplaymath id:frac\endcsname}
575\permanent\protected\def\tfrac{\csname\inlineordisplaymath id:tfrac\endcsname}
576\permanent\protected\def\sfrac{\csname\inlineordisplaymath id:sfrac\endcsname}
577\permanent\protected\def\dfrac{\csname\inlineordisplaymath id:dfrac\endcsname}
578
579\definemathfraction
580  [d:binom]
581  [d:frac]
582  [\c!rule=\v!no,
583   \c!mathmeaning=binom,
584 % \c!mathstyle=\s!display,
585   \c!left="28,
586   \c!right="29]
587
588\definemathfraction
589  [i:binom]
590  [i:frac]
591  [\c!rule=\v!no,
592   \c!mathmeaning=binom,
593  %\c!mathstyle=\s!text,
594   \c!left="28,
595   \c!right="29]
596
597\permanent\protected\def\binom{\csname\inlineordisplaymath id:binom\endcsname}
598
599\definemathfraction
600  [dbinom]
601  [d:binom]
602  [\c!mathstyle=\s!display]
603
604\definemathfraction
605  [tbinom]
606  [i:binom]
607  [\c!mathstyle=\s!text]
608
609%D \macros
610%D   {cfrac}
611%D
612%D \startbuffer
613%D $\cfrac{12}{3} \cfrac[l]{12}{3} \cfrac[c]{12}{3} \cfrac[r]{12}{3}$
614%D $\cfrac{1}{23} \cfrac[l]{1}{23} \cfrac[c]{1}{23} \cfrac[r]{1}{23}$
615%D \stopbuffer
616%D
617%D \typebuffer
618%D
619%D \getbuffer
620%D
621%D Now we can align every combination we want:
622%D
623%D \startbuffer
624%D $\cfrac{12}{3} \cfrac[l]{12}{3} \cfrac[c]{12}{3} \cfrac[r]{12}{3}$
625%D $\cfrac{1}{23} \cfrac[l]{1}{23} \cfrac[c]{1}{23} \cfrac[r]{1}{23}$
626%D $\cfrac[cl]{12}{3} \cfrac[cc]{12}{3} \cfrac[cr]{12}{3}$
627%D $\cfrac[lc]{1}{23} \cfrac[cc]{1}{23} \cfrac[rc]{1}{23}$
628%D \stopbuffer
629%D
630%D \typebuffer
631%D
632%D \getbuffer
633
634% % we forget about this ams one ... no one uses it anyway
635%
636% \permanent\protected\def\cfrac
637%   {\doifelsenextoptionalcs\math_cfrac_yes\math_cfrac_nop}
638%
639% \def\math_cfrac_nop    {\math_cfrac_indeed[cc]}
640% \def\math_cfrac_yes[#1]{\math_cfrac_indeed[#1cc]}
641%
642% \def\math_cfrac_indeed[#1#2#3]#4#5%
643%   {{\displaystyle
644%     \frac
645%       {\strut
646%        \ifx r#1\hfill\fi#4\ifx l#1\hfill\fi}%
647%       {\ifx r#2\hfill\fi#5\ifx l#2\hfill\fi}%
648%     \ifzeropt\nulldelimiterspace\else
649%       \kern-\nulldelimiterspace
650%     \fi}}
651%
652% instead we predefine one:
653
654\definemathfraction
655  [cfrac]
656  [\c!mathstyle=\v!text]
657
658% so users can do this:
659%
660% \setupmathfraction
661%   [cfrac]
662%   [topalign=flushright]
663%
664% or define an child instance that presets it.
665
666%D \macros
667%D   {splitfrac, splitdfrac}
668%D
669%D Occasionally one needs to typeset multi||line fractions. These commands use \type
670%D {\genfrac} to create such fractions.
671%D
672%D \startbuffer
673%D \startformula
674%D      a=\frac{
675%D          \splitfrac{xy + xy + xy + xy + xy}
676%D                    {+ xy + xy + xy + xy}
677%D        }
678%D        {z}
679%D      =\frac{
680%D          \splitdfrac{xy + xy + xy + xy + xy}
681%D                    {+ xy + xy + xy + xy}
682%D        }
683%D        {z}
684%D \stopformula
685%D \stopbuffer
686%D
687%D \typebuffer \getbuffer
688
689\defcsname\??mathalignsimple\v!split:\v!flushleft\endcsname#1%
690  {#1%
691   \ifchkdimension\mathfractionparameter\c!distance\or\hkern\lastchkdimension\fi
692   \hfill}
693
694\defcsname\??mathalignsimple\v!split:\v!flushright\endcsname#1%
695  {\hfill
696   \ifchkdimension\mathfractionparameter\c!distance\or\hkern\lastchkdimension\fi
697   \mathatom \s!class \mathordcode \s!unroll {}% prevents +/- seen as sign, unroll prevents empty box
698   #1}
699
700\definemathfraction
701  [splitfrac]
702  [\c!mathnumeratorstyle=\v!text,
703   \c!mathdenominatorstyle=\v!text,
704   \c!topalign=\v!split:\v!flushleft,
705   \c!bottomalign=\v!split:\v!flushright,
706   \c!distance=\emwidth,
707   \c!rule=\v!no]
708
709\definemathfraction
710  [splitdfrac]
711  [splitfrac]
712  [\c!mathnumeratorstyle=\v!display,
713   \c!mathdenominatorstyle=\v!display]
714
715%D More fracking:
716%D
717%D \starttyping
718%D \m {\mathaxisbelow\vfrac             {1}{x}}
719%D \m {\mathaxisbelow\vfrac[method=line]{1}{x}}
720%D \stoptyping
721
722\definemathfraction
723  [\s!vfrac]
724  [\c!method=\v!horizontal]
725
726% \definemathfraction
727%   [hfrac] % for ton's asciimath
728%   [\c!method=\v!line]
729
730%D And a cheat (for Mikael):
731
732% \definemathfraction
733%   [afrac]
734%   [\c!mathclass=\mathrelationcode,
735%    \c!rule=\v!symbol,
736%    \c!middle="2192]
737
738%D New stretched fraction with middle symnbol:
739
740% \enableexperiments[math.arrows] % enforce construction of these in math-act
741%
742% {
743%     tweak = "addarrows",
744%     list  = { [0x3D] = { squeeze = .85, yoffset = .0975 } } -- bonum
745% },
746
747\definemathfraction
748  [relfraction]
749  [\c!mathclass=\mathrelationcode,
750   \c!margin=.25\emwidth,
751   \c!rule=\v!symbol]
752
753\definemathfraction [bartext]                [relfraction] [\c!middle="203E]
754\definemathfraction [leftarrowtext]          [relfraction] [\c!middle="2190]
755\definemathfraction [rightarrowtext]         [relfraction] [\c!middle="2192]
756\definemathfraction [twoheadleftarrowtext]   [relfraction] [\c!middle="219E]
757\definemathfraction [twoheadrightarrowtext]  [relfraction] [\c!middle="21A0]
758\definemathfraction [reltext]                [relfraction] [\c!middle="002D]
759\definemathfraction [equaltext]              [relfraction] [\c!middle="003D]
760\definemathfraction [mapstotext]             [relfraction] [\c!middle="21A6]
761\definemathfraction [hookleftarrowtext]      [relfraction] [\c!middle="21A9]
762\definemathfraction [hookrightarrowtext]     [relfraction] [\c!middle="21AA]
763\definemathfraction [leftharpoondowntext]    [relfraction] [\c!middle="21BD]
764\definemathfraction [leftharpoonuptext]      [relfraction] [\c!middle="21BC]
765\definemathfraction [rightharpoondowntext]   [relfraction] [\c!middle="21C1]
766\definemathfraction [rightharpoonuptext]     [relfraction] [\c!middle="21C0]
767\definemathfraction [rightoverleftarrowtext] [relfraction] [\c!middle="21C4]
768\definemathfraction [leftrightharpoonstext]  [relfraction] [\c!middle="21CB]
769\definemathfraction [rightleftharpoonstext]  [relfraction] [\c!middle="21CC]
770\definemathfraction [triplereltext]          [relfraction] [\c!middle="2261]
771\definemathfraction [leftrightarrowtext]     [relfraction] [\c!middle="27F7]
772\definemathfraction [rightleftarrowtext]     [relfraction] [\c!middle="27F7]
773\definemathfraction [Leftarrowtext]          [relfraction] [\c!middle="27F8]
774\definemathfraction [Rightarrowtext]         [relfraction] [\c!middle="27F9]
775\definemathfraction [Leftrightarrowtext]     [relfraction] [\c!middle="27FA]
776\definemathfraction [Rightleftarrowtext]     [relfraction] [\c!middle="27FA]
777
778\protect \endinput
779