86f6a31e |
1 | % \begin{meta-comment} |
2 | % |
4a655c6f |
3 | % $Id: mdwmath.dtx,v 1.2 2003/09/05 16:14:36 mdw Exp $ |
86f6a31e |
4 | % |
5 | % Various nicer mathematical things |
6 | % |
4a655c6f |
7 | % (c) 2003 Mark Wooding |
86f6a31e |
8 | % |
9 | %----- Revision history ----------------------------------------------------- |
10 | % |
11 | % $Log: mdwmath.dtx,v $ |
4a655c6f |
12 | % Revision 1.2 2003/09/05 16:14:36 mdw |
13 | % Fraction typesetting; more symbols; better documentation of Biggles. |
14 | % |
86f6a31e |
15 | % Revision 1.1 2002/02/03 20:49:03 mdw |
16 | % Checkin for new build system. |
17 | % |
18 | % Revision 1.1 1996/11/19 20:53:21 mdw |
19 | % Initial revision |
20 | % |
21 | % |
22 | % \end{meta-comment} |
23 | % |
24 | % \begin{meta-comment} <general public licence> |
25 | %% |
26 | %% mdwmath package -- various nicer mathematical things |
4a655c6f |
27 | %% Copyright (c) 2003 Mark Wooding |
86f6a31e |
28 | %% |
29 | %% This program is free software; you can redistribute it and/or modify |
30 | %% it under the terms of the GNU General Public License as published by |
31 | %% the Free Software Foundation; either version 2 of the License, or |
32 | %% (at your option) any later version. |
33 | %% |
34 | %% This program is distributed in the hope that it will be useful, |
35 | %% but WITHOUT ANY WARRANTY; without even the implied warranty of |
36 | %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
37 | %% GNU General Public License for more details. |
38 | %% |
39 | %% You should have received a copy of the GNU General Public License |
40 | %% along with this program; if not, write to the Free Software |
41 | %% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
42 | %% |
43 | % \end{meta-comment} |
44 | % |
45 | % \begin{meta-comment} <Package preamble> |
46 | %<+package>\NeedsTeXFormat{LaTeX2e} |
47 | %<+package>\ProvidesPackage{mdwmath} |
4a655c6f |
48 | %<+package> [2003/08/25 1.3 Nice mathematical things] |
86f6a31e |
49 | %<+oldeqnarray>\NeedsTeXFormat{LaTeX2e} |
50 | %<+oldeqnarray>\ProvidesPackage{eqnarray} |
51 | %<+oldeqnarray> [1996/04/11 1.1 Old enhanced eqnarray] |
52 | % \end{meta-comment} |
53 | % |
4a655c6f |
54 | % \CheckSum{729} |
86f6a31e |
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 | \let\opmod\pmod |
77 | \usepackage{amssymb} |
78 | \describespackage{mdwmath} |
4a655c6f |
79 | %\describespackage{eqnarray} |
86f6a31e |
80 | \ignoreenv{old-eqnarray} |
4a655c6f |
81 | %\unignoreenv{old-eqnarray} |
86f6a31e |
82 | \mdwdoc |
83 | %</driver> |
84 | % |
85 | % \end{meta-comment} |
86 | % |
87 | % \section{User guide} |
88 | % |
89 | % \subsection{Square root typesetting} |
90 | % |
91 | % \DescribeMacro{\sqrt} |
92 | % The package supplies a star variant of the |\sqrt| command which omits the |
93 | % vinculum over the operand (the line over the top). While this is most |
94 | % useful in simple cases like $\sqrt*{2}$ it works for any size of operand. |
95 | % The package also re-implements the standard square root command so that it |
96 | % positions the root number rather better. |
97 | % |
98 | % \begin{figure} |
99 | % \begin{demo}[w]{Examples of the new square root command} |
100 | %\[ \sqrt*{2} \quad \mbox{rather than} \quad \sqrt{2} \] |
101 | %\[ \sqrt*[3]{2} \quad \mbox{ rather than } \quad \sqrt[3]{2} \] |
102 | %\[ \sqrt{x^3 + \sqrt*[y]{\alpha}} - \sqrt*[n+1]{a} \] |
103 | %\[ x = \sqrt*[3]{\frac{3y}{7}} \] |
104 | %\[ q = \frac{2\sqrt*{2}}{5}+\sqrt[\frac{n+1}{2}]{2x^2+3xy-y^2} \] |
105 | % \end{demo} |
106 | % \end{figure} |
107 | % |
108 | % [Note that omission of the vinculum was originally a cost-cutting exercise |
109 | % because the radical symbol can just fit in next to its operand and |
110 | % everything ends up being laid out along a line. However, I find that the |
111 | % square root without vinculum is less cluttered, so I tend to use it when |
112 | % it doesn't cause ambiguity.] |
113 | % |
114 | % \subsection{Modular arithmetic} |
115 | % |
116 | % In standard maths mode, there's too much space before the parentheses in |
117 | % the output of the |\pmod| command. Suppose that $x \equiv y^2 \opmod n$: |
118 | % then the spacing looks awful. Go on, admit it. |
119 | % |
120 | % It looks OK in a display. For example, if |
121 | % \[ c \equiv m^e \opmod n \] |
122 | % then it's fine. The package redefines the |\pmod| command to do something |
123 | % more sensible. So now $c^d \equiv m^{ed} \equiv m \pmod n$ and all looks |
124 | % fine. |
125 | % |
126 | % \subsection{Some maths symbols you already have} |
127 | % |
128 | % \DescribeMacro\bitor |
129 | % \DescribeMacro\bitand |
130 | % \DescribeMacro\dblor |
131 | % \DescribeMacro\dbland |
132 | % Having just tried to do some simple things, I've found that there are maths |
133 | % symbols missing. Here they are, in all their glory: |
134 | % \begin{center} \unverb\| \begin{tabular}{cl|cl|cl} |
135 | % $\&$ & "\&" & $\bitor$ & "\bitor" & $\dbland$ & "\dbland" \\ |
136 | % $\bitand$ & "\bitand" & $\dblor$ & "\dblor" & |
137 | % \end{tabular} \end{center} |
138 | % |
139 | % \DescribeMacro\xor |
140 | % \DescribeMacro\cat |
141 | % I also set up the |\xor| command to typeset `$\xor$', which is commonly |
142 | % used to represent the bitsize exclusive-or operation among cryptographers. |
143 | % The command |\cat| typesets `$\cat$', which is a common operator indicating |
144 | % concatenation of strings. |
145 | % |
146 | % \DescribeMacro\lsl |
147 | % \DescribeMacro\lsr |
148 | % \DescribeMacro\rol |
149 | % \DescribeMacro\ror |
150 | % The commands |\lsl| and |\lsr| typeset binary operators `$\lsl$' and |
151 | % `$\lsr$' respectively, and |\rol| and |\ror| typeset `$\rol$' and `$\ror$'. |
152 | % Note that these are spaced as binary operators, rather than relations. |
153 | % |
154 | % \DescribeMacro\compose |
155 | % \DescribeMacro\implies |
156 | % \DescribeMacro\vect |
157 | % The |\compose| command typesets `$\compose$', which is usually used to |
158 | % denote function composition. The |\implies| command is made to typeset |
159 | % `$\implies$'. And \syntax{"\\vect{"<x>"}"} typesets `$\vect{x}$'. |
160 | % |
161 | % \DescribeMacro\statclose |
162 | % \DescribeMacro\compind |
163 | % The |\statclose| command typesets `$\statclose$', which indicates |
164 | % `statistical closeness' of probability distributions; |\compind| typesets |
165 | % `$\compind$', which indicates computational indistinguishability. |
166 | % |
4a655c6f |
167 | % \subsection{Fractions} |
168 | % |
169 | % \DescribeMacro\fracdef |
170 | % We provide a general fraction system, a little tiny bit like |
171 | % \package{amsmath}'s |\genfrac|. Say |
172 | % \syntax{"\\fracdef{"<name>"}{"<frac-params>"}"} to define a new |
173 | % |\frac|-like operator. The \<frac-params> are a comma-separated list of |
174 | % parameters: |
175 | % \begin{description} |
176 | % \item[\lit*{line}] Include a horizontal line between the top and bottom |
177 | % (like |\frac|). |
178 | % \item[\lit*{line=}\<length>] Include a horizontal line with width |
179 | % \<length>. |
180 | % \item[\lit*{noline}] Don't include a line (like |\binom|). |
181 | % \item[\lit*{leftdelim=}\<delim>] Use \<delim> as the left-hand delimiter. |
182 | % \item[\lit*{rightdelim=}\<delim>] Use \<delim> as the right-hand delimiter. |
183 | % \item[\lit*{nodelims}] Don't include delimiters. |
184 | % \item[\lit*{style=}\<style>] Typeset the fraction in \<style>, which is one |
185 | % of |display|, |text|, |script| or |scriptscript|. |
186 | % \item[\lit*{style}] Use the prevailing style for the fraction. |
187 | % \item[\lit*{innerstyle=}\<style>] Typeset the \emph{components} of the |
188 | % fraction in \<style>. |
189 | % \item[\lit*{innerstyle}] Typeset the fraction components according to the |
190 | % prevailing style. |
191 | % \end{description} |
192 | % The commands created by |\fracdef| have the following syntax: |
193 | % \syntax{<name>"["<frac-params>"]{"<top>"}{"<bottom>"}"}. Thus, you can use |
194 | % the optional argument to `tweak' the fraction if necessary. This isn't |
195 | % such a good idea to do often. |
196 | % |
197 | % \DescribeMacro\frac |
198 | % \DescribeMacro\binom |
86f6a31e |
199 | % \DescribeMacro\jacobi |
4a655c6f |
200 | % The macros |\frac|, |\binom| and |\jacobi| are defined using |\fracdef|. |
201 | % They typset $\frac{x}{y}$, $\binom{n}{k}$ and $\jacobi{x}{n}$ respectively. |
202 | % (The last may be of use to number theorists talking about Jacobi or |
203 | % Lagrange symbols.) |
204 | % |
205 | % By way of example, these commands were defined using |
206 | %\begin{verbatim} |
207 | %\fracdef\frac{nodelims, line} |
208 | %\fracdef\binom{leftdelim = (, rightdelim = ), noline} |
209 | %\fracdef\jacobi{leftdelim = (, rightdelim = ), line} |
210 | %\end{verbatim} |
86f6a31e |
211 | % |
212 | % \subsection{Rant about derivatives} |
213 | % |
214 | % \DescribeMacro\d |
215 | % There is a difference between UK and US typesetting of derivatives. |
216 | % Americans typeset |
217 | % \[ \frac{dy}{dx} \] |
218 | % while the British want |
219 | % \[ \frac{\d y}{\d x}. \] |
4a655c6f |
220 | % The command |\d| command is fixed to typeset a `$\d$'. (In text mode, |
221 | % |\d{x}| still typesets `\d{x}'.) |
86f6a31e |
222 | % |
223 | % \subsection{New operator names} |
224 | % |
225 | % \DescribeMacro\keys |
226 | % \DescribeMacro\dom |
227 | % \DescribeMacro\ran |
228 | % \DescribeMacro\supp |
229 | % \DescribeMacro\lcm |
4a655c6f |
230 | % \DescribeMacro\ord |
231 | % \DescribeMacro\poly |
232 | % \DescribeMacro\negl |
86f6a31e |
233 | % A few esoteric new operator names are supplied. |
234 | % \begin{center} \unverb\| \begin{tabular}{cl|cl|cl} |
235 | % $\keys$ & "\keys" & $\dom$ & "\dom" & $\ran$ & "\ran" \\ |
4a655c6f |
236 | % $\supp$ & "\supp" & $\lcm$ & "\lcm" & $\ord$ & "\ord" \\ |
237 | % $\poly$ & "\poly" & $\negl$ & "\negl" |
86f6a31e |
238 | % \end{tabular} \end{center} |
239 | % I think |\lcm| ought to be self-explanatory. The |\dom| and |\ran| |
240 | % operators pick out the domain and range of a function, respectively; thus, |
241 | % if $F\colon X \to Y$ is a function, then $\dom F = X$ and $\ran F = Y$. |
242 | % The \emph{support} of a probability distribution $\mathcal{D}$ is the set |
243 | % of objects with nonzero probability; i.e., $\supp{D} = \{\, x \in |
4a655c6f |
244 | % \dom\mathcal{D} \mid \mathcal{D}(x) > 0 \,\}$. If $g \in G$ is a group |
245 | % element then $\ord g$ is the \emph{order} of $g$; i.e., the smallest |
246 | % positive integer $i$ where $g^i$ is the identity element, or $0$ if there |
247 | % is no such $i$. $\poly(n)$ is some polynomial function of $n$. A function |
248 | % $\nu(\cdot)$ is \emph{negligible} if, for every polynomial function |
249 | % $p(\cdot)$, there is an integer $N$ such that $\nu(n) < 1/p(n)$ for all $n |
250 | % > N$; $\negl(n)$ is some negligible function of $n$. |
86f6a31e |
251 | % |
252 | % \subsection{Standard set names} |
253 | % |
254 | % \DescribeMacro\Z |
255 | % \DescribeMacro\Q |
256 | % \DescribeMacro\R |
257 | % \DescribeMacro\C |
258 | % \DescribeMacro\N |
259 | % \DescribeMacro\F |
260 | % \DescribeMacro\powerset |
4a655c6f |
261 | % \DescribeMacro\gf |
86f6a31e |
262 | % If you have a |\mathbb| command defined, the following magic is revealed: |
263 | % \begin{center} \unverb\| \begin{tabular}{cl|cl|cl} |
264 | % $\Z$ & "\Z" & $\Q$ & "\Q" & $\R$ & "\R" \\ |
265 | % $\N$ & "\N" & $\F$ & "\F" & $\C$ & "\C" |
266 | % \end{tabular} \end{center} |
267 | % which are handy for various standard sets of things. Also the |\powerset| |
4a655c6f |
268 | % command typesets `$\powerset$', and \syntax{"\\gf{"<q>"}"}, which by default |
269 | % typesets $\gf{\syntax{<q>}}$ but you might choose to have it set |
270 | % $\mathrm{GF}(\syntax{<q>})$ intead. |
271 | % |
272 | % \subsection{Biggles} |
273 | % |
274 | % \DescribeMacro\bbigg |
275 | % \DescribeMacro\bbiggl |
276 | % \DescribeMacro\bbiggr |
277 | % \DescribeMacro\bbiggm |
278 | % The |\bbigg| commands generalizes the Plain \TeX\ |\bigg| family of |
279 | % macros. |\bbigg| produces an `ordinary' symbol; |\bbiggl| and |\bbiggr| |
280 | % produce left and right delimiters; and |\bbiggm| produces a relation. They |
281 | % produce symbols whose size is related to the prevailing text size -- so |
282 | % they adjust correctly in chapter headings, for example. |
283 | % |
284 | % The syntax is straightforward: |
285 | % \syntax{"\\"<bigop>"["$a$"]{"$n$"}{"<delim>"}"}. Describing it is a bit |
286 | % trickier. The size is based on the current |\strut| height. If |\strut| |
287 | % has a height of $h$ and a depth of $d$, then the delimiter produced has a |
288 | % height of $n \times (h + d + a)$. |
289 | % |
290 | % The old |\big| commands have been redefined in terms of |\bbigg|. |
86f6a31e |
291 | % |
292 | % \subsection{The `QED' symbol} |
293 | % |
294 | % \DescribeMacro\qed |
295 | % \DescribeMacro\qedrule |
296 | % For use in proofs of theorems, we provide a `QED' symbol which behaves well |
297 | % under bizarre line-splitting conditions. To use it, just say |\qed|. The |
298 | % little `\qedrule' symbol is available on its own, by saying |\qedrule|. |
299 | % This also sets |\qedsymbol| if it's not set already. |
300 | % \qed |
301 | % |
302 | % \begin{ignore} |
303 | % There used to be an eqnarray here, but that's migrated its way into the |
304 | % \package{mdwtab} package. Maybe the original version, without dependency |
305 | % on \package{mdwtab} ought to be releasable separately. I'll keep it around |
306 | % just in case. |
307 | % |
308 | % The following is the documentation for the original version. There's an |
309 | % updated edition in \package{mdwtab}. |
310 | % \end{ignore} |
311 | % |
312 | % \begin{old-eqnarray} |
313 | % |
314 | % \subsection{A new \env{eqnarray} environment} |
315 | % |
316 | % \LaTeX's built-in \env{eqnarray} is horrible -- it puts far too much space |
317 | % between the items in the array. This environment is rather nearer to the |
318 | % \env{amsmath} \env{align} environments, although rather less capable. |
319 | % |
320 | % \bigskip |
321 | % \DescribeEnv{eqnarray} |
322 | % {\synshorts |
323 | % \setbox0\hbox{"\\begin{eqnarray}["<preamble>"]" \dots "\\end{eqnarray}"} |
324 | % \leavevmode \hskip-\parindent \fbox{\box0} |
325 | % } |
326 | % \smallskip |
327 | % |
328 | % The new version of \env{eqnarray} tries to do everything which you really |
329 | % want it to. The \synt{preamble} string allows you to define the column |
330 | % types in a vaguely similar way to the wonderful \env{tabular} environment. |
331 | % The types provided (and it's easy-ish to add more) are: |
332 | % |
333 | % \def\ch{\char`} |
334 | % \begin{description} \def\makelabel{\hskip\labelsep\normalfont\ttfamily} |
335 | % \item [r] Right aligned equation |
336 | % \item [c] Centre-aligned equation |
337 | % \item [l] Left aligned equation |
338 | % \item [\textrm{\texttt{Tr}, \texttt{Tc} and \texttt{Tl}}] Right, centre and |
339 | % left aligned text (not maths) |
340 | % \item [L] Left aligned zero-width equation |
341 | % \item [x] Centred entire equation |
342 | % \item [:] Big gap separating sets of equations |
343 | % \item [q] Quad space |
344 | % \item [>\ch\{\synt{text}\ch\}] Insert text before column |
345 | % \item [<\ch\{\synt{text}\ch\}] Insert text after column |
346 | % \end{description} |
347 | % |
348 | % Some others are also defined: don't use them because they do complicated |
349 | % things which are hard to explain and they aren't much use anyway. |
350 | % |
351 | % The default preamble, if you don't supply one of your own, is \lit{rcl}. |
352 | % Most of the time, \lit{rl} is sufficient, although compatibility is more |
353 | % important to me. |
354 | % |
355 | % By default, there is no space between columns, which makes formul\ae\ in an |
356 | % \env{eqnarray} environment look just like formul\ae\ typeset on their own, |
357 | % except that things get aligned in columns. This is where the default |
358 | % \env{eqnarray} falls down: it leaves |\arraycolsep| space between each |
359 | % column making the thing look horrible. |
360 | % |
361 | % An example would be good here, I think. This one's from exercise 22.9 of |
362 | % the \textit{\TeX book}. |
363 | % |
364 | % \begin{demo}[w]{Simultaneous equations} |
365 | %\begin{eqnarray}[rcrcrcrl] |
366 | % 10w & + & 3x & + & 3y & + & 18z & = 1 \\ |
367 | % 6w & - & 17x & & & - & 5z & = 2 |
368 | %\end{eqnarray} |
369 | % \end{demo} |
370 | % |
371 | % Choosing a more up-to-date example, here's one demonstrating the \lit{:} |
372 | % column specifier from the \textit{\LaTeX\ Companion}. |
373 | % |
374 | % \begin{demo}[w]{Lots of equations} |
375 | %\begin{eqnarray}[rl:rl:l] |
376 | % V_i &= v_i - q_i v_j, & X_i &= x_i - q_i x_j, & |
377 | % U_i = u_i, \qquad \mbox{for $i \ne j$} \label{eq:A} \\ |
378 | % V_j &= v_j, & X_j &= x_j & |
379 | % U_j u_j + \sum_{i \ne j} q_i u_i. |
380 | %\end{eqnarray} |
381 | % \end{demo} |
382 | % |
383 | % We can make things more interesting by adding a plain text column. Here we |
384 | % go: |
385 | % |
386 | % \begin{demo}[w]{Plain text column} |
387 | %\begin{eqnarray}[rlqqTl] |
388 | % x &= y & by (\ref{eq:A}) \\ |
389 | % x' &= y' & by definition \\ |
390 | % x + x' &= y + y' & by Axiom~1 |
391 | %\end{eqnarray} |
392 | % \end{demo} |
393 | % |
394 | % The new features also mean that you don't need to mess about with |
395 | % |\lefteqn| any more. This is handled by the \lit{L} column type: |
396 | % |
397 | % \begin{demo}{Splitting example} |
398 | %\begin{eqnarray*}[Ll] |
399 | % w+x+y+z = \\ |
4a655c6f |
400 | % & a+b+c+d+e+{} \\ |
86f6a31e |
401 | % & f+g+h+i+j |
402 | %\end{eqnarray*} |
403 | % \end{demo} |
404 | % |
405 | % Finally, just to prove that the spacing's right at last, here's another one |
406 | % from the \textit{Companion}. |
407 | % |
408 | % \begin{demo}{Spacing demonstration} |
409 | %\begin{equation} |
410 | % x^2 + y^2 = z^2 |
411 | %\end{equation} |
412 | %\begin{eqnarray}[rl] |
413 | % x^2 + y^2 &= z^2 \\ |
414 | % y^2 &< z^2 |
415 | %\end{eqnarray} |
416 | % \end{demo} |
417 | % |
418 | % Well, that was easy enough. Now on to numbering. As you've noticed, the |
419 | % equations above are numbered. You can use the \env{eqnarray$*$} |
420 | % environment to turn off the numbering in the whole environment, or say |
421 | % |\nonumber| on a line to suppress numbering of that one in particular. |
422 | % More excitingly, you can say \syntax{"\\nonumber["<text>"]"} to choose |
423 | % what text to display. |
424 | % |
425 | % A note for cheats: you can use the sparkly new \env{eqnarray} for simple |
426 | % equations simply by specifying \lit{x} as the column description. Who |
427 | % needs \AmSTeX? |;-)| |
428 | % |
429 | % \end{old-eqnarray} |
430 | % |
431 | % \implementation |
432 | % |
433 | % \section{Implementation} |
434 | % |
435 | % This isn't really complicated (honest) although it is a lot hairier than I |
436 | % think it ought to be. |
437 | % |
438 | % \begin{macrocode} |
439 | %<*package> |
4a655c6f |
440 | \RequirePackage{amssymb} |
441 | \RequirePackage{mdwkey} |
86f6a31e |
442 | % \end{macrocode} |
443 | % |
444 | % \subsection{Square roots} |
445 | % |
446 | % \subsubsection{Where is the square root sign?} |
447 | % |
448 | % \LaTeX\ hides the square root sign away somewhere without telling anyone |
449 | % where it is. I extract it forcibly by peeking inside the |\sqrtsign| macro |
450 | % and scrutinising the contents. Here we go: prepare for yukkiness. |
451 | % |
452 | % \begin{macrocode} |
453 | \newcount\sq@sqrt \begingroup \catcode`\|0 \catcode`\\12 |
454 | |def|sq@readrad#1"#2\#3|relax{|global|sq@sqrt"#2|relax} |
455 | |expandafter|sq@readrad|meaning|sqrtsign|relax |endgroup |
456 | \def\sq@delim{\delimiter\sq@sqrt\relax} |
457 | % \end{macrocode} |
458 | % |
459 | % \subsubsection{Drawing fake square root signs} |
460 | % |
461 | % \TeX\ absolutely insists on drawing square root signs with a vinculum over |
462 | % the top. In order to get the same effect, we have to attempt to emulate |
463 | % \TeX's behaviour. |
464 | % |
465 | % \begin{macro}{\sqrtdel} |
466 | % |
467 | % This does the main job of typesetting a vinculum-free radical.\footnote{^^A |
468 | % Note for chemists: this is nothing to do with short-lived things which |
469 | % don't have their normal numbers of electrons. And it won't reduce the |
470 | % appearance of wrinkles either.} |
471 | % It's more or less a duplicate of what \TeX\ does internally, so it might be |
472 | % a good plan to have a copy of Appendix~G open while you examine this. |
473 | % |
474 | % We start off by using |\mathpalette| to help decide how big things should |
475 | % be. |
476 | % |
477 | % \begin{macrocode} |
478 | \def\sqrtdel{\mathpalette\sqrtdel@i} |
479 | % \end{macrocode} |
480 | % |
481 | % Read the contents of the radical into a box, so we can measure it. |
482 | % |
483 | % \begin{macrocode} |
484 | \def\sqrtdel@i#1#2{% |
485 | \setbox\z@\hbox{$\m@th#1#2$}% %%% Bzzzt -- uncramps the mathstyle |
486 | % \end{macrocode} |
487 | % |
488 | % Now try and sort out the values needed in this calculation. We'll assume |
489 | % that $\xi_8$ is 0.6\,pt, the way it usually is. Next try to work out the |
490 | % value of $\varphi$. |
491 | % |
492 | % \begin{macrocode} |
493 | \ifx#1\displaystyle% |
494 | \@tempdima1ex% |
495 | \else% |
496 | \@tempdima.6\p@% |
497 | \fi% |
498 | % \end{macrocode} |
499 | % |
500 | % That was easy. Now for $\psi$. |
501 | % |
502 | % \begin{macrocode} |
503 | \@tempdimb.6\p@% |
504 | \advance\@tempdimb.25\@tempdima% |
505 | % \end{macrocode} |
506 | % |
507 | % Build the `delimiter' in a box of height $h(x)+d(x)+\psi+\xi_8$, as |
508 | % requested. Box~2 will do well for this purpose. |
509 | % |
510 | % \begin{macrocode} |
511 | \dimen@.6\p@% |
512 | \advance\dimen@\@tempdimb% |
513 | \advance\dimen@\ht\z@% |
514 | \advance\dimen@\dp\z@% |
515 | \setbox\tw@\hbox{% |
516 | $\left\sq@delim\vcenter to\dimen@{}\right.\n@space$% |
517 | }% |
518 | % \end{macrocode} |
519 | % |
520 | % Now we need to do some more calculating (don't you hate it?). As far as |
521 | % Appendix~G is concerned, $\theta=h(y)=0$, because we want no rule over the |
522 | % top. |
523 | % |
524 | % \begin{macrocode} |
525 | \@tempdima\ht\tw@% |
526 | \advance\@tempdima\dp\tw@% |
527 | \advance\@tempdima-\ht\z@% |
528 | \advance\@tempdima-\dp\z@% |
529 | \ifdim\@tempdima>\@tempdimb% |
530 | \advance\@tempdima\@tempdimb% |
531 | \@tempdimb.5\@tempdima% |
532 | \fi% |
533 | % \end{macrocode} |
534 | % |
535 | % Work out how high to raise the radical symbol. Remember that Appendix~G |
536 | % thinks that the box has a very small height, although this is untrue here. |
537 | % |
538 | % \begin{macrocode} |
539 | \@tempdima\ht\z@% |
540 | \advance\@tempdima\@tempdimb% |
541 | \advance\@tempdima-\ht\tw@% |
542 | % \end{macrocode} |
543 | % |
544 | % Build the output (finally). The brace group is there to turn the output |
545 | % into a mathord, one of the few times that this is actually desirable. |
546 | % |
547 | % \begin{macrocode} |
548 | {\raise\@tempdima\box\tw@\vbox{\kern\@tempdimb\box\z@}}% |
549 | } |
550 | % \end{macrocode} |
551 | % |
552 | % \end{macro} |
553 | % |
554 | % \subsubsection{The new square root command} |
555 | % |
556 | % This is where we reimplement all the square root stuff. Most of this stuff |
557 | % comes from the \PlainTeX\ macros, although some is influenced by \AmSTeX\ |
558 | % and \LaTeXe, and some is original. I've tried to make the spacing vaguely |
559 | % automatic, so although it's not configurable like \AmSTeX's version, the |
560 | % output should look nice more of the time. Maybe. |
561 | % |
562 | % \begin{macro}{\sqrt} |
563 | % |
564 | % \LaTeX\ says this must be robust, so we make it robust. The first thing to |
565 | % do is to see if there's a star and pass the appropriate squareroot-drawing |
566 | % command on to the rest of the code. |
567 | % |
568 | % \begin{macrocode} |
569 | \DeclareRobustCommand\sqrt{\@ifstar{\sqrt@i\sqrtdel}{\sqrt@i\sqrtsign}} |
570 | % \end{macrocode} |
571 | % |
572 | % Now we can sort out an optional argument to be displayed on the root. |
573 | % |
574 | % \begin{macrocode} |
575 | \def\sqrt@i#1{\@ifnextchar[{\sqrt@ii{#1}}{\sqrt@iv{#1}}} |
576 | % \end{macrocode} |
577 | % |
578 | % Stages~2 and~3 below are essentially equivalents of \PlainTeX's |
579 | % |\root|\dots|\of| and |\r@@t|. Here we also find the first wrinkle: the |
580 | % |\rootbox| used to store the number is spaced out on the left if necessary. |
581 | % There's a backspace after the end so that the root can slip underneath, and |
582 | % everything works out nicely. Unfortunately size is fixed here, although |
583 | % doesn't actually seem to matter. |
584 | % |
585 | % \begin{macrocode} |
586 | \def\sqrt@ii#1[#2]{% |
587 | \setbox\rootbox\hbox{$\m@th\scriptscriptstyle{#2}$}% |
588 | \ifdim\wd\rootbox<6\p@% |
589 | \setbox\rootbox\hb@xt@6\p@{\hfil\unhbox\rootbox}% |
590 | \fi% |
591 | \mathpalette{\sqrt@iii{#1}}% |
592 | } |
593 | % \end{macrocode} |
594 | % |
595 | % Now we can actually build everything. Note that the root is raised by its |
596 | % depth -- this prevents a common problem with letters with descenders. |
597 | % |
598 | % \begin{macrocode} |
599 | \def\sqrt@iii#1#2#3{% |
600 | \setbox\z@\hbox{$\m@th#2#1{#3}$}% |
601 | \dimen@\ht\z@% |
602 | \advance\dimen@-\dp\z@% |
603 | \dimen@.6\dimen@% |
604 | \advance\dimen@\dp\rootbox% |
605 | \mkern-3mu% |
606 | \raise\dimen@\copy\rootbox% |
607 | \mkern-10mu% |
608 | \box\z@% |
609 | } |
610 | % \end{macrocode} |
611 | % |
612 | % Finally handle a non-numbered root. We read the rooted text in as an |
613 | % argument, to stop problems when people omit the braces. (\AmSTeX\ does |
614 | % this too.) |
615 | % |
616 | % \begin{macrocode} |
617 | \def\sqrt@iv#1#2{#1{#2}} |
618 | % \end{macrocode} |
619 | % |
620 | % \end{macro} |
621 | % |
622 | % \begin{macro}{\root} |
623 | % |
624 | % We also re-implement \PlainTeX's |\root| command, just in case someone uses |
625 | % it, and supply a star-variant. This is all very trivial. |
626 | % |
627 | % \begin{macrocode} |
628 | \def\root{\@ifstar{\root@i\sqrtdel}{\root@i\sqrtsign}} |
629 | \def\root@i#1#2\of{\sqrt@ii{#1}[#2]} |
630 | % \end{macrocode} |
631 | % |
632 | % \end{macro} |
633 | % |
634 | % \subsection{Modular programming} |
635 | % |
636 | % \begin{macro}{\pmod} |
637 | % |
638 | % Do some hacking if not |\ifouter|. |
639 | % |
640 | % \begin{macrocode} |
641 | \def\pmod#1{% |
642 | \ifinner\;\else\allowbreak\mkern18mu\fi% |
643 | ({\operator@font mod}\,\,#1)% |
644 | } |
645 | % \end{macrocode} |
646 | % |
647 | % \end{macro} |
648 | % |
649 | % \subsection{Some magic new maths characters} |
650 | % |
651 | % \begin{macro}{\bitor} |
652 | % \begin{macro}{\bitand} |
653 | % \begin{macro}{\dblor} |
654 | % \begin{macro}{\dbland} |
655 | % \begin{macro}{\xor} |
656 | % \begin{macro}{\lor} |
657 | % \begin{macro}{\ror} |
658 | % \begin{macro}{\lsl} |
659 | % \begin{macro}{\lsr} |
660 | % |
661 | % The new boolean operators. |
662 | % |
663 | % \begin{macrocode} |
664 | \DeclareMathSymbol{&}{\mathbin}{operators}{`\&} |
665 | \DeclareMathSymbol{\bitand}{\mathbin}{operators}{`\&} |
666 | \def\bitor{\mathbin\mid} |
667 | \def\dblor{\mathbin{\mid\mid}} |
668 | \def\dbland{\mathbin{\mathrel\bitand\mathrel\bitand}} |
669 | \let\xor\oplus |
670 | \def\lsl{\mathbin{<\!\!<}} |
671 | \def\lsr{\mathbin{>\!\!>}} |
672 | \def\rol{\mathbin{<\!\!<\!\!<}} |
673 | \def\ror{\mathbin{>\!\!>\!\!>}} |
674 | \AtBeginDocument{\ifx\lll\@@undefined\else |
675 | \def\lsl{\mathbin{\ll}} |
676 | \def\lsr{\mathbin{\gg}} |
677 | \def\rol{\mathbin{\lll}} |
678 | \def\ror{\mathbin{\ggg}} |
679 | \fi} |
680 | % \end{macrocode} |
681 | % |
682 | % \end{macro} |
683 | % \end{macro} |
684 | % \end{macro} |
685 | % \end{macro} |
686 | % \end{macro} |
687 | % \end{macro} |
688 | % \end{macro} |
689 | % \end{macro} |
690 | % \end{macro} |
691 | % |
692 | % \begin{macro}{\cat} |
693 | % \begin{macro}{\compose} |
694 | % \begin{macro}{\implies} |
695 | % \begin{macro}{\vect} |
696 | % \begin{macro}{\d} |
697 | % \begin{macro}{\jacobi} |
698 | % |
699 | % A mixed bag of stuff. |
700 | % |
701 | % \begin{macrocode} |
702 | \def\cat{\mathbin{\|}} |
703 | \let\compose\circ |
704 | \def\implies{\Rightarrow} |
705 | \def\vect#1{\mathord{\mathbf{#1}}} |
4a655c6f |
706 | \def\d{% |
707 | \ifmmode\mathord{\operator@font d}% |
708 | \else\expandafter\a\expandafter d\fi% |
709 | } |
86f6a31e |
710 | \def\jacobi#1#2{{{#1}\overwithdelims()#2}} |
711 | % \end{macrocode} |
712 | % |
713 | % \end{macro} |
714 | % \end{macro} |
715 | % \end{macro} |
716 | % \end{macro} |
717 | % \end{macro} |
718 | % \end{macro} |
719 | % |
720 | % \begin{macro}{\statclose} |
721 | % \begin{macro}{\compind} |
722 | % |
723 | % Fancy new relations for probability distributions. |
724 | % |
725 | % \begin{macrocode} |
726 | \def\statclose{\mathrel{\mathop{=}\limits^{\scriptscriptstyle s}}} |
727 | \def\compind{\mathrel{\mathop{\approx}\limits^{\scriptscriptstyle c}}} |
728 | % \end{macrocode} |
729 | % |
730 | % \end{macro} |
731 | % \end{macro} |
732 | % |
733 | % \begin{macro}{\keys} |
734 | % \begin{macro}{\dom} |
735 | % \begin{macro}{\ran} |
736 | % \begin{macro}{\supp} |
737 | % \begin{macro}{\lcm} |
4a655c6f |
738 | % \begin{macro}{\poly} |
739 | % \begin{macro}{\negl} |
740 | % \begin{macro}{\ord} |
86f6a31e |
741 | % |
742 | % And the new operator names. |
743 | % |
744 | % \begin{macrocode} |
745 | \def\keys{\mathop{\operator@font keys}\nolimits} |
746 | \def\dom{\mathop{\operator@font dom}\nolimits} |
747 | \def\ran{\mathop{\operator@font ran}\nolimits} |
748 | \def\supp{\mathop{\operator@font supp}\nolimits} |
749 | \def\lcm{\mathop{\operator@font lcm}\nolimits} |
4a655c6f |
750 | \def\poly{\mathop{\operator@font poly}\nolimits} |
751 | \def\negl{\mathop{\operator@font negl}\nolimits} |
752 | \def\ord{\mathop{\operator@font ord}\nolimits} |
86f6a31e |
753 | % \end{macrocode} |
754 | % |
755 | % \end{macro} |
756 | % \end{macro} |
757 | % \end{macro} |
758 | % \end{macro} |
759 | % \end{macro} |
4a655c6f |
760 | % \end{macro} |
761 | % \end{macro} |
762 | % \end{macro} |
763 | % |
764 | % \subsection{Fractions} |
765 | % |
766 | % \begin{macro}{\@frac@parse} |
767 | % |
768 | % \syntax{"\\@frac@parse{"<stuff>"}{"<frac-params>"}"} -- run \<stuff> |
769 | % passing it three arguments: an infix fraction-making command, the `outer' |
770 | % style, and the `inner' style. |
771 | % |
772 | % This is rather tricky. We clear a load of parameters, parse the parameter |
773 | % list, and then build a token list containing the right stuff. Without the |
774 | % token list fiddling, we end up expanding things at the wrong times -- for |
775 | % example, |\{| expands to something terribly unpleasant in a document |
776 | % preamble. |
777 | % |
778 | % All of the nastiness is contained in a group. |
779 | % |
780 | % \begin{macrocode} |
781 | \def\@frac@parse#1#2{% |
782 | \begingroup% |
783 | \let\@wd\@empty\def\@ldel{.}\def\@rdel{.}% |
784 | \def\@op{over}\let\@dim\@empty\@tempswafalse% |
785 | \let\@is\@empty\let\@os\@empty% |
786 | \mkparse{mdwmath:frac}{#2}% |
787 | \toks\tw@{\endgroup#1}% |
788 | \toks@\expandafter{\csname @@\@op\@wd\endcsname}% |
789 | \if@tempswa% |
790 | \toks@\expandafter{\the\expandafter\toks@\@ldel}% |
791 | \toks@\expandafter{\the\expandafter\toks@\@rdel}% |
792 | \fi% |
793 | \expandafter\toks@\expandafter{\the\expandafter\toks@\@dim}% |
794 | \toks@\expandafter{\the\toks\expandafter\tw@\expandafter{\the\toks@}} |
795 | \toks@\expandafter{\the\expandafter\toks@\expandafter{\@os}} |
796 | \toks@\expandafter{\the\expandafter\toks@\expandafter{\@is}} |
797 | \the\toks@% |
798 | } |
799 | % \end{macrocode} |
800 | % |
801 | % The keyword definitions are relatively straightforward now. The error |
802 | % handling for \textsf{style} and \textsf{innerstyle} could do with |
803 | % improvement. |
804 | % |
805 | % \begin{macrocode} |
806 | \def\@frac@del#1#2{\def\@wd{withdelims}\@tempswatrue\def#1{#2}} |
807 | \mkdef{mdwmath:frac}{leftdelim}{\@frac@del\@ldel{#1}} |
808 | \mkdef{mdwmath:frac}{rightdelim}{\@frac@del\@rdel{#1}} |
809 | \mkdef{mdwmath:frac}{nodelims}*{\let\@wd\@empty\@tempswafalse} |
810 | \mkdef{mdwmath:frac}{line}{% |
811 | \def\@op{above}\setlength\dimen@{#1}\edef\@dim{\the\dimen@\space}% |
812 | } |
813 | \mkdef{mdwmath:frac}{line}*{\def\@op{over}\let\@dim\@empty} |
814 | \mkdef{mdwmath:frac}{noline}*{\def\@op{atop}\let\@dim\@empty} |
815 | \def\@frac@style#1#2{% |
816 | \ifx\q@delim#2\q@delim\let#1\@empty% |
817 | \else% |
818 | \expandafter\ifx\csname #2style\endcsname\relax% |
819 | \PackageError{mdwmath}{Bad maths style `#2'}\@ehc% |
820 | \else% |
821 | \edef#1{\csname#2style\endcsname}% |
822 | \fi% |
823 | \fi% |
824 | } |
825 | \mkdef{mdwmath:frac}{style}[]{\@frac@style\@os{#1}} |
826 | \mkdef{mdwmath:frac}{innerstyle}[]{\@frac@style\@is{#1}} |
827 | % \end{macrocode} |
828 | % |
829 | % \end{macro} |
830 | % |
831 | % \begin{macro}{\fracdef} |
832 | % |
833 | % Here's where the rest of the pain is. We do a preliminary parse of the |
834 | % parameters and `compile' the result into the output macro. If there's no |
835 | % optional argument, then we don't need to do any really tedious formatting |
836 | % at the point of use. |
837 | % |
838 | % \begin{macrocode} |
839 | \def\fracdef#1#2{\@frac@parse{\fracdef@i{#1}{#2}}{#2}} |
840 | \def\fracdef@i#1#2#3#4#5{\def#1{\@frac@do{#2}{#3}{#4}{#5}}} |
841 | \def\@frac@do#1#2#3#4{% |
842 | \@ifnextchar[{\@frac@complex{#1}}{\@frac@simple{#2}{#3}{#4}}% |
843 | } |
844 | \def\@frac@complex#1[#2]{\@frac@parse\@frac@simple{#1,#2}} |
845 | \def\@frac@simple#1#2#3#4#5{{#2{{#3#4}#1{#3#5}}}} |
846 | % \end{macrocode} |
847 | % |
848 | % \end{macro} |
849 | % |
850 | % \begin{macro}{\frac@fix} |
851 | % \begin{macro}{\@@over} |
852 | % \begin{macro}{\@@atop} |
853 | % \begin{macro}{\@@above} |
854 | % \begin{macro}{\@@overwithdelims} |
855 | % \begin{macro}{\@@atopwithdelims} |
856 | % \begin{macro}{\@@abovewithdelims} |
857 | % |
858 | % Finally, we need to fix up |\@@over| and friends. Maybe \package{amsmath} |
859 | % has hidden the commands away somewhere unhelpful. If not, we make the |
860 | % requisite copies. |
861 | % |
862 | % \begin{macrocode} |
863 | \def\q@delim{\q@delim} |
864 | \def\frac@fix#1{\expandafter\frac@fix@i\string#1\q@delim} |
865 | \def\frac@fix@i#1#2\q@delim{\frac@fix@ii{#2}\frac@fix@ii{#2withdelims}} |
866 | \def\frac@fix@ii#1{% |
867 | \expandafter\ifx\csname @@#1\endcsname\relax% |
868 | \expandafter\let\csname @@#1\expandafter\endcsname\csname#1\endcsname% |
869 | \fi% |
870 | } |
871 | \frac@fix\over \frac@fix\atop \frac@fix\above |
872 | % \end{macrocode} |
873 | % |
874 | % \end{macro} |
875 | % \end{macro} |
876 | % \end{macro} |
877 | % \end{macro} |
878 | % \end{macro} |
879 | % \end{macro} |
880 | % \end{macro} |
881 | % |
882 | % \begin{macro}{\frac} |
883 | % \begin{macro}{\binom} |
884 | % \begin{macro}{\jacobi} |
885 | % |
886 | % And finally, we define the fraction-making commands. |
887 | % |
888 | % \begin{macrocode} |
889 | \fracdef\frac{nodelims, line} |
890 | \fracdef\binom{leftdelim = (, rightdelim = ), noline} |
891 | \fracdef\jacobi{leftdelim = (, rightdelim = ), line} |
892 | % \end{macrocode} |
893 | % |
894 | % \end{macro} |
895 | % \end{macro} |
896 | % \end{macro} |
86f6a31e |
897 | % |
898 | % \subsection{Blackboard bold stuff} |
899 | % |
900 | % \begin{macro}{\Z} |
901 | % \begin{macro}{\Q} |
902 | % \begin{macro}{\R} |
903 | % \begin{macro}{\C} |
904 | % \begin{macro}{\N} |
905 | % \begin{macro}{\F} |
906 | % \begin{macro}{\powerset} |
4a655c6f |
907 | % \begin{macro}{\gf} |
86f6a31e |
908 | % |
909 | % First of all, the signs. |
910 | % |
911 | % \begin{macrocode} |
912 | \def\Z{\mathbb{Z}} |
913 | \def\Q{\mathbb{Q}} |
914 | \def\R{\mathbb{R}} |
915 | \def\C{\mathbb{C}} |
916 | \def\N{\mathbb{N}} |
917 | \def\F{\mathbb{F}} |
918 | \def\powerset{\mathbb{P}} |
4a655c6f |
919 | \def\gf#1{\F_{#1}} |
920 | %\def\gf#1{\mathrm{GF}({#1})} |
86f6a31e |
921 | % \end{macrocode} |
922 | % |
923 | % \end{macro} |
924 | % \end{macro} |
925 | % \end{macro} |
926 | % \end{macro} |
927 | % \end{macro} |
928 | % \end{macro} |
929 | % \end{macro} |
4a655c6f |
930 | % \end{macro} |
86f6a31e |
931 | % |
932 | % And now, define |\mathbb| if it's not there already. |
933 | % |
934 | % \begin{macrocode} |
935 | \AtBeginDocument{\ifx\mathbb\@@undefined\let\mathbb\mathbf\fi} |
936 | % \end{macrocode} |
937 | % |
938 | % \subsection{Biggles} |
939 | % |
940 | % Now for some user-controlled delimiter sizing. The standard bigness of |
941 | % plain \TeX's delimiters are all right, but it's a little limiting. |
942 | % |
943 | % The biggness of delimiters is based on the size of the current |\strut|, |
944 | % which \LaTeX\ keeps up to date all the time. This will make the various |
945 | % delimiters grow in proportion when the text gets bigger. Actually, I'm |
946 | % not sure that this is exactly right -- maybe it should be nonlinear, |
947 | % |
948 | % \begin{macro}{\bbigg} |
949 | % \begin{macro}{\bbiggl} |
950 | % \begin{macro}{\bbiggr} |
951 | % \begin{macro}{\bbiggm} |
952 | % |
953 | % This is where the bigness is done. This is more similar to the plain \TeX\ |
954 | % big delimiter stuff than to the \package{amsmath} stuff, although there's |
955 | % not really a lot of difference. |
956 | % |
957 | % The two arguments are a multiplier for the delimiter size, and a small |
958 | % increment applied \emph{before} the multiplication (which is optional). |
959 | % |
960 | % This is actually a front for a low-level interface which can be called |
961 | % directly for efficiency. |
962 | % |
963 | % \begin{macrocode} |
964 | \def\bbigg{\@bbigg\mathord} \def\bbiggl{\@bbigg\mathopen} |
965 | \def\bbiggr{\@bbigg\mathclose} \def\bbiggm{\@bbigg\mathrel} |
966 | % \end{macrocode} |
967 | % |
968 | % \end{macro} |
969 | % \end{macro} |
970 | % \end{macro} |
971 | % \end{macro} |
972 | % |
973 | % \begin{macro}{\@bbigg} |
974 | % |
975 | % This is an optional argument parser providing a front end for the main |
976 | % macro |\bbigg@|. |
977 | % |
978 | % \begin{macrocode} |
979 | \def\@bbigg#1{\@ifnextchar[{\@bigg@i{#1}}{\@bigg@i{#1}[\z@]}} |
980 | \def\@bigg@i#1[#2]#3#4{#1{\bbigg@{#2}{#3}{#4}}} |
981 | % \end{macrocode} |
982 | % |
983 | % \end{macro} |
984 | % |
985 | % \begin{macro}{\bbigg@} |
986 | % |
987 | % This is it, at last. The arguments are as described above: an addition |
988 | % to be made to the strut height, and a multiplier. Oh, and the delimiter, |
989 | % of course. |
990 | % |
991 | % This is a bit messy. The smallest `big' delimiter, |\big|, is the same |
992 | % height as the current strut box. Other delimiters are~$1\frac12$, $2$ |
993 | % and~$2\frac12$ times this height. I'll set the height of the delimiter by |
994 | % putting in a |\vcenter| of the appropriate size. |
995 | % |
996 | % Given an extra height~$x$, a multiplication factor~$f$ and a strut |
997 | % height~$h$ and depth~$d$, I'll create a vcenter with total height |
998 | % $f(h+d+x)$. Easy, isn't it? |
999 | % |
1000 | % \begin{macrocode} |
1001 | \def\bbigg@#1#2#3{% |
1002 | {\hbox{$% |
1003 | \dimen@\ht\strutbox\advance\dimen@\dp\strutbox% |
1004 | \advance\dimen@#1% |
1005 | \dimen@#2\dimen@% |
1006 | \left#3\vcenter to\dimen@{}\right.\n@space% |
1007 | $}}% |
1008 | } |
1009 | % \end{macrocode} |
1010 | % |
1011 | % \end{macro} |
1012 | % |
1013 | % \begin{macro}{\big} |
1014 | % \begin{macro}{\Big} |
1015 | % \begin{macro}{\bigg} |
1016 | % \begin{macro}{\Bigg} |
1017 | % |
1018 | % Now for the easy macros. |
1019 | % |
1020 | % \begin{macrocode} |
1021 | \def\big{\bbigg@\z@\@ne} |
1022 | \def\Big{\bbigg@\z@{1.5}} |
1023 | \def\bigg{\bbigg@\z@\tw@} |
1024 | \def\Bigg{\bbigg@\z@{2.5}} |
1025 | % \end{macrocode} |
1026 | % |
1027 | % \end{macro} |
1028 | % \end{macro} |
1029 | % \end{macro} |
1030 | % \end{macro} |
1031 | % |
1032 | % \subsection{The `QED' symbol} |
1033 | % |
1034 | % \begin{macro}{\qed} |
1035 | % \begin{macro}{\qedrule} |
1036 | % \begin{macro}{\qedsymbol} |
1037 | % |
1038 | % This is fairly simple. Just be careful will the glue and penalties. The |
1039 | % size of the little box is based on the current font size. |
1040 | % |
1041 | % The horizontal list constructed by the macro is like this: |
1042 | % |
1043 | % \begin{itemize} |
1044 | % \item A |\quad| of space. This might get eaten if there's a break here or |
1045 | % before. That's OK, though. |
1046 | % \item An empty box, to break a run of discardable items. |
1047 | % \item A |\penalty 10000| to ensure that the spacing glue isn't discarded. |
1048 | % \item |\hfill| glue to push the little rule to the end of the line. |
1049 | % \item A little square rule `\qedrule', with some small kerns around it. |
1050 | % \item A glue item to counter the effect of glue added at the paragraph |
1051 | % boundary. |
1052 | % \end{itemize} |
1053 | % |
4a655c6f |
1054 | % The vertical mode case is simpler, but less universal. It copes with |
1055 | % relatively simple cases only. |
1056 | % |
86f6a31e |
1057 | % A |\qed| commend ends the paragraph. |
1058 | % |
1059 | % \begin{macrocode} |
4a655c6f |
1060 | \def\qed{% |
1061 | \ifvmode% |
1062 | \unskip% |
1063 | \setbox\z@\hb@xt@\linewidth{\hfil\strut\qedsymbol}% |
1064 | \prevdepth-\@m\p@% |
1065 | \ifdim\prevdepth>\dp\strutbox% |
1066 | \dimen@\prevdepth\advance\dimen@-\dp\strutbox% |
1067 | \kern-\dimen@% |
1068 | \fi% |
1069 | \penalty\@M\vskip-\baselineskip\box\z@% |
1070 | \else% |
1071 | \unskip% |
1072 | \penalty\@M\hfill% |
1073 | \hbox{}\penalty200\quad% |
1074 | \hbox{}\penalty\@M\hfill\qedsymbol\hskip-\parfillskip\par% |
1075 | \fi% |
86f6a31e |
1076 | } |
1077 | \def\qedrule{{% |
1078 | \dimen@\ht\strutbox% |
4a655c6f |
1079 | \advance\dimen@\dp\strutbox% |
86f6a31e |
1080 | \dimen@ii1ex% |
1081 | \advance\dimen@-\dimen@ii% |
1082 | \divide\dimen@\tw@% |
1083 | \advance\dimen@-\dp\strutbox% |
1084 | \advance\dimen@\dimen@ii% |
1085 | \advance\dimen@ii-\dimen@% |
1086 | \kern\p@% |
1087 | \vrule\@width1ex\@height\dimen@\@depth\dimen@ii% |
1088 | \kern\p@% |
1089 | }} |
1090 | \providecommand\qedsymbol{\qedrule} |
1091 | % \end{macrocode} |
1092 | % |
1093 | % \end{macro} |
1094 | % \end{macro} |
1095 | % \end{macro} |
1096 | % |
1097 | % \begin{ignore} |
1098 | % The following is the original definition of the enhanced eqnarray |
1099 | % environment. It's not supported, although if you can figure out how to |
1100 | % extract it, it's all yours. |
1101 | % \end{ignore} |
1102 | % |
1103 | % \begin{old-eqnarray} |
1104 | % |
1105 | % \subsection{The sparkly new \env{eqnarray}} |
1106 | % |
1107 | % Start off by writing a different package. |
1108 | % |
1109 | % \begin{macrocode} |
1110 | %</package> |
1111 | %<*oldeqnarray> |
1112 | % \end{macrocode} |
1113 | % |
1114 | % \subsubsection{Options handling} |
1115 | % |
1116 | % We need to be able to cope with \textsf{fleqn} and \textsf{leqno} options. |
1117 | % This will adjust our magic modified \env{eqnarray} environment |
1118 | % appropriately. |
1119 | % |
1120 | % \begin{macrocode} |
1121 | \newif\if@fleqn |
1122 | \newif\if@leqno |
1123 | \DeclareOption{fleqn}{\@fleqntrue} |
1124 | \DeclareOption{leqno}{\@leqnotrue} |
1125 | \ProcessOptions |
1126 | % \end{macrocode} |
1127 | % |
1128 | % This is all really different to the \LaTeX\ version. I've looked at the |
1129 | % various \env{tabular} implementations, the original \env{eqnarray} and the |
1130 | % \textit{\TeX book} to see how best to do this, and then went my own way. |
1131 | % If it doesn't work it's all my fault. |
1132 | % |
1133 | % \subsubsection{Some useful registers} |
1134 | % |
1135 | % The old \LaTeX\ version puts the equation numbers in by keeping a count of |
1136 | % where it is in the alignment. Since I don't know how may columns there are |
1137 | % going to be, I'll just use a switch in the preamble to tell me to stop |
1138 | % tabbing. |
1139 | % |
1140 | % \begin{macrocode} |
1141 | \newif\if@eqalast |
1142 | % \end{macrocode} |
1143 | % |
1144 | % Now define some useful length parameters. First allocate them: |
1145 | % |
1146 | % \begin{macrocode} |
1147 | \newskip\eqaopenskip |
1148 | \newskip\eqacloseskip |
1149 | \newskip\eqacolskip |
1150 | \newskip\eqainskip |
1151 | % \end{macrocode} |
1152 | % |
1153 | % Now assign some default values. Users can play with these if they really |
1154 | % want although I can't see the point myself. |
1155 | % |
1156 | % \begin{macrocode} |
1157 | \if@fleqn |
1158 | \AtBeginDocument{\eqaopenskip\leftmargini} |
1159 | \else |
1160 | \eqaopenskip\@centering |
1161 | \fi |
1162 | \eqacloseskip\@centering |
1163 | \eqacolskip\@centering |
1164 | \eqainskip\z@ |
1165 | % \end{macrocode} |
1166 | % |
1167 | % We allow the user to play with the style if this is really wanted. I dunno |
1168 | % why, really. Maybe someone wants very small alignments. |
1169 | % |
1170 | % \begin{macrocode} |
1171 | \let\eqa@style\displaystyle |
1172 | % \end{macrocode} |
1173 | % |
1174 | % \subsubsection{The main environments} |
1175 | % |
1176 | % We define the toplevel commands here. They just add in default arguments |
1177 | % and then call |\@eqnarray| with a preamble string. The only difference is |
1178 | % the last column they add in -- \env{eqnarray$*$} throws away the last |
1179 | % column by sticking it in box~0. (I used to |\@gobble| it but that caused |
1180 | % the |\cr| to be lost.) |
1181 | % |
1182 | % \begin{macrocode} |
1183 | \def\eqnarray{\@ifnextchar[\eqnarray@i{\eqnarray@i[rcl]}} |
1184 | \def\eqnarray@i[#1]{% |
1185 | \@eqnarray{#1!{\hb@xt@\z@{\hss##}\tabskip\z@}} |
1186 | } |
1187 | \@namedef{eqnarray*}{\@ifnextchar[\eqnarray@s@i{\eqnarray@s@i[rcl]}} |
1188 | \def\eqnarray@s@i[#1]{% |
1189 | \@eqnarray{#1!{\nonumber\setbox\z@\hbox{##}\tabskip\z@}}% |
1190 | } |
1191 | % \end{macrocode} |
1192 | % |
1193 | % \subsubsection{Set up the initial display} |
1194 | % |
1195 | % \begin{macro}{\@eqnarray} |
1196 | % |
1197 | % The |\@eqnarray| command does most of the initial work. It sets up some |
1198 | % flags and things, builds the |\halign| preamble, and returns. |
1199 | % |
1200 | % \begin{macrocode} |
1201 | \def\@eqnarray#1{% |
1202 | % \end{macrocode} |
1203 | % |
1204 | % Start playing with the counter here. The original does some icky internal |
1205 | % playing, which isn't necessary. The |\if@eqnsw| switch is |true| if the |
1206 | % user hasn't supplied an equation number. The |\if@eqalast| switch is |
1207 | % |true| in the final equation-number column. |
1208 | % |
1209 | % \begin{macrocode} |
1210 | \refstepcounter{equation}% |
1211 | \@eqalastfalse% |
1212 | \global\@eqnswtrue% |
1213 | \m@th% |
1214 | % \end{macrocode} |
1215 | % |
1216 | % Set things up for the |\halign| which is coming up. |
1217 | % |
1218 | % \begin{macrocode} |
1219 | \openup\jot% |
1220 | \tabskip\eqaopenskip% |
1221 | \let\\\@eqncr% |
1222 | \everycr{}% |
1223 | $$% |
1224 | % \end{macrocode} |
1225 | % |
1226 | % We'll build the real |\halign| and preamble in a token register. All we |
1227 | % need to do is stuff the header in the token register, clear a switch |
1228 | % (that'll be explained later), parse the preamble and then expand the |
1229 | % tokens we collected. Easy, no? |
1230 | % |
1231 | % \begin{macrocode} |
1232 | \toks@{\halign to\displaywidth\bgroup}% |
1233 | \@tempswafalse% |
1234 | \eqa@preamble#1\end% |
1235 | \the\toks@\cr% |
1236 | } |
1237 | % \end{macrocode} |
1238 | % |
1239 | % \end{macro} |
1240 | % |
1241 | % \subsubsection{Parsing the preamble} |
1242 | % |
1243 | % All this actually involves is reading the next character and building a |
1244 | % command from it. That can pull off an argument if it needs it. Just make |
1245 | % sure we don't fall off the end and we'll be OK. |
1246 | % |
1247 | % \begin{macrocode} |
1248 | \def\eqa@preamble#1{% |
1249 | \ifx\end#1\else\csname eqa@char@#1\expandafter\endcsname\fi% |
1250 | } |
1251 | % \end{macrocode} |
1252 | % |
1253 | % Adding stuff to the preamble tokens is a simple matter of using |
1254 | % |\expandafter| in the correct way.\footnote{^^A |
1255 | % I have no idea why \LaTeX\ uses \cmd\edef\ for building its preamble. It |
1256 | % seems utterly insane to me -- the amount of bodgery that \env{tabular} |
1257 | % has to go through to make everything expand at the appropriate times is |
1258 | % scary. Maybe Messrs~Lamport and Mittelbach just forgot about token |
1259 | % registers when they were writing the code. Maybe I ought to rewrite the |
1260 | % thing properly some time. Sigh. |
1261 | % |
1262 | % As a sort of postscript to the above, I \emph{have} rewritten the |
1263 | % \env{tabular} environment, and made a damned fine job of it, in my |
1264 | % oh-so-humble opinion. All this \env{eqnarray} stuff has been remoulded |
1265 | % in terms of the generic column-defining things in \package{mdwtab}. |
1266 | % You're reading the documentation of the old version, which isn't |
1267 | % supported any more, so any bugs here are your own problem.} |
1268 | % |
1269 | % \begin{macrocode} |
1270 | \def\eqa@addraw#1{\expandafter\toks@\expandafter{\the\toks@#1}} |
1271 | % \end{macrocode} |
1272 | % |
1273 | % Now for some cleverness again. In order to put all the right bits of |
1274 | % |\tabskip| glue in the right places we must \emph{not} terminate each |
1275 | % column until we know what the next one is. We set |\if@tempswa| to be |
1276 | % |true| if there's a column waiting to be closed (so it's initially |
1277 | % |false|). The following macro adds a column correctly, assuming we're in |
1278 | % a formula. Other column types make their own arrangements. |
1279 | % |
1280 | % \begin{macrocode} |
1281 | \def\eqa@add#1{% |
1282 | \if@tempswa% |
1283 | \eqa@addraw{\tabskip\eqainskip}% |
1284 | \else% |
1285 | \eqa@addraw{#1}% |
1286 | \fi% |
1287 | \@tempswatrue% |
1288 | } |
1289 | % \end{macrocode} |
1290 | % |
1291 | % Now to defining column types. Let's define a macro which allows us to |
1292 | % define column types: |
1293 | % |
1294 | % \begin{macrocode} |
1295 | \def\eqa@def#1{\expandafter\def\csname eqa@char@#1\endcsname} |
1296 | % \end{macrocode} |
1297 | % |
1298 | % Now we can define the column types. Each column type must loop back to |
1299 | % |\eqa@preamble| once it's finished, to read the rest of the preamble |
1300 | % string. Note the positioning of ord atoms in the stuff below. This will |
1301 | % space out relations and binops correctly when they occur at the edges of |
1302 | % columns, and won't affect ord atoms at the edges, because ords pack |
1303 | % closely. |
1304 | % |
1305 | % First the easy onces. Just stick |\hfil| in the right places and |
1306 | % everything will be all right. |
1307 | % |
1308 | % \begin{macrocode} |
1309 | \eqa@def r{\eqa@add{\hfil$\eqa@style##{}$}\eqa@preamble} |
1310 | \eqa@def c{\eqa@add{\hfil$\eqa@style{}##{}$\hfil}\eqa@preamble} |
1311 | \eqa@def l{\eqa@add{$\eqa@style{}##$\hfil}\eqa@preamble} |
1312 | \eqa@def x{\eqa@add{\hfil$\eqa@style##$\hfil}\eqa@preamble} |
1313 | % \end{macrocode} |
1314 | % |
1315 | % Now for the textual ones. This is also fairly easy. |
1316 | % |
1317 | % \begin{macrocode} |
1318 | \eqa@def T#1{% |
1319 | \eqa@add{}% |
1320 | \if#1l\else\eqa@addraw{\hfil}\fi% |
1321 | \eqa@addraw{##}% |
1322 | \if#1r\else\eqa@addraw{\hfil}\fi% |
1323 | \eqa@preamble% |
1324 | } |
1325 | % \end{macrocode} |
1326 | % |
1327 | % Sort of split types of equations. I mustn't use |\rlap| here, or |
1328 | % everything goes wrong -- |\\| doesn't get noticed by \TeX\ in the same way |
1329 | % as |\cr| does. |
1330 | % |
1331 | % \begin{macrocode} |
1332 | \eqa@def L{\eqa@add{\hb@xt@\z@{$\eqa@style##$\hss}\qquad}\eqa@preamble} |
1333 | % \end{macrocode} |
1334 | % |
1335 | % The \lit{:} column type is fairly simple. We set |\tabskip| up to make |
1336 | % lots of space and close the current column, because there must be one.^^A |
1337 | % \footnote{This is an assumption.} |
1338 | % |
1339 | % \begin{macrocode} |
1340 | \eqa@def :{% |
1341 | \eqa@addraw{\tabskip\eqacolskip&}\@tempswafalse\eqa@preamble% |
1342 | } |
1343 | \eqa@def q{\eqa@add{\quad}\@tempswafalse\eqa@preamble} |
1344 | % \end{macrocode} |
1345 | % |
1346 | % The other column types just insert given text in an appropriate way. |
1347 | % |
1348 | % \begin{macrocode} |
1349 | \eqa@def >#1{\eqa@add{#1}\@tempswafalse\eqa@preamble} |
1350 | \eqa@def <#1{\eqa@addraw{#1}\eqa@preamble} |
1351 | % \end{macrocode} |
1352 | % |
1353 | % Finally, the magical \lit{!} column type, which sets the equation number. |
1354 | % We set up the |\tabskip| glue properly, tab on, and set the flag which |
1355 | % marks the final column. |
1356 | % |
1357 | % \begin{macrocode} |
1358 | \eqa@def !#1{% |
1359 | \eqa@addraw{\tabskip\eqacloseskip&\@eqalasttrue#1}\eqa@preamble% |
1360 | } |
1361 | % \end{macrocode} |
1362 | % |
1363 | % \subsubsection{Newline codes} |
1364 | % |
1365 | % Newline sequences (|\\|) get turned into calls of |\@eqncr|. The job is |
1366 | % fairly simple, really. However, to avoid reading `|&|' characters |
1367 | % prematurely, we set up a magic brace (from the \package{array} package -- |
1368 | % this avoids creating ord atoms and other nastyness). |
1369 | % |
1370 | % \begin{macrocode} |
1371 | \def\@eqncr{% |
1372 | \iffalse{\fi\ifnum0=`}\fi% |
1373 | \@ifstar{\eqacr@i{\@M}}{\eqacr@i{\interdisplaylinepenalty}}% |
1374 | } |
1375 | \def\eqacr@i#1{\@ifnextchar[{\eqacr@ii{#1}}{\eqacr@ii{#1}[\z@]}} |
1376 | \def\eqacr@ii#1[#2]{% |
1377 | \ifnum0=`{}\fi% |
1378 | \eqa@eqnum% |
1379 | \noalign{\penalty#1\vskip#2\relax}% |
1380 | } |
1381 | % \end{macrocode} |
1382 | % |
1383 | % \subsubsection{Setting equation numbers} |
1384 | % |
1385 | % Before we start, we need to generalise the flush-left number handling bits. |
1386 | % The macro |\eqa@eqpos| will put its argument in the right place. |
1387 | % |
1388 | % \begin{macrocode} |
1389 | \if@leqno |
1390 | \def\eqa@eqpos#1{% |
1391 | \hb@xt@.01\p@{}\rlap{\normalfont\normalcolor\hskip-\displaywidth#1}% |
1392 | } |
1393 | \else |
1394 | \def\eqa@eqpos#1{\normalfont\normalcolor#1} |
1395 | \fi |
1396 | % \end{macrocode} |
1397 | % |
1398 | % First we need to move into the right column. Then we just set the equation |
1399 | % number appropriately. There is some subtlety here, ish. The |\relax| is |
1400 | % important, to delay expansion of the |\if|\dots\ until the new column has |
1401 | % been started. The two helper macros are important too, to hide `|&|'s and |
1402 | % `|\cr|'s from \TeX's scanner until the right time. |
1403 | % |
1404 | % \begin{macrocode} |
1405 | \def\eqa@eqnum{% |
1406 | \relax% |
1407 | \if@eqalast\expandafter\eqa@eqnum@i\else\expandafter\eqa@eqnum@ii\fi% |
1408 | } |
1409 | \def\eqa@eqnum@i{% |
1410 | \if@eqnsw% |
1411 | \eqa@eqpos{(\theequation)}\stepcounter{equation}% |
1412 | \else% |
1413 | \eqa@eqpos\eqa@number% |
1414 | \fi% |
1415 | \global\@eqnswtrue% |
1416 | \cr% |
1417 | } |
1418 | \def\eqa@eqnum@ii{&\eqa@eqnum} |
1419 | % \end{macrocode} |
1420 | % |
1421 | % \subsubsection{Numbering control} |
1422 | % |
1423 | % This is trivial. We set the |\if@eqnsw| flag to be |false| and store the |
1424 | % text in a macro. |
1425 | % |
1426 | % \begin{macrocode} |
1427 | \let\nonumber\relax |
1428 | \newcommand\nonumber[1][]{\global\@eqnswfalse\global\def\eqa@number{#1}} |
1429 | % \end{macrocode} |
1430 | % |
1431 | % \subsubsection{Closing the environments off} |
1432 | % |
1433 | % This is really easy. Set the final equation number, close the |\halign|, |
1434 | % tidy up the equation counter (it's been stepped once too many times) and |
1435 | % close the display. |
1436 | % |
1437 | % \begin{macrocode} |
1438 | \def\endeqnarray{% |
1439 | \eqa@eqnum% |
1440 | \egroup% |
1441 | \global\advance\c@equation\m@ne% |
1442 | $$% |
1443 | \global\@ignoretrue% |
1444 | } |
1445 | \expandafter\let\csname endeqnarray*\endcsname\endeqnarray |
1446 | % \end{macrocode} |
1447 | % |
1448 | % Now start up the other package again. |
1449 | % |
1450 | % \begin{macrocode} |
1451 | %</oldeqnarray> |
1452 | %<*package> |
1453 | % \end{macrocode} |
1454 | % |
1455 | % \end{old-eqnarray} |
1456 | % |
1457 | % That's all there is. Byebye. |
1458 | % |
1459 | % \begin{macrocode} |
1460 | %</package> |
1461 | % \end{macrocode} |
1462 | % |
1463 | % \hfill Mark Wooding, \today |
1464 | % |
1465 | % \Finale |
1466 | \endinput |