1

I'd like to use memoir's \ordinaltoname to refer to a specific item in an enumerated block. The item is marked with a label command. The naive code fails to compile, apparently because the label is undefined on the first pass and \ordinaltoname doesn't know what to do. Consider the following MWE:

\documentclass{memoir}

\title{Title}
\author{Author}
\date{\today}

\begin{document}
\frontmatter

\mainmatter

\begin{enumerate}
 \item{}\label{por:existence}First point;
 \item{}\label{por:defn}Second point;
 \item{}\label{por:associativity}Third point.
\end{enumerate}

\ordinaltoname{\ref{por:existence}}

\backmatter


\end{document}

Upon compiling,

[78] Yeah? pdflatex mwe
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./mwe.tex
LaTeX2e <2018-04-01> patch level 5
(/usr/local/texlive/2018/texmf-dist/tex/latex/memoir/memoir.cls
Document Class: memoir 2018/04/04 v3.7g configurable book, report, article docu
ment class
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2018/texmf-dist/tex/latex/ifetex/ifetex.sty
(/usr/local/texlive/2018/texmf-dist/tex/plain/ifetex/ifetex.tex))
(/usr/local/texlive/2018/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/local/texlive/2018/texmf-dist/tex/latex/memoir/mem10.clo))
No file mwe.aux.
! Missing number, treated as zero.
<to be read again> 
                   \protect 
l.23 \ordinaltoname{\ref{por:existence}}

? 

What is the correct way to convert a label reference to a number usable in a command like ordinal?

Werner
  • 603,163
lsfinn
  • 123

1 Answers1

1

This is similar in nature to Macro to generate ordinal words from numbers?. You can get by using with refcount's \getrefnumber, which is expandable:

enter image description here

\documentclass{memoir}

\usepackage{refcount}

\begin{document}

\begin{enumerate}
  \item \label{por:existence}
    First point;
  \item \label{por:defn}
    Second point;
  \item \label{por:associativity}
    Third point.
\end{enumerate}

This reference points to the \ordinaltoname{\getrefnumber{por:existence}} element.

\end{document}
Werner
  • 603,163