[Tex/LaTex] Nice display of proof steps without eqnarray

equationsmath-mode

This is a follow-up question to: Is eqnarray really obsolete?

The background is that I want to follow the general advice to avoid eqnarray. However, while working on old documents still containing eqnarray (here, my use case is working on the conference version of a paper when preparing an extended version for a journal), I encountered two situations in my previous question linked above where I did not find an obvious way to obtain an output that had at least the same quality as when using eqnarray but using different environments like align. For the first of these two situations (namely a sequence of proof steps where equations are successively applied to a term), one answer suggested to use array instead of eqnarray while the other answer suggested using a combination of align and \mathclap. However, here I have another problem when using either solution to replace the use of eqnarray. The following code contains 5 versions of the same sequence of proof steps, the first using eqnarray, the second and third using the first suggested solution from the previous question, and the fourth and fifth the second suggested solution from the previous question:

\documentclass{article}

\usepackage{array}
\usepackage{mathtools}

\begin{document}

\begin{eqnarray*}
f(x,y,z) & =                                   & \frac{g(x,y,z)}{h(x,y,z)}\\
& =                                   & \left\lfloor\frac{\frac{\frac{x}{z}}{y}+\frac{y}{z}}{\frac{z}{y} + \frac{y}{x}}\right\rfloor\\
& \stackrel{(\mathit{condition1})}{=} & \left\lfloor\frac{\frac{a}{b}+\frac{\frac{c}{a}}{b}}{\frac{c}{a} + \frac{b}{a}}\right\rfloor\\
& \stackrel{(\mathit{condition2})}{=} & 42
\end{eqnarray*}

{\renewcommand{\arraystretch}{1.5}
$\begin{array}{@{} r @{\;} >{{}} c <{{}} @{\;} l @{}} f(x,y,z) & = & \frac{g(x,y,z)}{h(x,y,z)}\\ & = & \left\lfloor\frac{\frac{\frac{x}{z}}{y}+\frac{y}{z}}{\frac{z}{y} + \frac{y}{x}}\right\rfloor\\ & \stackrel{(\mathit{condition1})}{=} & \left\lfloor\frac{\frac{a}{b}+\frac{\frac{c}{a}}{b}}{\frac{c}{a} + \frac{b}{a}}\right\rfloor\\ & \stackrel{(\mathit{condition2})}{=} & 42 \end{array}$
\renewcommand{\arraystretch}{1}}

{\renewcommand{\arraystretch}{2}
$\begin{array}{@{} r @{\;} >{{}} c <{{}} @{\;} l @{}} f(x,y,z) & = & \frac{g(x,y,z)}{h(x,y,z)}\\ & = & \left\lfloor\frac{\frac{\frac{x}{z}}{y}+\frac{y}{z}}{\frac{z}{y} + \frac{y}{x}}\right\rfloor\\ & \stackrel{(\mathit{condition1})}{=} & \left\lfloor\frac{\frac{a}{b}+\frac{\frac{c}{a}}{b}}{\frac{c}{a} + \frac{b}{a}}\right\rfloor\\ & \stackrel{(\mathit{condition2})}{=} & 42 \end{array}$
\renewcommand{\arraystretch}{1}}

\begingroup
\begin{align*}
f(x,y,z) & = \frac{g(x,y,z)}{h(x,y,z)}\\
& = \left\lfloor\frac{\frac{\frac{x}{z}}{y}+\frac{y}{z}}{\frac{z}{y} + \frac{y}{x}}\right\rfloor\\
& \stackrel{\mathclap{(\mathit{condition1})}}{=} \left\lfloor\frac{\frac{a}{b}+\frac{\frac{c}{a}}{b}}{\frac{c}{a} + \frac{b}{a}}\right\rfloor\\
& \stackrel{\mathclap{(\mathit{condition2})}}{=} 42
\end{align*}
\endgroup

\begingroup
\begin{align*}
f(x,y,z) & = \frac{g(x,y,z)}{h(x,y,z)}\\
& = \left\lfloor\frac{\frac{\frac{x}{z}}{y}+\frac{y}{z}}{\frac{z}{y} + \frac{y}{x}}\right\rfloor\\
& \stackrel{\mathclap{(\mathit{condition1})}}{=} \left\lfloor\frac{\frac{a}{b}+\frac{\frac{c}{a}}{b}}{\frac{c}{a} + \frac{b}{a}}\right\rfloor\\
& \stackrel{\mathclap{(\mathit{condition2})}}{=} 42
\end{align*}
\endgroup

$(\mathit{condition1})$ holds since the sky is red and $(\mathit{condition2})$ because this is the answer.

\end{document}


The output looks as follows:

• eqnarray:

• array:

• array with higher stretch factor:

• align:

• align with higher \thickmuskip:

The problems in this example are the following:

• The relation symbols used in each step may have a different horizontal length but should be aligned below each other in a centered way. Therefore, the usual AMS environments do not work in an obvious way since they only offer left- or right-aligned columns. The second solution tries to overcome this problem by using \mathclap, but then the space between the relation symbols and everything else must be adjusted manually (as seen in the last version).

• When using array, the vertical space between each line is "set" manually by adjusting the value of \arraystretch. While in the previous question a value of 1.5 was "the right" value, here the same value leads to overlapping lines. So with the first solution, the vertical space needs to be adjusted manually for each case separately.

• Another problem when using array is that the fractions seem to be compressed.

Is there a way to achieve an output of at least the quality of version 1 without the need to manually adjust values for different cases of such proof step sequences and without using eqnarray?

Sorry, eqnarray has so many limitations that even being forced to do some tricks has its advantages. For instance, eqnarray can never be broken across pages, whereas your proof steps might be so long that a page break could become necessary.

\documentclass{article}

\usepackage{mathtools}

\newcommand{\alignedrel}[2]{%
\Cen{2}{\overset{#1}{#2}{}}%
}
\makeatletter
\newcommand{\Cen}[2]{% see http://tex.stackexchange.com/a/209732/4427
\ifmeasuring@
#2%
\else
\makebox[\ifcase\expandafter #1\maxcolumn@widths\fi][c]{$\displaystyle#2$}%
\fi
}
\makeatother

\begin{document}

\begin{alignat*}{2}
f(x,y,z)
& \alignedrel{}{=}
&& \frac{g(x,y,z)}{h(x,y,z)}\\
& \alignedrel{}{=}
&& \left\lfloor\frac{\frac{\frac{x}{z}}{y}+\frac{y}{z}}{\frac{z}{y} + \frac{y}{x}}\right\rfloor\\
& \alignedrel{\text{(condition1)}}{=}
&& \left\lfloor\frac{\frac{a}{b}+\frac{\frac{c}{a}}{b}}{\frac{c}{a} + \frac{b}{a}}\right\rfloor\\
& \alignedrel{\text{(condition2)}}{=}
&& 42
\end{alignat*}

\end{document}