%D \module %D [ file=math-frc, %D version=2013.04.06, % 2007.07.19, %D title=\CONTEXT\ Math Macros, %D subtitle=Fractions, %D author=Hans Hagen, %D date=\currentdate, %D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] %C %C This module is part of the \CONTEXT\ macro||package and is %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. % todo : mathclass=\mathnothingcode, % todo also accept string \writestatus{loading}{ConTeXt Math Macros / Fractions} \unprotect %D This module is reimplemented in \MKIV\ style. \registerctxluafile{math-frc}{autosuffix} %D \macros %D {frac, xfrac, xxfrac} %D %D This is another one Tobias asked for. It replaces the primitive \type {\over}. We %D also take the opportunity to handle math style restoring, which makes sure units %D and chemicals come out ok. The \type {\frac} macro kind of replaces the awkward %D \type {\over} primitive. Say that we have the following formulas: %D %D \startbuffer[sample] %D test $\frac {1}{2}$ test $$1 + \frac {1}{2} = 1.5$$ %D test $\xfrac {1}{2}$ test $$1 + \xfrac {1}{2} = 1.5$$ %D test $\xxfrac{1}{2}$ test $$1 + \xxfrac{1}{2} = 1.5$$ %D \stopbuffer %D %D \typebuffer[sample] %D %D With the most straightforward definitions, we get: %D %D \startbuffer[code] %D \def\dofrac#1#2#3{\relax\mathematics{{{#1{#2}}\over{#1{#3}}}}} %D %D \def\frac {\dofrac\mathstyle} %D \def\xfrac {\dofrac\scriptstyle} %D \def\xxfrac{\dofrac\scriptscriptstyle} %D \stopbuffer %D %D \typebuffer[code] \getbuffer[code,sample] %D %D Since this does not work well, we can try: %D %D \startbuffer[code] %D \def\xfrac #1#2{\hbox{$\dofrac\scriptstyle {#1}{#2}$}} %D \def\xxfrac#1#2{\hbox{$\dofrac\scriptscriptstyle{#1}{#2}$}} %D \stopbuffer %D %D \typebuffer[code] \getbuffer[code,sample] %D %D This for sure looks better than: %D %D \startbuffer[code] %D \def\xfrac #1#2{{\scriptstyle \dofrac\relax{#1}{#2}}} %D \def\xxfrac#1#2{{\scriptscriptstyle\dofrac\relax{#1}{#2}}} %D \stopbuffer %D %D \typebuffer[code] \getbuffer[code,sample] %D %D So we stick to the next definitions (watch the local overloading of %D \type {\xfrac}). %D %D In the meantime, in \LUATEX, we have better control over styles so the following %D macros are different from the \MKII\ ones. \installcorenamespace{mathfractions} \installcorenamespace{mathfractionstyle} \installcorenamespace{mathfractionalternative} \installcommandhandler \??mathfractions {mathfraction} \??mathfractions \aliased\let\setupmathfractions\setupmathfraction % color only applies to rule, use regular color for rest \setupmathfractions [\c!mathstyle=, \c!method=\v!vertical, \c!mathnumeratorstyle=\mathfractionparameter\c!mathstyle, \c!mathdenominatorstyle=\mathfractionparameter\c!mathstyle, \c!mathclass=\mathfractioncode, \c!alternative=\v!inner, \c!margin=\zeropoint, % \c!rulethickness=.1\exheight, % was .25 for above / atop \c!rulethickness=\v!font, \c!left="2E, \c!right="2E, \c!middle="2F, \c!strut=\v!yes, \c!topdistance=, \c!bottomdistance=, \c!source=\zerocount, \c!hfactor=\plusthousand, \c!vfactor=\plusthousand, \c!rule=\v!auto] \appendtoks \instance\frozen\protected\edefcsname\currentmathfraction\endcsname{\math_frac{\currentmathfraction}}% \to \everydefinemathfraction % Sometimes users want control over the distances: \let\math_fraction_set_distance\relax \appendtoks \math_fraction_set_distance \to \everymathematics % why only displaystyle .. a bit weak .. will become a set \protected\def\math_fraction_set_distance_top {\Umathfractionnumup \displaystyle\m_math_fraction_distance_top \relax} \protected\def\math_fraction_set_distance_bot {\Umathfractiondenomdown\displaystyle\m_math_fraction_distance_bot \relax} \protected\def\math_fraction_set_distance_all {\Umathfractionnumup \displaystyle\m_math_fraction_distance_top \Umathfractiondenomdown\displaystyle\m_math_fraction_distance_bot \relax} \appendtoks \ifempty\currentmathfraction \edef\m_math_fraction_distance_top{\mathfractionparameter\c!topdistance}% \edef\m_math_fraction_distance_bot{\mathfractionparameter\c!bottomdistance}% \ifempty\m_math_fraction_distance_top \ifempty\m_math_fraction_distance_bot \let\math_fraction_set_distance\relax \else \let\math_fraction_set_distance\math_fraction_set_distance_bot \fi \else \ifempty\m_math_fraction_distance_bot \let\math_fraction_set_distance\math_fraction_set_distance_top \else \let\math_fraction_set_distance\math_fraction_set_distance_all \fi \fi \fi \to \everysetupmathfraction % So far for control. % no : \ruledhbox{\m{\frac[strut=no] {28}{8\times29}}} \par % tight : \ruledhbox{\m{\frac[strut=tight]{28}{8\times29}}} \par % yes : \ruledhbox{\m{\frac[strut=yes] {28}{8\times29}}} \par % math : \ruledhbox{\m{\frac[strut=math] {28}{8\times29}}} \par % text : \ruledhbox{\m{\frac[strut=text] {28}{8\times29}}} \par \installcorenamespace{mathfractionstrut} \def\math_frac_no_strut {\enforced\let\m_fractions_strut_top\relax \enforced\let\m_fractions_strut_bot\relax} \defcsname\??mathfractionstrut\v!yes\endcsname {\enforced\let\m_fractions_strut_top\mathstrut \enforced\let\m_fractions_strut_bot\mathstrut} \defcsname\??mathfractionstrut\v!math\endcsname {\enforced\let\m_fractions_strut_top\mathstrut \enforced\let\m_fractions_strut_bot\mathstrut} \letcsname\??mathfractionstrut\v!no\endcsname\math_frac_no_strut \defcsname\??mathfractionstrut\v!tight\endcsname {\enforced\let\m_fractions_strut_top\mathdepthstrut \enforced\let\m_fractions_strut_bot\mathheightstrut} \defcsname\??mathfractionstrut\v!text\endcsname {\enforced\let\m_fractions_strut_top\strut \enforced\let\m_fractions_strut_bot\strut} \math_frac_no_strut \newdimension\d_math_fraction_margin \def\math_fraction_margin_kern_indeed{\kern\d_math_fraction_margin} \let\math_fraction_margin_kern\relax %D \starttyping %D $\Uover{2}{3} ^4$ % double script error but no longer because we use the prescripts %D ${\over{2}{3}}^4$ % no issue anyway because we wrap in {} (goes unnoticed) %D $\frac {2}{3} ^4$ % we wrap in \mathfrac so we can also use prescripts %D \stoptyping \installlocalcurrenthandler\??mathfractions {mathfraction} \tolerant\protected\def\math_frac#1#*[#2]%% {\beginmathgroup % \setlocalmathfractioncurrent{#1}% \edef\currentmathfraction{#1}% % \ifparameter#2\or\setupcurrentmathfraction[#2]\fi % \edef\p_math_fraction_fences{\mathfractionparameter\c!fences}% % \math_atom_by_parameter\mathfractionparameter\bgroup \ifempty\p_math_fraction_fences \else \math_fenced_fenced_start\p_math_fraction_fences \fi % \d_math_fraction_margin\mathfractionparameter\c!margin\relax \ifcase\d_math_fraction_margin \let\math_fraction_margin_kern\relax \else \let\math_fraction_margin_kern\math_fraction_margin_kern_indeed \fi % \edef\p_math_fractions_strut{\mathfractionparameter\c!strut}% \ifcsname\??mathfractionstrut\p_math_fractions_strut\endcsname \lastnamedcs \else \math_frac_no_strut \fi % \expandnamespaceparameter\??mathfractionalternative\mathfractionparameter\c!alternative\v!inner} \protected\def\math_frac_wrapup {\ifempty\p_math_fraction_fences \else \math_fenced_fenced_stop\p_math_fraction_fences \fi \egroup \endmathgroup} \integerdef\math_frac_no_delim "2E % or just \zerocount % Having a \withmarginornot{#1}{#2} makes not much sense nor do 4 tests or 4 redundant % kerns (longer node lists plus possible interference). A split in normal and margin % also makes testing easier. When left and right margins are needed we might merge the % variants again. After all, these are not real installers. % % The denominator is normally in cramped mode! % % See \MKIV\ for the old (more messy) implementation where we have to fight the over % related syntax (we now use a lmtx primitive). % timestamp: 01/2022 : (re)watching eNerdā“ - Time Capsule 2020 a.k.a. Farewell Party % for Normalcy (UHD) with the soekris/neumanns combination \installcorenamespace{fractionmethods} \defcsname\??fractionmethods\v!vertical \v!no \v!none\endcsname{\Uatop} \defcsname\??fractionmethods\v!vertical \v!no \endcsname{\Uatopwithdelims \Udelimiter\zerocount\fam\scratchcounterone \Udelimiter\zerocount\fam\scratchcountertwo} \defcsname\??fractionmethods\v!vertical \v!yes \v!none\endcsname{\Uabove} \defcsname\??fractionmethods\v!vertical \v!yes \endcsname{\Uabovewithdelims \Udelimiter\zerocount\fam\scratchcounterone \Udelimiter\zerocount\fam\scratchcountertwo} \defcsname\??fractionmethods\v!vertical \v!hidden \v!none\endcsname{\Uabove} \defcsname\??fractionmethods\v!vertical \v!hidden \endcsname{\Uabovewithdelims \Udelimiter\zerocount\fam\scratchcounterone \Udelimiter\zerocount\fam\scratchcountertwo} \defcsname\??fractionmethods\v!vertical \v!auto \v!none\endcsname{\Uover} \defcsname\??fractionmethods\v!vertical \v!auto \endcsname{\Uoverwithdelims \Udelimiter\zerocount\fam\scratchcounterone \Udelimiter\zerocount\fam\scratchcountertwo} \defcsname\??fractionmethods\v!vertical \v!symbol \v!none\endcsname{\Ustretched \Udelimiter\zerocount\fam\scratchcounterthree} \defcsname\??fractionmethods\v!vertical \v!symbol \endcsname{\Ustretchedwithdelims \Udelimiter\zerocount\fam\scratchcounterone \Udelimiter\zerocount\fam\scratchcountertwo \Udelimiter\zerocount\fam\scratchcounterthree} \defcsname\??fractionmethods\v!horizontal \v!none\endcsname{\Uskewed \Udelimiter\zerocount\fam\scratchcounterthree \s!hfactor \numexpr\mathfractionparameter\c!hfactor\relax} \defcsname\??fractionmethods\v!horizontal \endcsname{\Uskewedwithdelims \Udelimiter\zerocount\fam\scratchcounterone \Udelimiter\zerocount\fam\scratchcountertwo \Udelimiter\zerocount\fam\scratchcounterthree \s!hfactor \numexpr\mathfractionparameter\c!hfactor\relax} \defcsname\??fractionmethods\v!line \v!none\endcsname{\Uskewed \Udelimiter\zerocount\fam\scratchcounterthree \s!noaxis \space \s!hfactor \numexpr\mathfractionparameter\c!hfactor\relax} \defcsname\??fractionmethods\v!line \endcsname{\Uskewedwithdelims \Udelimiter\zerocount\fam\scratchcounterone \Udelimiter\zerocount\fam\scratchcountertwo \Udelimiter\zerocount\fam\scratchcounterthree \s!noaxis \space \s!hfactor \numexpr\mathfractionparameter\c!hfactor\relax} \setupmathfractions % we now inherit ! [\c!topcolor=\mathfractionparameter\c!color, \c!bottomcolor=\mathfractionparameter\c!color, \c!rulecolor=\mathfractionparameter\c!color] \def\math_frac_command_u {\edef\p_method {\mathfractionparameter\c!method}% \edef\p_rule {\mathfractionparameter\c!rule}% \edef\p_thickness{\mathfractionparameter\c!rulethickness}% \scratchcounterone \mathfractionparameter\c!left \relax \scratchcountertwo \mathfractionparameter\c!right \relax \scratchcounterthree \mathfractionparameter\c!middle \relax \ifcsname \??fractionmethods \p_method \ifx\p_method\v!horizontal \orelse\ifx\p_method\v!line \orelse\ifcsname\??fractionmethods\p_method\p_rule\endcsname \p_rule \else \v!auto \fi \ifnum\scratchcounterone=\math_frac_no_delim \ifnum\scratchcountertwo=\math_frac_no_delim \v!none \fi \fi \endcsname \lastnamedcs \else \csname\??fractionmethods\v!vertical\v!auto\endcsname \fi \usedcolorparameterattributes{\mathfractionparameter\c!rulecolor}% was \c!color so we break compatibility ! thickness \ifx\p_thickness\v!font \zeropoint \s!font \space \else \dimexpr\p_thickness\relax \fi \s!class \math_class_by_parameter\mathfractionparameter\c!mathclass \s!vfactor \numexpr\mathfractionparameter\c!vfactor\relax \s!source \number\namedboxanchor{\mathfractionparameter\c!source}} \installcorenamespace{mathalignsimple} \defcsname\??mathalignsimple\v!right \endcsname#1{#1\hfill} \defcsname\??mathalignsimple\v!flushleft \endcsname#1{#1\hfill} \defcsname\??mathalignsimple\v!left \endcsname#1{\hfill#1} \defcsname\??mathalignsimple\v!flushright\endcsname#1{\hfill#1} \defcsname\??mathalignsimple\v!middle \endcsname#1{\hfill#1\hfill} \protected\def\math_frac_aligned_top{\begincsname\??mathalignsimple\mathfractionparameter\c!topalign \endcsname} \protected\def\math_frac_aligned_bot{\begincsname\??mathalignsimple\mathfractionparameter\c!bottomalign\endcsname} % \protected\def\math_frac_aligned_top{\begincsname\??mathalignsimple\mathfractionparameter\c!align\endcsname} % \protected\def\math_frac_aligned_bot{\begincsname\??mathalignsimple\mathfractionparameter\c!align\endcsname} \protected\defcsname\??mathfractionalternative\v!inner\endcsname#1#2% {%\beginmathgroup \math_frac_command_u {\dousecolorparameter{\mathfractionparameter\c!topcolor}% \math_fraction_margin_kern \usemathstyleparameter\mathfractionparameter\c!mathnumeratorstyle \m_fractions_strut_top\math_frac_aligned_top{#1}% \math_fraction_margin_kern}% {\dousecolorparameter{\mathfractionparameter\c!bottomcolor}% \math_fraction_margin_kern \usemathstyleparameter\mathfractionparameter\c!mathdenominatorstyle \m_fractions_strut_bot\math_frac_aligned_bot{#2}% \math_fraction_margin_kern}% %\endmathgroup \math_frac_wrapup} \protected\defcsname\??mathfractionalternative\v!outer\endcsname#1#2% {\beginmathgroup \usemathstyleparameter\mathfractionparameter\c!mathstyle \math_frac_command_u {\dousecolorparameter{\mathfractionparameter\c!topcolor}% \math_fraction_margin_kern \m_fractions_strut_top\math_frac_aligned_top{#1}% \math_fraction_margin_kern}% {\dousecolorparameter{\mathfractionparameter\c!bottomcolor}% \math_fraction_margin_kern \m_fractions_strut_bot\math_frac_aligned_bot{#2}% \math_fraction_margin_kern}% \endmathgroup \math_frac_wrapup} \protected\defcsname\??mathfractionalternative\v!both\endcsname#1#2% {\beginmathgroup \usemathstyleparameter\mathfractionparameter\c!mathstyle \math_frac_command_u {\dousecolorparameter{\mathfractionparameter\c!topcolor}% \math_fraction_margin_kern \usemathstyleparameter\mathfractionparameter\c!mathnumeratorstyle \m_fractions_strut_top\math_frac_aligned_top{#1}% \math_fraction_margin_kern}% {\dousecolorparameter{\mathfractionparameter\c!bottomcolor}% \math_fraction_margin_kern \usemathstyleparameter\mathfractionparameter\c!mathdenominatorstyle \m_fractions_strut_bot\math_frac_aligned_bot{#2}% \math_fraction_margin_kern}% \endmathgroup \math_frac_wrapup} \nulldelimiterspace\zeropoint % was 1.2pt \definemathfraction[xfrac] [\c!alternative=\v!inner,\c!mathstyle=\s!script] \definemathfraction[xxfrac][\c!alternative=\v!inner,\c!mathstyle=\s!scriptscript] \aliased\let\normalxfrac\xfrac \permanent\protected\def\xfrac#1#2{\normalxfrac{\enforced\let\xfrac\xxfrac#1}{\enforced\let\xfrac\xxfrac#2}} %D Spacing (sensitive for definition of \triggermathstyle: \permanent\protected\def\nomathfractiongaps {\normalexpanded{\math_no_fraction_gaps \allmathstyles}} \permanent\protected\def\overlaymathfractiongaps{\normalexpanded{\math_overlay_fraction_gaps\allmathstyles}} \protected\def\math_no_fraction_gaps#1% {\Umathfractionnumup #1\zeropoint \Umathfractiondenomdown#1\zeropoint} \protected\def\math_overlay_fraction_gaps#1% {\Umathfractionnumup #1\zeropoint \Umathfractionnumvgap #1\zeropoint \Umathfractiondenomvgap#1\zeropoint \Umathfractiondenomdown#1\zeropoint} \installcorenamespace{mathfractiondistance} \letcsname\??mathfractiondistance\v!none \endcsname\nomathfractiongaps \letcsname\??mathfractiondistance\v!no \endcsname\nomathfractiongaps \letcsname\??mathfractiondistance\v!overlay\endcsname\overlaymathfractiongaps \setupmathfractions [\c!distance=\v!none] % we need to keep it local, so not everybodyfont \appendtoks \edef\p_distance{\rootmathfractionparameter\c!distance}% \ifempty\p_distance\else \begincsname\??mathfractiondistance\p_distance\endcsname \fi \to \everymathematics % theshold is new! \let\math_fraction_set_threshold_inline \relax \let\math_fraction_set_threshold_display\relax \appendtoks \math_fraction_set_threshold_inline \math_fraction_set_threshold_display \to \everymathematics \appendtoks \ifempty\currentmathfraction \edef\p_threshold{\mathfractionparameter\c!inlinethreshold}% \ifempty\p_threshold \let\math_fraction_set_threshold_inline\math_fraction_set_threshold_inline_auto \orelse\ifx\p_threshold\v!auto \let\math_fraction_set_threshold_inline\math_fraction_set_threshold_inline_auto \else \let\math_fraction_set_threshold_inline\math_fraction_set_threshold_inline_ratio \fi \edef\p_threshold{\mathfractionparameter\c!displaythreshold}% \ifempty\p_threshold \let\math_fraction_set_threshold_display\math_fraction_set_threshold_display_auto \orelse\ifx\p_threshold\v!auto \let\math_fraction_set_threshold_display\math_fraction_set_threshold_display_auto \else \let\math_fraction_set_threshold_display\math_fraction_set_threshold_display_ratio \fi \fi \to \everysetupmathfraction \def\math_fraction_set_threshold_inline_auto {\Umathfractiondelsize\allmathstyles\maxdimen} \def\math_fraction_set_threshold_display_auto {\Umathfractiondelsize\alldisplaystyles\maxdimen} \def\math_fraction_set_threshold_inline_ratio {\edef\p_threshold{\mathfractionparameter\c!inlinethreshold}% \Umathfractiondelsize\alltextstyles \p_threshold\dimexpr\textface\relax \Umathfractiondelsize\allscriptstyles \p_threshold\dimexpr\scriptface\relax \Umathfractiondelsize\allscriptscriptstyles\p_threshold\dimexpr\scriptscriptface\relax} \def\math_fraction_set_threshold_display_ratio {\edef\p_threshold{\mathfractionparameter\c!displaythreshold}% \Umathfractiondelsize\alldisplaystyles\p_threshold\dimexpr\textface\relax} \setupmathfractions [\c!inlinethreshold=1.2, % no unit but fraction \c!displaythreshold=\v!auto, % no unit but fraction \c!threshold=.25\exheight] \appendtoks \Umathskeweddelimitertolerance\allmathstyles\mathfractionparameter\c!threshold \to \everymathematics % else original lost: \to \everybodyfont %D \macros %D {dfrac, tfrac, frac, dbinom, tbinom, binom} %D %D \startbuffer %D $\dfrac {1}{2} \tfrac {1}{2} \frac {1}{2}$ %D $\dbinom{1}{2} \tbinom{1}{2} \binom{1}{2}$ %D \stopbuffer %D %D \typebuffer %D \getbuffer % $$ % {{a}\over{b}} + % {{a}\overwithdelims(){b}} + % {{a}\atopwithdelims(){b}} + % {{a}\abovewithdelims()\zeropoint{b}} + % \left({{a}\over{b}}\right) % $$ % \dorecurse {10} { % weird % $$ {{a}\abovewithdelims()#1pt{b}} $$ % } \definemathfraction[i:frac] [\c!alternative=\v!inner,\c!mathstyle=\v!small] \definemathfraction[i:tfrac][\c!alternative=\v!inner,\c!mathstyle=\s!script] \definemathfraction[i:sfrac][\c!alternative=\v!inner,\c!mathstyle=\s!scriptscript] \definemathfraction[i:dfrac][\c!alternative=\v!inner,\c!mathstyle=\s!display] \definemathfraction[d:frac] [\c!alternative=\v!inner,\c!mathstyle=\s!cramped] \definemathfraction[d:tfrac][\c!alternative=\v!inner,\c!mathstyle={\s!cramped,\s!script}] \definemathfraction[d:sfrac][\c!alternative=\v!inner,\c!mathstyle={\s!cramped,\s!scriptscript}] \definemathfraction[d:dfrac][\c!alternative=\v!both,\c!mathstyle=\s!display] %D \protected\def\ShowMathFractions#1#2% %D {\dontleavehmode %D \begingroup %D \showmathstruts %D \mathematics{x+\tfrac{#1}{#2}+1+\frac{#1}{#2}+2+\sfrac{#1}{#2}+g}% %D \endgroup} %D %D The default \type {tfrac}, \type {frac} and \type \sfrac} look like this: %D %D \blank %D \ShowMathFractions{a}{a}\par %D \ShowMathFractions{1}{x}\par %D \ShowMathFractions{a}{b}\par %D \ShowMathFractions{1}{b}\par %D \blank % % There is no real need to support ams styling so this is now obsolete: \permanent\protected\def\frac {\csname\inlineordisplaymath id:frac\endcsname} \permanent\protected\def\tfrac{\csname\inlineordisplaymath id:tfrac\endcsname} \permanent\protected\def\sfrac{\csname\inlineordisplaymath id:sfrac\endcsname} \permanent\protected\def\dfrac{\csname\inlineordisplaymath id:dfrac\endcsname} % \definemathfraction[ams] [\c!strut=\v!no,\c!alternative=\v!outer] % \definemathfraction[i:ams:frac][ams][\c!mathstyle={\s!cramped,\s!text}] % \definemathfraction[d:ams:frac][ams][\c!mathstyle={\s!cramped,\s!display}] % % \permanent\protected\def\ctxfrac{\csname\inlineordisplaymath id:frac\endcsname} % \permanent\protected\def\amsfrac{\csname\inlineordisplaymath id:ams:frac\endcsname} % % \appendtoks % \doifelse{\mathematicsparameter\c!fractions}{ams}% % {\enforced\let\frac\amsfrac}% % {\enforced\let\frac\ctxfrac}% % \to \everysetupmathematics % % Also gone: % % \definemathfraction[ddfrac][\c!mathstyle=\s!display] % \definemathfraction[ttfrac][\c!mathstyle=\s!text] % \definemathfraction[ssfrac][\c!mathstyle=\s!script] % % \protected\def\binom #1#2{{\Ustack {{#1}\normalabovewithdelims()\zeropoint{#2}}}} % \protected\def\dbinom#1#2{{\displaystyle{{#1}\normalabovewithdelims()\zeropoint{#2}}}} % \protected\def\tbinom#1#2{{\textstyle {{#1}\normalabovewithdelims()\zeropoint{#2}}}} % % \definemathfraction % [binom] % [\c!alternative=\v!outer, % \c!rule=\v!no, % \c!left="28, % \c!right="29, % \c!mathstyle=\s!auto] % % \definemathfraction % [dbinom] % [binom] % [\c!mathstyle=\s!display] % % \definemathfraction % [tbinom] % [binom] % [\c!mathstyle=\s!text] \definemathfraction [d:binom] [d:frac] [\c!rule=\v!no, % \c!mathstyle=\s!display, \c!left="28, \c!right="29] \definemathfraction [i:binom] [i:frac] [\c!rule=\v!no, %\c!mathstyle=\s!text, \c!left="28, \c!right="29] \permanent\protected\def\binom{\csname\inlineordisplaymath id:binom\endcsname} \definemathfraction [dbinom] [d:binom] [\c!mathstyle=\s!display] \definemathfraction [tbinom] [i:binom] [\c!mathstyle=\s!text] %D \macros %D {cfrac} %D %D \startbuffer %D $\cfrac{12}{3} \cfrac[l]{12}{3} \cfrac[c]{12}{3} \cfrac[r]{12}{3}$ %D $\cfrac{1}{23} \cfrac[l]{1}{23} \cfrac[c]{1}{23} \cfrac[r]{1}{23}$ %D \stopbuffer %D %D \typebuffer %D %D \getbuffer %D %D Now we can align every combination we want: %D %D \startbuffer %D $\cfrac{12}{3} \cfrac[l]{12}{3} \cfrac[c]{12}{3} \cfrac[r]{12}{3}$ %D $\cfrac{1}{23} \cfrac[l]{1}{23} \cfrac[c]{1}{23} \cfrac[r]{1}{23}$ %D $\cfrac[cl]{12}{3} \cfrac[cc]{12}{3} \cfrac[cr]{12}{3}$ %D $\cfrac[lc]{1}{23} \cfrac[cc]{1}{23} \cfrac[rc]{1}{23}$ %D \stopbuffer %D %D \typebuffer %D %D \getbuffer % % we forget about this ams one ... no one uses it anyway % % \permanent\protected\def\cfrac % {\doifelsenextoptionalcs\math_cfrac_yes\math_cfrac_nop} % % \def\math_cfrac_nop {\math_cfrac_indeed[cc]} % \def\math_cfrac_yes[#1]{\math_cfrac_indeed[#1cc]} % % \def\math_cfrac_indeed[#1#2#3]#4#5% % {{\displaystyle % \frac % {\strut % \ifx r#1\hfill\fi#4\ifx l#1\hfill\fi}% % {\ifx r#2\hfill\fi#5\ifx l#2\hfill\fi}% % \ifzeropt\nulldelimiterspace\else % \kern-\nulldelimiterspace % \fi}} % % instead we predefine one: \definemathfraction [cfrac] [\c!mathstyle=\v!text] % so users can do this: % % \setupmathfraction % [cfrac] % [topalign=flushright] % % or define an child instance that presets it. %D \macros %D {splitfrac, splitdfrac} %D %D Occasionally one needs to typeset multi||line fractions. These commands use \type %D {\genfrac} to create such fractions. %D %D \startbuffer %D \startformula %D a=\frac{ %D \splitfrac{xy + xy + xy + xy + xy} %D {+ xy + xy + xy + xy} %D } %D {z} %D =\frac{ %D \splitdfrac{xy + xy + xy + xy + xy} %D {+ xy + xy + xy + xy} %D } %D {z} %D \stopformula %D \stopbuffer %D %D \typebuffer \getbuffer \defcsname\??mathalignsimple\v!split:\v!flushleft\endcsname#1% {#1% \ifchkdim\mathfractionparameter\c!distance\or\hskip\lastchkdim\fi \hfill} \defcsname\??mathalignsimple\v!split:\v!flushright\endcsname#1% {\hfill \ifchkdim\mathfractionparameter\c!distance\or\hskip\lastchkdim\fi \mathatom \s!class \mathordcode \s!unroll {}% prevents +/- seen as sign, unroll prevents empty box #1} \definemathfraction [splitfrac] [\c!mathnumeratorstyle=\v!text, \c!mathdenominatorstyle=\v!text, \c!topalign=\v!split:\v!flushleft, \c!bottomalign=\v!split:\v!flushright, \c!distance=\emwidth, \c!rule=\v!no] \definemathfraction [splitdfrac] [splitfrac] [\c!mathnumeratorstyle=\v!display, \c!mathdenominatorstyle=\v!display] %D More fracking (for Alan): % \appendtoks % \Umathskewedfractionhgap\allmathstyles\namedmathfractionparameter\s!vfrac\c!hfactor\fontemwidth \mathstylefont\textstyle % \Umathskewedfractionvgap\allmathstyles\namedmathfractionparameter\s!vfrac\c!vfactor\fontexheight\mathstylefont\textstyle % \to \everymathematics \definemathfraction [\v!horizontal] [\c!method=\v!horizontal] \definemathfraction [\s!vfrac] [\v!horizontal] [\c!hfactor=20, \c!vfactor=10] %D And a cheat (for Mikael): % \definemathfraction % [afrac] % [\c!mathclass=\mathrelationcode, % \c!rule=\v!symbol, % \c!middle="2192] %D New stretched fraction with middle symnbol: % \enableexperiments[math.arrows] % enforce construction of these in math-act % % { % tweak = "addarrows", % list = { [0x3D] = { squeeze = .85, yoffset = .0975 } } -- bonum % }, \definemathfraction [relfraction] [\c!mathclass=\mathrelationcode, \c!margin=.25\emwidth, \c!rule=\v!symbol] \definemathfraction [bartext] [relfraction] [\c!middle="203E] \definemathfraction [leftarrowtext] [relfraction] [\c!middle="2190] \definemathfraction [rightarrowtext] [relfraction] [\c!middle="2192] \definemathfraction [twoheadleftarrowtext] [relfraction] [\c!middle="219E] \definemathfraction [twoheadrightarrowtext] [relfraction] [\c!middle="21A0] \definemathfraction [reltext] [relfraction] [\c!middle="002D] \definemathfraction [equaltext] [relfraction] [\c!middle="003D] \definemathfraction [mapstotext] [relfraction] [\c!middle="21A6] \definemathfraction [hookleftarrowtext] [relfraction] [\c!middle="21A9] \definemathfraction [hookrightarrowtext] [relfraction] [\c!middle="21AA] \definemathfraction [leftharpoondowntext] [relfraction] [\c!middle="21BD] \definemathfraction [leftharpoonuptext] [relfraction] [\c!middle="21BC] \definemathfraction [rightharpoondowntext] [relfraction] [\c!middle="21C1] \definemathfraction [rightharpoonuptext] [relfraction] [\c!middle="21C0] \definemathfraction [rightoverleftarrowtext] [relfraction] [\c!middle="21C4] \definemathfraction [leftrightharpoonstext] [relfraction] [\c!middle="21CB] \definemathfraction [rightleftharpoonstext] [relfraction] [\c!middle="21CC] \definemathfraction [triplereltext] [relfraction] [\c!middle="2261] \definemathfraction [leftrightarrowtext] [relfraction] [\c!middle="27F7] \definemathfraction [rightleftarrowtext] [relfraction] [\c!middle="27F7] \definemathfraction [Leftarrowtext] [relfraction] [\c!middle="27F8] \definemathfraction [Rightarrowtext] [relfraction] [\c!middle="27F9] \definemathfraction [Leftrightarrowtext] [relfraction] [\c!middle="27FA] \definemathfraction [Rightleftarrowtext] [relfraction] [\c!middle="27FA] \protect \endinput % I have no clue what \mthfrac and \mthsqrt are supposed to do but % I guess that it can be done with tweaking luatex's math parameters. % Otherwise I'll write something from scratch. % \def\math_stylebuilders_frac#1#2#3#4#5#6#7% % {\begingroup % \mathsurround\zeropoint % \setbox0\hbox{$#1 #6$}% % \setbox2\hbox{$#1 #7$}% % \dimen0\wd\ifdim\wd2>\wd0 2\else 0\fi % \setbox4\hbox to \dimen0{\leaders\hbox{#4}\hss#5}% % \mathord{\vcenter{{\offinterlineskip % \hbox to \dimen0{\hss\box0\hss}% % \kern\ht4% % \hbox to \dimen0{\hss\copy4\hss}% % \kern\ht4% % \hbox to \dimen0{\hss\box2\hss}}}}% % \endgroup} % % \def\math_stylebuilders_sqrt#1#2#3#4#5% % {\begingroup % \mathsurround\zeropoint % \setbox0\hbox{$#1 #5$}% % \ht0\dimexpr1.05\ht0+\onepoint\relax % \dp0\dimexpr1.05\dp0+\onepoint\relax % \setbox4\hbox to \wd0{\mr#2\leaders\hbox{#3}\hfill#4}% % \delimitershortfall\zeropoint % \nulldelimiterspace\zeropoint % \setbox2\hbox{$\left\delimiter"0270370 \vrule \s!height\ht0 \s!depth \dp0 \s!width\zeropoint\right.$}% is this the right code point? % \mathord{\vcenter{\hbox{\copy2\rlap{\raise\dimexpr\ht2-\ht4\relax\copy4}\copy0}}}% % \endgroup} % % \def\mthfrac#1#2#3#4#5{\mathchoice % {\math_stylebuilders_frac\displaystyle \textface {#1}{#2}{#3}{#4}{#5}}% % {\math_stylebuilders_frac\textstyle \textface {#1}{#2}{#3}{#4}{#5}}% % {\math_stylebuilders_frac\scriptstyle \scriptface {#1}{#2}{#3}{#4}{#5}}% % {\math_stylebuilders_frac\scriptscriptstyle\scriptscriptface{#1}{#2}{#3}{#4}{#5}}} % % \def\mthsqrt#1#2#3{\mathchoice % {\math_stylebuilders_sqrt\displaystyle \textface{#1}{#2}{#3}}% % {\math_stylebuilders_sqrt\textstyle \textface{#1}{#2}{#3}}% % {\math_stylebuilders_sqrt\scriptstyle \textface{#1}{#2}{#3}}% % {\math_stylebuilders_sqrt\scriptscriptstyle\textface{#1}{#2}{#3}}} % \protected\def\mthfrac#1#2#3{[mthfrac: #1 #2 #3]} % \protected\def\mthsqrt#1#2#3{[mthsqrt: #1 #2 #3]} % used for prototyping \Uskewed % % \protected\def\skewedfractiona#1#2{% % \raise % \Umathskewedfractionvgap\textstyle % \hbox\bgroup % $\scriptstyle#1\hskip\dimexpr\Umathskewedfractionhgap\scriptstyle/2\relax$% % \egroup % \hbox to \zeropoint\bgroup % \hss$\textstyle/$\hss % \egroup % \lower % \Umathskewedfractionvgap\textstyle % \hbox\bgroup % $\hskip\dimexpr\Umathskewedfractionhgap\scriptstyle/2\relax\scriptstyle#2$% % \egroup % } % % \protected\def\skewedfractionb#1#2{% % \raise % \Umathskewedfractionvgap\textstyle % \hbox\bgroup % $\scriptstyle#1\hskip\dimexpr\Umathskewedfractionhgap\textstyle/2\relax$% % \egroup % \hbox to \zeropoint\bgroup % \hss$\textstyle/$\hss % \egroup % \lower % \Umathskewedfractionvgapskewedfractionvgap\textstyle % \hbox\bgroup % $\hskip\dimexpr\Umathskewedfractionhgap\textstyle/2\relax\scriptstyle#2$% % \egroup % } % % $\skewedfractiona{1}{2}$ % $\skewedfractionb{1}{2}$