Memoir's \NumToName doesn't work with cross-referenced items

I got external references to work with memoir and hyperref here: hyperref and xr-hyper break memoir's \titleref, but references to external documents don't work with memoir \NumToName: Chapter~\NumToName{\ref{chap:example}} errors out with Missing number.

Here are the two files that show this behavior:

\documentclass[12pt]{memoir}
\usepackage{xr-hyper}
\usepackage{hyperref}

\begin{document}
\chapter{Example}\label{chap:example}

Examples
\end{document}


Call that one example.tex, run pdflatex on it, and then the second file references it:

\documentclass[12pt]{memoir}
\usepackage{xr-hyper}
\usepackage{hyperref}

\externaldocument{example}
\begin{document}
See Chapter~\NumToName{\ref{chap:example}}.
\end{document}


Compile the second file and the issue will appear.

Here's the error message I get:

! Missing number, treated as zero.
\protect
l.7     See Chapter~\NumToName{\ref{chap:example}}


How to I get a NumToName reference to an external document?

• it has to be a number, \ref generally isn't (not on the TeX level), see Karls solution. – daleif Mar 7 '14 at 13:15

You can solve this issue by loading the package refcount and substituting \ref with \getrefnumber.

To creat the link you can use the command \hyperref from the hyperref package.

In other words, rewrite your latter file as

\documentclass[12pt]{memoir}
\usepackage{xr-hyper}
\usepackage{hyperref}
\usepackage{refcount}

\externaldocument{example}
\begin{document}
See Chapter~\hyperref[chap:example]{\NumToName{\getrefnumber{chap:example}}}.
\end{document}


and you will get the expected output:

• Embarrassingly I got really close to this solution but forgot to wrap \getrefnumber itself in {} – bombcar Mar 9 '14 at 0:55