% \iffalse meta comment
% File: numprint.dtx Copyright (C) 2000, 2001 Harald Harders
% $Id: numprint.dtx,v 1.4 2001/03/12 17:22:55 harders Exp $
% \fi
%
% \iffalse
%
%<*package>
\def\packagename{numprint}
\def\fileversion{0.06}
\def\filedate{2002/09/18}
\def\docdate{2002/09/18}
%</package>
%<*driver>
\documentclass{ltxdoc}
\IfFileExists{numprint.sty}{\usepackage{numprint}
 \let\numprintSTYfound\active}{\GenericWarning{numprint.dtx}{Package
 file numprint.sty not found (Documentation will be messed up!^^J^^A
 Generate numprint.sty by (La)TeXing numprint.ins, process
 numprint.dtx again)^^J}\stop}
\usepackage{longtable}
\title{The \texttt{numprint} package\thanks{This file has version 
    \fileversion\ last revised \filedate, documentation dated \docdate.}}
\author{Harald Harders\\\texttt{h.harders@tu-bs.de}}
\date{File Date \filedate, Printed \today}
\newlength{\tempdima}%
\makeatletter
\renewenvironment{table}[1][]{%
  \@float{table}[#1]%
  \centering%
  \setlength{\tempdima}{\abovecaptionskip}%
  \setlength{\abovecaptionskip}{\belowcaptionskip}%
  \setlength{\belowcaptionskip}{\tempdima}%
  }{%
\end@float
}
\makeatother
\EnableCrossrefs
\CodelineIndex
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter}
\DoNotIndex{\setcounter,\space}
\CodelineNumbered
\RecordChanges
\CheckSum{624}
\begin{document}
 \DocInput{numprint.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{0.01}{2000/08/30}{Changed to dtx format}
%
% \maketitle
% \begin{abstract}
% \noindent This package prints numbers with a separator every three
% digits and it converts numbers given as \verb|123e456| to $123\cdot 
% 10^{456}$.
% \end{abstract}
%
% \tableofcontents
%
% \section*{Copyright}
% Copyright 2000, 2001, 2002 Harald Harders.
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.
%
% \section{The user interface}
%
% To use this package place
% \begin{verbatim}
% \usepackage{numprint}
% \end{verbatim}
% in the preamble of your document. No options are necessary.
%
% \subsection{Print numbers in text and math mode}
%
% \DescribeMacro{\numprint}%
% The package provides the command \verb|\numprint[#1]{#2}| that prints
% the number given in the required argument. The number is printed in the
% active mode (math or text) so that an eventual chosen difference
% between mathematical and text numbers stays visible (e.g. by using
% the eco-package.
%
% Numbers may contain of these characters:
% ``+-0123456789.,eE''. Either a ``,'' or a ''.'' can be used as
% decimal sign. No thousand separators are allowed in the
% argument. ``E'' or ``e'' is converted to $\cdot 10^{x}$.
%
% For example typing
% \begin{verbatim}
% \numprint{-123456}; \numprint[N/mm^2]{-123456}; \numprint{3,1415927e-3.1}
% \end{verbatim}
% leads to ``\numprint{-123456}; \numprint[N/mm^2]{-123456};
% \numprint{3,1415927e-3.1}''. Notice 
% that ``.'' and ``,'' can be mixed within one number.
%
% If no number is given before the exponential character ``e''
% resp. ``E'' a pure exponential format is generated.
% For example typing
% \begin{verbatim}
% \numprint{e4.3242}
% \end{verbatim}
% leads to ``\numprint{e4.3242}''.
% \changes{0.04}{2001/03/06}{Added support for pure $10^x$ format}%
%
% \changes{0.02}{2000/08/30}{Added optional argument for units}%
% If the optional argument is given it is printed as a unit in math
% mode with an upright font (\verb|\mathrm|). The space between the
% number and the unit is \verb|\,| by default. It can be changed using
% the command |\unitseparator|.
%
% \DescribeMacro{\thousandsep}%
% \DescribeMacro{\thousandthpartsep}%
% \DescribeMacro{\decimalsign}%
% \DescribeMacro{\productsign}%
% By using the three commands \verb|\thousandsep{#1}|,
% \verb|\decimalsign{#1}|, and
% \verb|\productsign{#1}| several separators can be
% changed. E.g.
% \begin{verbatim}
% \decimalsign{.}\thousandsep{,}\productsign{\times}%
% \numprint{-123456}; \numprint{3,1415927e-3.1}
% \end{verbatim}
% leads to ``{\decimalsign{.}\thousandsep{,}\productsign{\times}%
% \numprint{-123456}; \numprint{3,1415927e-3.1}}''.
%
% \DescribeMacro{\global}%
% These commands change the behaviour of the \verb|\numprint| command
% only locally (inside the current group). By preceding \verb|\global| 
% the change can be made global. For example:
% \begin{verbatim}
% Local:
% \numprint{123e4},
% {\productsign{\times}\numprint{123e4}},
% \numprint{123e4}.
% Global:
% \numprint{123e4},
% {\global\productsign{\times}\numprint{123e4}},
% \numprint{123e4}
% \end{verbatim}
% leads to the following:
%
% \noindent Local:
% \numprint{123e4},
% {\productsign{\times}\numprint{123e4}},
% \numprint{123e4}.
% Global:
% \numprint{123e4},
% {\global\productsign{\times}\numprint{123e4}},
% \numprint{123e4}
% \productsign{\cdot}
%
% The current version has the following defaults:
% \begin{verbatim}
% \thousandsep{\,}
% \thousandthpartsep{\,}
% \decimalsign{,}
% \productsign{{}\cdot{}}
% \unitseparator{\,}
% \end{verbatim}
% These will surely change in a new version when I add automatic
% international support. Then the defaults will by language dependent.
%
% \subsection{Change the behaviour}
%
% \DescribeMacro{\fourdigitsep}%
% \DescribeMacro{\fourdigitnosep}%
% \changes{0.06}{2002/09/18}{Add description for not separating four
% digit numbers}%
% Some people want numbers with four digits not to be devided by a
% thousand separator.
% This can be achieved using the command |\fourdigitnosep|.
% You can switch back to separating with |\fourdigitsep|.
% An example:
% \begin{verbatim}
% \fourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ --
% \fourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$
% \end{verbatim}
% Leads to
% '\fourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ --
% \fourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$'.
% Default values can be set by the package options |sepfour| and
% |nosepfour|.
%
% \DescribeMacro{\addmissingzero}%
% \DescribeMacro{\noaddmissingzero}%
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before
%   and after decimalsign}%
% Sometimes people let out a leading zero or a zero after the
% decimalsign, e.g. |123.| or |.123|. 
% Numprint can add the left out zero, when |\addmissingzero| is
% used. This behaviour can be switched of with |\noaddmissingzero|.
% Corresponding package options are |addmissingzero| and
% |noaddmissinzero|. Default is |addmissingzero|.
%
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% \subsection{Print aligned numbers in tabulars}
%
% The aim of this function is to combine the functionality of the
% \verb|dcolumn| package with this one. This has not been achieved by
% this version. But a first step is done.
%
% \DescribeMacro{columntype n}
% \DescribeMacro{columntype N}
% This package defines two new column types \verb|n| and \verb|N|. The
% first one alignes the base number to the decimal sign, the second
% additionaly alignes the exponent.
% Use these commands like follows:
% \begin{verbatim}
% \begin{tabular}{|n{5}{3}|N{5}{3}{3}|}
% \hline
% \numprint{123.45e12.12}& \numprint{123.45e12.12}\\
% \numprint{12345.678e123.123}& \numprint{12345.678e123.123}\\
% \hline
% \end{tabular}
% \end{verbatim}
% This leads to\par
% \begin{tabular}{|n{5}{3}|N{5}{3}{3}|}
% \hline
% \numprint{123.45e12.12}& \numprint{123.45e12.12}\\
% \numprint{12345.678e123.123}& \numprint{12345.678e123.123}\\
% \hline
% \end{tabular}
%
% The first option defines the number of digits before the decimal
% sign, the second the number after.
% In case of the type \verb|N| the third option defines the number of
% digits before the decimal sign in the exponent.
% Unfortunately the number of digits can not be calculated
% automatically.
% Notice that the command \verb|\numprint| has to be written again in
% each tabular entry. This will hopefully be changed in a future version.
%
% \section{To Do}
%
% \begin{itemize}
% \item Add automatic international support using babel, german, or ngerman:
%
% German: \decimalsign{,}\thousandsep{\,}\productsign{\cdot}%
% \numprint{3,1415927e-3.1}
%
% American: \decimalsign{.}\thousandsep{,}\productsign{\times}%
% \numprint{3,1415927e-3.1}
% \item Combine the packages dcolumn and numprint.
% \item Fix spacing in aligned exponents (spacing is too large).
% \end{itemize}
%
% \StopEventually{\PrintChanges \PrintIndex}
%
%
% \section{The implementation}
% \iffalse
%<*package>
% \fi
% Heading of the package:
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{numprint}[\filedate\space v\fileversion\space Print numbers]
\message{Package `numprint', Version \fileversion\space of \filedate.}
%    \end{macrocode}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% Load package calc.sty for calculating widths of boxes.
%    \begin{macrocode}
\RequirePackage{calc}
%    \end{macrocode}
% Load package array.sty for the new column types.
%    \begin{macrocode}
\RequirePackage{array}
%    \end{macrocode}
% Define a boolean if the first digit is separated in a four digit
% number. Default is true for compatibility with older versions.
%    \begin{macrocode}
\newif\if@numsepfour
%    \end{macrocode}
% Define a command which helds the zero to be added if necessary.
%    \begin{macrocode}
\newcommand\@addmissingzero{}
%    \end{macrocode}
% \begin{macro}{\fourdigitsep}
% Switch separating of the fourth digit on.
%    \begin{macrocode}
\newcommand*{\fourdigitsep}{\@numsepfourtrue}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\fourdigitnosep}
% Switch separating of the fourth digit off.
%    \begin{macrocode}
\newcommand*{\fourdigitnosep}{\@numsepfourfalse}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\addmissingzero}
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before
%   and after decimalsign}%
% Add a missing zero before or after decimalsign.
%    \begin{macrocode}
\newcommand*{\addmissingzero}{\def\@addmissingzero{0}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\noaddmissingzero}
% Don't add a missing zero before or after decimalsign.
%    \begin{macrocode}
\newcommand*{\noaddmissingzero}{\def\@addmissingzero{}}%
%    \end{macrocode}
% \end{macro}
% Declare options. \verb|nosepfour| switches seperating of the fourth
% digit off, \verb|sepfour| switches it on. Default is on four
% compatibility reasons with older versions.
%    \begin{macrocode}
\DeclareOption{nosepfour}{\fourdigitnosep}
\DeclareOption{sepfour}{\fourdigitsep}
\DeclareOption{noaddmissingzero}{\noaddmissingzero}
\DeclareOption{addmissingzero}{\addmissingzero}
\ExecuteOptions{sepfour,addmissingzero}
\ProcessOptions\relax
%    \end{macrocode}
% Define commands to change the output of the \verb|\numprint|
% command.
%
% \begin{macro}{\decimalsign}
% Change the decimal sign. In English it is normally ``.'', in German
% ``,''.
% The additional pair of braces \verb|{}| prevents from inserting
% additional space in math mode, e.g. $1,2$ versus $1{,}2$.
%    \begin{macrocode}
\newcommand{\decimalsign}[1]{\def\nprt@decimal{{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\thousandsep}
% Change the thousand separator. In English it often is ``,'', in
% German ``.'' or ``\,'' (\verb|\,|).
% Here again the additional \verb|{}| is used as above.
% This command changes both the sign before and after the comma. If
% you want a different sign after the comma you have to call
% \verb|\thousandthpartsep| after \verb|\thousandsep|.
%    \begin{macrocode}
\newcommand{\thousandsep}[1]{\def\nprt@thousand{{#1}}%
  \def\nprt@thousandthpart{{#1}}}
%    \end{macrocode}
% \end{macro}%
% \begin{macro}{\thousandthpartsep}
%    \begin{macrocode}
\newcommand{\thousandthpartsep}[1]{\def\nprt@thousandthpart{{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\productsign}
% Change the product sign that is printed in numbers with exponent
% like $\numprint{123e4}$. Normally it is \verb|\cdot|. In American
% texts sometimes \verb|\times|.
% The two pairs of braces \verb|{}| ensure the correct spacing on the
% left and right side of the product sign, e.g. 3$\cdot$4 versus
% 3${}\cdot{}$4.
%    \begin{macrocode}
\newcommand{\productsign}[1]{\def\nprt@prod{\ensuremath{{}#1{}}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\unitseparator}
% Change the separator between number an unit.
% Here again the additional \verb|{}| is used as above.
% \changes{0.03}{2001/02/10}{Fixed bug with units}%
%    \begin{macrocode}
\newcommand{\unitseparator}[1]{\def\nprt@unitsep{{#1}}}
%    \end{macrocode}
% \end{macro}
% Set the default values for the separators. They will surely change
% in a new version with automatic international support. At the moment 
% the defaults match the German language.
%    \begin{macrocode}
\thousandsep{\,}%
\thousandthpartsep{\,}%
\decimalsign{,}%
\productsign{{}\cdot{}}%
\unitseparator{\,}%
%    \end{macrocode}
% Define the signs as commands. This is necessary to be able to
% compare them with other characters. 
%    \begin{macrocode}
\def\nprt@plus@test{+}
\def\nprt@minus@test{-}
%    \end{macrocode}
% Define commands for printing the signs in math mode. This ensures
% that the printed signs really are signs and not hyphens. Compare
% ``-'' to ``\ensuremath{-}''.
%    \begin{macrocode}
\def\nprt@plus{\ensuremath{+}}
\def\nprt@minus{\ensuremath{-}}
%    \end{macrocode}
% \begin{macro}{\nprt@printdigit}
% Print a digit. If this digit is a sign (\verb|+| or \verb|-|) it is
% printed in math mode, else it is printed in the active mode.
%    \begin{macrocode}
\def\nprt@printdigit#1{%
  \def\nprt@tmp{#1}%
  \ifx\nprt@tmp\nprt@plus@test
    \nprt@plus
  \else
    \ifx\nprt@tmp\nprt@minus@test
      \nprt@minus
    \else
      #1%
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% Define some booleans.
% \verb|\ifnprt@block| decides whether the number is centered to the
% decimal sign.
% \verb|\ifnprt@blockexp| does the same for the exponent.
% \verb|\ifnprt@exponent| is true when printing the exponent and false
% otherwise.
% \verb|\ifnprt@inmath| is set to true when using the command in math
% mode.
%    \begin{macrocode}
\newif\ifnprt@block
\newif\ifnprt@blockexp
\newif\ifnprt@exponent
\newif\ifnprt@inmath
%    \end{macrocode}
% \begin{macro}{\digits}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% With this command the user can switch to aligned printing.
% The first parameter stands for the digits before the decimal sign
% and the second for the digits after it.
%    \begin{macrocode}
\newcommand{\digits}[2]{%
  \xdef\nprt@blockbefore{#1}%
  \xdef\nprt@blockafter{#2}%
  \nprt@blocktrue}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nodigits}
% Switch back to normal printing.
%    \begin{macrocode}
\newcommand{\nodigits}{\nprt@blockfalse}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\exponentdigits}
% With this command the user can switch to aligned printing of the
% exponent.
% The parameter stands for the digits before the decimal sign.
%    \begin{macrocode}
\newcommand{\exponentdigits}[1]{%
  \xdef\nprt@blockexpbefore{#1}%
  \nprt@blockexptrue}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\noexponentdigits}
% Switch back to normal printing.
%    \begin{macrocode}
\newcommand{\noexponentdigits}{\nprt@blockexpfalse}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@three}
% Print up to three digits and call this command again recursively if there
% are more digits to print.
%
% The command must be called in a different way than normal \LaTeX\
% commands. Braces must not be used but at the end of the command
% list \verb|\@empty| has to appear in the source code. The command
% gets four arguments where the first three are single digits and the
% fourth contains the rest of the text preceding the \verb|\@empty|.
%    \begin{macrocode}
\def\nprt@three#1#2#3#4\@empty{%
%    \end{macrocode}
% Print the three digits.
%    \begin{macrocode}
  \nprt@printdigit#1%
  \nprt@printdigit#2%
  \nprt@printdigit#3%
%    \end{macrocode}
% Define a temporary variable containing the rest string for testing
% if there is a rest at all.
%    \begin{macrocode}
  \def\nprt@tmp{#4}%
  \ifx\nprt@tmp\empty
  \else
%    \end{macrocode}
% If there is a rest string insert the thousand separator \dots
%    \begin{macrocode}
    \nprt@thousand%
%    \end{macrocode}
% \dots\ and call this command recursively.
% Append enough \verb|\@empty| statements to ensure that the command
% gets four arguments.
%    \begin{macrocode}
    \nprt@three#4\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@threeafter}
% Print up to three digits and call this command again recursively if there
% are more digits to print. For use after the decimal sign.
%    \begin{macrocode}
\def\nprt@threeafter#1#2#3#4\@empty{%
%    \end{macrocode}
% Print the three digits.
%    \begin{macrocode}
  \nprt@printdigit#1%
  \nprt@printdigit#2%
  \nprt@printdigit#3%
%    \end{macrocode}
% Define a temporary variable containing the rest string for testing
% if there is a rest at all.
%    \begin{macrocode}
  \def\nprt@tmp{#4}%
  \ifx\nprt@tmp\empty
  \else
%    \end{macrocode}
% If there is a rest string insert the thousand separator \dots
%    \begin{macrocode}
    \nprt@thousandthpart%
%    \end{macrocode}
% \dots\ and call this command recursively.
% Append enough \verb|\@empty| statements to ensure that the command
% gets four arguments.
%    \begin{macrocode}
    \nprt@threeafter#4\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@two}
% Print two digits and call \verb|\nprt@three| if there
% are more digits to print. This command is maximally used once at the 
% beginning of the number when it contains 2, 5, 8, 11, \dots\ digits
% before the decimal sign. For a description have a look at
% \verb|\nprt@three|.
%    \begin{macrocode}
\def\nprt@two#1#2#3\@empty{%
  \nprt@printdigit#1%
  \nprt@printdigit#2%
  \def\nprt@tmp{#3}%
  \ifx\nprt@tmp\empty
  \else
    \nprt@thousand\nprt@three#3\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@one}
% Print one digit and call \verb|\nprt@three| if there
% are more digits to print. This command is maximally used once at the 
% beginning of the number when it contains 1, 4, 7, 10, \dots\ digits
% before the decimal sign. For a description watch \verb|\nprt@three|.
%    \begin{macrocode}
\def\nprt@one#1#2\@empty{%
  \nprt@printdigit#1%
  \def\nprt@tmp{#2}%
  \ifx\nprt@tmp\empty
  \else
%    \end{macrocode}
% Test if the first character was a sign. The thousand separator may
% only be printed if the first character is no sign.
%    \begin{macrocode}
    \def\nprt@tmp{#1}%
    \ifx\nprt@tmp\nprt@plus@test
    \else
      \ifx\nprt@tmp\nprt@minus@test
      \else
        \nprt@thousand
      \fi
    \fi
    \nprt@three#2\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% Define routines to test if a character is included in a string. If
% yes the command \verb|\nprt@tmp| returns a nonempty string. If the
% string does not contain the character \verb|\nprt@tmp| returns
% nothing. To achieve this functionality the commands have to be
% called in a special way. For example to test for a comma in a command
% \verb|\str| you have to write
% \verb|\nprt@commatest\str,\@empty|. So you always have to
% append the character you are searching for (e.g. \verb|,|) and
% \verb|\@empty| to your search string.
%    \begin{macrocode}
\def\nprt@exptest#1e#2\@empty{\gdef\nprt@tmp{#2}}
\def\nprt@Exptest#1E#2\@empty{\gdef\nprt@tmp{#2}}
\def\nprt@commatest#1,#2\@empty{\gdef\nprt@tmp{#2}}
\def\nprt@dottest#1.#2\@empty{\gdef\nprt@tmp{#2}}
%    \end{macrocode}
% \begin{macro}{\nprt@exp}
% Print number in the exponential format with an argument containing a 
% small ``e''. Call: \verb|\nprt@exp| number\verb|\@empty|,
% e.g. \verb|\nprt@exp 123.2e4,3\@empty|. Both numbers containing a comma or 
% a dot work.
%    \begin{macrocode}
\def\nprt@exp#1e#2\@empty{\expnumprint{#1}{#2}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@Exp}
% Print number in the exponential format with an argument containing a 
% capital ``E''. Call: \verb|\nprt@Exp| number\verb|\@empty|,
% e.g. \verb|\nprt@Exp 123.2E4,3\@empty|. Both numbers containing a comma or 
% a dot work.
%    \begin{macrocode}
\def\nprt@Exp#1E#2\@empty{\expnumprint{#1}{#2}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@comma}
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before
%   and after decimalsign}%
% Print a number without exponential part containing a comma. Call:
% \verb|\nprt@comma| number\verb|\@empty|, e.g. 
% \verb|\nprt@comma 123,2\@empty|.
%    \begin{macrocode}
\def\nprt@comma#1,#2\@empty{%
  \nprt@dotcomma{#1}{#2}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@dot}
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before
%   and after decimalsign}%
% Print a number without exponential part containing a comma. Call:
% \verb|\nprt@dot| number\verb|\@empty|, e.g.
% \verb|\nprt@dot 123.2\@empty|.
%    \begin{macrocode}
\def\nprt@dot#1.#2\@empty{%
  \nprt@dotcomma{#1}{#2}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@dotcomma}
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before
%   and after decimalsign}%
% Print a number without exponential part containing a dot or a comma. Call:
% \verb|\nprt@dotcomma{before}{after}|, e.g.
% \verb|\nprt@dot{123}{2}|.
%    \begin{macrocode}
\def\nprt@dotcomma#1#2{%
  \expandafter\nprt@count\expandafter{#2}%
  \setcounter{nprt@digitsafterdecimal}{\thenprt@digitsbeforedecimal}%
  \expandafter\nprt@count\expandafter{#1}%
  \ifnum\the\c@nprt@digitsbeforedecimal=0
    \@addmissingzero
  \else
    \beforecomma{#1}%
  \fi
  \nprt@decimal
  \ifnum\the\c@nprt@digitsafterdecimal>0
    \aftercomma{#2}%
  \else
    \@addmissingzero
  \fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\expnumprint}
% Print number in the exponential format. This function is called by
% \verb|\nprt@exp| and \verb|\nprt@Exp|. It just calls
% \verb|\numprint| for the number itself, prints $\cdot 10$, and
% calls \verb|\numprint| for the exponent. It is distinguished between 
% text and math mode to ensure the usage of the right fonts.
% \changes{0.04}{2001/03/06}{Added support for pure $10^x$ format}%
%    \begin{macrocode}
\newcommand{\expnumprint}[2]{%
  \def\nprt@tmp{#1}%
  \ifx\nprt@tmp\@empty
    \nprt@exponenttrue
    \ifmmode
      10^{\numprint{#2}}%
    \else
      10\textsuperscript{\numprint{#2}}%
    \fi
  \else
    \ifmmode
      \numprint{#1}%
      \nprt@exponenttrue
      \nprt@prod 10^{\numprint{#2}}%
    \else
      \numprint{#1}%
      \nprt@exponenttrue
      \nprt@prod 10\textsuperscript{\numprint{#2}}%
    \fi
  \fi
  \nprt@exponentfalse
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\numprint}
% This is the main command of this package. It gets a number in the
% argument and prints it.
%    \begin{macrocode}
\newcommand{\numprint}[2][\@empty]{%
%    \end{macrocode}
% Call \verb|\nprt@Exptest| to test the argument for an ``E''.
%    \begin{macrocode}
  \expandafter\nprt@Exptest#2E\@empty
%    \end{macrocode}
% If the argument contains no ``E'' proceed here.
%    \begin{macrocode}
  \ifx\nprt@tmp\empty
%    \end{macrocode}
% Call \verb|\nprt@exptest| to test the argument for an ``e''.
%    \begin{macrocode}
    \expandafter\nprt@exptest#2e\@empty
%    \end{macrocode}
% If the argument contains no ``e'' the argument contains a simple
% number. Then proceed here.
%    \begin{macrocode}
    \ifx\nprt@tmp\empty
%    \end{macrocode}
% Call \verb|\nprt@commatest| to test the argument for a ``,''.
%    \begin{macrocode}
      \expandafter\nprt@commatest#2,\@empty
%    \end{macrocode}
% If the argument contains no ``,'' proceed here.
%    \begin{macrocode}
      \ifx\nprt@tmp\empty
%    \end{macrocode}
% Call \verb|\nprt@commatest| to test the argument for a ``.''.
%    \begin{macrocode}
        \expandafter\nprt@dottest#2.\@empty
%    \end{macrocode}
% If the argument contains no ``.'' the number has no decimal
% places. Then proceed here.
%    \begin{macrocode}
        \ifx\nprt@tmp\empty
%    \end{macrocode}
% Print only the integer part.
%    \begin{macrocode}
          \expandafter\nprt@count\expandafter{#2}%
          \beforecomma{#2}%
%    \end{macrocode}
% If the argument contains a ``.'' proceed here.
% Call \verb|\nprt@dot| to print the whole number.
%    \begin{macrocode}
        \else
          \expandafter\nprt@dot#2\@empty
        \fi
%    \end{macrocode}
% If the argument contains a ``,'' proceed here.
% Call \verb|\nprt@comma| to print the whole number.
%    \begin{macrocode}
      \else
        \expandafter\nprt@comma#2\@empty
      \fi
%    \end{macrocode}
% If the argument contains a ``e'' proceed here.
% Call \verb|\nprt@exp| to print the whole number.
%    \begin{macrocode}
    \else
      \expandafter\nprt@exp#2\@empty
    \fi
%    \end{macrocode}
% If the argument contains a ``E'' proceed here.
% Call \verb|\nprt@Exp| to print the whole number.
%    \begin{macrocode}
  \else
    \expandafter\nprt@Exp#2\@empty
  \fi
%    \end{macrocode}
% \changes{0.02}{2000/08/30}{Added optional argument for units}%
% \changes{0.03}{2001/02/10}{Fixed bug with units}%
% Handle optional argument and print the unit only when specified.
%    \begin{macrocode}
  \edef\nprt@unit{#1}%
  \ifx\nprt@unit\@empty
  \else
    \ensuremath{\nprt@unitsep\mathrm{\nprt@unit}}%
  \fi
}
%    \end{macrocode}
% \end{macro}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% Counters for counting digits: \verb|nprt@countblocks| counts number
% of blocks before the decimal sign. \verb|nprt@digitsfirstblock|
% counts the digits in the first block (0 to
% 2). \verb|nprt@digitsbeforedecimal| counts the total number of
% digits before the decimal sign.
%    \begin{macrocode}
\newcounter{nprt@countblocksbefore}%
\newcounter{nprt@digitsfirstblock}%
\newcounter{nprt@digitsbeforedecimal}%
\newcounter{nprt@digitsafterdecimal}%
%    \end{macrocode}
% \begin{macro}{\nprt@count}
% Count the number of digits of the argument. This is done recursively 
% by taking one character of the string and counting the runs of this
% command. Every three digits the counter is resetted to zero because
% only the modulus (Rest??) of the number of digits devided by 3 is
% important.
%
% If the optional parameter contains anything other than
% \verb|\@empty| the number of digits after the comma is counted.
%    \begin{macrocode}
\newcommand{\nprt@count}[1]{%
  \setcounter{nprt@digitsbeforedecimal}{0}%
  \def\nprt@arg{#1}%
%    \end{macrocode}
% Handle an empty argument.
%    \begin{macrocode}
  \ifx\nprt@arg\empty
  \else
%    \end{macrocode}
% Count the digits.
%    \begin{macrocode}
    \nprt@@count#1\@empty\@empty
  \fi
%    \end{macrocode}
%    \begin{macrocode}
  \setcounter{nprt@countblocksbefore}{\arabic{nprt@digitsbeforedecimal}/3}%
  \setcounter{nprt@digitsfirstblock}{%
    \arabic{nprt@digitsbeforedecimal}-3*\arabic{nprt@countblocksbefore}}%
%  \typeout{#1: \thenprt@digitsbeforedecimal\space before comma, 
%    \thenprt@countblocks\space total thousand blocks,
%    \thenprt@digitsfirstblock\space digits in first not total block^^J}%
}
%    \end{macrocode}
% Do the counting itself.
%    \begin{macrocode}
\def\nprt@@count#1#2\@empty{%
  \def\nprt@tmp{#2}%
  \ifx\nprt@tmp\empty
  \else
    \nprt@@count#2\@empty\@empty
  \fi
  \addtocounter{nprt@digitsbeforedecimal}{1}%
}
%    \end{macrocode}
% \end{macro}
% Print the digits before the decimal sign. Depending on the number of 
% digits either \verb|\nprt@one|, \verb|\nprt@two|, or
% \verb|\nprt@three| is called.
%    \begin{macrocode}
\newlength{\nprt@digitwidth}%
\newlength{\nprt@sepwidth}%
\newcounter{nprt@digitcount}%
\newcounter{nprt@sepcount}%
\newlength{\nprt@blockwidth}%
%    \end{macrocode}
% \begin{macro}{beforecomma}
% Prints the number before the decimal sign.
%    \begin{macrocode}
\newcommand{\beforecomma}[1]{%
%    \end{macrocode}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% If the number should be printed aligned generate a block with the
% correct size.
%    \begin{macrocode}
  \ifnprt@block
    \ifnprt@exponent
    \else
      \settowidth{\nprt@digitwidth}{1}%
      \settowidth{\nprt@sepwidth}{\nprt@thousand}%
      \setcounter{nprt@digitcount}{\nprt@blockbefore}%
      \setcounter{nprt@sepcount}{(\nprt@blockbefore-1)/3}%
      \setlength{\nprt@blockwidth}{%
        \arabic{nprt@digitcount}\nprt@digitwidth+%
        \arabic{nprt@sepcount}\nprt@sepwidth}%
%    \end{macrocode}
% If block length is four digits and fourth digit is not to be
% separated adjust new width.
%    \begin{macrocode}
      \if@numsepfour
      \else
        \ifnum\nprt@blockbefore=4
          \ifnum\nprt@blockafter<5
            \setlength{\nprt@blockwidth}{4\nprt@digitwidth}%
          \fi
        \fi
      \fi
%    \end{macrocode}
% If math mode switch to math mode again after invoking box.
%    \begin{macrocode}
      \ifmmode\nprt@inmathtrue\fi
      \makebox[\nprt@blockwidth][r]{%
      \ifnprt@inmath$\fi
    \fi
  \fi
  \ifnprt@blockexp
    \ifnprt@exponent
      \settowidth{\nprt@digitwidth}{1}%
      \settowidth{\nprt@sepwidth}{\nprt@thousand}%
      \setcounter{nprt@digitcount}{\nprt@blockexpbefore}%
      \setcounter{nprt@sepcount}{(\nprt@blockexpbefore-1)/3}%
      \setlength{\nprt@blockwidth}{%
        \arabic{nprt@digitcount}\nprt@digitwidth+%
        \arabic{nprt@sepcount}\nprt@sepwidth}%
%    \end{macrocode}
% If block length is four digits and fourth digit is not to be
% separated adjust new width.
%    \begin{macrocode}
      \if@numsepfour
      \else
        \ifnum\nprt@blockexpbefore=4
          \setlength{\nprt@blockwidth}{4\nprt@digitwidth}%
        \fi
      \fi
      \ifmmode\nprt@inmathtrue\fi
      \makebox[\nprt@blockwidth][r]{%
%    \end{macrocode}
% asdf
% To do: correct font size (normalstyle, scriptstyle, scriptscriptstyle)
%    \begin{macrocode}
      \ifnprt@inmath$\scriptstyle\fi
    \fi
  \fi
%    \end{macrocode}
% Print the number itself.
%    \begin{macrocode}
  \ifnum\thenprt@digitsfirstblock=1
    \ifnum\thenprt@digitsbeforedecimal=4
      \if@numsepfour
        \nprt@one#1\@empty\@empty\@empty
      \else
        \ifnum\thenprt@digitsafterdecimal<5
          #1\ignorespaces
        \else
          \nprt@one#1\@empty\@empty\@empty
        \fi
      \fi
    \else
      \nprt@one#1\@empty\@empty\@empty
    \fi
  \fi
  \ifnum\thenprt@digitsfirstblock=2
    \nprt@two#1\@empty\@empty\@empty
  \fi
  \ifnum\thenprt@digitsfirstblock=0
    \nprt@three#1\@empty\@empty\@empty\@empty
  \fi
%    \end{macrocode}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% Close the block if necessary.
%    \begin{macrocode}
  \ifnprt@blockexp
    \ifnprt@exponent
      \ifnprt@inmath$\fi
      }%
    \fi
  \fi
  \ifnprt@block
    \ifnprt@exponent
    \else
      \ifnprt@inmath$\fi
      }%
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{aftercomma}
% Print the digits after the decimal sign.
%    \begin{macrocode}
\newcommand{\aftercomma}[1]{%
%    \end{macrocode}
% Count number of digits.
%    \begin{macrocode}
%  \expandafter\nprt@count\expandafter{#1}%
%    \end{macrocode}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% If the number should be printed aligned generate a block with the
% correct size.
%    \begin{macrocode}
  \ifnprt@block
    \ifnprt@exponent
    \else
      \settowidth{\nprt@digitwidth}{1}%
      \settowidth{\nprt@sepwidth}{\nprt@thousand}%
      \setcounter{nprt@digitcount}{\nprt@blockafter}%
      \setcounter{nprt@sepcount}{(\nprt@blockafter-1)/3}%
      \setlength{\nprt@blockwidth}{%
        \arabic{nprt@digitcount}\nprt@digitwidth+%
        \arabic{nprt@sepcount}\nprt@sepwidth}%
%    \end{macrocode}
% If block length is four digits and fourth digit is not to be
% separated adjust new width.
%    \begin{macrocode}
      \if@numsepfour
      \else
        \ifnum\nprt@blockafter=4
          \ifnum\nprt@blockbefore<5
            \setlength{\nprt@blockwidth}{4\nprt@digitwidth}%
          \fi
        \fi
      \fi
      \ifmmode\nprt@inmathtrue\fi
      \makebox[\nprt@blockwidth][l]{%
      \ifnprt@inmath$\fi
    \fi
  \fi
%    \end{macrocode}
% Print the number itself.
%    \begin{macrocode}
    \ifnum\thenprt@digitsafterdecimal=4
      \if@numsepfour
        \nprt@threeafter#1\@empty\@empty\@empty
      \else
        \ifnum\thenprt@digitsbeforedecimal<5
          #1\ignorespaces
        \else
          \nprt@threeafter#1\@empty\@empty\@empty
        \fi
      \fi
    \else
      \nprt@threeafter#1\@empty\@empty\@empty
    \fi
%    \end{macrocode}
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}%
% Close the block if necessary.
%    \begin{macrocode}
  \ifnprt@block
    \ifnprt@exponent
    \else
      \ifnprt@inmath$\fi
      }%
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
% Define two new column types.
%
% The column type \verb|n| aligns the base number but not the exponent.
%    \begin{macrocode}
\newcolumntype{n}[2]{>{\digits{#1}{#2}$}l<{$\nodigits}}
%    \end{macrocode}
% Define two new column types.
%
% The column type \verb|n| aligns the base number as well as the exponent.
%    \begin{macrocode}
\newcolumntype{N}[3]{%
  >{\digits{#1}{#2}\exponentdigits{#3}$}l<{$\nodigits\noexponentdigits}}
%    \end{macrocode}
% \iffalse
%</package>
% \fi
% \Finale

