# Change figure/equation labels, along with their \ref?

Say I labeled a Equation with \label{ABC}, and refer to it couple of times with \ref{ABC}. Now I want to change the label to \label{XYZ}. Is there an automatic way that those \ref{ABC} will be simultaneously changed to \ref{XYZ}?

I also have multiple .tex files and \input them to the main file. So search/replace doesn't work well...

-
this would be a good reason to learn about sed –  cmhughes Jun 14 '12 at 4:26

You can make the references equivalent. Consider the following setup:

$$f(x)=ax^2+bx+c \label{abc}$$
See~(\ref{abc}).


Now you change the label to \label{xyz}. In order to make all abc labels still reference the newly defined xyz, you can execute

\makeatletter
\let\r@abc\r@xyz
\makeatother


Here's a complete example:

\documentclass{article}
\begin{document}
$$f(x)=ax^2+bx+c \label{xyz}% ...was \label{abc}$$
\makeatletter
\let\r@abc\r@xyz% Reference abc is equivalent to xyz
\makeatother
See~(\ref{abc}) and~(\ref{xyz}).
\end{document}

-
This is helpful to know this fact. However, it does not directly solve my problem... –  Yu Hu Jun 14 '12 at 4:28
@YuHu: Does the updated answer seem more promising? –  Werner Jun 14 '12 at 4:53
sed -i 's/\\ref{ABC}/\\ref{XYZ}/g' *.tex