Number equations and preserving alignment of equal signs

So as I have learned from a previous post that the \begin{aligned}... \end{aligned} with the usage of "&" before "=" will help arrange neatly the equations where the equal sign of each equation will be just below the equal sign of the following equation and so on.

My question is if I have a total of 8 equations, how to number each equation and at the same time preserve the alignment of the equal signs.

Note if I use $$...$$, I get only one number for the collection of 8 equations at the very end which is not what I want.

• What about \begin{align}...\end{align} that's well explained in the manual of amsmath? – egreg Aug 9 '15 at 14:56

Here is a small sample of numbering equations.

\documentclass[12pt]{article}

\usepackage{amsmath}

\begin{document}

\begin{align} % numbers equations automatically
x &= (1-x) + 2x \\ % \\ ends the line
&= (x+y) - y \nonumber \\ % \nonumber removes the equation number
&= \frac{x}{2} + \frac{x}{2} % last line does not have \\
\end{align}

\begin{align*} % use of * removes all numbers in this block
x &= (2x + 5) - (x+5) \\
&= yx - (y-1) x
\end{align*}

\end{document}


This sample produces