| 1 |
\documentclass{article} |
| 2 |
\usepackage{mdwtab} |
| 3 |
|
| 4 |
\errorcontextlines 999 |
| 5 |
|
| 6 |
\showboxbreadth\maxdimen |
| 7 |
\showboxdepth=2 |
| 8 |
|
| 9 |
\makeatletter |
| 10 |
|
| 11 |
% --- Switch allocations --- |
| 12 |
|
| 13 |
\newif\if@fleqn |
| 14 |
\newif\if@leqno |
| 15 |
|
| 16 |
% --- Dimen allocations --- |
| 17 |
|
| 18 |
\newdimen\eqa@thiscolwd |
| 19 |
\newdimen\eqa@maxcolwd |
| 20 |
\newdimen\eqa@maxeqwd |
| 21 |
\newdimen\eqa@maxcoleqwd |
| 22 |
|
| 23 |
% --- Main environments --- |
| 24 |
|
| 25 |
\def\equations{% |
| 26 |
\def\eqa@defnumber{(\theequation)\stepcounter{equation}}% |
| 27 |
\let\eqa@defmarker\eqa@fullmarker% |
| 28 |
\eqa@equations% |
| 29 |
} |
| 30 |
|
| 31 |
\def\endequations{% |
| 32 |
\\% |
| 33 |
\noalign{\global\dimen@i\prevdepth}% |
| 34 |
\multispan\tab@columns\hfill\vrule\@depth\dimen@i\cr% |
| 35 |
\egroup% |
| 36 |
\eqa@offsetcalc% |
| 37 |
\egroup% |
| 38 |
\eqa@restore% |
| 39 |
{\scrollmode\showbox\z@}% |
| 40 |
} |
| 41 |
|
| 42 |
\def\eqa@equations#1{% |
| 43 |
% |
| 44 |
% Set up restoring of things. |
| 45 |
% |
| 46 |
\toks@\expandafter{\eqa@number}% |
| 47 |
\toks\tw@\expandafter{\eqa@marker}% |
| 48 |
\edef\eqa@restore{% |
| 49 |
\gdef\noexpand\eqa@number{\the\toks@}% |
| 50 |
\gdef\noexpand\eqa@marker{\the\toks\tw@}% |
| 51 |
\eqa@maxcolwd\the\eqa@maxcolwd% |
| 52 |
\eqa@maxcoleqwd\the\eqa@maxcoleqwd% |
| 53 |
\eqa@maxeqwd\the\eqa@maxeqwd% |
| 54 |
}% |
| 55 |
% |
| 56 |
% Initialise numbering things. |
| 57 |
% |
| 58 |
\global\let\eqa@number\eqa@defnumber% |
| 59 |
\global\let\eqa@marker\eqa@defmarker% |
| 60 |
\let\eqa@markpen\@ne% |
| 61 |
% |
| 62 |
% Parse the preamble string. Put measuring things in the right places. |
| 63 |
% |
| 64 |
\tab@initread% |
| 65 |
\def\tab@tabtext{&\tabskip\z@skip}% |
| 66 |
\if@leqno% |
| 67 |
\tab@append\tab@preamble{\let\eqa@measure\eqa@domeasure}% |
| 68 |
\fi% |
| 69 |
\def\eqa@seteqcol##1{% |
| 70 |
\def\eqa@eqcol{##1} |
| 71 |
\if@leqno\let\eqa@seteqcol\relax\fi% |
| 72 |
}% |
| 73 |
\colset{equations}% |
| 74 |
\tab@doreadpream{#1}% |
| 75 |
\if@leqno\else% |
| 76 |
\tab@prepend\tab@pretext{\let\eqa@measure\eqa@domeasure}% |
| 77 |
\fi% |
| 78 |
\tab@readpreamble{}% |
| 79 |
% |
| 80 |
% Setting the newline command and some other initialisation. |
| 81 |
% |
| 82 |
\let\\\eqa@cr% |
| 83 |
\global\eqa@maxcolwd\z@% |
| 84 |
\global\eqa@maxcoleqwd\z@% |
| 85 |
\global\eqa@maxeqwd\z@% |
| 86 |
% |
| 87 |
% Start the box. Hacking to make \prevdepth work properly. |
| 88 |
% |
| 89 |
\setbox\z@\vbox\expandafter\bgroup% |
| 90 |
\expandafter\prevdepth\the\prevdepth% |
| 91 |
\relax% |
| 92 |
% |
| 93 |
% And now the alignment. |
| 94 |
% |
| 95 |
\tabskip\z@skip% |
| 96 |
\halign\expandafter\bgroup\the\tab@preamble\cr% |
| 97 |
} |
| 98 |
|
| 99 |
% --- Column building things --- |
| 100 |
|
| 101 |
\def\eqa@aligncol#1#2#3{% |
| 102 |
\eqa@seteqcol{#1}% |
| 103 |
\ifx l#1\eqa@aligncol@i{#2#3}{#2\hfil}\else% |
| 104 |
\ifx c#1\eqa@aligncol@i{\hfil#2#3}{#3#2\hfil}\else% |
| 105 |
\ifx r#1\eqa@aligncol@i{\hfil#2}{#3#2}% |
| 106 |
\fi\fi\fi% |
| 107 |
} |
| 108 |
\def\eqa@aligncol@i#1#2{% |
| 109 |
\tabcoltype% |
| 110 |
{\setbox\z@\hbox\bgroup#1}% |
| 111 |
{#2\egroup\eqa@measure}% |
| 112 |
} |
| 113 |
|
| 114 |
\colpush{equations} |
| 115 |
|
| 116 |
\coldef l{\eqa@aligncol l${{}}} |
| 117 |
\coldef c{\eqa@aligncol c${{}}} |
| 118 |
\coldef r{\eqa@aligncol r${{}}} |
| 119 |
|
| 120 |
\coldef M#1{\eqa@aligncol{#1}${{}}} |
| 121 |
\coldef T#1{\eqa@aligncol{#1}{}{}} |
| 122 |
|
| 123 |
\colpop |
| 124 |
|
| 125 |
% --- Equation measuring macros --- |
| 126 |
|
| 127 |
\let\eqa@number\relax |
| 128 |
\let\eqa@marker\relax |
| 129 |
|
| 130 |
\def\eqnumber#1{% |
| 131 |
\global\let\eqa@marker\eqa@fullmarker% |
| 132 |
\gdef\eqa@number{#1}% |
| 133 |
} |
| 134 |
|
| 135 |
\def\nonumber{% |
| 136 |
\global\let\eqa@marker\eqa@nonummarker% |
| 137 |
\global\let\eqa@number\@empty% |
| 138 |
} |
| 139 |
|
| 140 |
\def\eqa@measure{\unhbox\z@} |
| 141 |
\def\eqa@domeasure{% |
| 142 |
\global\eqa@thiscolwd\wd\z@% |
| 143 |
\ifdim\eqa@maxcolwd<\eqa@thiscolwd% |
| 144 |
\global\eqa@maxcolwd\eqa@thiscolwd% |
| 145 |
\fi% |
| 146 |
\unhbox\z@% |
| 147 |
} |
| 148 |
|
| 149 |
% --- The newline command --- |
| 150 |
|
| 151 |
\def\eqa@cr{\tab@cr\eqa@cr@i\z@\@M} |
| 152 |
\def\eqa@cr@i#1#2{% |
| 153 |
\cr% |
| 154 |
\noalign{% |
| 155 |
\eqa@marker{#1}{#2}% |
| 156 |
\global\let\eqa@number\eqa@defnumber% |
| 157 |
\global\let\eqa@marker\eqa@defmarker% |
| 158 |
\penalty\eqa@markpen% |
| 159 |
}% |
| 160 |
} |
| 161 |
|
| 162 |
\def\eqa@fullmarker#1#2{% |
| 163 |
\dimen@\prevdepth% |
| 164 |
\vskip\eqa@thiscolwd% |
| 165 |
\penalty#2% |
| 166 |
\skip@#1\advance\skip@\jot% |
| 167 |
\vskip\skip@% |
| 168 |
\setbox\z@\hbox{\eqa@number}% |
| 169 |
\dimen@\eqa@thiscolwd\advance\dimen@\wd\z@% |
| 170 |
\ifdim\dimen@\eqa@maxcoleqwd<\dimen@% |
| 171 |
\global\eqa@maxcoleqwd\dimen@% |
| 172 |
\global\eqa@maxeqwd\wd\z@% |
| 173 |
\fi% |
| 174 |
\nointerlineskip\hb@xt@\z@{\hbox{\eqa@number}}% |
| 175 |
\prevdepth\dimen@% |
| 176 |
} |
| 177 |
|
| 178 |
\def\eqa@nonummarker#1#2{% |
| 179 |
\penalty#2% |
| 180 |
\skip@#1\advance\skip@\jot% |
| 181 |
\vskip\skip@% |
| 182 |
\penalty\eqa@markpen% |
| 183 |
} |
| 184 |
|
| 185 |
% --- Offset calculation --- |
| 186 |
% |
| 187 |
% This stuff is sort of like the standard offset calculation, only it's |
| 188 |
% different. |
| 189 |
|
| 190 |
\def\eqa@offsetcalc{% |
| 191 |
\setbox\z@\lastbox% |
| 192 |
\unskip% |
| 193 |
\csname eqa@calc:\eqa@eqcol\expandafter\noexpand\if@leqno\endcsname% |
| 194 |
} |
| 195 |
|
| 196 |
\@namedef{eqa@calc:l\noexpand\iffalse}{% |
| 197 |
|
| 198 |
|
| 199 |
% --- Test document --- |
| 200 |
|
| 201 |
\makeatother |
| 202 |
|
| 203 |
\begin{document} |
| 204 |
|
| 205 |
\setcounter{equation}{23} |
| 206 |
|
| 207 |
\begin{equations}{rrl} |
| 208 |
x &= y^2 +& z^2 \\ |
| 209 |
x-y &= 3y^2 -& 2z^2 |
| 210 |
\end{equations} |
| 211 |
|
| 212 |
\end{document} |