summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/context/manuals/reference/en/co-formulas.tex
blob: ac148bab3f9df15dee90866429eec355032472ec (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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
\startcomponent co-formulas

\environment contextref-env
\product contextref

% \input supp-mps % for \MPdivten (chemic)
\let \ifgrTEXgraphic \ifforceMPTEXgraphic

\chapter[formulas]{Formulas}

\section{Introduction}

For what reason do we need a complete chapter on formulas?
The reason is obvious: a considerable part of the
functionality of \TEX\ relates to math typesetting since
the main reason for developing \TEX\ was the need for
typesetting math.

In \CONTEXT\ math typesetting is not really an issue.
\CONTEXT\ was developed for typesetting educational
materials and not necessarily math. Therefore more attention
was paid to chemical formulas and consistent use of units
than to math. Math was available anyhow.

In \CONTEXT\ the functionality is more oriented towards the
educational disciplines and these can be found in specific
modules. A module will not supply basic functionality
because it can be found in the core.

There are modules for chemical stuff, units and
flow||charts, which all have their own manual. The same goes
for the math module. This module contains the same
functionality as the macros developed by the {\em American
Mathematical Society}. Those macros are well||known in the
\TEX\ community. Most extensions concern the interface and
consistent spacing. In this chapter we pay attention to the
standard functionality in \CONTEXT.

\section{Basic commands}
\index{placing+formulas}
\index{overviews+formulas}
\index{numbering+formulas}
\index{formulas+placing}
\index{formulas+overviews}
\macro{\tex{setupformulae}}
\macro{\tex{placeformula}}
\macro{\tex{placesubformula}}
\macro{\tex{subformulanumber}}
\macro{\tex{formulanumber}}
\macro{\tex{startformula}}

Typesetting formulas is one of the strong points of \TEX.
Special commands are available for typesetting math. These
commands are enclosed by single or double dollar signs.

In the running text we use single dollar signs:
\type {$a=b^2+1/c$} becomes  $a=b^2+1/c$. In conjunction
with in||line||math there is display||math, or rather
formulas surrounded by whitespace. Those formulas are
frequently numbered. The location and way of numbering can
be set with:

\showsetup{setupformulas}

With \type{left} and \type{right} characters on the left
or right side of the formula number are set up. Default
these are \type{(}~and~\type{)}.

A (numbered) formula is defined with the commands:

\showsetup{placeformula}

\showsetup{placesubformula}

The reference and subnumber are optional. Below we give
some examples of formulas. In the margin we display the
references. Typing the formula number manually is necessary
when we make use of tables, matrices and \TEX||commando's
like \type{\displaylines}. In the examples we use \type
{$$} to save some space; however we advise you to use the
command \type {\startformula}.

\startmode[mkiv]
\fixme{Mark IV doesn't have a \tex{formulanumber} command at the
moment, the rest of this paragraph is suppressed}
\stopmode

\startnotmode[mkiv]
\start

\def\ShowMathExample[#1]%
  {\bgroup
   \setupinmargin[location=left]
   \def\doShowMathExample##1{\in{##1:}[##1]\\}%
   \doifsomething{#1}
     {\margintitle{\processcommalist[#1]\doShowMathExample\unskip}}
   \typebuffer
   \getbuffer
   \egroup}

\startbuffer
\placeformula          $$ a + b = c                            $$
\stopbuffer
\ShowMathExample[]

\startbuffer
\placeformula          $$ a + b = c                            $$
\stopbuffer
\ShowMathExample[]

\startbuffer
\placesubformula   {a} $$ a + b = c                            $$
\stopbuffer
\ShowMathExample[]

\startbuffer
\placesubformula   {b} $$ a + b = c                            $$
\stopbuffer
\ShowMathExample[]

\startbuffer
\placeformula   [a]    $$ a + b = c                            $$
\stopbuffer
\ShowMathExample[a]

\startbuffer
\placeformula   [b]    $$ a + b = c                            $$
\stopbuffer
\ShowMathExample[b]

\startbuffer
\placesubformula[c]{a} $$ a + b = c                            $$
\stopbuffer
\ShowMathExample[c]

\startbuffer
\placesubformula[d]{b} $$ a + b = c                            $$
\stopbuffer
\ShowMathExample[d]

\startbuffer
\placeformula          $$ a + b = c \quad \formulanumber       $$
\stopbuffer
\ShowMathExample[]

\startbuffer
\placeformula          $$ a + b = c \quad \formulanumber       $$
\stopbuffer
\ShowMathExample[]

\startbuffer
\placesubformula   {a} $$ a + b = c \quad \formulanumber       $$
\stopbuffer
\ShowMathExample[]

\startbuffer
\placesubformula   {b} $$ a + b = c \quad \formulanumber       $$
\stopbuffer
\ShowMathExample[]

\startbuffer
\placeformula   [e]    $$ a + b = c \quad \formulanumber       $$
\stopbuffer
\ShowMathExample[e]

\startbuffer
\placeformula   [f]    $$ a + b = c \quad \formulanumber       $$
\stopbuffer
\ShowMathExample[f]

\startbuffer
\placesubformula[g]{a} $$ a + b = c \quad \formulanumber       $$
\stopbuffer
\ShowMathExample[g]

\startbuffer
\placesubformula[h]{b} $$ a + b = c \quad \formulanumber       $$
\stopbuffer
\ShowMathExample[h]

\startbuffer
\placesubformula      $$ a + b = c \quad \formulanumber   {a} $$
\stopbuffer
\ShowMathExample[]

\startbuffer
\placesubformula       $$ a + b = c \quad \formulanumber   {b} $$
\stopbuffer
\ShowMathExample[]

\startbuffer
\placeformula          $$ a + b = c \quad \formulanumber[i]    $$
\stopbuffer
\ShowMathExample[i]

\startbuffer
\placeformula          $$ a + b = c \quad \formulanumber[j]    $$
\stopbuffer
\ShowMathExample[j]

\startbuffer
\placesubformula       $$ a + b = c \quad \formulanumber[k]{a} $$
\stopbuffer
\ShowMathExample[k]

\startbuffer
\placesubformula       $$ a + b = c \quad \formulanumber[l]{b} $$
\stopbuffer
\ShowMathExample[l]

\startbuffer
\placeformula   [m]    $$ a + b = c \quad \formulanumber   {a} $$
\stopbuffer
\ShowMathExample[m]

\startbuffer
\placeformula   [n]    $$ a + b = c \quad \formulanumber   {b} $$
\stopbuffer
\ShowMathExample[n]

\startbuffer
\placesubformula[o]    $$ a + b = c \quad \formulanumber   {a} $$
\stopbuffer
\ShowMathExample[o]

\startbuffer
\placesubformula[p]    $$ a + b = c \quad \formulanumber   {b} $$
\stopbuffer
\ShowMathExample[p]

\startbuffer
\placeformula   [q]    $$ a + b = c \quad \formulanumber[r]{a} $$
\stopbuffer
\ShowMathExample[q,r]

\startbuffer
\placeformula   [s]    $$ a + b = c \quad \formulanumber[t]{b} $$
\stopbuffer
\ShowMathExample[s,t]

\startbuffer
\placesubformula[u]    $$ a + b = c \quad \formulanumber[v]{a} $$
\stopbuffer
\ShowMathExample[u,v]

\startbuffer
\placesubformula[w]    $$ a + b = c \quad \formulanumber[x]{b} $$
\stopbuffer
\ShowMathExample[w,x]

\stop
\stopnotmode

When we want {\em no} numbers we have to indicate that
explicitly by means of \type{[-]}:

\startbuffer
\placeformula[-]
  $$\displaylines
      {ab=ba\hfill\cr
       ac+bc=(a+b)c\hfill\cr}$$
\stopbuffer

\startexample
\typebuffer
\stopexample

This results in:

\getbuffer

We also could have used here \type {\startformula...}\type
{\stopformula}:

\startbuffer
\placeformula[-]
  \startformula
  \displaylines{ab=ba\hfill\cr ac+bc=(a+b)c\hfill\cr}
  \stopformula
\stopbuffer

\startexample
\typebuffer
\stopexample

The use of the \type{\start...}\type{\stop}||pair
has the advantage that we can test symmetry in some
wordprocessors. The disadvantage is we can not see
immediately that we work in math mode.

\showsetup{startformula}

The next examples does use numbers. In this example \type
{[that's it]} is a logical name, a label, for future
referencing.

\startbuffer
\placeformula
  \startformula
    \displaylines
        {a\times b=b\times a\hfill\formulanumber\cr
         a+b=b+a\hfill\subformulanumber\cr
         ac+bc=(a+b)c\hfill\formulanumber[that's it]{x}\cr}
  \stopformula
\stopbuffer

\startexample
\typebuffer
\stopexample

This becomes:

\doifnotmode{mkiv}{\getbuffer}
\doifmode{mkiv}{\fixme{getbuffer suppressed}}

\section{Legends}
\index{formulas+legends}
\macro{\tex{startfact}}
\macro{\tex{startlegend}}

In case of physics formulas you may want to explain the
meaning of the used symbols. There are two commands to do
that:

\showsetup{startlegend}

\showsetup{startfact}

A legend and facts are coded as follows:

\startbuffer
\placeformula[for:force]$$F = m a$$

\startlegend
\leg F \\ force        \\ N       \\
\leg m \\ mass         \\ kg      \\
\leg a \\ acceleration \\ m/{s^2} \\
\stoplegend

Determine by means of formula~\in[for:force] the acceleration~$a$
when given is that:

\startfact
\fact mass  \\ m \\ 10~kg  \\
\fact force \\ F \\ 1500~N \\
\stopfact
\stopbuffer

\startexample
\typebuffer
\stopexample

This results in:

\getbuffer

A combination is also possible:

\startbuffer
\startlegend[two]
\leg F \\      \\ force        \\ N       \\
\leg m \\   10 \\ mass         \\ kg      \\
\leg a \\ 1500 \\ acceleration \\ m/{s^2} \\
\stoplegend
\stopbuffer

\getbuffer

This was specified in this way:

\typebuffer

\section[units]{Units}
\index{overviews+units}
\index{formulas+units}
\index{units}
\macro{\tex{unit}}
\macro{\tex{mathematics}}

A unit can be typeset with:

\startexample
\starttyping
10~$\rm m^3$
\stoptyping
\stopexample

For the purpose of consistent typesetting the command
\type{\unit} is available. This is an example of the use of
synonyms as described in \in{section}[synonyms].

\startexample
\starttyping
\unit {strange} {m^3\!/s^2} {a strange unit}
\stoptyping
\stopexample

In this case the \type{\!} takes care of backskipping
the~$/$ in such a way that in stead of $\rm m^3/s^2$ we get
$\rm m^3\!/s^2$. In fact we can do without these kind of
cryptic typing, because the unit module offers a better
alternative. The module is loaded in the set up area of your
source file with:

\starttyping
\usemodule[unit]
\stoptyping

After that you can type the recall unit by typing them. For
example:

\starttyping
... 10 \Meter \Per \Second\ ...
... 33 \Kilo \Gram \Per \Square \Meter\ ...
\stoptyping

At this point we advise you to read the manual that comes
with this module for more examples.

When we use math commands there may occur problems as soon
as we use~\type{$} in a nested way. When we are in math mode
and we use a~\type{$} for the purpose of switching to math
mode we just end math mode like this:

\startexample
\starttyping
$a $\times$ b$
\stoptyping
\stopexample

\TEX\ will produce an error because \type{\times} is typed
outside math mode. In this example we saw what goes wrong
but the problem is less obvious in the next example:

\startexample
\starttyping
\def\multiply{$\times$}
$a \multiply b$
\stoptyping
\stopexample

This seems correct but with \type{\multiply} we leave math
mode. We can prevent errors by defining \type{\multiply}
as follows:

\startexample
\starttyping
\def\multiply{\ifmmode \times \else $\times$ \fi}
\stoptyping
\stopexample

The next commands does just that:

\showsetup{mathematics}

We can use this command in nested situations:

\startbuffer
\mathematics{a\mathematics{b\mathematics{c\mathematics{d\mathematics{e}}}}}
\stopbuffer

\startexample
\typebuffer
\stopexample

and it will result in a correct output:

\startreality
\getbuffer
\stopreality

so do not use this:

\startbuffer
$a$b$c$d$e$
\stopbuffer

\startreality
\getbuffer
\stopreality

which we would have obtained by typing:

\startexample
\typebuffer
\stopexample

\section{Chemicals}
\index[PPCHTEX]{\PPCHTEX}
\index{chemical formulas}
\macro{ch}
\macro{startchemical}
\macro{chemical}
\macro{usemodule}

Earlier we stated that in this chapter we also describe the
module for chemical typesetting. This module is loaded with:

\starttyping
\usemodule[chemic]
\stoptyping

The first version of this module used \PICTEX\ for
positioning text and drawing the chemical structures, the
current version uses \METAPOST\ for drawing the graphics.
The results are better and the files are more compact.

\startbuffer
\startchemical[with=fit,height=fit]
  \chemical
    [SIX,B,C,ADJ1,
     FIVE,ROT3,SB34,+SB2,-SB5,Z345,DR35,SR4,CRZ35,SUB1,
     ONE,OFF1,SB258,Z0,Z28]
    [C,N,C,O,O,
     CH,COOC_2H_5,COOC_2H_5]
\stopchemical
\stopbuffer

\startlinecorrection
\getbuffer
\stoplinecorrection

This chemical structure was typed as follows:

\typebuffer

The interface (syntax) looks rather cryptic but after some
practice its compactness is an asset. There is an extensive
manual and a collection of examples available.

One characteristic of chemical typesetting is the fact that
all super|| respectively subscripts are at the same height.
This is not the case in math typesetting where the location
of the super|| and subscripts depend on the available
vertical space. The command \type {\chemical} takes this
into account. When you want to put a chemical formula in a
math formula |<|for example when you want to display an
expression for a chemical equilibrium|>| there is the
command \type{\ch}. This command has one argument and adapts
automatically to its context: \type
{$\frac{\ch{N}}{\ch{O}}$}

\section{Math}
\index{fraktur}
\index{gothic}
\index{calligraphy}
\index{fractions}
\macro{\tex{fraction}}
\macro{\tex{frac}}
\macro{\tex{maframed}}
\macro{\tex{inmaframed}}
\macro{\tex{frak}}
\macro{\tex{goth}}
\macro{\tex{cal}}
\macro{\tex{fraktur}}
\macro{\tex{gothic}}
\macro{\tex{calligraphic}}

We limit ourselves only to those commands that are
available by default. In addition to the commands mentioned
here, the math module implements many more:

\starttyping
\usemodule[math]
\stoptyping

The extra commands are described in a separate manual.

Like in  plain \TEX\ we offer the next commands
for switching to some specialized fonts:

\starttabulate[|l|l|l|]
\NC \type {\frak} \NC fraktur      \NC \frak ABC \NC\NR
\doifnotmode{mkiv}{\NC \type {\goth} \NC gothic       \NC \goth abc \NC\NR}
\NC \type {\cal}  \NC calligraphic \NC \cal  ABC \NC\NR
\stoptabulate

Alternatively one can use the commands \type {\fraktur},
\type {\gothic} and \type {\calligraphic} which each take
one argument, like in \type {\fraktur {TEXT}}.

These are typical fonts meant for math typesetting and
special characters.

Fractions can occur quite often so we also added the command
\type {\frac} on request: \type {$\frac{a}{b}$} results as
expected $\frac{a}{b}$. This command adapts to its
surroundings as good as possible.

For instructional purposes a frame or a background can be
useful to indicate the specific math symbol. There is a
special version of \type {\framed}: \type {\maframed}. We
give some examples:

\startbuffer
\startformula
  y + \maframed{y} + y^{2} + y^{\maframed{2}}
\stopformula

\nonknuthmode % todo: one day this can be removed

\startformula
  x \times \maframed{y} \times y^{\maframed{z}_{\maframed{z}}}
\stopformula
\stopbuffer

\typebuffer

\getbuffer

To obtain a good spacing in framed math texts the \type
{offset} equals \type {overlay}. The offset is produced by
giving \type {frameoffset} an adequate value. Other setups
are also possible:

\startbuffer
\startformula
  x \times y^{\maframed[framecolor=red]{z}_z}
\stopformula
\stopbuffer

\typebuffer

\getbuffer

For in||line math the command \type {\inmaframed}
is available.

It is possible to typeset fractions without switching to
math mode with the command:

\showsetup{fraction}

The braces are essential in the next example.

\startbuffer
If \fraction{123}{456} equals \fraction{x}{y}, then \fraction{y}{x} equals
\fraction{456}{123}.
\stopbuffer

\startexample
\typebuffer
\stopexample

results in:

\startreality
\getbuffer
\stopreality


\section {Math collection}

Math is a complicated matter and therefore we will not spend
that many words on the gory details. For the user it is
enough to know that you can mix different math fonts in a
comfortable way and that \CONTEXT\ will take care of the
proper mapping on specific math fonts.

Because the wide range of math symbols can come from
different fonts, math characters are organized into so
called math collections. Normally such a collection is
chosen automatically when you load a font definition, just
as with font encodings. The \AMS\ math fonts extend the
default math collection, which gives you a comfortable fall
back. More information can be found in the documentation of
the math module.

You can generate a list of the current math character set
with the command \type {\showmathcharacters}.

\doifnotmode{mkiv}{\showmathcharacters}
\doifmode{mkiv}{command does not exist in mkiv}
\stopcomponent