# How to issue a warning if trying to reference a label in a starred equation environment?

My file is pretty big (it's over 100 equations and growing) and I don't want to check by hand which equation labels I've used. So my goal was to change all equation environments to equation*, but any reference to a labeled equation* outputs nothing or an "unrelated" number without creating any warning.

Is there a way to force such cases to produce a warning ?

MWE :

\documentclass[a4paper, 11pt]{article}
\usepackage{amsmath}

\begin{document}
\begin{equation*} \label{mylabel}
\pi = 3.2
\end{equation*}
I want a warning if i'm trying to reference equation \eqref{mylabel} since the equation environment is starred.
\end{document}

• It might be easier to solve your initial problem, and to check for each defined label whether it has been referenced. Depending on your OS, there are external solutions (like using regular expressions to extract all strings from \label and \ref commands and display those labels not \refed), or pure LaTeX solutions where each \ref command records its label and the \label commands check whether they have been used (the 'undefined label' check in reverse). Jun 24 at 17:44

The following causes \label calls from within equation* to print a warning:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\renewcommand*{\label@in@display}[1]{%
\errmessage{\string\label{#1} used in equation* environment!}%
}%
}
\makeatother

\begin{document}

\begin{equation*} \label{mylabel}
x = 3.2
\end{equation*}

\end{document}

• Perfectly what i was looking for. Thanks ! Jun 24 at 19:12
• You're welcome, glad to hear that! Jun 24 at 19:31