# Warning: Label(s) may have changed with breqn

In a document I am preparing I make extensive use of the breqn package. However, this seems to cause a problem when I attempt to use math inside of captions. An MWE:

\documentclass[11pt,oneside,openright,a4paper]{memoir}

\usepackage[T1]{fontenc}
\usepackage{etoolbox}

% Equation breaking
\usepackage{breqn}

% Add support for automatic equation breaking
\gdef\wrap@breqn@environ#1#2{
\expandafter\let\csname
breqn@oldbegin@#1\expandafter\endcsname\csname #1\endcsname
\expandafter\let\csname
breqn@oldend@#1\expandafter\endcsname\csname end#1\endcsname
\expandafter\gdef\csname breqn@begin@#1\endcsname{%
\expandafter\let\csname #1\expandafter\endcsname\csname
breqn@oldbegin@#1\endcsname%
\begin{#2}%
}
\expandafter\gdef\csname breqn@end@#1\endcsname{%
\expandafter\let\csname end#1\expandafter\endcsname\csname
breqn@oldend@#1\endcsname%
\end{#2}%
\expandafter\let\csname #1\expandafter\endcsname\csname
breqn@begin@#1\endcsname%
\expandafter\let\csname end#1\expandafter\endcsname\csname
breqn@end@#1\endcsname%
}
\expandafter\let\csname #1\expandafter\endcsname\csname
breqn@begin@#1\endcsname
\expandafter\let\csname end#1\expandafter\endcsname\csname
breqn@end@#1\endcsname
}
\wrap@breqn@environ{equation}{dmath}
\wrap@breqn@environ{equation*}{dmath*}

\makeatletter
\AtBeginDocument{
\catcode_=12
\begingroup\lccode~=_
\lowercase{\endgroup\let~}\sb
\mathcode_="8000
\immediate\write\@auxout{\catcode_=12 }
}
\makeatother

\begin{document}

\begin{figure}
Foo
\caption{\label{fig:sumrcpint}Graphical illustration of how  $\sum_{r = m +1}^n r^{-k} < \int_{m}^{\infty} r^{-k} d r$.}
\end{figure}

\end{document}


which seems to perpetually generate a warning that the labels may have changed. However, the .aux file remains unchanged.

• I am unable to reproduce the issue you've raised, i.e., I can't seem to get a warning about labels having changed. Which TeX distribution, and which version of breqn, do you use? (I have MacTeX2016 on my system.) – Mico Sep 25 '16 at 7:38
• @Mico: TexLive 2015 through MacTex. – Freddie Witherden Sep 25 '16 at 14:55
• Thanks for providing this piece of information. I trust @egreg's solution has solved the issue, right? – Mico Sep 25 '16 at 15:34
• @Micro: Yes, although I still have not been able to test with TexLive 2016 to see if it works out of the box. – Freddie Witherden Sep 28 '16 at 14:04

A more minimal example:

\documentclass{memoir}
\usepackage{breqn}

\begin{document}

\begin{figure}
\caption{$a^b$\label{foo}}
\end{figure}

\end{document}


Note that the issue disappears if article is used, instead of memoir.

\immediate\write\@auxout{\catcode^=12 }%


\makeatletter
\catcode_=12
\begingroup\lccode~=_
\immediate\write\@auxout{\catcode_=12 }% <-- add this