summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/math-ini.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/math-ini.mkiv')
-rw-r--r--tex/context/base/mkiv/math-ini.mkiv179
1 files changed, 147 insertions, 32 deletions
diff --git a/tex/context/base/mkiv/math-ini.mkiv b/tex/context/base/mkiv/math-ini.mkiv
index 2e7831d75..8c682bdcb 100644
--- a/tex/context/base/mkiv/math-ini.mkiv
+++ b/tex/context/base/mkiv/math-ini.mkiv
@@ -19,6 +19,10 @@
% todo: 0x2062 : invisible times
% todo: 0x2063 : invisible comma
+% a bit tricky way to set ... no (pseudo) registers but math hash values:
+%
+% \normalexpanded{\Umathlimitabovevgap\displaystyle=40\dimexpr\the\Umathlimitabovevgap\displaystyle\relax}
+
% Todo in luatex maincontrol.w: also accept a number here:
%
% case set_math_param_cmd:
@@ -73,9 +77,28 @@
\registerctxluafile{math-fbk}{1.001}
\registerctxluafile{math-dir}{1.001}
+%D A starter:
+%D
+%D \startbuffer
+%D \mathsurround 10pt
+%D \mathsurroundskip30pt
+%D x $x + \ruledhbox{$x$} + x$ x
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \start \blank \getbuffer \blank \stop
+
+\newcount\mathnestinglevel
+
+\appendtoks
+ \advance\mathnestinglevel\plusone
+\to \everymathematics
+
%D A few compatibility helpers:
\def\Umathbotaccent{\Umathaccent \s!bottom }
+\def\Umathtopaccent{\Umathaccent \s!top }
\def\Umathaccents {\Umathaccent \s!both }
\ifdefined\Umathcharclass \else
@@ -84,7 +107,7 @@
\def\Umathcharslot {\cldcontext{tex.getmathcode(token.scan_int())[3]}}
\fi
-%D The attributes that we will use:
+%D The attributes that we will use (todo: pack some into one but uglier code):
\definesystemattribute[mathalphabet] [public]
\definesystemattribute[mathsize] [public]
@@ -95,6 +118,7 @@
\definesystemattribute[mathcategory] [public]
\definesystemattribute[mathmode] [public]
\definesystemattribute[mathitalics] [public]
+\definesystemattribute[mathkernpairs] [public]
\definesystemattribute[mathbidi] [public]
\definesystemattribute[mathdomain] [public]
@@ -106,9 +130,6 @@
\appendtoks
\attribute\mathmodeattribute\plusone
-\to \everybeforedisplayformula
-
-\appendtoksonce
\attribute\displaymathattribute\plusone
\to \everybeforedisplayformula
@@ -139,10 +160,12 @@
\unexpanded\def\startforceddisplaymath
{\startimath
\displaystyle
+ \begingroup
\settrue\indisplaymath}
\unexpanded\def\stopforceddisplaymath
- {\stopimath}
+ {\endgroup
+ \stopimath}
% \unexpanded\def\rawmathcharacter#1% slow but only for tracing
% {\begingroup
@@ -215,7 +238,9 @@
\def\math_m_yes_text[#1]%
{\begingroup
- \edef\currentmathematics{#1}% check for valid
+ \doifassignmentelse{#1}%
+ {\setupcurrentmathematics[#1]}%
+ {\edef\currentmathematics{#1}}% check for valid
\edef\p_openup{\mathematicsparameter\c!openup}%
\ifx\p_openup\v!yes
\expandafter\math_m_yes_text_openedup
@@ -337,13 +362,13 @@
\unexpanded\def\math_set_font_style #1{\ifmmode\clf_setmathstyle{#1}\fi}
\unexpanded\def\math_set_font_alternate#1{\ifmmode\clf_setmathalternate\defaultmathfamily{#1}\fi}
-\installcorenamespace{mathstylealternate} % might become a setuphandler
+\installcorenamespace{mathstylealternative} % might become a setuphandler
\unexpanded\def\math_set_font_style_alternate#1%
- {\ifcsname\??mathstylealternate\fontclass:#1\endcsname
+ {\ifcsname\??mathstylealternative\fontclass:#1\endcsname
%\expandafter\math_set_font_alternate\csname\??mathstylealternate\fontclass:#1\endcsname
\expandafter\math_set_font_alternate\lastnamedcs
- \else\ifcsname\??mathstylealternate#1\endcsname
+ \else\ifcsname\??mathstylealternative#1\endcsname
%\expandafter\math_set_font_alternate\csname\??mathstylealternate#1\endcsname
\expandafter\math_set_font_alternate\lastnamedcs
\fi\fi}
@@ -353,19 +378,30 @@
\def\math_setup_rendering[#1][#2]%
{\ifsecondargument
- \getparameters[\??mathstylealternate#1:][#2]%
+ \getparameters[\??mathstylealternative#1:][#2]%
\else
- \getparameters[\??mathstylealternate][#1]%
+ \getparameters[\??mathstylealternative][#1]%
\fi}
+\appendtoks
+ \edef\p_stylealternative{\mathematicsparameter\c!stylealternative}%
+ \ifx\p_stylealternative\empty\else
+ \clf_presetmathalternate\defaultmathfamily{\p_stylealternative}%
+ \fi
+\to \everymathematics
+
% if there were many features we could have a feature pass over math nodes but it makes no
% sense now so we have commands to deal with it
-\unexpanded\def\mathaltcal {\math_set_font_alternate{cal}\cal} % set via goody file
-%unexpanded\def\mathslashedzero {\math_set_font_alternate{zero}0} % set via goody file or automatic
-\unexpanded\def\mathdotless {\math_set_font_alternate{dotless}} % set via goody file or automatic
-\unexpanded\def\mathdotlessi {{\mathdotless i}}
-\unexpanded\def\mathdotlessj {{\mathdotless j}}
+\unexpanded\def\mathaltcalligraphic{\math_set_font_alternate{calligraphic}\cal} % set via goody file
+\unexpanded\def\mathaltitalic {\math_set_font_alternate{italic}} % set via goody file
+\unexpanded\def\mathslashedzero {\begingroup\math_set_font_alternate{zero}∅\endgroup} % set via goody file or automatic
+\unexpanded\def\mathdotless {\math_set_font_alternate{dotless}} % set via goody file or automatic
+\unexpanded\def\mathdotlessi {\begingroup\mathdotless i\endgroup}
+\unexpanded\def\mathdotlessj {\begingroup\mathdotless j\endgroup}
+
+\let\mathaltcal\mathaltcalligraphic
+\let\mathaltit \mathaltitalic
%let\textslashedzero\slashedzero \unexpanded\def\autoslashedzero{\mathortext\mathslashedzero\textslashedzero}
\let\textdotlessi \dotlessi \unexpanded\def\autodotlessi {\mathortext\mathdotlessi \textdotlessi}
@@ -377,13 +413,15 @@
\let\dotlessj \autodotlessj
\to \everymathematics
-\let\setmathattribute \math_set_attribute
-\let\setmathalphabet \math_set_alphabet
-\let\setmathfontstyle \math_set_font_style
-\let\setmathfontalternate \math_set_font_alternate
-\let\setmathfontstylealternate\math_set_font_style_alternate
+\let\setmathattribute \math_set_attribute
+\let\setmathalphabet \math_set_alphabet
+\let\setmathfontstyle \math_set_font_style
+\let\setmathfontalternate \math_set_font_alternate
+\let\setmathfontalternative \math_set_font_alternate
+\let\setmathfontstylealternate \math_set_font_style_alternate
+\let\setmathfontstylealternative\math_set_font_style_alternate
-\let\mathalternate \math_set_font_alternate
+\let\mathalternate \math_set_font_alternate
\unexpanded\def\mathupright {\math_set_attribute\s!regular\s!tf\math_set_font_style_alternate\s!tf}
\unexpanded\def\mathitalic {\math_set_attribute\s!regular\s!it\math_set_font_style_alternate\s!it}
@@ -445,9 +483,9 @@
\ifdefined\normalbi\else\let\normalbi\bi\fi \unexpanded\def\bi{\ifmmode\mathbi\else\normalbi\fi}
\ifdefined\normalbs\else\let\normalbs\bs\fi \unexpanded\def\bs{\ifmmode\mathbs\else\normalbs\fi}
-\let\normalrm\rm \unexpanded\def\rm{\ifmmode\mathrm\else\normalrm\fi}
-\let\normalss\ss \unexpanded\def\ss{\ifmmode\mathss\else\normalss\fi}
-\let\normaltt\tt \unexpanded\def\tt{\ifmmode\mathtt\else\normaltt\fi}
+\unexpanded\def\rm{\ifmmode\mathrm\else\normalrm\fi}
+\unexpanded\def\ss{\ifmmode\mathss\else\normalss\fi}
+\unexpanded\def\tt{\ifmmode\mathtt\else\normaltt\fi}
\ifdefined\mr \else \let\mr\relax \fi
\ifdefined\mb \else \let\mb\relax \fi
@@ -519,11 +557,13 @@
\unexpanded\def\doifelseutfmathabove #1{\clf_doifelseutfmathabove {#1}}
\unexpanded\def\doifelseutfmathbelow #1{\clf_doifelseutfmathbelow {#1}}
\unexpanded\def\doifelseutfmathfiller#1{\clf_doifelseutfmathfiller{#1}}
+\unexpanded\def\doifelseutfmathlimop #1{\clf_doifelseutfmathlimop {#1}}
\let\doifutfmathaccentelse \doifelseutfmathaccent
\let\doifutfmathaboveelse \doifelseutfmathabove
\let\doifutfmathbelowelse \doifelseutfmathbelow
\let\doifutfmathfillerelse \doifelseutfmathfiller
+\let\doifutfmathlimopelse \doifelseutfmathlimop
%D Not used that much:
@@ -1322,6 +1362,31 @@
% \csname\??mathitalics\mathematicsparameter\s!italics\endcsname
% \to \everyswitchmathematics % only in mathematics
+%D Math kerns (experiment)
+
+\installcorenamespace{mathkernpairs}
+
+\setnewconstant\c_math_kernpairs_attribute\attributeunsetvalue % no real need for an extra constant
+
+\def\math_kernpairs_initialize
+ {\ifnum\c_math_kernpairs_attribute=\attributeunsetvalue \else
+ \clf_initializemathkernpairs % one time
+ \global\let\math_kernpairs_initialize\relax
+ \fi}
+
+\appendtoks
+ \edef\p_kernpairs{\mathematicsparameter\s!kernpairs}%
+ \c_math_kernpairs_attribute\ifx\p_kernpairs\v!yes\plusone\else\attributeunsetvalue\fi\relax
+\to \everyswitchmathematics % only in mathematics
+
+\appendtoks
+ \math_kernpairs_initialize
+ \attribute\mathkernpairsattribute\c_math_kernpairs_attribute
+\to \everymathematics
+
+\setupmathematics
+ [\s!kernpairs=\v!no]
+
%D \macros
%D {enablemathpunctuation,disablemathpunctuation}
%D
@@ -2084,16 +2149,53 @@
% if needed we can get rid of the normalize (predo in font code)
-\def\math_text_choice_font#1%
+% \def\math_text_choice_font#1#2#%
+% {\normalizebodyfontsize\m_math_text_choice_face{\mathstyleface\normalmathstyle}%
+% \hbox#2\bgroup
+% \font_basics_switchtobodyfont\m_math_text_choice_face
+% #1%
+% \let\next}
+
+% \def\math_text_choice_word#1#2#%
+% {\normalizebodyfontsize\m_math_text_choice_face{\mathstyleface\normalmathstyle}%
+% \hbox#2\bgroup
+% \font_basics_switchtobodyfont\m_math_text_choice_face
+% #1%
+% \nospacing % \normalnospaces\plusone
+% \let\next}
+
+%D We accept a low level box specification so that one can make helpers:
+%D
+%D \startbuffer
+%D \startformula
+%D \startalign[m=2,align={middle}]
+%D \NC \text to 6cm{One\hfill} \NC a = 1 \NR
+%D \NC \text to 6cm{One Two\hfill} \NC b = 2 \NR
+%D \NC \text to 6cm{One Two Three\hfill} \NC c = 3 \NR
+%D \stopalign
+%D \stopformula
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
+\def\math_text_choice_font#1#2#%
{\normalizebodyfontsize\m_math_text_choice_face{\mathstyleface\normalmathstyle}%
- \hbox\bgroup
+ \hbox#2\bgroup
+ \bgroup
+ \aftergroup\hss
+ \aftergroup\egroup
+ \hss
\font_basics_switchtobodyfont\m_math_text_choice_face
#1%
\let\next}
-\def\math_text_choice_word#1%
+\def\math_text_choice_word#1#2#%
{\normalizebodyfontsize\m_math_text_choice_face{\mathstyleface\normalmathstyle}%
- \hbox\bgroup
+ \hbox#2\bgroup
+ \bgroup
+ \aftergroup\hss
+ \aftergroup\egroup
+ \hss
\font_basics_switchtobodyfont\m_math_text_choice_face
#1%
\nospacing % \normalnospaces\plusone
@@ -2155,9 +2257,7 @@
\newtoks\mathdisplayaligntweaks
-\appendtoks
- \resetdisplaymatheq % moved to here
-\to \mathdisplayaligntweaks
+% this can become an option:
\unexpanded\def\math_display_align_hack % I don't like the global, maybe we should push and pop
{\global\let\math_display_align_hack_indeed\math_display_align_hack_remove_skip
@@ -2418,6 +2518,21 @@
\setupmathematics
[\s!italics=3] % for the moment only this one makes sense .. still experimental
+%D For special purposed we set this one:
+
+\installcorenamespace{mathrules}
+
+\unexpanded\def\enablemathrules{\global\letvalue{\??mathrules\fontclass}\plusone}
+
+\appendtoks
+ \mathrulesmode\ifcsname\??mathrules\fontclass\endcsname
+ \lastnamedcs
+ \else
+ \zerocount
+ \fi
+ \mathrulesfam\zerocount
+\to \everymathematics
+
\protect \endinput
% % not used (yet)