Nice display of proof steps without eqnarray

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?

• I honestly think there is very little need for placing content above the =. I think you can get an equally clear presentation (if not better, since the spacing is consistent) using this layout... – Werner Jan 18 '16 at 5:56
• @Werner True, but what if the whole thing needs all the space of the textwidth? The variant over the = symbols saves some space in such cases. – cryingshadow Jan 18 '16 at 5:58
• Then, instead of placing a "huge" (condition1) or (condition2) over =, I'll use (1) or (2) and describe that after the entire construction. – Werner Jan 18 '16 at 6:00
• @Werner, True again. But what happens if you have more than 10 such things? And don't tell me that the proof is too complicated if it needs more than 10 steps (which is probably also true but finding shorter and still clear proofs is definitely a very hard problem)... ;) – cryingshadow Jan 18 '16 at 6:02
• You will probably always find a "but..." based on a counter-suggestion... You seem to be convinced that eqnarray is still a hidden hero. Go for it then. – Werner Jan 18 '16 at 6:05

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}{%
\Cen{2}{\overset{#1}{#2}{}}%
}
\makeatletter
\newcommand{\Cen}{% 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} • The pagebreaks are a good point. However, this seems to be problematic with other environments as well. I found tex.stackexchange.com/questions/51682/… and it says pagebreaks are only possible with align and gather. Is alignat mandatory for your solution? Is there a way to break a page in alignat (maybe a follow-up question if the answer is not simply "no")? – cryingshadow Jan 18 '16 at 9:00
• I'd rather use \intertext{condition/explanation} as they become natual break points. In writing comments like this does not belon on top of relations etc. You might do this on a blackboard, but not in typeset text – daleif Jan 18 '16 at 9:02
• @cryingshadow Well, that comment didn't tell the full truth and is gone. Be happy: also alignat is breakable. My typographic choice would of course be setting the conditions on the side, not above the equals signs. – egreg Jan 18 '16 at 9:04

Rather than overburden some of the = symbols with too much information, I would recommend that you provide a normal-language sentence after the group of equations to explain, in words, why the final two equalities hold.

Oh, and I would definitely use an align* environment, not an eqnarray* environment. \documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor}
\begin{document}

\begin{align*}
f(x,y,z)
&= \frac{g(x,y,z)}{h(x,y,z)}\\
&= \floor*{\frac{\frac{x/z}{y}+\frac{y}{z}}{\frac{z}{y} + \frac{y}{x}}}\\
&= \floor*{\frac{\frac{a}{b}+\frac{c/a}{b}}{\frac{c}{a} + \frac{b}{a}}}\\
&= 42.
\end{align*}
The second-to-last equality follows because the sky is red (Condition~1), and the final equality holds because it is the answer (Condition~2).

\end{document}

Addendum to address the OP's follow-up comment: If you have relation symbols that have different widths, e.g., = and \hookrightarrow, you could still use an align environment, by reversing the order of the relation symbols and the & symbols, as is shown in the following example. (The {} particle are there to get the right amount of spacing.)

\begin{align*}
f(x,y,z)
={}& \frac{g(x,y,z)}{h(x,y,z)}\\
={}& \floor*{\frac{\frac{x/z}{y}+\frac{y}{z}}{\frac{z}{y} + \frac{y}{x}}}\\
\hookrightarrow{}& \floor*{\frac{\frac{a}{b}+\frac{c/a}{b}}{\frac{c}{a} + \frac{b}{a}}}\\
={}& 42.
\end{align*}
• Okay, then suppose that I have different relation symbols with a different width (e.g. \hookrightarrow and = - this is what happened in one of my real examples). I think your solution only works if I have relation symbols of equal width. Is that true? – cryingshadow Jan 18 '16 at 6:30
• Ah, never mind the \hookrightarrow one - that was only due to strange mode changes. In normal math mode, this would work. – cryingshadow Jan 18 '16 at 6:35
• @cryingshadow -- I've posted an addendum to my answer, to show how you might handle relation symbols of varying widths. – Mico Jan 18 '16 at 6:37
• So the "solution" is basically to avoid not only eqnarray but also \stackrel (at least in this combination). Since with \stackrel, your solution would probably have the same problems that I had in the previous question (true?). While I would still be interested in a solution that allows to use \stackrel, your answer at least allows me to work around my current issue (although that means tiny changes to the content). Thanks! – cryingshadow Jan 18 '16 at 6:44
• Ah, but here I have another mean one (I guess I had evil things in this paper...): What if I have something like =_D? Even with your addendum, this gets "shifted" a bit. – cryingshadow Jan 18 '16 at 6:49

some possibilities \documentclass{article}

\usepackage{array}
\usepackage{mathtools}
\newlength\mylength
\begin{document}

eqnarray
\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*}

array in display
{\setlength\extrarowheight{10pt}
$\begin{array}{@{} >\displaystyle r @{\;} >{\displaystyle{}} c <{{}} @{\;} >\displaystyle 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}}

align
\begingroup
\settowidth\mylength{$\scriptstyle(\mathit{condition2})$}
\newcommand\condeq{\stackrel{\makebox[\mylength]{$\scriptstyle#1$}}{=}}
\begin{align*}
f(x,y,z) & \condeq{} \frac{g(x,y,z)}{h(x,y,z)}\\
& \condeq{} \left\lfloor\frac{\frac{\frac{x}{z}}{y}+\frac{y}{z}}{\frac{z}{y} + \frac{y}{x}}\right\rfloor\\
& \condeq{(\mathit{condition1})} \left\lfloor\frac{\frac{a}{b}+\frac{\frac{c}{a}}{b}}{\frac{c}{a} + \frac{b}{a}}\right\rfloor\\
& \condeq{(\mathit{condition2})} 42
\end{align*}
\endgroup

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

\end{document}
• I would add a \scriptsize directive to the argument of \makebox, ie., write \newcommand\condeq{\stackrel{\makebox[6em]{\scriptsize$#1$}}{=}}. – Mico Jan 18 '16 at 8:03
• Would it be possible to "infer" the correct length for the \makebox instead of manually specifying it? – cryingshadow Jan 18 '16 at 8:13
• @cryingshadow answer updated – David Carlisle Jan 18 '16 at 9:03
• @Mico sorry missed your comment, was driving:-) In the update I did \scriptsyle... which is similar. – David Carlisle Jan 18 '16 at 9:04 • @cryingshadow in my head I solve all kinds of problems while driving, unfortunately the real world does not always fit to my mental model though. – David Carlisle Jan 18 '16 at 9:07 To my best effort I don't understand your intention. To invent new form how to write solution depend on some condition? For selection one of solution regarding to some conditionamsmath and mathtools provide environments cases and dcases respectively: \documentclass{article} \usepackage{mathtools} \begin{document} \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 \\ & = \begin{dcases} \left\lfloor \frac{\frac{a}{b}+\frac{\frac{c}{a}}{b}} {\frac{c}{a} + \frac{b}{a}} \right\rfloor &\quad \text{condition 1} \\ 42 &\quad \text{condition 2} \end{dcases} \end{align*}(\mathit{condition1})$holds since the sky is red and$(\mathit{condition2})\$ because this is the answer.
\end{document} If you only look how to align right side of equations at different width of relations between left and right side of equations, than the result without some manual tweaking always will not look nice (according to different taste of people).

• No, I think this is a misunderstanding. The last two steps in the example should be "explained" by condition1 and condition2 (i.e., these steps hold because these conditions are true). There should not be a case analysis as with cases. Sorry for not being clear enough. – cryingshadow Jan 18 '16 at 7:16
• If you say so. However, I still believe that your approach lead to notation which is very difficult to understand a math meaning as well is typographical very ugly. Different people, different tastes ... :-) – Zarko Jan 18 '16 at 7:22
• Well, this notation is not my invention. But you're definitely right that it is a matter of taste whether this notation is considered beautiful or ugly. Actually, this kind of notation was the first form for such proof sequences that was introduced to me. So I'm quite used to it and never questioned its look from a more distant perspective. It's interesting for me that so many people seem to find this notation awkward and I will definitely think about alternatives (nevertheless, from a technical point of view I find the question here still interesting whether it is just possible). – cryingshadow Jan 18 '16 at 7:31