# Equation autolabelling

I am just wondering if there is a way to refer to autolabelled equations in the text.

I can use:

$$x^2$$

The equation will autonumber, but I can't refer to it in the text without providing a label, and I don't want to do that because I might be added other equations before it in the future (plus I'd still have to update the text).

Apologies if this has been asked. I have tried to search for it with no luck. Maybe I am using the wrong search terms.

• Welcome to TeX.SE! See the posting Cross-reference packages: which to use, which conflict? for an overview and discussion of LaTeX packages that simplify and/or extend cross-referencing to various objects in a document, including equations. – Mico Mar 8 '18 at 18:12
• Thanks for the edit Phelype Oleinik. I made the code bits code but it didn't look right for some reason. – cohara Mar 9 '18 at 14:10

You don't have to number the equations by yourself. Let LaTeX do the heavy lifting. You can just give names to the equations and refer to them by their names:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Equation~\ref{xsquared} shows that the universe is
infinite, but equation~\ref{ysquared} says otherwise.
$$\label{xsquared} a = x^2$$
$$\label{ysquared} b = y^2$$
\end{document}

If you insert an equation before it, LaTeX will do the numbering by itself:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

Equation~\ref{xsquared} shows that the universe is
infinite, but equation~\ref{ysquared} says otherwise.
$$\label{answer} x = y = 42$$
$$\label{xsquared} a = x^2$$
$$\label{ysquared} b = y^2$$
\end{document}

# Getting fancy :)

Barbara Beeton pointed a few problems with my previous answer.

An empty line between an and the next will create an extra empty space between the equations, so I removed them.

Notice also the ugly spacing between equations (1) and (2) in the previous figure. The gather environment from amsmath allows multiple equations inside the same environment and makes the spacing between them correct. At the same time, it allows one label per equation the same way that the three equation environments allowed:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

Equation~\ref{xsquared} shows that the universe is
infinite, but equation~\ref{ysquared} says otherwise.
\begin{gather}