summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/math-ali.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/math-ali.mkiv')
-rw-r--r--Master/texmf-dist/tex/context/base/math-ali.mkiv187
1 files changed, 120 insertions, 67 deletions
diff --git a/Master/texmf-dist/tex/context/base/math-ali.mkiv b/Master/texmf-dist/tex/context/base/math-ali.mkiv
index 94800b3ba8b..a172dc8ae5f 100644
--- a/Master/texmf-dist/tex/context/base/math-ali.mkiv
+++ b/Master/texmf-dist/tex/context/base/math-ali.mkiv
@@ -15,17 +15,6 @@
\unprotect
-% helpers .. will move
-
-\def\doxxdoubleempty#1#2%
- {\ifx#2[\expandafter\dodoxxdoubleempty\else\expandafter\noxxdoubleempty\fi#1#2}
-
-\def\dodoxxdoubleempty#1[#2]#3%
- {\ifx#3[\else\expandafter\nonoxxdoubleempty\fi#1[#2]#3}
-
-\def\noxxdoubleempty #1{#1[][]}
-\def\nonoxxdoubleempty#1[#2]{#1[#2][]}
-
%D The code here has been moved from other files. Beware: the \MKII\ and
%D \MKIV\ code is not gathered in files with the same name. In the
%D meantime this code has been adapted to \MKIV\ but mnore is possible.
@@ -38,19 +27,25 @@
% n>1 #### needed, strange # interaction in recurse
+\newtoks\c_math_align_a
+\newtoks\c_math_align_b
+\newtoks\c_math_align_c
+
\def\math_build_eqalign
{\scratchtoks\emptytoks
- \dorecurse{\mathalignmentparameter\c!m}
- {\ifnum\recurselevel>\plusone
- %\appendtoks
- % \tabskip\mathalignmentparameter\c!distance&\tabskip\zeropoint
- %\to\scratchtoks
- \scratchtoks\expandafter{\the\scratchtoks\tabskip\mathalignmentparameter\c!distance&\tabskip\zeropoint}%
- \fi
- \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksa}}%
- \dorecurse{\numexpr\mathalignmentparameter\c!n-\plusone\relax}
- {\normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksb}}}}%
- \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksc}}}
+ \dorecurse{\mathalignmentparameter\c!m}\math_build_eqalign_step
+ \normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_c}}}
+
+\def\math_build_eqalign_step
+ {\ifnum\recurselevel>\plusone
+ %\appendtoks
+ % \tabskip\mathalignmentparameter\c!distance&\tabskip\zeropoint
+ %\to\scratchtoks
+ \scratchtoks\expandafter{\the\scratchtoks\tabskip\mathalignmentparameter\c!distance&\tabskip\zeropoint}%
+ \fi
+ \normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_a}}%
+ \dorecurse{\numexpr\mathalignmentparameter\c!n-\plusone\relax}
+ {\normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_b}}}}
\def\math_math_in_eqalign#1{$\tabskip\zeropoint\everycr\emptytoks\displaystyle{{}#1{}}$}
\def\math_text_in_eqalign#1{$\tabskip\zeropoint\everycr\emptytoks#1$}
@@ -73,14 +68,14 @@
% use zeroskipplusfill
\def\math_prepare_r_eqalign_no
- {\!!toksa{\strut\math_first_in_eqalign\hfil\math_left_of_equalign\span\math_math_in_eqalign{##}\math_right_of_eqalign\tabskip\zeropoint}%
- \!!toksb{&\math_next_in_eqalign\math_left_of_equalign\span\math_math_in_eqalign{##}\math_right_of_eqalign\tabskip\zeropoint}%
+ {\c_math_align_a{\strut\math_first_in_eqalign\hfil\math_left_of_equalign\span\math_math_in_eqalign{##}\math_right_of_eqalign\tabskip\zeropoint}%
+ \c_math_align_b{&\math_next_in_eqalign\math_left_of_equalign\span\math_math_in_eqalign{##}\math_right_of_eqalign\tabskip\zeropoint}%
\ifnum\mathraggedstatus=\plusone
- \!!toksc{\hfil&\span\math_text_in_eqalign{##}\tabskip\zeropoint}%
+ \c_math_align_c{\hfil&\span\math_text_in_eqalign{##}\tabskip\zeropoint}%
\else\ifnum\mathraggedstatus=\plusthree
- \!!toksc{\hfil\tabskip\zeropoint\!!plus 1\!!fill&\span\math_text_in_eqalign{##}\tabskip\zeropoint}%
+ \c_math_align_c{\hfil\tabskip\zeropoint\s!plus 1\s!fill&\span\math_text_in_eqalign{##}\tabskip\zeropoint}%
\else
- \!!toksc{\hfil\tabskip\centering&\llap{\span\math_text_in_eqalign{##}}\tabskip\zeropoint}%
+ \c_math_align_c{\hfil\tabskip\centering&\llap{\span\math_text_in_eqalign{##}}\tabskip\zeropoint}%
\fi\fi
\global\mathnumberstatus\zerocount
\math_build_eqalign
@@ -88,31 +83,31 @@
\tabskip\centering}
\def\math_prepare_l_eqalign_no
- {\!!toksa{\strut\math_first_in_eqalign\hfil\math_left_of_equalign\span\math_math_in_eqalign{##}\math_right_of_eqalign\tabskip\zeropoint}%
- \!!toksb{&\math_next_in_eqalign\math_left_of_equalign\span\math_math_in_eqalign{##}\math_right_of_eqalign\tabskip\zeropoint}%
+ {\c_math_align_a{\strut\math_first_in_eqalign\hfil\math_left_of_equalign\span\math_math_in_eqalign{##}\math_right_of_eqalign\tabskip\zeropoint}%
+ \c_math_align_b{&\math_next_in_eqalign\math_left_of_equalign\span\math_math_in_eqalign{##}\math_right_of_eqalign\tabskip\zeropoint}%
% problem: number is handled after rest and so ends up in the margin
\ifnum\mathraggedstatus=\plusone
- \!!toksc{\hfil&\kern-\displaywidth\rlap{\span\math_text_in_eqalign{##}}\tabskip\displaywidth}%
+ \c_math_align_c{\hfil&\kern-\displaywidth\rlap{\span\math_text_in_eqalign{##}}\tabskip\displaywidth}%
\else\ifnum\mathraggedstatus=\plusthree
- \!!toksc{\hfil\tabskip\zeropoint\!!plus 1\!!fill&\kern-\displaywidth\span\math_rlap{\span\math_text_in_eqalign{##}}\tabskip\displaywidth}%
+ \c_math_align_c{\hfil\tabskip\zeropoint\s!plus 1\s!fill&\kern-\displaywidth\span\math_rlap{\span\math_text_in_eqalign{##}}\tabskip\displaywidth}%
\else
- \!!toksc{\hfil\tabskip\centering&\kern-\displaywidth\rlap{\span\math_text_in_eqalign{##}}\tabskip\displaywidth}%
+ \c_math_align_c{\hfil\tabskip\centering&\kern-\displaywidth\rlap{\span\math_text_in_eqalign{##}}\tabskip\displaywidth}%
\fi\fi
\global\mathnumberstatus\zerocount
\math_build_eqalign
\the\mathdisplayaligntweaks
\tabskip\centering}
-\def\math_both_eqalign_no#1#2%
+\def\math_both_eqalign_no_normal#1#2%
{\ifmmode
- \the\mathdisplayaligntweaks % \let\doplaceformulanumber\relax % strange hack
+ \the\mathdisplayaligntweaks % \let\strc_formulas_place_number\relax % strange hack
\vcenter\bgroup
\let\math_finish_eqalign_no\egroup
\else
\let\math_finish_eqalign_no\relax
\fi
#1%
- \halign \ifcase\eqalignmode \or to \displaywidth \fi \@EA {\the\scratchtoks\crcr#2\crcr}%
+ \halign \ifcase\eqalignmode \or to \displaywidth \fi \expandafter {\the\scratchtoks\crcr#2\crcr}%
\math_finish_eqalign_no}
\def\math_both_eqalign_no_aligned#1%
@@ -128,7 +123,7 @@
\fi
\fi
#1%
- \halign \ifcase\eqalignmode \or to \displaywidth \fi \@EA \bgroup\the\scratchtoks\crcr}
+ \halign \ifcase\eqalignmode \or to \displaywidth \fi \expandafter \bgroup\the\scratchtoks\crcr}
\def\math_rlap#1%
{\setbox\scratchbox\hbox{#1}%
@@ -158,7 +153,7 @@
\newtoks \everymathalignment
\def\math_alignment_NR_indeed[#1][#2]%
- {\donestedformulanumber{#1}{#2}% to be tagged (better an attribute)
+ {\strc_formulas_place_number_nested{#1}{#2}% to be tagged (better an attribute)
\crcr
\dostoptagged % finish row
\noalign{\glet\math_alignment_NC\math_alignment_NC_first}} % noalign used for change state, conditional does not work here
@@ -221,11 +216,31 @@
\setupmathalignment
[\c!n=2,
\c!m=1,
- \c!distance=1em]
+ \c!distance=\emwidth]
\definemathalignment[align] % default case (this is what amstex users expect)
\definemathalignment[\v!mathalignment] % prefered case (this is cleaner, less clashing)
+% special case.. in case one mistypes ..
+
+\ifdefined \startalignment
+
+ \let\align_math_normal_start\startalign
+ \let\align_math_normal_stop \stopalign
+
+ \let\align_text_normal_start\startalignment
+ \let\align_text_normal_stop \stopalignment
+
+ \unexpanded\def\startalign{\ifmmode\expandafter\align_math_normal_start\else\expandafter\align_text_normal_start\fi}
+ \unexpanded\def\stopalign {\ifmmode\expandafter\align_math_normal_stop \else\expandafter\align_text_normal_stop \fi}
+
+ \let\startalignment\startalign
+ \let\stopalignment \stopalign
+
+\fi
+
+%
+
\def\numberedeqalign
{\doifelse{\formulaparameter\c!location}\v!left
\math_handle_eqalign_no_l_aligned
@@ -265,7 +280,7 @@
\letvalue{\??mathalignmentvariant\v!middle}\plusthree
\def\math_align_NR_generic[#1][#2]%
- {\donestedformulanumber{#1}{#2}\crcr}
+ {\strc_formulas_place_number_nested{#1}{#2}\crcr}
%D \starttyping
%D \placeformula[eqn0]\startformula \startalign[n=1] a\NR \stopalign \stopformula See \in[eqn0]
@@ -408,8 +423,9 @@
\installcommandhandler \??mathcases {mathcases} \??mathcases
\setupmathcases
- [\c!distance=1em,
- \c!numberdistance=2.5em,
+ [\c!distance=\emwidth,
+ \c!strut=\v!yes, % new
+ \c!numberdistance=2.5\emwidth,
\c!left={\left\{\mskip\thinmuskip},
\c!right={\right.}]
@@ -423,30 +439,72 @@
\edef\currentmathcases{#1}%
\dosingleempty\math_cases_start_indeed}
+\def\math_cases_NC_zero
+ {\math_cases_NC}
+
+\def\math_cases_MC_zero
+ {\math_cases_NC
+ \ifmmode\else
+ \startimath
+ \let\math_cases_end_math\stopimath
+ \fi}
+
+\let\math_cases_end_math\relax
+
+\def\math_cases_NR_zero
+ {\unskip
+ \math_cases_end_math
+ \aligntab
+ \global\let\math_cases_NC\math_cases_NC_first
+ \dodirectdoubleempty\math_cases_NR}
+
+\def\math_cases_NC_first
+ {\global\let\math_cases_NC\math_cases_NC_second}
+
+\def\math_cases_NC_second
+ {\math_cases_end_math\aligntab}
+
+\let\math_cases_NR\math_align_NR_generic
+
\unexpanded\def\math_cases_start_indeed[#1]%
{\iffirstargument
\setupcurrentmathcases[#1]%
\fi
+ \edef\p_strut{\mathcasesparameter\c!strut}%
+ \ifx\p_strut\v!yes
+ \let\math_cases_strut\strut
+ \else
+ \let\math_cases_strut\relax
+ \fi
\mathcasesparameter\c!left
\vcenter\bgroup
\pushmacro\math_cases_NC
\let\endmath\relax
- \def\NC{\math_cases_NC}%
- \def\MC{\math_cases_NC\ifmmode\else$\def\endmath{$}\fi}%
- \global\let\math_cases_NC\math_cases_NC_indeed
- \def\NR{\unskip\endmath&\global\let\math_cases_NC\math_cases_NC_indeed\doxxdoubleempty\math_cases_NR}%
+ \let\NC\math_cases_NC_zero
+ \let\MC\math_cases_MC_zero
+ \let\NR\math_cases_NR_zero
+ \global\let\math_cases_NC\math_cases_NC_first
\normalbaselines
\mathsurround\zeropoint
\everycr\emptytoks
\tabskip\zeropoint
\global\c_math_eqalign_column\plusone
\halign\bgroup
- $\mathcasesparameter\c!style##$\hfil
- &\hskip\mathcasesparameter\c!distance\relax
- \popmacro\math_cases_NC##\hfil
- &\hskip\mathcasesparameter\c!numberdistance\relax
- \let\formuladistance\!!zeropoint
- \span\math_text_in_eqalign{##}%
+ \startimath
+ \mathcasesparameter\c!style
+ \alignmark\alignmark
+ \stopimath
+ \hfil
+ \aligntab
+ \hskip\mathcasesparameter\c!distance\relax
+ \popmacro\math_cases_NC
+ \math_cases_strut % looks better
+ \alignmark\alignmark
+ \hfil
+ \aligntab
+ \hskip\mathcasesparameter\c!numberdistance\relax
+ \let\formuladistance\!!zeropoint
+ \span\math_text_in_eqalign{\alignmark\alignmark}%
\crcr} % todo: number
\def\math_cases_stop
@@ -457,11 +515,6 @@
\mathcasesparameter\c!right
\endgroup}
-\def\math_cases_NC_indeed
- {\gdef\math_cases_NC{\endmath&}}
-
-\let\math_cases_NR\math_align_NR_generic
-
\definemathcases[cases]
\definemathcases[\v!mathcases]
@@ -515,7 +568,7 @@
\installcommandhandler \??mathmatrix {mathmatrix} \??mathmatrix
\setupmathmatrix
- [\c!distance=1em,
+ [\c!distance=\emwidth,
\c!left=,
\c!right=,
\c!align=\v!middle]
@@ -570,20 +623,20 @@
\definemathmatrix[\v!mathmatrix]
\def\math_matrix_prepare
- {\!!toksa{\strut\math_first_in_eqalign\math_left_of_equalign\span
+ {\c_math_align_a{\strut\math_first_in_eqalign\math_left_of_equalign\span
\math_text_in_eqalign{\mathmatrixparameter\c!style##}\math_right_of_eqalign}%
- \!!toksb{&\hskip\mathmatrixparameter\c!distance
+ \c_math_align_b{&\hskip\mathmatrixparameter\c!distance
\math_next_in_eqalign\math_left_of_equalign\span
\math_text_in_eqalign{\mathmatrixparameter\c!style##}\math_right_of_eqalign}%
- \!!toksc{&&\hskip\mathmatrixparameter\c!distance
+ \c_math_align_c{&&\hskip\mathmatrixparameter\c!distance
\math_left_of_equalign\span
\math_text_in_eqalign{\mathmatrixparameter\c!style##}\math_right_of_eqalign}%
\scratchtoks\emptytoks
- \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksa}}%
+ \normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_a}}%
\dorecurse{\numexpr\scratchcounter-\plusone\relax}
- {\normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksb}}}%
- \normalexpanded{\scratchtoks{\the\scratchtoks\the\!!toksc}}%
- \halign \@EA \bgroup\the\scratchtoks \crcr}
+ {\normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_b}}}%
+ \normalexpanded{\scratchtoks{\the\scratchtoks\the\c_math_align_c}}%
+ \halign \expandafter \bgroup\the\scratchtoks \crcr}
\unexpanded\def\dodomatrixNC
{\gdef\domatrixNC{\endmath&}}
@@ -887,10 +940,10 @@
\expandafter\mathbin
\else\ifdim\wd\scratchbox>\zeropoint
\endgroup
- \expandafter\expandafter\expandafter\mathrel
+ \doubleexpandafter\mathrel
\else
\endgroup
- \expandafter\expandafter\expandafter\firstofoneargument
+ \doubleexpandafter\firstofoneargument
\fi\fi}
\unexpanded\def\overset#1#2%
@@ -947,7 +1000,7 @@
\let\normalleqno\leqno
\let\normaleqno \eqno
% added
- \doplaceformulanumber
+ \strc_formulas_place_number
\setbox\scratchbox\math_hbox to \displaywidth\bgroup
\mathinnerstrut
$%