% \iffalse meta-comment
%
% Copyright (C) 2007 by Enrico Gregorio
% <Enrico dot Gregorio (at) univr dot it>
% ---------------------------------------
% 
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.2
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.2 or later is part of all distributions of LaTeX 
% version 1999/12/01 or later.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{itnumpar.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{itnumpar}
%<*package>
    [2007/04/03 v1.0 Numbers in words for Italian]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[english,italian]{babel}
\usepackage{itnumpar}

\IfFileExists{titlesec.sty}{
\usepackage{titlesec}
\titleformat{name=\section}{}{}{0pt}%
  {\large\bfseries\Ordinalef{section} sezione: }
\titleformat{name=\section,numberless}{}{}{0pt}{\large\bfseries}
}
{\renewcommand{\thesection}{\Ordinalef{section} sezione:}}

\def\GuIT{%
  {\fontencoding{OT1}\fontfamily{cmr}\fontseries{m}\scshape
  g\kern -0.26em\lower 0.714ex\hbox{u}%
  \kern -0.125em I\kern -0.125em t}}

\newcommand{\cmdname}[1]{\texttt{\char`\\#1}}
\EnableCrossrefs         
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{itnumpar.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{589}
% 
% \catcode`\@=12
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v1.0}{2007/04/03}{Initial version}
%
% \GetFileInfo{itnumpar.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment,\',\@ctrerr,\@gobble}
% \DoNotIndex{\@ifstar,\begingroup,\count@,\csname,\def,\else}
% \DoNotIndex{\endcsname,\endgroup,\expandafter,\fi,\ifcase}
% \DoNotIndex{\ifnum,\let,\number,\or,\relax,\xdef}
% 
%
% \title{The \textsf{itnumpar} package\\ Il pacchetto
% \textsf{itnumpar}\thanks{This document corresponds to
% \textsf{itnumpar}~\fileversion, dated \filedate.}}
% 
% \author{Enrico Gregorio \\ \texttt{Enrico dot Gregorio (at) univr
% dot it}}
% 
% \date{\filedate}
%
% \maketitle
%
% \section{Introduzione in inglese}
% \begin{otherlanguage*}{english}
% Sorry, this is a package intended for people writing in Italian.
% The title of this section is `Introduction in English'.  However,
% I'll give the flavor of it, if not the whole story.
% 
% The name of the package is \texttt{itnumpar}: \texttt{it} for
% Italian, \texttt{num} for `\mbox{numero}' (number), \texttt{par} for
% `\mbox{parola}' (word).
% 
% Its purpose is to give a representation of a number in words.  The
% following commands take as an argument a counter's name (they are
% similar to \cmdname{arabic}, \cmdname{roman} and similar ones:
% \begin{itemize}
% \item \cmdname{numeroinparole} for representing the counter's value
% in Italian words, with lowercase initial;
% 
% \item \cmdname{Numeroinparole} for representing the counter's value
% in Italian words, with uppercase initial;
% 
% \item \cmdname{ordinalem} for representing the counter's value as a
% (spelled out) ordinal number in masculine form with lowercase
% initial;
% 
% \item \cmdname{ordinalef} for representing the counter's value as a
% (spelled out) ordinal number in feminine form with lowercase
% initial;
% 
% \item \cmdname{Ordinalem} for representing the counter's value as a
% (spelled out) ordinal number in masculine form with uppercase
% initial;
% 
% \item \cmdname{Ordinalem} for representing the counter's value as a
% (spelled out) ordinal number in feminine form with uppercase
% initial.  \end{itemize} The Italian word `\mbox{ordinale}' means
% `ordinal', of course; `\mbox{numero}~in~\mbox{parole}' means `number
% in words'.
% 
% The other defined commands are
% \begin{center}
% \begin{tabular}{cc}
% \cmdname{printnumeroinparole}&\cmdname{printNumeroinparole}\\
% \cmdname{printordinalem}&\cmdname{printordinalef}\\
% \cmdname{printOrdinalem}&\cmdname{printOrdinalef}
% \end{tabular}
% \end{center}
% which take a number as an argument and print its textual 
% representation like the commands above.
% 
% For example, the present document has been written saying
% \begin{verbatim}
% \renewcommand{\thesection}{\Ordinalef{section} sezione:}
% \end{verbatim}
% thus getting the spelled out feminine ordinal in front of the
% section title (section in Italian is `\mbox{sezione}' and is
% feminine).
% 
% The package (in the present version) supports positive numbers up to
% $9999$ for \cmdname{numeroinparole} and \cmdname{Numeroinparole}; up
% to $999$ for the ordinal forms.  For \cmdname{numeroinparole}, zero
% is admissible.  For all the commands, negative numbers give an empty
% result.
% 
% All these commands are fully expandable and their result is a string
% of character tokens.  For example, \verb|\printnumeroinparole{12}|
% expands to the string of characters `\texttt{\printnumeroinparole{12}}'.
% \end{otherlanguage*}
%
% \section{Introduzione in italiano}
% 
% Il nome del pacchetto \`e \texttt{itnumpar} (numeri in parole in
% italiano).  Ci sono altri pacchetti su \textsc{ctan} che fanno un
% servizio simile per altre lingue, ma nessuno \`e facilmente
% adattabile all'italiano.  O forse s\`{\i}, una volta ho provato ad
% adattarne uno, ma senza grandi risultati.
% 
% Quali sono i problemi?  Che alcune vocali si assimilano:
% ``\printnumeroinparole{20}--\printnumeroinparole{21}'',
% ``\printnumeroinparole{37}--\printnumeroinparole{38}'',
% ``\printnumeroinparole{121}'', ``\printnumeroinparole{186}''.  Che i
% numeri con cifra delle unit\`a~$3$ in lettere vogliono l'accento:
% ``\printnumeroinparole{23}''; con l'unica eccezione
% di~``\printnumeroinparole{3}''.
% 
% Il pacchetto tratta solo numeri relativamente piccoli; non potrete
% usarlo per compilare assegni di importo superiore a
% \printnumeroinparole{9999}~euro\footnote{In alcuni paesi, non in
% Italia, \`e possibile stamparsi i propri assegni.}.  Tuttavia una
% famosa opera letteraria in italiano \`e divisa in
% \printnumeroinparole{100} parti e quindi ho deciso di andare oltre
% il limite di \printnumeroinparole{99} di un primo abbozzo apparso
% sul Forum del \GuIT\footnote{Gruppo Utenti Italiani di \TeX,
% \texttt{www.guit.sssup.it}}.
% 
% Rispetto a quella versione ho introdotto anche la possibilit\`a di
% scrivere gli ordinali (fino al \printordinalem{999}), sia come
% aggettivi maschili che femminili, come vedete nella numerazione
% delle sezioni di questo stesso documento.
% 
% I comandi che descrivo nella prossima sezione sono completamente
% espandibili e danno come risultato una lista di \emph{token} fatta
% di caratteri.  Per esempio, l'espansione di
% \verb|\printnumeroinparole{12}| \`e la sequenza di caratteri
% `\texttt{\printnumeroinparole{12}}'.
% 
% \clearpage
% 
% \section{I comandi}
% 
% \DescribeMacro{\numeroinparole}
% \DescribeMacro{\Numeroinparole}
% \DescribeMacro{\ordinalem}
% \DescribeMacro{\ordinalef}
% \DescribeMacro{\Ordinalem}
% \DescribeMacro{\Ordinalef}

% In analogia con i comandi del tipo \cmdname{arabic}, \cmdname{Roman}
% e simili, possiamo rappresentare il valore di un contatore con il
% numero scritto in parole o con l'ordinale corrispondente, maschile o
% femminile, con iniziale minuscola o maiuscola; ciascuno prende come
% argomento il nome di un contatore:
% \begin{itemize}
% \item \cmdname{numeroinparole} rappresenta in parole il valore del
% contatore, con iniziale minuscola;
% 
% \item \cmdname{Numeroinparole} rappresenta in parole il valore del 
% contatore, con iniziale maiuscola;
% 
% \item \cmdname{ordinalem} rappresenta il valore del contatore come 
% numero ordinale maschile con iniziale minuscola;
% 
% \item \cmdname{ordinalef} rappresenta il valore del contatore come 
% numero ordinale femminile con iniziale minuscola;
% 
% \item \cmdname{Ordinalem} rappresenta il valore del contatore come 
% numero ordinale maschile con iniziale maiuscola;
% 
% \item \cmdname{Ordinalem} rappresenta il valore del contatore come 
% numero ordinale femminile con iniziale maiuscola.
% \end{itemize}
% Per esempio, nel preambolo di questo documento compare il comando
% \begin{verbatim}
% \renewcommand{\thesection}{\Ordinalef{section} sezione:}
% \end{verbatim}
% che spiega il curioso formato dei titoli di sezione.
% 
% \DescribeMacro{\printnumeroinparole}
% \DescribeMacro{\printNumeroinparole}
% \DescribeMacro{\printordinalem}
% \DescribeMacro{\printordinalef}
% \DescribeMacro{\printOrdinalem}
% \DescribeMacro{\printOrdinalef}
% Ci sono altri comandi a disposizione, che permettono di scrivere in 
% lettere o come ordinale un numero dato come argomento:
% \begin{center}
% \begin{tabular}{cc}
% \cmdname{printnumeroinparole}&\cmdname{printNumeroinparole}\\
% \cmdname{printordinalem}&\cmdname{printordinalef}\\
% \cmdname{printOrdinalem}&\cmdname{printOrdinalef}
% \end{tabular}
% \end{center}
% Per esempio, con \verb|\printOrdinalef{123}| si ottiene
% ``\printOrdinalef{123}'', mentre con
% \verb|\printnumeroinparole{6783}| si ottiene
% ``\printnumeroinparole{6783}''.
% 
% Non \`e possibile ottenere, con questi comandi, il modo antiquato di
% esprimere gli ordinali: ``decimoprimo'' invece di ``undicesimo''.
% Per precisa scelta stilistica, si ottiene ``\printordinalem{111}'' e
% non ``centundicesimo'' come alcuni scrivono\footnote{Se non vi va,
% scrivete voi il vostro pacchetto.}.  Ovviamente, per stampare il
% valore di un contatore in parole, si deve scrivere, per esempio
% \begin{verbatim}
% \printnumeroinparole{\value{section}}
% \end{verbatim}
% che, dato qui, produce~``\printnumeroinparole{\value{section}}''.
% 
% \section{Limitazioni}
% 
% Il comando \cmdname{numeroinparole} (e il corrispondente
% \cmdname{printnumeroinparole}) non possono essere usati solo con
% numeri interi~$m$ tali che $0\le m\le 9999$.  I comandi per i numeri
% ordinali funzionano solo con interi~$n$ tali che $1\le n\le 999$.
% 
% Usati con numeri negativi (e anche zero per le forme ordinali),
% danno un risultato vuoto, senza messaggio di errore.
% 
% Forse future versioni del pacchetto amplieranno l'intervallo di
% applicabilit\`a.
% 
% 
% \section{Esempi}
% 
% Esiste, e l'ho aggiunto solo per questa applicazione, una 
% variante~\texttt{*} del comando \cmdname{printnumeroinparole}; i
% versi seguenti sono stato scritti come
% \begin{verbatim}
% \begin{verse}
% In Italia \printnumeroinparole{640},\\
% In Almagna \printnumeroinparole*{231},\\
% \printNumeroinparole{100} in Francia,
%   in Turchia \printnumeroinparole*{91},\\
% Ma in Ispagna son gi\`a \printnumeroinparole{1003}.
% \end{verse}
% \end{verbatim}
% ed ecco le immortali parole dell'abate Da~Ponte:
% \begin{verse}
% In Italia \printnumeroinparole{640},\\
% In Almagna \printnumeroinparole*{231},\\
% \printNumeroinparole{100} in Francia, in Turchia
% \printnumeroinparole*{91},\\
% Ma in Ispagna son gi\`a \printnumeroinparole{1003}.
% \end{verse}
% 
% Supponiamo di voler scrivere con la classe \textsf{book}, in modo
% che i capitoli siano numerati in parole: ``Capitolo~uno'',
% ``Capitolo~due'' e cos\`{\i} via, ma che poi vogliamo riferirci ai
% capitoli per numero durante il testo.  Dare
% \begin{verbatim}
% \renewcommand{\thechapter}{\numeroinparole{chapter}}
% \end{verbatim}
% sarebbe sbagliato, perch\'e i riferimenti sarebbero con la forma
% testuale e non numerica.  Occorre dunque modificare il comando
% \cmdname{chapter} o, per essere precisi, \cmdname{@chapter}, che \`e
% quello chiamato da \cmdname{chapter} se non si usa la
% variante~\texttt{*}.  Per essere ancora pi\`u precisi, occorre
% modificare \cmdname{@makechapterhead}, che \`e il comando
% responsabile della stampa del titolo.  Invece di modificare del
% tutto il comando, gli aggiungiamo qualcosa.
% \begin{verbatim}
% \makeatletter
% \let\orig@makechapterhead\@makechapterhead
% \def\@makechapterhead#1{\begingroup
%   \def\thechapter{\numeroinparole{chapter}}%
%   \orig@makechapterhead{#1}\endgroup}
% \makeatother
% \end{verbatim}
% e otteniamo il risultato voluto.  L'uso del pacchetto
% \textsf{titlesec} \`e indicato per ottenere effetti diversi senza
% troppa fatica.  Nel caso della classe \textsf{amsbook} occorre un
% trucco diverso:
% \begin{verbatim}
% \makeatletter
% \let\orig@makechapterhead\@makechapterhead
% \def\@makechapterhead#1{\begingroup
%   \edef\thechapter{\uppercase{\numeroinparole{chapter}}}%
%   \orig@makechapterhead{#1}\endgroup}
% \makeatother
% \end{verbatim}
% perch\'e la scritta ``capitolo uno'' deve essere tutta in maiuscolo.
% 
% In entrambe le modifiche, si usa il fatto che 
% \cmdname{@makechapterhead} chiama al suo interno \cmdname{thechapter} 
% per stampare il numero; lo usiamo allo stesso modo, ma ridefinendo 
% localmente \cmdname{thechapter}. Con \textsf{amsbook} possiamo usare 
% il fatto che \cmdname{numeroinparole} \`e completamente espandibile, 
% mentre \cmdname{uppercase} non lo \`e.
%
% \StopEventually{\PrintChanges\PrintIndex}
%
% \section{Implementation}
% \selectlanguage{english}
% I'll use English to describe the implementation of the macros.
%
% Usual stuff for representing counters \verb|\|\meta{name} is the
% user interface, \verb|\@|\meta{name} is the internal command The
% capital letter is for a capital initial, `m' is for `masculine', `f'
% is for `feminine'.
% \begin{macro}{\numeroinparole}
% \begin{macro}{\Numeroinparole}
% \begin{macro}{\ordinalem}
% \begin{macro}{\ordinalef}
% \begin{macro}{\Ordinalem}
% \begin{macro}{\Ordinalef}
%    \begin{macrocode}
%<*package>
\def\numeroinparole#1{\expandafter\@numeroinparole\csname c@#1\endcsname}
\def\Numeroinparole#1{\expandafter\@Numeroinparole\csname c@#1\endcsname}
\def\ordinalem#1{\expandafter\@ordinalem\csname c@#1\endcsname}
\def\ordinalef#1{\expandafter\@ordinalef\csname c@#1\endcsname}
\def\Ordinalem#1{\expandafter\@Ordinalem\csname c@#1\endcsname}
\def\Ordinalef#1{\expandafter\@Ordinalef\csname c@#1\endcsname}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% 
% \begin{macro}{\printnumeroinparole}
% \begin{macro}{\printNumeroinparole}
% \begin{macro}{\printordinalem}
% \begin{macro}{\printordinalef}
% \begin{macro}{\printOrdinalem}
% \begin{macro}{\printOrdinalef}
% \verb|\print|\meta{name} gets as an argument a \meta{number} and
% produces it in the literal form; instead of doing six similar
% definitions, we do it only once
%    \begin{macrocode}
\begingroup
\def\np@doprintdef#1{%
  \expandafter\xdef\csname print#1\endcsname##1{%
    {\count@=##1\relax\csname @#1\endcsname{\count@}}}}
  \np@doprintdef{numeroinparole}
  \np@doprintdef{Numeroinparole}
  \np@doprintdef{ordinalem}
  \np@doprintdef{ordinalef}
  \np@doprintdef{Ordinalem}
  \np@doprintdef{Ordinalef}
\endgroup
%    \end{macrocode}
% Just for an application, I define a \texttt{*} version of 
% \verb|\printnumeroinparole|
%    \begin{macrocode}
\def\np@oa{o}
\let\@printnumeroinparole\printnumeroinparole
\def\printnumeroinparole{%
  \@ifstar{\@printnumeroinparolef}{\@printnumeroinparole}%
}
\def\@printnumeroinparolef#1{{\def\np@oa{a}\printnumeroinparole{#1}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\@numeroinparole}
% \begin{macro}{\@Numeroinparole}
% \verb|\@numeroinparole| must keep care of two particularities:
% `zero' and `tre', since all numbers ending in `3' must have an
% accent in the word, except for `3' itself.  So we look for the
% particular cases and then call \verb|\np@numeroinparole| with an
% empty second argument.  \verb|\@Numeroinparole| works in the same
% way.
%    \begin{macrocode}
\def\@numeroinparole#1{%
  \ifnum#1=0 zero% Exception
  \else
  \ifnum#1=3 tre% Exception
  \else
  \np@numeroinparole{#1}{}%
  \fi\fi}
\def\@Numeroinparole#1{%
  \ifnum#1=0 Zero% Exception
  \else
  \ifnum#1=3 Tre% Exception
  \else
  \np@Numeroinparole{#1}{}%
  \fi\fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\np@numeroinparole}
% \begin{macro}{\np@Numeroinparole}
% \verb|\np@numeroinparole| is defined with two arguments; the first
% one is the number, the second one is either empty or~`o'.  We
% support only numbers less than $10000$.  If $999<\#<10000$, we call
% \verb|\np@thousand|; if $99<\#<1000$ we call \verb|\np@hundred|; if
% $29<\#<100$, we call \verb|\np@large|; if $0<\#<30$ we call
% \verb|\np@small|.  Numbers from 1 to 19 are special; numbers from 20
% to 29 have~`i' in the root, numbers from 30 to 99 have~`a' in the
% root: `venti', `trenta', `quaranta' and so on. The same for 
% \verb|\np@Numeroinparole|.
%    \begin{macrocode}
\def\np@numeroinparole#1#2{%
  \ifnum#1>9999
    \@ctrerr
  \else
  \ifnum#1>999
    \expandafter\np@thousand\number#1 \np@del
  \else
  \ifnum#1>99
    \expandafter\np@hundred\number#1 \np@del
  \else
  \ifnum#1<30 
    \np@small{#1}{#2}%
  \else
    \expandafter\np@large\number#1{#2}%
  \fi\fi\fi\fi}
\def\np@Numeroinparole#1#2{%
  \ifnum#1>9999
    \@ctrerr
  \else
  \ifnum#1>999
    \expandafter\np@Thousand\number#1 \np@del
  \else
  \ifnum#1>99
    \expandafter\np@Hundred\number#1 \np@del
  \else
  \ifnum#1<30 
    \np@Small{#1}{#2}%
  \else
    \expandafter\np@Large\number#1{#2}%
  \fi\fi\fi\fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\np@small}
% \begin{macro}{\np@Small}
% \verb|\np@small| is just an \verb|\ifcase| routine; we add in front
% the second argument, which is empty if $1<\#<100$ or if the third
% digit is~$0$.  The same for \verb|\np@Small|, but argument \verb|#2|
% will always be empty.
%    \begin{macrocode}
\def\np@small#1#2{#2\ifcase#1 \or
  un\np@oa\or due\or tr\'e\or quattro\or cinque\or
  sei\or sette\or otto\or nove\or dieci\or
  undici\or dodici\or tredici\or quattordici\or quindici\or
  sedici\or diciassette\or diciotto\or diciannove\or venti\or
  ventuno\or ventidue\or ventitr\'e\or ventiquattro\or venticinque\or
  ventisei\or ventisette\or ventotto\or ventinove\fi}
\def\np@Small#1#2{\ifcase#1 \or
  Uno\or Due\or\or Quattro\or Cinque\or Sei\or Sette\or
  Otto\or Nove\or Dieci\or Undici\or Dodici\or Tredici\or
  Quattordici\or Quindici\or Sedici\or Diciassette\or Diciotto\or
  Diciannove\or Venti\or Ventuno\or Ventidue\or Ventitr\'e\or
  Ventiquattro\or Venticinque\or Ventisei\or Ventisette\or
  Ventotto\or Ventinove\fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\np@large}
% \begin{macro}{\np@Large}
% \verb|\np@large| has three arguments: the two digits of \# and the
% second argument to \verb|\np@numeroinparole|.  We do a pair of
% \verb|\ifcase|; notice that the third argument is not put in front
% of `ottant', since we say `centottanta', not doubling the~`o'.
% Since we say `trentuno' and `trentadue', we put the vowel, when
% needed, in the second part.  In a similar way we define
% \verb|\np@Large|.
%    \begin{macrocode}
\def\np@large#1#2#3{%
  \ifcase#1 \or\or\or #3trent\or #3quarant\or #3cinquant\or
    #3sessant\or #3settant\or ottant\or #3novant\fi
  \ifcase#2 a\or un\np@oa\or adue\or atr\'e\or aquattro\or
    acinque\or asei\or asette\or otto\or anove\fi}
\def\np@Large#1#2#3{%
  \ifcase#1 \or\or\or Trent\or Quarant\or Cinquant\or
    Sessant\or Settant\or Ottant\or Novant\fi
  \ifcase#2 a\or uno\or adue\or atr\'e\or aquattro\or
    acinque\or asei\or asette\or otto\or anove\fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\np@hundred}
% \begin{macro}{\np@Hundred}
% \verb|\np@hundred| has two arguments, the third digit and the other
% two: 123 is split into `1' and `23'.  We add the digit name in front
% of `cent' if the digit is $>1$; if the second argument is zero, we
% add a final~`o' and we are done (cento, duecento, and so on),
% otherwise we call recursively \verb|\np@numeroinparole| with~`o' as
% its second argument.
%    \begin{macrocode}
\def\np@hundred#1#2\np@del{%
  \ifcase#1 \or\or due\or tre\or quattro\or cinque\or
    sei\or sette\or otto\or nove\fi cent%
  \ifnum#2=0 o\else\np@numeroinparole{#2}{o}\fi}
\def\np@Hundred#1#2\np@del{%
  \ifcase#1 \or Cent\or Duecent\or Trecent\or Quattrocent\or
    Cinquecent\or Seicent\or Settecent\or Ottocent\or Novecent\fi
  \ifnum#2=0 o\else\np@numeroinparole{#2}{o}\fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\np@thousand}
% \begin{macro}{\np@Thousand}
% \verb|\np@thousand| does similarly (1234 is split into `1' and
% `234'); if the fourth digit is~1, we output `mille', otherwise
% \meta{digitname}mila.  Next we call recursively
% \verb|\np@numeroinparole| on the second part.
%    \begin{macrocode}
\def\np@thousand#1#2\np@del{%
  \ifnum#1=1 mille\else
  \ifcase#1 \or\or due\or tre\or quattro\or cinque\or
    sei\or sette\or otto\or nove\fi mila\fi
  \ifnum#2=0 \else\np@numeroinparole{#2}{}\fi}
\def\np@Thousand#1#2\np@del{%
  \ifnum#1=1
    Mille%
  \else
  \ifcase#1 \or\or Due\or Tre\or Quattro\or Cinque\or
    Sei\or Sette\or Otto\or Nove\fi
    mila\fi
  \ifnum#2=0 \else\np@numeroinparole{#2}{}\fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\@ordinalem}
% \begin{macro}{\@ordinalef}
% \begin{macro}{\@Ordinalem}
% \begin{macro}{\@Ordinalef}
% Now we come to the ordinals; each one of the commands calls the 
% generic one adding `o' for the masculine form and `a' for the 
% feminine form.
%    \begin{macrocode}
\def\@ordinalem#1{\np@ordinal{#1}{}o}
\def\@ordinalef#1{\np@ordinal{#1}{}a}
\def\@Ordinalem#1{\np@Ordinal{#1}{}o}
\def\@Ordinalef#1{\np@Ordinal{#1}{}a}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\np@ordinal}
% \begin{macro}{\np@ordinall}
% \begin{macro}{\np@Ordinal}
% \begin{macro}{\np@Ordinall}
% \verb|\np@ordinal| has two arguments, for reasons similar to the above. 
% Ordinals for $0<\#<11$ are very special, they cannot be used in the 
% recursion; so we check for that case and otherwise we call 
% \verb|\np@ordinall|.
%    \begin{macrocode}
\def\np@ordinal#1#2{%
  \ifnum#1=0
     \expandafter\@gobble
  \else
  \ifnum#1<11
  \ifcase#1 \or prim\or second\or terz\or quart\or quint\or
    sest\or settim\or ottav\or non\or decim\fi
  \else
    \np@ordinall{#1}{#2}%
  \fi\fi}
%    \end{macrocode}
% The definition of \verb|\np@ordinall| is similar to that of 
% \verb|\np@numeroinparole|, but we support only numbers less than~1000.
%    \begin{macrocode}
\def\np@ordinall#1#2{%
  \ifnum#1>999
    \@ctrerr
  \else
  \ifnum#1>99
    \expandafter\np@hundredord\number#1 \np@del
  \else
  \ifnum#1<30
    \np@smallord{#1}{#2}%
  \else
    \expandafter\np@largeord\number#1{#2}%
  \fi\fi\fi}
\def\np@Ordinal#1#2{%
  \ifnum#1=0
    \expandafter\@gobble
  \else
  \ifnum#1<11
  \ifcase#1 \or Prim\or Second\or Terz\or Quart\or Quint\or
    Sest\or Settim\or Ottav\or Non\or Decim\fi
  \else\np@Ordinall{#1}{#2}\fi\fi}
\def\np@Ordinall#1#2{%
  \ifnum#1>999
    \@ctrerr
  \else
  \ifnum#1>99
    \expandafter\np@hundredOrd\number#1 \np@del
  \else
  \ifnum#1<30
    \np@smallOrd{#1}{#2}%
  \else
    \expandafter\np@largeOrd\number#1{#2}%
  \fi\fi\fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\np@smallord}
% \verb|\np@smallord| is similar to \verb|\np@small| (the first cases
% are used only when called recursively.  It produces, e.g.,
% `tredicesim', the final letter is added by \verb|\@ordinalm| or
% \verb|\@ordinalf| or the capitalized forms.
%    \begin{macrocode}
\def\np@smallord#1#2{%
  \ifcase#1 \or un\or #2du\or #2tre\or #2quattr\or #2cinqu\or
    #2sei\or #2sett\or ott\or #2nov\or \or #2undic\or
    #2dodic\or #2tredic\or #2quattordic\or #2quindic\or
    #2sedic\or #2diciassett\or #2diciott\or #2diciannov\or
    #2vent\or #2ventun\or #2ventidu\or #2ventitre\or
    #2ventiquattr\or #2venticinqu\or #2ventisei\or
    #2ventisett\or #2ventott\or #2ventinov%
  \fi esim}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\np@largeord}
% \verb|\np@largeord| is similar to \verb|\np@large|.
%    \begin{macrocode}
\def\np@largeord#1#2#3{%
  \ifcase#1 \or\or\or #3trent\or #3quarant\or #3cinquant\or
    #3sessant\or #3settant\or ottant\or #3novant\fi
  \ifcase#2 \or un\or adu\or atre\or aquattr\or
    acinqu\or asei\or asett\or ott\or anov\fi esim}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\np@hundredord}
% \verb|\np@hundredord| is similar to \verb|\np@hundred|.  It calls
% recursively \verb|\np@ordinall| with~`o' as second argument if \# is
% not a multiple of~100.
%    \begin{macrocode}
\def\np@hundredord#1#2\np@del{%
  \ifcase#1 \or\or due\or tre\or quattro\or cinque\or
    sei\or sette\or otto\or nove\fi cent%
    \ifnum#2=0 esim\else\np@ordinall{#2}{o}\fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\np@smallOrd}
% \begin{macro}{\np@largeOrd}
% \begin{macro}{\np@hundredOrd}
% The last three commands are similar to the similar uncapitalized
% ones; the last calls \verb|\np@ordinall| for the second step.
%    \begin{macrocode}
\def\np@smallOrd#1{%
  \ifcase#1 \or \or \or \or \or \or  \or \or \or \or \or
    Undicesim\or Dodicesim\or Tredicesim\or Quattordicesim\or
    Quindicesim\or Sedicesim\or Diciassettesim\or Diciottesim\or
    Diciannovesim\or Ventesim\or Ventunesim\or Ventiduesim\or
    Ventitreesim\or Ventiquattresim\or Venticinquesim\or
    Ventiseiesim\or Ventisettesim\or Ventottesim\or Ventinovesim%
  \fi}
\def\np@largeOrd#1#2{%
  \ifcase#1 \or\or\or Trent\or Quarant\or Cinquant\or
    Sessant\or Settant\or Ottant\or Novant\fi
  \ifcase#2 \or un\or adu\or atre\or aquattr\or
    acinqu\or asei\or asett\or ott\or anov\fi esim}
\def\np@hundredOrd#1#2\np@del{%
  \ifcase#1 \or C\or Duec\or Trec\or Quattroc\or Cinquec\or
    Seic\or Settec\or Ottoc\or Novec\fi ent%
    \ifnum#2=0 esim\else\np@ordinall{#2}{o}\fi}
%</package>
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \Finale
\endinput