# How can we typeset a multi-line expression with both an equation number and a comment?

What is your favourite way of typesetting (multi-line) mathematical expression (with an equality or inequality symbol in the middle) that needs to have both a number and a comment? Here, a comment refers to anything resembling "2.5.1", "By Lemma 3", "Using Jensen's inequality", or something excruciatingly long. The following picture (from Yurii Nesterov's Lectures on Convex Optimization) hopefully gives an idea of what I'm talking about.

I like Nesterov's style where he puts the comment (almost always a reference to an equation) above the symbol in the middle. This gives us the freedom to put an equation number in any line. But this also becomes problematic easily if the comment is a little too long.

Another approach could be to put the equation number above the equality symbol, and put the comment as tag{}. This has the additional advantage that if the comment is too long to be put in the same line as the expression, it automagically adjusts itself to be in a new line (right-aligned).

Yet another (albeit relatively uncommon) convention that I have seen is to simply not have any comments in the equation at all! The authors who follow this prefer to put the comments in the text following the equation. While this seems like a reasonable idea, in my opinion, it breaks the linear, compact form of the multi-line expression.

I would like to know what conventions others follow and the corresponding pros and cons.

• Also note that the vertical location of your equation, when vertically centered over your equation, looks a bit off in the example you show. That is also the case in the first two examples in the answer below. The third suggestion is truly the best among the three. Commented Feb 18, 2023 at 17:06
• @mickep Are you hinting at the fact that the equation number (3.1.73) is not perfectly aligned with either of the lines? Commented Feb 18, 2023 at 17:30
• Yes, and it is really one equation, so it might be preferably to load amsmath with tbtags to have the number aligned with the last line. Commented Feb 18, 2023 at 17:36

## 1 Answer

I'm not a fan of this style, that leaves too much space around the relation symbol.

Since you asked about “best practices”, I'll present a few ways to do it.

\documentclass{article}
\usepackage{amsmath}
\usepackage{newtxtext,newtxmath}

\newcommand{\relcomm}[2]{% #1 = comment, #2 = relation
\overset{\substack{\text{\makebox[0pt]{#1}}\\\downarrow}}{#2}%
}

\begin{document}

% just to get the same numbers as in the picture
\renewcommand{\theequation}{3.1.\arabic{equation}}
\setcounter{equation}{71}

First a dummy equation for the reference
$$\label{A} 1=1$$
Now I present the first solution
\begin{aligned} (g^*,x_\delta-x_*) &\overset{\text{\eqref{A}}}{\ge} K(A^T\bar{y},\bar{x}+\delta-x^*) =K(\bar{y},A\delta+b-Ax_*) \\ &\overset{\hphantom{\text{\eqref{A}}}}{=} K\lVert b-Ax_*\rVert + K(A^T\bar{y},\delta) \end{aligned}
Next the second solution
\begin{aligned} (g^*,x_\delta-x_*) &\relcomm{\eqref{A}}{\ge} K(A^T\bar{y},\bar{x}+\delta-x^*) =K(\bar{y},A\delta+b-Ax_*) \\ &= K\lVert b-Ax_*\rVert + K(A^T\bar{y},\delta) \end{aligned}
and finally the third solution
\begin{aligned} (g^*,x_\delta-x_*) &\ge K(A^T\bar{y},\bar{x}+\delta-x^*) && \text{by \eqref{A}} \\ &= K(\bar{y},A\delta+b-Ax_*) \\ &= K\lVert b-Ax_*\rVert + K(A^T\bar{y},\delta) \end{aligned}

\end{document}


• I agree about the abundance of horizontal space around the relation symbol. Anything more than an equation number looks awful. It also wastes a lot of equation space for that reason. The second solution, for some reason, looks inappropriate to me for a formal document. Moreover, I can see a lot of awkward vertical space creeping in if someone needs to use it in anywhere other than the first line. The third solution seems like the most reasonable one. Commented Feb 18, 2023 at 16:35
• @Saptam I don't see “a lot” of space. Anyway, here's my classification: 3.1.73 is ugly (like Eli Wallach), 3.1.74 is bad (like Lee Van Cleef), and 3.1.75 is good (like Clint Eastwood). Commented Feb 18, 2023 at 16:41
• What I meant to say is if someone needs to use the \relcomm command in, say, the second line of the equation. And wow, that's... something new. :o Commented Feb 18, 2023 at 17:00
• @Saptam I get this (click here). It doesn't seem to have too much space. Commented Feb 18, 2023 at 17:10
• @Saptam You just enclose in align instead of equation and aligned, using \notag for the lines you don't want to be numbered. If you want less space between the equation and the comment, use \begin{alignat}{2} and &\qquad&\text{<comment>} Commented Feb 18, 2023 at 17:40