%D \module %D [ file=math-fen, %D version=2012.02.18, %D title=\CONTEXT\ Math Macros, %D subtitle=Fences, %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. % 0x -> " \writestatus{loading}{ConTeXt Math Macros / Fences} \unprotect % todo: mathstyle % \definemathfence [fancybracket] [bracket] [command=yes,color=blue] % % test $|x|$ test \par % test $||x||$ test (okay) \par % test $a\left|\frac{1}{b}\right|c$ test \par % test $a\left||\frac{1}{b}\right||c$ test (not okay) \par % % \setupmathfences [color=red] % % test $a\fenced[bar]{\frac{1}{b}}c$ test \par % test $a\fenced[doublebar]{\frac{1}{b}}c$ test \par % test $a\fenced[bracket]{\frac{1}{b}}c$ test \par % test $a\fancybracket{\frac{1}{b}}c$ test \par \installcorenamespace{mathfences} \installcommandhandler \??mathfences {mathfence} \??mathfences \let\setupmathfences\setupmathfence \setupmathfences [\c!left=0x2E, \c!right=0x2E, \c!middle=0x2E, \c!mathstyle=, \c!color=, \c!command=] \appendtoks \edef\p_command{\mathfenceparameter\c!command}% \ifx\p_command\v!yes \setuevalue\currentmathfence{\math_fenced_fenced[\currentmathfence]}% \fi \to \everydefinemathfence % no Uchar here: \def\math_fenced_left {\math_fenced_color_push\normalleft \utfchar{\mathfenceparameter\c!left }\math_fenced_color_pop} \def\math_fenced_middle{\mskip\thinmuskip \math_fenced_color_push\normalmiddle\utfchar{\mathfenceparameter\c!middle}\math_fenced_color_pop \mskip\thinmuskip} \def\math_fenced_right {\math_fenced_color_push\normalright \utfchar{\mathfenceparameter\c!right }\math_fenced_color_pop} \def\math_fenced_color_do_push{\pushcolor[\p_math_fenced_color]} \let\math_fenced_color_do_pop \popcolor \let\fence \relax \let\fenced\relax \unexpanded\def\math_fenced_fenced[#1]#2% {\begingroup \edef\currentmathfence{#1}% \startusemathstyleparameter\mathfenceparameter \let\fence\math_fenced_middle \edef\p_math_fenced_color{\mathfenceparameter\c!color}% \ifx\p_math_fenced_color\empty \let\math_fenced_color_push\donothing \let\math_fenced_color_pop \donothing \else \let\math_fenced_color_push\math_fenced_color_do_push \let\math_fenced_color_pop \math_fenced_color_do_pop \fi \math_fenced_left #2% \math_fenced_right \stopusemathstyleparameter \endgroup} \appendtoks \let\fenced\math_fenced_fenced \to \everymathematics \definemathfence [parenthesis] [\c!left=0x0028,\c!right=0x0029] \definemathfence [bracket] [\c!left=0x005B,\c!right=0x005D] \definemathfence [braces] [\c!left=0x007B,\c!right=0x007D] \definemathfence [bar] [\c!left=0x007C,\c!right=0x007C] \definemathfence [doublebar] [\c!left=0x2016,\c!right=0x2016] \definemathfence [angle] [\c!left=0x003C,\c!right=0x003E] %definemathfence [fancybracket] [bracket] [command=yes,color=red] % experimental accents: % % \definemathoverextensible [top] [hoed] ["FE302] % \definemathoverextensible [top] [slang] ["FE303] \protect