%%
%% `numspell-italian.sty' Italian language package for 'numspell.sty'
%%
%% Copyright 2017-2024 by Tibor Tomacs
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% 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.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Tibor Tomacs.
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{numspell-italian}[2017/09/30 v1.0 Italian language package for numspell]

%% GROUP NAMES
\def\numspell@group@ii@it@name{\numspell@{mille}}
\def\numspell@group@iii@it@name{\numspell@{milione}}
\def\numspell@group@iv@it@name{\numspell@{miliardo}}
\def\numspell@group@v@it@name{\numspell@{bilione}}
\def\numspell@group@vi@it@name{\numspell@{biliardo}}
\def\numspell@group@vii@it@name{\numspell@{trilione}}
\def\numspell@group@viii@it@name{\numspell@{triliardo}}
\def\numspell@group@ix@it@name{\numspell@{quadrilione}}
\def\numspell@group@x@it@name{\numspell@{quadriliardo}}
\def\numspell@group@xi@it@name{\numspell@{quintilione}}
\def\numspell@group@xii@it@name{\numspell@{quintiliardo}}
\def\numspell@group@xiii@it@name{\numspell@{sextilione}}
\def\numspell@group@xiv@it@name{\numspell@{sextiliardo}}
\def\numspell@group@xv@it@name{\numspell@{septilione}}
\def\numspell@group@xvi@it@name{\numspell@{septiliardo}}
\def\numspell@group@xvii@it@name{\numspell@{octilione}}
\def\numspell@group@xviii@it@name{\numspell@{octiliardo}}
\def\numspell@group@xix@it@name{\numspell@{nonilione}}
\def\numspell@group@xx@it@name{\numspell@{noniliardo}}
\def\numspell@group@xxi@it@name{\numspell@{decilione}}
\def\numspell@group@xxii@it@name{\numspell@{deciliardo}}

%% GROUP NAMES (PLURAL)
\def\numspell@group@ii@it@name@plural{\numspell@{mila}}
\def\numspell@group@iii@it@name@plural{\numspell@{milioni}}
\def\numspell@group@iv@it@name@plural{\numspell@{miliardi}}
\def\numspell@group@v@it@name@plural{\numspell@{bilioni}}
\def\numspell@group@vi@it@name@plural{\numspell@{biliardi}}
\def\numspell@group@vii@it@name@plural{\numspell@{trilioni}}
\def\numspell@group@viii@it@name@plural{\numspell@{triliardi}}
\def\numspell@group@ix@it@name@plural{\numspell@{quadrilioni}}
\def\numspell@group@x@it@name@plural{\numspell@{quadriliardi}}
\def\numspell@group@xi@it@name@plural{\numspell@{quintilioni}}
\def\numspell@group@xii@it@name@plural{\numspell@{quintiliardi}}
\def\numspell@group@xiii@it@name@plural{\numspell@{sextilioni}}
\def\numspell@group@xiv@it@name@plural{\numspell@{sextiliardi}}
\def\numspell@group@xv@it@name@plural{\numspell@{septilioni}}
\def\numspell@group@xvi@it@name@plural{\numspell@{septiliardi}}
\def\numspell@group@xvii@it@name@plural{\numspell@{octilioni}}
\def\numspell@group@xviii@it@name@plural{\numspell@{octiliardi}}
\def\numspell@group@xix@it@name@plural{\numspell@{nonilioni}}
\def\numspell@group@xx@it@name@plural{\numspell@{noniliardi}}
\def\numspell@group@xxi@it@name@plural{\numspell@{decilioni}}
\def\numspell@group@xxii@it@name@plural{\numspell@{deciliardi}}

%% ORDINAL GROUP NAMES
\def\numspell@ordgroup@ii@it@name{\numspell@{millesim}}
\def\numspell@ordgroup@iii@it@name{\numspell@{milionesim}}
\def\numspell@ordgroup@iv@it@name{\numspell@{miliardesim}}
\def\numspell@ordgroup@v@it@name{\numspell@{bilionesim}}
\def\numspell@ordgroup@vi@it@name{\numspell@{biliardesim}}
\def\numspell@ordgroup@vii@it@name{\numspell@{trilionesim}}
\def\numspell@ordgroup@viii@it@name{\numspell@{triliardesim}}
\def\numspell@ordgroup@ix@it@name{\numspell@{quadrilionesim}}
\def\numspell@ordgroup@x@it@name{\numspell@{quadriliardesim}}
\def\numspell@ordgroup@xi@it@name{\numspell@{quintilionesim}}
\def\numspell@ordgroup@xii@it@name{\numspell@{quintiliardesim}}
\def\numspell@ordgroup@xiii@it@name{\numspell@{sextilionesim}}
\def\numspell@ordgroup@xiv@it@name{\numspell@{sextiliardesim}}
\def\numspell@ordgroup@xv@it@name{\numspell@{septilionesim}}
\def\numspell@ordgroup@xvi@it@name{\numspell@{septiliardesim}}
\def\numspell@ordgroup@xvii@it@name{\numspell@{octilionesim}}
\def\numspell@ordgroup@xviii@it@name{\numspell@{octiliardesim}}
\def\numspell@ordgroup@xix@it@name{\numspell@{nonilionesim}}
\def\numspell@ordgroup@xx@it@name{\numspell@{noniliardesim}}
\def\numspell@ordgroup@xxi@it@name{\numspell@{decilionesim}}
\def\numspell@ordgroup@xxii@it@name{\numspell@{deciliardesim}}

%% GENDER
\def\numspellitmasculine{\def\numspell@it@gender{\numspell@{o}}}
\def\numspellitfeminine{\def\numspell@it@gender{\numspell@{a}}}
\numspellitmasculine

%% SPELLING CARDINAL NUMBER GROUP
%% ---------------------------------
%% \numspell@group@spell@it{<group>} (<group>=000,001,...,999)
%% ---------------------------------
%% \numspell@group@digits{<group>}
%% Adding the <group> spelling to \thenumspell
%%
\def\numspell@group@spell@it#1{%
    \numspell@group@digits{#1}%
    \ifcase\numspell@group@digit@i%
        \or\or\numspell@{due}\or\numspell@{tre}\or\numspell@{quattro}\or\numspell@{cinque}%
        \or\numspell@{sei}\or\numspell@{sette}\or\numspell@{otto}\or\numspell@{nove}%
    \fi%
    \ifnum\numspell@group@digit@i>0%
        \numspell@{cent}%
        \ifnum\numspell@group@digit@ii=8\else%
            \numspell@{o}%
        \fi%
    \fi%
    \ifcase\number\numexpr10*\numspell@group@digit@ii+\numspell@group@digit@iii%
        \or\or\numspell@{due}\or\or\numspell@{quattro}\or\numspell@{cinque}\or\numspell@{sei}\or\numspell@{sette}%
        \or\numspell@{otto}\or\numspell@{nove}\or\numspell@{dieci}\or\numspell@{undici}\or\numspell@{dodici}%
        \or\numspell@{tredici}\or\numspell@{quattordici}\or\numspell@{quindici}\or\numspell@{sedici}%
        \or\numspell@{diciassette}\or\numspell@{diciotto}\or\numspell@{diciannove}\or\numspell@{venti}%
        \or\numspell@{ventuno}\or\numspell@{ventidue}\or\numspell@{ventitr\'{e}}\or\numspell@{ventiquattro}%
        \or\numspell@{venticinque}\or\numspell@{ventisei}\or\numspell@{ventisette}\or\numspell@{ventotto}\or\numspell@{ventinove}%
    \fi%
    \ifcase\numspell@group@digit@ii%
        \or\or\or\numspell@{trent}\or\numspell@{quarant}\or\numspell@{cinquant}\or\numspell@{sessant}%
        \or\numspell@{settant}\or\numspell@{ottant}\or\numspell@{novant}%
    \fi%
    \ifnum\numspell@group@digit@ii>2%
        \ifcase\numspell@group@digit@iii%
            \numspell@{a}\or\numspell@{uno}\or\numspell@{adue}\or\numspell@{atr\'{e}}\or\numspell@{aquattro}%
            \or\numspell@{acinque}\or\numspell@{asei}\or\numspell@{asette}\or\numspell@{otto}\or\numspell@{anove}%
        \fi%
    \fi%
    \ifnum\numspell@group@digit@i>0%
        \ifnum\numspell@group@digit@ii=0%
            \ifcase\numspell@group@digit@iii%
                \or\numspell@{uno}\or\or\numspell@{tr\'{e}}%
            \fi%
        \fi%
    \fi%
    \ifnum\number\numexpr\numspell@group@digit@i+\numspell@group@digit@ii=0%
        \ifcase\numspell@group@digit@iii%
            \or\or\or\numspell@{tre}%
        \fi%
    \fi%
}

%% SPELLING ORDINAL NUMBER GROUP
%% ------------------------------------
%% \numspell@ordgroup@spell@it{<group>} (<group>=000,001,...,999)
%% ------------------------------------
%% \numspell@group@digits{<group>}
%% Adding the <group> ordinal spelling to \thenumspell
%%
\def\numspell@ordgroup@spell@it#1{%
    \numspell@group@digits{#1}%
    \ifcase\numspell@group@digit@i%
        \or\or\numspell@{due}\or\numspell@{tre}\or\numspell@{quattro}\or\numspell@{cinque}%
        \or\numspell@{sei}\or\numspell@{sette}\or\numspell@{otto}\or\numspell@{nove}%
    \fi%
    \ifnum\numspell@group@digit@i>0%
        \numspell@{cent}%
        \ifnum\numspell@group@digit@ii=8\else%
            \ifnum\number\numexpr\numspell@group@digit@ii+\numspell@group@digit@iii>0\numspell@{o}\fi%
        \fi%
    \fi%
    \ifcase\number\numexpr10*\numspell@group@digit@ii+\numspell@group@digit@iii%
        \or\or\numspell@{du}\or\or\numspell@{quattr}\or\numspell@{cinqu}\or\numspell@{sei}\or\numspell@{sett}%
        \or\numspell@{ott}\or\numspell@{nov}\or\numspell@{diec}\or\numspell@{undic}\or\numspell@{dodic}%
        \or\numspell@{tredic}\or\numspell@{quattordic}\or\numspell@{quindic}\or\numspell@{sedic}%
        \or\numspell@{diciassett}\or\numspell@{diciott}\or\numspell@{diciannov}\or\numspell@{vent}%
        \or\numspell@{ventun}\or\numspell@{ventidu}\or\numspell@{ventitre}\or\numspell@{ventiquattr}%
        \or\numspell@{venticinqu}\or\numspell@{ventisei}\or\numspell@{ventisett}\or\numspell@{ventott}\or\numspell@{ventinov}%
    \fi%
    \ifcase\numspell@group@digit@ii%
        \or\or\or\numspell@{trent}\or\numspell@{quarant}\or\numspell@{cinquant}\or\numspell@{sessant}%
        \or\numspell@{settant}\or\numspell@{ottant}\or\numspell@{novant}%
    \fi%
    \ifnum\numspell@group@digit@ii>2%
        \ifcase\numspell@group@digit@iii%
            \or\numspell@{un}\or\numspell@{adu}\or\numspell@{atre}\or\numspell@{aquattr}%
            \or\numspell@{acinqu}\or\numspell@{asei}\or\numspell@{asett}\or\numspell@{ott}\or\numspell@{anov}%
        \fi%
    \fi%
    \ifnum\numspell@group@digit@i>0%
        \ifnum\numspell@group@digit@ii=0%
            \ifcase\numspell@group@digit@iii%
                \or\numspell@{un}\or\or\numspell@{tre}%
            \fi%
        \fi%
    \fi%
    \ifnum\number\numexpr\numspell@group@digit@i+\numspell@group@digit@ii=0%
        \ifcase\numspell@group@digit@iii%
            \or\or\or\numspell@{tre}%
        \fi%
    \fi%
}

%% SPELLING CARDINAL NUMBER
%% --------------------------------------
%% \numspell@num@spell@it{<num1>}{<num2>}
%% --------------------------------------
%% \numspell@groups{<num1>}{<num2>}
%% Adding the \numspell@num spelling to \thenumspell
%%
\def\numspell@num@spell@it#1#2{%
    \gdef\thenumspell{}%
    \numspell@groups{#1}{#2}%
    \setcounter{numspell@groupcount}{22}%
    \@whilenum\value{numspell@groupcount}>2%
    \do{%
        \IfEq{\csname numspell@group@\roman{numspell@groupcount}\endcsname}{0}{}{%
            \IfEq{\csname numspell@group@\roman{numspell@groupcount}\endcsname}{1}{\numspell@{un}}{}%
            \numspell@group@spell@it{\csname numspell@group@\roman{numspell@groupcount}\endcsname}%
            \numspell@{ }%
            \IfEq{\csname numspell@group@\roman{numspell@groupcount}\endcsname}{1}%
                {\csname numspell@group@\roman{numspell@groupcount}@it@name\endcsname}%
                {\csname numspell@group@\roman{numspell@groupcount}@it@name@plural\endcsname}%
            \ifnum\csname numspell@group@\roman{numspell@groupcount}@before\endcsname>0\numspell@{ }\fi%
        }%
        \addtocounter{numspell@groupcount}{-1}%
    }%
    \IfEq{\numspell@group@ii}{0}{}{%
        \numspell@group@spell@it{\numspell@group@ii}%
        \IfEq{\numspell@group@ii}{1}{\numspell@group@ii@it@name}{\numspell@group@ii@it@name@plural}%
        \numspell@group@digits{\numspell@group@ii}%
        \ifnum\numspell@group@digit@i>0\ifnum\number\numexpr\numspell@group@digit@ii+\numspell@group@digit@iii>0%
            \ifnum\numspell@group@ii@before>0\numspell@{ }\fi%
        \fi\fi%
    }%
    \IfEq{\numspell@group@i}{0}{}{%
        \IfEq{\numspell@group@i}{1}{\numspell@{uno}}{}%
        \ifnum\numspell@group@max>1%
            \IfEq{\numspell@group@i}{3}{\numspell@{tr\'{e}}}{\numspell@group@spell@it{\numspell@group@i}}%
        \else%
            \numspell@group@spell@it{\numspell@group@i}%
        \fi%
    }%
    \ifnum\numspell@group@max=0\numspell@{zero}\fi%
}

%% SPELLING ORDINAL NUMBER
%% -----------------------------------------
%% \numspell@ordnum@spell@it{<num1>}{<num2>}
%% -----------------------------------------
%% \numspell@groups{<num1>}{<num2>}
%% Adding the \numspell@num ordinal spelling to \thenumspell
%%
\def\numspell@ordnum@spell@it#1#2{%
    \gdef\thenumspell{}%
    \numspell@groups{#1}{#2}%
    \setcounter{numspell@groupcount}{22}%
    \@whilenum\value{numspell@groupcount}>2%
    \do{%
        \IfEq{\csname numspell@group@\roman{numspell@groupcount}\endcsname}{0}{}{%
            \IfEq{\csname numspell@group@\roman{numspell@groupcount}\endcsname}{1}{\numspell@{un}}{}%
            \numspell@group@spell@it{\csname numspell@group@\roman{numspell@groupcount}\endcsname}%
            \numspell@{ }%
            \ifnum\csname numspell@group@\roman{numspell@groupcount}@before\endcsname>0%
                \IfEq{\csname numspell@group@\roman{numspell@groupcount}\endcsname}{1}%
                    {\csname numspell@group@\roman{numspell@groupcount}@it@name\endcsname}%
                    {\csname numspell@group@\roman{numspell@groupcount}@it@name@plural\endcsname}%
                \numspell@{ }%
            \else%
                \csname numspell@ordgroup@\roman{numspell@groupcount}@it@name\endcsname%
                \numspell@it@gender%
            \fi%
        }%
        \addtocounter{numspell@groupcount}{-1}%
    }%
    \IfEq{\numspell@group@ii}{0}{}{%
        \numspell@group@spell@it{\numspell@group@ii}%
        \ifnum\numspell@group@ii@before>0%
            \IfEq{\numspell@group@ii}{1}{\numspell@group@ii@it@name}{\numspell@group@ii@it@name@plural}%
        \else%
            \numspell@ordgroup@ii@it@name%
            \numspell@it@gender%
        \fi%
        \numspell@group@digits{\numspell@group@ii}%
        \ifnum\numspell@group@digit@i>0\ifnum\number\numexpr\numspell@group@digit@ii+\numspell@group@digit@iii>0%
            \ifnum\numspell@group@ii@before>0\numspell@{ }\fi%
        \fi\fi%
    }%
    \IfEq{\numspell@group@i}{0}{}{%
        \ifnum\numspell@group@max>1%
            \IfEq{\numspell@group@i}{1}{\numspell@{un}}{}%
            \numspell@ordgroup@spell@it{\numspell@group@i}%
            \numspell@{esim}%
            \numspell@it@gender%
        \else%
            \ifcase\numspell@group@i%
                \or\numspell@{prim}\or\numspell@{second}\or\numspell@{terz}\or\numspell@{quart}\or\numspell@{quint}%
                \or\numspell@{sest}\or\numspell@{settim}\or\numspell@{ottav}\or\numspell@{non}\or\numspell@{decim}%
            \else%
                \numspell@ordgroup@spell@it{\numspell@group@i}%
                \numspell@{esim}%
            \fi%
            \numspell@it@gender%
        \fi%
    }%
    \ifnum\numspell@group@max=0\numspell@{zeresim}\numspell@it@gender\fi%
}

%% ----------------------
%% \numspell@uppercase@it
%% ----------------------
%% E.g. \def\thenumspell{uno}\numspell@uppercase\thenumspell --> 'Uno'
%% \MakeUppercase does not work on pdf bookmark (see hyperref), so using another effective macro.
%%
\def\numspell@uppercase@it{%
    \fullexpandarg%
    \StrChar{\thenumspell}{1}[\numspell@firstletter]%
    \expandarg%
    \StrGobbleLeft{\thenumspell}{1}[\numspell@trunc]%
    \fullexpandarg%
    \def\numspell@the{}%
    \IfStrEq{\numspell@firstletter}{u}{\g@addto@macro\numspell@the{U}}{}% uno
    \IfStrEq{\numspell@firstletter}{d}{\g@addto@macro\numspell@the{D}}{}% due
    \IfStrEq{\numspell@firstletter}{t}{\g@addto@macro\numspell@the{T}}{}% tre
    \IfStrEq{\numspell@firstletter}{q}{\g@addto@macro\numspell@the{Q}}{}% quattro
    \IfStrEq{\numspell@firstletter}{c}{\g@addto@macro\numspell@the{C}}{}% cinque
    \IfStrEq{\numspell@firstletter}{s}{\g@addto@macro\numspell@the{S}}{}% sei
    \IfStrEq{\numspell@firstletter}{o}{\g@addto@macro\numspell@the{O}}{}% otto
    \IfStrEq{\numspell@firstletter}{n}{\g@addto@macro\numspell@the{N}}{}% nove
    \IfStrEq{\numspell@firstletter}{v}{\g@addto@macro\numspell@the{V}}{}% venti
    \IfStrEq{\numspell@firstletter}{m}{\g@addto@macro\numspell@the{M}}{}% mille
    \IfStrEq{\numspell@firstletter}{z}{\g@addto@macro\numspell@the{Z}}{}% zero
    \IfStrEq{\numspell@firstletter}{p}{\g@addto@macro\numspell@the{P}}{}% primo
    \ifx\numspell@the\@empty\@latexerr{'numspell.sty' error! There is not '\numspell@firstletter' in uppercase!}{}\fi%
    \g@addto@macro\numspell@the{\numspell@trunc}%
    \def\thenumspell{\numspell@the}%
}

\endinput