%%
%% `numspell-magyar.sty' Hungarian 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-magyar}[2017/02/09 v1.0 Hungarian language package for numspell]

%% Automatic Hungarian definite article ('a' or 'az')
%% ---------------
%% \numspell@az@hu
%% ---------------
%% E.g. \def\thenumspell{egy}\numspell@az@hu\thenumspell --> 'az egy'
%%      \def\thenumspell{hat}\numspell@az@hu\thenumspell --> 'a hat'
%%
\def\numspell@az@hu{%
    \fullexpandarg%
    \StrChar{\thenumspell}{1}[\numspell@firstletter]%
    \expandarg%
    \StrGobbleLeft{\thenumspell}{0}[\numspell@original]%
    \fullexpandarg%
    \def\numspell@the{}%
    \IfStrEq{\numspell@firstletter}{e}{\g@addto@macro\numspell@the{az }}{% az egy, az ezer
    \IfStrEq{\numspell@firstletter}{{\"{o}}}{\g@addto@macro\numspell@the{az }}{% az \"{o}t
    \g@addto@macro\numspell@the{a }}}% a hat
    \g@addto@macro\numspell@the{\numspell@original}%
    \def\thenumspell{\numspell@the}%
}

%% Automatic Hungarian definite article ('A' or 'Az')
%% ---------------
%% \numspell@Az@hu
%% ---------------
%% E.g. \def\thenumspell{egy}\numspell@Az@hu\thenumspell --> 'Az egy'
%%      \def\thenumspell{hat}\numspell@Az@hu\thenumspell --> 'A hat'
%%
\def\numspell@Az@hu{%
    \fullexpandarg%
    \StrChar{\thenumspell}{1}[\numspell@firstletter]%
    \expandarg%
    \StrGobbleLeft{\thenumspell}{0}[\numspell@original]%
    \fullexpandarg%
    \def\numspell@the{}%
    \IfStrEq{\numspell@firstletter}{e}{\g@addto@macro\numspell@the{Az }}{% Az egy, Az ezer
    \IfStrEq{\numspell@firstletter}{{\"{o}}}{\g@addto@macro\numspell@the{Az }}{% Az \"{o}t
    \g@addto@macro\numspell@the{A }}}% A hat, A nyolc,...
    \g@addto@macro\numspell@the{\numspell@original}%
    \def\thenumspell{\numspell@the}%
}

%% --------------------------
%% \anumspell[<num2>]{<num1>} (Default <num2> is 0)
%% --------------------------
%% \numspell@num@spell@hu{<num1>}{<num2>}
%% \numspell@az@hu
%% \thenumspell
%%
%% ---------------------------
%% \anumspell*[<num2>]{<num1>} works like \anumspell, but \thenumspell will not be expanded.
%% ---------------------------
%%
\newcommand{\anumspell@output}[2][0]{\numspell@num@spell@hu{#2}{#1}\numspell@az@hu\thenumspell}
\newcommand{\anumspell@@output}[2][0]{\numspell@num@spell@hu{#2}{#1}\numspell@az@hu\ignorespaces}
\DeclareRobustCommand*{\anumspell}{%
    \ifnum\pdf@strcmp{\languagename}{magyar}=\z@\else\@latexerr{'numspell.sty' error! \protect\anumspell\space supported only in 'magyar' language}{}\fi%
    \@ifstar{\anumspell@@output}{\anumspell@output}%
}

%% --------------------------
%% \Anumspell[<num2>]{<num1>} (Default <num2> is 0)
%% --------------------------
%% \numspell@num@spell@hu{<num1>}{<num2>}
%% \numspell@Az@hu
%% \thenumspell
%%
%% ---------------------------
%% \Anumspell*[<num2>]{<num1>} works like \Anumspell, but \thenumspell will not be expanded.
%% ---------------------------
%%
\newcommand{\Anumspell@output}[2][0]{\numspell@num@spell@hu{#2}{#1}\numspell@Az@hu\thenumspell}
\newcommand{\Anumspell@@output}[2][0]{\numspell@num@spell@hu{#2}{#1}\numspell@Az@hu\ignorespaces}
\DeclareRobustCommand*{\Anumspell}{%
    \ifnum\pdf@strcmp{\languagename}{magyar}=\z@\else\@latexerr{'numspell.sty' error! \protect\Anumspell\space supported only in 'magyar' language}{}\fi%
    \@ifstar{\Anumspell@@output}{\Anumspell@output}%
}

%% -----------------------------
%% \aordnumspell[<num2>]{<num1>} (Default <num2> is 0)
%% -----------------------------
%% \numspell@ordnum@spell@hu{<num1>}{<num2>}
%% \numspell@az@hu
%% \thenumspell
%%
%% ------------------------------
%% \aordnumspell*[<num2>]{<num1>} works like \aordnumspell, but \thenumspell will not be expanded.
%% ------------------------------
%%
\newcommand{\aordnumspell@output}[2][0]{\numspell@ordnum@spell@hu{#2}{#1}\numspell@az@hu\thenumspell}
\newcommand{\aordnumspell@@output}[2][0]{\numspell@ordnum@spell@hu{#2}{#1}\numspell@az@hu\ignorespaces}
\DeclareRobustCommand*{\aordnumspell}{%
    \ifnum\pdf@strcmp{\languagename}{magyar}=\z@\else\@latexerr{'numspell.sty' error! \protect\aordnumspell\space supported only in 'magyar' language}{}\fi%
    \@ifstar{\aordnumspell@@output}{\aordnumspell@output}%
}

%% -----------------------------
%% \Aordnumspell[<num2>]{<num1>} (Default <num2> is 0)
%% -----------------------------
%% \numspell@ordnum@spell@hu{<num1>}{<num2>}
%% \numspell@Az@hu
%% \thenumspell
%%
%% ------------------------------
%% \Aordnumspell*[<num2>]{<num1>} works like \Aordnumspell, but \thenumspell will not be expanded.
%% ------------------------------
%%
\newcommand{\Aordnumspell@output}[2][0]{\numspell@ordnum@spell@hu{#2}{#1}\numspell@Az@hu\thenumspell}
\newcommand{\Aordnumspell@@output}[2][0]{\numspell@ordnum@spell@hu{#2}{#1}\numspell@Az@hu\ignorespaces}
\DeclareRobustCommand*{\Aordnumspell}{%
    \ifnum\pdf@strcmp{\languagename}{magyar}=\z@\else\@latexerr{'numspell.sty' error! \protect\Aordnumspell\space supported only in 'magyar' language}{}\fi%
    \@ifstar{\Aordnumspell@@output}{\Aordnumspell@output}%
}

%% GROUP NAMES
\def\numspell@group@ii@hu@name{\numspell@{ezer}}
\def\numspell@group@iii@hu@name{\numspell@{milli\'{o}}}
\def\numspell@group@iv@hu@name{\numspell@{milli\'{a}rd}}
\def\numspell@group@v@hu@name{\numspell@{billi\'{o}}}
\def\numspell@group@vi@hu@name{\numspell@{billi\'{a}rd}}
\def\numspell@group@vii@hu@name{\numspell@{trilli\'{o}}}
\def\numspell@group@viii@hu@name{\numspell@{trilli\'{a}rd}}
\def\numspell@group@ix@hu@name{\numspell@{kvadrilli\'{o}}}
\def\numspell@group@x@hu@name{\numspell@{kvadrilli\'{a}rd}}
\def\numspell@group@xi@hu@name{\numspell@{kvintilli\'{o}}}
\def\numspell@group@xii@hu@name{\numspell@{kvintilli\'{a}rd}}
\def\numspell@group@xiii@hu@name{\numspell@{szextilli\'{o}}}
\def\numspell@group@xiv@hu@name{\numspell@{szextilli\'{a}rd}}
\def\numspell@group@xv@hu@name{\numspell@{szeptilli\'{o}}}
\def\numspell@group@xvi@hu@name{\numspell@{szeptilli\'{a}rd}}
\def\numspell@group@xvii@hu@name{\numspell@{oktilli\'{o}}}
\def\numspell@group@xviii@hu@name{\numspell@{oktilli\'{a}rd}}
\def\numspell@group@xix@hu@name{\numspell@{nonilli\'{o}}}
\def\numspell@group@xx@hu@name{\numspell@{nonilli\'{a}rd}}
\def\numspell@group@xxi@hu@name{\numspell@{decilli\'{o}}}
\def\numspell@group@xxii@hu@name{\numspell@{decilli\'{a}rd}}

%% ORDINAL GROUP NAMES
\def\numspell@ordgroup@ii@hu@name{\numspell@{ezredik}}
\def\numspell@ordgroup@iii@hu@name{\numspell@{milliomodik}}
\def\numspell@ordgroup@iv@hu@name{\numspell@{milli\'{a}rdodik}}
\def\numspell@ordgroup@v@hu@name{\numspell@{billiomodik}}
\def\numspell@ordgroup@vi@hu@name{\numspell@{billi\'{a}rdodik}}
\def\numspell@ordgroup@vii@hu@name{\numspell@{trilliomodik}}
\def\numspell@ordgroup@viii@hu@name{\numspell@{trilli\'{a}rdodik}}
\def\numspell@ordgroup@ix@hu@name{\numspell@{kvadrilliomodik}}
\def\numspell@ordgroup@x@hu@name{\numspell@{kvadrilli\'{a}rdodik}}
\def\numspell@ordgroup@xi@hu@name{\numspell@{kvintilliomodik}}
\def\numspell@ordgroup@xii@hu@name{\numspell@{kvintilli\'{a}rdodik}}
\def\numspell@ordgroup@xiii@hu@name{\numspell@{szextilliomodik}}
\def\numspell@ordgroup@xiv@hu@name{\numspell@{szextilli\'{a}rdodik}}
\def\numspell@ordgroup@xv@hu@name{\numspell@{szeptilliomodik}}
\def\numspell@ordgroup@xvi@hu@name{\numspell@{szeptilli\'{a}rdodik}}
\def\numspell@ordgroup@xvii@hu@name{\numspell@{oktilliomodik}}
\def\numspell@ordgroup@xviii@hu@name{\numspell@{oktilli\'{a}rdodik}}
\def\numspell@ordgroup@xix@hu@name{\numspell@{nonilliomodik}}
\def\numspell@ordgroup@xx@hu@name{\numspell@{nonilli\'{a}rdodik}}
\def\numspell@ordgroup@xxi@hu@name{\numspell@{decilliomodik}}
\def\numspell@ordgroup@xxii@hu@name{\numspell@{decilli\'{a}rdodik}}

%% SPELLING CARDINAL NUMBER GROUP
%% ---------------------------------
%% \numspell@group@spell@hu{<group>} (<group>=000,001,...,999)
%% ---------------------------------
%% \numspell@group@digits{<group>}
%% Adding the <group> spelling to \thenumspell
%%
\def\numspell@group@spell@hu#1{%
    \numspell@group@digits{#1}%
    \ifcase\numspell@group@digit@i%
        \or\or\numspell@{k\'{e}t}\or\numspell@{h\'{a}rom}\or\numspell@{n\'{e}gy}\or\numspell@{{\"{o}}t}% 1 --> 'ezeregysz\'{a}z' but 'sz\'{a}z'
        \or\numspell@{hat}\or\numspell@{h\'{e}t}\or\numspell@{nyolc}\or\numspell@{kilenc}%
    \fi%
    \ifnum\numspell@group@digit@i>0%
        \numspell@{sz\'{a}z}%
    \fi%
    \ifnum\numspell@group@digit@iii>0%
        \ifcase\numspell@group@digit@ii%
            \or\numspell@{tizen}\or\numspell@{huszon}%
        \fi%
    \else%
        \ifcase\numspell@group@digit@ii%
            \or\numspell@{t\'{i}z}\or\numspell@{h\'{u}sz}%
        \fi%
    \fi%
    \ifcase\numspell@group@digit@ii%
        \or\or\or\numspell@{harminc}\or\numspell@{negyven}\or\numspell@{{\"{o}}tven}\or\numspell@{hatvan}%
        \or\numspell@{hetven}\or\numspell@{nyolcvan}\or\numspell@{kilencven}%
    \fi%
    \ifcase\numspell@group@digit@iii%
        \or\numspell@{egy}\or\or\numspell@{h\'{a}rom}\or\numspell@{n\'{e}gy}\or\numspell@{{\"{o}}t}% 2 --> 'k\'{e}t' or 'kett\H{o}'
        \or\numspell@{hat}\or\numspell@{h\'{e}t}\or\numspell@{nyolc}\or\numspell@{kilenc}%
    \fi%
}

%% SPELLING ORDINAL NUMBER GROUP
%% ------------------------------------
%% \numspell@ordgroup@spell@hu{<group>} (<group>=000,001,...,999)
%% ------------------------------------
%% \numspell@group@digits{<group>}
%% Adding the <group> ordinal spelling to \thenumspell
%%
\def\numspell@ordgroup@spell@hu#1{%
    \numspell@group@digits{#1}%
    \ifcase\numspell@group@digit@i%
        \or\or\numspell@{k\'{e}t}\or\numspell@{h\'{a}rom}\or\numspell@{n\'{e}gy}\or\numspell@{{\"{o}}t}% 1 --> 'ezeregysz\'{a}z' but 'sz\'{a}z'
        \or\numspell@{hat}\or\numspell@{h\'{e}t}\or\numspell@{nyolc}\or\numspell@{kilenc}%
    \fi%
    \ifnum\numspell@group@digit@i>0%
        \ifnum\number\numexpr\numspell@group@digit@i*(\numspell@group@digit@ii+\numspell@group@digit@iii)>0%
            \numspell@{sz\'{a}z}%
        \else%
            \numspell@{sz\'{a}zadik}%
        \fi%
    \fi%
    \ifnum\numspell@group@digit@iii>0%
        \ifcase\numspell@group@digit@ii%
            \or\numspell@{tizen}\or\numspell@{huszon}\or\numspell@{harminc}\or\numspell@{negyven}\or\numspell@{{\"{o}}tven}%
            \or\numspell@{hatvan}\or\numspell@{hetven}\or\numspell@{nyolcvan}\or\numspell@{kilencven}%
        \fi%
    \else%
        \ifcase\numspell@group@digit@ii%
            \or\numspell@{tizedik}\or\numspell@{huszadik}\or\numspell@{harmincadik}\or\numspell@{negyvenedik}%
            \or\numspell@{{\"{o}}tvenedik}\or\numspell@{hatvanadik}\or\numspell@{hetvenedik}%
            \or\numspell@{nyolcvanadik}\or\numspell@{kilencvenedik}%
        \fi%
    \fi%
    \ifcase\numspell@group@digit@iii%
        \or\or\or\numspell@{harmadik}\or\numspell@{negyedik}\or\numspell@{{\"{o}}t\"{o}dik}% 1 --> 'els\H{o}' or 'egyedik' 2 --> 'm\'{a}sodik' or 'kettedik'
        \or\numspell@{hatodik}\or\numspell@{hetedik}\or\numspell@{nyolcadik}\or\numspell@{kilencedik}%
    \fi%
}

%% SPELLING CARDINAL NUMBER
%% --------------------------------------
%% \numspell@num@spell@hu{<num1>}{<num2>}
%% --------------------------------------
%% \numspell@groups{<num1>}{<num2>}
%% Adding the \numspell@num spelling to \thenumspell
%%
\def\numspell@num@spell@hu#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}{}{%
            \numspell@group@digits{\csname numspell@group@\roman{numspell@groupcount}\endcsname}%
            \ifnum\numspell@group@max>\value{numspell@groupcount}%
                \ifcase\numspell@group@digit@i\or\numspell@{egy}\fi%
            \fi%
            \numspell@group@spell@hu{\csname numspell@group@\roman{numspell@groupcount}\endcsname}%
            \ifcase\numspell@group@digit@iii\or\or\numspell@{k\'{e}t}\fi%
            \csname numspell@group@\roman{numspell@groupcount}@hu@name\endcsname%
            \ifnum\numspell@group@min<\value{numspell@groupcount}\numspell@dash@\fi%
        }%
        \addtocounter{numspell@groupcount}{-1}%
    }%
    \IfEq{\numspell@group@ii}{0}{}{%
        \numspell@group@digits{\numspell@group@ii}%
        \ifnum\numspell@group@max>2%
            \ifcase\numspell@group@digit@i\or\numspell@{egy}\fi%
        \fi%
        \IfEq{\numspell@group@ii}{1}{%
            \ifnum\numspell@group@max>2%
                \numspell@group@spell@hu{\numspell@group@ii}%
            \fi}%
            {\numspell@group@spell@hu{\numspell@group@ii}}%
        \ifcase\numspell@group@digit@iii\or\or\numspell@{k\'{e}t}\fi%
        \numspell@group@ii@hu@name%
        \ifnum\numspell@group@min<2%
            \IfEq{\numspell@group@ii}{1}{}{\numspell@dash@}%
        \fi%
    }%
    \IfEq{\numspell@group@i}{0}{}{%
        \numspell@group@digits{\numspell@group@i}%
        \ifnum\numspell@group@max>1%
            \ifcase\numspell@group@digit@i\or\numspell@{egy}\fi%
        \fi%
        \numspell@group@spell@hu{\numspell@group@i}%
        \ifcase\numspell@group@digit@iii\or\or\numspell@{kett\H{o}}\fi%
    }%
    \ifnum\numspell@group@max=0\numspell@{nulla}\fi%
}

%% SPELLING ORDINAL NUMBER
%% -----------------------------------------
%% \numspell@ordnum@spell@hu{<num1>}{<num2>}
%% -----------------------------------------
%% \numspell@groups{<num1>}{<num2>}
%% Adding the \numspell@num ordinal spelling to \thenumspell
%%
\def\numspell@ordnum@spell@hu#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}{}{%
            \numspell@group@digits{\csname numspell@group@\roman{numspell@groupcount}\endcsname}%
            \ifnum\numspell@group@max>\value{numspell@groupcount}%
                \ifcase\numspell@group@digit@i\or\numspell@{egy}\fi%
            \fi%
            \numspell@group@spell@hu{\csname numspell@group@\roman{numspell@groupcount}\endcsname}%
            \ifcase\numspell@group@digit@iii\or\or\numspell@{k\'{e}t}\fi%
            \ifnum\numspell@group@min<\value{numspell@groupcount}%
                \csname numspell@group@\roman{numspell@groupcount}@hu@name\endcsname%
                \numspell@dash@%
            \else%
                \csname numspell@ordgroup@\roman{numspell@groupcount}@hu@name\endcsname%
            \fi%
        }%
        \addtocounter{numspell@groupcount}{-1}%
    }%
    \IfEq{\numspell@group@ii}{0}{}{%
        \numspell@group@digits{\numspell@group@ii}%
        \ifnum\numspell@group@max>2%
            \ifcase\numspell@group@digit@i\or\numspell@{egy}\fi%
        \fi%
        \IfEq{\numspell@group@ii}{1}{%
            \ifnum\numspell@group@max>2%
                \numspell@group@spell@hu{\numspell@group@ii}%
            \fi}%
            {\numspell@group@spell@hu{\numspell@group@ii}}%
        \ifcase\numspell@group@digit@iii\or\or\numspell@{k\'{e}t}\fi%
        \ifnum\numspell@group@min<2%
            \numspell@group@ii@hu@name%
            \IfEq{\numspell@group@ii}{1}{}{\numspell@dash@}%
        \else%
            \numspell@ordgroup@ii@hu@name%
        \fi%
    }%
    \IfEq{\numspell@group@i}{0}{}{%
        \numspell@group@digits{\numspell@group@i}%
        \ifnum\numspell@group@max>1%
            \ifcase\numspell@group@digit@i\or\numspell@{egy}\fi%
        \fi%
        \numspell@ordgroup@spell@hu{\numspell@group@i}%
        \ifnum\numspell@numlength>1%
            \ifcase\numspell@group@digit@iii%
                \or\numspell@{egyedik}\or\numspell@{kettedik}%
            \fi%
        \else%
            \ifcase\numspell@group@digit@iii%
                \or\numspell@{els\H{o}}\or\numspell@{m\'{a}sodik}%
            \fi%
        \fi%
    }%
    \ifnum\numspell@group@max=0\numspell@{nulladik}\fi%
}

%% ----------------------
%% \numspell@uppercase@hu
%% ----------------------
%% E.g. \def\thenumspell{egy}\numspell@uppercase\thenumspell --> 'Egy'
%% \MakeUppercase does not work on pdf bookmark (see hyperref), so using another effective macro.
%%
\def\numspell@uppercase@hu{%
    \fullexpandarg%
    \StrChar{\thenumspell}{1}[\numspell@firstletter]%
    \expandarg%
    \StrGobbleLeft{\thenumspell}{1}[\numspell@trunc]%
    \fullexpandarg%
    \def\numspell@the{}%
    \IfStrEq{\numspell@firstletter}{e}{\g@addto@macro\numspell@the{E}}{}% egy
    \IfStrEq{\numspell@firstletter}{k}{\g@addto@macro\numspell@the{K}}{}% kett\H{o}
    \IfStrEq{\numspell@firstletter}{m}{\g@addto@macro\numspell@the{M}}{}% m\'{a}sodik
    \IfStrEq{\numspell@firstletter}{h}{\g@addto@macro\numspell@the{H}}{}% h\'{a}rom
    \IfStrEq{\numspell@firstletter}{n}{\g@addto@macro\numspell@the{N}}{}% n\'{e}gy
    \IfStrEq{\numspell@firstletter}{{\"{o}}}{\g@addto@macro\numspell@the{\"{O}}}{}% \"{o}t
    \IfStrEq{\numspell@firstletter}{t}{\g@addto@macro\numspell@the{T}}{}% t\'{i}z
    \IfStrEq{\numspell@firstletter}{s}{\g@addto@macro\numspell@the{S}}{}% sz\'{a}z
    \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