% \iffalse meta-comment
%
% Copyright (C) 2012-2013 by Robin Schneider <ypid23@aol.de>
%
% 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.
%
% The Current Maintainer of this work is Robin Schneider.
%
% This work consists of the files fnumprint.dtx and fnumprint.ins
% and the derived filebase fnumprint.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{fnumprint.dtx}
%</driver>
%<package>%% See file 'fnumprint.dtx' for copyright and licence.
%<package>\NeedsTeXFormat{LaTeX2e}[1998/12/01]
%<package>\ProvidesPackage{fnumprint}
%<*package>
    [2012/08/27 v1.1a Printing fancy numbers]
%</package>
%
%<*driver>
\documentclass[english]{ltxdoc}
\newcommand{\PackageURL}{https://github.com/ypid/latex-packages/tree/master/fnumprint}
\newcommand{\PackageCTANURL}{http://www.ctan.org/pkg/fnumprint}
\newcommand{\PackageAuthor}{Robin Schneider}
\newcommand{\PackageAuthorEmail}{ypid23@aol.de}
\newcommand{\PackageName}{\PrintPackage{fnumprint}}
\newcommand{\PrintPackage}[1]{\textsf{#1}}
\usepackage{fnumprint}
\usepackage{
  babel,
  csquotes,
  xcolor,
  url,
  hypdoc,
}
\GetFileInfo{fnumprint.dtx}
\hypersetup{
  pdftitle={A manual for \PackageName},
  pdfauthor={\PackageAuthor{} <\PackageAuthorEmail>},
  pdfsubject={\fileinfo},
  baseurl={\PackageURL},
  pdfkeywords={This document corresponds to \PackageName~\fileversion,
    dated \filedate}
}

\title{The \PackageName{} package\thanks{This document
corresponds to \PackageName~\fileversion, dated \filedate.}}
\author{\PackageAuthor \\
  \texttt{\href{mailto:\PackageAuthorEmail?subject=LaTeX package fnumprint%
    \&body=Dear Robin Schneider,}%
    {\PackageAuthorEmail}%
  }%
}

\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{fnumprint.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{101}
% \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{v0.1}{2011/06/12}{Initial version} %% ^^A date guessed
% \changes{v1.0}{2012/08/22}{Wrote this documentation and the \LaTeX{}-package
% and added support for English}
% \changes{v1.1}{2012/08/27}{Added optional parameter \enquote{ein}}
% \changes{v1.1a}{2012/08/27}{Added support for real numbers}
%
% \DoNotIndex{\RequirePackage, \DeclareOption, \ProcessOptions}
% \DoNotIndex{\PackageWarning, \MessageBreak}
% \DoNotIndex{\DeclareRobustCommand, \newcommand, \renewcommand}
% \DoNotIndex{\newenvironment}
% \DoNotIndex{\if, \else, \fi, \ifcase, \or, \ifthenelse, \AND, \value, \relax}
% \DoNotIndex{\equal, \@currname, \newcounter, \setcounter, \(, \), \NOT, \OR}
% \DoNotIndex{\endinput}
%
% \maketitle
%
% \phantomsection
% \addcontentsline{toc}{section}{\abstractname}
% \begin{abstract}
% The \PrintPackage{fnumprint} package can decide to typeset a
% number either as number or as word name (only in English or German). \\
% Information site on CTAN: \url{\PackageCTANURL} \\
% Fork me on GitHub: \url{\PackageURL} \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
% The \PackageName{} package defines two macros which decide to
% typeset a number either as Arabic number or as word name for the number. If
% the number is between zero and twelve (including zero and twelve) then the
% word name will be used. This package uses the \PrintPackage{zahl2string}
% package to convert a number in the word name in German. The conversion of a
% number (0--12) to the English word name is implemented by this package. If
% the number is outside of the range then it will be typesetted with the
% \PrintPackage{numprint} package.
%
% \section{Usage}
% Just load the package placing
% \begin{quote}
%   |\usepackage{fnumprint}|
% \end{quote}
% in the preamble of your \LaTeXe{} source file. In this case the last by
% \PackageName{} supported language given as class option will be
% used. You can overwrite this with a package option like
% this:
% \begin{quote}
%   |\usepackage[english]{fnumprint}|
% \end{quote}
%
% \DescribeMacro{\fnumprintc}
% The macro |\fnumprintc| \oarg{eins} \marg{\LaTeX{} counter name} takes a
% name of a LaTeX counter as not optional parameter and typesets it's
% value. The optional parameter is only active if the German language was
% selected. In this case it can be used to typeset \enquote{ein} instead of
% \enquote{eins}. This is for example necessary if you would like to typeset
% \enquote{ein Jahr}.
%
% \DescribeMacro{\fnumprint}
% The macro |\fnumprint| \oarg{eins} \marg{number} is like the |\fnumprintc|
% macro but it takes a number or a macro that expands to a number. A \TeX{}
% counter can also be used with this macro.
%
% \section{Examples}
% \begin{tabular}{ll}
%   \textbf{macro}           & \textbf{expanded macro} \\
%   |\fnumprint{-1}|         & \fnumprint{-1} \\
%   |\fnumprint{0}|          & \fnumprint{0} \\
%   |\fnumprint{1}|          & \fnumprint{1} \\
%   |\fnumprint{3.14}|       & \fnumprint{3.14} \\
%   |\fnumprint{10}|         & \fnumprint{10} \\
%   |\fnumprint{12}|         & \fnumprint{12} \\
%   |\fnumprint{13}|         & \fnumprint{13} \\
%   |\fnumprint{\the\month}| & \fnumprint{\the\month} \\
%   |\fnumprint{\the\day}|   & \fnumprint{\the\day} \\
%   |\fnumprintc{page}|      & \fnumprintc{page} \\
% \end{tabular}
%
% \section{ToDo}
% Here are some things that could be useful.
% \begin{itemize}
%   \item Provide more features implemented by the \PrintPackage{zahl2string}
%     package and create macros which implement these features for the
%     English language.
% \end{itemize}
%
% \StopEventually{}
%
% \section{Implementation}
% \iffalse
%<*package>
% \fi
% This package depends on these packages.
%    \begin{macrocode}
\RequirePackage{xifthen}
\RequirePackage[autolanguage]{numprint}
%    \end{macrocode}
% \subsection{Language checking}
% I used the counter |fnumprint@language| to save the (last) selected language.
% Meaning from the counter values:
%
% \begin{tabular}{rl}
%   \textbf{value}   & \textbf{meaning} \\
%   0   & no supported language selected \\
%   1   & German selected \\
%   2   & English selected \\
% \end{tabular}
%    \begin{macrocode}
\newcounter{fnumprint@language}
\setcounter{fnumprint@language}{0}
\DeclareOption{german}{\setcounter{fnumprint@language}{1}}
\DeclareOption{ngerman}{\setcounter{fnumprint@language}{1}}
\DeclareOption{english}{\setcounter{fnumprint@language}{2}}
\DeclareOption{USenglish}{\setcounter{fnumprint@language}{2}}
\DeclareOption{american}{\setcounter{fnumprint@language}{2}}
\DeclareOption{UKenglish}{\setcounter{fnumprint@language}{2}}
\DeclareOption{british}{\setcounter{fnumprint@language}{2}}
\DeclareOption{canadian}{\setcounter{fnumprint@language}{2}}
\DeclareOption{australian}{\setcounter{fnumprint@language}{2}}
\DeclareOption{newzealand}{\setcounter{fnumprint@language}{2}}
\ProcessOptions\relax
%    \end{macrocode}
% If none of the supported languages was selected a package warning will appear.
%    \begin{macrocode}
\ifcase\value{fnumprint@language}
  \PackageWarning{\@currname}{No supported language selected
    \MessageBreak
    This package supports only English and German
    \MessageBreak
    There will be no word names printed}
%    \end{macrocode}
% The zahl2string package will only be loaded if it is necessary.
%    \begin{macrocode}
\or
  \RequirePackage{zahl2string}
%    \end{macrocode}
% \begin{macro}{\ns@en@neunzehn}
% This internal marco expands to the English word name for a number.
% It only goes from 0 to 19. It will only be defined if it is necessary.
%    \begin{macrocode}
\or
  \newcommand{\ns@en@neunzehn}[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 sixteen\or seventeen\or%
    eighteen\or nineteen\fi%
  }
\fi
%    \end{macrocode}
% \end{macro}
% \subsection{Macro definition}
% \begin{macro}{\fnumprint}
% Here is the |\fnumprint| macro definition.
% It takes one not optional parameter.
% The parameter must be a number or a macro which expands to a number.
% It can also take a optional parameter which replaces the German word
% \enquote{eins} with \enquote{ein}.
%    \begin{macrocode}
\DeclareRobustCommand{\fnumprint}[2][]{%
  \ifthenelse{\NOT \(\isin{,}{#2} \OR \isin{.}{#2} \)
  \AND -1 < #2 \AND #2 < 13}{%
    \ifthenelse{\value{fnumprint@language} = 1}{%
      \ifthenelse{\equal{#1}{ein} \AND #2 = 1}{ein}{\numstr{#2}}%
    }{%
      \ifthenelse{\value{fnumprint@language} = 2}{%
        \ns@en@neunzehn{#2}%
      }{\numprint{#2}}%
    }%
  }{\numprint{#2}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\fnumprintc}
% Here is the |\fnumprintc| macro definition.
% It takes one not optional parameter.
% The parameter must be the name of a \LaTeX{} counter.
% It can also take a optional parameter which replaces the German word
% \enquote{eins} with \enquote{ein}.
%    \begin{macrocode}
\DeclareRobustCommand{\fnumprintc}[2][]{%
  \ifthenelse{-1 < \value{#2} \AND \value{#2} < 13}{%
    \ifthenelse{\value{fnumprint@language} = 1}{%
    \ifthenelse{\equal{#1}{ein} \AND \value{#2} = 1}{ein}{\numstring{#2}}}{%
      \ifthenelse{\value{fnumprint@language} = 2}{%
        \ns@en@neunzehn{\value{#2}}%
      }{\cntprint{#2}}%
    }%
  }{\cntprint{#2}}%
}
\endinput
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput