Debian Codegraph @

texmf-dist/doc/lualatex/longmath/longmath-doc.tex

raw
1 %%
2 %% longmath-doc.tex is part of longmath version 1.0.
3 %%
4 %% (c) 2024 Hans-Jürgen Matschull
5 %%
6 %% This work may be distributed and/or modified under the
7 %% conditions of the LaTeX Project Public License, either version 1.3
8 %% of this license or (at your option) any later version.
9 %% The latest version of this license is in
10 %% http://www.latex-project.org/lppl.txt
11 %% and version 1.3 or later is part of all distributions of LaTeX
12 %% version 2005/12/01 or later.
13 %%
14 %% This work has the LPPL maintenance status 'maintained'.
15 %%
16 %% The Current Maintainer of this work is Hans-Jürgen Matschull
17 %%
18 %% see README for a list of files belonging to longmath.
19 %%
20
21 \documentclass{longmath-doc}
22
23 \usepackage{longmath}
24 \usepackage{unicode-math}
25 \usepackage{tikz}
26 \usepackage{array}
27 \usepackage{multido}
28
29
30 \def\intro{
31 The \p{longmath} package provides yet another solution to some well known
32 typesetting problems solved in a variety of ways: multi line formulas
33 with paired and nested delimiters. It tackles the problem at the Lua
34 level, which has some advantages over solutions implemented in \TeX.
35 In particular, the \TeX\ code need not be executed multiple times, and
36 there is no interference between \TeX\ grouping and the nesting of
37 delimiter groups.
38
39 As a byproduct, delimiters can be scaled in various ways, inner
40 delimiters come in different flavours like relational and binary
41 operators, punctuation symbols etc., and outer delimiters can be
42 selected automatically according to the nesting level. Last but not
43 least, delimiter groups can even extend across several array cells
44 or across the whole document.
45
46 A special environment is provided as well, which allows multi line
47 expressions to be placed inside a displayed equation and make \TeX\
48 do the line splitting and alignment.
49 }
50
51 \newcommand{\icol}[1]{% inline column vector
52 \lleft(\begin{matrix}#1\end{matrix}\rright)%
53 }
54
55 \def\tr{\mathrm{Tr}}
56
57 \def\lagrange{
58 -\frac{1}{4}
59 \lleft( \partial_\mu B_\nu-\partial_\nu B_\mu \rright )
60 \lleft( \partial^\mu B^\nu-\partial^\nu B^\mu \rright )
61 - \frac{1}{8}\tr\lleft\{
62 \lleft[ \partial_\mu W_\nu-\partial_\nu W_\mu+\frac{ig_2}{2}
63 \lleft( W_\mu W_\nu- W_\nu W_\mu\rright) \rright]
64 \lleft[ \partial^\mu W^\nu-\partial^\nu W^\mu+\frac{ig_2}{2}
65 \lleft( W^\mu W^\nu- W^\nu W^\mu\rright) \rright]
66 \rright\}
67 - \frac{1}{2}\tr\lleft\{
68 \lleft[\partial_\mu G_\nu-\partial_\nu G_\mu
69 + G_\mu G_\nu- G_\nu G_\mu\rright]
70 \lleft[\vphantom{G_\mu} \partial^\mu G^\nu-\partial^\nu G^\mu
71 + G^\mu G^\nu- G^\nu G^\mu\rright]
72 \rright\}
73 + \icol{\nu_L\\e_L}^\dagger \tilde{\sigma}^\mu i
74 \lleft[\partial_\mu-\frac{ig_1}{2}B_\mu+\frac{ig_2}{2}W_\mu\rright]\icol{\nu_L\\e_L}
75 - \lleft\{\lleft[\partial_\mu-\frac{ig_1}{2}B_\mu+\frac{ig_2}{2}W_\mu\rright]\icol{\nu_L\\e_L}
76 \rright\}^\dagger
77 i \tilde{\sigma}^\mu \icol{\nu_L\\e_L}
78 + e_R^\dagger i \sigma^\mu
79 \lleft[\partial_\mu-ig_1B_\mu\rright]e_R
80 + \nu_R^\dagger i \sigma^\mu\partial_\mu\nu_R
81 - \lleft\{ \left[\partial_\mu-ig_1B_\mu\right] e_R \rright\}^\dagger i \sigma^\mu e_R
82 - \lleft\{ \partial_\mu\nu_R \rright\}^\dagger i \sigma^\mu \nu_R
83 - \frac{\sqrt{2}}{\nu}
84 \lleft[ \icol{\nu_L\\e_L}^\dagger \phi M^ee_R
85 +e_R^\dagger M^{e\dagger} \phi^\dagger \icol{\nu_L\\e_L} \rright]
86 - \frac{\sqrt{2}}{\nu}
87 \lleft[ \icol{ -e_L\\ \nu_L}^\dagger \phi^{*}M^\nu\nu_R
88 + \nu_R^\dagger M^{\nu^\dagger} \phi^T\icol{-e_L\\\nu_L} \rright]
89 + \icol{u_L\\d_L}^\dagger\tilde{\sigma}^\mu i
90 \lleft[\partial_\mu-\frac{ig_1}{6}B_\mu+\frac{ig_2}{2}W_\mu+igG_\mu\rright]\icol{u_L\\d_L}
91 - \lleft\{\lleft[\partial_\mu-\frac{ig_1}{6}B_\mu+\frac{ig_2}{2}W_\mu+igG_\mu\rright]\icol{u_L\\d_L}\rright\}^\dagger
92 i\tilde{\sigma}^\mu \icol{u_L\\d_L}
93 + u_R^\dagger \sigma^\mu i \lleft[\partial_\mu+\frac{ig_1}{3}B_\mu+igG_\mu\rright]u_r
94 - \lleft\{ \lleft[\partial_\mu+\frac{ig_1}{3}B_\mu+igG_\mu\rright]u_r \rright\}^\dagger i \sigma^\mu u_R
95 + d_R^\dagger \sigma^\mu i \lleft[\partial_\mu - \frac{ig_1}{3}B_\mu+igG_\mu\rright]d_R
96 - \lleft\{ \lleft[\partial_\mu - \frac{ig_1}{3}B_\mu+igG_\mu\rright]d_R \rright\}^\dagger i \sigma^\mu d_R
97 - \frac{\sqrt{2}}{\nu}\lleft[\icol{u_L\\d_L}^\dagger \phi M^d d_R
98 + \lleft( M^d d_R\rright) ^\dagger \phi^\dagger \icol{u_L\\d_L}\rright]
99 -\frac{\sqrt{2}}{\nu}\lleft[\icol{-d_L\\u_L}^\dagger \phi^{*} M^u u_R
100 + \lleft( M^u u_R \rright)^\dagger \phi^\top \icol{-d_L\\u_L}\rright]
101 + \lleft\{\lleft[\partial_\mu+\frac{ig_1}{2}B_\mu+\frac{ig_2}{2}W_\mu\rright]\phi\rright\}^\dagger
102 \lleft[\partial^\mu+\frac{ig_1}{2}B^\mu+\frac{ig_2}{2}W^\mu\rright]\phi
103 - \frac{ m_h^2 }{ 2 \nu^2 } \lleft[ \phi^\dagger \phi - \frac{\nu^2}{2} \rright]^2
104 }
105
106 \begin{document}
107
108 \begin{center}
109 \tikzset{ txt/.style = { fill=white,fill opacity=0.6,text opacity=1.0 } }
110 \begin{tikzpicture}
111 \useasboundingbox (0,0.53\textheight);
112 \node[color=yellow!85!black,rotate=-17,scale=1.8] at (-0.7,0)
113 {$\displaystyle \mathcal{L} = \begin{longmath}[t]{110mm+30mm} \lagrange \end{longmath}$};
114 \node[txt,scale=1.8] at (0,7.2) {\Huge\textbf{\p{longmath}}};
115 \node[txt,scale=1.2] at (0,5.4) {\Large Documentation for Version 1.0};
116 \node[txt,scale=1.2] at (0,4.0) {\large Hans-Jürgen Matschull};
117 \node[txt,scale=1.2] at (0,3.3) {\texttt{[email protected]}};
118 \node[txt,scale=1.2] at (0,1.7) {\texttt{2024/07/04}};
119 \node[txt,scale=1.0] at (0,-3) {\begin{minipage}{130mm}\parskip 1.3ex \intro\end{minipage}};
120 \end{tikzpicture}
121 \end{center}
122
123 \parskip 1ex plus 3pt
124 \parindent 0pt
125 \baselineskip 13pt plus 1pt
126 \lineskip 2pt plus 1pt
127 \lineskiplimit 2pt
128
129 \newpage
130
131 \section{Delimiters}
132 \label{delims}
133
134 The \p{longmath} package provides ``long'' versions of the "\left" and "\right" primitives.
135
136 \comm{"\lleft" [°scale°] °delimiter°} marks the beginning of a delimiter group and inserts an opening °delimiter°.
137
138 \comm{"\rright" [°scale°] °delimiter°} marks the end of a delimiter group and inserts a closing °delimiter°.
139
140 The optional °scale° argument will be explained below. The °delimiter° can be anything that is also accepted by "\left" and "\right", including a dot representing an invisible or null delimiter, any character with a "\delcode", or an explicit "\delimiter" or "\Udelimiter". If you want to use the \p{longmath} package with existing documents, or just stick to the familiar notation, and provided that this does not cause conflicts with other packages manipulating the original primitives, it is even save to say "\let\left\lleft" and "\let\right\rright".
141
142 Here is a simple example. Of course, as \LaTeX\ authors, we should better use some math environment instead of "$$", but let's stick to them here just to save some space, and indicate that everything should work regardless of what environment we use.
143 \begin{code}
144 The Sellmann-Yokuzi contribution to the
145 Johansson Entropy is given by
146 $$ S^\top = k · \lleft[ A + \lleft( B_C
147 + D^{E^2} \rright) ^ { \lleft( 3+κ^2 \rright)^2 }
148 + F \rright] $$
149 \end{code}
150 \begin{exec}
151 The Sellmann-Yokuzi contribution to the
152 Johansson Entropy is given by
153 $$ S^\top = k · \lleft[ A +
154 \lleft( B_C + D^{E^2} \rright)^{\lleft( 3+κ^2 \rright)^2 }
155 + F \rright] $$
156 \end{exec}
157 The "\lleft" and "\rright" delimiters enclose a \emph{delimiter group}. Within the group, you can have arbitrarily many inner or middle delimiters. As these often have different interpretations, several ``long'' variants of the "\middle" primitive are provided, associated with different types of math atoms.
158
159 \comm{"\mmiddle" [°scale°] °delimiter°} inserts an inner °delimiter° into a delimiter group.
160
161 \comm{"\mmrel" [°scale°] °delimiter°} interprets the °delimiter° as a relational operator.
162
163 \comm{"\mmbin" [°scale°] °delimiter°} interprets the °delimiter° as a binary operator.
164
165 \comm{"\mmord" [°scale°] °delimiter°} interprets the °delimiter° as an ordinary symbol.
166
167 \comm{"\mmop" [°scale°] °delimiter°} interprets the °delimiter° as a large operator.
168
169 \comm{"\mmpunct" [°scale°] °delimiter°} interprets the °delimiter° as a punctuation character.
170
171 They differ in the way \TeX\ inserts spaces before and after these delimiters, just as if you had written "\mathrel{"°delimiter°"}", "\mathbin{"°delimiter°"}", etc. Like the "\middle" primitive, the "\mmiddle" variant creates a "\mathinner{"°delimiter°"}".
172 \begin{code}
173 The scalar product is written as
174 $$ \lleft\langle A_1 \mmiddle| \tilde A_2 \rright\rangle . $$ %%%
175 \end{code}
176 \begin{exec}
177 The scalar product is written as
178 $$ \lleft\langle A_1 \mmiddle| \tilde A_2 \rright\rangle . $$
179 \end{exec}
180 \begin{code}
181 There are three parallel lines
182 $$ \lleft. A_1 B_1 \mmrel \Vert A_2 \hat B_2
183 \mmrel \Vert \hat A_2 B_2 \rright. . $$ %%%
184 \end{code}
185 \begin{exec}
186 There are three parallel lines
187 $$ \lleft. A_1 B_1 \mmrel \Vert A_2 \hat B_2
188 \mmrel \Vert \hat A_2 B_2 \rright. . $$
189 \end{exec}
190 \begin{code}
191 The centre of mass is defined as
192 $$ \vec R = \lleft( \sum_{k=1}^{n} m_k \, \vec r_k
193 \mmbin / \sum_{k=1}^{n} m_k \rright) . $$ %%%
194 \end{code}
195 \begin{exec}
196 The centre of mass is defined as
197 $$ \vec R = \lleft( \sum_{k=1}^{n} m_k \, \vec r_k
198 \mmbin / \sum_{k=1}^{n} m_k \rright) . $$
199 \end{exec}
200 \begin{code}
201 Vectors can be written as tuples like %%%
202 $$ \lleft( \tilde X_1 \mmpunct| \tilde X_2 \mmpunct|
203 \tilde X_3 \mmpunct| \dots \rright) . $$
204 \end{code}
205 \begin{exec}
206 Vectors can be written as tuples like
207 $$ \lleft( \tilde X_1 \mmpunct| \tilde X_2 \mmpunct|
208 \tilde X_3 \mmpunct| \dots \rright) . $$
209 \end{exec}
210 \begin{code}
211 This expression makes no sense:
212 $$ \lleft. \int \mmord( \sum \mmord[ \prod \mmord\} \rright. $$
213 \end{code}
214 \begin{exec}
215 This expression makes no sense:
216 $$ \lleft. \int \mmord( \sum \mmord[ \prod \mmord\} \rright. $$
217 \end{exec}
218 Unlike the standard "\left"-"\middle"-"\right" primitives, the long variants do not create subformulas or induce grouping at the \TeX\ level. \TeX nically, each delimiter is actually its own group, paired with an invisible delimiter, and with an empty "\hbox" between them. As such, it behaves like a single mathematical symbol of the respective type, or like an atom in \TeX's language. In particular, sub- and superscripts can be attached to individual delimiters, not only to the whole group, and the operator version really behaves like a big operator.
219 \begin{code}
220 Applying the triangular square limit, we get
221 $$ \lleft. W(x) + \mmop \uparrow_n^\infty
222 \frac{ 1-x^n }{ 1-x } \rright. = \log( x ). $$ %%%
223 \end{code}
224 \begin{exec}
225 Applying the triangular square limit, we get
226 $$ \lleft. W(x) + \mmop \uparrow_n^\infty
227 \frac{ 1-x^n }{ 1-x } \rright. = \log( x ). $$
228 \end{exec}
229 \begin{code}
230 The relations $1^\star$ and $2^\star$ imply the existence of
231 $$ \lleft[ \lleft( A_k \mmrel |^{\lleft(1^\star\rright)}
232 B_k \mmrel |^{\lleft(2^\star\rright)}
233 C_k \rright) \rright] .$$
234 \end{code}
235 \begin{exec}
236 The relations $1^\star$ and $2^\star$ imply the existence of
237 $$ \lleft[ \lleft( A_k \mmrel |^{\lleft(1^\star\rright)}
238 B_k \mmrel |^{\lleft(2^\star\rright)}
239 C_k \rright) \rright] .$$
240 \end{exec}
241 Within a formula or subformula, you can have unbalanced groups, or even inner delimiters only. The formula is then interpreted and typeset as if there were invisible delimiters at one or both ends.
242 \begin{code}
243 $$ \prod_{p\in\mathbfit{P}} G(p) \mmbin \uparrow
244 \sum_{q\in\mathbfit{Q}} H(q) \mmbin \downarrow
245 \lim_{x\to\infty} F(x) $$
246 \end{code}
247 \begin{exec}\:
248 $$ \prod_{p\in\mathbfit{P}} G(p) \mmbin \uparrow
249 \sum_{q\in\mathbfit{Q}} H(q) \mmbin \downarrow
250 \lim_{x\to\infty} F(x) $$
251 \end{exec}
252 \begin{code}
253 A skewed-rational fraction can be written as
254 $$ \frac{ x × \lleft( 1 - x^2 }
255 { x^2 + 1 \rright) × x } . $$ %%%
256 \end{code}
257 \begin{exec}
258 A skewed-rational fraction can be written as
259 $$ \frac{ x × \lleft( 1 - x^2 }{ x^2 + 1 \rright) × x } . $$
260 \end{exec}
261 When the formula is processed, each actual delimiter group is temporarily put in a box and the size of that box is determined. Then the dimensions of the empty "\hbox"es inside the fake delimiter groups are set accordingly, so that \TeX\ can apply its algorithm to finally fix the sizes of the delimiters. As this takes place after the whole formula has been transformed into a list of math nodes, no \TeX\ code has to be processed multiple times. It also allows to add some features that cannot be implemented otherwise, unless you are willing to go really deep into macro and token magic.
262
263 For example, the limits of large operators like sums or integrals can be excluded from the box that determines the delimiter size. This feature can be turned on and off with two control sequences.
264
265 \comm{"\includelimits"} includes the limits of large operators (default).
266
267 \comm{"\ignorelimits"} ignores the limits of large operators.
268
269 It is possible to use the switch in the middle of a formula or even inside a delimiter group. The switch position at the moment the operator is created determines whether its limits are included or ignored.
270 \begin{code}
271 \ignorelimits
272 $$ \vec R = \lleft( \sum_{k=1}^{n} m_k \, \vec r_k
273 \mmbin / \sum_{k=1}^{n} m_k \rright) . $$ %%%
274 \end{code}
275 \begin{exec}\:
276 \ignorelimits
277 $$ \vec R = \lleft( \sum_{k=1}^{n} m_k \, \vec r_k
278 \mmbin / \sum_{k=1}^{n} m_k \rright) . $$ %%%
279 \end{exec}
280 \begin{code}
281 $$ \lleft[ \ignorelimits \sum_{A_X^3}^{A_Y^3} F(Z)
282 + \includelimits \sum_a^c f(x) \rright] $$ %%%
283 \end{code}
284 \begin{exec}\:
285 $$ \lleft[ \ignorelimits \sum_{A_X^3}^{A_Y^3} F(Z)
286 + \includelimits \sum_a^c f(x) \rright] $$ %%%
287 \end{exec}
288 \begin{code}
289 \includelimits
290 $$ A = 3 × \lleft[ \int\limits_1^5
291 \lleft( 1 + \sqrt{ 1 + x } \rright) \, \mathrm{d}x \rright] $$
292 \end{code}
293 \begin{exec}\:
294 \includelimits
295 $$ A = 3 × \lleft[ \int\limits_1^5
296 \lleft( 1 + \sqrt{ 1 + x } \rright) \, \mathrm{d}x \rright] $$
297 \end{exec}
298 \begin{code}
299 \ignorelimits
300 $$ A = 3 × \lleft[ \int\limits_1^5
301 \lleft( 1 + \sqrt{ 1 + x } \rright) \, \mathrm{d}x \rright] $$
302 \end{code}
303 \begin{exec}\:
304 \ignorelimits
305 $$ A = 3 × \lleft[ \int\limits_1^5
306 \lleft( 1 + \sqrt{ 1 + x } \rright) \, \mathrm{d}x \rright] $$
307 \end{exec}
308 There are several ways to fine tune the sizes of delimiters. A priori, the minimal size of all delimiters within a group is determined by the total height and depth of everything in this group, except for the delimiters themselves. \TeX\ then checks if a predefined character with the required size exists in the current math font and uses it. Otherwise it creates a stretched symbol with the required size.
309
310 Two plain \TeX\ parameters modify the finally chosen sizes of all delimiters. By default, they are used to shrink them slightly, which makes the final formula look less bulky while keeping it readably. This can be seen in the integral example above. An additional third parameter is provided by the \p{longmath} package, which applies to middle delimiters only.
311
312 \comm{"\delimiterfactor" °factor°} scales all delimiters by $°factor°/1000$
313 (default \the\delimiterfactor).
314
315 \comm{"\delimitershortfall" °dimension°} limits the shrinkage of delimiters to the °dimension°
316 (default \the\delimitershortfall).
317
318 \comm{"\delimiterscale" °factor°} additionally scales middle delimiters by $°factor°/1000$
319 (default \the\delimiterscale).
320
321 The parameters "\delimiterfactor" (a count register) and "\delimitershortfall" (a dimension register) are explained in the \TeX book. Briefly summarised, every delimiter is finally resized by the given $°factor°/1000$, but the shrinkage is limited to the given °dimension°. The "\delimiterscale" (another count register) is applied to all middle delimiters before the final scaling is applied, and there is no limited shrinkage at this stage.
322 \begin{code}
323 \delimiterscale 400
324 $$ \vec R = \lleft( \sum_{k=1}^{n} m_k \, \vec r_k
325 \mmbin / \sum_{k=1}^{n} m_k \rright) . $$ %%%
326 \end{code}
327 \begin{exec}\:
328 \delimiterscale 400
329 $$ \vec R = \lleft( \sum_{k=1}^{n} m_k \, \vec r_k
330 \mmbin / \sum_{k=1}^{n} m_k \rright) . $$ %%%
331 \end{exec}
332 Instead of changing "\delimiterscale", the scale factor can also be applied to each delimiter individually, using the optional °scale° argument. In this case, the "\delimiterscale" is ignored and replaced by the given number.
333 \begin{code}
334 $$ X = \lleft ( \sum_k^\infty A \mmbin 900 | \sum_k^\infty B
335 \mmbin 700 | \sum_k^\infty C \mmbin 500 | \sum_k^\infty D
336 \mmbin 300 | \sum_k^\infty E \rright ) $$
337 \end{code}
338 \begin{exec}\:
339 $$ X = \lleft ( \sum_k^\infty A \mmbin 900 | \sum_k^\infty B
340 \mmbin 700 | \sum_k^\infty C \mmbin 500 | \sum_k^\infty D
341 \mmbin 300 | \sum_k^\infty E \rright ) $$
342 \end{exec}
343 If you want to produce strange and ugly results, you can even scale the opening and closing delimiters independently, or choose factors greater than $1000$.
344 \begin{code}
345 $$ \vec R = \lleft 900 ( \sum_{k=1}^{n} m_k \, \vec r_k
346 \mmbin 1300 \divslash \sum_{k=1}^{n} m_k \rright 700 ) $$
347 \end{code}
348 \begin{exec}\:
349 $$ \vec R = \lleft 900 ( \sum_{k=1}^{n} m_k \, \vec r_k
350 \mmbin 1300 \divslash \sum_{k=1}^{n} m_k \rright 700 ) $$
351 \end{exec}
352
353
354 \section{Alignment}
355 \label{align}
356
357 There are two more special delimiter types not listed in section~\ref{delims}. They are treated as middle delimiters regarding the logical grouping, but when they are finally typeset, they are treated as opening and closing delimiters.
358
359 \comm{"\mleft" [°scale°] °delimiter°} typesets a left °delimiter°, but does not open a new group.
360
361 \comm{"\mright" [°scale°] °delimiter°} typesets a right °delimiter°, but does not close the current group.
362
363 To see what they are useful for, consider the following example.
364 \begin{code}
365 $$ \lleft( A + \sum B \rright)
366 \lleft( C + \int D \rright) $$
367 \end{code}
368 \begin{exec}\:
369 $$ \lleft( A + \sum B \rright)
370 \lleft( C + \int D \rright) $$
371 \end{exec}
372 Can we make the brackets to have the same size? A few "\vphantom"s would probably fix it. But then we need to know in advance which symbols are the responsible ones, or we have to place the content of each bracket as a phantom inside the other one and make \TeX\ process everything twice. Alternatively, we could include everything in a single group and make the two brackets in the middle inner delimiters. But then the correct spacing between them and the adjacent symbols is lost.
373 \begin{code}
374 $$ \lleft( A + \sum B \mmiddle )
375 \mmiddle ( C + \int D \rright) $$
376 \end{code}
377 \begin{exec}\:
378 $$ \lleft( A + \sum B \mmiddle )
379 \mmiddle 1000 ( C + \int D \rright) $$
380 \end{exec}
381 With "\mleft" and "\mright", we get the same sizes and the correct spacing. Since in this case we only have these two pairs of brackets, we can simple make the whole formula a single group.
382 \begin{code}
383 $$ \mleft( A + \sum B \mright)
384 \mleft( C + \int D \mright) $$
385 \end{code}
386 \begin{exec}\:
387 $$ \mleft( A + \sum B \mright)
388 \mleft( C + \int D \mright) $$
389 \end{exec}
390 What "\mleft" and "\mright" basically do is not to adapt the opening and closing delimiters to the content between them, but align them with the enclosing group.
391 \begin{code*}
392 $$ \lleft( \mleft( 1 + 2 \mright) \mleft( 1 + 2^2 \mright) \mleft( 1 + 2^{2^2} \mright)
393 \mleft( 1 + 2^{2^{2^2}} \mright) + \mleft( 1 + 3 \mright) \mleft( 1 + 3^3 \mright)
394 \mleft( 1 + 3^{3^3} \mright) + \mleft( 1 + 5 \mright) \mleft( 1 + 5^5 \mright) \rright) $$
395 \end{code*}
396 \begin{exec}\:
397 $$ \lleft( \mleft( 1 + 2 \mright) \mleft( 1 + 2^2 \mright) \mleft( 1 + 2^{2^2} \mright)
398 \mleft( 1 + 2^{2^{2^2}} \mright) + \mleft( 1 + 3 \mright) \mleft( 1 + 3^3 \mright)
399 \mleft( 1 + 3^{3^3} \mright) + \mleft( 1 + 5 \mright) \mleft( 1 + 5^5 \mright) \rright) $$
400 \end{exec}
401 But what if there is more stuff inside the enclosing group and we only want to align particular brackets with each other? Something like this, and we want both the square and the round brackets to be aligned.
402 \begin{code*}
403 $$ F\lleft[ X \rright] \lleft( 1 + 2^2 \rright) \lleft( 1 + 2^{2^2} \rright)
404 + F\lleft[ X^2 \rright] \lleft( 1 + 3^3 \rright) \lleft( 1 + 3^{3^3} \rright)
405 + F\lleft[ X^3 \rright] \lleft( 1 + 5^5 \rright) \lleft( 1 + 5^{5^5} \rright) $$
406 \end{code*}
407 \begin{exec}\:
408 $$ F\lleft[ X \rright] \lleft( 1 + 2^2 \rright) \lleft( 1 + 2^{2^2} \rright)
409 + F\lleft[ X^2 \rright] \lleft( 1 + 3^3 \rright) \lleft( 1 + 3^{3^3} \rright)
410 + F\lleft[ X^3 \rright] \lleft( 1 + 5^5 \rright) \lleft( 1 + 5^{5^5} \rright) $$
411 \end{exec}
412 Now we definitely need "\vphantom"s, right? In principle, yes, but the \p{longmath} package provides a way to set them up automatically and hide them inside the delimiters. To use this feature, we have to attach a tag to those delimiters we want to align. The tag is enclosed in braces and placed between the control sequence and the delimiter symbol.
413
414 \comm{"\"°type° "{"°tag°"}" [°scale°] °delimiter°} aligns this °delimiter° with all delimiters with the same °tag°.
415
416 Here, "\"°type° is any of the above delimiter types, and the °tag° is any string that would also do as, say, an argument to "\label". The basic idea is to make all delimiters with the same °tag° attached to them behave as if they belong to the same group. So, the problem just posed can be solved as follows.
417 \begin{code*}
418 $$ F\lleft {Fx} [ X \rright] \lleft {Pw} ( 1 + 2^2 \rright) \lleft {Pw} ( 1 + 2^{2^2} \rright)
419 + F\lleft {Fx} [ X^2 \rright] \lleft {Pw} ( 1 + 3^3 \rright) \lleft {Pw} ( 1 + 3^{3^3} \rright)
420 + F\lleft {Fx} [ X^3 \rright] \lleft {Pw} ( 1 + 5^5 \rright) \lleft {Pw} ( 1 + 5^{5^5} \rright) $$
421 \end{code*}
422 \begin{exec}\:
423 $$ F\lleft {Fx} [ X \rright] \lleft {Pw} ( 1 + 2^2 \rright) \lleft {Pw} ( 1 + 2^{2^2} \rright)
424 + F\lleft {Fx} [ X^2 \rright] \lleft {Pw} ( 1 + 3^3 \rright) \lleft {Pw} ( 1 + 3^{3^3} \rright)
425 + F\lleft {Fx} [ X^3 \rright] \lleft {Pw} ( 1 + 5^5 \rright) \lleft {Pw} ( 1 + 5^{5^5} \rright) $$
426 \end{exec}
427 It is enough to tag only the left delimiters, or just one delimiter per group, because those belonging to the same group are aligned anyway. What we actually do is to align groups with each other, not individual delimiters.
428
429 The groups being linked need not belong to a common subformula. Here we want to align the brackets and the division slashed in the numerators.
430 \begin{code}
431 $$ \frac{ \lleft ( a + 1 \rright) \mmord / x }{a}
432 + \frac{ \lleft ( \sum_k b^k \rright) \mmord / y }{b}
433 + \frac{ \lleft ( c^2 + 1 \rright) \mmord / z }{c} $$ %%%
434 \end{code}
435 \begin{exec}\:
436 $$ \frac{ \lleft ( a + 1 \rright) \mmord / x }{a}
437 + \frac{ \lleft ( \sum_k b^k \rright) \mmord / y }{b}
438 + \frac{ \lleft ( c^2 + 1 \rright) \mmord / z }{c} $$
439 \end{exec}
440 This is how it can be done.
441 \begin{code}
442 $$ \frac{ \lleft {f5} ( a + 1 \rright) \mmord / x }{a}
443 + \frac{ \lleft {f5} ( \sum_k b^k \rright) \mmord / y }{b}
444 + \frac{ \lleft {f5} ( c^2 + 1 \rright) \mmord / z }{c} $$
445 \end{code}
446 \begin{exec}\:
447 $$ \frac{ \lleft {f5} ( a + 1 \rright) \mmord / x }{a}
448 + \frac{ \lleft {f5} ( \sum_k b^k \rright) \mmord / y }{b}
449 + \frac{ \lleft {f5} ( c^2 + 1 \rright) \mmord / z }{c} $$
450 \end{exec}
451 Note that the division slashes are outside the linked groups. But in each numerator, the slash belongs to the enclosing group, which is the subformula formed by the numerator. As this group also contains the brackets, the size of the slash is also adapted to them and thus all slashes get the same size as well. Alternatively, we could have done it like this.
452 \begin{code}
453 $$ \frac{ \mleft ( a + 1 \mright) \mmord {f6} / x }{a}
454 + \frac{ \mleft ( \sum_k b^k \mright) \mmord {f6} / y }{b}
455 + \frac{ \mleft ( c^2 + 1 \mright) \mmord {f6} / z }{c} $$
456 \end{code}
457 \begin{exec}\:
458 $$ \frac{ \mleft ( a + 1 \mright) \mmord {f6} / x }{a}
459 + \frac{ \mleft ( \sum_k b^k \mright) \mmord {f6} / y }{b}
460 + \frac{ \mleft ( c^2 + 1 \mright) \mmord {f6} / z }{c} $$
461 \end{exec}
462 But not like this, which aligns the slashes, but not the brackets.
463 \begin{code}
464 $$ \frac{ \lleft ( a + 1 \rright) \mmord {f7} / x }{a}
465 + \frac{ \lleft ( \sum_k b^k \rright) \mmord {f7} / y }{b}
466 + \frac{ \lleft ( c^2 + 1 \rright) \mmord {f7} / z }{c} $$
467 \end{code}
468 \begin{exec}\:
469 $$ \frac{ \lleft ( a + 1 \rright) \mmord {f7} / x }{a}
470 + \frac{ \lleft ( \sum_k b^k \rright) \mmord {f7} / y }{b}
471 + \frac{ \lleft ( c^2 + 1 \rright) \mmord {f7} / z }{c} $$
472 \end{exec}
473 For the alignment to work, the linked delimiters need not be visible. An invisible inner delimiter basically behaves like a "\vphantom", whose content is the whole group to which this delimiter belongs. More precisely, it is actually the empty "\hbox" that is present in our special delimiters which replaces the "\vphantom". We can use this to align the square roots in the following example.
474 \begin{code}
475 $$ \sqrt{ \mleft {sq8} . a + 1 }
476 + \sqrt{ \mleft {sq8} . \sum\nolimits_k b_k } %%%
477 + \sqrt{ \mleft {sq8} . c^2 + 1 } $$
478 \end{code}
479 \begin{exec}\:
480 $$ \sqrt{ \mleft {sq8} . a + 1 }
481 + \sqrt{ \mleft {sq8} . \sum\nolimits_k b_k }
482 + \sqrt{ \mleft {sq8} . c^2 + 1 } $$
483 \end{exec}
484 Why did we use "\mleft" here, and not one of the middle delimiters? The first reason is that putting an opening atom at the beginning of a subformula will get the horizontal spacing correct, independent of what kind of symbol follows. The second reason is that a middle delimiter would be scaled by "\delimiterscale", so that it wouldn't have the required size to align the heights of the square roots. The "\delimiterfactor" is irrelevant here, because it doesn't affect an invisible delimiter.
485
486 We can even go a step further and link delimiters in different equations and, in fact, all across the document.
487 \begin{code}
488 Equations that start with
489 $$ \lleft( \int\limits_1^\infty f(x) \, \mathrm{d}x \rright)
490 \lleft {longeq} ( \sum_k a_k + 1000 + 999 + \cdots $$
491 often go on for pages and end with
492 $$ \cdots + 1 \rright {longeq} ) = 0 . $$
493 \end{code}
494 \begin{exec}
495 Equations that start with
496 $$ \lleft( \int\limits_1^\infty f(x) \, \mathrm{d}x \rright)
497 \lleft {longeq} ( \sum_k a_k + 1000 + 999 + \cdots $$
498 often go on for pages and end with
499 $$ \cdots + 1 \rright {longeq} ) = 0 . $$
500 \end{exec}
501 To make this possible, the \LaTeX\ method of storing information in the "aux" file is used. The dimensions of all tagged delimiter groups are saved and reloaded when the document is typeset the next time. It therefore requires a second run to get the sizes of linked delimiters correct. If the size of any delimiter changes while the typesetting is in progress, a warning message is issued at the end, similar to the message that you need to rerun the document to get all the "\ref"erences to "\label"s right.
502
503 You will also get a warning message if you set up the tags so that some delimiter group is linked to its own parent or subgroup. In such a case, there is no consistent way to determine the required sizes. With each run, they will change randomly or even start to increase and diverge. It's okay, however, to link delimiters in different math styles. You can link an exponent in script style to its own basis in display style, although this might not make much sense.
504
505 For all this to work, the tags must be document wide unique. But unlike equation labels or bibliography entries, they typically only link delimiters within a single equation or an array of equations. It is therefore preferable to have short tags like the ones used above, or even simple letters or numbers. To make this possible, you can locally define a °prefix°, which is added to each tag used within its scope.
506
507 \comm{"\delimiterprefix{"°prefix°"}"} prepends the °prefix° to the tags of all tagged delimiters.
508
509 It is then sufficient to use a document wide unique prefix for each section, equation, or whatever scope suits best. The setting is local to the \TeX\ group, but if the same prefix is used at different places, the tagged delimiters within those scopes are linked to each other. For example, if the prefix is "introduction-" and the tag "a2" is attached to a delimiter, then the actual tag used internally is "introduction-a2", and this is a global name.
510
511 You can even automate this, by setting a dynamical prefix like this in the preamble.
512 \begin{code*}
513 \delimiterprefix{\theequation.}
514 \end{code*}
515 Provided that you use unique equations numbers, and link delimiters within single equations only, your tags will then always be local to the current equation, something like "5.16.a" if the tag "a" is used in equation~(5.16).
516
517 The perhaps most useful application of tagged delimiters is to typeset formulas that extend over several cells or lines in an array. Here is a little challenge. In the following array, we want the multiplication and addition operators to be aligned vertically, and of course the brackets to be adapted to the content they enclose. We use the \p{array} package to define a few special column types to get the math style and the spacing correct.
518 \begin{code*}
519 \newcolumntype{d}{ >{\displaystyle} c }
520 \newcolumntype{s}{ @{} >{{}} c <{{}} @{} }
521 \end{code*}
522 \newcolumntype{d}{ >{\displaystyle} c }
523 \newcolumntype{s}{ @{} >{{}} c <{{}} @{} }
524 \begin{code}
525 $$ \begin{array}{dsdsdsd}
526 \lleft [ Z & - & \sum_k A & × &
527 \lleft ( B & + & C^X \rright ) \rright ] \\[3ex] %%%
528 \lleft [ P & × & \lleft ( U & + &
529 \int_R V \rright ) & - & W^Y \rright ]
530 \end{array} $$
531 \end{code}
532 \begin{exec}
533 $$ \begin{array}{dsdsdsd}
534 \lleft[ Z & - & \sum_k A & × &
535 \lleft( B & + & C^X \rright) \rright] \\[3ex]
536 \lleft[ P & × & \lleft( U & + &
537 \int_R V \rright ) & - & W^Y \rright]
538 \end{array} $$
539 \end{exec}
540 In an "array", each cell is typeset as a separate formula. Therefore, the delimiters in each cell are adapted only to the content of this particular cell. Apparently, it would be quite a complicated task to fix this with "\vphantom"s. Let's try to simply link the delimiters that belong together.
541 \begin{code}
542 $$ \begin{array}{dsdsdsd}
543 \lleft {a1} [ Z & - & \sum_k A & × &
544 \lleft {b1} ( B & + & C^X \rright {b1} ) \rright {a1} ] \\[3ex]
545 \lleft {a2} [ P & × & \lleft {b2} ( U & + &
546 \int_R V \rright {b2} ) & - & W^Y \rright {a2} ]
547 \end{array} $$
548 \end{code}
549 \begin{exec}
550 $$ \begin{array}{dsdsdsd}
551 \lleft {a1} [ Z & - & \sum_k A & × &
552 \lleft {b1} ( B & + & C^X \rright {b1} ) \rright {a1} ] \\[3ex]
553 \lleft {a2} [ P & × & \lleft {b2} ( U & + &
554 \int_R V \rright {b2} ) & - & W^Y \rright {a2} ]
555 \end{array} $$
556 \end{exec}
557 A first step, but not the expected result. It seems that we have to look at it more closely and sort out which parts of which cells actually belong to the same groups. But there is in fact a simple solution that doesn't require any deeper thinking or sorting out. We just need to connect the end of each cell to the beginning of the next one. We can do this by inserting invisible delimiters.
558 \begin{code}
559 $$ \begin{array}{dsdsdsd}
560 \lleft[ Z \mright{c1}. & - & \mleft{c1}. \sum_k A \mright{c2}.
561 & × & \mleft{c2}. \lleft( B \mright{c3}. & + &
562 \mleft{c3}. C^X \rright ) \rright ] \\[3ex]
563 \lleft[ P \mright{d1}. & × & \mleft{d1}. \lleft ( U \mright{d2}.
564 & + & \mleft{d2}. \int_R V \rright ) \mright{d3}. & - &
565 \mleft{d3}. W^Y \rright ] \end{array} $$
566 \end{code}
567 \begin{exec}
568 $$ \begin{array}{dsdsdsd}
569 \lleft[ Z \mright{c1}. & - & \mleft{c1}. \sum_k A \mright{c2}.
570 & × & \mleft{c2}. \lleft( B \mright{c3}. & + &
571 \mleft{c3}. C^X \rright ) \rright ] \\[3ex]
572 \lleft[ P \mright{d1}. & × & \mleft{d1}. \lleft ( U \mright{d2}.
573 & + & \mleft{d2}. \int_R V \rright ) \mright{d3}. & - &
574 \mleft{d3}. W^Y \rright ] \end{array} $$
575 \end{exec}
576 This is the desired output, but the code starts to look complicated. But it is a simple rule, so there should be a way to automate it. Can we include the invisible linking delimiters into the cell template? The problem is that we need a unique tag for each transition from one cell to the next. For this purpose, two macros are provided.
577
578 \comm{"\pushdelimiter"} inserts an invisible closing delimiter with an automatically generated unique tag.
579
580 \comm{"\pulldelimiter"} inserts an invisible opening delimiter with the previously generated tag.
581
582 The generated tags are stored on a stack, so that multiple push and pull operations can be nested. They are globally unique and survive the current \TeX\ group. If we include the macros into the cell template, they connect each cell to the next one. We can also define templates that start a new sequence or end the current one. As Lua\TeX\ allows this, let's use Greek letters for the beginning, the middle, and the end of a row.
583 \begin{code*}
584 \newcolumntype{α}{ >{ \displaystyle } c <{ \pushdelimiter } }
585 \newcolumntype{μ}{ >{ \displaystyle \pulldelimiter } c <{ \pushdelimiter } }
586 \newcolumntype{ω}{ >{ \displaystyle \pulldelimiter } c }
587 \end{code*}
588 \newcolumntype{α}{ >{ \displaystyle } c <{ \pushdelimiter } }
589 \newcolumntype{μ}{ >{ \displaystyle \pulldelimiter } c <{ \pushdelimiter } }
590 \newcolumntype{ω}{ >{ \displaystyle \pulldelimiter } c }
591 Now the code is as simple as it was in the beginning. We can just ignore the cell boundaries and write the formula as if it was a single line in "$$"s, or whatever single line math environment.
592 \begin{code}
593 $$ \begin{array}{αsμsμsω}
594 \lleft [ Z & - & \sum_k A & × &
595 \lleft ( B & + & C^X \rright ) \rright ] \\[3ex] %%%
596 \lleft [ P & × & \lleft ( U & + &
597 \int_R V \rright ) & - & W^Y \rright ]
598 \end{array} $$
599 \end{code}
600 \begin{exec}\.[-4ex]
601 $$ \begin{array}{αsμsμsω}
602 \lleft [ Z & - & \sum_k A & × &
603 \lleft ( B & + & C^X \rright ) \rright ] \\[3ex] %%%
604 \lleft [ P & × & \lleft ( U & + &
605 \int_R V \rright ) & - & W^Y \rright ]
606 \end{array} $$
607 \end{exec}
608 If you want the formula to continue on the next line with pending delimiters, you can include the push and pull macros into the line separator as well.
609 \begin{code}
610 \newcommand\continue[1][0pt]{ \pushdelimiter \\[#1] \pulldelimiter }
611 $$ \begin{array}{αsμsμsω}
612 \lleft \{ Z & - & \sum_k \lleft ( A & × &
613 B^3 \rright ) & + & \continue[3ex] %%%
614 & + & \lleft ( U & + &
615 \int_R V \rright ) & - & W^Y \rright \}
616 \end{array} $$
617 \end{code}
618 \begin{exec}
619 \newcommand\continue[1][0pt]{ \pushdelimiter \\[#1] \pulldelimiter }
620 $$ \begin{array}{αsμsμsω}
621 \lleft \{ Z & - & \sum_k \lleft ( A & × &
622 B^3 \rright ) & + & \continue[3ex] %%%
623 & + & \lleft ( U & + &
624 \int_R V \rright ) & - & W^Y \rright \}
625 \end{array} $$
626 \end{exec}
627 A construction like this can also be used with \p{amsmath} environments like "multiline" or "split" , which require explicit line breaks to be inserted into long formulas. The "longmath" environment described in section~\ref{multiline} provides an alternative method to typeset long formulas without the need to specify the breakpoints manually.
628
629 \section{Automatic Nesting}
630
631 It is possible to select the kinds of brackets used as outer delimiters automatically depending on the nesting level. This might not add much value for formulas that are explicitly written into the document. But it could be useful for semi-automatically produced formulas, where the author doesn't have direct control over individual symbols.
632
633 The basic idea is to define a collection of delimiter pairs, and let \TeX\ pick them according to the current nesting level.
634
635 \comm{"\autodelimiters{"°sample°"}"} defines a collection of nested delimiters pairs.
636
637 The °sample° must be an otherwise empty, nested structure of delimiters enclosing an asterisk "*" as a single object.
638 \autodelimiters{ \lfloor [ \{ ( * ) \} ] \rceil }
639 \begin{code*}
640 \autodelimiters{ \lfloor [ \{ ( * ) \} ] \rceil }
641 \end{code*}
642 Once this is set up, you can pick one of them by using "*" as a variable delimiter.
643 \begin{code}
644 The corrected Sellmann-Yokuzi contribution to the
645 Johansson Entropy is given by
646 $$ S^\top = k · \lleft* A + \lleft* B_C +
647 \lleft* D^E \rright* ^ 2 \rright*
648 ^ { \lleft* 3+κ \rright* ^2 } + F \rright* $$
649 \end{code}
650 \begin{exec}
651 The corrected Sellmann-Yokuzi contribution to the
652 Johansson Entropy is given by
653 $$ S^\top = k · \lleft* A + \lleft* B_C +
654 \lleft* D^E \rright* ^ 2
655 \rright* ^ { \lleft* 3+κ \rright* ^2 } + F \rright* $$
656 \end{exec}
657 If the nesting level exceeds the number of sample pairs provided, the outermost pair is repeated.
658 \begin{code+}
659 $$ \lleft* A + \lleft* B + \lleft* C + \lleft*
660 D + \frac{ \lleft* X + Y \rright* × Z }{ W }
661 \rright* · E \rright* · F \rright* · G \rright* $$
662 \end{code+}
663 \begin{exec}\:
664 $$ \lleft* A + \lleft* B + \lleft* C + \lleft*
665 D + \frac{ \lleft* X + Y \rright* × Z }{ W }
666 \rright* · E \rright* · F \rright* · G \rright* $$
667 \end{exec}
668 Automatic delimiters can be mixed with explicit delimiters. When the nesting level is determined, only the "*" delimiters are taken into account. To demonstrate this, let's choose a different collection and set a negative value for "\delimitershortfall". This makes the bracket size increase linearly with the nesting level.
669 \autodelimiters{ < \lceil \lfloor [ \{ ( * ) \} ] \rfloor \rceil > }
670 \begin{code*}
671 \delimitershortfall -2pt
672 \autodelimiters{ < \lceil \lfloor [ \{ ( * ) \} ] \rfloor \rceil > }
673 \end{code*}
674 This is what we get with automatic brackets only. The numbers indicate the actually used level.
675 \begin{code}
676 $$ \lleft* 5 + \lleft* 4 + \lleft* 3
677 + \lleft* 2 + \lleft* 1 + A \rright* + B \rright*
678 + C \rright* + D \rright* + E \rright* $$
679 \end{code}
680 \begin{exec}\:
681 \delimitershortfall -2pt
682 $$ \lleft* 5 + \lleft* 4 + \lleft* 3
683 + \lleft* 2 + \lleft* 1 + A \rright* + B \rright*
684 + C \rright* + D \rright* + E \rright* $$
685 \end{exec}
686 If we replace the second level by explicit square brackets, the counting continues at the third level.
687 \begin{code}
688 $$ \lleft* 4 + \lleft* 3 + \lleft* 2
689 + \lleft[ 0 + \lleft* 1 + A \rright* + B \rright]
690 + C \rright* + D \rright* + E \rright* $$
691 \end{code}
692 \begin{exec}\:
693 \delimitershortfall -2pt
694 $$ \lleft* 4 + \lleft* 3 + \lleft* 2
695 + \lleft[ 0 + \lleft* 1 + A \rright* + B \rright]
696 + C \rright* + D \rright* + E \rright* $$
697 \end{exec}
698 And here two levels are skipped.
699 \begin{code}
700 $$ \lleft* 3 + \lleft| 0 + \lleft* 2
701 + \lleft[ 0 + \lleft* 1 + A \rright* + B \rright]
702 + C \rright* + D \rright| + E \rright* $$
703 \end{code}
704 \begin{exec}\:
705 \delimitershortfall -2pt
706 $$ \lleft* 3 + \lleft| 0 + \lleft* 2
707 + \lleft[ 0 + \lleft* 1 + A \rright* + B \rright]
708 + C \rright* + D \rright| + E \rright* $$
709 \end{exec}
710 In the first experimental version of this packages, there was an interaction between automatic and explicit brackets. This has been removed. It didn't work well with linked groups, and it caused problems with bracktes used for purposes other than grouping, like function arguments, binomial coeffiecients etc.
711
712 If automatic delimiters are tagged and aligned, this also applies to the chosen delimiter from the collection. Here is a typical example. Without tagging, we get this.
713 \begin{code}
714 $$ \lleft * \frac{ n+1 }{ n^2 } \rright * ^2
715 + \lleft * \frac{ n }{ \lleft * n - 1 \rright *^2 } %%%
716 \rright * ^2 $$
717 \end{code}
718 \begin{exec}\:
719 $$ \lleft * \frac{ n+1 }{ n^2 } \rright * ^2
720 + \lleft * \frac{ n }{ \lleft * n - 1 \rright *^2}
721 \rright * ^2 $$
722 \end{exec}
723 If the outer brackets are aligned, both become second level brackets.
724 \begin{code}
725 $$ \lleft {qx} * \frac{ n+1 }{ n^2 } \rright * ^2
726 + \lleft {qx} * \frac{ n }{ \lleft * n - 1 \rright *^2}
727 \rright * ^2 $$
728 \end{code}
729 \begin{exec}\:
730 $$ \lleft {qx} * \frac{ n+1 }{ n^2 } \rright * ^2
731 + \lleft {qx} * \frac{ n }{ \lleft * n - 1 \rright *^2}
732 \rright * ^2 $$
733 \end{exec}
734 As a last challenge, let's consider the array from the previous section with a slight modification. If we replace all brackets with automatic delimiters, but do not link the cells, we get this.
735 \begin{code}
736 $$ \begin{array}{dsdsdsd}
737 \lleft * Z & - & \sum_k A & × &
738 \lleft * B & + & C^X \rright * \rright * \\[3ex] %%%
739 \lleft * P & × & \lleft * \lleft * U^2 \rright * & + &
740 \int_R V \rright * & - & W^Y \rright *
741 \end{array} $$
742 \end{code}
743 \begin{exec}\.[-4ex]
744 $$ \begin{array}{dsdsdsd}
745 \lleft * Z & - & \sum_k A & × &
746 \lleft * B & + & C^X \rright * \rright * \\[3ex] %%%
747 \lleft * P & × & \lleft * \lleft * U^2 \rright * & + &
748 \int_R V \rright * & - & W^Y \rright *
749 \end{array} $$
750 \end{exec}
751 As expected, only the brackets within each cell are set up properly, but with no relation to those in the other cells. If we use the version with linked cells, we get the intended result.
752 \begin{code}
753 $$ \begin{array}{αsμsμsω}
754 \lleft * Z & - & \sum_k A & × &
755 \lleft * B & + & C^X \rright * \rright * \\[3ex] %%%
756 \lleft * P & × & \lleft * \lleft * U^2 \rright * & + &
757 \int_R V \rright * & - & W^Y \rright *
758 \end{array} $$
759 \end{code}
760 \begin{exec}\.[-4ex]
761 \delimiterprefix{A}
762 $$ \begin{array}{αsμsμsω}
763 \lleft * Z & - & \sum_k A & × &
764 \lleft * B & + & C^X \rright * \rright * \\[3ex] %%%
765 \lleft * P & × & \lleft * \lleft * U^2 \rright * & + &
766 \int_R V \rright * & - & W^Y \rright *
767 \end{array} $$
768 \end{exec}
769
770
771 \section{Multi Line Formulas}
772 \label{multiline}
773 Unlike the \TeX\ primitives, the \p{longmath} macros do not create a subformula that cannot be broken into lines. In inline math mode, long formulas with delimiter groups can extend over several lines just like ordinary text.
774 \begin{code*}
775 \newcommand\polyA{ x^{10} + x^9 - x^8 + 2 x^6 + 9 x^5 + 2 x^4 - 4 x^3 - 2 x^2 + 6 x + 4 }
776 \newcommand\polyB{ x^4 - x^3 + x + 2 } \newcommand\polyC{ x^6 + 2 x^5 + x^4 - 2 x^2 + 2 x + 2 }
777 \end{code*}
778 \newcommand\polyA{ x^{10} + x^9 - x^8 + 2 x^6 + 9 x^5 + 2 x^4 - 4 x^3 - 2 x^2 + 6 x + 4 }
779 \newcommand\polyB{ x^4 - x^3 + x + 2 } \newcommand\polyC{ x^6 + 2 x^5 + x^4 - 2 x^2 + 2 x + 2 }
780 \begin{code+}
781 Factorising the polynomial
782 $ P\lleft( \polyA \rright) $
783 gives $ P \lleft( \polyB \rright)
784 · P \lleft( \polyC \rright) $. %%%
785 \end{code+}
786 \begin{exec*}\openup 1pt
787 Factorising the polynomial
788 $ P\lleft( \polyA \rright) $
789 gives $ P \lleft( \polyB \rright)
790 · P \lleft( \polyC \rright) $.
791 \end{exec*}
792 There is no interference between nested delimiter groups and logical \TeX\ groups. Delimiters can be placed deep inside "\begingroup"-"\endgroup" constructs, and they do not create such groups themselves. The following example uses the \p{multido} package. It wouldn't work with "\left", "\right" and "\middle".
793 \begin{code}
794 Applying the Hofstadt Zebelajev theorem, we conclude that
795 $ \lleft( \hat A_0
796 \multido{\i=1+1}{10}{ \mmbin \uparrow \hat A_{\i} }
797 \rright) \in \lleft[\mathcal{H}^\infty\rright]^{11}$.
798 \end{code}
799 \begin{exec*}\openup 2pt
800 Applying the Hofstadt Zebelajev theorem, we conclude that
801 $ \lleft( \hat A_0
802 \multido{\i=1+1}{10}{ \mmbin \uparrow \hat A_{\i} }
803 \rright) \in \lleft[\mathcal{H}^\infty\rright]^{11}$.
804 \end{exec*}
805 For multi line formulas in display mode, \p{longmath} provides a special environment.
806
807 \comm{"\begin{longmath}["°align°"]{"°width°"}"} begins a multi line expression in display mode.
808
809 \comm{"\end{longmath}"} ends a multi line expression in display mode.
810
811 It works like the "minipage" environment. You have to specify the °width° of the box the formula will by placed into, and how to °align° it vertically with the rest of the displayed equation. The optional alignment argument is either "c" for centre, which is the default, or "t" for top or "b" for bottom.
812 \begin{code*}
813 \newcommand\harm[2]{ \frac{1}{#1} \mmultido{\n=#1+1}{#2}{ + \frac{1}{\n} } }
814 \end{code*}
815 \newcommand\harm[2]{ \frac{1}{#1} \mmultido{\n=#1+1}{#2}{ + \frac{1}{\n} } }
816 \begin{code+}
817 The harmonic series starts with
818 $$ Q = \begin{longmath}[t]{70mm}
819 1 + \harm{2}{21} + \cdots %%%
820 \end{longmath} $$
821 and diverges very slowly.
822 \end{code+}
823 \begin{exec}
824 The harmonic series starts with
825 $$ Q = \begin{longmath}[t]{70mm}
826 1 + \harm{2}{21} + \cdots
827 \end{longmath} $$
828 and diverges very slowly.
829 \end{exec}
830 No markers are needed to force line breaks at particular points. \TeX's line breaking algorithm is used to find the ``best'' breakpoints. If you're familiar with it, you can insert penalties into the formula to optimize it.
831
832 The °width° can be specified either as an absolute dimension or as fraction of the available width of the display.
833 \begin{code+}
834 One can easily prove that
835 $$ \begin{longmath}[b]{0.7}
836 1 + \harm{2}{21} + \cdots
837 \end{longmath} \to \infty, $$
838 which comes as a surprise for some students.
839 \end{code+}
840 \begin{exec}
841 One can easily prove that
842 $$ \begin{longmath}[b]{0.7}
843 1 + \harm{2}{21} + \cdots
844 \end{longmath} \to \infty, $$
845 which comes as a surprise for some students.
846 \end{exec}
847 As formulas typically have fewer possible breakpoints than ordinary text, no attempt is made to justify the lines. Instead, some flexible glue is inserted at both sides of each line to avoid extreme stretching or shrinking. Only the beginning of the first line and the end of the last line are forced to align with the boundary of the box specified by the °width° parameter. If the whole formula fits into a single line, a box with only the required width is created. This ensures that, regardless of the number of lines, a top aligned "longmath" box always aligns neatly with an expression to the left, and the formula in a bottom aligned "longmath" box can be continued to the right.
848
849 Since the "longmath" environment creates a vertical box, you can have several of them in a single display.
850 \begin{code+}
851 $$ \lleft[ \begin{longmath}[c]{0.33}
852 \polyA
853 \end{longmath} \rright] =
854 \lleft[ \begin{longmath}[c]{0.33}
855 \lleft( \polyB \rright) \cdot %%%
856 \lleft( \polyC \rright)
857 \end{longmath} \rright] $$
858 \end{code+}
859 \begin{exec}
860 $$ \lleft[ \begin{longmath}[c]{0.33}
861 \polyA
862 \end{longmath} \rright] =
863 \lleft[ \begin{longmath}[c]{0.33}
864 \lleft( \polyB \rright) \cdot
865 \lleft( \polyC \rright)
866 \end{longmath} \rright] $$
867 \end{exec}
868 To make this look a bit nicer, you can add some extra space to the width of the box and arrange the lines from the top left to the bottom right. If the °width° parameter is given as °linewidth°"+"°extrawidth°, the lines are stacked so that the total width of the box is the sum of °linewidth° and °extrawidth°. Both values can be given as absolute dimensions or as fractions of the total display width.
869 \begin{code+}
870 $$ \lleft[ \begin{longmath}[c]{0.33+0.07}
871 \polyA
872 \end{longmath} \rright] =
873 \lleft[ \begin{longmath}[c]{0.33+0.07}
874 \lleft( \polyB \rright) \cdot %%%
875 \lleft( \polyC \rright)
876 \end{longmath} \rright] $$
877 \end{code+}
878 \begin{exec}
879 $$ \lleft[ \begin{longmath}[c]{0.33+0.07}
880 \polyA
881 \end{longmath} \rright] =
882 \lleft[ \begin{longmath}[c]{0.33+0.07}
883 \lleft( \polyB \rright) \cdot
884 \lleft( \polyC \rright)
885 \end{longmath} \rright] $$
886 \end{exec}
887 A "longmath" box can replace any kind of subformula. Just specify the maximal width the subformula is allowed to have. If it fits into this width, it will be typeset normally. Otherwise, it is split into several lines.
888 \begin{code*}
889 $$ \frac{ \begin{longmath}{40mm+10mm} \polyA \end{longmath} }
890 { \begin{longmath}{40mm+10mm} \polyB \end{longmath} }
891 = \begin{longmath}{40mm+10mm} \polyC \end{longmath} $$
892 \end{code*}
893 \begin{exec}
894 $$ \frac{ \begin{longmath}{40mm+10mm} \polyA \end{longmath} }
895 { \begin{longmath}{40mm+10mm} \polyB \end{longmath} }
896 = \begin{longmath}{40mm+10mm} \polyC \end{longmath} $$
897 \end{exec}
898 \begin{code*}
899 \newcommand\polyX{ x^5 - x^4 + x^3 - x^2 + x - 1 }
900 \newcommand\polyY{ x^{10} - 2 x^9 + 3 x^8 - 4 x^7 + 5 x^6 - 6 x^5 + 5 x^4 - 4 x^3 + 3 x^2 - 2 x + 1 }
901 $$ \sqrt{ \begin{longmath}{40mm+10mm} \polyY \end{longmath} }
902 = \begin{longmath}{40mm+10mm} \polyX \end{longmath} $$
903 \end{code*}
904 \begin{exec}
905 \newcommand\polyX{ x^5 - x^4 + x^3 - x^2 + x - 1 }
906 \newcommand\polyY{ x^{10} - 2 x^9 + 3 x^8 - 4 x^7 + 5 x^6 - 6 x^5 + 5 x^4 - 4 x^3 + 3 x^2 - 2 x + 1 }
907 $$ \sqrt{ \begin{longmath}{50mm+10mm} \polyY \end{longmath} }
908 = \begin{longmath}{50mm+10mm} \polyX \end{longmath} $$
909 \end{exec}
910
911 There is also a smarter "longmath*" environment, which sets the width of the box ``intelligently'', so that the formula is split into equally long segments and the available space is used efficiently. The idea is to specify a maximal width, then let \TeX\ find the number of lines needed, and adapt the width to the total length divided by the number of lines. This will usually result in a box that is slightly shorter than the given width.
912
913 Whether this really succeeds depends on a sufficient number of possible breakpoints and stretchable and shrinkable glue in the formula, so that \TeX's algorithm can actually split it into equally long parts. Take it with a grain of salt and don't mind if it doesn't work properly in difficult cases. As an example, here is what we get without this feature.
914 \begin{code*}
915 To prove it, observe that each bracket is larger than $\frac 12$:
916 $$ \lleft\{ \begin{longmath}[c]{0.8+0.1}
917 \lleft( 1 + \frac{1}{2} \rright) + \lleft( \harm{3}{1} \rright) + \lleft( \harm{5}{3} \rright) +
918 \lleft( \harm{9}{7} \rright) + \lleft( \harm{17}{15} \rright) + \lleft( \harm{33}{3}
919 + \cdots \rright. \end{longmath} \rright\} $$
920 \end{code*}
921 \begin{exec}
922 To prove it, observe that each bracket is larger than $\frac 12$:
923 $$ \lleft\{ \begin{longmath}[c]{0.8+0.1}
924 \lleft( 1 + \frac{1}{2} \rright) + \lleft( \harm{3}{1} \rright) + \lleft( \harm{5}{3} \rright) +
925 \lleft( \harm{9}{7} \rright) + \lleft( \harm{17}{15} \rright) + \lleft( \harm{33}{3}
926 + \cdots \rright. \end{longmath} \rright\} $$
927 \end{exec}
928 If we replace "longmath" by "longmath*", but stick to the same width specification, we get this.
929 \begin{exec}
930 There is even a slightly ``shorter'' proof:
931 $$ \lleft\{ \begin{longmath*}[c]{0.8+0.1}
932 \lleft( 1 + \frac{1}{2} \rright) + \lleft( \harm{3}{1} \rright) + \lleft( \harm{5}{3} \rright) +
933 \lleft( \harm{9}{7} \rright) + \lleft( \harm{17}{15} \rright) + \lleft( \harm{33}{3}
934 + \cdots \rright. \end{longmath*} \rright\} $$
935 \end{exec}
936 The spacing between the lines is controlled by a dimension register that can be adjusted.
937
938 \comm{"\longmathlinesep"} dimension to be added to the line skip in the "longmath" environment (default \the\longmathlinesep).
939
940 This dimension is added to the current "\baselineskip" and "\lineskip" when the content of the box is split into lines and placed in a vertical box, basically using \TeX's "\openup" macro. Some additional effort is made to adjust the line spacing if the "longmath" environment is placed in a sub- or superscript as in this final example.
941 \begin{code*}
942 $$ \Omega = \lleft| \begin{longmath*}[c]{0.6+0.1}
943 \mathscr{Q} + \lleft[ \lleft( T · H · I^{\lleft(a+b\rright)^4} · S \rright)
944 + I · S + A + \lleft\{ V · E^{\lleft(a^2+2ab+b^2\rright)^2} · R · Y + L · O · N · G
945 + \lleft[ \int\limits_I^N T · \lleft( E^{G^R} \rright) · A_L \rright]
946 - \frac{ D^I · V^I }{ D · E · D } \mmbin / \lleft\{ B · Y
947 + A × \sum\limits_{-\infty}^{\infty} O^F \lleft< S^c_a L^a_r \mmiddle | \prod\nolimits^s \rright>
948 \rright\} \rright\} \rright] + C^\infty \end{longmath*} \rright|
949 ^ { \lleft( \begin{longmath*}[c]{25mm+5mm} a+b+c+d+e+f+g+h+i+j+k+l+m \end{longmath*} \rright) } $$
950 \end{code*}
951 \begin{exec}
952 \ignorelimits
953 $$ \Omega = \lleft| \begin{longmath*}[c]{0.6+0.1}
954 \mathscr{Q} + \lleft[ \lleft( T · H · I^{\lleft(a+b\rright)^4} · S \rright)
955 + I · S + A + \lleft\{ V · E^{\lleft(a^2+2ab+b^2\rright)^2} · R · Y + L · O · N · G
956 + \lleft[ \int\limits_I^N T · \lleft( E^{G^R} \rright) · A_L \rright]
957 - \frac{ D^I · V^I }{ D · E · D } \mmbin / \lleft\{ B · Y
958 + A × \sum\limits_{-\infty}^{\infty} O^F \lleft< S^c_a L^a_r \mmiddle | \prod\nolimits^s \rright>
959 \rright\} \rright\} \rright] + C^\infty \end{longmath*} \rright|
960 ^ { \lleft( \begin{longmath*}[c]{25mm+5mm} a+b+c+d+e+f+g+h+i+j+k+l+m \end{longmath*} \rright) } $$
961 \end{exec}
962
963
964 \end{document}