summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/mdwtools/mathenv.tex
blob: 5c8d80ae1e63f83b4b453a16305c8005cbc42913 (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
\documentclass{article}
\usepackage{mdwtab}

\errorcontextlines 999

\showboxbreadth\maxdimen
\showboxdepth=2

\makeatletter

% --- Switch allocations ---

\newif\if@fleqn
\newif\if@leqno

% --- Dimen allocations ---

\newdimen\eqa@thiscolwd
\newdimen\eqa@maxcolwd
\newdimen\eqa@maxeqwd
\newdimen\eqa@maxcoleqwd

% --- Main environments ---

\def\equations{%
  \def\eqa@defnumber{(\theequation)\stepcounter{equation}}%
  \let\eqa@defmarker\eqa@fullmarker%
  \eqa@equations%
}

\def\endequations{%
    \\%
    \noalign{\global\dimen@i\prevdepth}%
    \multispan\tab@columns\hfill\vrule\@depth\dimen@i\cr%
    \egroup%
    \eqa@offsetcalc%
  \egroup%
  \eqa@restore%
  {\scrollmode\showbox\z@}%
}

\def\eqa@equations#1{%
%
% Set up restoring of things.
%
  \toks@\expandafter{\eqa@number}%
  \toks\tw@\expandafter{\eqa@marker}%
  \edef\eqa@restore{%
    \gdef\noexpand\eqa@number{\the\toks@}%
    \gdef\noexpand\eqa@marker{\the\toks\tw@}%
    \eqa@maxcolwd\the\eqa@maxcolwd%
    \eqa@maxcoleqwd\the\eqa@maxcoleqwd%
    \eqa@maxeqwd\the\eqa@maxeqwd%
  }%
%
% Initialise numbering things.
%
  \global\let\eqa@number\eqa@defnumber%
  \global\let\eqa@marker\eqa@defmarker%
  \let\eqa@markpen\@ne%
%
% Parse the preamble string.  Put measuring things in the right places.
%
  \tab@initread%
  \def\tab@tabtext{&\tabskip\z@skip}%
  \if@leqno%
    \tab@append\tab@preamble{\let\eqa@measure\eqa@domeasure}%
  \fi%
  \def\eqa@seteqcol##1{%
    \def\eqa@eqcol{##1}
    \if@leqno\let\eqa@seteqcol\relax\fi%
  }%
  \colset{equations}%
  \tab@doreadpream{#1}%
  \if@leqno\else%
    \tab@prepend\tab@pretext{\let\eqa@measure\eqa@domeasure}%
  \fi%
  \tab@readpreamble{}%
%
% Setting the newline command and some other initialisation.
%
  \let\\\eqa@cr%
  \global\eqa@maxcolwd\z@%
  \global\eqa@maxcoleqwd\z@%
  \global\eqa@maxeqwd\z@%
%
% Start the box.  Hacking to make \prevdepth work properly.
%
  \setbox\z@\vbox\expandafter\bgroup%
    \expandafter\prevdepth\the\prevdepth%
    \relax%
%
% And now the alignment.
%
    \tabskip\z@skip%
    \halign\expandafter\bgroup\the\tab@preamble\cr%
}

% --- Column building things ---

\def\eqa@aligncol#1#2#3{%
  \eqa@seteqcol{#1}%
  \ifx l#1\eqa@aligncol@i{#2#3}{#2\hfil}\else%
  \ifx c#1\eqa@aligncol@i{\hfil#2#3}{#3#2\hfil}\else%
  \ifx r#1\eqa@aligncol@i{\hfil#2}{#3#2}%
  \fi\fi\fi%
}
\def\eqa@aligncol@i#1#2{%
  \tabcoltype%
    {\setbox\z@\hbox\bgroup#1}%
    {#2\egroup\eqa@measure}%
}

\colpush{equations}

\coldef l{\eqa@aligncol l${{}}}
\coldef c{\eqa@aligncol c${{}}}
\coldef r{\eqa@aligncol r${{}}}

\coldef M#1{\eqa@aligncol{#1}${{}}}
\coldef T#1{\eqa@aligncol{#1}{}{}}

\colpop

% --- Equation measuring macros ---

\let\eqa@number\relax
\let\eqa@marker\relax

\def\eqnumber#1{%
  \global\let\eqa@marker\eqa@fullmarker%
  \gdef\eqa@number{#1}%
}

\def\nonumber{%
  \global\let\eqa@marker\eqa@nonummarker%
  \global\let\eqa@number\@empty%
}

\def\eqa@measure{\unhbox\z@}
\def\eqa@domeasure{%
  \global\eqa@thiscolwd\wd\z@%
  \ifdim\eqa@maxcolwd<\eqa@thiscolwd%
    \global\eqa@maxcolwd\eqa@thiscolwd%
  \fi%
  \unhbox\z@%
}

% --- The newline command ---

\def\eqa@cr{\tab@cr\eqa@cr@i\z@\@M}
\def\eqa@cr@i#1#2{%
  \cr%
  \noalign{%
    \eqa@marker{#1}{#2}%
    \global\let\eqa@number\eqa@defnumber%
    \global\let\eqa@marker\eqa@defmarker%
    \penalty\eqa@markpen%
  }%
}

\def\eqa@fullmarker#1#2{%
  \dimen@\prevdepth%
  \vskip\eqa@thiscolwd%
  \penalty#2%
  \skip@#1\advance\skip@\jot%
  \vskip\skip@%
  \setbox\z@\hbox{\eqa@number}%
  \dimen@\eqa@thiscolwd\advance\dimen@\wd\z@%
  \ifdim\dimen@\eqa@maxcoleqwd<\dimen@%
    \global\eqa@maxcoleqwd\dimen@%
    \global\eqa@maxeqwd\wd\z@%
  \fi%
  \nointerlineskip\hb@xt@\z@{\hbox{\eqa@number}}%
  \prevdepth\dimen@%
}

\def\eqa@nonummarker#1#2{%
  \penalty#2%
  \skip@#1\advance\skip@\jot%
  \vskip\skip@%
  \penalty\eqa@markpen%
}

% --- Offset calculation ---
%
% This stuff is sort of like the standard offset calculation, only it's
% different.

\def\eqa@offsetcalc{%
  \setbox\z@\lastbox%
  \unskip%
  \csname eqa@calc:\eqa@eqcol\expandafter\noexpand\if@leqno\endcsname%
}

\@namedef{eqa@calc:l\noexpand\iffalse}{%
  

% --- Test document ---

\makeatother

\begin{document}

\setcounter{equation}{23}

\begin{equations}{rrl}
  x &= y^2 +& z^2 \\
x-y &= 3y^2 -& 2z^2
\end{equations}

\end{document}