5

Possible Duplicate:
How to correctly format (and align) a LaTeX proof?

In my proofs I would like to have justifications of each step to the side of the numerical manipulation. For instance consider what I have been doing:

\begin{align*}
\lvert p-q \rvert &= \sqrt{(p-q)^2} \text{      by definition of square root}\\
&=\sqrt{p^2 -2pq +q^2}\text{        by multiplication}\\
&=\sqrt{p^2-2pq+q^2 +2pq -2pq} \text{by the additive identity}\\
&=\sqrt{p^2+2pq+q^2 -4pq}\text{     by grouping like terms}\\
&=\sqrt{(p+q)^2 -4n}\text{          by the distributive law}
\end{align*}

This is messy and more time consuming.

  1. How can I achieve my justifications in some kind of defined format?
  2. What are other best practices?

marked as duplicate by Andrew Swann, Gonzalo Medina, percusse, Paul Gaborit, Mensch Oct 28 '12 at 22:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5

You can also use the alignat math environment as follows:

\documentclass[letterpaper]{article}
\usepackage{amsmath,amssymb}
\newcommand{\justif}[2]{&{#1}&\text{#2}}
\begin{document}
\begin{alignat*}{2}
\lvert p-q\rvert &=\sqrt{(p-q)^2}               &\quad &\text{by definition of square root}\\
                 &=\sqrt{p^2 -2pq +q^2}         &\quad &\text{by multiplication}\\
                 &=\sqrt{p^2-2pq+q^2 +2pq -2pq} &\quad &\text{by the additive identity}\\
                 &=\sqrt{p^2+2pq+q^2 -4pq}      &\quad &\text{by grouping like terms}\\
                 &=\sqrt{(p+q)^2 -4n}           &\quad &\text{by the distributive law}        
\end{alignat*}
%--------------------------------------------------------------------------------
\begin{alignat*}{2}
\lvert p-q\rvert &=\sqrt{(p-q)^2}               \justif{\quad}{by definition of square root}\\
                 &=\sqrt{p^2 -2pq +q^2}         \justif{\quad}{by multiplication}\\
                 &=\sqrt{p^2-2pq+q^2 +2pq -2pq} \justif{\quad}{by the additive identity}\\
                 &=\sqrt{p^2+2pq+q^2 -4pq}      \justif{\quad}{by grouping like terms}\\
                 &=\sqrt{(p+q)^2 -4n}           \justif{\quad}{by the distributive law}           
\end{alignat*}
\end{document}

enter image description here

Increase the space between the math expression and text by adjusting the quad part. Note @egreg suggested an intuitive way of simplifying the input of the comments by a using \justif command.

  • You only need one of the first &\quad& incantation; on subsequent lines && will be sufficient – Andrew Swann May 14 '13 at 8:29
1

In such a situation I personally use an align with multiple "equations" on the same line:

\begin{align*}
  (p-q) &= \sqrt{(p-q)^2} & & \text{by definition of square root}\\
  &=\sqrt{p^2 -2pq +q^2} & & \text{by multiplication}\\
  &=\sqrt{p^2-2pq+q^2 +2pq -2pq} & & \text{by the additive identity}\\
  &=\sqrt{p^2+2pq+q^2 -4pq} & & \text{by grouping like terms}\\
  &=\sqrt{(p+q)^2 -4n} & & \text{by the distributive law}
\end{align*}
  • Possibly adding a personal command (see my comment to Gonzalo's answer). – egreg Oct 28 '12 at 22:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.