Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?
share|improve this question

marked as duplicate by Andrew Swann, Gonzalo Medina, percusse, Paul Gaborit, Kurt 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.

    
A tip: If you indent lines by 4 spaces or enclose words in backticks `, they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). –  hpesoj626 Oct 28 '12 at 22:10
    
See egreg's answer to exactly the same question. –  Andrew Swann Oct 28 '12 at 22:15

2 Answers 2

up vote 3 down vote accepted

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.

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

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*}
share|improve this answer
    
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.