1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
%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.
\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}
\installcorenamespace{mathfencesleft}
\installcorenamespace{mathfencesmiddle}
\installcorenamespace{mathfencesright}
\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
\def\math_fenced_left {\normalleft \utfchar{\mathfenceparameter\c!left }} % no Uchar here
\def\math_fenced_middle{\normalmiddle\utfchar{\mathfenceparameter\c!middle}} % no Uchar here
\def\math_fenced_right {\normalright \utfchar{\mathfenceparameter\c!right }} % no Uchar here
\let\fence \relax
\let\fenced\relax
\unexpanded\def\math_fenced_fenced[#1]%
{\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
\expandafter\math_fenced_normal
\else
\expandafter\math_fenced_colored
\fi}
\def\math_fenced_normal#1%
{\math_fenced_left
#1%
\math_fenced_right
\stopusemathstyleparameter
\endgroup}
\def\math_fenced_colored#1%
{\pushcolor[\p_math_fenced_color]%
\math_fenced_left
\popcolor
#1%
\pushcolor[\p_math_fenced_color]%
\math_fenced_right
\popcolor
\stopusemathstyleparameter
\endgroup}
\appendtoks
\let\fenced\math_fenced_fenced
\to \everymathematics
\definemathfence [parenthesis] [\c!left=0x28,\c!right=0x29]
\definemathfence [bracket] [\c!left=0x5B,\c!right=0x5D]
\definemathfence [braces] [\c!left=0x7B,\c!right=0x7D]
\definemathfence [bar] [\c!left=0x7C,\c!right=0x7C]
\definemathfence [doublebar] [\c!left=0x2016,\c!right=0x2016]
\definemathfence [angle] [\c!left=0x3C,\c!right=0x3E]
%definemathfence [fancybracket] [bracket] [command=yes,color=red]
\protect
|