Referring an equation inside a theorem

I have theorems which LaTeX numbers and then some equations inside and outside theorems that LateX has numbered.

When I refer to an equation inside a theorem statement then LaTeX is referring to it by the theorem's number and not the equation's number.

\usepackage{amsmath}
\newtheorem{prop}[thm]{Proposition}
\begin{prop}
Blah is
$$\label{eq:Blah} B=L+a-H$$
\end{prop}

From equation ~\ref{eq:Blah} we know blah blah blah.


Suppose the proposition number is 4.1 and the equation number is 12 then my text catches 4.1 and not 12. I don't particularly care which number is catches, so long as it is consistent. So that someone reading the text can find what I am referring to.

How can I fix this?

-
I think this comes down to where you are putting your \label; in your example the reference works as expected... Presumably this is a stripped-down version of the actual problem? – cmhughes Nov 23 '12 at 21:43
By the way, if you put a real space in front of an unbreakable space ~, what you get is a regular breakable space. – T. Verron Nov 23 '12 at 22:45
Please clarify if my comment is correct, and update your question with a MWE that demonstrates the problem – cmhughes Nov 24 '12 at 0:36

Generating correct labels for referencing forms part of a two-step process:

1. A counter is increased using \refstepcounter (a "referencable" form of counter incrementation). This typically happens when you call a macro (like \section) or environment. Here's a snapshot of \refstepcounter from latex.ltx:

\def\refstepcounter#1{\stepcounter{#1}%
\protected@edef\@currentlabel
{\csname p@#1\endcsname\csname the#1\endcsname}%
}


See that \refstepcounter is a "modified \stepcounter", since it also updates \@currentlabel.

2. When inserting a \label, the default behaviour of LaTeX is to write the macro \@currentlabel and \thepage to the .aux file as arguments to \newlabel. Here's a snapshot of \label from latex.ltx:

\def\label#1{\@bsphack
\protected@write\@auxout{}%
{\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
\@esphack}


Generally speaking, \newlabel here is just a mechanism built in to check whether a label already exists/not and warn you thereof (in the form of "There were multiply-defined labels" or "Label ...' multiply defined").

So, whenever a \refstepcounter is performed, \@currentlabel is updated and therefore would change any reference created with a \label. The most commonly identified problem of this incorrect labelling is when users perform (say)

\begin{figure}
% Image stuff here
\label{mylabel}
\caption{My caption}
\end{figure}


and receive an incorrect reference to their figure. This is because \caption executes \refstepcounter and not the figure environment itself, resulting in an incorrect \@currentlabel to be written to the .aux file (whatever that may be). A practical example:

\documentclass{article}
\begin{document}
\section{A section}
See Figure~\ref{fig:ref} in section~\ref{sec:ref}.
\section{A section} Here is some text. \label{sec:ref}
\begin{figure}[bh!]
\centering\rule{.8\textwidth}{.2\textheight}
\label{fig:ref}\caption{A figure caption}
\end{figure}
\end{document}


Note how the figure reference \ref{fig:ref} returns 2 instead of 1. That's because an issue of \label{fig:ref} write \@currentlabel which is still set to 2 by the preceding \section. Switching around \label and \caption would yield the desired result (however simplistic).

Bottom line is that there's an appropriate placement of \label with respect to counters, otherwise references might be incorrect. The emphasis here denotes the fact that some environments gather content a post-process them, possibly correcting for inappropriate placements of things like \label`.

-