[Tex/LaTex] Referencing formula before defining it

cross-referencingequationshyperref

I'm writing a scientific article and I would like to reference a formula before it appears in the text. In principle it should work, the problem is that I want to use the hyperref package, so that I can create a hyperlink to that formula. This is the code I'm using:

F is defined in Formula \ref{eq:Fdef} \\

\begin{equation} \label{eq:Fdef}
F = RU
\end{equation}

If I use \usepackage{hyperref} at the beginning of the document I obtain the following error:

! Paragraph ended before \Hy@setref@link was complete.

I thought that maybe there was some way of defining the equation before, but including it in the text later, but I didn't find how to do it, any suggestion?

Best Answer

The fix is obtained by removing the \\ from the line, following the \ref.

As I commented, the use of \\ is specialized for things like tabular and should generally be avoided in normal text. See David's answer at When to use \par and when \\, or blank lines for a better discussion.

I don't know what hyperref did to actually make the code break by placing a \\ immediately following a \ref, but since it is bad LaTeX to use it, good grammar takes care of the problem.

As barbara adds, an equation environment is generally not preceded by a paragraph break.

And, as egreg adds, the "F" in the text should be $F$ to place it in math mode.

\documentclass{article}
\usepackage{hyperref}
\begin{document}
$F$ is defined in Formula \ref{eq:Fdef}
\begin{equation} \label{eq:Fdef}
F = RU
\end{equation}
\end{document}

enter image description here