17

What is the "best LaTeX practices" for writing equations with multiple steps? Feel free to recommend packages that might help. Do these methods work just as well within an enumeration?

Here is what I currently do:

\documentclass{article}

\begin{document}

\begin{enumerate}

\item Using the previous property, $|\mathbf{x} + \mathbf{y}|^2$

\( = (\mathbf{x} \cdot \mathbf{y}) \cdot (\mathbf{x} \cdot \mathbf{y}) \)

\( = \sum_{i=1}^k (x_i + y_i)(x_i + y_i) \)
(by the definition of inner product

\( = \sum_{i=1}^k (x_i^2 + 2 x_i^{} y_i^{} + y_i^2) \)

\( = \mathbf{x} \cdot \mathbf{x} + 2 \mathbf{x} \cdot \mathbf{y} + \mathbf{y} \cdot \mathbf{y} \)

\( \leq |\mathbf{x} \cdot \mathbf{x}| + 2 |\mathbf{x} \mathbf{y}| + |\mathbf{y} \cdot \mathbf{y}| \)

\( \leq |\mathbf{x}| |\mathbf{x}| + 2 |\mathbf{x}| |\mathbf{y}| + |\mathbf{y}| |\mathbf{y}| \)
(by Property 4)

\( = (|\mathbf{x}| + |\mathbf{y}|)^2, \)

and since both sides are $\geq 0$, we can take the square root.

\end{enumerate}

\end{document}

The main problem is that, because of the enumerate environment, I can't indent each step of the equality, so that first term looks sort of separate...

jamaicanworm
  • 29,114

3 Answers3

21

I usually advise against longish enumerate items in a proof; the indent at the start of a paragraph followed by a number is sufficient to mark a step. If the proof is longer than one page, the page would be very uneven.

1. Using the previous property,
\begin{align*}
\abs{\mathbf{x} + \mathbf{y}}^2
&= (\mathbf{x} \cdot \mathbf{y}) \cdot (\mathbf{x} \cdot \mathbf{y}) \\
&= \sum_{i=1}^k (x_i + y_i)(x_i + y_i)
   \quad\text{(by the definition of inner product)}\\
&= \sum_{i=1}^k (x_i^2 + 2 x_i^{} y_i^{} + y_i^2) \\
&= \mathbf{x} \cdot \mathbf{x}
   + 2 \mathbf{x} \cdot \mathbf{y}
   + \mathbf{y} \cdot \mathbf{y} \\
&\leq \abs{\mathbf{x} \cdot \mathbf{x}}
      + 2 \abs{\mathbf{x} \mathbf{y}}
      + \abs{\mathbf{y} \cdot \mathbf{y}} \\
&\leq \abs{\mathbf{x}} \abs{\mathbf{x}}
      + 2 \abs{\mathbf{x}} \abs{\mathbf{y}}
      + \abs{\mathbf{y}} + \abs{\mathbf{y}}
      \quad\text{(by Property 4)} \\
&= (\abs{\mathbf{x}} + \abs{\mathbf{y}})^2,
\end{align*}
and since both sides are $\geq 0$, we can take the square root.

enter image description here

A tip: notice that in the third line of the alignment I wrote

x_i^2 + 2 x_i^{} y_i^{} + y_i^2

with empty exponents, that will lower the subscripts at the same height as the others on the line.

David Carlisle
  • 757,742
egreg
  • 1,121,712
11

In the following example, the environment align and the command \intertext from the package amsmath are used to get the "nice formatting".

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{enumerate}

\item
First, we will show that
\begin{align*}
x^8-y^8 &= (x^4+y^4)(x^4-y^4),
\intertext{where we used the relation $a^2-b^2=(a+b)(a-b)$, and we can continue:}
&= (x^4+y^4)(x^2+y^2)(x^2-y^2)
\\
&= (x^4+y^4)(x^2+y^2)(x+y)(x-y).
\end{align*}

\item
Second item.

\end{enumerate}

\end{document}
David Carlisle
  • 757,742
yo'
  • 51,322
3

There is a really neat package called witharrows that does a really nice job of what you're trying to do. It creates an environment called WithArrows that takes the place of aligned. There are several tweaks you can use to adjust the spacing, color, and types of arrows used to describe the steps.

Here is an MWE:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{witharrows}

%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{equation}
\setlength{\jot}{10pt}
\begin{WithArrows}
ax^2 + bx + c & = 0 \Arrow[xoffset=-2cm]{Multiply both sides by $4a$} \\
4a^2 x^2 + 4abx + 4ac & = 0 \Arrow[xoffset=-1cm]{Subtract $4ac$} \\
4a^2 x^2 + 4abx & = - 4ac \\
4a^2 x^2 + 4abx + b^2 & = b^2 - 4ac \\
(2ax + b)^2 & = b^2 - 4ac \\
2ax + b & = \pm \sqrt{b^2 - 4ac} \\
2ax & = -b \pm \sqrt{b^2 - 4ac}
\end{WithArrows}
\nonumber
\end{equation}

\end{document}

Here is the output:

enter image description here

G. Khanna
  • 508