# Cross reference with ordinal numbers

I'm writing a document in a latex. In a part of this document I would like to use ordinal numbers for cross-referencing chapters and parts.

For example i would like that the code

... in the \ref{ch:firstPart} part ...


Would result in

... in the first part ...


and not

... in the I part ...


I'm not interested in modifying globally how the cross references are managed because I would like to use ordinal numbers only in part of the document.

The solution proposed in How to refer to a chapter with a word works only for chapters.

Is there a package or another solution for doing it?

• @Qrrbrbirlbel Why not :-) As soon as I don't have to define new labels because the document is quite big and already complete. – Maverik Feb 18 '13 at 17:33
• @lucaghera Please, tell if you don't need it in English; for other languages the answer linked by Werner doesn't apply. Did you change your gravatar because of yesterday? ;-) – egreg Feb 18 '13 at 17:50
• @egreg that solution is quite good, however it doesn't work for parts and I would like to have the ordinal number with the first letter not in capital case. – Maverik Feb 18 '13 at 18:00
• For lowercase you use \ordinaltoname; unfortunately this doesn't work with part numbers, because the reference is in a Roman numeral. Please, edit your question mentioning the linked one and the problem it doesn't solve, so it can be reopened. I'll keep an eye on it. – egreg Feb 18 '13 at 18:06
• @egreg done, thanks! – Maverik Feb 18 '13 at 18:12

The problem is to convert back the Roman numeral with which parts are referred to into an arabic number for \ordinaltoname from numname to work.

Happily, the LaTeX3 bundle has the \int_from_roman:n function, but we have to stretch it a bit so that it expands a \getrefnumber given as argument to it:

\documentclass{book}

\usepackage{numname}
\usepackage{refcount}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\partnumbertoname}{m}
{
\ordinaltoname { \int_from_roman:f { \getrefnumber{ #1 } } }
}
\cs_generate_variant:Nn \int_from_roman:n {f}
\ExplSyntaxOff

\begin{document}

\mainmatter
\part{Part}\label{p1}

\chapter{Chapter}\label{c1}

In the \ordinaltoname{\getrefnumber{c1}} chapter...

In the \partnumbertoname{p1} part...

\end{document}


A couple of runs are necessary, as usual, for the right name to appear.

Thanks to Heiko Oberdiek (refcount), Peter Wilson (the macros in numname) and the LaTeX3 team.