2

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}
1
  • 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).
    – gernot
    Jun 24 at 17:44

1 Answer 1

5

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

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\AddToHook{env/equation*/begin}{%
  \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}
2
  • Perfectly what i was looking for. Thanks ! Jun 24 at 19:12
  • You're welcome, glad to hear that!
    – frougon
    Jun 24 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.