3

I am using a combination of refcount and fmtcount to allow chapter references to produce a string (based on the solution to Macro to generate ordinal words from numbers?). However, I have found that when using hyperref such references lose their link.

A minimal working example is:

\documentclass{book}
\usepackage{hyperref}
\usepackage{fmtcount}
\usepackage{refcount}

\newcommand{\chapterref}[1]{%
    \Numberstringnum{\getrefnumber{#1}}}

\begin{document}
\chapter{The First Chapter}\label{cha:first}
Hello, this is a chapter.

\chapter{The Second Chapter}\label{cha:second}
In Chapter~\chapterref{cha:first} we did very little indeed. In Chapter~\ref{cha:second} we have done a little more.

\end{document}

Which produces this for the second chapter:

MWE ouput

The reference produced with the \chapterref command has no link whereas the reference produced with the conventional \ref command does.

Any suggestions as to how to incorporate hyperref?

Tom Brien
  • 771

1 Answers1

5

Just wrap \hyperref around the reference:

\documentclass{book}

\usepackage{fmtcount}
\usepackage{refcount}
\usepackage[colorlinks]{hyperref}

\newcommand{\chapterref}[1]{%
  \hyperref[#1]{\Numberstringnum{\getrefnumber{#1}}}%
}

\begin{document}
\chapter{The First Chapter}\label{cha:first}
Hello, this is a chapter.

\chapter{The Second Chapter}\label{cha:second}

In Chapter~\chapterref{cha:first} we did very little indeed.
In Chapter~\ref{cha:second} we have done a little more.

\end{document}

enter image description here

egreg
  • 1,121,712
  • @TomBrien: Perhaps you did not have hyperref after the other packages ;-) –  Mar 10 '15 at 15:21
  • Actually no I went through the undo history, it was fine except the braces for hyperref were misplaced. Oh well live and learn – Tom Brien Mar 10 '15 at 15:43