-
Notifications
You must be signed in to change notification settings - Fork 0
/
amsmath-multline.tex
111 lines (97 loc) · 2.82 KB
/
amsmath-multline.tex
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
\begin{multline*}
f = \begin{matrix} x \end{matrix}
\end{multline*}
\newenvironment{multline*}{\start@multline\st@rredtrue}{\endmultline}
% expand \multline*
\start@multline\st@rredtrue
f = \begin{matrix} x \end{matrix}
\end{multline*}
\def\start@multline#1{%
\RIfM@ % \def\RIfM@{\relax\ifmmode}
\nomath@env
\DN@{\@namedef{end\@currenvir}{}\@gobble}% \def\DN@{\def\next@}
\else
$$%
#1%
\ifst@rred
\nonumber
\else
\global\@eqnswtrue
\fi
\let\next@\multline@
\fi
\collect@body\next@
}
$$
% expand \start@multline, #1 = "\st@rredtrue"
% expand \RIfM@, false
\double@dollar%
\st@rredtrue
\ifst@rred
\nonumber
\else
\global\@eqnswtrue
\fi
\let\next@\multline@
\collect@body\next@
f = \begin{matrix} x \end{matrix}
\end{multline*}
% expand \start@multline, #1 = "\st@rredtrue"
% expand \RIfM@, false
% expand \st@rredtrue, skip until \nonumber
% \next@ -> let to \multline@
\double@dollar
\collect@body\next@
f = \begin{matrix} x \end{matrix}
\end{multline*}
\def\collect@body#1{%
\@envbody{\@xp#1\@xp{\the\@envbody}}%
\edef\process@envbody{\the\@envbody\@nx\end{\@currenvir}}%
\@envbody\@emptytoks \def\begin@stack{b}%
\begingroup
\@xp\let\csname\@currenvir\endcsname\collect@@body
\edef\process@envbody{\@xp\@nx\csname\@currenvir\endcsname}%
\process@envbody % equivalent to \collect@@body
}
% expand \collect@body, #1 = "\next@"
% \next@ -> let to \multline@
% \@envbody -> toks "\@xp\next@\@xp{\the\@envbody}"
% \process@envbody -> "\@xp\next@\@xp{\the\@envbody}\end{multline*}"
% \@envbody -> toks ""
% \begin@stack -> "b"
% (start new group)
% (local) \multline* -> let to \collect@@body
% (local) \process@envbody -> "\multline*"
\double@dollar
\begingroup
\process@envbody % equivalent to \collect@@body
f = \begin{matrix} x \end{matrix}
\end{multline*}
\def\collect@@body#1\end#2{%
\edef\begin@stack{\push@begins#1\begin\end \@xp\@gobble\begin@stack}%
\ifx\@empty\begin@stack
\endgroup
\@checkend{#2}%
\addto@envbody{#1}%
\else
\addto@envbody{#1\end{#2}}%
\fi
\process@envbody % A little tricky! Note the grouping
}
% expand \process@envbody, #1 = "f = \begin{matrix} x ", #2 = "matrix"
% - if #1 contains \begin{...}, \begin@stack is nonempty, continue collecting,
% (local) \process@envbody is equal to \collect@@body
% - otherwise, \begin@stack is empty, end the group, end the collection,
% \process@envbody -> "\@xp\next@\@xp{\the\@envbody}\end{multline*}"
\double@dollar
\begingroup
\edef\begin@stack{\push@begins f = \begin{matrix} x \begin\end \@xp\@gobble\begin@stack}%
\ifx\@empty\begin@stack
\endgroup
\@checkend{matrix}%
\addto@envbody{f = \begin{matrix} x }%
\else
\addto@envbody{f = \begin{matrix} x \end{matrix}}%
\fi
\process@envbody % A little tricky! Note the grouping
\end{multline*}