# Describing steps in an equation

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:

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: 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. • I think you will be better with a tabular environment, or a special command to add lines of equations. – Yiannis Lazarides May 21 '12 at 18:36 • @YiannisLazarides I guess so, but how would the align feature still maintained within a tabular environment. Wouldn't there be column and row separation issues? And the declaration of the column type for the math section may pose an issue. – azetina May 21 '12 at 18:49 ## 2 Answers 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}  • since amsmath is being used, i suggest using \text{...} rather than \mbox. – barbara beeton May 21 '12 at 18:54 • This seems to do the job. I will wait and see if there are more feedback from the community and then will accept your answer. The question then would be: How do we deal with long descriptions while maintaining proper display? – azetina May 21 '12 at 19:18 • @azentina - perhaps minipage helps – robert.marik.cz May 21 '12 at 19:26 Package witharrows provides a new environment WithArrows similar to align where it's possible to use command \Arrow to print some text beside an arrow going from one line to another one. Here you have the possible result with OP's examples: \documentclass[letterpaper]{article} \usepackage{fullpage} \usepackage{amsmath,amssymb,amsthm,enumitem} \usepackage[dvipsnames]{xcolor} \usepackage{tikz} \usetikzlibrary{calc, arrows.meta, bending, decorations.pathreplacing} \usepackage{witharrows} \newcommand{\red}[1]{% {\color{OrangeRed}#1}} \begin{document} Let us show that by completing the square, we can achieve this. \[ \begin{WithArrows} f(x)&=ax^2+bx+c \Arrow{Factor a from ax^2+bx. Do you know why?}\\ &=a\left(x^2+\frac{b}{a}x\right)+c \Arrow[tikz=OrangeRed]{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)}\Arrow{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{WithArrows} \end{document}


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

\usepackage{tikz}
\usetikzlibrary{calc, arrows.meta, bending, decorations.pathreplacing}

\usepackage{witharrows}

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

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


Note: Package documentation doesn't mention it, but we should load TikZ and calc, arrows.meta, bending, decorations.pathreplacing tikzlibraries to use WithArrows environment.