Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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...

share|improve this question
    
this would be a good reason to learn about sed –  cmhughes Jun 14 '12 at 4:26
add comment

2 Answers

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}
share|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
add comment

Elaborating on @cmhughes's comment, use sed:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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