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}

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


Here's a complete example:

enter image description here

  f(x)=ax^2+bx+c \label{xyz}% ...was \label{abc}
\let\r@abc\r@xyz% Reference abc is equivalent to xyz
See~(\ref{abc}) and~(\ref{xyz}).
  • This is helpful to know this fact. However, it does not directly solve my problem... – Yu Hu Jun 14 '12 at 4:28
  • 1
    @YuHu: Does the updated answer seem more promising? – Werner Jun 14 '12 at 4:53

Elaborating on @cmhughes's comment, use sed:

sed -i 's/\\ref{ABC}/\\ref{XYZ}/g' *.tex

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.