%D \module %D [ file=math-ini, %D version=2008.01.02, %D title=\CONTEXT\ Math Macros, %D subtitle=Initializations, %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. \writestatus{loading}{ConTeXt Math Macros / Initializations} %D This module provides namespaces for math fonts, thereby %D permitting mixed usage of math fonts. Although not strictly %D needed, we also provide a family name mapping mechanism as %D used in the (original) AMS math definition files, but here %D these names can recursively be remapped and if needed, %D dynamically be changed. We've tried to minimize the number %D of definition commands and use plain \TEX\ definitions as %D fallback. We've tried to follow a couple of conventions %D from plain and AMS math in order to achieve backward %D compatinility. We also kept an eye on future usage of these %D modules in the perspective of MathML and unicode fonts. \unprotect %D We move these definitions into the format: % test [[\char948 \cldcontext{utf.char(948)}]] % test $[[\char948 \cldcontext{utf.char(948)}]]$ \registerctxluafile{math-ini}{1.001} \registerctxluafile{math-dim}{1.001} \registerctxluafile{math-act}{1.001} \registerctxluafile{math-ext}{1.001} \registerctxluafile{math-vfu}{1.001} \registerctxluafile{math-map}{1.001} \registerctxluafile{math-ren}{1.001} \registerctxluafile{math-noa}{1.001} \registerctxluafile{math-tag}{1.001} \definesystemattribute[mathalphabet] [public] \definesystemattribute[mathsize] [public] \definesystemattribute[mathpunctuation][public] \definesystemattribute[mathgreek] [public] \definesystemattribute[mathalternate] [public] \definesystemattribute[mathrendering] [public] \definesystemattribute[mathcategory] [public] \definesystemattribute[mathmode] [public] \definesystemattribute[mathitalics] [public] \appendtoks \attribute\mathmodeattribute\plusone \to \everydisplay \appendtoks \attribute\mathmodeattribute\plusone \to \everybeforedisplayformula \setnewconstant\defaultmathfamily \zerocount % 255 %D \macros %D {setupmathematics} %D %D Configuration for integrals. (If needed we can speed this up and make it %D installable; no processaction is needed then). \newtoks\everysetupmathematics \unexpanded\def\setupmathematics {\dosingleargument\dosetupmathematics} \def\dosetupmathematics[#1]% {\getparameters[\??mo][#1]% \the\everysetupmathematics} \def\mathematicsparameter#1% {\ifcsname\??mo#1\endcsname\csname\??mo#1\endcsname\fi} % Normally this is applied to only one character. % % $ABC$ $\cal ABC$ $\mathaltcal ABC$ % todo: only in mmode \unexpanded\def\mathgreekupright{\attribute\mathgreekattribute22 } \unexpanded\def\mathgreekitalic {\attribute\mathgreekattribute33 } \unexpanded\def\mathgreekdefault{\attribute\mathgreekattribute\attributeunsetvalue} \let\mathgreeknormal\mathgreekupright \let\mathgreeknone \mathgreekdefault \def\setmathattribute#1#2{\ifmmode\ctxcommand{setmathattribute("#1","#2")}\fi} \def\setmathalphabet #1{\ifmmode\ctxcommand{setmathalphabet("#1")}\fi} \def\setmathstyle #1{\ifmmode\ctxcommand{setmathstyle("#1")}\fi} \def\setmathalternate #1{\ifmmode\ctxcommand{setmathalternate(\number\defaultmathfamily,"#1")}\fi} \def\setmathstylealterternate#1% {\ifcsname\??mo:\c!alternative:\fontclass:#1\endcsname \setmathalternate{\csname\??mo:\c!alternative:\fontclass:#1\endcsname}% \else\ifcsname\??mo:\c!alternative:#1\endcsname \setmathalternate{\csname\??mo:\c!alternative:#1\endcsname}% \fi\fi} \unexpanded\def\setupmathrendering % the name might change {\dodoubleargument\dosetupmathrendering} \def\dosetupmathrendering[#1][#2]% {\ifsecondargument \getparameters[\??mo:\c!alternative:#1:][#2]% \else \getparameters[\??mo:\c!alternative:][#1]% \fi} \def\mathaltcal{\setmathalternate{cal}\cal} % ss01 in xits \let\mathalternate\setmathalternate % obsolete \unexpanded\def\mr {\setmathattribute\s!regular\c!tf\setmathstylealterternate\s!tf} \unexpanded\def\mathdefault {\setmathattribute\s!regular\c!it\setmathstylealterternate\s!it} \unexpanded\def\mathscript {\setmathalphabet \s!script \setmathstylealterternate\s!script} \unexpanded\def\mathfraktur {\setmathalphabet \s!fraktur \setmathstylealterternate\s!fraktur} \unexpanded\def\mathblackboard{\setmathalphabet \s!blackboard \setmathstylealterternate\s!blackboard} \unexpanded\def\mathrm {\setmathattribute\s!rm\c!tf \setmathstylealterternate\s!tf} \unexpanded\def\mathss {\setmathattribute\s!ss\c!tf \setmathstylealterternate\s!tf} \unexpanded\def\mathtt {\setmathattribute\s!tt\c!tf \setmathstylealterternate\s!tf} \unexpanded\def\mathtf {\setmathstyle\s!tf \setmathstylealterternate\s!tf} \unexpanded\def\mathsl {\setmathstyle\s!it \setmathstylealterternate\s!it} % no sl \unexpanded\def\mathit {\setmathstyle\s!it \setmathstylealterternate\s!it} \unexpanded\def\mathbf {\setmathstyle\s!bf \setmathstylealterternate\s!bf} \unexpanded\def\mathbs {\setmathstyle\s!bi \setmathstylealterternate\s!bi} % no sl \unexpanded\def\mathbi {\setmathstyle\s!bi \setmathstylealterternate\c!bi} \let\tfmath\mathtf % maybe a grouped command \let\slmath\mathsl \let\itmath\mathit \let\bfmath\mathbf \let\bsmath\mathbs \let\bimath\mathbi \let\Bbb\mathblackboard \unexpanded\def\frak {\ifmmode\expandafter\mathfraktur \fi} \unexpanded\def\cal {\ifmmode\expandafter\mathscript \fi} \unexpanded\def\bbd {\ifmmode\expandafter\mathblackboard\fi} \unexpanded\def\blackboard{\ifmmode\expandafter\mathblackboard\fi} \unexpanded\def\fraktur {\ifmmode\expandafter\mathfraktur \fi} \unexpanded\def\gothic {\ifmmode\expandafter\mathfraktur \fi} \unexpanded\def\mathcal #1{{\mathscript #1}} % for AMS compatibility \unexpanded\def\mathfrak#1{{\mathfraktur #1}} % for AMS compatibility \unexpanded\def\mathbb #1{{\mathblackboard#1}} % for AMS compatibility \let\normalmr\mr \let\normaltf\tf \unexpanded\def\tf{\ifmmode\mathtf\else\normaltf\fi} \let\normalbf\bf \unexpanded\def\bf{\ifmmode\mathbf\else\normalbf\fi} \let\normalit\it \unexpanded\def\it{\ifmmode\mathit\else\normalit\fi} \let\normalsl\sl \unexpanded\def\sl{\ifmmode\mathsl\else\normalsl\fi} \let\normalbi\bi \unexpanded\def\bi{\ifmmode\mathbi\else\normalbi\fi} \let\normalbs\bs \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\mr{\ifmmode \normalmr\fi} \prependtoks \mathdefault \to \everymathematics %D We could set the rendering attribute at the \LUA\ end but as there %D can be many small math snippets we keep track of the state at the %D \TEX\ end (mapping is export safe). %D %D \starttyping %D \startformula %D \reals {\mathbf R} \utfchar{"0211D} \utfchar{"1D411} %D \stopformula %D %D \setupmathematics %D [symbolset=blackboard-to-bold] %D %D \startformula %D \reals {\mathbf R} \utfchar{"0211D} \utfchar{"1D411} %D \stopformula %D \stoptyping \newcount\math_renderings_attribute \appendtoks \math_renderings_attribute\cldcontext{mathematics.renderset("\mathematicsparameter\c!symbolset")}\relax \to \everysetupmathematics \appendtoks \ifcase\math_renderings_attribute\else \attribute\mathrenderingattribute\math_renderings_attribute \fi \to \everymathematics \setupmathematics [\c!symbolset=] %D \macros %D {boldsymbol} %D %D To be done. \let\mathboldsymbol\relax % yet unsupported, will be \def\boldsymbol {\mathortext\mathboldsymbol\bold} %D Helpers: \def\utfmathclass #1{\cldcontext{mathematics.utfmathclass (\!!bs#1\!!es)}} \def\utfmathstretch#1{\cldcontext{mathematics.utfmathstretch(\!!bs#1\!!es)}} \def\utfmathcommand#1{\cldcontext{mathematics.utfmathcommand(\!!bs#1\!!es)}} \def\utfmathfiller #1{\cldcontext{mathematics.utfmathfiller (\!!bs#1\!!es)}} \def\@@mathlimopcomm #1{\mathop{#1}} %no \limits \def\@@mathnolopcomm #1{\mathop{#1}\nolimits} \def\@@mathboxcomm #1{\dontleavehmode\hbox\Ustartmath\mathsurround\zeropoint#1\Ustopmath} \def\@@mathchoicecomm#1{[todo #1]} \setnewconstant\mathordcode 0 \let\mathordcomm \mathord \setnewconstant\mathopcode 1 \let\mathopcomm \mathop \setnewconstant\mathbincode 2 \let\mathbincomm \mathbin \setnewconstant\mathrelcode 3 \let\mathrelcomm \mathrel \setnewconstant\mathopencode 4 \let\mathopencomm \mathopen \setnewconstant\mathclosecode 5 \let\mathclosecomm \mathclose \setnewconstant\mathpunctcode 6 \let\mathpunctcomm \mathpunct \setnewconstant\mathalphacode 7 \let\mathalphacomm \firstofoneargument \setnewconstant\mathinnercode 0 \let\mathinnercomm \mathinner \setnewconstant\mathnothingcode 0 \let\mathnothingcomm \firstofoneargument \setnewconstant\mathlimopcode 1 \let\mathlimopcomm \@@mathlimopcomm \setnewconstant\mathnolopcode 1 \let\mathnolopcomm \@@mathnolopcomm \setnewconstant\mathchoicecode 0 \let\mathchoicecomm \@@mathchoicecomm \setnewconstant\mathboxcode 0 \let\mathboxcomm \@@mathboxcomm \setnewconstant\mathaccentcode 8 \setnewconstant\mathradicalcode 9 \def\puremathcode#1{\the\csname math#1code\endcsname} \def\puremathcomm#1{\csname math#1comm\endcsname} % \startlines % $\mathopnolimits{\rm d}x$ % $\mathopnolimits{\kern\zeropoint \rm d}x$ % $\puremathcomm{nolop}{\rm d}x$ % $\puremathcomm{nolop}{\kern\zeropoint\rm d}x$ % \blank % $\puremathcomm{nolop}{\mr d}x$ % $\puremathcomm{nolop}{\kern\zeropoint\mr d}x$ % $\mathop{\kern\zeropoint\mr d}x$ % $\mathopnolimits{\kern\zeropoint d}x$ % \stoplines % this will be sorted out: % \let\mathcharacter \getvalue % \let\textcharacter \getvalue % % \unexpanded\def\definefamilysynonym {\dotripleempty\dodefinefamilysynonym} % \def\dodefinefamilysynonym [#1][#2][#3]{} % \unexpanded\def\definemathsymbol {\dosixtupleempty\dodefinemathsymbol} % \def\dodefinemathsymbol [#1][#2][#3][#4][#5][#6]{} % \unexpanded\def\definemathcharacter {\dosixtupleempty\dodefinemathcharacter} % \def\dodefinemathcharacter [#1][#2][#3][#4][#5][#6]{} \unexpanded\def\definemathcommand {\dotripleempty\dodefinemathcommand} % \def\dodefinemathcommand[#1][#2][#3]#4% command class args meaning % {\ifthirdargument % \edef\nofmathcommandarguments{#3}% % \ifx\nofmathcommandarguments\v!one % \setuvalue{#1}##1{\puremathcomm{#2}{#4{##1}}}% % \else\ifx\nofmathcommandarguments\v!two % \setuvalue{#1}##1##2{\puremathcomm{#2}{#4{##1}{##2}}}% % \else % \setuvalue{#1}{\puremathcomm{#2}{#4}}% % \fi\fi % \else\ifsecondargument % \setuvalue{#1}{\puremathcomm{#2}{#4}}% % \else % \setuvalue{#1}{\puremathcomm{nothing}{#4}}% % \fi\fi} \def\dodefinemathcommand[#1][#2][#3]#4% command class args meaning {\ifthirdargument \edef\nofmathcommandarguments{#3}% \ifx\nofmathcommandarguments\v!one \setuvalue{\??mo::#1}##1{\puremathcomm{#2}{#4{##1}}}% \else\ifx\nofmathcommandarguments\v!two \setuvalue{\??mo::#1}##1##2{\puremathcomm{#2}{#4{##1}{##2}}}% \else \setuvalue{\??mo::#1}{\puremathcomm{#2}{#4}}% \fi\fi \else\ifsecondargument \setuvalue{\??mo::#1}{\puremathcomm{#2}{#4}}% \else \setuvalue{\??mo::#1}{\puremathcomm{nothing}{#4}}% \fi\fi \letcsnamecsname\csname#1\endcsname\csname\??mo::#1\endcsname} \unexpanded\def\mathcommand#1% {\csname\??mo::#1\endcsname} %D Moved from font-ini.mkiv: %D %D \macros %D {mf,mbox,enablembox,mathop} %D %D Todo: \unexpanded\def\mf {\csname\fontalternative\endcsname} \let\normalmathop\mathop \unexpanded\def\mathop {\normalmathop \bgroup \let\rm\mf \let\next=} \def\normalmbox {\normalhbox\bgroup\mf \dowithnextbox{\flushnextbox\egroup}\normalhbox} \def\mbox % we cannot add \dontleavehmode ... else no \setbox0\mbox possible {\ifmmode\normalmbox\else\normalhbox\fi} \unexpanded\def\enablembox {\appendtoks \ifx\normalhbox\undefined\let\normalhbox\hbox\fi \let\hbox\mbox \to\everymathematics} %D The next hack is needed needed for sine, cosine etc. \let\mathfunction\firstofoneargument \let\taggedmathfunction \firstofoneargument \let\taggedmathfunctionlabeltext\mathlabeltext \let\taggedmathmo\firstofoneargument \let\taggedmathmi\firstofoneargument \def\taggedmathmn#1{\begingroup\mr#1\endgroup} \def\taggedmathms#1{\begingroup\mr#1\endgroup} \def\mfunction #1{{\mr\taggedmathfunction{#1}}} \def\mfunctionlabeltext#1{{\mr\taggedmathfunctionlabeltext{#1}}} % Once this is stable we can store the number at the tex end which is % faster. Functions getnumbers >= 1000. \def\dotaggedmathfunction #1{\ctxcommand{taggedmathfunction("#1",false,\ifconditional\c_apply_function true\else false\fi)}} \def\dotaggedmathfunctionlabeltext#1{\ctxcommand{taggedmathfunction("#1",true ,\ifconditional\c_apply_function true\else false\fi)}} \def\dotaggedmo#1{\begingroup \attribute\mathcategoryattribute\plusone #1\endgroup} \def\dotaggedmi#1{\begingroup \attribute\mathcategoryattribute\plustwo #1\endgroup} \def\dotaggedmn#1{\begingroup\mr\attribute\mathcategoryattribute\plusthree#1\endgroup} \def\dotaggedms#1{\begingroup\mr\attribute\mathcategoryattribute\plusfour #1\endgroup} \newconditional\c_apply_function \def\taggedmathapply#1#2% {\begingroup \settrue\c_apply_function #1% \endgroup \begingroup % todo: auto () #2% \endgroup} \appendtoks \let\taggedmathfunction \dotaggedmathfunction \let\taggedmathfunctionlabeltext\dotaggedmathfunctionlabeltext \let\taggedmathmo \dotaggedmo \let\taggedmathmi \dotaggedmi \let\taggedmathmn \dotaggedmn \let\taggedmathms \dotaggedms \to \everyenableelements \appendtoks \let\mo \taggedmathmo \let\mi \taggedmathmi \let\mn \taggedmathmn \let\ms \taggedmathms \let\apply\taggedmathapply \to\everymathematics % \def\mlimitsfunction #1{\mathlimopcomm{{\mr#1}} % \def\mnolimitsfunction#1{\mathnolopcomm{{\mr#1}} %D Taco posted this solution as response to a mail by Olivier, so %D let's integrate it here. \def\currentmscaledstyle{rm} % will be plugged into the typeface text=ss option \unexpanded\def\do@mathopnolimits #1{\mathop{\mscaledtext{#1}}\nolimits} \unexpanded\def\do@mfunction #1{\mscaledtext{\taggedmathfunction{#1}}} \unexpanded\def\do@mfunctionlabeltext#1{\mscaledtext{\taggedmathfunctionlabeltext{#1}}} \def\setmathfunctionstyle#1% rm ss tt (can be made faster if needed) {\doifsomething{#1} {\def\currentmscaledstyle{#1}% \let\mathopnolimits \do@mathopnolimits \let\mfunction \do@mfunction \let\mfunctionlabeltext\do@mfunctionlabeltext}} \def\mscaledtext#1% {\mathchoice {\hbox{\csname\currentmscaledstyle\endcsname\tf #1}} {\hbox{\csname\currentmscaledstyle\endcsname\tf #1}} {\hbox{\csname\currentmscaledstyle\endcsname\tfx #1}} {\hbox{\csname\currentmscaledstyle\endcsname\tfxx#1}}} %D We can force the way functions are typeset by manipulating the text %D option: %D %D \starttyping %D \definetypeface[iwona][ss][sans][iwona][default][encoding=texnansi] %D \definetypeface[iwona][mm][math][iwona][default][encoding=texnansi,text=ss] %D \stoptyping %D %D This hooks into the math handler with: % no longer supported this way, has to be done with \setupmathematics % % \appendtoks % \setmathfunctionstyle\currentmathtextstyle % \to \everybodyfont %D Usage: %D %D \starttyping %D \setmathfunctionstyle\fontstyle % or {rm} or {ss} or .. %D \rm test $\sin{(x^{\sin(x^{\sin(x)})})}$ test %D \ss test $\sin{(x^{\sin(x^{\sin(x)})})}$ test %D \tt test $\sin{(x^{\sin(x^{\sin(x)})})}$ test %D \stoptyping %D Some goodies: \def\Angstrom{\nomathematics{\Aring}} %D \macros %D {nonknuthmode, donknuthmode} %D %D The underscore is frequently used in manuals but unfortunately \TEX\ prefers %D it to be a math specific character. And since computer modern fonts didn't %D have an underscore, one had to use commands to fake one. Nowadays we do %D have underscores in latin modern, and since all other fonts have them, we %D decided to get away from the restriction to use the underscore character in %D text mode. %D %D \starttyping %D \def\test#1{#1} %D %D \nonknuthmode $x_2$ x_2 \test{$x_2$} \test{x_2} %D %D \donknuthmode $x_2$ x_2 \test{$x_2$} \test{x_2} %D \stoptyping %D %D The result is as expected: the first line typesets ok, while the second %D one triggers an error message. \setnewconstant\activemathcharcode "8000 \newtoks\activatedmathcharacters \def\activatemathcharacter#1% {\appendtoks \global\mathcode#1=\activemathcharcode \to \activatedmathcharacters} \def\activatemathcharacters {\the\activatedmathcharacters} \setnewconstant\primeasciicode 39 % ' \activatemathcharacter\circumflexasciicode \activatemathcharacter\underscoreasciicode \activatemathcharacter\ampersandasciicode \activatemathcharacter\primeasciicode % not used: % % \mathcode\spaceasciicode\activemathcharcode % % not used: % % \bgroup % \catcode\underscoreasciicode\activecatcode % \doglobal\appendtoks % \mathcode\underscoreasciicode\activemathcharcode % \let_\activemathunderscore % \to \everymathematics % \egroup % % plain tex legacy: \bgroup \catcode\primeasciicode\activecatcode \doglobal\appendtoks \let'\domathprime % todo: do this at the lua end \to \everymathematics \egroup \bgroup \catcode\underscoreasciicode\activecatcode \catcode\circumflexasciicode\activecatcode \catcode\ampersandasciicode \activecatcode \doglobal \appendtoks \let_\normalsubscript \let^\normalsuperscript \let&\normalmathaligntab % use \def when it's \aligntab \to \everymathematics \egroup \newtoks\everydonknuthmode \newtoks\everynonknuthmode \newconditional \knuthmode \let\nonknuthmode\relax \let\donknuthmode\relax % \def\nonknuthmode % {\pushcatcodetable % \setcatcodetable\ctxcatcodes % \the\everynonknuthmode % \let\nonknuthmode\relax % \popcatcodetable} % % \def\donknuthmode % {\pushcatcodetable % \setcatcodetable\ctxcatcodes % \the\everydonknuthmode % \popcatcodetable} % % \bgroup % % \catcode\underscoreasciicode\activecatcode % \catcode\circumflexasciicode\activecatcode % \catcode\ampersandasciicode \activecatcode % % \global \everynonknuthmode {\appendtoks % \let_\normalsubscript % \let^\normalsuperscript % \let&\normalmathaligntab % use \def when it's \aligntab % \to \everymathematics} % % \egroup % % \appendtoks % \setfalse\knuthmode % \catcode\underscoreasciicode\othercatcode % \catcode\circumflexasciicode\othercatcode % \catcode\ampersandasciicode \othercatcode % \to \everynonknuthmode % % \appendtoks % \settrue\knuthmode % \catcode\underscoreasciicode\subscriptcatcode % \catcode\circumflexasciicode\superscriptcatcode % \catcode\ampersandasciicode \alignmentcatcode % \to \everydonknuthmode % % \appendtoks % \startextendcatcodetable\ctxcatcodes % \catcode\underscoreasciicode\othercatcode % \catcode\circumflexasciicode\othercatcode % \catcode\ampersandasciicode \othercatcode % \stopextendcatcodetable % \to \everynonknuthmode % % \appendtoks % \startextendcatcodetable\ctxcatcodes % \catcode\underscoreasciicode\subscriptcatcode % \catcode\circumflexasciicode\superscriptcatcode % \catcode\ampersandasciicode \alignmentcatcode % \stopextendcatcodetable % \to \everydonknuthmode %D Even more drastic (this code will move as nonknuthmode is default now) % \unexpanded\def\enableasciimode % {\ctxlua{resolvers.macros.enablecomment()}% % \glet\enableasciimode\relax} % % \unexpanded\def\asciimode % {\catcodetable\txtcatcodes % \enableasciimode % \nonknuthmode} % % \unexpanded\def\startasciimode % {\pushcatcodetable % \catcodetable\txtcatcodes % \enableasciimode % \nonknuthmode} % % \unexpanded\def\stopasciimode % {\popcatcodetable % \ifconditional\knuthmode\else\donknuthmode\fi} \unexpanded\def\enableasciimode {\ctxlua{resolvers.macros.enablecomment()}% \glet\enableasciimode\relax} \unexpanded\def\asciimode {\catcodetable\txtcatcodes \enableasciimode} \unexpanded\def\startasciimode {\pushcatcodetable \catcodetable\txtcatcodes \enableasciimode} \unexpanded\def\stopasciimode {\popcatcodetable} %D Needed for unicode: \def\nulloperator{\mathortext{\mathop{\emptyhbox}}{\emptyhbox}} %D Memory saver: \appendtoks \doifelse{\mathematicsparameter\c!compact}\v!yes {\enabledirectives [math.virtual.optional]}% {\disabledirectives[math.virtual.optional]}% \to \everysetupmathematics \setupmathematics [\c!compact=no] %D Arabic: \newconditional\mathematics_right_to_left \appendtoks \doifelse{\mathematicsparameter\c!align}{r2l}% {\settrue \mathematics_right_to_left}% {\setfalse\mathematics_right_to_left}% \to \everysetupmathematics \unexpanded\def\mathematics_synchronize_direction {\mathdir T\ifconditional\mathematics_right_to_left R\else L\fi T} \appendtoks \mathematics_synchronize_direction %to \everymathematics % comes too late and I'm not in the mood for a mixed mode kludge now \to \everysetupmathematics %D Delayed: greek. %D %D \starttyping %D \usetypescript[cambria]\setupbodyfont[cambria] %D \startTEXpage %D $\alpha \mathgreekupright \alpha \mathgreekitalic \alpha$ %D \stopTEXpage %D \stoptyping % [lc uc] normal (upright) = 2, italic = 3, none = 0/1 \setevalue{\??mo:greek:\v!normal :\v!normal}{\attribute\mathgreekattribute22 } \setevalue{\??mo:greek:\v!normal :\v!italic}{\attribute\mathgreekattribute23 } \setevalue{\??mo:greek:\v!normal :\v!none }{\attribute\mathgreekattribute21 } \setevalue{\??mo:greek:\v!italic :\v!normal}{\attribute\mathgreekattribute32 } \setevalue{\??mo:greek:\v!italic :\v!italic}{\attribute\mathgreekattribute33 } \setevalue{\??mo:greek:\v!italic :\v!none }{\attribute\mathgreekattribute31 } \setevalue{\??mo:greek:\v!none :\v!normal}{\attribute\mathgreekattribute12 } \setevalue{\??mo:greek:\v!none :\v!italic}{\attribute\mathgreekattribute13 } \setevalue{\??mo:greek:\v!none :\v!none }{\attribute\mathgreekattribute\attributeunsetvalue} \appendtoks \csname\??mo:greek:\@@molcgreek:\@@moucgreek\endcsname \to \everymathematics % todo: field specific sets in order to avoid option mess \setupmathematics [lcgreek=\v!italic, ucgreek=\v!normal] % was: none %D Math italics (experiment) % we need keys \setevalue{\??mo:italics:1}{\attribute\mathitalicsattribute\plusone } % fontitalics \setevalue{\??mo:italics:2}{\attribute\mathitalicsattribute\plustwo } % fontdata \setevalue{\??mo:italics:3}{\attribute\mathitalicsattribute\plusthree} % quad based \setevalue{\??mo:italics:4}{\attribute\mathitalicsattribute\plusfour } % combination of 1 and 3 \setupmathematics [italics=] \appendtoks \doifsomething\@@moitalics{\ctxlua{mathematics.setitalics()}}% \to \everysetupmathematics \appendtoks \csname\??mo:italics:\@@moitalics\endcsname \to \everymathematics %D \macros %D {enablemathpunctuation,disablemathpunctuation} %D %D \startbuffer %D \enablemathpunctuation$(1,2) (1, 2) (1{,}2) \hbox{foo, not bar}$ %D \stopbuffer %D %D \typebuffer %D %D \blank{\getbuffer}\blank \setfalse \automathpunctuation \def\enablemathpunctuation {\settrue \automathpunctuation} \def\disablemathpunctuation{\setfalse\automathpunctuation} \ifx\v!autopunctuation\undefined \def\v!autopunctuation{autopunctuation} \fi \appendtoks \doifelse{\mathematicsparameter\v!autopunctuation}\v!yes\enablemathpunctuation\disablemathpunctuation \to \everysetupmathematics \appendtoks \ifconditional\automathpunctuation\attribute\mathpunctuationattribute\plusone\fi \to \everymathematics \setupmathematics [\v!autopunctuation=\v!no] %D \macros %D {mathstyle} %D %D If one want to be sure that something is typeset in the %D appropriate style, \type {\mathstyle} can be used: %D %D \starttyping %D \mathstyle{something} %D \stoptyping % \def\mathstyle#1% % {\mathchoice % {\displaystyle #1}% % {\textstyle #1}% % {\scriptstyle #1}% % {\scriptscriptstyle#1}} % % We now have a primitive operation for this. As the % macro overloads a new primitive introduced in \LUATEX, % we need to use \type {\normalmathstyle} when we consult % the current math style. % % \let \mathstyle \Ustack % spoils cramped % % \let \mathstyle \firstofoneargument % % 0 = display % 1 = crampeddisplay % 2 = text % 3 = crampedtext % 4 = script % 5 = crampedscript % 6 = scriptscript % 7 = crampedscriptscript \def\uncramped#1% {{\ifcase\normalmathstyle \or \displaystyle \or \or \textstyle \or \or \scriptstyle \or \or \scriptscriptstyle \fi #1}} \def\cramped#1% {{\ifcase\normalmathstyle \crampeddisplaystyle \or \or % 0 -> 1 \crampedtextstyle \or \or % 2 -> 3 \crampedscriptstyle \or \or % 4 -> 5 \crampedscriptscriptstyle \fi % 6 -> 7 #1}} \def\triggermathstyle#1% #1 is number {\ifcase#1\relax \displaystyle \or \crampeddisplaystyle \or \textstyle \or \crampedtextstyle \or \scriptstyle \or \crampedscriptstyle \or \scriptscriptstyle \or \crampedscriptscriptstyle \else % error \fi} \def\cramped#1% {{\ifcase\normalmathstyle \crampeddisplaystyle \or \or % 0 -> 1 \crampedtextstyle \or \or % 2 -> 3 \crampedscriptstyle \or \or % 4 -> 5 \crampedscriptscriptstyle \fi % 6 -> 7 #1}} \def\mathstylefont#1% #1 is number (\normalmathstyle) {\ifcase#1\relax \textfont \or \textfont \or \textfont \or \textfont \or \scriptfont \or \scriptfont \or \scriptscriptfont \or \scriptscriptfont \else \textfont \fi\zerocount} %D Something similar can be used in the (re|)|definition %D of \type {\text}. This version is a variation on the one %D in the math module (see \type{m-math} and|/|or \type %D {m-newmat}). \unexpanded\def\mathtext {\mathortext\domathtext\hbox} \def\domathtext#1% {\mathchoice {\dodomathtext\displaystyle\textface {#1}}% {\dodomathtext\textstyle \textface {#1}}% {\dodomathtext\textstyle \scriptface {#1}}% {\dodomathtext\textstyle \scriptscriptface{#1}}} \def\dodomathtext#1#2#3% no \everymath ! %{\hbox{\everymath{#1}\switchtobodyfont [#2]#3}} % 15 sec {\hbox{\everymath{#1}\setcurrentfontbody{#2}#3}} % 3 sec (no math) %D Safeguard against redefinitions: \appendtoks \let\_\normalunderscore % is textunderscore or fakeunderscore \to \everymathematics %D Because we may overload \type {\text} in other (structuring) %D macros, we say: \appendtoks \let\text\mathtext \to \everymathematics %D The next code is derived from plain \TEX. \newcount\interdisplaylinepenalty \interdisplaylinepenalty=100 \newif\ifdt@p \def\displ@y {\global\dt@ptrue \openup\displayopenupvalue % was \openup\jot \everycr {\noalign {\ifdt@p \global\dt@pfalse \ifdim\prevdepth>-\thousandpoint \vskip-\lineskiplimit \vskip\normallineskiplimit \fi \else \penalty\interdisplaylinepenalty \fi}}} \let\normaldispl@y\displ@y \def\displ@y{\resetdisplaymatheq\normaldispl@y} \def\m@th{\mathsurround\zeropoint} % obsolete %D Text in math: \def\mathortext {\ifmmode \expandafter\firstoftwoarguments \else \expandafter\secondoftwoarguments \fi} % \defineactivecharacter _ {\mathortext{_}{\_}} text_text $a^2$ % force text mode, will be overloaded later \ifx\text\undefined \let\text\hbox \fi \def\mathoptext#1{\mathop{\text{#1}}} % for a while: \def\Umathbotaccent{\Umathaccent bottom } \protect \endinput