# \ref doesn't work in math mode if hyperref and bidi packages are loaded [closed]

Is \ref supposed to work in math mode? If hyperref and bidi are loaded, it generates errors:

\documentclass{article}
\usepackage{hyperref}
\usepackage{bidi}
\begin{document}

Testing labels with \verb+hyperref+ and \verb+bidi+.

\section{This is a section}
\label{sec}

$$a = b \label{eq}$$

In text mode everything works fine.  Referencing equation~\ref{eq} in section~\ref{sec}.

But if we try to do it in math mode, we get errors:  $\ref{eq}$

$\ref{sec}$

$\ref{eq}$

$\ref{sec}$

\end{document}

• And is \ref -- which essentially returns a text-mode contents -- supposed to work in math mode? – yo' Feb 28 '13 at 0:21
• @tohecz It does work if no extra packages are loaded. Is that just a fluke? – Ari Brodsky Feb 28 '13 at 0:26

This issue is now fixed in version 12.2 of bidi package which is now on CTAN. Please for future, do not report bidi issues here; it is very hard for us to search Internet and hunt down who has got problem and who has not. Instead, please do as stated in README file of bidi package.
I don't know why it happens, but enclosing \ref in \mbox seems to cure the disease:
$\mbox{\ref{sec}}$

it seems that the combination of hyperref and bidi doesn't like xrefs in math. you can \usepackage{amstext} and then \text{\ref{...}}.