[Tex/LaTex] File ended while scanning the use of \frac

errorssyntax

I'm sure I made a mistake here somewhere, which didn't allow me to compile the PDF file in order to see what I'm doing. Sure enough, I've been looking at the \frac, trying to catch some rule violation, but there seems to be none! If you wish to contribute to make this equation beautiful, that helps too!

\begin{IEEEeqnarray}{rCl}
\label{key}
E_{k,k}&=&\frac{1}{2}\left[\mathcal{B}_{x}^{\left(e\right)}
    +\mathcal{B}_{y}^{\left(e\right)}\right]J\left(J+1\right)
    +\left(\mathcal{B}_{z}^{\left(e\right)}-\frac{1}{2}
  \left[\mathcal{B}_{x}^{\left(e\right)}
       +\mathcal{B}_{y}^{\left(e\right)}\right]\right)\kappa^{2}  \\
E_{k\pm2,k}&=&\frac{1}{4}[\mathcal{B}_{x}^{(e)}-\mathcal{B}_{y}^{(e)}]
    {[J(J+1)-k(k\pm1)]\times[J(J+1)-k(k\pm1)(k\pm2)]}^{\frac{1}{2}}
\end{IEEEeqnarray}

Best Answer

I am unable to generate the error message you say you're getting. I would like to suggest, though, that you rewrite some of the code to use \left and \right much more sparingly than you do at present. If you compare the LaTeX codes for the first and second groups of equations, you will hopefully agree that the second group's code is much simpler and easier to read.

A separate comment: The IEEEeqnarray environment is extremely powerful and flexible. However, at present you don't really seem to be making use of the package's machinery. You may therefore wish to look into making use of the simpler align environment, which is provided by the amsmath package. As the second and third groups of equations in the following screenshot demonstrate, the output is identical -- though, arguably, the syntax of the align environment is simpler.

enter image description here

\documentclass{article}  
\usepackage{IEEEtrantools} % for 'IEEEeqnarray' env.
\usepackage{geometry,amsmath}
\begin{document}

OP's original form
\begin{IEEEeqnarray}{rCl}\label{key1}
E_{k,k}&=&\frac{1}{2}\left[\mathcal{B}_{x}^{\left(e\right)}+
    \mathcal{B}_{y}^{\left(e\right)}\right]J\left(J+1\right)+
    \left(\mathcal{B}_{z}^{\left(e\right)}-\frac{1}{2}
    \left[\mathcal{B}_{x}^{\left(e\right)}+\mathcal{B}_{y}^{\left(e\right)}
    \right]\right)\kappa^{2}  \\
E_{k\pm2,k}&=&\frac{1}{4}[\mathcal{B}_{x}^{(e)}-\mathcal{B}_{y}^{(e)}]
    {[J(J+1)-k(k\pm1)]\times[J(J+1)-k(k\pm1)(k\pm2)]}^{\frac{1}{2}}
\end{IEEEeqnarray}

\bigskip
Suggested edits
\begin{IEEEeqnarray}{rCl}\label{key2}
E_{k,k}&=& \tfrac{1}{2}
    [\mathcal{B}_{x}^{(e)}+\mathcal{B}_{y}^{(e)}]J(J+1)
    +\bigl( \mathcal{B}_{z}^{(e)} -\tfrac{1}{2}
    [\mathcal{B}_{x}^{(e)}+\mathcal{B}_{y}^{(e)}]
    \bigr)\kappa^{2}  \\
E_{k\pm2,k}&=& \tfrac{1}{4}
    [\mathcal{B}_{x}^{(e)}-\mathcal{B}_{y}^{(e)}]
    [J(J+1)-k(k\pm1)]\times
    \bigl[J(J+1)-k(k\pm1)(k\pm2)\bigr]^{1/2}
\end{IEEEeqnarray}

\bigskip
Solution that uses an \texttt{align} environment
\begin{align}\label{key3}
E_{k,k} &= \tfrac{1}{2}
    [\mathcal{B}_{x}^{(e)}+\mathcal{B}_{y}^{(e)}]J(J+1)
    +\bigl( \mathcal{B}_{z}^{(e)} -\tfrac{1}{2}
    [\mathcal{B}_{x}^{(e)}+\mathcal{B}_{y}^{(e)}]
    \bigr)\kappa^{2}  \\
E_{k\pm2,k} &= \tfrac{1}{4}
    [\mathcal{B}_{x}^{(e)}-\mathcal{B}_{y}^{(e)}]
    [J(J+1)-k(k\pm1)]\times
    \bigl[J(J+1)-k(k\pm1)(k\pm2)\bigr]^{1/2}
\end{align}
\end{document}
Related Question