summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/math/math-alignments.tex
blob: bb2801b8a901ca14eadc4e6c61457168fd650fd8 (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
\environment math-layout

\startcomponent math-alignments

\startchapter[title=Alignments and such]

\startsection[title=Using ampersands]

When you come from plain \TEX, using ampersands probably comes as a custom, like in:

\startbuffer
\startformula
\bordermatrix {
   a & b & c & d \cr
   e & f & G & h \cr
   i & j & k & l \cr
}
\stopformula
\stopbuffer

\typebuffer \getbuffer

or:

\startbuffer
\startformula
\bbordermatrix {
   a & b & c & d \cr
   e & f & G & h \cr
   i & j & k & l \cr
}
\stopformula
\stopbuffer

\typebuffer \getbuffer

A more \CONTEXT\ way is this:

\startbuffer
\startformula
\startbordermatrix
   \NC a \NC b \NC c \NC d \NR
   \NC e \NC f \NC G \NC h \NR
   \NC i \NC j \NC k \NC l \NR
\stopbordermatrix
\stopformula
\stopbuffer

\typebuffer \getbuffer

and:

\startbuffer
\startformula
\startbbordermatrix
   \NC a \NC b \NC c \NC d \NR
   \NC e \NC f \NC G \NC h \NR
   \NC i \NC j \NC k \NC l \NR
\stopbbordermatrix
\stopformula
\stopbuffer

\typebuffer \getbuffer

Just that you know. In general ampersands in \CONTEXT\ text mode are just that:
ampersands, not something alignment related.

\stopsection

\startsection[title=Locations]

The \type {location} feature gives some control over the alignment of alignments.
The following examples are taken from an email exchange with Henri Menke.

\startbuffer
\startplaceformula
  \startformula
    \startmathalignment[location=top]
      \NC a + b \NC= c + d \NR
      \NC a + b \NC= c + d \NR
      \NC a + b \NC= c + d \NR
    \stopmathalignment
    \quad\text{or}\quad
    \startmathalignment[location=center]
      \NC a + b \NC= c + d \NR
      \NC a + b \NC= c + d \NR
      \NC a + b \NC= c + d \NR
    \stopmathalignment
    \quad\text{or}\quad
    \startmathalignment[location=bottom]
      \NC a + b \NC= c + d \NR
      \NC a + b \NC= c + d \NR
      \NC a + b \NC= c + d \NR
    \stopmathalignment
  \stopformula
\stopplaceformula
\stopbuffer

\typebuffer \getbuffer

Numbering works ok for a single mathalignment

\startbuffer
\startplaceformula
  \startformula
    \startmathalignment[number=auto]
      \NC a + b \NC= c + d \NR
      \NC a + b \NC= c + d \NR
      \NC a + b \NC= c + d \NR
    \stopmathalignment
  \stopformula
\stopplaceformula
\stopbuffer

\typebuffer \getbuffer

But for one with a location the results are suboptimal:

\startbuffer
\startplaceformula
  \startformula
    \startmathalignment[location=center,number=auto]
      \NC a + b \NC= c + d \NR
      \NC a + b \NC= c + d \NR
      \NC a + b \NC= c + d \NR
    \stopmathalignment
  \stopformula
\stopplaceformula
\stopbuffer

\typebuffer \getbuffer

Here is a real example:

\startbuffer
\startplaceformula
  \startformula
    U_2 = \frac{1}{2!}
      \int_0^\beta \diff\tau_1 \int_0^\beta \diff\tau_2\;
      \sum_{\startsubstack k_1,q_1 \NR k_2,q_2 \stopsubstack}
      \Bigl\langle
      \startmathalignment[location=top,align=left]
        \NC
          \mathcal T \Bigl[
            c_{k_1}^\dagger (\tau_1)
            \Delta_{k_1,q_1}^r c_{-k_1}^* (\tau_1) + c_{-q_1}^T (\tau_1)
            \Delta_{k_1,q_1}^{r\dagger} c_{q_1} (\tau_1)
          \Bigr]
        \NR
        \NC
          \times \Bigl[
            c_{k_2}^\dagger(\tau_2) \Delta_{k_2,q_2}^r c_{-k_2}^*
            (\tau_2) + c_{-q_2}^T (\tau_2) \Delta_{k_2,q_2}^{r\dagger}
            c_{q_2} (\tau_2)
          \Bigr] \Bigr\rangle .
        \NR
      \stopmathalignment
  \stopformula
\stopplaceformula
\stopbuffer

\typebuffer \getbuffer

\stopsection

\startsection[title=Tuning alignments]

Again a few examples of manipulating alignments. It really helps to play
with examples if you want to get an idea what is possible.

\startbuffer
\startformula
    \startalign[m=2,align={middle}]
        \NC \text to 6cm{} \NC x = 0 \NR
    \stopalign
\stopformula

\startformula
    \startalign[m=2,align={middle}]
        \NC \text to 6cm{One\hfill}           \NC a = 1 \NR
        \NC \text to 6cm{One Two\hfill}       \NC b = 2 \NR
        \NC \text to 6cm{One Two Three\hfill} \NC c = 3 \NR
    \stopalign
\stopformula

\startformula
    \startalign[m=2,align={left}]
        \NC \text to 6cm{One\hfill}           \NC a = 1 \NR
        \NC \text to 6cm{One Two\hfill}       \NC b = 2 \NR
        \NC \text to 6cm{One Two Three\hfill} \NC c = 3 \NR
    \stopalign
\stopformula
\stopbuffer

\typebuffer \getbuffer

\startbuffer
\startformula
    \startalign[m=2,align={middle}]
        \NC \text to 6cm{} \NC x = 0 \NR
    \stopalign
\stopformula

\startformula
    \startalign[m=2,align={middle}]
        \NC \text to 6cm{One}           \NC a = 1 \NR
        \NC \text to 6cm{One Two}       \NC b = 2 \NR
        \NC \text to 6cm{One Two Three} \NC c = 3 \NR
    \stopalign
\stopformula

\startformula
    \startalign[m=2,align={left}]
        \NC \text to 6cm{One}           \NC a = 1 \NR
        \NC \text to 6cm{One Two}       \NC b = 2 \NR
        \NC \text to 6cm{One Two Three} \NC c = 3 \NR
    \stopalign
\stopformula
\stopbuffer

\typebuffer \getbuffer

\startbuffer
\startformula
    \startalign[m=2,align={middle}]
        \NC \text{} \NC x = 0 \NR
    \stopalign
\stopformula

\startformula
    \startalign[m=2,align={middle}]
        \NC \text{One}           \NC a = 1 \NR
        \NC \text{One Two}       \NC b = 2 \NR
        \NC \text{One Two Three} \NC c = 3 \NR
    \stopalign
\stopformula

\startformula
    \startalign[m=2,align={left}]
        \NC \text{One}           \NC a = 1 \NR
        \NC \text{One Two}       \NC b = 2 \NR
        \NC \text{One Two Three} \NC c = 3 \NR
    \stopalign
\stopformula
\stopbuffer

\typebuffer \getbuffer

\stopsection

\startsection[title={Splitting over pages}]

Because formula placement has positioning options a formula gets
wrapped in a box. As a consequence formulas will not break across
pages. This can be an issue with alignments. There is an experimental
option for this (the result is shown in \in {figure} [fig:splitalign]):

\startbuffer[demo]
\usemodule[art-01]
\setupbodyfont[13pt]
\starttext
  \input tufte
  \startplaceformula
    \startsplitformula
      \startalign
        \NC a \EQ b \NR[+]
        \NC   \EQ d \NR
        \NC c \EQ f \NR[+]
        \NC   \EQ g \NR
        \NC   \EQ h \NR[+]
        \dorecurse{100}{\NC \EQ i + #1 - #1\NR[+]}%
        \NC   \EQ x \NR
      \stopalign
    \stopsplitformula
  \stopplaceformula
  \input tufte
\stoptext
\stopbuffer

\typebuffer[demo]

\startplacefigure[title={Splitting an alignment.},reference=fig:splitalign]
    \startcombination[nx=4,ny=1]
      {\typesetbuffer[demo][page=1,width=\measure{combination}]} {}
      {\typesetbuffer[demo][page=2,width=\measure{combination}]} {}
      {\typesetbuffer[demo][page=3,width=\measure{combination}]} {}
      {\typesetbuffer[demo][page=4,width=\measure{combination}]} {}
    \stopcombination
\stopplacefigure

\stoptext

\stopsection

\stopchapter

\stopcomponent