[Tex/LaTex] Describing steps in an equation

equationshorizontal alignment

I am always describing the steps on how a formula is achieved or describing the underlying Mathematical principles taken to solve a problem in the align environment. But the descriptions are not displayed in the best manner possible. For example:

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\newcommand{\red}[1]{%
{\color{OrangeRed}#1}}

\begin{document}
Let us show that by completing the square, we can achieve this.
        \begin{align*}
        f(x)&=ax^2+bx+c \qquad\qquad\qquad\qquad\qquad\mbox{ Factor $a$ from $ax^2+bx$. Do you know why?}\\
            &=a\left(x^2+\frac{b}{a}x\right)+c\qquad\qquad\qquad\qquad\mbox{ \red{Complete the square by adding $\frac{b^2}{4a^2}$.}} \\
            &=a\left(x^2+\frac{b}{a}x+\red{\frac{b^2}{4a^2}} \right)+c\red{-a\left(\frac{b^2}{4a^2}\right)}\mbox{~~~Factor and simplify.}\\
            &=a\left(x+\frac{b}{2a}\right)^2+c-\frac{b^2}{4a}\\
            &=a\left(x+\frac{b}{2a}\right)^2+\frac{4ac-b^2}{4a}\\
            &=a(x-h)^2+k
        \end{align*}
 \end{document}

yeilds:

enter image description here

which does not display the description properly. If you notice in my code above, I am forcing the descriptions to have a left indent based on the longest line of math display (where the a\left(x^2+\frac{b}{a}x+\red{\frac{b^2}{4a^2}} \right)+c\red{-a\left(\frac{b^2}{4a^2}\right)} is found.)

Now here is a different scenario:

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\newcommand{\red}[1]{%
{\color{OrangeRed}#1}}

\begin{document}
Let us apply completing the square to the standard form of a quadratic equation, $ax^2+bx+c=0$.

\begin{align*}
    ax^2+bx+c&=0 &\mbox{Divide by $a$, the leading coefficient.}&\\[1.25ex]
    x^2+\frac{b}{a}x+\frac{c}{a}&=0 &\mbox{Transpose the constant term to the RHS.}&\\[1.25ex]
    x^2+\frac{b}{a}x&=-\frac{c}{a}&\mbox{\red{Add $\left(\frac{1}{2}\left(\frac{b}{a}\right)\right)^2$ to both sides.}}&\\[1.25ex]
    x^2+\frac{b}{a}x+\frac{b^2}{4a^2}&=-\frac{c}{a}+\frac{b^2}{4a^2}&\mbox{Factor the LHS and simplify the RHS.}&\\[1.25ex]
    \left(x+\frac{b}{a}\right)^2&=\frac{b^2-4ac}{4a^2}&\mbox{Take the square root of both sides.}&\\[1.25ex]
    x+\frac{b}{a}&=\pm\frac{\sqrt{b^2-4ac}}{2a}&\mbox{Solve for $x$.}&\\[1.25ex]
    x&=\frac{-b\pm\sqrt{b^2-4ac}}{2a}&\mbox{\textbf{Quadratic Formula}.}&
    \end{align*}
 \end{document}

which yields:

enter image description here

But what happens in this example is that the description is right aligned and not dependent on the longest line of math display. I have read somewhere that using

\text{\parbox[t]{2in}{ can be used in mathmode with a very long long long long long long long description}

Of course I foresee a drawback as the length of the parabox should be calculated on the remaining space of text while staying within the margin.

In summary, I would like the descriptions to be left aligned and dependent on the longest math display or possible split if using the split environment for math equations and that if the description goes beyond one line that it goes to a second or third line with the same proper indentation. Any help into the matter will be highly appreciated.

Best Answer

Somehing like this? (two && before the \mbox)

\documentclass[letterpaper]{article}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,enumitem}
\usepackage[dvipsnames]{xcolor}
\newcommand{\red}[1]{%
  {\color{OrangeRed}#1}}

\begin{document}
Let us apply completing the square to the standard form of a quadratic equation, $ax^2+bx+c=0$.

\begin{align*}
  ax^2+bx+c&=0 &&\text{Divide by $a$, the leading coefficient.}&\\[1.25ex]
  x^2+\frac{b}{a}x+\frac{c}{a}&=0 &&\text{Transpose the constant term to the RHS.}&\\[1.25ex]
  x^2+\frac{b}{a}x&=-\frac{c}{a}&&\text{\red{Add $\left(\frac{1}{2}\left(\frac{b}{a}\right)\right)^2$ to both sides.}}&\\[1.25ex]
  x^2+\frac{b}{a}x+\frac{b^2}{4a^2}&=-\frac{c}{a}+\frac{b^2}{4a^2}&&\text{Factor the LHS and simplify the RHS.}&\\[1.25ex]
  \left(x+\frac{b}{a}\right)^2&=\frac{b^2-4ac}{4a^2}&&\text{Take the square root of both sides.}&\\[1.25ex]
  x+\frac{b}{a}&=\pm\frac{\sqrt{b^2-4ac}}{2a}&&\text{Solve for $x$.}&\\[1.25ex]
  x&=\frac{-b\pm\sqrt{b^2-4ac}}{2a}&&\text{\textbf{Quadratic Formula}.}&
\end{align*}
\end{document}

enter image description here