[comp.text.tex] Problem with LaTeX eqnarray...

sullivan@msor.exeter.ac.uk (Rob Sullivan) (02/05/91)

I would be most grateful if someone could point out what is wrong with
the following LaTeX file. It appears to produce a TeX 'weird' error.
What should I do if I want aligned commutator brackets.

\documentstyle{article}
\begin{document}
text text text text
\begin{eqnarray}
[a,b]&=&0 \\
[a,b]&=&0
\end{eqnarray}
text text text
\end{document}
--
- - - -
Robert Sullivan           JANET    : sullivan@uk.ac.exeter.msor
Theoretical Physics Dept. UUCP     : sullivan%msor.exeter.ac.uk@ukc.uucp
University of Exeter      BITNET   : sullivan%msor.exeter.ac.uk@UKACRL
England.                  Internet : sullivan%msor.exeter.ac.uk@cunyvm.cuny.edu
EX4 4QL                   Tel      : +44 392 264198

"One must be open-minded --
 --but not so open-minded that one's brains fall out."

gvr@cs.brown.edu (George V. Reilly) (02/05/91)

In article <SULLIVAN.91Feb4162119@msor0.msor.exeter.ac.uk> sullivan@msor.exeter.ac.uk (Rob Sullivan) writes:
% I would be most grateful if someone could point out what is wrong with
% the following LaTeX file. It appears to produce a TeX 'weird' error.
% What should I do if I want aligned commutator brackets.
% 
% \documentstyle{article}
% \begin{document}
% text text text text
% \begin{eqnarray}
% [a,b]&=&0 \\
% [c,d]&=&0
% \end{eqnarray}
% text text text
% \end{document}

If you look at p. 151 of the LaTeX book, you'll see that \\ can take
an optional argument enclosed in [square brackets].  Either
enclose the [c,d] in braces
	[a,b]&=&0 \\
	{[c,d]}&=&0
or put an empty pair of braces after the \\
	[a,b]&=&0 \\{}
	[c,d]&=&0
________________
George V. Reilly   `InvisibleManiac'	gvr@cs.brown.edu   +1 (401) 863-7684
uunet!brunix!gvr   gvr@browncs.bitnet	Box 1910, Brown U, Prov, RI 02912

ogawa@orion.arc.nasa.gov (Arthur Ogawa) (02/05/91)

In article <SULLIVAN.91Feb4162119@msor0.msor.exeter.ac.uk> sullivan@msor.exeter.ac.uk (Rob Sullivan) writes:
>I would be most grateful if someone could point out what is wrong with
>the following LaTeX file. It appears to produce a TeX 'weird' error.
>
>\documentstyle{article}
>\begin{document}
>text text text text
>\begin{eqnarray}
>[a,b]&=&0 \\
>[a,b]&=&0
>\end{eqnarray}
>text text text
>\end{document}

Be careful: the \\ command at the end of each line in the eqnarray
will be looking for an optional argument of the form [<stuff>].
It's also looking for a preceding *. Rewrite your eqnarray's content:

\begin{eqnarray}
[a,b]&=&0 \\\relax
[a,b]&=&0
\end{eqnarray}

Note that the \relax command is probably only one of many ways to overcome
this problem, but it's the one I favor.

>What should I do if I want aligned commutator brackets.

The right bracket will be aligned as is. If you want the left brackets to 
align, too, you could do

\begin{equation}%
\everymath{\displaystyle}%
\begin{tabular}{l@{}r@{}l}
$[{aaa\over b},$&$b]$&${}=0$ \\\relax
$[a,$&$bbbb]$&${}=0$
\end{tabular}
\end{equation}

Explanation: We use an equation environment so we can continue to have 
numbered equations. Inside of the environment is a tabular environment,
whose features are used to accomplish the alignment (otherwise unavailable
in eqnarray). The first column is left justified (thus aligning the left
bracket) the second column is aligned on the right for the sake of the 
right bracket. In order to continue to set the material in math mode, 
each cell is surrounded with $s (you could use \(\) equally well). And,
in order to simulate display math, each cell is set in \displaystyle.

I know the above solution is not characterized by pretty markup, and that
you've lost the ability to apply an equation number to each line. The 
alternative is to change the definition of the eqnarray environment. I could
post this, if there is interest.