My document has chapters and sections. When I refer to sections in the same chapter I write \ref{section_label} when I refer to section in a different chapter I write \ref{chapter_label}.\ref{section_label}. On paper this has the desired effect.

Unfortunately, hyperref produce (of course) two different links in place o one. So replace the latter reference with


This produces the desired behavior in some viewer (Okular, Evince) but it has no effect on others (PDF.js).

I don't think the 'hack' above is a correct use of hyperref. Any suggestion?

  • 3
    did you check cleverref or varioref?
    – Johannes_B
    Commented Apr 30, 2017 at 9:32
  • 1
    Not a solution, but I really find it confusing to mix and match the reference. You should be consistent and use the same notation throughout your paper, possibly with varioref which integrates the page number in the reference, or with the customizations of cleveref
    – Moriambar
    Commented Apr 30, 2017 at 9:39
  • Something like here? tex.stackexchange.com/questions/356248/… or here: tex.stackexchange.com/questions/353491/… ?
    – user31729
    Commented Apr 30, 2017 at 9:40
  • 3
    I'd say \ref*{chapter_label}.\ref{section_label}
    – egreg
    Commented Apr 30, 2017 at 9:44
  • Why do you want that? Doesn't \ref{section_label} already contain the chapter number?
    – Arzigoglu
    Commented Apr 30, 2017 at 9:59

1 Answer 1


Normally formatting is done by \label (actually \refstepcounter). One could use multiple labels depending on how one wanted the reference to look. This uses the same \mylabel macro used here.

Hyperref uses its own labels which can be found using \getrefbykeydefault. Also, \ref is protected (will not expand until printed), so if you want to use it in a macro you need to use \getrefnumber instead. See refcount manual.

I threw in egreg's solution for comparison.


\renewcommand{\thesection}{\arabic{section}}% non-standard definition

  {\newcommand{\mylabel}[2]% #1=name, #2 = contents
  {\newcommand{\mylabel}[2]% #1=name, #2 = contents

\newcommand{\getrefanchor}[1]% #1 = label


One can use \ref*{chapter}.\ref{section}, \ref{mylabel} or 

  • @egreg 's solution is what I was looking for. Thank you! Commented Apr 30, 2017 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .