# LaTeX issues warning about a Reference being undefined even though a \label statement was issued

I want to show a few equations in a row as I solve an integration, then number the final unsimplified equation and use the number in the next line.

\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}}
...
\begin{gather*}
\left[\frac12x-\frac1{4n}\sin2nx\right]_a^{a+2\pi}\\
\frac{a+2\pi}2-\frac1{4n}\sin(2n(a+2\pi))-\frac{a}2+\frac1{4n}\sin(2an)\\
\frac{a+2\pi}2-\frac{a}2+\frac1{4n}\sin(2an)-\frac1{4n}\sin(2an+4n\pi)\numberthis\label{unsimplified integral of sine squared}\\
\sin(x+2\pi)\equiv\sin(x)\implies\ref{unsimplified integral of sine squared}=\frac{a+2\pi-a}2
\end{gather*}


This gives me the error

LaTeX Warning: Reference unsimplified integral of sine squared' on page 6 undefined

• labels is not meant for issues with \label ;-) – user31729 Oct 6 '17 at 21:23
• Off-topic: I would use \eqref instead of \ref to create the cross-reference to the numbered equation. – Mico Oct 6 '17 at 21:30
• @Mico why's that? And how do I implement it if it has advantages? – theonlygusti Oct 6 '17 at 21:34
• @theonlygusti - If you change \ref to \eqref, LaTeX will encase the number 1 in parentheses. This might be helpful to your readers, who might otherwise be puzzling over the apparent claim that 1=\pi... – Mico Oct 6 '17 at 21:38
• @Mico I was going to just write the brackets myself. Using eqref looks better though, i assume it was designed for this. – theonlygusti Oct 6 '17 at 21:41

LaTeX's \label-\ref mechanism employs the \refstepcounter macro to (a) increment the specified counter and (b) enable the argument of \label to be associated with the most-recently-incremented counter variable.

Thus, simply change

\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}}


to

\newcommand\numberthis{\refstepcounter{equation}\tag{\theequation}}
`