diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/math-ali.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/math-ali.mkiv | 816 |
1 files changed, 564 insertions, 252 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/math-ali.mkiv b/Master/texmf-dist/tex/context/base/mkiv/math-ali.mkiv index ebb20e33e31..49a343ba0b6 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/math-ali.mkiv +++ b/Master/texmf-dist/tex/context/base/mkiv/math-ali.mkiv @@ -25,26 +25,28 @@ %D Modules may provide additional alignment features. The following %D mechanisms are provided by the core. +% why all these spans + % n>1 ### needed, strange # interaction in recurse -\newtoks\c_math_align_a -\newtoks\c_math_align_b -\newtoks\c_math_align_c +\newtoks\t_math_align_a +\newtoks\t_math_align_b +\newtoks\t_math_align_c \def\displayopenupvalue{.25\bodyfontsize} \def\math_build_eqalign {\scratchtoks\emptytoks \dorecurse{\mathalignmentparameter\c!m}\math_build_eqalign_step - \normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_c}}} + \normalexpanded{\scratchtoks{\the\scratchtoks\the\t_math_align_c}}} -\def\math_build_eqalign_step +\unexpanded\def\math_build_eqalign_step % make sure no expansion in tracing {\ifnum\recurselevel>\plusone \scratchtoks\expandafter{\the\scratchtoks\tabskip\mathalignmentparameter\c!distance\aligntab\tabskip\zeropoint}% \fi - \normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_a}}% + \normalexpanded{\scratchtoks{\the\scratchtoks\the\t_math_align_a}}% \dorecurse{\numexpr\mathalignmentparameter\c!n-\plusone\relax} - {\normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_b}}}} + {\normalexpanded{\scratchtoks{\the\scratchtoks\the\t_math_align_b}}}} \def\math_math_in_eqalign#1% {\startforceddisplaymath @@ -83,70 +85,141 @@ % use zeroskipplusfill -% i really need to redo this eqno mess ... in lua - \def\math_prepare_r_eqalign_no - {\c_math_align_a{\strut\math_first_in_eqalign\hfil\math_left_of_equalign\span\math_math_in_eqalign{\alignmark\alignmark}\math_right_of_eqalign\tabskip\zeropoint}% - \c_math_align_b{\aligntab\math_next_in_eqalign\math_left_of_equalign\span\math_math_in_eqalign{\alignmark\alignmark}\math_right_of_eqalign\tabskip\zeropoint}% + {\t_math_align_a + {\strut + \tabskip\zeropoint + \alignmark\alignmark % for picking up the number + \aligntab + \math_first_in_eqalign + \hfil + \math_left_of_equalign + \span + \math_math_in_eqalign{\alignmark\alignmark}% + \math_right_of_eqalign + \tabskip\zeropoint}% + \t_math_align_b + {\aligntab + \math_next_in_eqalign + \math_left_of_equalign + \span + \math_math_in_eqalign{\alignmark\alignmark}% + \math_right_of_eqalign + \tabskip\zeropoint}% \ifnum\mathraggedstatus=\plusone - \c_math_align_c{\hfil\aligntab\span\math_text_in_eqalign{\alignmark\alignmark}\tabskip\zeropoint}% + \t_math_align_c + {\hfil + \aligntab + \span + \math_text_in_eqalign{\alignmark\alignmark}% + \tabskip\zeropoint}% \else\ifnum\mathraggedstatus=\plusthree - \c_math_align_c{\hfil\tabskip\zeropoint\s!plus 1\s!fill\aligntab\span\math_text_in_eqalign{\alignmark\alignmark}\tabskip\zeropoint}% + \t_math_align_c + {\hfil + \tabskip\zeropoint\s!plus 1\s!fill + \aligntab + \span + \math_text_in_eqalign{\alignmark\alignmark}% + \tabskip\zeropoint}% \else - \c_math_align_c{\hfil\tabskip\centering\aligntab\llap{\span\math_text_in_eqalign{\alignmark\alignmark}}\tabskip\zeropoint}% + \t_math_align_c + {\hfil + \tabskip\centering + \aligntab + \span + \llap{\math_text_in_eqalign{\alignmark\alignmark}}% + \tabskip\zeropoint}% \fi\fi - \global\mathnumberstatus\zerocount \math_build_eqalign \the\mathdisplayaligntweaks \tabskip\centering} \def\math_prepare_l_eqalign_no % \checkeddisplaymath - {\c_math_align_a{\strut\math_first_in_eqalign\hfil\math_left_of_equalign\span\math_math_in_eqalign{\alignmark\alignmark}\math_right_of_eqalign\tabskip\zeropoint}% - \c_math_align_b{\aligntab\math_next_in_eqalign\math_left_of_equalign\span\math_math_in_eqalign{\alignmark\alignmark}\math_right_of_eqalign\tabskip\zeropoint}% - % problem: number is handled after rest and so ends up in the margin + {\t_math_align_a + {\strut + \tabskip\zeropoint + \alignmark\alignmark % for picking up the number + \aligntab + \math_first_in_eqalign + \hfil + \math_left_of_equalign + \span + \math_math_in_eqalign{\alignmark\alignmark}% + \math_right_of_eqalign + \tabskip\zeropoint}% + \t_math_align_b + {\aligntab + \math_next_in_eqalign + \math_left_of_equalign + \span + \math_math_in_eqalign{\alignmark\alignmark}% + \math_right_of_eqalign + \tabskip\zeropoint}% \ifnum\mathraggedstatus=\plusone - \c_math_align_c{\hfil\aligntab\kern-\displaywidth\rlap{\span\math_text_in_eqalign{\alignmark\alignmark}}\tabskip\displaywidth}% + \t_math_align_c + {\hfil + \aligntab + \kern-\displaywidth + \span + \rlap{\math_text_in_eqalign{\alignmark\alignmark}}% + \tabskip\displaywidth}% \else\ifnum\mathraggedstatus=\plusthree - \c_math_align_c{\hfil\tabskip\zeropoint\s!plus 1\s!fill\aligntab\kern-\displaywidth\span\math_rlap{\span\math_text_in_eqalign{\alignmark\alignmark}}\tabskip\displaywidth}% + \t_math_align_c + {\hfil + \tabskip\zeropoint\s!plus 1\s!fill + \aligntab + \kern-\displaywidth + \span + \math_rlap{\math_text_in_eqalign{\alignmark\alignmark}}% + \tabskip\displaywidth}% \else - \c_math_align_c{\hfil\tabskip\centering\aligntab\kern-\displaywidth\rlap{\span\math_text_in_eqalign{\alignmark\alignmark}}\tabskip\displaywidth}% + \t_math_align_c + {\hfil + \tabskip\centering + \aligntab + \kern-\displaywidth + \span + \rlap{\math_text_in_eqalign{\alignmark\alignmark}}% + \tabskip\displaywidth}% \fi\fi - \global\mathnumberstatus\zerocount \math_build_eqalign \the\mathdisplayaligntweaks \tabskip\centering} +\def\math_halign_checked + {\halign \ifcase\eqalignmode \or to \checkeddisplaywidth \fi} + \def\math_both_eqalign_no_normal#1#2% {\ifmmode - \the\mathdisplayaligntweaks % \let\strc_formulas_place_number\relax % strange hack + \the\mathdisplayaligntweaks \vcenter\bgroup \let\math_finish_eqalign_no\egroup \else \let\math_finish_eqalign_no\relax \fi #1% - \halign \ifcase\eqalignmode \or to \checkeddisplaywidth \fi \expandafter {\the\scratchtoks\crcr#2\crcr}% + \math_halign_checked\expandafter\bgroup\the\scratchtoks\crcr#2\crcr\egroup \math_finish_eqalign_no} \def\math_both_eqalign_no_aligned#1% {\ifmmode - \the\mathdisplayaligntweaks - \global\mathnumberstatus\plusone - \ifcase\mathraggedstatus + \the\mathdisplayaligntweaks + \global\mathnumberstatus\plusone + \ifcase\mathraggedstatus \def\math_finish_eqalign_no{\crcr\egroup}% - \else + \else % we're in a mathbox \vcenter\bgroup \def\math_finish_eqalign_no{\crcr\egroup\egroup}% - \fi + \fi \fi #1% - \halign \ifcase\eqalignmode \or to \checkeddisplaywidth \fi \expandafter \bgroup\the\scratchtoks\crcr} + \math_halign_checked\expandafter\bgroup\the\scratchtoks\crcr} \def\math_rlap#1% {\setbox\scratchbox\hbox{#1}% - \ifdim\wd\scratchbox>\mathnumbercorrection - \xdef\mathnumbercorrection{\the\wd\scratchbox}% + \ifdim\wd\scratchbox>\d_math_number_correction + \global\d_math_number_correction\wd\scratchbox \fi \box\scratchbox \global\mathnumberstatus\plustwo} @@ -157,12 +230,9 @@ \def\math_handle_eqalign_no_l_aligned{\math_both_eqalign_no_aligned\math_prepare_l_eqalign_no} \def\math_finish_eqalign_no {\crcr\egroup} -\let \reqalignno \math_handle_eqalign_no_r_normal -\let \leqalignno \math_handle_eqalign_no_l_normal -\let\alignreqalignno \math_handle_eqalign_no_r_aligned -\let\alignleqalignno \math_handle_eqalign_no_l_aligned -\let \eqalignno \math_handle_eqalign_no_r_normal -\let \aligneqalignno \math_handle_eqalign_no_r_aligned +\let\reqalignno\relax +\let\leqalignno\relax +\let\eqalignno \relax %D Here we implement the user interface part. We start with basic math alignments: @@ -170,26 +240,28 @@ \newtoks \everymathalignment -\def\math_alignment_NR_indeed[#1][#2]% - {\strc_formulas_place_number_nested{#1}{#2}% to be tagged (better an attribute) +\def\math_alignment_NC_first#1\NR + {\glet\math_alignment_NC\math_alignment_NC_rest + \scratchtoks{\math_number_left_of_eqalign\aligntab#1\NR}% \math_number_left_of_eqalign not used yet + \dodoubleempty\math_alignment_NC_first_indeed} + +\def\math_alignment_NC_first_indeed[#1][#2]% + {\strc_formulas_place_number_nested{#1}{#2}\the\scratchtoks} + +\def\math_alignment_NR + {\aligntab + \dostoptagged % finish cell + \math_number_right_of_eqalign \crcr \dostoptagged % finish row \noalign{\glet\math_alignment_NC\math_alignment_NC_first}} % noalign used for change state, conditional does not work here -\def\math_alignment_NC_first - {\glet\math_alignment_NC\math_alignment_NC_rest} - \def\math_alignment_NC_rest {\aligntab} \def\math_alignment_EQ {\NC=} -\def\math_alignment_NR - {\aligntab - \dostoptagged % finish cell - \dodoubleempty\math_alignment_NR_indeed} % use xx from tabulate - \appendtoks \glet\math_alignment_NC\math_alignment_NC_first \unexpanded\def\NC{\math_alignment_NC}% messy, due to lookahead (we cannot use a flag) @@ -227,7 +299,7 @@ \the\everymathalignment \c_math_eqalign_column\zerocount \processcommacommand - [\mathalignmentparameter\c!align] + [\mathalignmentparameter\c!align]% {\advance\c_math_eqalign_column\plusone\math_eqalign_set_column}% takes argument \global\c_math_eqalign_column\plusone \dostarttagged\t!math\empty @@ -311,15 +383,33 @@ \def\math_left_of_equalign {\ifcsname\??mathalignmentvariant\number\c_math_eqalign_column\endcsname - \ifcase\csname\??mathalignmentvariant\number\c_math_eqalign_column\endcsname\or - \relax \or \hfill \or \hfill - \fi + \ifcase\lastnamedcs \or \relax \or \hfill \or \hfill \fi \fi} \def\math_right_of_eqalign {\ifcsname\??mathalignmentvariant\number\c_math_eqalign_column\endcsname - \ifcase\csname\??mathalignmentvariant\number\c_math_eqalign_column\endcsname\or - \hfill \or \relax \or \hfill + \ifcase\lastnamedcs \or \hfill \or \relax \or \hfill \fi + \fi} + +\newconditional\c_math_alignment_local_number % not used but when true puts in front (todo) + +\def\math_number_right_of_eqalign + {\ifcase\wd\b_strc_formulas_number\else + \ifconditional\c_math_alignment_local_number + \ifcase\c_strc_math_number_location\or\or + \box\b_strc_formulas_number + \fi + \else + \box\b_strc_formulas_number + \fi + \fi} + +\def\math_number_left_of_eqalign + {\ifcase\wd\b_strc_formulas_number\else + \ifconditional\c_math_alignment_local_number + \ifcase\c_strc_math_number_location\or + \box\b_strc_formulas_number + \fi \fi \fi} @@ -677,8 +767,10 @@ \def\math_matrix_stop {\crcr - \mathstrut\crcr - \noalign{\kern-\baselineskip}% + % \ifgridsnapping \else + \mathstrut\crcr + \noalign{\vskip-\baselineskip}% + % \fi \egroup \popmacro\math_matrix_NC \egroup @@ -689,19 +781,19 @@ \definemathmatrix[\v!mathmatrix] \def\math_matrix_prepare - {\c_math_align_a{\strut\math_first_in_eqalign\math_left_of_equalign\span + {\t_math_align_a{\strut\math_first_in_eqalign\math_left_of_equalign\span \math_text_in_eqalign{\mathmatrixparameter\c!style\alignmark\alignmark}\math_right_of_eqalign}% - \c_math_align_b{\aligntab\hskip\mathmatrixparameter\c!distance + \t_math_align_b{\aligntab\hskip\mathmatrixparameter\c!distance \math_next_in_eqalign\math_left_of_equalign\span \math_text_in_eqalign{\mathmatrixparameter\c!style\alignmark\alignmark}\math_right_of_eqalign}% - \c_math_align_c{\aligntab\aligntab\hskip\mathmatrixparameter\c!distance + \t_math_align_c{\aligntab\aligntab\hskip\mathmatrixparameter\c!distance \math_left_of_equalign\span \math_text_in_eqalign{\mathmatrixparameter\c!style\alignmark\alignmark}\math_right_of_eqalign}% \scratchtoks\emptytoks - \normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_a}}% + \normalexpanded{\scratchtoks{\the\scratchtoks\the\t_math_align_a}}% \dorecurse{\numexpr\scratchcounter-\plusone\relax} - {\normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_b}}}% - \normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_c}}% + {\normalexpanded{\scratchtoks{\the\scratchtoks\the\t_math_align_b}}}% + \normalexpanded{\scratchtoks{\the\scratchtoks\the\t_math_align_c}}% \halign \expandafter \bgroup\the\scratchtoks \crcr} \unexpanded\def\math_matrix_NC_indeed @@ -1023,9 +1115,8 @@ %D The following code comes from \type {math-str.mkiv}. %D -%D Here we implement a basic math alignment mechanism. Numbers -%D are also handled. The macros \type {\startinnermath} and -%D \type {\stopinnermath} can be overloaded in specialized +%D Here we implement a basic math alignment mechanism. Numbers are also handled. The macros +%D \type {\startinnermath} and \type {\stopinnermath} can be overloaded in specialized %D modules. \installcorenamespace{mathinnerstart} @@ -1052,223 +1143,444 @@ \newconstant\mathraggedstatus % normal left center right \newconstant\mathnumberstatus % nothing normal shift_right -\let\mathnumbercorrection\!!zeropoint - -\let\math_the_r_eq_no\empty -\let\math_the_l_eq_no\empty - -\unexpanded\def\startmathbox#1% - {\hsize\displaywidth % \checkeddisplaymath - \global\mathnumberstatus\plusone - \mathraggedstatus#1\relax - \let\mathnumbercorrection\!!zeropoint - \global\let\math_the_r_eq_no\empty - \global\let\math_the_l_eq_no\empty - \def\reqno{\gdef\math_the_r_eq_no}% - \def\leqno{\gdef\math_the_l_eq_no}% - \let\eqno\reqno - % added - \let\normalreqno\reqno - \let\normalleqno\leqno - \let\normaleqno \eqno - % added - \strc_formulas_place_number - \setbox\scratchbox\math_hbox to \displaywidth\bgroup % \checkeddisplaymath - \mathinnerstrut - \startforceddisplaymath - \ifcase\mathraggedstatus\or\hfill\or\hfill\fi} +\newdimen\d_math_number_correction \def\math_box_llapped_math_no {\ifcase\mathraggedstatus\or - \math_the_r_eq_no + \box\b_strc_formulas_number \or - \llap{\math_the_r_eq_no}% + \llap{\box\b_strc_formulas_number}% \or - \llap{\math_the_r_eq_no}% + \llap{\box\b_strc_formulas_number}% \fi} \def\math_box_rlapped_math_no {\ifcase\mathraggedstatus\or - \rlap{\math_the_l_eq_no}% + \rlap{\box\b_strc_formulas_number}% \or - \rlap{\math_the_l_eq_no}% + \rlap{\box\b_strc_formulas_number}% \or - \math_the_l_eq_no + \box\b_strc_formulas_number + \fi} + +\newconditional\c_strc_math_has_number +\newconditional\c_strc_math_display_overflow +\newconstant \c_strc_math_number_location +\newdimen \d_strc_math_number_width +\newdimen \d_strc_math_display_width +\newbox \b_strc_math_display +\newconstant \c_strc_formulas_frame_mode + +\let\d_strc_math_framed_width\displaywidth + +\setvalue{\??formulaoption\v!frame}% + {\edef\p_frame{\formulaparameter\c!frame}% + \ifx\p_frame\v!number + \c_strc_formulas_frame_mode\plustwo % inside frame + \else + \c_strc_formulas_frame_mode\plusone % outside frame + \fi} + +% mode: 0=no frame | 1=number inside frame | 2=number outside frame + +\def\strc_math_flush_aligned + {\ifcase\mathraggedstatus\or\hfill\or\hfill\fi + \box\b_strc_math_display + \ifcase\mathraggedstatus\or\or\hfill\or\hfill\fi} + +\def\strc_math_flush_box_normal + {\hbox to \displaywidth\bgroup + \strc_math_flush_aligned + \egroup} + +\def\strc_math_flush_box_framed_common + {\setformulaframedparameter\c!align{\formulaparameter\c!align}% + \letformulaframedparameter\c!strut\v!no + \d_framed_formula\ht\b_strc_math_display + \ifcase\mathraggedstatus\or\hfill\or\hfill \fi + \inheritedformulaframedframed{\box\b_strc_math_display}% + \ifcase\mathraggedstatus\or \or\hfill\or\hfill\fi} + +% \def\strc_math_flush_box_framed_inline +% {\letformulaframedparameter\c!location\empty +% \letformulaframedparameter\c!width\displaywidth +% \strc_math_flush_box_framed_common} + +\def\strc_math_flush_box_framed_display + {\let\currentformulaframed\currentformula + \letformulaframedparameter\c!location\v!formula + \setformulaframedparameter\c!width{\d_strc_math_framed_width}% + \strc_math_flush_box_framed_common} + +\def\strc_math_flush_box_framed_fit_inline + {\let\currentformulaframed\currentformula + \letformulaframedparameter\c!location\empty + \letformulaframedparameter\c!width\v!fit + \strc_math_flush_box_framed_common} + +\def\strc_math_flush_box_framed_fit_display + {\let\currentformulaframed\currentformula + \letformulaframedparameter\c!location\v!formula + \letformulaframedparameter\c!width\v!fit + \strc_math_flush_box_framed_common} + +% combiners + +\def\strc_math_flush_box + {\ifcase\c_strc_formulas_frame_mode + \strc_math_flush_box_normal + \else + \strc_math_flush_box_framed_display + \fi} + +\def\strc_math_number_right_normal + {\strc_math_flush_aligned + \hss % hss makes room for number + \math_box_llapped_math_no} + +\def\strc_math_number_left_normal + {\math_box_rlapped_math_no + \strc_math_flush_aligned + \hss} % hss makes room for number + +\def\strc_math_number_right_normal_outside + {\ifconditional\c_strc_formulas_tight + \strc_math_flush_box_framed_fit_display + \else + \strc_math_flush_box_framed_display + \fi + \hss % hss makes room for number + \math_box_llapped_math_no} + +\def\strc_math_number_left_normal_outside + {\math_box_rlapped_math_no + \hss % hss makes room for number + \ifconditional\c_strc_formulas_tight + \strc_math_flush_box_framed_fit_display + \else + \strc_math_flush_box_framed_display + \fi} + +\def\strc_math_number_right_normal_inside + {\setbox\b_strc_math_display\hpack to \dimexpr\displaywidth-\d_framed_locator_lo-\d_framed_locator_ro\relax\bgroup + \strc_math_flush_aligned + \hss + \math_box_llapped_math_no + \egroup + \strc_math_flush_box_framed_fit_inline} + +\def\strc_math_number_left_normal_inside + {\setbox\b_strc_math_display\hpack to \dimexpr\displaywidth-\d_framed_locator_lo-\d_framed_locator_ro\relax\bgroup + \math_box_rlapped_math_no + \hss + \strc_math_flush_aligned + \egroup + \strc_math_flush_box_framed_fit_inline} + +\def\strc_math_number_right_overflow + {\vpack\bgroup + \strc_math_flush_box + \par + \hpack to \displaywidth\bgroup + \hss + \math_box_llapped_math_no + \egroup + \egroup} + +\def\strc_math_number_left_overflow + {\vpack\bgroup + \hpack to \displaywidth\bgroup + \math_box_rlapped_math_no + \hss + \egroup + \strc_math_flush_box + \egroup} + +\def\strc_math_number_right_overflow_outside + {\vpack\bgroup + \strc_math_flush_box_framed_fit_inline +% \hskip\zeropoint % nicely breaks the line without introducing funny vertical spacing ... why o why + \hpack to \displaywidth\bgroup + \hss + \math_box_llapped_math_no + \egroup + \egroup} + +\def\strc_math_number_left_overflow_outside + {\vpack\bgroup + \hpack to \dimexpr\displaywidth-\d_framed_locator_lo\relax\bgroup + \math_box_rlapped_math_no + \hss + \egroup + \hskip\zeropoint % nicely breaks the line without introducing funny vertical spacing ... why o why + \strc_math_flush_box_framed_fit_inline + \egroup} + +\def\strc_math_number_right_overflow_inside + {\setbox\b_strc_math_display\vpack\bgroup + \box\b_strc_math_display + \hpack to \displaywidth\bgroup + \hss + \math_box_llapped_math_no + \hskip\d_framed_locator_ro + \egroup + \egroup + \strc_math_flush_box_framed_fit_inline} + +\def\strc_math_number_left_overflow_inside + {\setbox\b_strc_math_display\vpack\bgroup + \hpack to \displaywidth\bgroup + % \hskip\d_framed_locator_lo + \math_box_rlapped_math_no + \hss + \egroup + \box\b_strc_math_display + \egroup + \strc_math_flush_box_framed_fit_inline} + +% checkers + +\def\strc_math_number_check + {\d_strc_math_display_width\wd\b_strc_math_display + \ifconditional\c_strc_formulas_tight + \ifdim\d_strc_math_display_width>\displaywidth + \settrue\c_strc_math_display_overflow + \else + \displaywidth\d_strc_math_display_width + \setfalse\c_strc_math_display_overflow + \fi + \else + \ifdim\d_strc_math_display_width>\displaywidth + \settrue\c_strc_math_display_overflow + \else + \setfalse\c_strc_math_display_overflow + \fi \fi} -\unexpanded\def\stopmathbox +\def\strc_math_number_check_outside + {\d_strc_math_display_width\naturalwd\b_strc_math_display + \ifdim\dimexpr\d_strc_math_display_width+\d_framed_locator_lo+\d_framed_locator_ro\relax>\displaywidth + \settrue\c_strc_math_display_overflow + \else + \setfalse\c_strc_math_display_overflow + \fi + % still ok? + \ifnum\mathraggedstatus=\plustwo + \edef\d_strc_math_framed_width{\the\dimexpr\displaywidth-2\wd\b_strc_formulas_number\relax}% + \else + \edef\d_strc_math_framed_width{\the\dimexpr\displaywidth-\wd\b_strc_formulas_number\relax}% + \fi} + +\let\strc_math_number_check_inside\strc_math_number_check_outside + +% offsets + +\def\strc_math_number_check_offsets + {\begingroup + \setbox\scratchbox\hbox + {\inheritedformulaframedframed + {\pack_framed_locator_set_lo\pack_framed_locator_set_ro}}% + \endgroup} + +% tracing + +\def\strc_math_traced_state_yes + {\llap{\setbox\scratchbox\hbox{\infofont + \ifcase\mathraggedstatus unset\or right\or middle\or left\fi + \space + \ifcase\c_strc_formulas_frame_mode no\or out\or in\fi + \space + \ifconditional\c_strc_math_display_overflow overflow\else fit\fi + \quad}\ht\scratchbox\zeropoint\dp\scratchbox\zeropoint\box\scratchbox}} + +\let\strc_math_traced_state\relax + +\installtextracker + {formulas.framed} + {\let\strc_math_traced_state\strc_math_traced_state_yes} + {\let\strc_math_traced_state\relax} + +% packaging + +\unexpanded\def\strc_math_box_start#1% + {\hsize\displaywidth % \checkeddisplaymath + \global\mathnumberstatus\plusone + \mathraggedstatus#1\relax + % + \global\d_math_number_correction\zeropoint + % + \edef\p_location{\formulaparameter\c!location}% + \useformulacolorparameter\c!color + \c_strc_math_number_location\ifx\p_location\v!left\plusone\else\ifx\p_location\v!right\plustwo\else\zerocount\fi\fi + % + %\strc_formulas_place_number % not here as we can have inner alignment numbers + \dontcomplain + \setbox\b_strc_math_display\math_hbox\bgroup % \checkeddisplaymath + \mathinnerstrut + \startforceddisplaymath} + +\def\strc_math_flush_number_no + {\ifconditional\c_strc_math_display_overflow + \ifcase\c_strc_formulas_frame_mode + \strc_math_flush_box_normal + \else + \strc_math_flush_box_framed_fit_inline + \fi + \else + \ifcase\c_strc_formulas_frame_mode + %\ifconditional\c_strc_formulas_tight + % \strc_math_flush_box_normal + %\else + \strc_math_flush_box_normal + %\fi + \else + \ifconditional\c_strc_formulas_tight + \strc_math_flush_box_framed_fit_inline + \else + \strc_math_flush_box_framed_display + \fi + \fi + \fi} + +\def\strc_math_flush_number_left + {\ifconditional\c_strc_math_display_overflow + \ifcase\c_strc_formulas_frame_mode + \strc_math_number_left_overflow + \or + \strc_math_number_left_overflow_outside + \or + \strc_math_number_left_overflow_inside + \fi + \else + \ifcase\c_strc_formulas_frame_mode + \strc_math_number_left_normal + \or + \strc_math_number_left_normal_outside + \or + \strc_math_number_left_normal_inside + \fi + \fi} + +\def\strc_math_flush_number_right + {\ifconditional\c_strc_math_display_overflow + \ifcase\c_strc_formulas_frame_mode + \strc_math_number_right_overflow + \or + \strc_math_number_right_overflow_outside + \or + \strc_math_number_right_overflow_inside + \fi + \else + \ifcase\c_strc_formulas_frame_mode + \strc_math_number_right_normal + \or + \strc_math_number_right_normal_outside + \or + \strc_math_number_right_normal_inside + \fi + \fi} + +\unexpanded\def\strc_math_box_stop {\stopforceddisplaymath - \ifcase\mathraggedstatus\or\or\hfill\or\hfill\fi \egroup - \setbox0\hbox{\unhcopy\scratchbox}% - \scratchdimen\wd0 - % to be tested: \scratchdimen\naturalwd\scratchbox - \ifdim\scratchdimen>\displaywidth % \checkeddisplaymath - \donetrue + % % not needed, attribute driven + % \ifgridsnapping + % \snaptogrid[\v!math]\vbox + % \fi + % \bgroup + % check number + \d_strc_math_number_width\wd\b_strc_formulas_number + % + \ifcase\mathnumberstatus + \setfalse\c_strc_math_has_number + \or\ifzeropt\d_strc_math_number_width + \setfalse\c_strc_math_has_number \else - \donefalse + \settrue\c_strc_math_has_number + \fi\fi + % preroll left and right offsets + \ifcase\c_strc_formulas_frame_mode + % no frame + \else + \strc_math_number_check_offsets + \fi + \ifcase\c_strc_formulas_frame_mode + \strc_math_number_check + \or + \strc_math_number_check_outside + \else + \strc_math_number_check_inside \fi - \hbox to \displaywidth\bgroup + \noindent % \noindentation % not \dontleavehmode + \hskip\d_strc_formulas_display_margin_left % was kern but that doesn't indent + \strc_math_traced_state + \hbox to \displaywidth \bgroup \ifcase\mathnumberstatus - \box\scratchbox - \or - \ifx\math_the_l_eq_no\empty - \ifx\math_the_r_eq_no\empty - \box\scratchbox + \strc_math_flush_box + \or % status 1 + \ifcase\c_strc_math_number_location + \strc_math_flush_box + \or % number left + \ifzeropt\wd\b_strc_formulas_number + \strc_math_flush_number_no \else - \ifdone - \vpack{\box\scratchbox\hpack to \displaywidth{\hss\math_box_llapped_math_no}}% \checkeddisplaymath - \else - \hss\box\scratchbox\math_box_llapped_math_no % hss makes room for number - \fi + \strc_math_flush_number_left \fi - \else - \ifdone - \vpack{\hpack to \displaywidth{\math_box_rlapped_math_no\hss}\box\scratchbox}% \checkeddisplaymath + \else % number right + \ifzeropt\wd\b_strc_formulas_number + \strc_math_flush_number_no \else - \math_box_rlapped_math_no\box\scratchbox\hss % hss makes room for number + \strc_math_flush_number_right \fi \fi - \or - \hskip\mathnumbercorrection - \box\scratchbox + \or % status 2 + \hskip\d_math_number_correction % probably no longer used + \strc_math_flush_box \hss \else - \box\scratchbox + \strc_math_flush_box \fi + % \egroup \egroup} -\defineinnermathhandler\v!left {\startmathbox\plusone }{\stopmathbox} -\defineinnermathhandler\v!middle {\startmathbox\plustwo }{\stopmathbox} -\defineinnermathhandler\v!right {\startmathbox\plusthree}{\stopmathbox} -\defineinnermathhandler\v!flushleft {\startmathbox\plusthree}{\stopmathbox} -\defineinnermathhandler\v!center {\startmathbox\plustwo }{\stopmathbox} -\defineinnermathhandler\v!flushright{\startmathbox\plusone }{\stopmathbox} -\defineinnermathhandler\v!normal {} {} +\defineinnermathhandler\v!left {\strc_math_box_start\plusone }{\strc_math_box_stop} +\defineinnermathhandler\v!middle {\strc_math_box_start\plustwo }{\strc_math_box_stop} +\defineinnermathhandler\v!right {\strc_math_box_start\plusthree}{\strc_math_box_stop} +\defineinnermathhandler\v!flushleft {\strc_math_box_start\plusthree}{\strc_math_box_stop} +\defineinnermathhandler\v!center {\strc_math_box_start\plustwo }{\strc_math_box_stop} +\defineinnermathhandler\v!flushright{\strc_math_box_start\plusone }{\strc_math_box_stop} +\defineinnermathhandler\v!normal {\strc_math_box_start\plustwo }{\strc_math_box_stop} -%defineinnermathhandler\v!normal {\startmathbox\plustwo }{\stopmathbox} +%D Some inline math tweak. -%D [The examples below are in english and don't process in the -%D documentation style, which will be english some day.] -%D -%D Normally a formula is centered, but in case you want to -%D align it left or right, you can set up formulas to behave -%D that way. Normally a formula will adapt is left indentation -%D to the environment: -%D -%D \startbuffer -%D \fakewords{20}{40}\epar -%D \startitemize -%D \item \fakewords{20}{40}\epar -%D \placeformula \startformula \fakeformula \stopformula -%D \item \fakewords{20}{40}\epar -%D \stopitemize -%D \fakewords{20}{40}\epar -%D \stopbuffer -%D -%D % \getbuffer -%D -%D In the next examples we explicitly align formulas to the -%D left (\type {\raggedleft}), center and right (\type -%D {\raggedright}): -%D -%D \startbuffer -%D \setupformulas[align=left] -%D \startformula\fakeformula\stopformula -%D \setupformulas[align=middle] -%D \startformula\fakeformula\stopformula -%D \setupformulas[align=right] -%D \startformula\fakeformula\stopformula -%D \stopbuffer -%D -%D \typebuffer -%D -%D Or in print: -%D -%D % {\getbuffer} -%D -%D With formula numbers these formulas look as follows: -%D -%D \startbuffer -%D \setupformulas[align=left] -%D \placeformula \startformula\fakeformula\stopformula -%D \setupformulas[align=middle] -%D \placeformula \startformula\fakeformula\stopformula -%D \setupformulas[align=right] -%D \placeformula \startformula\fakeformula\stopformula -%D \stopbuffer -%D -%D % {\getbuffer} -%D -%D This was keyed in as: -%D -%D \typebuffer -%D -%D When tracing is turned on (\type {\tracemathtrue}) you can -%D visualize the bounding box of the formula, -%D -%D % {\tracemathtrue\getbuffer} -%D -%D As you can see, the dimensions are the natural ones, but if -%D needed you can force a normalized line: -%D -%D \startbuffer -%D \setupformulas[strut=yes] -%D \placeformula \startformula \fakeformula \stopformula -%D \stopbuffer -%D -%D \typebuffer -%D -%D This time we get a more spacy result. -%D -%D % {\tracemathtrue\getbuffer} -%D -%D We will now show a couple of more settings and combinations -%D of settings. In centered formulas, the number takes no space -%D -%D \startbuffer -%D \setupformulas[align=middle] -%D \startformula \fakeformula \stopformula -%D \placeformula \startformula \fakeformula \stopformula -%D \stopbuffer -%D -%D \typebuffer % {\tracemathtrue\getbuffer} -%D -%D You can influence the placement of the whole box with the -%D parameters \type {leftmargin} and \type {rightmargin}. -%D -%D \startbuffer -%D \setupformulas[align=right,leftmargin=3em] -%D \startformula \fakeformula \stopformula -%D \placeformula \startformula \fakeformula \stopformula -%D -%D \setupformulas[align=left,rightmargin=1em] -%D \startformula \fakeformula \stopformula -%D \placeformula \startformula \fakeformula \stopformula -%D \stopbuffer -%D -%D \typebuffer % {\tracemathtrue\getbuffer} -%D -%D You can also inherit the margin from the environment. -%D -%D \startbuffer -%D \setupformulas[align=right,margin=standard] -%D \startformula \fakeformula \stopformula -%D \placeformula \startformula \fakeformula \stopformula -%D \stopbuffer -%D -%D \typebuffer % {\tracemathtrue\getbuffer} -%D -%D The distance between the formula and the number is only -%D applied when the formula is left or right aligned. -%D -%D \startbuffer -%D \setupformulas[align=left,distance=2em] -%D \startformula \fakeformula \stopformula -%D \placeformula \startformula \fakeformula \stopformula -%D \stopbuffer -%D -%D \typebuffer % {\tracemathtrue\getbuffer} +\appendtoks + \ifcase\mathnestinglevel\or + % 4=disable 6=only when no spaces + \mathsurroundskip\mathematicsparameter\c!textdistance\relax + \ifzeropt\mathsurroundskip + \ifdim\gluestretch\mathsurroundskip=\zeropoint + \ifdim\glueshrink\mathsurroundskip=\zeropoint + \mathsurroundmode\plussix + \else + \mathsurroundskip\zeropoint + \mathsurroundmode\plusfour + \fi + \else + \mathsurroundmode\plussix + \fi + \else + \mathsurroundmode\plussix + \fi + \else + \mathsurroundmode\plusfour + \mathsurroundskip\zeropoint + \fi +\to \everymathematics + +\setupmathematics + [\c!textdistance=\zeropoint] + +%D For documentation, see \type {math-mkiv.tex}. \protect \endinput |