# 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

## 1 Answer

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}}
`

and you're in business.

• Perfect, will accept in 3 mins. Super concise yet thorough, that's pretty awesome actually! – theonlygusti Oct 6 '17 at 21:21
• @theonlygusti: The 3 mins have passed ... ;-) – user31729 Oct 6 '17 at 21:28
• @ChristianHupfer - You got the OP's attention! :-) – Mico Oct 6 '17 at 21:30