Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Counting in words

6 views
Skip to first unread message

Andrew Thornton

unread,
Jan 23, 2002, 11:13:14 AM1/23/02
to
Hi!
I'm probably being useless, but I can't seem to find a package that will
display the value of counters in words, e.g. one, two, three...

Does such a package exist?

Thanks,

andy

--
ar...@cam.ac.uk --- Assistant Technical Director --- Queens' Bats
``So many questions, so few fish.''

Peter Wilson

unread,
Jan 23, 2002, 3:14:17 PM1/23/02
to

"Andrew Thornton" <ar...@spamtrap.cam.ac.uk> wrote in message
news:a2mneq$9gq$1...@pegasus.csx.cam.ac.uk...

> Hi!
> I'm probably being useless, but I can't seem to find a package that
will
> display the value of counters in words, e.g. one, two, three...
>
> Does such a package exist?

I don't know about a package, but the memoir class has a command to
print counters from 1 to 99 (one to ninety nine).

Peter W.

Bill Henry III Gates

unread,
Jan 23, 2002, 5:07:43 PM1/23/02
to
ar...@spamtrap.cam.ac.uk (Andrew Thornton) wrote in
news:a2mneq$9gq$1...@pegasus.csx.cam.ac.uk:

my advice is to make a pdf/dvi and then convert it to ascii (with existing
tools) and then do a wordcount either from your editor or "wc" if you are on
a unix

--
-kbg

Donald Arseneau

unread,
Jan 23, 2002, 5:13:38 PM1/23/02
to
ar...@spamtrap.cam.ac.uk (Andrew Thornton) writes:

> I'm probably being useless, but I can't seem to find a package that will
> display the value of counters in words, e.g. one, two, three...

Did inwords.sty ever get onto ctan? Seems not.

It looks a bit outdated on the \ref patches. Try it and see though.


% inwords.tex or inwords.sty -- convert a number into words (in English)
%
% Usage: \inwords{...} \Cap\inwords{...}
%
% where ... is the number to be converted. Specifying \Cap capitalizes
% the first letter of the first word, as for the beginning of a sentence.
%
% Example:
%
% The number \inwords{314159265} is very large.
%
% produces
%
% The number three hundred fourteen million one hundred fifty-nine
% thousand two hundred sixty-five is very large.
%
% by Raymond Chen
%-----------------
%% change to avoid doubled spaces, allow zero or negative, and
%% allow capitalization via \Cap -- Donald Arseneau
%-----------------

\edef\CategoricallyNot{\the\catcode`\@}
\catcode`\@=11

\def\undertwenty#1{\expandafter \C@
\ifcase#1\relax\or one\ \or two\ \or three\ \or four\ \or five\ \or
six\ \or seven\ \or eight\ \or nine\ \or ten\ \or eleven\ \or twelve\ \or
thirteen\ \or fourteen\ \or fifteen\ \or sixteen\ \or seventeen\ \or
eighteen\ \or nineteen\ \fi}

% The careful sidestepping involved in \count@=#1 \allocationnumber=\count@
% is to make sure the right thing happens, even if #1=\count@ or
% #1=\allocationnumber.
%
% We use \allocationnumber as a scratch count variable. It and \count@
% are always used inside a group, so their original values will be
% restored when the macros finish their job.

\def\underhundred#1{\ifnum#1<20 \undertwenty{#1}\else
{\count@#1\relax \allocationnumber\count@ \divide\count@ 10
\expandafter \C@
\ifcase\count@ \or\or twenty\or thirty\or forty\or fifty\or sixty\or
seventy\or eighty\or ninety\fi
\multiply\count@ 10
\advance\allocationnumber by-\count@
\ifnum\allocationnumber>\z@ -\penalty\exhyphenpenalty
\undertwenty\allocationnumber \else\ \fi
}\fi}

\def\numbersplit#1#2#3#4#5{%
\ifnum#5<#1\relax#2{#5}\else
{\count@#5\relax \allocationnumber\count@ \divide\count@ #1\relax
#3\count@#4\multiply\count@ #1\relax
\advance\allocationnumber-\count@ #2\allocationnumber
}\fi}

\def\underthousand{\numbersplit{100}\underhundred\undertwenty{hundred\ }}
\def\undermillion{\numbersplit\@m\underthousand\underthousand{thousand\ }}
\def\underbillion{\numbersplit{1000000}\undermillion\underthousand{million\ }}

\def\inwords#1{\ifmmode\hbox\fi{\ifnum#1=\z@ \C@ zero\ \else\ifnum#1<\z@ \C@ negative\ %
\numbersplit{1000000000}\underbillion\underthousand{billion\ }{-#1}\else
\numbersplit{1000000000}\underbillion\underthousand{billion\ }{#1}\fi\fi
\unskip}}

\def\Cap{\global\let\C@\C@pit}
\def\C@pit#1{\uppercase{#1}\global\let\C@\relax}
\global\let\C@\relax

%
% This can be used for displaying LaTeX counters:
% \renewcommand\theequation{\protect\inwords{\arabic{equation}}}
% but will not work with \ref unless the following patch is made:
%


%% RmS 91/10/25: added a few extra \reset@font,
%% as suggested by Bernd Raichle

% DJA 93/02/02: Suggested changes to \ref:
% combine functions in \@metaref
% get rid of \edef so fragile commands don't break
% use \csname instead of \@nameuse to reduce number of \expandafters

\def\ref#1{\@metaref\@car{#1}}
\def\pageref#1{\@metaref\@cdr{#1}}

\def\@metaref#1#2{\expandafter\ifx\csname r@#2\endcsname\relax
{\reset@font\bf ??}\@warning
{Reference `#2' on page \thepage \space undefined}%
\else
\expandafter\expandafter\expandafter #1\csname r@#2\endcsname\@nil\null
\fi}

\catcode`\@=\CategoricallyNot \let\CategoricallyNot\undYfined


Donald Arseneau as...@triumf.ca

Georg Kraml

unread,
Jan 23, 2002, 5:43:39 PM1/23/02
to
Andrew Thornton wrote:
> I'm probably being useless, but I can't seem to find a package that will
> display the value of counters in words, e.g. one, two, three...

Here's something that *may* solve your problem. It's inefficient [1],
it's quite ineptly formatted, it uses \global\def macros as
scratch pads; however, it *appears* to work.

\writenumber{0} => zero
\writenumber{42} => fourty-two
\writenumber{1086089} => one million eighty-six thousand eighty-nine
\writenumber{2000000} => two million

Forgive me if I botched the spelling.


% start
\newcount\scratch
\newcount\counta
\newcount\countb
\newcount\countc
\outer\def\writenumber#1{%
\def\defaultnumber{zero}%
\def\whitespace{}%
\counta=#1%
\countb=\counta\divide\countb by1000000000%
\writegroup{\countb}{\ billion}%
\multiply\countb by1000000000\advance\counta by-\countb%
\countb=\counta\divide\countb by1000000%
\writegroup{\countb}{\ million}%
\multiply\countb by1000000\advance\counta by-\countb%
\countb=\counta\divide\countb by1000%
\writegroup{\countb}{\ thousand}%
\multiply\countb by1000\advance\counta by-\countb%
\writegroup{\counta}{}%
\defaultnumber}
\def\writegroup#1#2{%
\countc=#1\scratch=\countc%
\ifnum\countc=0\else%
\global\def\defaultnumber{}%
\divide\scratch by100 %
\ifnum\scratch>0 %
\whitespace%
\writedigit{\scratch} hundred%
\global\def\whitespace{\ }%
\fi%
\multiply\scratch by100\advance\countc by-\scratch\scratch=\countc%
\divide\scratch by10 %
\ifnum\scratch>1 %
\whitespace%
\global\def\whitespace{-}%
\ifcase\scratch {}%
\or {}%
\or twenty%
\or thirty%
\or fourty%
\or fifty%
\or sixty%
\or seventy%
\or eighty%
\or ninety%
\fi%
\multiply\scratch by10\advance\countc by-\scratch%
\fi%
\ifnum\countc>0 %
\whitespace%
\global\def\whitespace{\ }%
\writedigit{\countc}%
\fi%
#2%
\global\def\whitespace{ }\fi}
\def\writedigit#1{%
\ifcase#1 zero%
\or one%
\or two%
\or three%
\or four%
\or five%
\or six%
\or seven%
\or eight%
\or nine%
\or ten%
\or eleven%
\or twelve%
\or thirteen%
\or fourteen%
\or fifteen%
\or sixtreen%
\or seventeen%
\or eightteen%
\or nineteen%
\else ??%
\fi}
% stop


(I had a much more elegant solution that worked recursively (i. e.,
"deal with the first digit, slice it off, hand whatever remains to
yourself"); unfortunately, it tended to smash the Tex stack.)

HTH,
Georg


--
Georg Kraml ge...@ads.tuwien.ac.at

Robin Fairbairns

unread,
Jan 23, 2002, 5:58:12 PM1/23/02
to
Donald Arseneau <as...@triumf.ca> wrote:
>ar...@spamtrap.cam.ac.uk (Andrew Thornton) writes:
>> I'm probably being useless, but I can't seem to find a package that will
>> display the value of counters in words, e.g. one, two, three...
>
>Did inwords.sty ever get onto ctan? Seems not.

ooh, i remember inwords.sty; i tried to convert it to produce english
(as opposed to american) numbers, and failed.

wonder if i could do it now...
--
Robin Fairbairns, Cambridge -- rf10 at cam dot ac dot uk

Andrew Thornton

unread,
Jan 23, 2002, 9:46:33 PM1/23/02
to
On 23 Jan 2002, you wrote in comp.text.tex:

>ar...@spamtrap.cam.ac.uk (Andrew Thornton) writes:
>
>> I'm probably being useless, but I can't seem to find a package that
>> will
>> display the value of counters in words, e.g. one, two, three...
>
>Did inwords.sty ever get onto ctan? Seems not.
>
>It looks a bit outdated on the \ref patches. Try it and see though.

I'm not really doing anything special. I just really wanted something like
the book class but with words instead of numbers for the chapters and a few
other heading differences. inwords.sty seems to work for this. Any ideas
why it was left off CTAN?

Thanks for the help,

Donald Arseneau

unread,
Jan 24, 2002, 1:48:29 AM1/24/02
to
ar...@spamtrap.cam.ac.uk (Andrew Thornton) writes:

> other heading differences. inwords.sty seems to work for this. Any ideas
> why it was left off CTAN?

It pre-dates ctan, and its original author has not been heard from.

I think the change to \ref will screw up things like babel and hyperref.

Donald Arseneau as...@triumf.ca

Henrik Holm

unread,
Jan 24, 2002, 2:35:45 AM1/24/02
to
[Robin Fairbairns]

> ooh, i remember inwords.sty; i tried to convert it to produce english
> (as opposed to american) numbers,

what is the difference?

(sorry for being OT, but it is very interesting, especially
for one who doesn't speak any of the languages natively, and
who struggles hard in order to be consistent in his writing.)


Henrik.

Henrik Holm

unread,
Jan 24, 2002, 2:37:50 AM1/24/02
to
[Andrew Thornton]

> I'm not really doing anything special. I just really wanted
> something like the book class but with words instead of
> numbers for the chapters and a few other heading
> differences. inwords.sty seems to work for this.

Note that the memoir class gives you this very easily.


Henrik.

Robin Fairbairns

unread,
Jan 24, 2002, 3:10:36 AM1/24/02
to
Henrik Holm <h.h...@spray.no> wrote:
>[Robin Fairbairns]
>
>> ooh, i remember inwords.sty; i tried to convert it to produce english
>> (as opposed to american) numbers,
>
>what is the difference?

"large" english numbers have the occasional conjunction in them --
"one hundred _and_ one", for example.

>(sorry for being OT, but it is very interesting, especially
>for one who doesn't speak any of the languages natively, and
>who struggles hard in order to be consistent in his writing.)

i doubt most americans know the difference either, but it's hard for
an englishman to avoid exposure to american numbers and american dates
(a salesman[*] at my work once nearly missed an important date because
of quoting it in english ... it became company policy never to quote
dates using numbers alone).

[*] one of the intelligent ones. they _do_ exist...

Robin Fairbairns

unread,
Jan 24, 2002, 4:52:04 AM1/24/02
to
Andrew Thornton <ar...@spamtrap.cam.ac.uk> wrote:

>On 23 Jan 2002, [donald] wrote in comp.text.tex:
>>
>>Did inwords.sty ever get onto ctan? Seems not.
>>
>>It looks a bit outdated on the \ref patches. Try it and see though.
>
>I'm not really doing anything special. I just really wanted something like
>the book class but with words instead of numbers for the chapters and a few
>other heading differences. inwords.sty seems to work for this. Any ideas
>why it was left off CTAN?

actually, it wasn't: it (or some variant of it) is in both
digests/tex-mag/v5.n2 and .n3 -- i leave as an exercise to the reader
the matter of finding what the differences are...

donald suggests raymond chen is no longer contactable: i would be
surprised if this was truly the case -- he has a significant web
presence. if someone else can track him down and get permission, i'm
sure we'll be happy to install the macros as a separate file on ctan.

Peter Wilson

unread,
Jan 24, 2002, 11:11:16 AM1/24/02
to

"Andrew Thornton" <ar...@spamtrap.cam.ac.uk> wrote in message
news:a2nsi9$dn0$1...@pegasus.csx.cam.ac.uk...

> On 23 Jan 2002, you wrote in comp.text.tex:
>
> >ar...@spamtrap.cam.ac.uk (Andrew Thornton) writes:
> >
> >> I'm probably being useless, but I can't seem to find a package that
> >> will
> >> display the value of counters in words, e.g. one, two, three...
> >
> >Did inwords.sty ever get onto ctan? Seems not.
> >
> >It looks a bit outdated on the \ref patches. Try it and see though.
>
> I'm not really doing anything special. I just really wanted something like
> the book class but with words instead of numbers for the chapters and a
few
> other heading differences. inwords.sty seems to work for this. Any ideas
> why it was left off CTAN?
>

The memoir class includes several chapter styles, one of which uses
words instead of numbers.

Peter W.

Dan Luecking

unread,
Jan 24, 2002, 3:34:52 PM1/24/02
to
r...@pallas.cl.cam.ac.uk (Robin Fairbairns) wrote in message news:<a2ofhs$s03$1...@pegasus.csx.cam.ac.uk>...

> Henrik Holm <h.h...@spray.no> wrote:
> >[Robin Fairbairns]
> >
> >> ooh, i remember inwords.sty; i tried to convert it to produce english
> >> (as opposed to american) numbers,
> >
> >what is the difference?
>
> "large" english numbers have the occasional conjunction in them --
> "one hundred _and_ one", for example.

While I was taught (in american schools) _not_ to insert such
conjuntions, the vast majority of Americans do seem to use them.
Even I use them in common speaking, but not (when I am careful) in
formal writing. Actually, for numbers large enough to need a
conjuction I would use numerals.

>
> >(sorry for being OT, but it is very interesting, especially
>

> i doubt most americans know the difference either,

I certainly didn't know the practice was "English", I thought it
was just "informal".

but it's hard for
> an englishman to avoid exposure to american numbers and american dates
> (a salesman[*] at my work once nearly missed an important date because
> of quoting it in english ... it became company policy never to quote
> dates using numbers alone).
>
> [*] one of the intelligent ones. they _do_ exist...

Hard to believe...

Dan Luecking

Jules Bean

unread,
Jan 25, 2002, 3:40:39 AM1/25/02
to
Dan Luecking wrote:

> I certainly didn't know the practice was "English", I thought it
> was just "informal".


It's definitely formal here.

If you get a printed cheque from (e.g.) a bank (or a banker's draft, or
a building society cheque, etc), it has (sometimes) a field called
"Amount in words", and then you definitely see some conjunctions. As
in, for example, "ONE THOUSAND FOUR HUNDRED AND FIFTY FIVE POUNDS"

Jules

Jeffrey Goldberg

unread,
Jan 25, 2002, 8:01:02 AM1/25/02
to
On Jan 24, 2002 Robin Fairbairns <r...@pallas.cl.cam.ac.uk> wrote
in <a2ofhs$s03$1...@pegasus.csx.cam.ac.uk>:

> "large" english numbers have the occasional conjunction in them --
> "one hundred _and_ one", for example.

American ones do in speech. It is only a prescriptive rule to omit them
in writing. I don't think anybody would refer to the Disney movie as "one
hundred one dalmations".

> (a salesman[*] at my work once nearly missed an important date because
> of quoting it in english ... it became company policy never to quote
> dates using numbers alone).

I "won" credit at Amazon.com in its early days for recommending that they
don't post dates only in (American style) numbers, but spell out the
month. My problem now is that I've become so confused about the different
conventions, that it would take me a conscious effort to get the numbers
right even for the culture where I was born, raised and currently live.
If I have to use numbers, I use ISO dating. There are hard boiled eggs in
the 'fridge with IS0 dates written on them.

-j

--
Jeffrey Goldberg http://www.goldmark.org/jeff/
Relativism is the triumph of authority over truth, convention over justice
I rarely read top-posted, over-quoting or HTML postings.

Michele Dondi

unread,
Jan 25, 2002, 10:18:16 AM1/25/02
to

Is it configured to work with babel?
I know I can try, but I'm at "work" now...


Michele
--
Liberta' va cercando, ch'e' si' cara,
Come sa chi per lei vita rifiuta.
[Dante Alighieri, Purg. I, 71-72]

I am my own country - United States Confederate of Me!
[Pennywise, "My own country"]

Peter Flynn

unread,
Jan 27, 2002, 10:51:58 AM1/27/02
to
Henrik Holm wrote:

> [Robin Fairbairns]
>
>
>> ooh, i remember inwords.sty; i tried to convert it to produce english
>> (as opposed to american) numbers,
>>
>
> what is the difference?

American numbers are all preceded by a dollar sign and only measure cubits.

:-)

///Peter

0 new messages