math-alignments.tex /size: 6929 b    last modification: 2021-10-28 13:50
1% language=us runpath=texruns:manuals/math
2
3\environment math-layout
4
5\startcomponent math-alignments
6
7\startchapter[title=Alignments and such]
8
9\startsection[title=Using ampersands]
10
11When you come from plain \TEX, using ampersands probably comes as a custom, like in:
12
13\startbuffer
14\startformula
15\bordermatrix {
16   a & b & c & d \cr
17   e & f & G & h \cr
18   i & j & k & l \cr
19}
20\stopformula
21\stopbuffer
22
23\typebuffer \getbuffer
24
25or:
26
27\startbuffer
28\startformula
29\bbordermatrix {
30   a & b & c & d \cr
31   e & f & G & h \cr
32   i & j & k & l \cr
33}
34\stopformula
35\stopbuffer
36
37\typebuffer \getbuffer
38
39A more \CONTEXT\ way is this:
40
41\startbuffer
42\startformula
43\startbordermatrix
44   \NC a \NC b \NC c \NC d \NR
45   \NC e \NC f \NC G \NC h \NR
46   \NC i \NC j \NC k \NC l \NR
47\stopbordermatrix
48\stopformula
49\stopbuffer
50
51\typebuffer \getbuffer
52
53and:
54
55\startbuffer
56\startformula
57\startbbordermatrix
58   \NC a \NC b \NC c \NC d \NR
59   \NC e \NC f \NC G \NC h \NR
60   \NC i \NC j \NC k \NC l \NR
61\stopbbordermatrix
62\stopformula
63\stopbuffer
64
65\typebuffer \getbuffer
66
67Just that you know. In general ampersands in \CONTEXT\ text mode are just that:
68ampersands, not something alignment related.
69
70\stopsection
71
72\startsection[title=Locations]
73
74The \type {location} feature gives some control over the alignment of alignments.
75The following examples are taken from an email exchange with Henri Menke.
76
77\startbuffer
78\startplaceformula
79  \startformula
80    \startmathalignment[location=top]
81      \NC a + b \NC= c + d \NR
82      \NC a + b \NC= c + d \NR
83      \NC a + b \NC= c + d \NR
84    \stopmathalignment
85    \quad\text{or}\quad
86    \startmathalignment[location=center]
87      \NC a + b \NC= c + d \NR
88      \NC a + b \NC= c + d \NR
89      \NC a + b \NC= c + d \NR
90    \stopmathalignment
91    \quad\text{or}\quad
92    \startmathalignment[location=bottom]
93      \NC a + b \NC= c + d \NR
94      \NC a + b \NC= c + d \NR
95      \NC a + b \NC= c + d \NR
96    \stopmathalignment
97  \stopformula
98\stopplaceformula
99\stopbuffer
100
101\typebuffer \getbuffer
102
103Numbering works ok for a single mathalignment
104
105\startbuffer
106\startplaceformula
107  \startformula
108    \startmathalignment[number=auto]
109      \NC a + b \NC= c + d \NR
110      \NC a + b \NC= c + d \NR
111      \NC a + b \NC= c + d \NR
112    \stopmathalignment
113  \stopformula
114\stopplaceformula
115\stopbuffer
116
117\typebuffer \getbuffer
118
119But for one with a location the results are suboptimal:
120
121\startbuffer
122\startplaceformula
123  \startformula
124    \startmathalignment[location=center,number=auto]
125      \NC a + b \NC= c + d \NR
126      \NC a + b \NC= c + d \NR
127      \NC a + b \NC= c + d \NR
128    \stopmathalignment
129  \stopformula
130\stopplaceformula
131\stopbuffer
132
133\typebuffer \getbuffer
134
135Here is a real example:
136
137\startbuffer
138\startplaceformula
139  \startformula
140    U_2 = \frac{1}{2!}
141      \int_0^\beta \diff\tau_1 \int_0^\beta \diff\tau_2\;
142      \sum_{\startsubstack k_1,q_1 \NR k_2,q_2 \stopsubstack}
143      \Bigl\langle
144      \startmathalignment[location=top,align=left]
145        \NC
146          \mathcal T \Bigl[
147            c_{k_1}^\dagger (\tau_1)
148            \Delta_{k_1,q_1}^r c_{-k_1}^* (\tau_1) + c_{-q_1}^T (\tau_1)
149            \Delta_{k_1,q_1}^{r\dagger} c_{q_1} (\tau_1)
150          \Bigr]
151        \NR
152        \NC
153          \times \Bigl[
154            c_{k_2}^\dagger(\tau_2) \Delta_{k_2,q_2}^r c_{-k_2}^*
155            (\tau_2) + c_{-q_2}^T (\tau_2) \Delta_{k_2,q_2}^{r\dagger}
156            c_{q_2} (\tau_2)
157          \Bigr] \Bigr\rangle .
158        \NR
159      \stopmathalignment
160  \stopformula
161\stopplaceformula
162\stopbuffer
163
164\typebuffer \getbuffer
165
166\stopsection
167
168\startsection[title=Tuning alignments]
169
170Again a few examples of manipulating alignments. It really helps to play
171with examples if you want to get an idea what is possible.
172
173\startbuffer
174\startformula
175    \startalign[m=2,align={middle}]
176        \NC \text to 6cm{} \NC x = 0 \NR
177    \stopalign
178\stopformula
179
180\startformula
181    \startalign[m=2,align={middle}]
182        \NC \text to 6cm{One\hfill}           \NC a = 1 \NR
183        \NC \text to 6cm{One Two\hfill}       \NC b = 2 \NR
184        \NC \text to 6cm{One Two Three\hfill} \NC c = 3 \NR
185    \stopalign
186\stopformula
187
188\startformula
189    \startalign[m=2,align={left}]
190        \NC \text to 6cm{One\hfill}           \NC a = 1 \NR
191        \NC \text to 6cm{One Two\hfill}       \NC b = 2 \NR
192        \NC \text to 6cm{One Two Three\hfill} \NC c = 3 \NR
193    \stopalign
194\stopformula
195\stopbuffer
196
197\typebuffer \getbuffer
198
199\startbuffer
200\startformula
201    \startalign[m=2,align={middle}]
202        \NC \text to 6cm{} \NC x = 0 \NR
203    \stopalign
204\stopformula
205
206\startformula
207    \startalign[m=2,align={middle}]
208        \NC \text to 6cm{One}           \NC a = 1 \NR
209        \NC \text to 6cm{One Two}       \NC b = 2 \NR
210        \NC \text to 6cm{One Two Three} \NC c = 3 \NR
211    \stopalign
212\stopformula
213
214\startformula
215    \startalign[m=2,align={left}]
216        \NC \text to 6cm{One}           \NC a = 1 \NR
217        \NC \text to 6cm{One Two}       \NC b = 2 \NR
218        \NC \text to 6cm{One Two Three} \NC c = 3 \NR
219    \stopalign
220\stopformula
221\stopbuffer
222
223\typebuffer \getbuffer
224
225\startbuffer
226\startformula
227    \startalign[m=2,align={middle}]
228        \NC \text{} \NC x = 0 \NR
229    \stopalign
230\stopformula
231
232\startformula
233    \startalign[m=2,align={middle}]
234        \NC \text{One}           \NC a = 1 \NR
235        \NC \text{One Two}       \NC b = 2 \NR
236        \NC \text{One Two Three} \NC c = 3 \NR
237    \stopalign
238\stopformula
239
240\startformula
241    \startalign[m=2,align={left}]
242        \NC \text{One}           \NC a = 1 \NR
243        \NC \text{One Two}       \NC b = 2 \NR
244        \NC \text{One Two Three} \NC c = 3 \NR
245    \stopalign
246\stopformula
247\stopbuffer
248
249\typebuffer \getbuffer
250
251\stopsection
252
253\startsection[title={Splitting over pages}]
254
255Because formula placement has positioning options a formula gets
256wrapped in a box. As a consequence formulas will not break across
257pages. This can be an issue with alignments. There is an experimental
258option for this (the result is shown in \in {figure} [fig:splitalign]):
259
260\startbuffer[demo]
261\usemodule[art-01]
262\setupbodyfont[13pt]
263\starttext
264  \input tufte
265  \startplaceformula
266    \startsplitformula
267      \startalign
268        \NC a \EQ b \NR[+]
269        \NC   \EQ d \NR
270        \NC c \EQ f \NR[+]
271        \NC   \EQ g \NR
272        \NC   \EQ h \NR[+]
273        \dorecurse{100}{\NC \EQ i + #1 - #1\NR[+]}%
274        \NC   \EQ x \NR
275      \stopalign
276    \stopsplitformula
277  \stopplaceformula
278  \input tufte
279\stoptext
280\stopbuffer
281
282\typebuffer[demo]
283
284\startplacefigure[title={Splitting an alignment.},reference=fig:splitalign]
285    \startcombination[nx=4,ny=1]
286      {\typesetbuffer[demo][page=1,width=\measure{combination}]} {}
287      {\typesetbuffer[demo][page=2,width=\measure{combination}]} {}
288      {\typesetbuffer[demo][page=3,width=\measure{combination}]} {}
289      {\typesetbuffer[demo][page=4,width=\measure{combination}]} {}
290    \stopcombination
291\stopplacefigure
292
293\stoptext
294
295\stopsection
296
297\stopchapter
298
299\stopcomponent
300