mdwmath.dtx 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. % \begin{meta-comment}
  2. %
  3. % $Id$
  4. %
  5. % Various nicer mathematical things
  6. %
  7. % (c) 1996 Mark Wooding
  8. %
  9. %----- Revision history -----------------------------------------------------
  10. %
  11. % $Log$
  12. % Revision 1.1 1998-09-21 10:19:01 michael
  13. % Initial implementation
  14. %
  15. % Revision 1.1 1996/11/19 20:53:21 mdw
  16. % Initial revision
  17. %
  18. %
  19. % \end{meta-comment}
  20. %
  21. % \begin{meta-comment} <general public licence>
  22. %%
  23. %% mdwmath package -- various nicer mathematical things
  24. %% Copyright (c) 1996 Mark Wooding
  25. %%
  26. %% This program is free software; you can redistribute it and/or modify
  27. %% it under the terms of the GNU General Public License as published by
  28. %% the Free Software Foundation; either version 2 of the License, or
  29. %% (at your option) any later version.
  30. %%
  31. %% This program is distributed in the hope that it will be useful,
  32. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  34. %% GNU General Public License for more details.
  35. %%
  36. %% You should have received a copy of the GNU General Public License
  37. %% along with this program; if not, write to the Free Software
  38. %% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  39. %%
  40. % \end{meta-comment}
  41. %
  42. % \begin{meta-comment} <Package preamble>
  43. %<+package>\NeedsTeXFormat{LaTeX2e}
  44. %<+package>\ProvidesPackage{mdwmath}
  45. %<+package> [1996/04/11 1.1 Nice mathematical things]
  46. %<+oldeqnarray>\NeedsTeXFormat{LaTeX2e}
  47. %<+oldeqnarray>\ProvidesPackage{eqnarray}
  48. %<+oldeqnarray> [1996/04/11 1.1 Old enhanced eqnarray]
  49. % \end{meta-comment}
  50. %
  51. % \CheckSum{259}
  52. % \begin{old-eqnarray}
  53. % \CheckSum{484}
  54. % \end{old-eqnarray}
  55. %% \CharacterTable
  56. %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  57. %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
  58. %% Digits \0\1\2\3\4\5\6\7\8\9
  59. %% Exclamation \! Double quote \" Hash (number) \#
  60. %% Dollar \$ Percent \% Ampersand \&
  61. %% Acute accent \' Left paren \( Right paren \)
  62. %% Asterisk \* Plus \+ Comma \,
  63. %% Minus \- Point \. Solidus \/
  64. %% Colon \: Semicolon \; Less than \<
  65. %% Equals \= Greater than \> Question mark \?
  66. %% Commercial at \@ Left bracket \[ Backslash \\
  67. %% Right bracket \] Circumflex \^ Underscore \_
  68. %% Grave accent \` Left brace \{ Vertical bar \|
  69. %% Right brace \} Tilde \~}
  70. %%
  71. %
  72. % \begin{meta-comment}
  73. %
  74. %<*driver>
  75. \input{mdwtools}
  76. \describespackage{mdwmath}
  77. % \describespackage{eqnarray}
  78. \ignoreenv{old-eqnarray}
  79. % \unignoreenv{old-eqnarray}
  80. \mdwdoc
  81. %</driver>
  82. %
  83. % \end{meta-comment}
  84. %
  85. % \section{User guide}
  86. %
  87. % \subsection{Square root typesetting}
  88. %
  89. % \DescribeMacro{\sqrt}
  90. % The package supplies a star variant of the |\sqrt| command which omits the
  91. % vinculum over the operand (the line over the top). While this is most
  92. % useful in simple cases like $\sqrt*{2}$ it works for any size of operand.
  93. % The package also re-implements the standard square root command so that it
  94. % positions the root number rather better.
  95. %
  96. % \begin{figure}
  97. % \begin{demo}[w]{Examples of the new square root command}
  98. %\[ \sqrt*{2} \quad \mbox{rather than} \quad \sqrt{2} \]
  99. %\[ \sqrt*[3]{2} \quad \mbox{ rather than } \quad \sqrt[3]{2} \]
  100. %\[ \sqrt{x^3 + \sqrt*[y]{\alpha}} - \sqrt*[n+1]{a} \]
  101. %\[ x = \sqrt*[3]{\frac{3y}{7}} \]
  102. %\[ q = \frac{2\sqrt*{2}}{5}+\sqrt[\frac{n+1}{2}]{2x^2+3xy-y^2} \]
  103. % \end{demo}
  104. % \end{figure}
  105. %
  106. % [Note that omission of the vinculum was originally a cost-cutting exercise
  107. % because the radical symbol can just fit in next to its operand and
  108. % everything ends up being laid out along a line. However, I find that the
  109. % square root without vinculum is less cluttered, so I tend to use it when
  110. % it doesn't cause ambiguity.]
  111. %
  112. % \subsection{Some maths symbols you already have}
  113. %
  114. % Having just tried to do some simple things, I've found that there are maths
  115. % symbols missing. Here they are, in all their glory:
  116. %
  117. % \begin{center} \unverb\| \begin{tabular}{cl|cl|cl}
  118. % $\&$ & "\&" & $\bitor$ & "\bitor" & $\dbland$ & "\dbland" \\
  119. % $\bitand$ & "\bitand" & $\dblor$ & "\dblor" &
  120. % \end{tabular} \end{center}
  121. %
  122. % \begin{ignore}
  123. % There used to be an eqnarray here, but that's migrated its way into the
  124. % \package{mdwtab} package. Maybe the original version, without dependency
  125. % on \package{mdwtab} ought to be releasable separately. I'll keep it around
  126. % just in case.
  127. %
  128. % The following is the documentation for the original version. There's an
  129. % updated edition in \package{mdwtab}.
  130. % \end{ignore}
  131. %
  132. % \begin{old-eqnarray}
  133. %
  134. % \subsection{A new \env{eqnarray} environment}
  135. %
  136. % \LaTeX's built-in \env{eqnarray} is horrible -- it puts far too much space
  137. % between the items in the array. This environment is rather nearer to the
  138. % \env{amsmath} \env{align} environments, although rather less capable.
  139. %
  140. % \bigskip
  141. % \DescribeEnv{eqnarray}
  142. % {\synshorts
  143. % \setbox0\hbox{"\\begin{eqnarray}["<preamble>"]" \dots "\\end{eqnarray}"}
  144. % \leavevmode \hskip-\parindent \fbox{\box0}
  145. % }
  146. % \smallskip
  147. %
  148. % The new version of \env{eqnarray} tries to do everything which you really
  149. % want it to. The \synt{preamble} string allows you to define the column
  150. % types in a vaguely similar way to the wonderful \env{tabular} environment.
  151. % The types provided (and it's easy-ish to add more) are:
  152. %
  153. % \def\ch{\char`}
  154. % \begin{description} \def\makelabel{\hskip\labelsep\normalfont\ttfamily}
  155. % \item [r] Right aligned equation
  156. % \item [c] Centre-aligned equation
  157. % \item [l] Left aligned equation
  158. % \item [\textrm{\texttt{Tr}, \texttt{Tc} and \texttt{Tl}}] Right, centre and
  159. % left aligned text (not maths)
  160. % \item [L] Left aligned zero-width equation
  161. % \item [x] Centred entire equation
  162. % \item [:] Big gap separating sets of equations
  163. % \item [q] Quad space
  164. % \item [>\ch\{\synt{text}\ch\}] Insert text before column
  165. % \item [<\ch\{\synt{text}\ch\}] Insert text after column
  166. % \end{description}
  167. %
  168. % Some others are also defined: don't use them because they do complicated
  169. % things which are hard to explain and they aren't much use anyway.
  170. %
  171. % The default preamble, if you don't supply one of your own, is \lit{rcl}.
  172. % Most of the time, \lit{rl} is sufficient, although compatibility is more
  173. % important to me.
  174. %
  175. % By default, there is no space between columns, which makes formul\ae\ in an
  176. % \env{eqnarray} environment look just like formul\ae\ typeset on their own,
  177. % except that things get aligned in columns. This is where the default
  178. % \env{eqnarray} falls down: it leaves |\arraycolsep| space between each
  179. % column making the thing look horrible.
  180. %
  181. % An example would be good here, I think. This one's from exercise 22.9 of
  182. % the \textit{\TeX book}.
  183. %
  184. % \begin{demo}[w]{Simultaneous equations}
  185. %\begin{eqnarray}[rcrcrcrl]
  186. % 10w & + & 3x & + & 3y & + & 18z & = 1 \\
  187. % 6w & - & 17x & & & - & 5z & = 2
  188. %\end{eqnarray}
  189. % \end{demo}
  190. %
  191. % Choosing a more up-to-date example, here's one demonstrating the \lit{:}
  192. % column specifier from the \textit{\LaTeX\ Companion}.
  193. %
  194. % \begin{demo}[w]{Lots of equations}
  195. %\begin{eqnarray}[rl:rl:l]
  196. % V_i &= v_i - q_i v_j, & X_i &= x_i - q_i x_j, &
  197. % U_i = u_i, \qquad \mbox{for $i \ne j$} \label{eq:A} \\
  198. % V_j &= v_j, & X_j &= x_j &
  199. % U_j u_j + \sum_{i \ne j} q_i u_i.
  200. %\end{eqnarray}
  201. % \end{demo}
  202. %
  203. % We can make things more interesting by adding a plain text column. Here we
  204. % go:
  205. %
  206. % \begin{demo}[w]{Plain text column}
  207. %\begin{eqnarray}[rlqqTl]
  208. % x &= y & by (\ref{eq:A}) \\
  209. % x' &= y' & by definition \\
  210. % x + x' &= y + y' & by Axiom~1
  211. %\end{eqnarray}
  212. % \end{demo}
  213. %
  214. % The new features also mean that you don't need to mess about with
  215. % |\lefteqn| any more. This is handled by the \lit{L} column type:
  216. %
  217. % \begin{demo}{Splitting example}
  218. %\begin{eqnarray*}[Ll]
  219. % w+x+y+z = \\
  220. % & a+b+c+d+e+ \\
  221. % & f+g+h+i+j
  222. %\end{eqnarray*}
  223. % \end{demo}
  224. %
  225. % Finally, just to prove that the spacing's right at last, here's another one
  226. % from the \textit{Companion}.
  227. %
  228. % \begin{demo}{Spacing demonstration}
  229. %\begin{equation}
  230. % x^2 + y^2 = z^2
  231. %\end{equation}
  232. %\begin{eqnarray}[rl]
  233. % x^2 + y^2 &= z^2 \\
  234. % y^2 &< z^2
  235. %\end{eqnarray}
  236. % \end{demo}
  237. %
  238. % Well, that was easy enough. Now on to numbering. As you've noticed, the
  239. % equations above are numbered. You can use the \env{eqnarray$*$}
  240. % environment to turn off the numbering in the whole environment, or say
  241. % |\nonumber| on a line to suppress numbering of that one in particular.
  242. % More excitingly, you can say \syntax{"\\nonumber["<text>"]"} to choose
  243. % what text to display.
  244. %
  245. % A note for cheats: you can use the sparkly new \env{eqnarray} for simple
  246. % equations simply by specifying \lit{x} as the column description. Who
  247. % needs \AmSTeX? |;-)|
  248. %
  249. % \end{old-eqnarray}
  250. %
  251. % \implementation
  252. %
  253. % \section{Implementation}
  254. %
  255. % This isn't really complicated (honest) although it is a lot hairier than I
  256. % think it ought to be.
  257. %
  258. % \begin{macrocode}
  259. %<*package>
  260. % \end{macrocode}
  261. %
  262. % \subsection{Square roots}
  263. %
  264. % \subsubsection{Where is the square root sign?}
  265. %
  266. % \LaTeX\ hides the square root sign away somewhere without telling anyone
  267. % where it is. I extract it forcibly by peeking inside the |\sqrtsign| macro
  268. % and scrutinising the contents. Here we go: prepare for yukkiness.
  269. %
  270. % \begin{macrocode}
  271. \newcount\sq@sqrt
  272. \begingroup
  273. \catcode`\|0 \catcode`\\12
  274. |def|sq@readrad#1"#2\#3|relax{|global|sq@sqrt"#2|relax}
  275. |expandafter|sq@readrad|meaning|sqrtsign|relax
  276. |endgroup
  277. \def\sq@delim{\delimiter\sq@sqrt\relax}
  278. % \end{macrocode}
  279. %
  280. % \subsubsection{Drawing fake square root signs}
  281. %
  282. % \TeX\ absolutely insists on drawing square root signs with a vinculum over
  283. % the top. In order to get the same effect, we have to attempt to emulate
  284. % \TeX's behaviour.
  285. %
  286. % \begin{macro}{\sqrtdel}
  287. %
  288. % This does the main job of typesetting a vinculum-free radical.\footnote{^^A
  289. % Note for chemists: this is nothing to do with short-lived things which
  290. % don't have their normal numbers of electrons. And it won't reduce the
  291. % appearance of wrinkles either.}
  292. % It's more or less a duplicate of what \TeX\ does internally, so it might be
  293. % a good plan to have a copy of Appendix~G open while you examine this.
  294. %
  295. % We start off by using |\mathpalette| to help decide how big things should
  296. % be.
  297. %
  298. % \begin{macrocode}
  299. \def\sqrtdel{\mathpalette\sqrtdel@i}
  300. % \end{macrocode}
  301. %
  302. % Read the contents of the radical into a box, so we can measure it.
  303. %
  304. % \begin{macrocode}
  305. \def\sqrtdel@i#1#2{%
  306. \setbox\z@\hbox{$\m@th#1#2$}% %%% Bzzzt -- uncramps the mathstyle
  307. % \end{macrocode}
  308. %
  309. % Now try and sort out the values needed in this calculation. We'll assume
  310. % that $\xi_8$ is 0.6\,pt, the way it usually is. Next try to work out the
  311. % value of $\varphi$.
  312. %
  313. % \begin{macrocode}
  314. \ifx#1\displaystyle%
  315. \@tempdima1ex%
  316. \else%
  317. \@tempdima.6\p@%
  318. \fi%
  319. % \end{macrocode}
  320. %
  321. % That was easy. Now for $\psi$.
  322. %
  323. % \begin{macrocode}
  324. \@tempdimb.6\p@%
  325. \advance\@tempdimb.25\@tempdima%
  326. % \end{macrocode}
  327. %
  328. % Build the `delimiter' in a box of height $h(x)+d(x)+\psi+\xi_8$, as
  329. % requested. Box~2 will do well for this purpose.
  330. %
  331. % \begin{macrocode}
  332. \[email protected]\p@%
  333. \advance\dimen@\@tempdimb%
  334. \advance\dimen@\ht\z@%
  335. \advance\dimen@\dp\z@%
  336. \setbox\tw@\hbox{%
  337. $\left\sq@delim\vcenter to\dimen@{}\right.\n@space$%
  338. }%
  339. % \end{macrocode}
  340. %
  341. % Now we need to do some more calculating (don't you hate it?). As far as
  342. % Appendix~G is concerned, $\theta=h(y)=0$, because we want no rule over the
  343. % top.
  344. %
  345. % \begin{macrocode}
  346. \@tempdima\ht\tw@%
  347. \advance\@tempdima\dp\tw@%
  348. \advance\@tempdima-\ht\z@%
  349. \advance\@tempdima-\dp\z@%
  350. \ifdim\@tempdima>\@tempdimb%
  351. \advance\@tempdima\@tempdimb%
  352. \@tempdimb.5\@tempdima%
  353. \fi%
  354. % \end{macrocode}
  355. %
  356. % Work out how high to raise the radical symbol. Remember that Appendix~G
  357. % thinks that the box has a very small height, although this is untrue here.
  358. %
  359. % \begin{macrocode}
  360. \@tempdima\ht\z@%
  361. \advance\@tempdima\@tempdimb%
  362. \advance\@tempdima-\ht\tw@%
  363. % \end{macrocode}
  364. %
  365. % Build the output (finally). The brace group is there to turn the output
  366. % into a mathord, one of the few times that this is actually desirable.
  367. %
  368. % \begin{macrocode}
  369. {\raise\@tempdima\box\tw@\vbox{\kern\@tempdimb\box\z@}}%
  370. }
  371. % \end{macrocode}
  372. %
  373. % \end{macro}
  374. %
  375. % \subsubsection{The new square root command}
  376. %
  377. % This is where we reimplement all the square root stuff. Most of this stuff
  378. % comes from the \PlainTeX\ macros, although some is influenced by \AmSTeX\
  379. % and \LaTeXe, and some is original. I've tried to make the spacing vaguely
  380. % automatic, so although it's not configurable like \AmSTeX's version, the
  381. % output should look nice more of the time. Maybe.
  382. %
  383. % \begin{macro}{\sqrt}
  384. %
  385. % \LaTeX\ says this must be robust, so we make it robust. The first thing to
  386. % do is to see if there's a star and pass the appropriate squareroot-drawing
  387. % command on to the rest of the code.
  388. %
  389. % \begin{macrocode}
  390. \DeclareRobustCommand\sqrt{\@ifstar{\sqrt@i\sqrtdel}{\sqrt@i\sqrtsign}}
  391. % \end{macrocode}
  392. %
  393. % Now we can sort out an optional argument to be displayed on the root.
  394. %
  395. % \begin{macrocode}
  396. \def\sqrt@i#1{\@ifnextchar[{\sqrt@ii{#1}}{\sqrt@iv{#1}}}
  397. % \end{macrocode}
  398. %
  399. % Stages~2 and~3 below are essentially equivalents of \PlainTeX's
  400. % |\root|\dots|\of| and |\r@@t|. Here we also find the first wrinkle: the
  401. % |\rootbox| used to store the number is spaced out on the left if necessary.
  402. % There's a backspace after the end so that the root can slip underneath, and
  403. % everything works out nicely. Unfortunately size is fixed here, although
  404. % doesn't actually seem to matter.
  405. %
  406. % \begin{macrocode}
  407. \def\sqrt@ii#1[#2]{%
  408. \setbox\rootbox\hbox{$\m@th\scriptscriptstyle{#2}$}%
  409. \ifdim\wd\rootbox<6\p@%
  410. \setbox\rootbox\hb@xt@6\p@{\hfil\unhbox\rootbox}%
  411. \fi%
  412. \mathpalette{\sqrt@iii{#1}}%
  413. }
  414. % \end{macrocode}
  415. %
  416. % Now we can actually build everything. Note that the root is raised by its
  417. % depth -- this prevents a common problem with letters with descenders.
  418. %
  419. % \begin{macrocode}
  420. \def\sqrt@iii#1#2#3{%
  421. \setbox\z@\hbox{$\m@th#2#1{#3}$}%
  422. \dimen@\ht\z@%
  423. \advance\dimen@-\dp\z@%
  424. \[email protected]\dimen@%
  425. \advance\dimen@\dp\rootbox%
  426. \mkern-3mu%
  427. \raise\dimen@\copy\rootbox%
  428. \mkern-10mu%
  429. \box\z@%
  430. }
  431. % \end{macrocode}
  432. %
  433. % Finally handle a non-numbered root. We read the rooted text in as an
  434. % argument, to stop problems when people omit the braces. (\AmSTeX\ does
  435. % this too.)
  436. %
  437. % \begin{macrocode}
  438. \def\sqrt@iv#1#2{#1{#2}}
  439. % \end{macrocode}
  440. %
  441. % \end{macro}
  442. %
  443. % \begin{macro}{\root}
  444. %
  445. % We also re-implement \PlainTeX's |\root| command, just in case someone uses
  446. % it, and supply a star-variant. This is all very trivial.
  447. %
  448. % \begin{macrocode}
  449. \def\root{\@ifstar{\root@i\sqrtdel}{\root@i\sqrtsign}}
  450. \def\root@i#1#2\of{\sqrt@ii{#1}[#2]}
  451. % \end{macrocode}
  452. %
  453. % \end{macro}
  454. %
  455. % \subsection{Some magic new maths characters}
  456. %
  457. % This is all really easy.
  458. %
  459. % \begin{macrocode}
  460. \DeclareMathSymbol{&}{\mathbin}{operators}{`\&}
  461. \DeclareMathSymbol{\bitand}{\mathbin}{operators}{`\&}
  462. \def\bitor{\mathbin\mid}
  463. \def\dblor{\mathbin{\mid\mid}}
  464. \def\dbland{\mathbin{\mathrel\bitand\mathrel\bitand}}
  465. % \end{macrocode}
  466. %
  467. % \subsection{Biggles}
  468. %
  469. % Now for some user-controlled delimiter sizing. The standard bigness of
  470. % plain \TeX's delimiters are all right, but it's a little limiting.
  471. %
  472. % The biggness of delimiters is based on the size of the current |\strut|,
  473. % which \LaTeX\ keeps up to date all the time. This will make the various
  474. % delimiters grow in proportion when the text gets bigger. Actually, I'm
  475. % not sure that this is exactly right -- maybe it should be nonlinear,
  476. %
  477. % \begin{macro}{\bbigg}
  478. % \begin{macro}{\bbiggl}
  479. % \begin{macro}{\bbiggr}
  480. % \begin{macro}{\bbiggm}
  481. %
  482. % This is where the bigness is done. This is more similar to the plain \TeX\
  483. % big delimiter stuff than to the \package{amsmath} stuff, although there's
  484. % not really a lot of difference.
  485. %
  486. % The two arguments are a multiplier for the delimiter size, and a small
  487. % increment applied \emph{before} the multiplication (which is optional).
  488. %
  489. % This is actually a front for a low-level interface which can be called
  490. % directly for efficiency.
  491. %
  492. % \begin{macrocode}
  493. \def\bbigg{\@bbigg\mathord}
  494. \def\bbiggl{\@bbigg\mathopen}
  495. \def\bbiggr{\@bbigg\mathclose}
  496. \def\bbiggm{\@bbigg\mathrel}
  497. % \end{macrocode}
  498. %
  499. % \end{macro}
  500. % \end{macro}
  501. % \end{macro}
  502. % \end{macro}
  503. %
  504. % \begin{macro}{\@bbigg}
  505. %
  506. % This is an optional argument parser providing a front end for the main
  507. % macro |\bbigg@|.
  508. %
  509. % \begin{macrocode}
  510. \def\@bbigg#1{\@ifnextchar[{\@bigg@i{#1}}{\@bigg@i{#1}[\z@]}}
  511. \def\@bigg@i#1[#2]#3#4{#1{\bbigg@{#2}{#3}{#4}}}
  512. % \end{macrocode}
  513. %
  514. % \end{macro}
  515. %
  516. % \begin{macro}{\bbigg@}
  517. %
  518. % This is it, at last. The arguments are as described above: an addition
  519. % to be made to the strut height, and a multiplier. Oh, and the delimiter,
  520. % of course.
  521. %
  522. % This is a bit messy. The smallest `big' delimiter, |\big|, is the same
  523. % height as the current strut box. Other delimiters are~$1\frac12$, $2$
  524. % and~$2\frac12$ times this height. I'll set the height of the delimiter by
  525. % putting in a |\vcenter| of the appropriate size.
  526. %
  527. % Given an extra height~$x$, a multiplication factor~$f$ and a strut
  528. % height~$h$ and depth~$d$, I'll create a vcenter with total height
  529. % $f(h+d+x)$. Easy, isn't it?
  530. %
  531. % \begin{macrocode}
  532. \def\bbigg@#1#2#3{%
  533. \hbox{$%
  534. \dimen@\ht\strutbox\advance\dimen@\dp\strutbox%
  535. \advance\dimen@#1%
  536. \dimen@#2\dimen@%
  537. \left#3\vcenter to\dimen@{}\right.\n@space%
  538. $}%
  539. }
  540. % \end{macrocode}
  541. %
  542. % \end{macro}
  543. %
  544. % \begin{macro}{\big}
  545. % \begin{macro}{\Big}
  546. % \begin{macro}{\bigg}
  547. % \begin{macro}{\Bigg}
  548. %
  549. % Now for the easy macros.
  550. %
  551. % \begin{macrocode}
  552. \def\big{\bbigg@\z@\@ne}
  553. \def\Big{\bbigg@\z@{1.5}}
  554. \def\bigg{\bbigg@\z@\tw@}
  555. \def\Bigg{\bbigg@\z@{2.5}}
  556. % \end{macrocode}
  557. %
  558. % \end{macro}
  559. % \end{macro}
  560. % \end{macro}
  561. % \end{macro}
  562. %
  563. %
  564. % \begin{ignore}
  565. % The following is the original definition of the enhanced eqnarray
  566. % environment. It's not supported, although if you can figure out how to
  567. % extract it, it's all yours.
  568. % \end{ignore}
  569. %
  570. % \begin{old-eqnarray}
  571. %
  572. % \subsection{The sparkly new \env{eqnarray}}
  573. %
  574. % Start off by writing a different package.
  575. %
  576. % \begin{macrocode}
  577. %</package>
  578. %<*oldeqnarray>
  579. % \end{macrocode}
  580. %
  581. % \subsubsection{Options handling}
  582. %
  583. % We need to be able to cope with \textsf{fleqn} and \textsf{leqno} options.
  584. % This will adjust our magic modified \env{eqnarray} environment
  585. % appropriately.
  586. %
  587. % \begin{macrocode}
  588. \newif\if@fleqn
  589. \newif\if@leqno
  590. \DeclareOption{fleqn}{\@fleqntrue}
  591. \DeclareOption{leqno}{\@leqnotrue}
  592. \ProcessOptions
  593. % \end{macrocode}
  594. %
  595. % This is all really different to the \LaTeX\ version. I've looked at the
  596. % various \env{tabular} implementations, the original \env{eqnarray} and the
  597. % \textit{\TeX book} to see how best to do this, and then went my own way.
  598. % If it doesn't work it's all my fault.
  599. %
  600. % \subsubsection{Some useful registers}
  601. %
  602. % The old \LaTeX\ version puts the equation numbers in by keeping a count of
  603. % where it is in the alignment. Since I don't know how may columns there are
  604. % going to be, I'll just use a switch in the preamble to tell me to stop
  605. % tabbing.
  606. %
  607. % \begin{macrocode}
  608. \newif\if@eqalast
  609. % \end{macrocode}
  610. %
  611. % Now define some useful length parameters. First allocate them:
  612. %
  613. % \begin{macrocode}
  614. \newskip\eqaopenskip
  615. \newskip\eqacloseskip
  616. \newskip\eqacolskip
  617. \newskip\eqainskip
  618. % \end{macrocode}
  619. %
  620. % Now assign some default values. Users can play with these if they really
  621. % want although I can't see the point myself.
  622. %
  623. % \begin{macrocode}
  624. \if@fleqn
  625. \AtBeginDocument{\eqaopenskip\leftmargini}
  626. \else
  627. \eqaopenskip\@centering
  628. \fi
  629. \eqacloseskip\@centering
  630. \eqacolskip\@centering
  631. \eqainskip\z@
  632. % \end{macrocode}
  633. %
  634. % We allow the user to play with the style if this is really wanted. I dunno
  635. % why, really. Maybe someone wants very small alignments.
  636. %
  637. % \begin{macrocode}
  638. \let\eqa@style\displaystyle
  639. % \end{macrocode}
  640. %
  641. % \subsubsection{The main environments}
  642. %
  643. % We define the toplevel commands here. They just add in default arguments
  644. % and then call |\@eqnarray| with a preamble string. The only difference is
  645. % the last column they add in -- \env{eqnarray$*$} throws away the last
  646. % column by sticking it in box~0. (I used to |\@gobble| it but that caused
  647. % the |\cr| to be lost.)
  648. %
  649. % \begin{macrocode}
  650. \def\eqnarray{\@ifnextchar[\eqnarray@i{\eqnarray@i[rcl]}}
  651. \def\eqnarray@i[#1]{%
  652. \@eqnarray{#1!{\hb@xt@\z@{\hss##}\tabskip\z@}}
  653. }
  654. \@namedef{eqnarray*}{\@ifnextchar[\eqnarray@s@i{\eqnarray@s@i[rcl]}}
  655. \def\eqnarray@s@i[#1]{%
  656. \@eqnarray{#1!{\nonumber\setbox\z@\hbox{##}\tabskip\z@}}%
  657. }
  658. % \end{macrocode}
  659. %
  660. % \subsubsection{Set up the initial display}
  661. %
  662. % \begin{macro}{\@eqnarray}
  663. %
  664. % The |\@eqnarray| command does most of the initial work. It sets up some
  665. % flags and things, builds the |\halign| preamble, and returns.
  666. %
  667. % \begin{macrocode}
  668. \def\@eqnarray#1{%
  669. % \end{macrocode}
  670. %
  671. % Start playing with the counter here. The original does some icky internal
  672. % playing, which isn't necessary. The |\if@eqnsw| switch is |true| if the
  673. % user hasn't supplied an equation number. The |\if@eqalast| switch is
  674. % |true| in the final equation-number column.
  675. %
  676. % \begin{macrocode}
  677. \refstepcounter{equation}%
  678. \@eqalastfalse%
  679. \global\@eqnswtrue%
  680. \m@th%
  681. % \end{macrocode}
  682. %
  683. % Set things up for the |\halign| which is coming up.
  684. %
  685. % \begin{macrocode}
  686. \openup\jot%
  687. \tabskip\eqaopenskip%
  688. \let\\\@eqncr%
  689. \everycr{}%
  690. $$%
  691. % \end{macrocode}
  692. %
  693. % We'll build the real |\halign| and preamble in a token register. All we
  694. % need to do is stuff the header in the token register, clear a switch
  695. % (that'll be explained later), parse the preamble and then expand the
  696. % tokens we collected. Easy, no?
  697. %
  698. % \begin{macrocode}
  699. \toks@{\halign to\displaywidth\bgroup}%
  700. \@tempswafalse%
  701. \eqa@preamble#1\end%
  702. \the\toks@\cr%
  703. }
  704. % \end{macrocode}
  705. %
  706. % \end{macro}
  707. %
  708. % \subsubsection{Parsing the preamble}
  709. %
  710. % All this actually involves is reading the next character and building a
  711. % command from it. That can pull off an argument if it needs it. Just make
  712. % sure we don't fall off the end and we'll be OK.
  713. %
  714. % \begin{macrocode}
  715. \def\eqa@preamble#1{%
  716. \ifx\end#1\else\csname eqa@char@#1\expandafter\endcsname\fi%
  717. }
  718. % \end{macrocode}
  719. %
  720. % Adding stuff to the preamble tokens is a simple matter of using
  721. % |\expandafter| in the correct way.\footnote{^^A
  722. % I have no idea why \LaTeX\ uses \cmd\edef\ for building its preamble. It
  723. % seems utterly insane to me -- the amount of bodgery that \env{tabular}
  724. % has to go through to make everything expand at the appropriate times is
  725. % scary. Maybe Messrs~Lamport and Mittelbach just forgot about token
  726. % registers when they were writing the code. Maybe I ought to rewrite the
  727. % thing properly some time. Sigh.
  728. %
  729. % As a sort of postscript to the above, I \emph{have} rewritten the
  730. % \env{tabular} environment, and made a damned fine job of it, in my
  731. % oh-so-humble opinion. All this \env{eqnarray} stuff has been remoulded
  732. % in terms of the generic column-defining things in \package{mdwtab}.
  733. % You're reading the documentation of the old version, which isn't
  734. % supported any more, so any bugs here are your own problem.}
  735. %
  736. % \begin{macrocode}
  737. \def\eqa@addraw#1{\expandafter\toks@\expandafter{\the\toks@#1}}
  738. % \end{macrocode}
  739. %
  740. % Now for some cleverness again. In order to put all the right bits of
  741. % |\tabskip| glue in the right places we must \emph{not} terminate each
  742. % column until we know what the next one is. We set |\if@tempswa| to be
  743. % |true| if there's a column waiting to be closed (so it's initially
  744. % |false|). The following macro adds a column correctly, assuming we're in
  745. % a formula. Other column types make their own arrangements.
  746. %
  747. % \begin{macrocode}
  748. \def\eqa@add#1{%
  749. \if@tempswa%
  750. \eqa@addraw{\tabskip\eqainskip&#1}%
  751. \else%
  752. \eqa@addraw{#1}%
  753. \fi%
  754. \@tempswatrue%
  755. }
  756. % \end{macrocode}
  757. %
  758. % Now to defining column types. Let's define a macro which allows us to
  759. % define column types:
  760. %
  761. % \begin{macrocode}
  762. \def\eqa@def#1{\expandafter\def\csname eqa@char@#1\endcsname}
  763. % \end{macrocode}
  764. %
  765. % Now we can define the column types. Each column type must loop back to
  766. % |\eqa@preamble| once it's finished, to read the rest of the preamble
  767. % string. Note the positioning of ord atoms in the stuff below. This will
  768. % space out relations and binops correctly when they occur at the edges of
  769. % columns, and won't affect ord atoms at the edges, because ords pack
  770. % closely.
  771. %
  772. % First the easy onces. Just stick |\hfil| in the right places and
  773. % everything will be all right.
  774. %
  775. % \begin{macrocode}
  776. \eqa@def r{\eqa@add{\hfil$\eqa@style##{}$}\eqa@preamble}
  777. \eqa@def c{\eqa@add{\hfil$\eqa@style{}##{}$\hfil}\eqa@preamble}
  778. \eqa@def l{\eqa@add{$\eqa@style{}##$\hfil}\eqa@preamble}
  779. \eqa@def x{\eqa@add{\hfil$\eqa@style##$\hfil}\eqa@preamble}
  780. % \end{macrocode}
  781. %
  782. % Now for the textual ones. This is also fairly easy.
  783. %
  784. % \begin{macrocode}
  785. \eqa@def T#1{%
  786. \eqa@add{}%
  787. \if#1l\else\eqa@addraw{\hfil}\fi%
  788. \eqa@addraw{##}%
  789. \if#1r\else\eqa@addraw{\hfil}\fi%
  790. \eqa@preamble%
  791. }
  792. % \end{macrocode}
  793. %
  794. % Sort of split types of equations. I mustn't use |\rlap| here, or
  795. % everything goes wrong -- |\\| doesn't get noticed by \TeX\ in the same way
  796. % as |\cr| does.
  797. %
  798. % \begin{macrocode}
  799. \eqa@def L{\eqa@add{\hb@xt@\z@{$\eqa@style##$\hss}\qquad}\eqa@preamble}
  800. % \end{macrocode}
  801. %
  802. % The \lit{:} column type is fairly simple. We set |\tabskip| up to make
  803. % lots of space and close the current column, because there must be one.^^A
  804. % \footnote{This is an assumption.}
  805. %
  806. % \begin{macrocode}
  807. \eqa@def :{%
  808. \eqa@addraw{\tabskip\eqacolskip&}\@tempswafalse\eqa@preamble%
  809. }
  810. \eqa@def q{\eqa@add{\quad}\@tempswafalse\eqa@preamble}
  811. % \end{macrocode}
  812. %
  813. % The other column types just insert given text in an appropriate way.
  814. %
  815. % \begin{macrocode}
  816. \eqa@def >#1{\eqa@add{#1}\@tempswafalse\eqa@preamble}
  817. \eqa@def <#1{\eqa@addraw{#1}\eqa@preamble}
  818. % \end{macrocode}
  819. %
  820. % Finally, the magical \lit{!} column type, which sets the equation number.
  821. % We set up the |\tabskip| glue properly, tab on, and set the flag which
  822. % marks the final column.
  823. %
  824. % \begin{macrocode}
  825. \eqa@def !#1{%
  826. \eqa@addraw{\tabskip\eqacloseskip&\@eqalasttrue#1}\eqa@preamble%
  827. }
  828. % \end{macrocode}
  829. %
  830. % \subsubsection{Newline codes}
  831. %
  832. % Newline sequences (|\\|) get turned into calls of |\@eqncr|. The job is
  833. % fairly simple, really. However, to avoid reading `|&|' characters
  834. % prematurely, we set up a magic brace (from the \package{array} package --
  835. % this avoids creating ord atoms and other nastyness).
  836. %
  837. % \begin{macrocode}
  838. \def\@eqncr{%
  839. \iffalse{\fi\ifnum0=`}\fi%
  840. \@ifstar{\eqacr@i{\@M}}{\eqacr@i{\interdisplaylinepenalty}}%
  841. }
  842. \def\eqacr@i#1{\@ifnextchar[{\eqacr@ii{#1}}{\eqacr@ii{#1}[\z@]}}
  843. \def\eqacr@ii#1[#2]{%
  844. \ifnum0=`{}\fi%
  845. \eqa@eqnum%
  846. \noalign{\penalty#1\vskip#2\relax}%
  847. }
  848. % \end{macrocode}
  849. %
  850. % \subsubsection{Setting equation numbers}
  851. %
  852. % Before we start, we need to generalise the flush-left number handling bits.
  853. % The macro |\eqa@eqpos| will put its argument in the right place.
  854. %
  855. % \begin{macrocode}
  856. \if@leqno
  857. \def\eqa@eqpos#1{%
  858. \hb@[email protected]\p@{}\rlap{\normalfont\normalcolor\hskip-\displaywidth#1}%
  859. }
  860. \else
  861. \def\eqa@eqpos#1{\normalfont\normalcolor#1}
  862. \fi
  863. % \end{macrocode}
  864. %
  865. % First we need to move into the right column. Then we just set the equation
  866. % number appropriately. There is some subtlety here, ish. The |\relax| is
  867. % important, to delay expansion of the |\if|\dots\ until the new column has
  868. % been started. The two helper macros are important too, to hide `|&|'s and
  869. % `|\cr|'s from \TeX's scanner until the right time.
  870. %
  871. % \begin{macrocode}
  872. \def\eqa@eqnum{%
  873. \relax%
  874. \if@eqalast\expandafter\eqa@eqnum@i\else\expandafter\eqa@eqnum@ii\fi%
  875. }
  876. \def\eqa@eqnum@i{%
  877. \if@eqnsw%
  878. \eqa@eqpos{(\theequation)}\stepcounter{equation}%
  879. \else%
  880. \eqa@eqpos\eqa@number%
  881. \fi%
  882. \global\@eqnswtrue%
  883. \cr%
  884. }
  885. \def\eqa@eqnum@ii{&\eqa@eqnum}
  886. % \end{macrocode}
  887. %
  888. % \subsubsection{Numbering control}
  889. %
  890. % This is trivial. We set the |\if@eqnsw| flag to be |false| and store the
  891. % text in a macro.
  892. %
  893. % \begin{macrocode}
  894. \let\nonumber\relax
  895. \newcommand\nonumber[1][]{\global\@eqnswfalse\global\def\eqa@number{#1}}
  896. % \end{macrocode}
  897. %
  898. % \subsubsection{Closing the environments off}
  899. %
  900. % This is really easy. Set the final equation number, close the |\halign|,
  901. % tidy up the equation counter (it's been stepped once too many times) and
  902. % close the display.
  903. %
  904. % \begin{macrocode}
  905. \def\endeqnarray{%
  906. \eqa@eqnum%
  907. \egroup%
  908. \global\advance\c@equation\m@ne%
  909. $$%
  910. \global\@ignoretrue%
  911. }
  912. \expandafter\let\csname endeqnarray*\endcsname\endeqnarray
  913. % \end{macrocode}
  914. %
  915. % Now start up the other package again.
  916. %
  917. % \begin{macrocode}
  918. %</oldeqnarray>
  919. %<*package>
  920. % \end{macrocode}
  921. %
  922. % \end{old-eqnarray}
  923. %
  924. % That's all there is. Byebye.
  925. %
  926. % \begin{macrocode}
  927. %</package>
  928. % \end{macrocode}
  929. %
  930. % \hfill Mark Wooding, \today
  931. %
  932. % \Finale
  933. \endinput