15

Is there a macro available that will turn "1" into "first", "2" into "second", etc. Let's call this macro "wordth". Then, for example, if item number 2 in an enumerate environment is labeled by \label{item:blah}, I could write something like

The \wordth{\ref{item:blah}} item is problematic.

which would be formatted as "The second item is problematic."

(Bonus points for other languages, but I only need it for English.)

This answer points to the nth package for turning "1" into "1st", etc. The engord package also does this. Neither appears to provide fully spelled out English ordinals. In many situations only full words for ordinals, not their abbreviations, are appropriate.

This is probably a FAQ, but it's one of those things that's difficult to search. Feel free to point to a dupe question and close.

2
  • 3
    The fmtcount package should help.
    – egreg
    Jun 9, 2014 at 20:37
  • For the bonus points, fmtcount also supports French, German, Spanish, Portuguese (although there's a bug that'll be fixed in the next release), German (likewise) and, by sneakily loading itnumpar and ensuring it works with the fmtcount commands, Italian. Jun 9, 2014 at 20:48

2 Answers 2

15

You can use a combination of fmtcount (for writing the ordinal form of a counter) and refcount for extracting the number associated with a reference:

enter image description here

\documentclass{article}
\usepackage{refcount, fmtcount}

\newcommand*{\wordth}[1]{% \wordth{<reference>}
  \ordinalstringnum{\getrefnumber{#1}}}%

\begin{document}

\begin{enumerate}
  \item\label{enum:first} First item.
  \item\label{enum:second} Second item.
  \item Last item.
\end{enumerate}

See the \wordth{enum:second} item above, or item number~\ref{enum:first}.

\end{document}

Since you are using the \label-\ref system, you need to compile at least twice on the first go in order to work with settled references.

Note that \wordth{<reference>} requires a reference to some label. If you wish to reference hierarchical numbering schemes (like a subsection that is numbered 1.1) you're going to run into trouble. However, one could use zref's magic to circumvent this. It would require a little more muscle to work, including a possible interface change.

6
  • The only objective I have is the usage of the superscript.
    – yo'
    Jun 9, 2014 at 21:01
  • @tohecz That's easily fixed with the level package option. Jun 9, 2014 at 21:03
  • @NicolaTalbot Yes I know. I only now realized that I forgot to start by "+1" :)
    – yo'
    Jun 9, 2014 at 21:13
  • It looks like \ordinalstringnum rather than \ordinalnum is the macro that produces the effect I wanted. I submitted an edit that makes that substitution. With that change, it's perfect. Thanks, especially for the use of \refcount; without that, I would have just gone in circles with fmtcount.
    – Mars
    Jun 9, 2014 at 23:08
  • I want to accept this answer, but it's still not quite correct two days after the answer was posted. There was a typo or minor oversight in the original answer. When \ordinalstringnum is substituted for \ordinalnum, it will be correct, I believe. Werner, you may be busy with the real world--the delay is no problem--but I thought I'd post a reminder comment. Thanks. (If someone else with edit-acceptance power wants to verify that my edit is correct and accept it, that would solve the issue, too.)
    – Mars
    Jun 12, 2014 at 4:47
7

If this is the only way you intend to reference the item, you could incorporate \ordinalstring into \theenumi. (I'm assuming this is just for use in an enumerate environment.) For example:

\documentclass{article}

\usepackage{fmtcount}

\renewcommand{\labelenumi}{\arabic{enumi}.}
\renewcommand{\theenumi}{\ordinalstring{enumi}}

\begin{document}

\begin{enumerate}
\item First item.
\item\label{item:blah} Second item.
\item Third item.
\end{enumerate}

The \ref{item:blah} item is problematic.

\end{document}

Alternatively, scoping the change so it only affects this particular enumerate environment:

\documentclass{article}

\usepackage{fmtcount}

\begin{document}

\begin{enumerate}
\renewcommand{\labelenumi}{\arabic{enumi}.}
\renewcommand{\theenumi}{\ordinalstring{enumi}}
\item First item.
\item\label{item:blah} Second item.
\item Third item.
\end{enumerate}

The \ref{item:blah} item is problematic.

\end{document}

Both produce:

Image of result

3
  • Thanks. Nice idea. In my case, I want to be able to do both. Sometimes "blahblah number 2" is natural in a sentence, and sometimes "second" is.
    – Mars
    Jun 9, 2014 at 23:10
  • @Mars In which case Werner's answer is best :-) Jun 10, 2014 at 8:04
  • Yes, but it's good to have alternative solutions for different cases.
    – Mars
    Jun 10, 2014 at 16:33

You must log in to answer this question.

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