summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/math-frc.mkii
blob: 767c5ec5cea480aa662031fb11cf8a603819c878 (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
%D \module
%D   [       file=math-frc,
%D        version=2007.07.19,
%D          title=\CONTEXT\ Math Macros,
%D       subtitle=Fractions,
%D         author={Hans Hagen \& Taco Hoekwater \& Aditya Mahajan},
%D           date=\currentdate,
%D      copyright=\PRAGMA]
%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 / Fractions}

\unprotect

\unexpanded\def\exmthfont#1%
  {\symbolicsizedfont#1\plusone{MathExtension}}

\def\domthfrac#1#2#3#4#5#6#7%
  {\begingroup
   \mathsurround\zeropoint
   \setbox0\hbox{$#1 #6$}%
   \setbox2\hbox{$#1 #7$}%
   \dimen0\wd0
   \ifdim\wd2>\dimen0 \dimen0\wd2 \fi
   \setbox4\hbox to \dimen0{\exmthfont#2#3\leaders\hbox{#4}\hss#5}%
   \mathord{\vcenter{{\offinterlineskip
     \hbox to \dimen0{\hss\box0\hss}%
     \kern \ht4%
     \hbox to \dimen0{\hss\copy4\hss}%
     \kern \ht4%
     \hbox to \dimen0{\hss\box2\hss}}}}%
   \endgroup}

\def\domthsqrt#1#2#3#4#5%
  {\begingroup
   \mathsurround\zeropoint
   \setbox0\hbox{$#1 #5$}%
   \dimen0=1.05\ht0 \advance\dimen0 1pt  \ht0 \dimen0
   \dimen0=1.05\dp0 \advance\dimen0 1pt  \dp0 \dimen0
   \dimen0\wd0
   \setbox4\hbox to \dimen0{\exmthfont#2\leaders\hbox{#3}\hfill#4}%
   \delimitershortfall=0pt
   \nulldelimiterspace=0pt
   \setbox2\hbox{$\left\delimiter"0270370 \vrule height\ht0 depth \dp0 width0pt
                  \right.$}%
   \mathord{\vcenter{\hbox{\copy2
                           \rlap{\raise\dimexpr\ht2-\ht4\relax\copy4}\copy0}}}%
   \endgroup}

\unexpanded\def\mthfrac#1#2#3#4#5{\mathchoice
  {\domthfrac\displaystyle     \textface        {#1}{#2}{#3}{#4}{#5}}
  {\domthfrac\textstyle        \textface        {#1}{#2}{#3}{#4}{#5}}
  {\domthfrac\scriptstyle      \scriptface      {#1}{#2}{#3}{#4}{#5}}
  {\domthfrac\scriptscriptstyle\scriptscriptface{#1}{#2}{#3}{#4}{#5}}}

\unexpanded\def\mthsqrt#1#2#3{\mathchoice
  {\domthsqrt\displaystyle     \textface    {#1}{#2}{#3}}
  {\domthsqrt\textstyle        \textface    {#1}{#2}{#3}}
  {\domthsqrt\scriptstyle      \textface    {#1}{#2}{#3}}
  {\domthsqrt\scriptscriptstyle\textface    {#1}{#2}{#3}}}

%D Moved from math-new.tex (not that new anyway:

%D \macros
%D   {genfrac}
%D
%D [TH] The definition of \type {\genfrac} \& co. is not
%D trivial, because it allows some flexibility. This is
%D supposed to be a user||level command, but will fail quite
%D desparately if called outside math mode (\CONTEXT\ redefines
%D \type {\over})
%D
%D [HH] We clean up this macro a bit and (try) to make it
%D understandable. The expansion is needed for generating
%D the second argument to \type {\dogenfrac}, which is to
%D be a control sequence like \type {\over}.

\unexpanded\def\genfrac#1#2#3#4%
  {\edef\!!stringa
     {#1#2}%
   \expanded
     {\dogenfrac{#4}%
      \csname
        \ifx @#3@%
          \ifx\!!stringa\empty
            \strippedcsname\normalover
          \else
            \strippedcsname\normaloverwithdelims
          \fi
        \else
          \ifx\!!stringa\empty
            \strippedcsname\normalabove
          \else
            \strippedcsname\normalabovewithdelims
          \fi
        \fi
      \endcsname}%
     {#1#2#3}}

\def\dogenfrac#1#2#3#4#5%
  {{#1{\begingroup#4\endgroup#2#3\relax#5}}}

%D \macros
%D   {dfrac, tfrac, frac, dbinom, tbinom, binom}
%D
%D \startbuffer
%D $\dfrac {1}{2} \tfrac {1}{2} \frac {1}{2}$
%D $\dbinom{1}{2} \tbinom{1}{2} \binom{1}{2}$
%D \stopbuffer
%D
%D \typebuffer
%D
%D \getbuffer

\unexpanded\def\dfrac {\genfrac\empty\empty{}\displaystyle}
\unexpanded\def\tfrac {\genfrac\empty\empty{}\textstyle}
\unexpanded\def\frac  {\genfrac\empty\empty{}\donothing}

\unexpanded\def\dbinom{\genfrac()\zeropoint\displaystyle}
\unexpanded\def\tbinom{\genfrac()\zeropoint\textstyle}
\unexpanded\def\binom {\genfrac()\zeropoint\donothing}

\unexpanded\def\xfrac {\genfrac\empty\empty{}\scriptstyle}
\unexpanded\def\xxfrac{\genfrac\empty\empty{}\scriptscriptstyle}

\unexpanded\def\frac#1#2{\mathematics{\genfrac\empty\empty{}\donothing{#1}{#2}}}

%D \macros
%D   {cfrac}
%D
%D \startbuffer
%D $\cfrac{12}{3} \cfrac[l]{12}{3} \cfrac[c]{12}{3} \cfrac[r]{12}{3}$
%D $\cfrac{1}{23} \cfrac[l]{1}{23} \cfrac[c]{1}{23} \cfrac[r]{1}{23}$
%D \stopbuffer
%D
%D \typebuffer
%D
%D \getbuffer
%D
%D Now we can align every combination we want:
%D
%D \startbuffer
%D $\cfrac{12}{3} \cfrac[l]{12}{3} \cfrac[c]{12}{3} \cfrac[r]{12}{3}$
%D $\cfrac{1}{23} \cfrac[l]{1}{23} \cfrac[c]{1}{23} \cfrac[r]{1}{23}$
%D $\cfrac[cl]{12}{3} \cfrac[cc]{12}{3} \cfrac[cr]{12}{3}$
%D $\cfrac[lc]{1}{23} \cfrac[cc]{1}{23} \cfrac[rc]{1}{23}$
%D \stopbuffer
%D
%D \typebuffer
%D
%D \getbuffer

\definecomplexorsimple\cfrac

\def\simplecfrac     {\docfrac[cc]}
\def\complexcfrac[#1]{\docfrac[#1cc]}

\def\docfrac[#1#2#3]#4#5%
  {{\displaystyle
    \frac
      {\strut
       \ifx r#1\hfill\fi#4\ifx l#1\hfill\fi}%
      {\ifx r#2\hfill\fi#5\ifx l#2\hfill\fi}%
    \kern-\nulldelimiterspace}}

%D \macros
%D   {splitfrac, splitdfrac}
%D
%D Occasionally one needs to typeset multi||line fractions.
%D These commands use \tex{genfrac} to create such fractions.
%D
%D \startbuffer
%D \startformula
%D      a=\frac{
%D          \splitfrac{xy + xy + xy + xy + xy}
%D                    {+ xy + xy + xy + xy}
%D        }
%D        {z}
%D      =\frac{
%D          \splitdfrac{xy + xy + xy + xy + xy}
%D                    {+ xy + xy + xy + xy}
%D        }
%D        {z}
%D \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D These macros are based on Michael J.~Downes posting on
%D comp.text.tex on 2001/12/06

\unexpanded\def\splitfrac#1#2%
  {\genfrac\empty\empty\zeropoint\textstyle%
     {\textstyle#1\quad\hfill}%
     {\textstyle\hfill\quad\mathstrut#2}}

\unexpanded\def\splitdfrac#1#2%
  {\genfrac\empty\empty\zeropoint\displaystyle%
     {#1\quad\hfill}
     {\hfill\quad\mathstrut #2}}

%D For thee moment here, but it might move:

%D \macros
%D   {qedsymbol}
%D
%D [HH] The general Quod Erat Domonstrandum symbol is defined
%D in such a way that we can configure it. Because this symbol
%D is also used in text mode, we make it a normal text symbol
%D with special behavior.

\unexpanded\def\qedsymbol#1%
  {\ifhmode
     \unskip~\hfill#1\par
   \else\ifmmode
     \eqno#1\relax % Do we really need the \eqno here?
   \else
     \leavevmode\hbox{}\hfill#1\par
   \fi\fi}

\definesymbol [qed] [\qedsymbol{\mathematics{\square}}]

%D \macros
%D   {QED}
%D
%D [HH] For compatbility reasons we also provide the \type
%D {\QED} command. In case this command is overloaded, we still
%D have the symbol available. \symbol[qed]

\unexpanded\def\QED{\symbol[qed]}

%D \macros
%D  {mathhexbox}
%D
%D [TH] \type {\mathhexbox} is also user||level (already
%D defined in Plain \TEX). It allows to get a math character
%D inserted as if it was a text character.

\unexpanded\def\mathhexbox#1#2#3%
  {\mathtext{$\mathsurround\zeropoint\mathchar"#1#2#3$}}

%D \macros
%D   {boxed}
%D
%D [HH] Another macro that users expect (slightly adapted):

\unexpanded\def\boxed
  {\ifmmode\expandafter\mframed\else\expandafter\framed\fi}

\protect \endinput