Text FormattingEnglish/Spanish/Any language list number to string

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User1802

English/Spanish/Any language list number to string

Post by User1802 »

Hello,

Is there a way to format an enumerated list, where the numbers show up as their string version, moreover, ending in "th", "nd", "st", e.g.

Instead of showing up like this:
1. lorem ipsum
2. dolor
...
99. sit amet
... we'll have...
First. lorem ipsum
Second. dolor
...
Ninety-ninth. sit amet
Many thanks,
VG
Last edited by User1802 on Mon Jun 20, 2011 4:24 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

English/Spanish/Any language list number to string

Post by localghost »

A possible remedy could be to use the solution from another topic [1]. There is a command \spelled defined like all those other well known numbering commands like \alph or \roman. The principal should be clear so you can adapt this to your needs.

[1] View topic: Spelled-out chapter numbers


Thorsten
User1802

English/Spanish/Any language list number to string

Post by User1802 »

Hello Thorsten,

Thanks for the provided link, however, I'm a bit in trouble with the list formatting part.

My list looks like this:

Code: Select all

\begin{enumerate}
  \item{lorem ipsum}
  \item{dolor sit amet}
\end{enumerate}
The formatting part, is this, based on the provided example link:

Code: Select all

\makeatletter
\newcommand*{\spelled}[1]{%
  \expandafter\@spelled\csname c@#1\endcsname
}
\newcommand*{\@spelled}[1]{%
  \ifcase#1\or{One}\or{Two}\or{Three}\or{Four}\or{Five}\or{Six}\or{Seven}\or{Eight}\or{Nine}\or{Ten}\else\@ctrerr\fi
}
\makeatother

\newcommand\listStyleVlads{%
	\renewcommand\theenumi{\arabic{enumi}}
	\renewcommand\labelenumi{\spelled{\theenumi}}
}
I get weird errosr whenever I try to compile the tex file, and I assume something is wrong in the way I approached the solution.

Any feedback on this is appreciated.

Many thanks,
Vladimir Ghetau
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

English/Spanish/Any language list number to string

Post by localghost »

This can be done much easier by the enumitem package.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{enumitem}
\usepackage{blindtext}

\makeatletter
\newcommand*{\spelled}[1]{%
  \expandafter\@spelled\csname c@#1\endcsname
}
\newcommand*{\@spelled}[1]{%
  \ifcase#1\or{One}\or{Two}\or{Three}\or{Four}\or{Five}\or{Six}\or{Seven}\or{Eight}\or{Nine}\or{Ten}\else\@ctrerr\fi
}
\AddEnumerateCounter{\spelled}{\@spelled}{Three}
\makeatother

\setenumerate[1]{leftmargin=4em,label={\spelled*.}} % New enumeration style set globally

\begin{document}
  \blindtext
  \begin{enumerate}
    \item \blindtext
    \item
    \item
    \item
    \item
    \item
    \item
  \end{enumerate}
\end{document}
Note that the blindtext package is only for creating dummy text, thus not part of the solution.
User1802

English/Spanish/Any language list number to string

Post by User1802 »

Hi Thorsten,

Thanks for the code, it works great. I have some questions though:

- what does this line do?

Code: Select all

\AddEnumerateCounter{\spelled}{\@spelled}{Three}
- what if I want to style only a certain list, instead of styling everything in the document. Moreover, what if I want to style only the top items of the list, and the sub-lists shouldn't be styled using this technique.

Thanks very much,
Vladimir
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

English/Spanish/Any language list number to string

Post by localghost »

vladimirghetau wrote:[…] - what does this line do?

Code: Select all

\AddEnumerateCounter{\spelled}{\@spelled}{Three}
[…]
See Section 2.3 of the enumitem manual.
vladimirghetau wrote:[…] - what if I want to style only a certain list, instead of styling everything in the document. […]
You can use local settings by optional arguments to the concerned list environment. See the manual for details.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{enumitem}
\usepackage{blindtext}

\makeatletter
\newcommand*{\spelled}[1]{%
  \expandafter\@spelled\csname c@#1\endcsname
}
\newcommand*{\@spelled}[1]{%
  \ifcase#1\or{One}\or{Two}\or{Three}\or{Four}\or{Five}\or{Six}\or{Seven}\or{Eight}\or{Nine}\or{Ten}\else\@ctrerr\fi
}
\AddEnumerateCounter{\spelled}{\@spelled}{Three}
\makeatother

\begin{document}
  \blindtext
  \begin{enumerate}[leftmargin=4em,label={\spelled*.}]
    \item \blindtext
    \item
    \item
    \item
    \item
    \item
    \item
  \end{enumerate}
\end{document}
vladimirghetau wrote:[…] Moreover, what if I want to style only the top items of the list, and the sub-lists shouldn't be styled using this technique.[…]
You mean nested lists? No problem. You can add options (or drop them) for every single list.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{enumitem}
\usepackage{blindtext}

\makeatletter
\newcommand*{\spelled}[1]{%
  \expandafter\@spelled\csname c@#1\endcsname
}
\newcommand*{\@spelled}[1]{%
  \ifcase#1\or{One}\or{Two}\or{Three}\or{Four}\or{Five}\or{Six}\or{Seven}\or{Eight}\or{Nine}\or{Ten}\else\@ctrerr\fi
}
\AddEnumerateCounter{\spelled}{\@spelled}{Three}
\makeatother

\begin{document}
  \blindtext
  \begin{enumerate}[leftmargin=4em,label={\spelled*.}]
    \item \blindtext
    \item
    \begin{enumerate}
      \item
      \item
    \end{enumerate}
    \item
    \item
  \end{enumerate}
\end{document}
User1802

English/Spanish/Any language list number to string

Post by User1802 »

Thanks Thorsten,

I'm starting to understand it better now.

I have a question on the top definition part, how can I define this list in such way that the spelled list should only be used as a label, instead of having it applied document wide.

I tried removing this line, but I get errors:

Code: Select all

\AddEnumerateCounter{\spelled}{\@spelled}{Three}
What I want to do, is use

Code: Select all

label={\spelled*.}


whenever I need it rather than having it applied document wide.

Also, If I want the nested list, one level deep list to use arabic, how can I disable the \spelled{} effect applied to it? Would I define the label differently in the main list, something like:

Code: Select all

\begin{enumerate}[label={\spelled\arabic*}]
The above didn't work.

Many thanks for your help again.

Vladimir
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

English/Spanish/Any language list number to string

Post by localghost »

vladimirghetau wrote:[…] I tried removing this line, but I get errors:

Code: Select all

\AddEnumerateCounter{\spelled}{\@spelled}{Three}
[…]
Please explain why you want to do so. You mustn't do that. This line is essential. It registers the new counter so enumitem can use it. Obviously you didn't read the passage of the manual I referred you to.
vladimirghetau wrote:[…] What I want to do, is use

Code: Select all

label={\spelled*.}


whenever I need it rather than having it applied document wide.[…]
In my last reply I have clearly shown how to that.
vladimirghetau wrote:[…] Also, If I want the nested list, one level deep list to use arabic, how can I disable the \spelled{} effect applied to it? Would I define the label differently in the main list, something like:

Code: Select all

\begin{enumerate}[label={\spelled\arabic*}
The above didn't work. […]
This can't work. Again the complete example with nested lists and different enumeration on different levels.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{enumitem}
\usepackage{blindtext}

\makeatletter
\newcommand*{\spelled}[1]{%
  \expandafter\@spelled\csname c@#1\endcsname
}
\newcommand*{\@spelled}[1]{%
  \ifcase#1\or{One}\or{Two}\or{Three}\or{Four}\or{Five}\or{Six}\or{Seven}\or{Eight}\or{Nine}\or{Ten}\else\@ctrerr\fi
}
\AddEnumerateCounter{\spelled}{\@spelled}{Three}
\makeatother

\begin{document}
  \blindtext
  \begin{enumerate}[leftmargin=4em,label={\spelled*.}]
    \item \blindtext
    \item
    \begin{enumerate}[label={\arabic*.}]
      \item
      \item
    \end{enumerate}
    \item
    \item
  \end{enumerate}
\end{document}
I think the principal should be clear now. The manual has further examples and explanations.
User1802

English/Spanish/Any language list number to string

Post by User1802 »

Hi Thorsten,

I thought the

Code: Select all

\AddEnumerateCounter{\spelled}{\@spelled}{Three}
applies "\spelled" by default to all list items. I wanted to comment it out in order to decide myself which lists (and possibly sub-lists) will have \spelled applied to their \items.

Ok, let me play around with this a bit more, I think I'm starting to get it but it's just a bit confusing as a newbie.

Thanks again for your help!

Vladimir
User1802

English/Spanish/Any language list number to string

Post by User1802 »

Thanks Thorsten for all the help.

The solution you presented is the one that works:

Code: Select all

\makeatletter
\newcommand*{\spelledEN}[1]{%
  \expandafter\@spelledEN\csname c@#1\endcsname
}
\newcommand*{\@spelledEN}[1]{%
  \ifcase#1\or{First}\or{Second}\or{Third}\or{Fourth}\or{Fifth}\or{Sixth}\or{Seventh}\or{Eighth}\or{Ninth}\or{Tenth}\or{Eleventh}\or{Twelvth}\or{Thirteenth}\or{Fourteenth}\or{Fifteenth}\or{Sixteenth}\or{Seventeenth}\or{Eighteenth}\or{Nineteenth}\or{Twentyth}\else\@ctrerr\fi
}
\AddEnumerateCounter{\spelledEN}{\@spelledEN}{Seventeenth}
\makeatother


\makeatletter
\newcommand*{\spelledES}[1]{%
  \expandafter\@spelledES\csname c@#1\endcsname
}
\newcommand*{\@spelledES}[1]{%
  \ifcase#1\or{Primera}\or{Segunda}\or{Tercera}\or{Cuarta}\or{Quinta}\or{Sexta}\or{S\'eptima}\or{Octava}\or{Novena}\or{D\'ecima}\or{Und\'ecima}\or{Duodecima}\or{D\'ecimotercera}\or{D\'ecimoquarta}\or{D\'ecimoquinta}\or{D\'ecimosexta}\or{D\'ecimos\'eptima}\or{D\'ecimoctava}\or{D\'ecimonovena}\or{Vix\'esima}\else\@ctrerr\fi
}
\AddEnumerateCounter{\spelledES}{\@spelledES}{Decimotercera}
\makeatother
In order to make a list use the spelled context:

Code: Select all

%spanish
\begin{enumerate}[label={\spelledES*.}]
\item{lorem ipsum dolor sit amet 1}
\item{lorem ipsum dolor sit amet 2}
\end{enumerate}

%english
\begin{enumerate}[label={\spelledEN*.}]
\item{lorem ipsum dolor sit amet 1}
\item{lorem ipsum dolor sit amet 2}
\end{enumerate}

Many thanks again!
Vladimir Ghetau
Post Reply