% \iffalse meta comment
% File: numprint032.dtx Copyright (C) 2000--2004 Harald Harders
% \fi
%
% \iffalse
%
%<*package>
\def\packagename{numprint}
\def\nprtfileversion{0.32}
\def\nprtfiledate{2003/09/18}
\def\nprtdocdate{2003/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 
    \nprtfileversion\ last revised \nprtfiledate, documentation dated
    \nprtdocdate.}}
\author{Harald Harders\\\texttt{harald.harders@gmx.de}}
\date{File Date \nprtfiledate, Printed \today}
\npdecimalsign{.}%
\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,\if,\else,\fi,\empty,\@empty,\ifx,\fi}
\DoNotIndex{\ifnum,\fi,\expandafter}
\CodelineNumbered
\RecordChanges
%\CheckSum{1016}
\begin{document}
 \DocInput{numprint.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{0.01}{2000/08/30}{Changed to dtx format}
% \changes{0.08}{2001/01/08}{Preceed ``np'' to some commands due to
% incompatibility with babel french}
%
% \maketitle
% \begin{abstract}
% \noindent This package prints numbers with a separator every three
% digits and it convert numbers given as |12345.6e789| to
% $12\,345{,}6\cdot 10^{789}$.
% The decimal sign, the thousand separator, as well as the product
% sign can be changed by the user, e.g. to reach
% $12{,}345.6\times 10^{789}$.
% If an optional argument is given it is printed upright as unit.
% \changes{0.21}{2003/02/25}{Abstract changed}
% \end{abstract}
%
% \tableofcontents
%
% \section*{Copyright}
% Copyright 2000--2004 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:
% ``|+-\pm0123456789.,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}$.
% |\pm| produces a $\pm$.
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}%
% From version 0.30 on, \cs{numprint} is stricter with the argument.
% It tests wheather the argument contains of supported characters
% only.
%
% 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 |\npunitseparator|.
%
% \DescribeMacro{\npthousandsep}%
% \DescribeMacro{\npthousandthpartsep}%
% \DescribeMacro{\npdecimalsign}%
% \DescribeMacro{\npproductsign}%
% By using the three commands \verb|\npthousandsep{#1}|,
% \verb|\npdecimalsign{#1}|, and
% \verb|\npproductsign{#1}|\footnote{These command did not have the
% ``np'' in older versions. This had to be changed in order to avoid
% an incompatibiliby with the french language of babel.} several
% separators can be changed. E.g.
% \begin{verbatim}
%\npdecimalsign{\ensuremath{\cdot}}\npthousandsep{,}\npproductsign{\times}%
%\numprint{-123456}; \numprint{3,1415927e-3.1}
% \end{verbatim}
% leads to ``{\npdecimalsign{\ensuremath{\cdot}}%
% \npthousandsep{,}\npproductsign{\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 inside a group. For example:
% \begin{verbatim}
%Local:
%\numprint{123e4},
%{\npproductsign{\times}\numprint{123e4}},
%\numprint{123e4}.
%Global:
%\numprint{123e4},
%{\global\npproductsign{\times}\numprint{123e4}},
%\numprint{123e4}
% \end{verbatim}
% leads to the following:
%
% \noindent Local:
% \numprint{123e4},
% {\npproductsign{\times}\numprint{123e4}},
% \numprint{123e4}.
% Global:
% \numprint{123e4},
% {\global\npproductsign{\times}\numprint{123e4}},
% \numprint{123e4}
% \npproductsign{\cdot}
%
% The current version has the following defaults:
% \begin{verbatim}
%\npthousandsep{\,}
%\npthousandthpartsep{\,}
%\npdecimalsign{,}
%\npproductsign{{}\cdot{}}
%\npunitseparator{\,}
% \end{verbatim}
% These will surely change in a new version when I add automatic
% international support. Then the defaults will by language dependent.
%
% \changes{0.31}{2003/09/16}{Describe automatic language-dependent
%   switch of decimal sign}%
% If you are using the |babel| package you may reach an automatic
% change of the parameters by using the \cs{addto} command of |babel|,
% e.g.:
% \begin{verbatim}
%\addto\extrasenglish{%
%  \npthousandsep{,}%
%  \npthousandthpartsep{,}%
%  \npdecimalsign{.}%
%  \npproductsign{{}\times{}}%
%}
%\addto\extrasngerman{%
%  \npthousandsep{\,}%
%  \npthousandthpartsep{\,}%
%  \npdecimalsign{,}%
%  \npproductsign{{}\cdot{}}%
%}
% \end{verbatim}
%
% \subsection{Change the behaviour}
% \subsubsection{Eliminate separators for four-digit numbers}
%
% \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|.
%
% If a number has four digits before the decimal sign, but more than
% four digits after it, or vice versa, the fourth digit is seperated
% \emph{before and after} the digital sign for consistency. 
% An example:
% \begin{verbatim}
%\fourdigitnosep$\numprint{1234.1234}$, $\numprint{1234.12345}$,
%$\numprint{12345.1234}$
% \end{verbatim}
% Leads to
% ``\fourdigitnosep$\numprint{1234.1234}$, $\numprint{1234.12345}$,
% $\numprint{12345.1234}$''.
%
% \subsubsection{Add missing zeros before or after decimal sign}
%
% \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|.
%
%
% \subsubsection[Rounding numbers]{Rounding numbers\footnote{This was
% an idea of Tilman Finke, tfinke@it-and-law.de}}%
% \changes{0.30}{2003/05/19}{Add rounding of numbers}%
%
% \DescribeMacro{\nprounddigits}%
% \DescribeMacro{\nproundexpdigits}%
% \DescribeMacro{\npnoround}%
% \DescribeMacro{\npnoroundexp}%
% By default, as many digits are printed after the decimal sign, as
% the \cs{numprint} command gets as argument.
% This behaviour can be changed to print a given number of digits
% where the number is rounded resp.\ filled with zeros.
% 
% This can be switched of using the
% \cs{nprounddigits\{\meta{\normalfont digits}\}} command for ordinary
% numbers and the \cs{nproundexpdigits\{\meta{\normalfont digits}\}}
% command for exponents.
% Rounding is switched off with \cs{npnoround} resp.\
% \cs{npnoroundexp}.
% For example,
% \begin{verbatim}
%\nprounddigits{2}$\numprint{1.123}$, $\numprint{1.149}$,
%$\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$ --
%\npnoround$\numprint{1.123}$, $\numprint{1.149}$,
%$\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$
% \end{verbatim}
% leads to
% ``\nprounddigits{2}$\numprint{1.123}$, $\numprint{1.149}$,
% $\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$ --
% \npnoround$\numprint{1.123}$, $\numprint{1.149}$,
% $\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$''
%
% \DescribeMacro{\npreplacenull}%
% \DescribeMacro{\npprintnull}%
% For amounts of money, sometimes a zero after the decimal sign is
% replaced by different signs, as for example ``---''. 
% If rounding is switched on, this can be done by calling
% \cs{npreplacenull\{\meta{\normalfont replacement}\}}, e.g.
% \begin{verbatim}
%\npreplacenull{\mbox{---}}
% \end{verbatim}
% Here, \cs{mbox} guarantees that ``---'' is printed in text mode.
% It can be switched off using \cs{npprintnull}.
%
%
% \subsection{Print aligned numbers in tabulars}%
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular
%   entries}%
%
% 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: \npdecimalsign{,}\npthousandsep{\,}\npproductsign{\cdot}%
% \numprint{3,1415927e-3.1}
%
% American: \npdecimalsign{.}\npthousandsep{,}\npproductsign{\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{numprint032}[\nprtfiledate\space v\nprtfileversion\space
  Print numbers]
\message{Package `numprint032', Version \nprtfileversion\space of \nprtfiledate.}
\message{Compatiblity version of numprint for versions prior 1.00}
%    \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}{\npdecimalsign}
% 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{\npdecimalsign}[1]{\def\nprt@decimal{{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npthousandsep}
% 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|\npthousandthpartsep| after \verb|\npthousandsep|.
%    \begin{macrocode}
\newcommand{\npthousandsep}[1]{\def\nprt@thousand{{#1}}%
  \def\nprt@thousandthpart{{#1}}}
%    \end{macrocode}
% \end{macro}%
% \begin{macro}{\npthousandthpartsep}
%    \begin{macrocode}
\newcommand{\npthousandthpartsep}[1]{\def\nprt@thousandthpart{{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npproductsign}
% 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{\npproductsign}[1]{\def\nprt@prod{\ensuremath{{}#1{}}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npunitseparator}
% 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{\npunitseparator}[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}
\npthousandsep{\,}%
\npthousandthpartsep{\,}%
\npdecimalsign{,}%
\npproductsign{{}\cdot{}}%
\npunitseparator{\,}%
%    \end{macrocode}
% \changes{0.30}{2003/05/19}{Add rounding of numbers}%
% \begin{macro}{\@fillnull}
% Defines command |#1| with a number of |#2| zeros filled.
%    \begin{macrocode}
\def\@fillnull#1#2{%
  \@tempcnta=0
  \loop
    \g@addto@macro{#1}{0}%
    \advance\@tempcnta by 1
  \ifnum\@tempcnta<#2
  \repeat
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprounddigits}
% Define a command that sets a count of digits after which the number
% is rounded.
% This command defines \cs{nprt@rounddigits} that stores the count and
% \cs{nprt@roundnull} that contains of \cs{nprt@rounddigits} ``0''
% digits.
%    \begin{macrocode}
\newcommand\nprounddigits[1]{%
  \def\nprt@rounddigits{#1}%
  \def\nprt@roundnull{}%
  \@fillnull{\nprt@roundnull}{#1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npnoround}
% A command to switch off rounding.
%    \begin{macrocode}
\newcommand\npnoround{\nprounddigits{-1}}
%    \end{macrocode}
% \end{macro}
% Don't round by default.
%    \begin{macrocode}
\npnoround
%    \end{macrocode}
% \begin{macro}{\nproundexpdigits}
% \begin{macro}{\npnoroundexp}
% The same for exponents.
%    \begin{macrocode}
\newcommand\nproundexpdigits[1]{%
  \def\nprt@roundexpdigits{#1}%
  \def\nprt@roundexpnull{}%
  \@fillnull{\nprt@roundexpnull}{#1}%
  }
\newcommand\npnoroundexp{\nproundexpdigits{-1}}
\npnoroundexp
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \changes{0.30}{2003/05/19}{Optionally replace zero after decimal sign}%
% \begin{macro}{\npreplacenull}
% Optionally, one or more zeros after the decimal sign can be replaced
% by other text, e.g.\ ``---'''.
%    \begin{macrocode}
\newcommand\npreplacenull[1]{\def\nprt@replacenull{#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npprintnull}
% Switch off replacement, again.
%    \begin{macrocode}
\newcommand\npprintnull{\let\nprt@replacenull=\@empty}
%    \end{macrocode}
% \end{macro}
% Print the zero by default.
%    \begin{macrocode}
\npprintnull
%    \end{macrocode}
% Define the signs as commands. This is necessary to be able to
% compare them with other characters. 
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}%
%    \begin{macrocode}
\def\nprt@plus@test{+}
\def\nprt@minus@test{-}
\def\nprt@plusminus@test{\pm}
%    \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{-}''.
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}%
%    \begin{macrocode}
\def\nprt@plus{\ensuremath{+}}
\def\nprt@minus{\ensuremath{-}}
\def\nprt@plusminus{\ensuremath{\pm}}
%    \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
      \ifx\nprt@tmp\nprt@plusminus@test
        \nprt@plusminus
      \else
        #1%
      \fi
    \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.
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}%
%    \begin{macrocode}
    \def\nprt@tmp{#1}%
    \ifx\nprt@tmp\nprt@plus@test
    \else
      \ifx\nprt@tmp\nprt@minus@test
      \else
        \ifx\nprt@tmp\nprt@plusminus@test
        \else
          \nprt@thousand
        \fi
      \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}%
% \changes{0.30}{2003/05/19}{Add support for rounding}%
% 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{%
  \begingroup
%    \end{macrocode}
% If \cs{nprt@dotcomma} is called for printing an exponent, copy the
% routines for exponents to the ordinary ones. This has to be done
% between \cs{begingroup} and \cs{endgroup} to preserve the normal
% settings.
%    \begin{macrocode}
  \ifnprt@exponent
    \edef\nprt@rounddigits{\nprt@roundexpdigits}%
    \edef\nprt@roundnull{\nprt@roundexpnull}%
  \fi
  \ifnum\nprt@rounddigits<0
%    \end{macrocode}
% If no rounding is done, just use the given arguments for printing.
%    \begin{macrocode}
    \def\nprt@charsbeforecomma{#1}%
    \def\nprt@charsaftercomma{#2}%
  \else
%    \end{macrocode}
% If rounding, do it.
% First, provide empty strings for the parts before and after the
% digit sign.
%    \begin{macrocode}
    \def\nprt@charsbeforecomma{}%
    \def\nprt@charsaftercomma{}%
%    \end{macrocode}
% Append enough zeros after the decimal sign that all digits are
% surely printed.
%    \begin{macrocode}
    \edef\zwei{#2\nprt@roundnull}%
%    \end{macrocode}
% Call the command \cs{nprt@roundaftercomma} that does the rounding
% for the part after the decimal sign.
%    \begin{macrocode}
    \expandafter\nprt@roundaftercomma\zwei\empty
%    \end{macrocode}
% If the first digit after the comma is rounded from 9 to 0, rounding
% has to be continued before the decimal sign by calling
% \cs{nprt@roundbeforecomma}.
%    \begin{macrocode}
    \if@@roundup
      \nprt@roundbeforecomma#1\empty
%    \end{macrocode}
% If the first digit has to be rounded from 9 to 0, a 1 has to be
% inserted before the number.
%    \begin{macrocode}
      \if@@roundup
        \expandafter\xdef\expandafter\nprt@charsbeforecomma{%
          1\nprt@charsbeforecomma}%
      \fi
    \else
      \def\nprt@charsbeforecomma{#1}%
    \fi
  \fi
%    \end{macrocode}
% Count the digits after the comma.
%    \begin{macrocode}
  \nprt@@hassignfalse
  \expandafter\nprt@count\nprt@charsaftercomma\@empty\@empty\@empty
%    \end{macrocode}
% Copy the result which is stored in |nprt@digitsbeforedecimal| to
% |nprt@digitsafterdecimal|.
%    \begin{macrocode}
  \setcounter{nprt@digitsafterdecimal}{\thenprt@digitsbeforedecimal}%
%    \end{macrocode}
% Count the digits before the comma.
%    \begin{macrocode}
  \expandafter\nprt@hassign\nprt@charsbeforecomma\@empty\@empty
  \expandafter\nprt@count\nprt@charsbeforecomma\@empty\@empty\@empty
%    \end{macrocode}
% Typeset the digits before the comma.
%    \begin{macrocode}
  \ifnum\the\c@nprt@digitsbeforedecimal=0
    \@addmissingzero
  \else
    \expandafter\beforecomma\nprt@charsbeforecomma\@empty\@empty
  \fi
%    \end{macrocode}
% Typeset the part after the decimal sign, if necessary.
%    \begin{macrocode}
  \ifnum\nprt@rounddigits=0
  \else
%    \end{macrocode}
% Typeset the decimal sign.
%    \begin{macrocode}
    \nprt@decimal
%    \end{macrocode}
% Typeset the digits after the comma.
%    \begin{macrocode}
    \ifnum\the\c@nprt@digitsafterdecimal>0
      \aftercomma{\nprt@charsaftercomma}%
    \else
      \ifx\nprt@replacenull\@empty
        \@addmissingzero
      \else
        \nprt@replacenull
      \fi
    \fi
  \fi
  \endgroup
}
%    \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}
% Define a macro that includes |\@empty|. This seems to be necesarry since
% the optional argument of |\numprint| is not expanded before printing it.
% \changes{0.22}{2003/02/27}{Bugfix with invalid spacing after the number}%
%    \begin{macrocode}
\def\nprt@empty{\@empty}%
%    \end{macrocode}
% \begin{macro}{\numprint}
% This is the main command of this package. It gets a number in the
% argument and prints it.
%    \begin{macrocode}
\DeclareRobustCommand*\numprint[2][\@empty]{%
%    \end{macrocode}
% \changes{0.32}{2003/09/28}{Reset the number of digits before and
%   after the decimal sign (Bugfix for nosepfour)}%
% Reset the number of digits before and after the decimal sign. 
% Without doing it, \texttt{nosepfour} is broken by one number with
% more than 4 digits.
%    \begin{macrocode}
  \setcounter{nprt@digitsafterdecimal}{0}%
  \setcounter{nprt@digitsbeforedecimal}{0}%
%    \end{macrocode}
% \changes{0.31}{2003/09/16}{Expand the mandatory argument of the
%   \cs{numprint} command before parsing it}%
% Expand argument first.
%    \begin{macrocode}
  \edef\nprt@marg{#2}%
%    \end{macrocode}
% Call \verb|\nprt@Exptest| to test the argument for an ``E''.
%    \begin{macrocode}
  \expandafter\nprt@Exptest\nprt@marg E\@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\nprt@marg e\@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\nprt@marg,\@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\nprt@marg.\@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}
% Count the digits of the integer number.
%    \begin{macrocode}
          \expandafter\nprt@hassign\nprt@marg\@empty
          \expandafter\nprt@count\nprt@marg\@empty\@empty\@empty
%    \end{macrocode}
% Print the number.
%    \begin{macrocode}
          \begingroup
%    \end{macrocode}
% If \cs{nprt@dotcomma} is called for printing an exponent, copy the
% routines for exponents to the ordinary ones. This has to be done
% between \cs{begingroup} and \cs{endgroup} to preserve the normal
% settings.
%    \begin{macrocode}
          \ifnprt@exponent
            \def\nprt@rounddigits{\nprt@roundexpdigits}%
            \def\nprt@roundnull{\nprt@roundexpnull}%
          \fi
%    \end{macrocode}
% If rounding is switched on with at least on digit, the part
% after the decimal sign has to be printed.
% Set the number of digits, then.
%    \begin{macrocode}
          \ifnum\nprt@rounddigits>0
            \setcounter{nprt@digitsafterdecimal}{\nprt@rounddigits}%
          \fi
%    \end{macrocode}
% Print the integer part.
%    \begin{macrocode}
          \expandafter\beforecomma\nprt@marg\@empty\@empty
%    \end{macrocode}
% Print the part after the decimal sign.
%    \begin{macrocode}
          \ifnum\nprt@rounddigits>0
            \nprt@decimal
            \aftercomma{\nprt@roundnull}%
          \fi
          \endgroup
%    \end{macrocode}
% If the argument contains a ``.'' proceed here.
% Call \verb|\nprt@dot| to print the whole number.
%    \begin{macrocode}
        \else
          \expandafter\nprt@dot\nprt@marg\@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\nprt@marg\@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\nprt@marg\@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\nprt@marg\@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}%
% \changes{0.20}{2003/02/24}{Fixed bug which made units fragile}%
% \changes{0.22}{2003/02/27}{Bugfix with invalid spacing after the number}%
% Handle optional argument and print the unit only when specified.
%    \begin{macrocode}
  \def\nprt@unit{#1}%
  \ifx\nprt@unit\nprt@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@digitsafterdecimal}%
\newcounter{nprt@digitsbeforedecimal}%
%    \end{macrocode}
% \begin{macro}{nprt@hassign}
% Tests weather the first character of a string is not a digit.
%    \begin{macrocode}
\newif\ifnprt@@hassign
\def\nprt@hassign#1#2\@empty{%
  \ifnum-9>-1#1
    \nprt@@hassignfalse
  \else
    \nprt@@hassigntrue
  \fi
}
%    \end{macrocode}
% \end{macro}
% \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}
\def\nprt@count#1#2\@empty{%
  \setcounter{nprt@digitsbeforedecimal}{0}%
  \edef\nprt@arg{#1}%
%    \end{macrocode}
% Handle an empty argument.
%    \begin{macrocode}
  \ifx\nprt@arg\@empty
  \else
%    \end{macrocode}
% Count the digits.
%    \begin{macrocode}
    \ifnprt@@hassign
      \nprt@@count#2\@empty\@empty
    \else
      \nprt@@count#1#2\@empty\@empty
    \fi
  \fi
%    \end{macrocode}
%    \begin{macrocode}
  \setcounter{nprt@countblocksbefore}{\arabic{nprt@digitsbeforedecimal}/3}%
  \setcounter{nprt@digitsfirstblock}{%
    \arabic{nprt@digitsbeforedecimal}-3*\arabic{nprt@countblocksbefore}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@@count}
% \changes{0.32}{2003/09/28}{Only one error message per \cs{numprint}}%
% Do the counting itself.
%    \begin{macrocode}
\def\nprt@@count#1#2\@empty{%
  \ifnum-9>-1#1
    \addtocounter{nprt@digitsbeforedecimal}{1}%
    \def\nprt@tmp{#2}%
    \ifx\nprt@tmp\empty
    \else
      \nprt@@count#2\@empty\@empty
    \fi
  \else
    \PackageError{numprint}{Incorrect number format in
      \string\numprint}{%
      The main argument of the \string\numprint\space command may only
      be started\MessageBreak
      with \string"+\string", \string"-\string", or
      \string"\string\pm\string" and then contain of\MessageBreak
      digits \string"0\string" to \string"9\string",
      \string",\string", \string".\string", \string"e\string", and 
      \string"E\string".}%
%    \setcounter{nprt@digitsbeforedecimal}{-1}%
  \fi
%    \end{macrocode}
% Count number of characters
%    \begin{macrocode}
}
%    \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}
\def\beforecomma#1#2\@empty{%
%    \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 %$ (only for syntax highlighing in emacs)
    \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 %$ (only for syntax highlighing in emacs)
    \fi
  \fi
%    \end{macrocode}
% \changes{0.31}{2003/09/16}{Bug Fix: With four-digit numbers, print
%   everything instead of first digit only}%
% Print the number itself.
%    \begin{macrocode}
  \ifnprt@@hassign
    \nprt@printdigit{#1}%
    \edef\nprt@tmp{#2}%
  \else
    \edef\nprt@tmp{#1#2}%
  \fi
  \ifnum\thenprt@digitsfirstblock=1
    \ifnum\thenprt@digitsbeforedecimal=4
      \if@numsepfour
        \expandafter\nprt@one\nprt@tmp\@empty\@empty\@empty
      \else
        \ifnum\thenprt@digitsafterdecimal<5
          \nprt@tmp\ignorespaces
        \else
          \expandafter\nprt@one\nprt@tmp\@empty\@empty\@empty
        \fi
      \fi
    \else
      \expandafter\nprt@one\nprt@tmp\@empty\@empty\@empty
    \fi
  \fi
  \ifnum\thenprt@digitsfirstblock=2
    \expandafter\nprt@two\nprt@tmp\@empty\@empty\@empty
  \fi
  \ifnum\thenprt@digitsfirstblock=0
    \expandafter\nprt@three\nprt@tmp\@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 %$ (only for syntax highlighing in emacs)
      }%
    \fi
  \fi
  \ifnprt@block
    \ifnprt@exponent
    \else
      \ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs)
      }%
    \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 %$ (only for syntax highlighing in emacs)
    \fi
  \fi
%    \end{macrocode}
% If a zero after the decimal sign is replaced, don't test on 4 digits
% after comma.
% Therefor, set |nprt@digitsafterdecimalsign| to zero.
%    \begin{macrocode}
  \ifx\nprt@replacenull\@empty
  \else
    \ifnum#1=0
      \setcounter{nprt@digitsafterdecimal}{0}%
    \fi
  \fi
%    \end{macrocode}
% Print the number itself.
%    \begin{macrocode}
  \ifnum\thenprt@digitsafterdecimal=4
    \if@numsepfour
      \expandafter\nprt@threeafter#1\@empty\@empty\@empty
    \else
      \ifnum\thenprt@digitsbeforedecimal<5
        #1\ignorespaces
      \else
        \expandafter\nprt@threeafter#1\@empty\@empty\@empty
      \fi
    \fi
  \else
%    \end{macrocode}
% Replace the zero after the comma by \cs{nprt@replacenull} if this is
% wanted.
% Otherwise, print the digits.
%    \begin{macrocode}
    \ifx\nprt@replacenull\@empty
      \expandafter\nprt@threeafter#1\@empty\@empty\@empty
    \else
      \ifnum#1=0
        \nprt@replacenull
      \else
        \expandafter\nprt@threeafter#1\@empty\@empty\@empty
      \fi
    \fi
  \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 %$ (only for syntax highlighing in emacs)
      }%
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
% New counter which shows the digit position for finding the digit
% where to round.
%    \begin{macrocode}
\newcounter{nprt@position}
%    \end{macrocode}
% Boolean that shows if a 9 has been rounded to 0.
%    \begin{macrocode}
\newif\if@@roundup
%    \end{macrocode}
% Current digit to be able to add 1 to it.
%    \begin{macrocode}
\newcounter{nprt@thisdigit}
%    \end{macrocode}
% \begin{macro}{\nprt@roundaftercomma}
% Command that rounds at the argument |#1#2| at the digit
% \cs{nprt@rounddigits}.
% This routine calls itself recursively.
%    \begin{macrocode}
\def\nprt@roundaftercomma#1#2\empty{%
  \addtocounter{nprt@position}{1}%
  \edef\zwei{#2}%
  \ifx\zwei\empty
  \else
    \expandafter\ifnum\thenprt@position<\nprt@rounddigits
      \nprt@roundaftercomma#2\empty
    \else
      \nprt@roundup#2\empty
    \fi
  \fi
  \setcounter{nprt@thisdigit}{#1}%
  \if@@roundup
    \addtocounter{nprt@thisdigit}{1}%
    \ifnum\thenprt@thisdigit>9
      \@@rounduptrue
      \setcounter{nprt@thisdigit}{0}%
    \else
      \@@roundupfalse
    \fi
  \fi
  \expandafter\xdef\expandafter\nprt@charsaftercomma{%
    \thenprt@thisdigit\nprt@charsaftercomma}%
  \addtocounter{nprt@position}{-1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@roundup}
%    \begin{macrocode}
\def\nprt@roundup#1#2\empty{%
  \ifnum#1>4
    \@@rounduptrue
  \else
    \@@roundupfalse
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@roundbeforecomma}
%    \begin{macrocode}
\def\nprt@roundbeforecomma#1#2\empty{%
  \edef\zwei{#2}%
  \ifx\zwei\empty
  \else
    \nprt@roundbeforecomma#2\empty
  \fi
  \edef\eins{#1}%
%  \ifx\eins\nprt@minus@test
%    \expandafter\xdef\expandafter\nprt@charsbeforecomma{%
%      #1\nprt@charsbeforecomma}%
%  \else
%    \setcounter{nprt@thisdigit}{#1}%
%    \if@@roundup
%      \addtocounter{nprt@thisdigit}{1}%
%      \ifnum\thenprt@thisdigit>9
%        \@@rounduptrue
%        \setcounter{nprt@thisdigit}{0}%
%      \else
%        \@@roundupfalse
%      \fi
%    \fi
  \ifnum-9>-1#1
    \setcounter{nprt@thisdigit}{#1}%
    \if@@roundup
      \addtocounter{nprt@thisdigit}{1}%
      \ifnum\thenprt@thisdigit>9
        \@@rounduptrue
        \setcounter{nprt@thisdigit}{0}%
      \else
        \@@roundupfalse
      \fi
    \fi
    \expandafter\xdef\expandafter\nprt@charsbeforecomma{%
      \thenprt@thisdigit\nprt@charsbeforecomma}%
  \else
    \if@@roundup
      \expandafter\xdef\expandafter\nprt@charsbeforecomma{%
        1\nprt@charsbeforecomma}%
      \@@roundupfalse
    \fi
    \expandafter\xdef\expandafter\nprt@charsbeforecomma{%
      #1\nprt@charsbeforecomma}%
  \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

