1

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
2

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

\begin{equation}
  f(x)=ax^2+bx+c \label{abc}
\end{equation}
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:

enter image description here

\documentclass{article}
\begin{document}
\begin{equation}
  f(x)=ax^2+bx+c \label{xyz}% ...was \label{abc}
\end{equation}
\makeatletter
\let\r@abc\r@xyz% Reference abc is equivalent to xyz
\makeatother
See~(\ref{abc}) and~(\ref{xyz}).
\end{document}
| improve this answer | |
  • 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
1

Elaborating on @cmhughes's comment, use sed:

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

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.