1

I'm trying to make cross referencing to a forward part in my document using \hyperref[<to_label>]{<link_text>} but it seems because of \label{} is ahead of \hyperref, that's not defined when code is compiled, so the link does not work properly.

I'm using this code to include enumerate environment items in equations numbering

\counterwithin*{equation}{section}
\counterwithin*{equation}{subsection}
\counterwithin*{equation}{enumi}
\usepackage{chngcntr,etoolbox}
\newif\ifinenumerate
    \AtBeginEnvironment{enumerate}{\inenumeratetrue}

\makeatletter
\renewcommand\theequation{%
  \ifnum\value{subsection}>0 \thesubsection.\else
  \ifnum\value{section}>0 \thesection.\fi\fi
  \ifinenumerate \theenumi\fi
  \arabic{equation}}

\renewcommand\thefigure{%
  \ifnum\value{subsection}>0 \thesubsection.\else
  \ifnum\value{section}>0 \thesection.\fi\fi
  \ifinenumerate \theenumi\fi
  \roman{figure}}
\makeatother

And this is my hyperref setup

\usepackage[colorlinks=false]{hyperref}
\hypersetup{
    pdftitle={...},
    pdfauthor={...},
    pdfsubject={...},
    pdfkeywords={...},
}

Here is a working example; as you can check my cross reference carries to last equation referenced instead of \label what I've defined.

\documentclass[8pt,a4paper,dvipsnames]{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,hmargin=2cm,vmargin={2cm,2.5cm}]{geometry}
\usepackage[colorlinks=false]{hyperref}
\hypersetup{
    pdftitle={...},
    pdfauthor={...},
    pdfsubject={...},
    pdfkeywords={...},
}
\usepackage{enumitem}
\usepackage{chngcntr}
\usepackage{cleveref}

\counterwithin*{equation}{section}
\counterwithin*{equation}{subsection}
\counterwithin*{equation}{enumi}

\usepackage{etoolbox}

\newif\ifinenumerate
\AtBeginEnvironment{enumerate}{\inenumeratetrue}

\makeatletter
\renewcommand\theequation{%
  \ifnum\value{subsection}>0 \thesubsection.\else
  \ifnum\value{section}>0 \thesection.\fi\fi
  \ifinenumerate \theenumi\fi
  \arabic{equation}}
\makeatother

\begin{document}
\section{test 1}
\subsection{test 1.1}
\begin{enumerate}[label=\alph*.]
\item item a
    \begin{itemize}
        \item item a case 1         
        \begin{equation}
        a = b
        \end{equation}              
        \begin{itemize}
        \item item a case 1 subcase 1       
        \begin{equation}
        a = b
        \end{equation}
        I need to reference \hyperref[not:Note1]{forward}
        \end{itemize}
    \end{itemize}
In here, for example \label{not:Note1}
\end{enumerate}
\end{document}
jfernandz
  • 881
  • 2
    all latex and hyperref cross referencing allows forward and backward references. please show a complete (small) document that fails otherwise impossible to guess what you did wrong. – David Carlisle Nov 02 '16 at 13:02
  • 2
    Please provide compilable LaTeX code that generates the problem behavior you're looking to fix. Please be sure to state which document class you and with which options hyperref is loaded. – Mico Nov 02 '16 at 13:02
  • 3
    a forward reference will not resolve with the first run. however, the value of the label will be placed in the .aux file, which is read in on subsequent runs, so after that is available, the reference should appear. – barbara beeton Nov 02 '16 at 13:12
  • 2
    Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – samcarter_is_at_topanswers.xyz Nov 02 '16 at 13:24
  • @barbarabeeton here is the .aux of this MWE http://pastebin.com/p9X22365 – jfernandz Nov 02 '16 at 13:57
  • 2
    there isn't anything to link to where you have the \label{not:Note1}. you need to establish a proper target. does this answer help: Link to arbitrary part of text?? – barbara beeton Nov 02 '16 at 14:23
  • Is this question still 'alive' or shall we vote to close it as 'unclear'? –  Jan 18 '17 at 17:34
  • It is clear with @barbarabeeton answer, I think. – jfernandz Jan 26 '17 at 17:26

1 Answers1

2

a better strategy, for something that doesn't have an obvious "anchor" (like a section heading or equation number) is to use a \hypertarget and \hyperlink pair. this is explained with a nice example in an answer to this question: Link to arbitrary part of text?

(trivial answer provided for question closed as duplicate.)