summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/m-newmat.tex
blob: 08ce33b4ce5c9f038f97c11dbbd3cec2a969978c (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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
%D \module
%D   [       file=m-newmat,
%D        version=2000.11.16,
%D          title=\CONTEXT\ Math Module,
%D       subtitle=AMS-like math extensions,
%D         author={Taco Hoekwater \& Hans Hagen},
%D           date=\currentdate,
%D      copyright={PRAGMA / Taco Hoekwater}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
%C details.

%D This module collects macros that \TEX\ users kind of expect
%D to be available when typesetting math. Most of them
%D originate in the \AMS\ macro packages. We have taken the
%D freedom to adapt them to \CONTEXT. This module is derived
%D from the \type {m-math} module by Taco Hoekwater (partially
%D derived from AMS math modules) and adapted|/|extended by
%D Hans Hagen.

%D Here we will add code on demand. So, just let us know what
%D should go in here.

%M \usemodule[newmat]

\unprotect

%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.

\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]

\def\QED{\symbol[qed]}

%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 [TH] No need to make these \type {\unexpanded} as well.

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

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

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

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

%D Better:

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

%D [HH] This shows up as:
%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

%D \macros
%D   {text}
%D
%D [TH] \type {\text} is a command to typeset more or less
%D ordinary text inside of super- and sub|-|scripts. It has to
%D do a full font switch to get the sides right, so it will be
%D quite slow. \type {\text} kind of replaces \CONTEXT's \type
%D {\mathstyle} command.

%D [HH] This macro is now also moved to the core, but we
%D keep it here as well for completeness.
%D
%D \starttyping
%D \unexpanded\def\mathtext
%D   {\mathortext\domathtext\hbox} % {\ifmmode\@EA\dotext\else\@EA\hbox\fi}
%D
%D \def\domathtext#1%
%D   {\mathchoice
%D      {\dodomathtext\displaystyle\textface        {#1}}%
%D      {\dodomathtext\textstyle   \textface        {#1}}%
%D      {\dodomathtext\textstyle   \scriptface      {#1}}%
%D      {\dodomathtext\textstyle   \scriptscriptface{#1}}}
%D
%D \def\dodomathtext#1#2#3% no \everymath !
%D  %{\hbox{\everymath{#1}\switchtobodyfont  [#2]#3}} % 15 sec
%D   {\hbox{\everymath{#1}\setcurrentfontbody{#2}#3}} %  3 sec (no math)
%D \stoptyping

%D [HH] We use the following indirectness because \type {\text}
%D is a natural candidate for user macros (actually, it is
%D used in some modules).
%D
%D \starttyping
%D \let\text\mathtext
%D \stoptyping

%D [HH] Actually, the font switch is not that slow when
%D typefaces are used. If needed this macro can be sped up.
%D
%D \startbuffer
%D ordinary text $x^{\text{extra ordinary text}}$
%D \stopbuffer
%D
%D \typebuffer
%D
%D \getbuffer

%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.

\gdef\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):

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

%D \macros
%D   {cfrac}
%D
%D [HH] Now let us see what this one does:
%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

\definecomplexorsimple\cfrac

\def\simplecfrac
  {\complexcfrac[c]}

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

%D [HH] The next alternative is nicer:

\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 [HH] 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

%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

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

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

\protect \endinput

%D \macros
%D   {startsubarray,substack,startsmallmatrix}
%D
%D [HH] I wonder what these are supposed to do. An example
%D will be inserted later. Contrary to the original we
%D support an optional argument between either \type {{}} or
%D \type {[]}.

\def\startsubarray
  {\doifnextcharelse\bgroup
     \simplestartsubarray{\dosingleempty\complexstartsubarray}}

\def\complexstartsubarray[#1]%
  {\simplestartsubarray{#1}}

\def\simplestartsubarray#1%
  {\vcenter\bgroup
   \baselineskip\fontdimen10 \scriptfont\plustwo
   \advance\baselineskip\fontdimen12 \scriptfont\plustwo
   \lineskip\plusthree\fontdimen8 \scriptfont\plusthree
   \lineskiplimit\lineskip
   \ialign\bgroup\ifx c#1\hfil\fi$\mathsurround\zeropoint\scriptstyle##$\hfil\crcr}

\def\stopsubarray
  {\crcr\egroup
   \egroup}

\def\startsubstack
  {\doifnextcharelse\bgroup
     \simplestartsubstack{\dosingleempty\complexstartsubstack}}

\def\complexstartsubstack[#1]%
  {\simplestartsubstack{#1}}

\def\simplesubstack#1%
  {\startsubarray[c]#1\stopsubarray}

\def\startsmallmatrix
  {\null
   \,%
   \vcenter\bgroup
   \baselineskip6\ex@
   \lineskip1.5\ex@
   \lineskiplimit\lineskip
   \ialign\bgroup\hfil$\mathsurround\zeropoint\scriptstyle##$\hfil&&\thickspace\hfil
     $\mathsurround\zeropoint\scriptstyle##$\hfil\crcr}

\def\stopsmallmatrix
  {\crcr\egroup
   \egroup
   \,}

\protect \endinput