aboutsummaryrefslogtreecommitdiffstats
path: root/doc/user/mat_defs
blob: 15d4e053839b34c63d18ae66afea5244ea7db7de (plain) (blame)
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
@Section
   @Title { Defining new mathematical symbols }
@Begin
@PP
Whenever you type a particular piece of mathematics repeatedly, you
can save time by using definitions.  Definitions are the subject of
Section {@NumberOf definitions}, so here we will just give a few examples
mathematics.definitions @SubIndex { definitions, use with }
definitions. @RawIndex { definitions }
definitions.use.with.mathematics @SubIndex { use with mathematics }
of their use in formatting mathematics.
@PP
Suppose for example that @OneCol @Math { p sub i ` log sub 2 ` p sub i }
occurs frequently in your document.  Then
@ID @Code "def epi { p sub i ` log sub 2 ` p sub i }"
makes the symbol @Code "epi" stand for the object between the braces:
@ID {
@Code @Verbatim { sum from { i=1 } to { n } ` epi }
|7ct
@Math { sum from { i=1 } to { n } ` epi }
}
Parameters are very useful when parts of the symbol vary:
@ID @OneRow @Code @Verbatim {
def ep right x
{
   p sub x ` log sub 2 ` p sub x
}
}
The parameter @Code x will be replaced by the object just to the right
of {@Code "ep"}:
@ID {
@Code {
"sum from { i=1 } to { k } ` ep i +"
"sum from { j=k+1 } to { n } ep j"
}
||7ct
@Math {
sum from { i=1 } to { k } ` ep i +
sum from { j=k+1 } to { n } ep j
}
}
The precedence of the symbols you define will be 100 by default.
To make the symbols of @Code "@Math" available within such definitions,
each must be preceded by {@Code "import @Math"}.  As explained in Section
{@NumberOf definitions}, the definitions go into a file called
{@Code "mydefs"}, which might look like this:
@ID @OneRow @Code @Verbatim {
import @Math
def epi { p sub i ` log sub 2 ` p sub i }

import @Math
def ep right x { p sub x ` log sub 2 ` p sub x }
}
Use of @Code "epi" and @Code "ep" outside @Code "@Math" will cause an error.
@End @Section