Left-aligned text inside an equation

Here's what you referred to for page 136:

\documentclass{article}
\usepackage{mathtool,lipsum}
\newcommand{\lefttext}[1]{\makebox[0pt][l]{#1}}
\begin{document}
\lipsum*[1]
\begin{equation}
\begin{aligned}[b]
\hbar\omega\eta\bar{\eta} 
  &= (2m)^{-1}(p+im\omega q)(p-im\omega q)\\
  &=(2m)^{-1}[p^{2}+m^{2}\omega^{2}q^{2}+im\omega(qp-pq)]\\
  &=H-\yfrac{1}{2}\hbar\omega 
\end{aligned}
\end{equation}
\vspace{\glueexpr-\baselineskip-\belowdisplayskip-\jot\relax}
\begin{flalign}
&\lefttext{and similarly}&  \hbar\omega\bar{\eta}\eta &= H+\tfrac{1}{2}\hbar\omega. &&\\
&\lefttext{Thus}& \bar{\eta}\eta-\eta\bar{\eta} &= 1.
\end{flalign}
\lipsum*[2]
\begin{flalign}
&\lefttext{Here}&\mathclap{a long equation} &&\\
&\lefttext{whence}&\mathclap{short} &&
\end{flalign}
\end{document}

We have to play a bit with the vertical spacing because two different environments must go one after another. Expect some manual intervention to fix cases like this (the space between equations 1 and 2 is not really precise).

The important aspect for you is the flalign environment. We provide two mock groups at start and end, with zero width, so the middle group will be effectively centered.

enter image description here

I've added a strategy for emulating gather:

\begin{flalign}
&\lefttext{Here}&\mathclap{a long equation} &&\\
&\lefttext{whence}&\mathclap{short} &&
\end{flalign}

Load mathtools for \mathclap. It will be up to you avoiding overlaps.


This is a variant, which works with math-environments which understand \tag. Together with the class-option leqno it doesn't work thou. I learned this approach from Philipp Stephani. It works the same way as amsmaths intertext, but puts the text on the same line as the equation.

\documentclass[letterpaper,11pt]{article}
\usepackage{amsmath}
\usepackage{etoolbox} 

\makeatletter
\newif\if@gather@prefix 
\preto\place@tag@gather{% 
  \if@gather@prefix\iftagsleft@ 
    \kern-\gdisplaywidth@ 
    \rlap{\gather@prefix}% 
    \kern\gdisplaywidth@ 
  \fi\fi 
} 
\appto\place@tag@gather{% 
  \if@gather@prefix\iftagsleft@\else 
    \kern-\displaywidth 
    \rlap{\gather@prefix}% 
    \kern\displaywidth 
  \fi\fi 
  \global\@gather@prefixfalse 
} 
\preto\place@tag{% 
  \if@gather@prefix\iftagsleft@ 
    \kern-\gdisplaywidth@ 
    \rlap{\gather@prefix}% 
    \kern\displaywidth@ 
  \fi\fi 
} 
\appto\place@tag{% 
  \if@gather@prefix\iftagsleft@\else 
    \kern-\displaywidth 
    \rlap{\gather@prefix}% 
    \kern\displaywidth 
  \fi\fi 
  \global\@gather@prefixfalse 
} 
\newcommand*{\beforetext}[1]{% 
  \ifmeasuring@\else
  \gdef\gather@prefix{#1}% 
  \global\@gather@prefixtrue 
  \fi
} 
\makeatother


\begin{document}
\begin{align}
  \label{eq:1}
  \beforetext{and similary} hwnn &= H+hw\\
  \beforetext{Thus} nn-nn &=1.
\end{align}
\end{document}

Output: enter image description here


Just patching \math@cr@@@align I could make Peter Breitfeld's solution to work as I needed. Now it works with align, gather, with and without equation numbers, and with some tricks even with aligned! It doesn't work with equation, but that can be replaced with gather.

I had to copy the definition from amsmath.sty, just to include the \if@gather@prefix\tag@true\fi, which must go after the \omit (I don't know if there's an easier way to patch it).

\documentclass[a5paper]{article}
\usepackage{amsmath,etoolbox} 

\makeatletter
\newif\if@gather@prefix 
\preto\place@tag@gather{% 
  \if@gather@prefix\iftagsleft@ 
    \kern-\gdisplaywidth@ 
    \rlap{\gather@prefix}% 
    \kern\gdisplaywidth@ 
  \fi\fi 
} 
\appto\place@tag@gather{% 
  \if@gather@prefix\iftagsleft@\else 
    \kern-\displaywidth 
    \rlap{\gather@prefix}% 
    \kern\displaywidth 
  \fi\fi 
  \global\@gather@prefixfalse 
} 
\preto\place@tag{% 
  \if@gather@prefix\iftagsleft@ 
    \kern-\gdisplaywidth@ 
    \rlap{\gather@prefix}% 
    \kern\displaywidth@ 
  \fi\fi 
} 
\appto\place@tag{% 
  \if@gather@prefix\iftagsleft@\else 
    \kern-\displaywidth 
    \rlap{\gather@prefix}% 
    \kern\displaywidth 
  \fi\fi 
  \global\@gather@prefixfalse 
} 
\def\math@cr@@@align{%
  \ifst@rred\nonumber\fi
  \if@eqnsw \global\tag@true \fi
  \global\advance\row@\@ne
  \add@amps\maxfields@
  \omit
  \kern-\alignsep@
  \if@gather@prefix\tag@true\fi
  \iftag@
    \setboxz@h{\@lign\strut@{\make@display@tag}}%
    \place@tag
  \fi
  \ifst@rred\else\global\@eqnswtrue\fi
  \global\lineht@\z@
  \cr
}
\newcommand*{\beforetext}[1]{% 
  \ifmeasuring@\else
  \gdef\gather@prefix{#1}% 
  \global\@gather@prefixtrue 
  \fi
} 
\makeatother

\begin{document}

align
\begin{align}
  \beforetext{and similary} hwnn &= H+hw\\
  \beforetext{Thus} nn-nn &=1.
\end{align}

align*
\begin{align*}
  \beforetext{and similary} hwnn &= H+hw\\
  \beforetext{Thus} nn-nn &=1.
\end{align*}

gather (\textbackslash notag on the first line)
\begin{gather}
  \beforetext{and similary} hwnn = H+hw \notag \\
  \beforetext{Thus} nn-nn =1.
\end{gather}

aligned
\begin{gather}
  \beforetext{$\displaystyle\begin{aligned}&\!\text{and similarly}\\&\!\text{Thus}\end{aligned}$}
  \begin{aligned}
    hwnn &= H+hw\\
    nn-nn &=1.
  \end{aligned}
\end{gather}

\end{document}

enter image description here