summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/math-frc.mkiv
blob: 59bd588c0b522d7167438d182b0f7d48349b8a0e (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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
%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},
%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 / Fractions}

\unprotect

% quite old ... still needed?

%D \macros
%D   {frac, xfrac, xxfrac}
%D
%D This is another one Tobias asked for. It replaces the
%D primitive \type {\over}. We also take the opportunity to
%D handle math style restoring, which makes sure units and
%D chemicals come out ok.
%D The \type {\frac} macro kind of replaces the awkward \type
%D {\over} primitive. Say that we have the following formulas:
%D
%D \startbuffer[sample]
%D test $\frac  {1}{2}$ test $$1 + \frac  {1}{2} = 1.5$$
%D test $\xfrac {1}{2}$ test $$1 + \xfrac {1}{2} = 1.5$$
%D test $\xxfrac{1}{2}$ test $$1 + \xxfrac{1}{2} = 1.5$$
%D \stopbuffer
%D
%D \typebuffer[sample]
%D
%D With the most straightforward definitions, we get:
%D
%D \startbuffer[code]
%D \def\dofrac#1#2#3{\relax\mathematics{{{#1{#2}}\over{#1{#3}}}}}
%D
%D \def\frac  {\dofrac\mathstyle}
%D \def\xfrac {\dofrac\scriptstyle}
%D \def\xxfrac{\dofrac\scriptscriptstyle}
%D \stopbuffer
%D
%D \typebuffer[code] \getbuffer[code,sample]
%D
%D Since this does not work well, we can try:
%D
%D \startbuffer[code]
%D \def\xfrac #1#2{\hbox{$\dofrac\scriptstyle      {#1}{#2}$}}
%D \def\xxfrac#1#2{\hbox{$\dofrac\scriptscriptstyle{#1}{#2}$}}
%D \stopbuffer
%D
%D \typebuffer[code] \getbuffer[code,sample]
%D
%D This for sure looks better than:
%D
%D \startbuffer[code]
%D \def\xfrac #1#2{{\scriptstyle      \dofrac\relax{#1}{#2}}}
%D \def\xxfrac#1#2{{\scriptscriptstyle\dofrac\relax{#1}{#2}}}
%D \stopbuffer
%D
%D \typebuffer[code] \getbuffer[code,sample]
%D
%D So we stick to the next definitions (watch the local
%D overloading of \type {\xfrac}).

\def\math_fractions_forced#1#2#3{\relax\mathematics{\Ustack{{#1{#2}}\normalover{#1{#3}}}}}
\def\math_fractions_auto    #1#2{\relax\mathematics{\Ustack{{#1}\normalover{#2}}}}

% $\mathfracmode0 \frac{1}{2}$
% $\mathfracmode1 \frac{1}{2}$
% $\mathfracmode2 \frac{1}{2}$
% $\mathfracmode3 \frac{1}{2}$
% $\mathfracmode4 \frac{1}{2}$
% $\mathfracmode5 \frac{1}{2}$

% 0=auto, 1=displaystyle, 2=textstyle, 3=scriptstyle, 4=scriptscriptstyle, 5=mathstyle

\setnewconstant\mathfracmode\zerocount

\unexpanded\def\frac % overloaded later on
  {\ifcase\mathfracmode
     \expandafter\math_fractions_auto
   \or
     \expandafter\math_fractions_forced\expandafter\displaystyle
   \or
     \expandafter\math_fractions_forced\expandafter\textstyle
   \or
     \expandafter\math_fractions_forced\expandafter\scriptstyle
   \or
     \expandafter\math_fractions_forced\expandafter\scriptscriptstyle
   \else
     \expandafter\math_fractions_forced\expandafter\mathstyle
   \fi}

\unexpanded\def\xfrac#1#2%
  {\begingroup
   \let\xfrac\xxfrac
   \math_fractions_forced\scriptstyle{#1}{#2}%
   \endgroup}

\unexpanded\def\xxfrac#1#2%
  {\begingroup
   \math_fractions_forced\scriptscriptstyle{#1}{#2}%
   \endgroup}

%D The \type {xx} variant looks still ugly, so maybe it's
%D best to say:

\unexpanded\def\xxfrac#1#2%
  {\begingroup
   \math_fractions_forced\scriptscriptstyle{#1}{\raise.25ex\hbox{$\scriptscriptstyle#2$}}%
   \endgroup}

%D Something low level for scientific calculator notation:

\unexpanded\def\scinot#1#2%
  {#1\times10^{#2}}

% I have no clue what \mthfrac and \mthsqrt are supposed to do but
% I guess that it can be done with tweaking luatex's math parameters.
% Otherwise I'll write something from scratch.

\unexpanded\def\mthfrac#1#2#3{[mthfrac: #1 #2 #3]}
\unexpanded\def\mthsqrt#1#2#3{[mthsqrt: #1 #2 #3]}

%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 \getbuffer

% extra {} after displaystyle etc are needed

%unexpanded\def\frac  #1#2{{                  {{#1}\normalover                       {#2}}}}
%unexpanded\def\xfrac #1#2{{\scriptstyle      {{#1}\normalover                       {#2}}}}
%unexpanded\def\xxfrac#1#2{{\scriptscriptstyle{{#1}\normalover                       {#2}}}}
\unexpanded\def\dfrac #1#2{{\displaystyle     {{#1}\normalover                       {#2}}}}
\unexpanded\def\tfrac #1#2{{\textstyle        {{#1}\normalover                       {#2}}}}

%unexpanded\def\binom #1#2{{                  {{#1}\normalabovewithdelims()\zeropoint{#2}}}}
\unexpanded\def\dbinom#1#2{{\displaystyle     {{#1}\normalabovewithdelims()\zeropoint{#2}}}}
\unexpanded\def\tbinom#1#2{{\textstyle        {{#1}\normalabovewithdelims()\zeropoint{#2}}}}

\unexpanded\def\binom #1#2{{\Ustack{{#1}\normalabovewithdelims()\zeropoint{#2}}}}

% \let\frac\math_fractions_auto

%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

\unexpanded\def\cfrac
  {\doifnextoptionalelse\math_cfrac_yes\math_cfrac_nop}

\def\math_cfrac_nop    {\math_cfrac_indeed[cc]}
\def\math_cfrac_yes[#1]{\math_cfrac_indeed[#1cc]}

\def\math_cfrac_indeed[#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 but adapted a bit.

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

\unexpanded\def\splitdfrac#1#2%
  {{\displaystyle{{          #1\quad\hfill}\normalabove\zeropoint{          \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\nobreakspace\hfill#1\par
   \else\ifmmode
     #1\relax % leading \eqno removed
   \else
     \dontleavehmode\emptyhbox\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   {boxed}
%D
%D [HH] Another macro that users might expect (slightly adapted):

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

\protect \endinput