- LaTeX Cookbook
- Stefan Kottwitz
- 463字
- 2021-07-09 21:25:00
Converting numbers to words
Numbers are sometimes written in words rather than using numerals. LaTeX is capable of automatically converting numbers to words. This is especially useful for values which originate from LaTeX counters, such as page or section numbers.
How to do it...
Load the fmtcount
package and use its commands for conversion:
- Start with any document class, such as
article
:\documentclass{article}
- Load the
fmtcount
package:\usepackage{fmtcount}
- Begin the document:
\begin{document}
- Write some text. Use the following instructions:
- Whenever you'd like to convert a number to a word, use the command
\numberstringnum
. - To print a counter value as a word, use
\numberstring
. - For a similar purpose, but in ordinal form, use
\ordinalstringnum
or\ordinalstring
. Let's take a look at the following commands:This document should have \numberstringnum{32} pages, now we are on page \numberstring{page} in the \ordinalstring{section} section.
- Whenever you'd like to convert a number to a word, use the command
- End the document:
\end{document}
- Compile the document. All numbers and counters are displayed as text, so you will get the following output:
This document should have thirty-two pages. Now we are on page one in the first section.
How it works...
The fmtcount
package provides a set of commands that print out numbers as words:
\ordinalstring{counter}
: This prints the value of a counter as an ordinal in text\numberstring{counter}
: This prints the counter's value as text\ordinalstringnum{number}
and\numberstringnum{number}
: These two commands do the same job, but based on an actual number instead of a counter\Ordinalstring{counter}
,\Numberstring{counter}
,\Ordinalstringnum{number}
, and\Numberstringnum{number}
: These are the capitalized versions; they print the initial letter in uppercase
There's more...
The fmtcount
package has even more to offer, such as multilingual capabilities, gender support, and support for new enumeration styles. We shall take a look at these features now.
The fmtcount
package supports several languages, such as English, Spanish, Portuguese, French, German, and Italian. It tries to detect the language option that has already been passed to the babel
or polyglossia
packages. You can explicitly load required definitions by typing the \FCloadlang{language}
command in the preamble, with a language name understood by the babel
package.
All the preceding commands support an optional gender argument at the end, taking one of the following values: m
(masculine), f
(feminine), or n
(neuter). It is used such as in the \numberstring{section}[f]
command. Masculine
is the default.
The moreenum
package provides new enumeration styles based on the fmtcount
package. Here's an example:
\documentclass{article} \usepackage{moreenum} \begin{document} \begin{enumerate}[label=\Nthwords*] \item live \item long \item prosper \end{enumerate} \end{document}
The items will be numbered first, second, and third, together with a dot. A label command \Nwords*
would print One
, Two
, Three
, with a dot. Also, here, there are lowercase versions, starting with a small letter n.
Besides the fmtcount
command, this builds on the enumitem
package, and so provides a similar key=value
interface.
- Android Jetpack開發(fā):原理解析與應(yīng)用實(shí)戰(zhàn)
- HTML5 移動(dòng)Web開發(fā)從入門到精通(微課精編版)
- iOS開發(fā)實(shí)戰(zhàn):從零基礎(chǔ)到App Store上架
- Python自然語言處理(微課版)
- Mastering LibGDX Game Development
- Bootstrap Essentials
- C語言課程設(shè)計(jì)
- 大數(shù)據(jù)分析與應(yīng)用實(shí)戰(zhàn):統(tǒng)計(jì)機(jī)器學(xué)習(xí)之?dāng)?shù)據(jù)導(dǎo)向編程
- Mastering Xamarin.Forms(Second Edition)
- RealSenseTM互動(dòng)開發(fā)實(shí)戰(zhàn)
- Vue.js 2 Web Development Projects
- Python項(xiàng)目實(shí)戰(zhàn)從入門到精通
- INSTANT Silverlight 5 Animation
- Django實(shí)戰(zhàn):Python Web典型模塊與項(xiàng)目開發(fā)
- Oracle Database XE 11gR2 Jump Start Guide