# How to diagnose a permanent "Label(s) may have changed" warning?

I'm getting the following warning:

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.


The problem is, it doesn't go away after rerunning (any number of times).

The document in question is over 200 pages long and includes about 30 packages, so it's not really feasible for me to provide a minimal example. But I know my own code pretty well. I can probably fix it if I knew a bit more about the problem. So I want to ask some general questions:

• How does the "labels changed; rerun" mechanism work, anyway?
• Is there a common culprit responsible for this problem?
• How would someone generally go about diagnosing it?

But I'm not using the elsarticle or acronym packages, so the accepted answer didn't apply to me.

More info: As suggested, I did a kind of 'commenting out' binary search. (By the way, if LaTeX knows that labels may have changed, why can't it tell me which labels?)

Anyway, I seemed to track down the problem to a specific figure. When I compile only chapters 1 to 3, removing that figure also removes the warning. However, if I once again include all chapters, removing that figure isn't enough. So I guess there are other problem locations. But I don't have time to search chapters 4 to 9 right now...

I can also tell you this: I have a tmp directory where LaTeX and friends dump all temporary files. And between two compilations, the relevant content of this directory does not change at all. That is to say, diff -r tells me that the only changes are some timestamps and the .pdf file. In particular: all .aux files are identical.

• Did you try the method of dividing the input into two in order to find the part that's responsible for the changing label? Jan 17, 2014 at 16:54
• The divide and "concur" can only work to a certain extent in this case. You can find by this method the shortest prefix of the code in which the problem occurs. The jumpy reference should occur at the end of this prefix. But, it could be that the jumpiness is a result of numbered reference, which, e.g., changes from three digits to four if the file is long enough. Jan 17, 2014 at 17:21
• Check if the varioref package is used. It's a common culprit for this kind of behaviour. The only fix would be to use a normal \ref at the point that's responsible or change the text slightly so the \vref isn't at a page boundary anymore. en.wikibooks.org/wiki/LaTeX/… Jan 17, 2014 at 17:55
• (3) @PauloCereda: Take a look at my extended answer. The auxiliary files stay identical between compiles. To add to that: the figure in question does not move in the .pdf. Jan 18, 2014 at 14:35
• The fact that removing the figure and reinstating the missing chapter makes the problem reappear might mean that you have two similar situations. Jan 18, 2014 at 14:46

(By the way, if LaTeX knows that labels may have changed, why can't it tell me which labels?)

The following document will give the re-run error message each time.

\documentclass{article}

\makeatletter

% \def\@testdef #1#2#3{%
%   \def\reserved@a{#3}\expandafter \ifx \csname #1@#2\endcsname
%  \reserved@a  \else
% \typeout{^^Jlabel #2 changed:^^J%
% \meaning\reserved@a^^J%
% \expandafter\meaning\csname #1@#2\endcsname^^J}%
% \@tempswatrue \fi}

\begin{document}
\providecommand\r@foo{{1}{1}}
\edef\@currentlabel{.\expandafter\@firstoftwo\r@foo}
\label{foo}
a

\end{document}


produces a log

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.


If you uncomment the block in the preamble you get an additional diagnostic telling you which label has changed, and the old and new definition:

label foo changed:
macro:->{............1}{1}
macro:->{...........1}{1}

)

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

• Awesome. :-) Will try this when I get home. Apr 3, 2014 at 14:31
• Thanks to this diagnostic trick, I was finally able to fix the issue. It turns out, the captions of all offending labels had inline math with a _ (subscript) inside (though the before/after versions were always identical). Replacing these was all I had to do! --- I am unable to reproduce this in a minimal document. Can't say I'm surprised. I hacked around in my thesis code so much, it's hardly LaTeX anymore. --- Thanks! Apr 6, 2014 at 18:14
• @DavidCarlisle This diagose does not always work. I still get an infinite loop without any hints. Aug 31, 2015 at 11:04
• @user877329 can't really say anything to a small comment, if you can make a reproducible example, please ask a new question, posting the code. Aug 31, 2015 at 11:06
• @NormanRamsey I guess so, it's my code so it must be safe, I think... (I can't see any real downsides) Aug 14, 2019 at 22:42

I had this issue too. I used David's excellent little snippet to catch changed references. Since the log file is very long, I grepped them out with:

\$ egrep -A2 "label .* changed:" jobname.log


In my case, I found that the unstable labels were of the form pgfidnnnn, which I believe come from using the TikZ key remember picture. And they weren't changing by much. Per the manual's suggestion, I had placed \tikzstyle{every picture}+=[remember picture] in my document's preamble. I shut off this blanket option and the unstable labels disappeared.

• In my case it was the \linegoal macro from the linegoal packet which repeatedly jumped between two calculations of the remaining line width. Using a hardcoded width instead of linegoal fixed it thanks do David's code! Jul 25, 2020 at 23:06
• In my case it was the breqn package. Jan 12 at 10:23