2 of 3
Corrected line break.
Werner
• 565k
• 118
• 1320
• 2163

# Modify eqnarray to match that of amsmath's align

This is a follow-up question to \eqnarray vs \align.

Sadly, some journals (and their accompanying document classes) still require the use of eqnarray to arrange a number of equations in a single block. What would be the easiest (and best) way to modify the eqnarray environment to match the output of align without having to modify the input regime. Something that produces the output of the second set of equations (in align) given the first set (in eqnarray):

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{eqnarray}
f(x) & = & ax^2 + bx + c \\
g(x) & = & dx^2 + ex + f
\end{eqnarray}

\setcounter{equation}{0}
\begin{align}
f(x) & = ax^2 + bx + c \\
g(x) & = dx^2 + ex + f
\end{align}
\end{document}

The idea is to provide a very minimal package that could be added to a document when it still uses eqnarray, without having to modify the code used for eqnarray.

My first attempt was to modify the setup within \eqnarray (from latex.ltx). Currently defined as

\def\eqnarray{%
\stepcounter{equation}%
\def\@currentlabel{\p@equation\theequation}%
\global\@eqnswtrue
\m@th
\global\@eqcnt\z@
\tabskip\@centering
\let\\\@eqncr
\everycr{}\halign to\displaywidth\bgroup \hskip\@centering\displaystyle\tabskip\z@skip{##}\@eqnsel &\global\@eqcnt\@ne\hskip \tw@\arraycolsep \hfil{##}\hfil &\global\@eqcnt\tw@ \hskip \tw@\arraycolsep \displaystyle{##}\hfil\tabskip\@centering &\global\@eqcnt\thr@@ \hb@xt@\z@\bgroup\hss##\egroup \tabskip\z@skip \cr } It's obvious that the three components of an equation are handled separately. Additionally, a horizontal skip of 2\arraycolsep is inserted around the middle component while also making that component equivalent to \mathord (wrapping it within {..}). A possible correction of this is therefore: \documentclass{article} \usepackage{amsmath}% http://ctan.org/pkg/amsmath \makeatletter \def\eqnarray{% \stepcounter{equation}% \def\@currentlabel{\p@equation\theequation}% \global\@eqnswtrue \m@th \global\@eqcnt\z@ \tabskip\@centering \let\\\@eqncr\everycr{}\halign to\displaywidth\bgroup
\hskip\@centering$\displaystyle\tabskip\z@skip{##}$\@eqnsel
&\global\@eqcnt\@ne${}##{}$% Removed horizontal skip + forced mathord
&\global\@eqcnt\tw@% Removed horizontal skip
$\displaystyle{##}$\hfil\tabskip\@centering
&\global\@eqcnt\thr@@ \hb@xt@\z@\bgroup\hss##\egroup
\tabskip\z@skip
\cr
}
\makeatother
\begin{document}
\begin{eqnarray}
f(x) & = & ax^2 + bx + c \\
g(x) & = & dx^2 + ex + f
\end{eqnarray}

\setcounter{equation}{0}
\begin{align}
f(x) & = ax^2 + bx + c \\
g(x) & = dx^2 + ex + f
\end{align}
\end{document}

What else?

Werner
• 565k
• 118
• 1320
• 2163