Best Pattern For Adding Commentary in align Environment?
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
f(ax + by) & = f(ax) + f(by) \tag{By Property 1}\\
& = af(x) + bf(y) \tag*{By Property 2}
\end{align}
\end{document}
Without knowing the full extent of the use-case for this commentary, the following works without problem:
\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcommand{\comment}[1]{%
\text{\phantom{(#1)}} \tag{#1}
}
\begin{document}
\begin{align*}
\comment{By Property 1} f(ax + by) & = f(ax) + f(by) \\
\comment{By Property 2} & = af(x) + bf(y)
\end{align*}
\end{document}
The above minimal example uses \tag
to typeset the comment (which is necessarily surrounded by parenthesis). This functionality is provided by amsmath
by default. However, you will not be able to add numbered equations, since \tag
is used as an alternative to equation numbers. Referencing within the tag is allowed, if needed.
\comment{<stuff>}
has to be used at the start of the equation in order to balance the equation over \textwidth
, since it typesets a \phantom
\tag
.
showframe
merely illustrates the text frame in this example, and is not needed in general.
Depending on the specific application, another option to consider would be to use \intertext
, or \shortintertext
from the mathtools
package:
or for longer commentary use a \parbox
:
\documentclass[border=2pt]{standalone}
\usepackage{mathtools}% includes amsmath
\begin{document}
\begin{align*}
\shortintertext{By Property 1} f(ax + by) & = f(ax) + f(by) \\
\shortintertext{By Property 2} & = af(x) + bf(y)
\end{align*}
\begin{align*}
f(ax + by) & = f(ax) + f(by) & \parbox[c]{0.4\linewidth}{Some long comment about first equation}\\
& = af(x) + bf(y) & \parbox[c]{0.4\linewidth}{Some other even longer comment about second equation}
\end{align*}
\end{document}