% \iffalse meta comment
% File: numprint.dtx Copyright (C) 2000--2005, 2007, 2008, 2012 Harald Harders
% \fi
%
% \iffalse
%
%<*driver>
\listfiles
\documentclass[ngerman,english,a4paper]{ltxdoc}
\usepackage[T1]{fontenc}
\IfFileExists{numprint.sty}{%
  \usepackage[warning,debug,autolanguage,boldmath,np]{numprint}
}{%
  \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
}
\IfFileExists{eco.sty}{%
  \usepackage{eco}
  \renewcommand*\ttdefault{cmtt}
}{%
  \GenericWarning{numprint.dtx}{Package file eco.sty not found
    (Documentation will be less clear than possible)}
}
\usepackage{longtable}
\usepackage{mathcomp}
\usepackage{babel}
\usepackage{url}
\usepackage{color}
\IfFileExists{booktabs.sty}{\usepackage{booktabs}}{%
  \GenericWarning{numprint.dtx}{Package file booktabs.sty not
    found. Documentation formatting will be poor}%
  \def\toprule\hline
  \def\midrule\hline
  \def\bottomrule\hline}
\GlossaryPrologue{\section*{{Change History}}%
  \markboth{{Change History}}{{Change History}}%
  Since the version~1.00 is an entirely new implementation, the Change
  History prior version~1.00 has been lost in this document. Have a
  look to \texttt{numprint032.dtx} or \texttt{README} to get it.
}
\GetFileInfo{numprint.sty}
\title{The numprint package}
\author{Harald Harders\\\texttt{harald.harders@gmx.de}}
\date{Version \fileversion, \filedate; printed \today}
\npdecimalsign{.}%
\newlength{\tempdima}%
\makeatletter
\renewenvironment{table}[1][]{%
  \@float{table}[#1]%
  \centering%
  \setlength{\tempdima}{\abovecaptionskip}%
  \setlength{\abovecaptionskip}{\belowcaptionskip}%
  \setlength{\belowcaptionskip}{\tempdima}%
  }{%
\end@float
}
\def\meta@font@select{\normalfont\itshape}
\makeatother
%%
\EnableCrossrefs
\CodelineIndex
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter}
\DoNotIndex{\setcounter,\space,\if,\else,\fi,\empty,\@empty,\ifx,\fi}
\DoNotIndex{\ifnum,\fi,\expandafter,\csname,\endcsname,\the}
\DoNotIndex{\MessageBreak,\message,\newlength,\newif,\xdef,\newcount}
\DoNotIndex{\begingroup,\endgroup,\,,\@tempcnta,\@tempdima,\advance}
\DoNotIndex{\ensuremath,\filedate,\fileversion,\docdate}
\DoNotIndex{\mathit,\mathrm,\mathsf,\nprt@tmp,\nprt@tmpnum,\relax}
\DoNotIndex{\protect,\renewcommand,\setlength,\settowidth,\stepcounter}
\DoNotIndex{\string}
\CodelineNumbered
\RecordChanges
\CheckSum{2257}
\begin{document}
 \DocInput{numprint.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{1.38}{2008/02/17}{Replaced \cs{stepcounter} and
%   \cs{addtocounter} by \cs{advance} 
%   because otherwhise, \cs{numprint} does not work inside
%   \cs{ensuremath}\{\cs{text}\{\$\ldots\$\}\}.}%
% \changes{1.38}{2008/02/17}{Moved counters \cs{nprt@curpos} and
%   \cs{nprt@rndpos} outside the macro definitions to avoid an overflow
%   of counters}%
% \changes{1.37}{2007/01/08}{Add support for French}%
% \changes{1.37}{2007/01/08}{Add an own separator for \textcelsius}%
% \changes{1.37}{2007/01/08}{Use separator for percent also for permil}%
% \changes{1.36}{2005/07/12}{Add support for Dutch}%
% \changes{1.36}{2005/07/12}{Improve documentation}%
% \changes{1.35}{2005/07/11}{Support not to separate percent sign from
%   number}%
% \changes{1.30}{2004/08/11}{Add the commands \cs{lenprint} and
%   \cs{cntprint} that print lengths and counters.}%
% \changes{1.22}{2004/08/08}{Use \cs{npunitcommand} to typeset units}%
% \changes{1.21}{2004/08/01}{Add support for Portuguese}%
% \changes{1.20}{2004/07/27}{Remove the reduction in font sizes in
%   documentation}%
% \changes{1.20}{2004/07/27}{Allow \cs{numprint\{-e5\}} in addition to
%   \cs{numprint\{e5\}}}%
% \changes{1.20}{2004/07/27}{Add padding a number on the left side}%
% \changes{1.13}{2004/04/01}{Small fix in documentation}%
% \changes{1.12}{2004/02/12}{Adapt Makefile to \TeX Live}%
% \changes{1.11}{2003/11/09}{Avoid use of \cs{fileversion} etc.}%
% \changes{1.00}{2003/10/07}{Total new implementation}%
%
% \maketitle
% \begin{abstract}
% \noindent
% This package prints numbers with a separator every three digits and
% convert numbers given as |12345.6e789| to
% {\npstylegerman\numprint{12345,6e789}}.
% Numbers are printed in the current mode (text or math) in order to use
% the correct font.
% 
% Many things, including the decimal sign, the thousand separator, as
% well as the product sign can be changed by the user, e.g., to reach
% \numprint{12,345.6e789}.
% If requested, numprint can round numbers to a given number of digits.
% 
% If an optional argument is given it is printed upright as unit.
% Numbers can be rounded to a given number of digits.
% 
% The package supports an automatic, language-dependent change of the
% number format.
% 
% Tabular alignment using the |tabular|(|*|), |array|, |tabularx|, and
% |longtable| environments (similar to the |dcolumn| and |rccol| packages)
% is supported using all features of numprint. Additional text can be
% added before and after the formatted number.
%
% If you want to print numbers with different bases (octal,
% hexadecimal, etc.) use the |nbaseprt| package which comes with the
% |numprint| package.
% \end{abstract}
%
% \tableofcontents
%
% \section*{Copyright}
% Copyright 2000--2005, 2007, 2008, 2012 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*{Remarks}
%
% \begingroup
% \itshape
% \sloppypar
%  The \cs{fourdigitsep}, \cs{fourdigitnosep},
% \cs{addmissingzero}, \cs{noaddmissingzero}, \cs{digits},
% \marginpar{\raggedleft\bfseries\Huge !}%
% \cs{nodigits}, \cs{exponentsdigits}, and \cs{noexponentdigits}
% commands have been renamed to \cs{npfourdigitsep},
% \cs{npfourdigitnosep}, \cs{npaddmissingzero},
% \cs{npnoaddmissingzero}, \cs{npdigits}, \cs{npnodigits},
% \cs{npexponentsdigits}, resp.\ \cs{npnoexponentdigits}.
%
% From version 1.00 to 1.10, the column types have been changed; see
% section~\ref{sec:tabular}.
% \marginpar{\raggedleft\bfseries\Huge !}%
% If you want to preserve the old column types, use the package option
% |oldcolumntypes|.
% \endgroup
%
% For typesetting this documentation, the usage of different font
% shapes has been reduced as much as possible in order to save disk
% memory and download times.
% Thus, for nearly all characters, the design size 10\,pt has been
% used.
% This reduced the size of the PDF file for version 1.10 from 858\,KB
% to 396\,KB.
% Please excuse that shortcoming in the typography.
%
%
% \section{Load the package}
%
% To use this package place
% \begin{verbatim}
%\usepackage{numprint}\end{verbatim}
% in the preamble of your document.
% No options are necessary but some are available.
% They are mentioned where their usage is described and in
% section~\ref{sec:package-options}.
%
% \section{Print numbers in text and math mode}
%
% \DescribeMacro{\numprint}%
% This package provides the command
% \cs{numprint\oarg{unit}\marg{number}} that prints the \meta{number}
% given in the required argument.
% The number is printed in the current mode (math or text mode) 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.,eEdD|''.
% Spaces, ``\cs{,}'' as well as ``\texttt{\~}'' in the argument are
% ignored.
% Either a ``|,|'' or a ''|.|'' can be used as decimal sign.
% By default, no thousand separators are allowed in the
% argument.\footnote{Section~\ref{sec:custom-parsing} describes how
%   this can be changed.}
% ``|E|'', ``|e|'', ``|D|'', or ``|d|''\footnote{This is useful for
% FORTRAN produced numbers.} is converted to an exponential format
% (e.g., $x\cdot 10^{y}$ or $x\times 10^{y}$, depending on the
% format settings described later).
% ``|\pm|'' and ``|+-|'' produce a $\pm$.
%
% For example, typing
% \begin{verbatim}
%\numprint{-123456}; \numprint{\pm 123456}; \numprint{+-3,1415927e-3.1}\end{verbatim}
% leads to ``\numprint{-123456}; \numprint{\pm 123456};
% \numprint{+-3,1415927e-3.1}''.
% Notice that ``|.|'' and ``|,|'' can be mixed within one number and
% are converted to the chosen decimal sign for the output.
%
% The number is printed in the active mode (text mode resp.\ math
% mode).
% This may be important if the digits are different in text and math
% mode as in this document that uses old-style figures in text and
% lining figures in math mode.\footnote{This is only the case if the
%   \texttt{eco} package is available on your system.}
% See the difference between
% ``\numprint{123456.134e123}'' and ``$\numprint{123456.134e123}$'',
% produced by
% \begin{verbatim}
%``\numprint{123456.134e123}'' and ``$\numprint{123456.134e123}$''\end{verbatim}
%
% If no number is given before the exponential characters ``|e|'',
% ``|E|'', ``|d|'', resp.\ ``|D|'', a pure exponential format is
% generated.
% For example, typing
% \begin{verbatim}
%\numprint{e4.3242}\end{verbatim}
% leads to ``\numprint{e4.3242}''.
% This also works with given signs, e.g.,
% \begin{verbatim}
%\numprint{-e4.3242}, \numprint{+-e4.3242} \end{verbatim}
% leads to ``\numprint{-e4.3242}, \numprint{+-e4.3242}''.
%
% Since \cs{numprint} expands the argument before typesetting it you
% may also use commands inside the argument, e.g.,
% \begin{verbatim}
%\def\numberbefore{1234}%
%\def\totalnumber{\numberbefore.5678}%
%\numprint{\totalnumber}\end{verbatim}
% leads to
% ``{\def\numberbefore{1234}\def\totalnumber
% {\numberbefore.5678}\numprint{\totalnumber}}''.
%
% If the optional argument is given it is printed as a \meta{unit} in
% math mode with an upright font (\verb|\mathrm|), e.g.,
% \begin{verbatim}
%\numprint[N/mm^2]{-123456}\end{verbatim}
% leads to ``\numprint[N/mm^2]{-123456}''.
%
% \changes{1.00}{2003/10/07}{Automatically don't separate degree sign
%   from number}%
% By default, the space between the number and the unit is \cs{,}.
% One exception is the degree symbol which is typeset without a
% distance to the number, e.g., $\numprint[\tcdegree]{360}$ in
% contrast to $\numprint[\tccelsius]{273,15}$ (only a single degree
% symbol is typeset without a separator).
% The |numprint| package detects this automatically if the
% \cs{tcdegree} command of the |mathcomp| package, the \cs{textdegree}
% command of the |textcomp| package, or the \cs{degree} command of the
% |gensymb| package is used, e.g.,
% \begin{verbatim}
%\numprint[\tcdegree]{360}, \numprint[\degree]{360}\end{verbatim}
% Unfortunately, typing in the ``\texttt{\textdegree}'' sign directly
% cannot be detected (any help welcome).
%
% You can change the spacing between the number and units, percent
% signs, or degree symbols.
% Have a look to Section~\ref{sec:changing-output}.
%
%
% \changes{1.32}{2004/09/13}{Improve documentation about
%   \texttt{textcomp} symbols}%
% If you want to use one of the |textcomp| symbols \textcelsius\
% (\cs{textcelsius}), \textohm\ (\cs{textohm}), \textmu\
% (\cs{textmu}), or \textperthousand\ (\cs{textperthousand})\ you have
% to load either the |mathcomp| or the |gensymb| package because the
% unit is printed in math mode.
% If you decide to use the |textomp| package use \cs{tc\meta{name}}
% instead of \cs{text\meta{name}}, e.g., \cs{tccelsius} instead of
% \cs{textcelsius}.
% If using |gensymb| just use \cs{\meta{name}}, e.g.,
% \cs{celsius}.\footnote{If you still use \cs{text\meta{name}}
% numprint uses \cs{tc\meta{name}} or \cs{\meta{name}} and generates a
% warning if one of these commands is available, and produces an error
% if not.}
%
%
% \DescribeMacro{\np}
% Since it is timeconsuming to type in the long command \cs{numprint}
% for every number in a text the shortcut \cs{np} can be defined by
% specifying the package option~\texttt{np}.
%
% By default, numbers are written in the format
% \begingroup
% \npstyledefault
% \numprint{12345,12345e12345},
% \endgroup
% for instance.
% This means, decimal sign ``\texttt{,}'', thousand
% separator ``\cs{,}'', and product sign
% ``\texttt{\{\}\cs{cdot}\{\}}''.
% This accords to German number formats and is a result of the history
% of this package.
% How you can change this is described in the following sections.
% Especially, have a look at the |autolanguage| package option in
% section~\ref{sec:international}.
%
%
% \subsection{Print counters and lengths}
%
% If you want to print a counter or a length, you may of course use 
% \begin{verbatim}
%\numprint{\arabic{page}}\end{verbatim}
% resp.
% \begin{verbatim}
%\makeatletter
%\numprint[pt]{\strip@pt\textwidth}
%\makeatother\end{verbatim}
% But these methods are not really nice.
%
% \DescribeMacro{\cntprint}%
% For printing counters, you may use
% \cs{cntprint\oarg{unit}\marg{counter}} where \meta{unit} is an
% optional unit that is printed as by \cs{numprint}.
% \meta{counter} is the name of a \LaTeX\ counter, for example,
% \begin{verbatim}
%$\cntprint{page}$\end{verbatim}
% leads to ``$\cntprint{page}$''.
%
% \DescribeMacro{\lenprint}%
% Lengths can be printed using \cs{lenprint\oarg{unit}\marg{length}}.
% \meta{length} is the macro containing a \LaTeX\ length or a \TeX\
% dimension, e.g., \cs{textwidth}.
% \meta{unit} is a different thing here.
% If the unit is not given \cs{lenprint} uses \LaTeX's standard and
% prints the length in |pt|:
% \begin{verbatim}
%$\lenprint{\textwidth}$\end{verbatim}
% leads to ``$\lenprint{\textwidth}$''.
% Giving |pt| does not change anything.
% But if you use other units, e.g., |mm|, |cm|, or |in|, the length is
% written using the given unit:
% \begin{verbatim}
%$\lenprint[pt]{\textwidth}$,
%$\lenprint[in]{\textwidth}$,
%$\lenprint[bp]{\textwidth}$,
%$\lenprint[mm]{\textwidth}$,
%$\lenprint[cm]{3\textwidth}$\end{verbatim}
% gives ``$\lenprint[pt]{\textwidth}$,
% $\lenprint[in]{\textwidth}$,
% $\lenprint[bp]{\textwidth}$,
% $\lenprint[mm]{\textwidth}$,
% $\lenprint[cm]{3\textwidth}$''.
%
% As you can see in the example, it is also possible to specify a
% factor in the argument, e.g. |3\textwidth|.
% When printing lengths, it is often desirable not to print all
% decimal places.
% |numprint| can round numbers, described in section~\ref{sec:round}.
% 
% \cs{lenprint} knows the units |pt|, |bp|, |in|, |ft|, |mm|, |cm|,
% |m|, and |km|.
% Section~\ref{sec:more-units} describes how to add or change units.
% 
%
% \section{Customization}
%
% \subsection{Eliminate separators for four-digit numbers}
%
% At least in German it is common not to add a separator to four-digit
% numbers in non-technical texts, e.g., to typeset
% {\npfourdigitnosep``\numprint{1234}''} instead of ``\numprint{1234}'',
% but longer numbers are separated: ``\numprint{12345}''.
% If a number, in contrast, has less than five digits on one side of
% the decimal sign but five or more digits on the other side,
% separators are inserted on both sides, e.g.,
% {\npfourdigitnosep``\numprint{1234,1234}'' but
% ``\numprint{1234,12345}''}.
%
% \DescribeMacro{\npfourdigitsep}%
% \DescribeMacro{\npfourdigitnosep}%
% This behaviour can be achieved using the command
% \cs{npfourdigitnosep}.
% If using this switch inside a group the change is local.
% You can switch back to separating with \cs{npfourdigitsep}.
% An example:
% \begin{verbatim}
%\npfourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ --
%\npfourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$\end{verbatim}
% Leads to
% {``\npfourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ --
% \npfourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$''.}
% Default values can be set by the package options |sepfour| and
% |nosepfour|.
%
%
% \subsection{Add missing zeros before or after decimal sign}
%
% \DescribeMacro{\npaddmissingzero}%
% \DescribeMacro{\npnoaddmissingzero}%
% 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 \cs{addmissingzero} is
% used.
% If, however, no decimal sign is given, e.g., ``|123|'', no decimal
% sign or zero is appended.
% Adding zeros can be switched off with \cs{noaddmissingzero}.
% The corresponding package options are |addmissingzero| and
% |noaddmissinzero|.
% The default is |addmissingzero|.
%
%
% \subsection{Add a plus sign}%
% \changes{1.00}{2003/10/07}{Support for adding a plus to a number}%
%
% \DescribeMacro{\npaddplus}%
% \DescribeMacro{\npnoaddplus}%
% Using the \cs{npaddplus} command or the package option |addplus|, a
% plus sign can be added to a number that is specified without a
% sign.
% This can be switched off using \cs{npnoaddplus} resp.\ |noaddplus|.
%
% \DescribeMacro{\npaddplusexponent}%
% \DescribeMacro{\npnoaddplusexponent}%
% The commands \cs{npaddplusexponent} and \cs{npnoaddplusexponent}
% resp.\ the package options |addplusexponent| and |noaddplusexponent|
% do the same for the exponents that the commands/options described
% above do for the number.
%
%
% \subsection{Rounding numbers}%
% \label{sec:round}%
%
% \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 on using the
% \cs{nprounddigits\marg{digits}} command for ordinary
% numbers and the \cs{nproundexpdigits\marg{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}$''
%
%
% \subsection{Padding a number on the left side}%
% 
% \DescribeMacro{\nplpadding}%
% \DescribeMacro{\npnolpadding}%
% Sometimes it is desireable to have a number of a fixed length with
% the missing digits filled with a character (mostly the character
% ``0'', so this is the default).
% This can be achieved calling
% \cs{nplpadding\oarg{character}\marg{digits}}.
% This affects only the mantissa, the part after the decimal sign and
% signs are not counted!
% If the orginal number has more digits than \meta{digits} no
% characters will be inserted.
% For example,
% \begin{verbatim}
%\nplpadding{6}%
%$\numprint{1234}$, $\numprint{-1234}$,
%$\numprint{12345678}$, $\numprint{1234.5678}$ --
%\nplpadding[x]{6}%
%$\numprint{1234}$, $\numprint{-1234}$,
%$\numprint{12345678}$, $\numprint{1234.5678}$\end{verbatim}
% leads to \begingroup
% ``\nplpadding{6}$\numprint{1234}$, $\numprint{-1234}$,
% $\numprint{12345678}$, $\numprint{1234.5678}$ -- 
% \nplpadding[x]{6}$\numprint{1234}$, $\numprint{-1234}$,
% $\numprint{12345678}$, $\numprint{1234.5678}$''
% \endgroup
% 
% \cs{npnolpadding} switches padding off.
%
%
% \subsection{Replace zeros by other characters}
%
% \DescribeMacro{\npreplacenull}%
% \DescribeMacro{\npprintnull}%
% For amounts of money, sometimes a zero after the decimal sign is
% replaced by different symbols, as for example ``---''. 
% This can be done by calling the command
% \cs{npreplacenull\marg{replacement}}, e.g.,
% \begin{verbatim}
%\npreplacenull{\mbox{---}}\end{verbatim}
% Here, \cs{mbox} guarantees that ``---'' is printed in text
% mode.\footnote{You should better use \texttt{amsmath} and the
% command \cs{text} which preserves the correct text size, too.}
%
% It can be switched off using \cs{npprintnull}.
%
%
% \subsection{Change the format of units}
%
% \DescribeMacro{\npunitcommand}%
% By default, the unit is printed in math mode with an upright font.
% This is reached by using the \cs{npunitcommand} macro which by
% default is defined as follows:
% \begin{verbatim}
%\newcommand*\npunitcommand[1]{\ensuremath{\mathrm{#1}}}\end{verbatim}
% If you want to change this, redefine the \cs{npunitcommand}.
% You really should use either \cs{ensuremath} or
% \cs{text}\footnote{Provided by \texttt{amsmath}.} to ensure math or
% text mode respectively.
% \cs{npunitcommand} has to take one mandatory argument.
%
% For example, a blue unit is reached by
% \begin{verbatim}
%\renewcommand*\npunitcommand[1]{\ensuremath{\color{blue}\mathrm{#1}}}\end{verbatim}
% And here is the result:
%\begingroup
%\renewcommand*\npunitcommand[1]{\ensuremath{\color{blue}\mathrm{#1}}}%
%\numprint[N/mm^2]{300}
%\endgroup
%
%
% \section{Add more units to \cs{lenprint}}%
% \label{sec:more-units}%
%
% \DescribeMacro{\npdefunit}%
% The command \cs{npdefunit\marg{unitname}\marg{unit}\marg{scale}} can
% be used to define new units or to redefine existing ones.
% For example, |mm| is defined as follows:
% \begin{verbatim}
%\npdefunit{mm}{mm}{0.35145980351}\end{verbatim}
% The first argument \meta{unitname} is the \LaTeX\ internal name that
% will be given as unit in the \cs{lenprint} command.
% The second argument \meta{unit} is the text that will be printed
% out.
%
% The \meta{scale} arises from the fact that the default unit
% $\mathrm{pt}$ is defined as $\np[pt]{1} = 1/\np[in]{72,27} =
% \np[in]{0,01383700013}$ and $\np[in]{1} = \np[mm]{25,4}$.
% Thus, $\np[pt]{1} = \np{0,01383700013} \times \np[mm]{25,4} =
% \np[mm]{0.35145980351}$.
% For defining a new unit, the factor from $\mathrm{pt}$ to the
% desired unit has to be calculated and given as third argument of
% \cs{npdefunit}.
% To redefine a unit with unchanged scale, use |*| instead.
% For example,
% \begin{verbatim}
%\npdefunit{in}{\!''}{*}\end{verbatim}
% redefines |in| to print $\mathrm{''}$ as unit instead of the default
% $\mathrm{in}$.
% The \cs{!} is used to remove the separator between number and unit
% (\cs{,}) again.
% This only works correctly if \cs{,} and \cs{!} use the same
% measure.
% \begin{verbatim}
%$\lenprint[in]{\textwidth}$,
%\npdefunit{in}{\!''}{*}%
%$\lenprint[in]{\textwidth}$\end{verbatim}
% leads to \begingroup
% ``$\lenprint[in]{\textwidth}$,
% \npdefunit{in}{\!''}{*}$\lenprint[in]{\textwidth}$''.
% \endgroup
%
%
%
% \section{International support}%
% \label{sec:international}%
% \changes{1.00}{2003/10/07}{Automatic support for different number
%   formats in different languages}%
%
% As mentioned above, |numprint| uses German settings for numbers:
% thousand separator ``\cs{,}'', decimal sign ``\texttt{,}'', product
% sign ``\cs{cdot}'', unit separator \cs{,}, and no degree separator,
% by default.
% This will stay stable for compatibility with older versions even if
% its unlogical since the default language of \LaTeX\ is English.
%
% Using the package option |autolanguage| this can be fixed.
% If you are using this option without the |babel| package the
% settings are switched to English at \cs{begin\{document\}}.
% See Table~\ref{tab:defaults}.
%
% \begin{table}%
%   \centering
%   \caption{Default values for language settings}%
%   \label{tab:defaults}%
%   \begin{tabular}{lllllll}
%     \toprule
%     language& thousand& decimal& product& unit& percent& degree \\
%     & sep.& sign& sign& sep.& sep.& sep. \\
%     \midrule
%     English& \texttt{,}& \texttt{.}& \cs{times}& \cs{,}& \cs{,}& none \\
%     German& \cs{,}& \texttt{,}& \cs{cdot}& \cs{,}& \cs{,}& none \\
%     Portuguese& \texttt{.}& \texttt{,}& \cs{cdot}& \cs{,}& \cs{,}& none \\
%     Dutch& \cs{,}& \texttt{,}& \cs{cdot}& \cs{,}& none& none \\
%     French& \texttt{\texttildelow}& \texttt{,}& \cs{cdot}& \cs{,}& \cs{,}& none \\
%     \bottomrule
%   \end{tabular}%
% \end{table}
%
% \DescribeMacro{\selectlanguage}
% If you are using the |babel| package in conjunction with the
% |autolanguage| package option, the behaviour of \cs{numprint} alters
% with the active language.
% If you, for instance, use
% \begin{verbatim}
%\selectlanguage{ngerman}\end{verbatim}
% the German settings are selected.
% If you then switch back to English, the English settings are active
% again.
%
% The current version supports English, German, Portuguese, Dutch, and
% French.
% Unfortunately, I don't really know how to write numbers in other
% languages than German.
% I am quite sure that the English version also is
% correct.\footnote{Maybe, the percent sign separator \cs{,} is not
%   common, but I will leave its value unchanged to preserve
%   compatibility with older versions.}
% But please help me to add other languages.
%
% If you want other settings than the default ones, listed in
% Table~\ref{tab:defaults}, please refer to
% Section~\ref{sec:advanced:international}.
%
% As long as |numprint| does not support your language you may add the
% definitions by yourself.
% How this can be done is also described in
% Section~\ref{sec:advanced:international}.
%
%
% \section{Print aligned numbers in tabulars}%
% \label{sec:tabular}%
% \changes{1.10}{2003/10/12}{New tabular alignment mechanism}%
%
% Aligning numbers in tabulars is providede by the \texttt{dcolumn}
% and \texttt{rccol} packages.
% But they have two disadvantages.
% First, they do not support typesetting numbers in the same way as
% \cs{numprint} does.
% Second, they force the numbers to be typeset in math mode.
% Thus, this packages provides own mechanisms to gain aligned
% numbers.
%
% In former versions up to 1.00, the align mechanism in tabulars has
% been somehow weak because the author had to repeat the \cs{numprint}
% call in every table cell.
% This has been improved in version~1.10.
% For compatibility reasons, the old column types |n| and |N| have
% been preserved if you specify the |oldcolumntypes| package option;
% they will be discussed in section~{sec:column:old}.
%
%
% \subsection{The new column types}%
% \label{sec:column:new}%
%
% \DescribeMacro{column type n}
% The |numprint| package provides the column type |n| that takes two
% mandatory arguments.
% They define the number of digits before and the number of digits
% after the decimal sign.
% The results can be seen in the left column of the tabular below.
% You can use this column type as the normal column types, e.g.,
% \begin{verbatim}
% \begin{tabular}{n{3}{4}n{4}{2}}\end{verbatim}
% The numbers are printed in a reserved space with the necessary width
% for the specified numbers, aligned at the decimal sign.
% If a column contains numbers that have an exponent it is appended
% left-aligned while the width of the column is extended by the
% required space.
% This is shown in the first column in the example below.
% 
% If you, in addition, want to reserve space for digits in the
% exponent you can insert one (specify numbers of digits before the
% decimal sign) or two (number of digits before and after the decimal
% sign) optional arguments, as can be seen in columns 2 and 3 in the
% example below.
% If you reserve space for the exponent, too long exponents may exceed
% the tabular cell (as can be seen in the second column).
%
% This example tabular\footnote{The tabulars are ugly here. But the
% only important thing is to show the effects of the alignments.}
%\par\medskip\noindent
% {\tabcolsep0mm\small
% \begin{tabular}{|n{5}{3}|n[3]{5}{3}|n[3][1]{5}{3}|N{5}{3}|}
%   \hline
%   123.45e12& 123.45e12& 123.45e12& 123.45e12 \\
%   12345.678e123& 12345.678e123& 12345.678e123& 12345.678e123 \\
%   123.45e12.3& 123.45e12.3& 123.45e12.3& 123.45e12.3 \\
%   12345.678e123.3& 12345.678e123.3& 12345.678e123.3& 12345.678e123.3 \\
%   \hline
% \end{tabular}}
% \par\medskip\noindent
% is produced by the following code:
% \begin{verbatim}
%\tabcolsep0mm\small
%\begin{tabular}{|n{5}{3}|n[3]{5}{3}|n[3][1]{5}{3}|N{5}{3}|}
%  \hline
%  123.45e12& 123.45e12& 123.45e12 & 123.45e12 \\
%  12345.678e123& 12345.678e123& 12345.678e123& 12345.678e123 \\
%  123.45e12.3& 123.45e12.3& 123.45e12.3& 123.45e12.3 \\
%  12345.678e123.3& 12345.678e123.3& 12345.678e123.3& 12345.678e123.3 \\
%  \hline
%\end{tabular}\end{verbatim}
% The |n| column type prints the number in math mode.
% Thus, the first three columns in the example are printed with lining
% figures.
% \DescribeMacro{column type N}
% To print numbers in text mode, you can use the |N| column type as
% shown in column four of the tabular.\footnote{If you use a tabular
%   environment that prints its arguments in math mode, e.g., the
%   \texttt{array} environment, also \texttt{N} prints the numbers in
%   math mode.}
% It takes the same arguments as the |n| column type.
%
% You may put additional text into tabular cells.
% The numprint package uses an algorithm to determine which part is
% the number and which is additional text.
% In order to preserve spaces and to use characters as text that could
% also be part of a number (e.g., digits or the characters ``e'',
% ``E'', ``d'', or ``D'') you have to enclose the text in
% braces, for example ``\texttt{\{hello\} 1234}'' instead of
% ``\texttt{hello 1234}''.
% (In some rare cases, even two pairs of braces is necessary.
% This is the case if you want to use a single character that may also
% be used in a number, e.g., ``\texttt{\{\{3\}\}
% 1234}''.\footnote{It is the same if the text starts with one of some
% special commands that normally don't occur at the beginning of
% tabular cells, \cs{end}, \cs{tabularnewline}, \cs{nprt@end},
% \cs{endtabular}, \cs{csname}, and \cs{relax}.})
% If you don't use these enclosing braces strange results may appear.
% For preceding text, you have to ensure that it has the same width
% for all lines of the same column.
% Have a look at the following example:
%\begin{verbatim}
%\begin{tabular}{n{2}{1}n{2}{1}n{2}{1}n[1]{2}{1}}
%  \toprule
%  {without braces}&
%  {with braces}&
%  {with braces and box}&
%  \multicolumn{1}{l}{with braces, exp, and box}
%  \\
%  \midrule
%  abc def 12,3e3 rt&
%  {abc def } 12,3e3 { rt}&
%  {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}&
%  {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}
%  \\
%  more 45,1 txt&
%  {more } 45,1 { txt}&
%  {\npmakebox[abc def ][l]{more }} 45,1 { txt}&
%  {\npmakebox[abc def ][l]{more }} 45,1 { txt}
%  \\
%  \midrule
%  not blue 45,1 txt&
%  {\color{blue}blue } 45,1 { txt}&
%  {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}&
%  {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}
%  \\
%  \bottomrule
%\end{tabular}
%\end{verbatim}
% The result looks as follows:
% \par\medskip\noindent
%{\footnotesize
%\begin{tabular}{n{2}{1}n{2}{1}n{2}{1}n[1]{2}{1}}
%  \toprule
%  {without braces}&
%  {with braces}&
%  {with braces and box}&
%  \multicolumn{1}{l}{with braces, exp, and box}
%  \\
%  \midrule
%  abc def 12,3e3 rt&
%  {abc def } 12,3e3 { rt}&
%  {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}&
%  {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}
%  \\
%  more 45,1 txt&
%  {more } 45,1 { txt}&
%  {\npmakebox[abc def ][l]{more }} 45,1 { txt}&
%  {\npmakebox[abc def ][l]{more }} 45,1 { txt}
%  \\
%  \midrule
%  not blue 45,1 txt&
%  {\color{blue}blue } 45,1 { txt}&
%  {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}&
%  {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}
%  \\
%  \bottomrule
%\end{tabular}}
% \par\medskip\noindent
% In the first column, the texts before and after the number are
% not enlosed by braces.
% Then, strange results appear:
% In the first line, ``\texttt{de}'' is interpreted as number.
% Thus, it is printed in math mode, and the rest of the cell,
% ``\texttt{f 12,3e3 rt}'' is printed as text, again.
% In the second line, the part ``\texttt{e 45,1}'' is printed as
% number.
%
% This strange behaviour can be avoided by enclosing the texts by
% braces, as mentioned above and shown in the second column.
% Thus, the texts are printed correctly.
% A space in the enclosed texts can separate the text from the number,
% as done in the example.
% Since the left texts have different widths the alignment of the
% numbers is broken, here.
%
% This can be fixed by putting the contents in boxes, using the
% \cs{makebox} or \cs{npmakebox} command, as shown in the third
% column.
% \DescribeMacro{\npmakebox}
% The \cs{npmakebox} has a similar syntax as the \cs{makebox} command
% but uses a text instead of a length to determine the width of the
% box: \cs{npmakebox\oarg{text 1}\oarg{justification}\marg{text 2}}.
% The command determines which width \meta{text 1} would have and
% typesets \meta{text 2} into a box of this width.
%
% If you put the preceding text in each line in such a box the number
% will be aligned as desired.
% 
% Still, the text on the right-hand side of the numbers is not
% aligned.
% This can be fixed by specifying the number of digits of the
% exponent, as shown in the fourth column.
%
% The third line is a little bit different from the others.
% Here, not only text is inserted but also a command that changes the
% output of the numbers.
% Even such commands have to be enclosed by braces.
%
% \DescribeMacro{\multicolumn}
% For producing tabular cells that don't contain a number, you either
% have to enclose the cell contents by braces or to use the
% \cs{multicolumn} command as shown in the first line of the example
% above.
%
% If you want to print a line in bold letters using the \cs{boldmath}
% command in math resp.\ \cs{bfseries} in text mode the alignment is
% not correct anymore.
% This is due to the fact that the bold letters are wider than the
% normal ones.
% You can avoid that problem if the font family provides a bold font
% shape that has the same width as the normal one.
% For the Computer Modern fonts, such a font shape exists.
% In text mode, you can access it by using 
% \changes{1.10}{2003/10/12}{Define math version \texttt{npbold}}%
% \begin{verbatim}
% \fontseries{b}\selectfont\end{verbatim}
% \DescribeMacro{\mathversion}
% \DescribeMacro{\npboldmath}
% If you also want to use that font in math mode, you may use the math
% version |npbold| by using \cs{mathversion\{npbold\}} or
% \cs{npboldmath}.
% In order to save memory, these commands and the |npbold| math
% version are only available if you call |numprint.sty| using the
% |boldmath| package option.
%
% An example:
% \begin{verbatim}
%\begin{tabular}{lN{12}{3}n{12}{3}}
%  \toprule
%  normal:& 
%  123456123456.123e12&
%  123456123456.123e12
%  \\
%  bold:&
%  {\fontseries{b}\selectfont} 123456123456.123e12&
%  {\npboldmath} 123456123456.123e12
%  \\
%  bold extended:&
%  {\bfseries} 123456123456.123e12&
%  {\boldmath} 123456123456.123e12
%  \\
%  \bottomrule
%\end{tabular}\end{verbatim}
% This produces:
% \par\medskip\noindent
%{\small
%\begin{tabular}{lN{12}{3}n{12}{3}}
%  \toprule
%  normal:& 
%  123456123456.123e12&
%  123456123456.123e12
%  \\
%  bold:&
%  {\fontseries{b}\selectfont} 123456123456.123e12&
%  {\npboldmath} 123456123456.123e12
%  \\
%  bold extended:&
%  {\bfseries} 123456123456.123e12&
%  {\boldmath} 123456123456.123e12
%  \\
%  \bottomrule
%\end{tabular}}
%\par\medskip
%
% If you want to add the same text or commands to all lines of a
% tabular column, you can use the ``|>|'' specifier in the declaration
% of the tabular column, as usual.
% You have to enclose its argument in an additional pair of braces, as
% shown in the example below.
% Unfortunately, the ``|<|'' specifier does not work properly.
% \DescribeMacro{\npafternum}
% Therefore, the \cs{npafternum} command is defined that takes one
% argument which is printed after the number.
% The following example shows text before and after the number:
% \begin{verbatim}
%\begin{tabular}{%
%  >{{before \npafternum{ after}}}n[2]{12}{3}%
%  >{{\nprounddigits{4}}}n{3}{4}%
%  >{{\color{blue}}}n{12}{3}}
%  \toprule
%  123456123456.123e12&
%  12.12345&
%  123456.23e1
%  \\
%  12345.123e12&
%  12.1&
%  14561234.562e12
%  \\
%  \bottomrule
%\end{tabular}\end{verbatim}
% This produces:
% \par\medskip\noindent
%{\small
%\begin{tabular}{%
%  >{{before \npafternum{ after}}}n[2]{12}{3}%
%  >{{\nprounddigits{3}}}n{3}{3}%
%  >{{\color{blue}}}n{8}{3}}
%  \toprule
%  123456123456.123e12&
%  12.12353&
%  123456.23e1
%  \\
%  12345.123e12&
%  12.1&
%  14561234.562e12
%  \\
%  \bottomrule
%\end{tabular}}
%\par\medskip
% As can be seen in the second column, numbers can be rounded in
% special columns by inserting \cs{nproundigits} into a ``|>|''
% specification.
% This can be said for all other commands that influence the format of
% numbers, too.
%
% \DescribeMacro{\npunit}
% Normally, units should not be typeset in the cells of a tabular.
% But if this is needed, it may be realized using the \cs{npunit}
% command, as shown here:
% \begin{verbatim}
%\begin{tabular}{>{{\npunit{N/mm^2}}}n{5}{3}}
%  \toprule
%  12345.123\\
%  12.12\\
%  {\npunit{psi}} 234.4\\
%  4.3\\
%  \bottomrule
%\end{tabular}\end{verbatim}
% This produces:
% \par\medskip\noindent
%{\small
%\begin{tabular}{>{{\npunit{N/mm^2}}}n{5}{3}}
%  \toprule
%  12345.123\\
%  12.12\\
%  {\npunit{psi}} 234.4\\
%  4.3\\
%  \bottomrule
%\end{tabular}}
%\par\medskip
%
% The tabular alignment of the |numprint| package has been tested with
% the |tabular|, |tabular*|, |array|, |tabularx|~\cite{carlisle1999a},
% and |longtable|~\cite{carlisle2000a} environments.
% It may or may not run with other packages and environments.
%
%
% \subsection{The old column types}%
% \label{sec:column:old}%
%
% \newcolumntype{m}[2]{>{\npdigits{#1}{#2}$}l<{$}}%
% \newcolumntype{M}[3]{>{\npdigits{#1}{#2}\npexponentdigits{#3}$}l<{$}}%
%
% \DescribeMacro{column type N}
% If the |oldcolumntype| package option is specified the column types
% |n| and |N| are defined differently than described in the previous
% section.
% \DescribeMacro{column type n}
% The |n| column type alignes the base number to the decimal sign, the
% |N| column type additionaly alignes the exponent.
%
% Use these commands as follows:
% \begin{verbatim}
%\tabcolsep0mm
%\begin{tabular}{|n{5}{3}|N{5}{3}{3}|}
%  \hline
%  \numprint{123.45e12}& \numprint{123.45e12}\\
%  \numprint{12345.678e123}& \numprint{12345.678e123}\\
%  \numprint{123.45e12.3}& \numprint{123.45e12.3}\\
%  \numprint{12345.678e123.3}& \numprint{12345.678e123.3}\\
%  \hline
%\end{tabular}\end{verbatim}
% This leads to\par\medskip\noindent
% {\tabcolsep0mm
% \begin{tabular}{|m{5}{3}|M{5}{3}{3}|}
%   \hline
%   \numprint{123.45e12}& \numprint{123.45e12}\\
%   \numprint{12345.678e123}& \numprint{12345.678e123}\\
%   \numprint{123.45e12.3}& \numprint{123.45e12.3}\\
%   \numprint{12345.678e123.3}& \numprint{12345.678e123.3}\\
%   \hline
% \end{tabular}}
% \medskip
%
% The first argument 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.
% It is not possible to define the numbers of digits after the decimal
% sign in the exponent; they are set to zero.
% Notice that the command \verb|\numprint| has to be written again in
% each tabular entry, using the old column types.
%
% 
% \subsection{Alignment in normal text}%
%
% The alignment of the numbers in tabulars is realized by writing the
% number inside a box with the specified width.
% This functionality can also be used outside tabular environments.
% \DescribeMacro{\npdigits}
% The \cs{npdigits\marg{before}\marg{after}} command switches on the
% alignment of numbers printed by \cs{numprint}. 
% The first argument defines the number of digits before the decimal
% sign while the second argument defines the number of digits after
% it for the mantissa.
% \DescribeMacro{\npexponentdigits}
% Since exponents are normally integer numbers the syntax of the
% corresponding \cs{npexponentdigits} command is slightly different.
% Its syntax is \cs{npexponentdigits\oarg{after}\marg{before}}.
% The mandatory argument defines the number of digits before the
% decimal sign of the exponent.
% If no optional argument is given, the number of digits after the
% decimal sign is set to zero.
% If it is given it defines the number of digits after the decimal
% sign.
%
% If the \cs{npdigits} or \cs{npexponentdigits} commands have been
% used inside a group the values are reset at the end of the group.
% \DescribeMacro{\npnodigits}
% \DescribeMacro{\npnoexponentdigits}
% Alignment can also be switched off using the \cs{npnodigits} resp.\
% \cs{npnoexponentdigits} commands.
%
%
% \section{Error messages etc.}
%
% By default, \cs{numprint} produces an error message if the argument
% uses some invalid characters or if the number format is invalid.
% Some people use \cs{numprint} to do strange things and thus use
% invalid arguments designedly.
% These people may switch off these error messages by using the
% package option |warning|.
%
% If you want some debug messages to be written into the log file, use
% the package option |debug|.
%
%
% \section{Advanced customization}%
% \label{sec:advanced}%
% 
% \subsection{Changing the output}%
% \label{sec:changing-output}%
%
% Most of the things described in this section are not necessary to be
% done by hand because the feature ``automatic language support'',
% described in section~\ref{sec:international} does this
% automatically.
%
% \subsubsection{Without the \textmd{\texttt{autolanguage}} option}
%
% \DescribeMacro{\npthousandsep}%
% \DescribeMacro{\npthousandthpartsep}%
% \DescribeMacro{\npdecimalsign}%
% \DescribeMacro{\npproductsign}%
% By using the commands
% \cs{npdecimalsign\marg{Sign}},
% \cs{npthousandsep\marg{Separator}},
% \cs{npthousandthpartsep\marg{Separator}}, and
% \cs{npproductsign\marg{Sign}},\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 and symbols can be changed, e.g.,
% \begin{verbatim}
%\npdecimalsign{\ensuremath{\cdot}}\npthousandsep{,}\npproductsign{*}%
%\numprint{-123456}; \numprint{3,1415927e-3.2}\end{verbatim}
% leads to ``{\npdecimalsign{\ensuremath{\cdot}}%
% \npthousandsep{,}\npproductsign{*}%
% \numprint{-123456}; \numprint{3,1415927e-3.2}}''.
%
% The \cs{npthousandsep} both changes the separators before and after
% the decimal sign. 
% If you want to use different separators, you have to call
% \cs{npthousandthpartsep} \emph{after} \cs{npthousandsep}.
%
% The separators as well as the decimal sign are typeset in the same
% mode as the number itself (math or text).
% If you want to guarantee a special mode, you have to use
% \cs{ensuremath} for math or either \cs{mbox}, \cs{textrm}, or
% \cs{text}\footnote{Provided by \texttt{amsmath}.} for text mode.
%
% The product sign, in contrast, is always printed in math mode.
% Thus, you don't have to add \cs{ensuremath} to use math commands.
%
% \DescribeMacro{\global}%
% If using these commands inside a group (|{|\ldots|}|,
% \cs{begingroup}\ldots\cs{endgroup}, or an environment) 
% the behaviour of the \verb|\numprint| command is changed
% 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{\cdot}\numprint{123e4}},
%\numprint{123e4}.
%Global:
%\numprint{123e4},
%{\global\npproductsign{\cdot}\numprint{123e4}},
%\numprint{123e4}\end{verbatim}
% leads to the following:
%
% \noindent Local:
% \numprint{123e4},
% {\npproductsign{\cdot}\numprint{123e4}},
% \numprint{123e4}.
% Global:
% \numprint{123e4},
% {\npproductsign{\cdot}\numprint{123e4},
% \numprint{123e4}}
%
% The current version has the following defaults:
% \begin{verbatim}
%\npthousandsep{\,}
%\npdecimalsign{,}
%\npproductsign{\cdot}
%\npunitseparator{\,}\end{verbatim}
%
% \DescribeMacro{\npunitseparator}%
% The space between the number and the unit is ``\cs{,}'' by
% default. It can be changed using the command
% \cs{npunitseparator\marg{Separator}},
% e.g.,
% \begin{verbatim}
%\npunitseparator{~}\end{verbatim}
%
% \DescribeMacro{\npdegreeseparator}%
% By default, no space is added between the number an a degree symbol.
% You may specify a separator for that using
% \cs{npdegreeseparator\marg{Separator}}.
% 
% \DescribeMacro{\npcelsiusseparator}%
% By default, the same space as for normal units is added between the
% number an \textcelsius.
% You may specify a different separator for that using
% \cs{npcelsiusseparator\marg{Separator}}.
% Note that \cs{tccentigrade} is not supported by |numprint|.
% 
% \DescribeMacro{\nppercentseparator}%
% By default, the same space as for normal units is added between the
% number and a percent sign.
% You may specify a different separator for that using
% \cs{nppercentseparator\marg{Separator}}.
% 
%
%
% \subsubsection{With the \textmd{\texttt{autolanguage}} option}%
% \label{sec:advanced:international}%
%
% If you are using the |autolanguage| option changes made with the
% commands described in the previous section get lost at the next
% change of the language or at \cs{begin\{document\}}.
% Thus, they cannot be used with this option in the way described
% there.
%
% Thus, you have to redefine the commands that set the
% language-dependent numprint settings.
% For each known language, a command \cs{npstyle\meta{language}} is
% defined that does the changes, e.g., \cs{npstyleenglish} for
% English.
% \DescribeMacro{\npstyleenglish}
% This command is defined as follows:
% \begin{verbatim}
%\newcommand*\npstyleenglish{%
%  \npthousandsep{,}%
%  \npdecimalsign{.}%
%  \npproductsign{\times}%
%  \npunitseparator{\,}%
%  \npdegreeseparator{}%
%  \npcelsiusseparator{\nprt@unitsep}%
%  \nppercentseparator{\nprt@unitsep}%
%}\end{verbatim}
%
% If you want to use different settings for this language, you have
% two possibilities:
% \begin{enumerate}
% \item
%   Copy the definition for \cs{npstyle\meta{language}} from the style
%   file and change it according to your wishes, for
%   example:\footnote{Notice that you have to use \cs{renewcommand*}
%   instead of \cs{newcommand*}.}
%   \begin{verbatim}
%\renewcommand*\npstyleenglish{%
%  \npthousandsep{,}%
%  \npdecimalsign{{\cdot}}%
%  \npproductsign{\times}%
%  \npunitseparator{\,}%
%  \npdegreeseparator{}%
%  \npcelsiusseparator{\nprt@unitsep}%
%  \nppercentseparator{\nprt@unitsep}%
%}\end{verbatim}
% \item
%   Another way to add different settings to a language is to use
%   \cs{g@addto@macro} to append commands to an existing
%   \cs{npstyle\meta{language}} command, e.g.,
%   \begin{verbatim}
%\makeatletter
%\g@addto@macro\npstyleenglish{%
%  \nppercentseparator{}%
%}%
%\makeatother\end{verbatim}
%   This has the advantage that changes in the original command are not
%   lost by using a copy.
%   The disadvantage is that some commands may be called twice which is
%   slightly slower.
% \end{enumerate}
% The changes take effect when the style command is called the next
% time; this is when the language is changed the next time or at
% \cs{begin\{document\}}.
%
%
% If the language you are using is not yet supported by |numprint| you
% may add support for it in the preamble of your document.
% 
% \DescribeMacro{\npaddtolanguage}
% The simplest case is a language that uses the same settings as one
% of the languages, already supported.
% If, for instance, you want to use Danish with the same settings as
% German, you just have to add
% \begin{verbatim}
%\npaddtolanguage{danish}{german}\end{verbatim}
% to the preamble of your document.
%
% If you, instead, want to use different settings, define a
% corresponding style command.
% Let's take Danish as an example, again.
% Define a command \cs{npstyledanish} which defines
% everything you want to change against the default (I choose some
% strange values for clearness):
% \begin{verbatim}
%\newcommand*\npstyledanish{%
%  \npthousandsep{.}%
%  \npdecimalsign{\ensuremath{\cdot}}%
%  \npproductsign{*}%
%  \npunitseparator{~}%
%  \npdegreeseparator{}%
%  \npcelsiusseparator{\nprt@unitsep}%
%  \nppercentseparator{\nprt@unitsep}%
%}\end{verbatim}
% In addition, append the call of this command to the
% language-switching command for Danish:
% \begin{verbatim}
%\npaddtolanguage{danish}{danish}\end{verbatim}
%
%
% \subsection{Changing the argument parsing}%
% \label{sec:custom-parsing}%
%
% It has been said above that thousand separators are not allowed in
% the argument of the \cs{numprint} command.
% This can be customized by the user.
%
% For most elements in the input, \cs{numprint} uses lists that
% contain the corresponding characters.
% \DescribeMacro{\nprt@dotlist}
% The macro \cs{nprt@dotlist} contains the characters interpreted as
% decimal signs.
% It is defined as followed:
% \begin{verbatim}
%\newcommand*\nprt@dotlist{.,}\end{verbatim}
% If you, for example, only want to allow the dot as decimal sign,
% redefined the list:
% \begin{verbatim}
%\renewcommand*\nprt@dotlist{.}\end{verbatim}
% If you want to do this in your document rather than in the
% configureation file \texttt{numprint.cfg}---see
% section~\ref{sec:configuration}--- you have to enclose this by
% \cs{makeatletter} and \cs{makeatother}.
%
% \DescribeMacro{\nprt@explist}%
% The \cs{nprt@explist} command contains the characters interpreted as
% delimiter between mantissa and exponent.
% By default it contains ``\texttt{eEdD}''.
% Redefine it as \cs{nprt@dotlist}.
%
% \DescribeMacro{\nprt@ignorelist}%
% The \cs{nprt@ignorelist} command contains a list of characters that
% are ignored in the input (in addition to spaces, ``\cs{,}'', and
% ``\texttt{\~}'').
% It is empty by default.
% If you, for example, only want to allow dots as decimal sign and
% commas may occur as thousand separators in the input, you may use
% following redefinition:
% \begin{verbatim}
%\renewcommand*\nprt@dotlist{.}
%\renewcommand*\nprt@ignorelist{,}\end{verbatim}
% Then, ``\texttt{,}'' is ignored in the input and ``\texttt{.}'' is
% interpreted as decimal sign.
% For example,
% \begin{verbatim}
%\makeatletter
%{\renewcommand*\nprt@dotlist{.}%
%\renewcommand*\nprt@ignorelist{,}%
%\numprint{12,234.123,45e1,2,3.0}}
%\makeatother\end{verbatim}
% leads to 
% \makeatletter%
% {\def\nprt@dotlist{.}\def\nprt@ignorelist{,}``\numprint{12,234.123,45e1,2,3.0}}''.
% \makeatother
% 
% \DescribeMacro{\nprt@signlist}%
% The \cs{nprt@signlist} command contains the list of known signs. 
% By default, it is set to ``\texttt{+-}\cs{pm}''.
% You may change the list of accepted signs by redefining
% \cs{nprt@signlist}.
% If, for instance, the letter ``\texttt{*}'' is intended to be a
% sign, just type in
% \begin{verbatim}
%\renewcommand*\nprt@signlist{+-\pm *}\end{verbatim}
% This character is typeset when using it as sign.
% But this indicates one problem: The sign might differ between text
% and math mode, as show in the following example:
% {\makeatletter\def\nprt@signlist{+-\pm *}\makeatother
% In text mode, \cs{numprint\{*1234\}} occurs as ``\numprint{*1234}''
% while is is typeset as ``$\numprint{*1234}$'' in math mode.}
% To avoid that, you may define a command that prints the sign.
% This command must have a name according to
% \cs{nprt@list@\meta{sign}}.
% \DescribeMacro{\nprt@sign@*}%
% In this case, you have to define \cs{nprt@list@*}.
% Since the sign might be arbitrary characters, you should define the
% command as follows:
% \begin{verbatim}
%\expandafter\newcommand\csname nprt@sign@*\endcsname{{\ensuremath{*}}}\end{verbatim}
% {\makeatletter\expandafter\def\csname nprt@sign@*\endcsname{{\ensuremath{*}}}%
% \def\nprt@signlist{+-\pm *}\makeatother
% With this command, \cs{numprint\{*1234\}} occurs as
% ``\numprint{*1234}'' in text mode and as ``$\numprint{*1234}$'' in
% math mode.}
%
% Because of this mechanism to print a sign, it is not possible to use
% other macro names than \cs{pm} for signs.\footnote{\cs{pm} is
% handled separately.}
% You have to use single characters as the shown ``\texttt{*}''.
%
%
% \section{Some tricks}
%
% \subsection{Let the signs depend on the mode}
%
% \DescribeMacro{\nprt@sign@+}%
% \DescribeMacro{\nprt@sign@-}%
% \DescribeMacro{\nprt@sign@+-}%
% The default signs are typeset in math mode independently of the mode
% the number ist printed.
% If you are using a font in which the sings of text and math mode
% differ much, this may be unsatisfactory.
% Then, you can typeset different signs for text and math mode.
% Therefore, it is used that the default signs use the same macros as
% user signs, described in section~\ref{sec:custom-parsing}.
% They are defined as follows:
% \begin{verbatim}
%\expandafter\newcommand\csname nprt@sign@+\endcsname{{\ensuremath{+}}}
%\expandafter\newcommand\csname nprt@sign@-\endcsname{{\ensuremath{-}}}
%\expandafter\newcommand\csname nprt@sign@+-\endcsname{{\ensuremath{\pm}}}\end{verbatim}
% If you, for instance, don't want to use the math minus for numbers
% in text mode but another character, you may redefine
% \cs{nprt@sign@-}:
% \begin{verbatim}
%\expandafter\renewcommand\csname nprt@sign@-\endcsname{%
%  \ifmmode {-}\else {---}\fi}\end{verbatim}
%{\makeatletter\expandafter\def\csname nprt@sign@-\endcsname
%  {\ifmmode {-}\else {---}\fi}\makeatother
% With this definition, \cs{numprint\{-1234\}} leads to
% ``\numprint{-1234}'' resp.\ ``$\numprint{-1234}$'' in text resp.\
% math mode.}
% 
%
% \subsection{Typing negative numbers in red}%
% \label{sec:negative-red}%
%
% If you want to print negative number in red colors, you can use the
% \cs{nprt@sign@-} command, too.
% The following example shows how to do it:
% \begin{verbatim}
%\usepackage{color}
%\makeatletter
%\expandafter\renewcommand\csname nprt@sign@-\endcsname{%
%  \color{red}{\ensuremath{-}}}
%\makeatother\end{verbatim}
% With this definition,
% \begin{verbatim}
%\numprint{1234}, \numprint{-1234},
%\numprint{1234e-123}, \numprint{-1234e123}.\end{verbatim}
% {\makeatletter\expandafter\def\csname nprt@sign@-\endcsname
%   {\color{red}{\ensuremath{-}}}\makeatother
% leads to ``\numprint{1234}, \numprint{-1234}, \numprint{1234e-123},
% \numprint{-1234e123}.''}\footnote{Whether you can see the effect in
% the output depends on the viewer; in PostScript and PDF the red
% color works, in many dvi viewers, it doesn't.}
% To avoid a negative exponent beeing printed in red for a positive
% mantissa, a hack is included in the page which is described in
% appendix~\ref{sec:code:main}, page~\pageref{page:code:color}.
% 
%
%
% \subsection{Configuration file}%
% \label{sec:configuration}%
% 
% If your \LaTeX\ installation provides a file \texttt{numprint.cfg}
% in the \TeX\ search path, it is loaded by \texttt{numprint.sty} as
% last action.
% Thus, you may add all changes and extensions, new languages for
% instance, into this file.
% 
%
% \appendix
%
% \section{Compatiblity to older versions}
%
% In most cases, the user macros of this package (the macros not
% containing a ``|@|'' in their name) should be compatible to older
% versions.
% The parsing of the argument has been improved that some arguments of
% \cs{numprint} may be accepted or not in contrast to the older
% version.
%
% The spacing of aligned numbers has also been corrected.
% Thus, this is be incompatible to the older version if you are using
% alignment in the exponent or math environmens other than
% \cs{textstyle}.
%
% 
% \section{Lists of options and commands}
%
% This section contains lists of all package options resp.\ available
% commands. 
% Items that belong together and may be exclusive are printed in
% groups together.
%
% \subsection{Package options}%
% \label{sec:package-options}%
%
% \begingroup
% \newcommand*\default{$^{*}$}%
% The default values are marked by \default.
% \begin{longtable}[l]{%
%     @{}>{\ttfamily}p{0.30\linewidth}@{}p{0.70\linewidth}@{}}
%   warning& Produce warnings rather than error messages. \\
%   error\default& Produce error messages rather than
%   warnings. \\[\medskipamount]
%   autolanguage& Switch the settings language dependent.\\
%   noautolanguage\default& Fixed settings.\\[\medskipamount]
%   sepfour\default& Separator for four-digit numbers.\\
%   nosepfour& No separator for four-digit numbers.\\[\medskipamount]
%   addmissingzero\default& Add missings zeros before or after the
%     decimal sign.\\
%   noaddmissingzero& Don't do that.\\[\medskipamount]
%   addplus& Add a plus to a number without a sign.\\
%   noaddplus\default& Don't do that.\\[\medskipamount]
%   addplusexponent& Add a plus to a number without a sign in
%   exponents.\\
%   noaddplusexponent\default& Don't do that.\\[\medskipamount]
%   oldcolumntypes& Define the old column types that need to use the
%     \cs{numprint} inside the tabular.\\
%   newcolumntypes\default& Use the new column types.\\[\medskipamount]
%   boldmath& Define the \texttt{npbold} math version.\\[\medskipamount]
%   np& Define the shortcut \cs{np} for
%     \cs{numprint}.\\[\medskipamount]
%   debug& Produce debug information in the log file.
% \end{longtable}
% \endgroup
%
% \subsection{Commands}
%
% \begin{longtable}[l]{%
%     @{}>{\ttfamily \char`\\}p{0.3\linewidth}@{}p{0.7\linewidth}@{}}
%   npfourdigitsep& Switch on separating four-digit numbers.\\
%   npfourdigitnosep& Switch off separating four-digit
%   numbers.\\[\medskipamount]
%   npaddmissingzero& Switch on adding missings zeros before or after the
%     decimal sign.\\
%   npnoaddmissingzero& Switch off adding missings zeros before or after
%   the decimal sign.\\[\medskipamount]
%   npaddplus& Add a plus to a number without a sign.\\
%   npnoaddplus& Don't do that.\\[\medskipamount]
%   npaddplusexponent& Add a plus to the exponent when it has no sign.\\
%   npnoaddplusexponent& Don't do that.\\[\medskipamount]
%   np& Shortcut for \cs{numprint} (only available with package
%   option~\texttt{np}).\\
%   numprint& Typesets a number (the package's main
%   command).\\[\medskipamount]
%   npdecimalsign& Change the decimal sign.\\
%   npthousandsep& Change the thousand separator (before and after the
%   decimal sign).\\
%   npthousandthpartsep& Change the thousand separator (only after the
%   decimal sign).\\
%   npproductsign& Change the product sign.\\
%   npunitseparator& Change the separator between a number and a
%   unit.\\
%   npdegreeseparator& Change the separator between a number and a
%   degree symbol.\\[\medskipamount]
%   npcelsiusseparator& Change the separator between a number and
%   \textcelsius.\\[\medskipamount]
%   nppercentseparator& Change the separator between a number and a
%   percent sign.\\[\medskipamount]
%   nprounddigits& Declare how many digits will be printed after the
%   decimal sign.\\
%   npnoround& Switch off rounding and print numbers as given.\\
%   nproundexpdigits& Declare how many digits will be printed after the
%   decimal sign in the exponent.\\
%   npnoroundexp& Switch off rounding for the
%   exponent.\\[\medskipamount]
%   nplpadding& Declare up to how many digits the number will be padded at
%   the lefthand side. \\
%   npnolpadding& Switch off padding. \\[\medskipamount]
%   npreplacenull& Replace the after-decimal-sign part by another text
%   if it is zero.\\
%   npprintnull& Print zeros after the decimal sign.\\[\medskipamount]
%   npdigits& Switch on aligned number printing with given digits before
%   and after the decimal sign.\\
%   npnodigits& Print numbers in a box that is as wide as needed by the
%   number.\\
%   npexponentdigits& Switch on aligned printing of the exponent.\\
%   npnoexponentdigits& Switch alignment off for the
%   exponent.\\[\medskipamount]
%   npaddtolanguage& Adds language definitions to the extras section
%   of a \texttt{babel} language.\\
%   npstyledefault& Defines the settings in standard format.\\
%   npstylegerman& Defines the German number format.\\
%   npstyleenglish& Defines the English number
%     format.\\[\medskipamount]
%   npmakebox& Command similar to \cs{makebox} but with text instead
%     of length in first optional argument.\\[\medskipamount]
%   npboldmath& Bold math version with digits with the same width as
%   normal digits.\\[\medskipamount]
%   npafternum& Puts text after the number in
%   tabulars.\\[\medskipamount]
%   npunit& Sets the unit in tabulars.\\[\medskipamount]
% \end{longtable}
%
% \section{Known bugs}
%
% \begin{itemize}
% \item When aligning the exponent for tabulars, the distance between
%   the ``10'' and the exponent is too small.
% \item Printing negative numbers in red does not work.
%   Only the minus sign is printed in red.
%   When was this bug introduced?
% \end{itemize}
%
% \section{To do}
%
% \begin{itemize}
% \item Add more languages to the automatic international support.
% \item Add support for ``|<|'' in tabular definitions.
% \item Avoid many of the temporary variables.
% \item Add support for numbers in tabulars that are right aligned or
%   centered.
% \end{itemize}
%
% \section{Acknowledgements}
%
% \begin{itemize}
% \item
%   Tilman Finke, had the idea of rounding numbers.
% \item
%   Stephan Helma has implemented padding numbers on the left side.
%   This function has been slightly changed by me.
% \item
%   Portuguese support by Vilar Camara Neto and Luis.
% \item
%   Dutch support by Ralph Hendriks.
% \item
%   French support by Daniel Flipo.
% \item
%   Ignacio Fern\'andez Galv\'an has reported a couple of bugs and
%   suggestions (which parly still have to be implemented\ldots)
% \end{itemize}
%
% \begin{thebibliography}{1}
% \bibitem{carlisle1999a}
%   Carlisle, David: \emph{The \texttt{tabularx} package},
%   version~2.07, 1999.\newblock
%   \url{CTAN:macros/latex/contrib/tabularx/}.
% \bibitem{carlisle2000a}
%   Carlisle, David: \emph{The \texttt{longtable} package},
%   version~4.10, 2000.\newblock
%   \url{CTAN:macros/latex/contrib/longtable/}.
% \bibitem{guthoehrlein2000a}
%   Guth\"ohrlein, Eckhart: \emph{The \texttt{rccol} package},
%   version~1.1a, 2000.\newblock
%   \url{CTAN:macros/latex/contrib/rccol/}.
% \end{thebibliography}
%
% \StopEventually{\PrintChanges \PrintIndex}
%
% \section{The implementation}
% \iffalse
%<*package>
% \fi
% Heading of the package:
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{numprint}
  [2012/08/20  v1.39  Print numbers (HH)]
%    \end{macrocode}
%
% \subsection{Load packages}
%
% \changes{1.33}{2004/11/19}{Avoid to use the \texttt{calc} package
%   since it causes problems with many other packages}%
%
% Load package array.sty for the new column types.
%    \begin{macrocode}
\RequirePackage{array}
%    \end{macrocode}
% \changes{1.10}{2003/10/12}{Avoid use of \texttt{substr} package}%
%
% \subsection{Package options and settings}
%
% 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\ifnprt@numsepfour
%    \end{macrocode}
% Show warnings or errors?
%    \begin{macrocode}
\newif\ifnprt@errormessage
%    \end{macrocode}
% Add missing zeros?
%    \begin{macrocode}
\newif\ifnprt@addmissingzero
%    \end{macrocode}
% Add missing plus signs?
%    \begin{macrocode}
\newif\ifnprt@addplus@mantissa
\newif\ifnprt@addplus@exponent
%    \end{macrocode}
% Switch the style depending on the language automatically?
%    \begin{macrocode}
\newif\ifnprt@autolanguage
%    \end{macrocode}
% Old or new column types?
%    \begin{macrocode}
\newif\ifnprt@newcolumntype
%    \end{macrocode}
% Declare new math type?
%    \begin{macrocode}
\newif\ifnprt@npbold
%    \end{macrocode}
% \begin{macro}{\npfourdigitsep}
% Switch separating of the fourth digit on.
%    \begin{macrocode}
\newcommand*\npfourdigitsep{\nprt@numsepfourtrue}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npfourdigitnosep}
% Switch separating of the fourth digit off.
%    \begin{macrocode}
\newcommand*\npfourdigitnosep{\nprt@numsepfourfalse}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npaddmissingzero}
% Add a missing zero before or after decimalsign.
%    \begin{macrocode}
\newcommand*\npaddmissingzero{\nprt@addmissingzerotrue}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npnoaddmissingzero}
% Don't add a missing zero before or after decimalsign.
%    \begin{macrocode}
\newcommand*\npnoaddmissingzero{\nprt@addmissingzerofalse}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npaddplus}
% Add a plus to the mantissa if no sign is given.
%    \begin{macrocode}
\newcommand*\npaddplus{\nprt@addplus@mantissatrue}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npnoaddplus}
% Don't add a plus to the mantissa if no sign is given.
%    \begin{macrocode}
\newcommand*\npnoaddplus{\nprt@addplus@mantissafalse}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npaddplusexponent}
% Add a plus to the exponent if no sign is given.
%    \begin{macrocode}
\newcommand*\npaddplusexponent{\nprt@addplus@exponenttrue}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npnoaddplusexponent}
% Don't add a plus to the exponent if no sign is given.
%    \begin{macrocode}
\newcommand*\npnoaddplusexponent{\nprt@addplus@exponentfalse}%
%    \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}{\npfourdigitnosep}
\DeclareOption{sepfour}{\npfourdigitsep}
%    \end{macrocode}
% Add missing zeros after decimal sign?
%    \begin{macrocode}
\DeclareOption{noaddmissingzero}{\npnoaddmissingzero}
\DeclareOption{addmissingzero}{\npaddmissingzero}
%    \end{macrocode}
% Add a plus sign to the mantissa if no sign is given?
%    \begin{macrocode}
\DeclareOption{noaddplus}{\npnoaddplus}
\DeclareOption{addplus}{\npaddplus}
%    \end{macrocode}
% Add a plus sign to the exponent if no sign is given?
%    \begin{macrocode}
\DeclareOption{noaddplusexponent}{\npnoaddplusexponent}
\DeclareOption{addplusexponent}{\npaddplusexponent}
%    \end{macrocode}
% Add missing zeros after decimal sign?
%    \begin{macrocode}
\DeclareOption{noautolanguage}{\nprt@autolanguagefalse}
\DeclareOption{autolanguage}{\nprt@autolanguagetrue}
%    \end{macrocode}
% \begin{macro}{\np}
% \changes{1.00}{2003/10/07}{Add shortcut for \cs{numprint}}%
% Define a shortcut for the \cs{numprint} command?
%    \begin{macrocode}
\DeclareOption{np}{\newcommand*\np{\numprint}}
%    \end{macrocode}
% \end{macro}
% Produce warnings or errors?
%    \begin{macrocode}
\DeclareOption{oldcolumntypes}{\nprt@newcolumntypefalse}
\DeclareOption{newcolumntypes}{\nprt@newcolumntypetrue}
%    \end{macrocode}
% Declare new math type?
%    \begin{macrocode}
\DeclareOption{boldmath}{\nprt@npboldtrue}
%    \end{macrocode}
% Produce warnings or errors?
%    \begin{macrocode}
\DeclareOption{warning}{\nprt@errormessagefalse}
\DeclareOption{error}{\nprt@errormessagetrue}
%    \end{macrocode}
% Generate some debug information to the log file?
%    \begin{macrocode}
\newcommand*\nprt@debug[1]{}
\DeclareOption{debug}{%
  \renewcommand*\nprt@debug[1]{\PackageInfo{numprint}{#1}}%
}
%    \end{macrocode}
% Execute default options and the given options.
%    \begin{macrocode}
\ExecuteOptions{sepfour,addmissingzero,error,noautolanguage,newcolumntypes}
\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 decimal
% sign.
% 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@separator@before{{#1}}%
  \def\nprt@separator@after{{#1}}}
%    \end{macrocode}
% \end{macro}%
% \begin{macro}{\npthousandthpartsep}
% Change the thousand separator after the decismal sign.
%    \begin{macrocode}
\newcommand*\npthousandthpartsep[1]{\def\nprt@separator@after{{#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 and unit.
% Here again the additional \verb|{}| is used as above.
%    \begin{macrocode}
\newcommand*\npunitseparator[1]{\def\nprt@unitsep{{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npdegreeseparator}
% Change the separator between number and \textdegree.
% Here again the additional \verb|{}| is used as above.
%    \begin{macrocode}
\newcommand*\npdegreeseparator[1]{\def\nprt@degreesep{{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npcelsiusseparator}
% Change the separator between number and \textcelsius.
% Here again the additional \verb|{}| is used as above.
%    \begin{macrocode}
\newcommand*\npcelsiusseparator[1]{\def\nprt@celsiussep{{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nppercentseparator}
% Change the separator between number and \%.
% Here again the additional \verb|{}| is used as above.
%    \begin{macrocode}
\newcommand*\nppercentseparator[1]{\def\nprt@percentsep{{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@fillnull}
% Defines command |#1| with a number of |#2| zeros filled.
% This should reside in Sect.~\ref{sec:code:round} but is called
% before.
%    \begin{macrocode}
\def\nprt@fillnull#1#2{%
  \@tempcnta=-1
  \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{}%
  \nprt@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{}%
  \nprt@fillnull{\nprt@roundexpnull}{#1}%
  }
\newcommand\npnoroundexp{\nproundexpdigits{-1}}
\npnoroundexp
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\nplpadding}
% This command sets the total counts of digits a number should contain.
% The missing digits are filled with the character from the second
% argument (which is 0 by default).
%    \begin{macrocode}
\newcommand\nplpadding[2][0]{%
  \def\nprt@lpaddigits{#2}%
  \def\nprt@lpadchar{#1}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npnolpadding}
% The command to switch of padding.
%    \begin{macrocode}
\newcommand*\npnolpadding{\nplpadding[\@empty]{-1}}
%    \end{macrocode}
% \end{macro}
% Don't pad by default.
%    \begin{macrocode}
\npnolpadding
%    \end{macrocode}
% \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}
% \begin{macro}{\npunitcommand}
% This command is used to typeset the unit.
%    \begin{macrocode}
\newcommand*\npunitcommand[1]{\ensuremath{\mathrm{#1}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npdigits}
% 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}
\newif\ifnprt@mantissa@fixeddigits
\newcommand*\npdigits[2]{%
  \edef\nprt@mantissa@fixeddigits@before{#1}%
  \edef\nprt@mantissa@fixeddigits@after{#2}%
  \nprt@mantissa@fixeddigitstrue
}
%    \end{macrocode}
% Initialize the numbers.
%    \begin{macrocode}
\def\nprt@mantissa@fixeddigits@before{-1}%
\def\nprt@mantissa@fixeddigits@after{-1}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npnodigits}
% Switch back to normal printing.
%    \begin{macrocode}
\newcommand*\npnodigits{\nprt@mantissa@fixeddigitsfalse}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npexponentdigits}
% 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}
\newif\ifnprt@exponent@fixeddigits
\newcommand*\npexponentdigits[2][0]{%
  \edef\nprt@exponent@fixeddigits@before{#2}%
  \edef\nprt@exponent@fixeddigits@after{#1}%
  \nprt@exponent@fixeddigitstrue
}
%    \end{macrocode}
% Initialize the numbers.
%    \begin{macrocode}
\def\nprt@exponent@fixeddigits@before{-1}%
\def\nprt@exponent@fixeddigits@after{-1}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npnoexponentdigits}
% Switch back to normal printing.
%    \begin{macrocode}
\newcommand*\npnoexponentdigits{\nprt@exponent@fixeddigitsfalse}
%    \end{macrocode}
% \end{macro}
% 
%
% \subsection{Error and warning messages}
%
% Define a boolean which helps \cs{numprint} to detect errors.
%    \begin{macrocode}
\newif\ifnprt@argumenterror
%    \end{macrocode}
% \begin{macro}{\nprt@error}
% Define \cs{nprt@error\marg{Message}\marg{Help text}} which prints
% a warning resp.\ an error message, depending on the package options
% |warning| and |error|.
%    \begin{macrocode}
\newcommand\nprt@error[2]{%
  \ifnprt@errormessage
    \PackageError{numprint}{#1}{#2}%
  \else
    \PackageWarning{numprint}{#1}%
  \fi
%    \end{macrocode}
% The boolean is set to ``true''.
% Then, \cs{numprint} knows that an error occured.
%    \begin{macrocode}
  \nprt@argumenterrortrue
}
%    \end{macrocode}
% \end{macro}
% 
%
% \subsection{String parsing}
%
% \changes{1.10}{2003/10/12}{Avoid use of \texttt{substr} package}%
% The \cs{IfCharInString} package does not work in the tabular
% alignment context.
% Thus, define an own command \cs{nprt@IfCharInString} that does the
% same.
% \begin{macro}{\nprt@charfound}
%    \begin{macrocode}
\newif\ifnprt@charfound
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@IfCharInString}
% ????
%    \begin{macrocode}
\newcommand*\nprt@IfCharInString[2]{%
  \nprt@charfoundfalse
  \begingroup
    \def\nprt@searchfor{#1}%
    \edef\nprt@argtwo{#2}%
    \expandafter\nprt@@IfCharInString\nprt@argtwo\@empty\@empty
  \endgroup
  \ifnprt@charfound
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@@IfCharInString}
% ????
%    \begin{macrocode}
  \def\nprt@@IfCharInString#1#2\@empty{%
    \def\nprt@argone{#1}%
    \edef\nprt@argtwo{#2}%
    \ifx\nprt@searchfor\nprt@argone
      \global\nprt@charfoundtrue
    \else
      \ifx\nprt@argtwo\@empty
      \else
        \nprt@@IfCharInString#2\@empty
      \fi
    \fi
  }
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Parsing of the \textmd{\cs{numprint}} argument}
%
% \begin{macro}{\nprt@plus@test}
% \begin{macro}{\nprt@minus@test}
% \begin{macro}{\nprt@plusminus@test}
% Define the signs as commands. This is necessary to be able to
% compare them with other characters. 
%    \begin{macrocode}
\newcommand*\nprt@plus@test{+}
\newcommand*\nprt@minus@test{-}
\newcommand*\nprt@plusminus@test{\pm}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\nprt@numberlist}
% \begin{macro}{\nprt@dotlist}
% \begin{macro}{\nprt@epxlist}
% \begin{macro}{\nprt@signlist}
% Define lists of valid characters for different elements of numbers
% for parsing the mandatory argument of the \cs{numprint} command.
% It has nothing to do with the output.
% \cs{nprt@numberlist} contains digits, \cs{nprt@dotlist} valid
% decimal signs, \cs{nprt@explist} the characters that start the
% exponent, and \cs{nprt@signlist} the valid signs, where
% ``\texttt{+-}'' as alias for ``\cs{pm}'' does not have to be
% specified seperately.
%    \begin{macrocode}
\newcommand*\nprt@numberlist{0123456789}
\newcommand*\nprt@dotlist{.,}
\newcommand*\nprt@explist{eEdD}
\newcommand*\nprt@signlist{+-\pm}
\newcommand*\nprt@ignorelist{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% Counters for the number of digits before and after the decimal sign
% of the mantissa.
%    \begin{macrocode}
\newcounter{nprt@mantissa@digitsbefore}%
\newcounter{nprt@mantissa@digitsafter}%
%    \end{macrocode}
% Counters for the number of digits before and after the decimal sign
% of the exponent.
%    \begin{macrocode}
\newcounter{nprt@exponent@digitsbefore}%
\newcounter{nprt@exponent@digitsafter}%
%    \end{macrocode}
% Boolean to store if an exponent will be printed.
%    \begin{macrocode}
\newif\ifnprt@expfound
%    \end{macrocode}
% Boolean to store if mantissa resp.\ exponent contain a decimal
% sign.
%    \begin{macrocode}
\newif\ifnprt@mantissa@decimalfound
\newif\ifnprt@exponent@decimalfound
%    \end{macrocode}
% \begin{macro}{\nprt@testsign}
% Define \cs{nprt@testsign\marg{Number type}\marg{Number}} which tests
% whether a sign is given and then starts \cs{nprt@testnumber} (the
% call actually is done by \cs{nprt@@testsign}).
%    \begin{macrocode}
\newcommand*\nprt@testsign[2]{%
%    \end{macrocode}
% First, store the expanded arguments in macros.
%    \begin{macrocode}
  \edef\nprt@commandname{#1}%
  \edef\nprt@tmp{#2}%
%    \end{macrocode}
% Call the working command \cs{nprt@@testsign}.
% The large number of \cs{expandafter} calls is necessary to ensure
% that the second to fourth argument are already expanded (thus, |#2|
% and |#3| are single characters).
% Append enough \cs{@empty} to ensure the argument-end marker is found
% even for an empty number.
%    \begin{macrocode}
  \expandafter\nprt@@testsign\expandafter{%
    \expandafter\nprt@commandname\expandafter}%
    \nprt@tmp\@empty\@empty\@empty\@empty
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@@testsign}
% The first argument is the Number type (``mantissa'' or
% ``exponent''). 
% Because it is longer than one character, it has to be enclosed in
% braces when calling this function (see the previous code line).
% The arguments |#2| to |#4| are the given number, where |#2| and |#3|
% contain of the first resp.\ second character of the number, while
% |#4| contains the rest.
%    \begin{macrocode}
\def\nprt@@testsign#1#2#3#4\@empty{%
%    \end{macrocode}
% Store the first argument to a macro.
%    \begin{macrocode}
  \edef\nprt@commandname{#1}%
%    \end{macrocode}
% Define the macros that store the digits before respectivly after the
% decimal sign.
% They are filled digit by digit and start empty.
%    \begin{macrocode}
  \expandafter\xdef\csname nprt@#1@before\endcsname{\@empty}%
  \expandafter\xdef\csname nprt@#1@after\endcsname{\@empty}%
%    \end{macrocode}
% Yet, no digits are stored.
%    \begin{macrocode}
  \setcounter{nprt@#1@digitsbefore}{0}%
  \setcounter{nprt@#1@digitsafter}{0}%
%    \end{macrocode}
% Test whether the first character of the number, |#2|, contains a
% sign symbol which is listed in \cs{nprt@signlist}.
%    \begin{macrocode}
  \nprt@IfCharInString{#2}{\nprt@signlist}{%
%    \end{macrocode}
% If yes, store that sign in the command
% \cs{nprt@\meta{\#2}@sign}.
%    \begin{macrocode}
    \expandafter\xdef\csname nprt@#1@sign\endcsname{#2}%
%    \end{macrocode}
% If the sign is a ``+'' the second character of the number may be a
% ``-'' to replace that combination by \cs{pm}.
% Thus, do an extra handling of that case.
%    \begin{macrocode}
    \expandafter\ifx\csname nprt@#1@sign\endcsname\nprt@plus@test
      \def\nprt@tmp{#3}%
      \ifx\nprt@tmp\nprt@minus@test
%    \end{macrocode}
% The second character, |#3|, \emph{is} a ``-'', thus redefine
% \cs{nprt@\meta{\#2}@sign} to \cs{pm}.
%    \begin{macrocode}
        \expandafter\xdef\csname nprt@#1@sign\endcsname{+-}%
%    \end{macrocode}
% The digits start at the third character of the number string which
% is |#4|.
% Start \cs{nprt@testnumber} to parse the digits of the number if a
% number is given after the given sign ``+-''.
% If not, empty \cs{nprt@\meta{\#1}} that \cs{numprint} can determine
% that only a sign has been given.
%    \begin{macrocode}
        \def\nprt@tmp{#4}%
        \ifx\nprt@tmp\@empty
          \expandafter\edef\csname nprt@#1\endcsname{\@empty}%
        \else
          \expandafter\nprt@testnumber\expandafter\nprt@commandname#4\@empty
        \fi
      \else
%    \end{macrocode}
% If there is a single sign character ``+'', the digits start at |#3|.
% Start \cs{nprt@testnumber} to parse the digits of the number if a
% number is given after the given sign ``+''.
% If not, empty \cs{nprt@\meta{\#1}} that \cs{numprint} can determine
% that only a sign has been given.
%    \begin{macrocode}
        \ifx#3\@empty
          \expandafter\edef\csname nprt@#1\endcsname{\@empty}%
        \else
          \expandafter\nprt@testnumber\expandafter\nprt@commandname#3#4\@empty
        \fi
      \fi
    \else
%    \end{macrocode}
% If the sign is a ``\cs{pm}'' store ``\texttt{+-} as sign.
%    \begin{macrocode}
      \expandafter\ifx\csname nprt@#1@sign\endcsname\nprt@plusminus@test
        \expandafter\xdef\csname nprt@#1@sign\endcsname{+-}%
      \fi
%    \end{macrocode}
% If there is a single sign character other than ``+'', the digits
% start at |#3|.
% Start \cs{nprt@testnumber} to parse the digits of the number if a
% number is given after the given sign.
% If not, empty \cs{nprt@\meta{\#1}} that \cs{numprint} can determine
% that only a sign has been given.
%    \begin{macrocode}
      \ifx#3\@empty
        \expandafter\edef\csname nprt@#1\endcsname{\@empty}%
      \else
        \expandafter\nprt@testnumber\expandafter\nprt@commandname#3#4\@empty
      \fi
    \fi
  }{%
%    \end{macrocode}
% If there is no sign, set \cs{nprt@\meta{\#2}@sign} empty.
%    \begin{macrocode}
    \expandafter\xdef\csname nprt@#1@sign\endcsname{\@empty}%
%    \end{macrocode}
% The digits start at |#2|.
% Start \cs{nprt@testnumber} to parse the digits of the number.
%    \begin{macrocode}
    \expandafter\nprt@testnumber\expandafter\nprt@commandname#2#3#4\@empty
  }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@testnumber}
% As with \cs{nprt@@testsign}, the first argument is the Number type,
% while the second and third arguments contain the number.
% |#2| contains the first character of the remaining number string,
% |#3| the rest.
%    \begin{macrocode}
\def\nprt@testnumber#1#2#3\@empty{%
%    \end{macrocode}
% Store the arguments in macros.
%    \begin{macrocode}
  \edef\nprt@commandname{#1}%
  \edef\nprt@argthree{#3}%
%    \end{macrocode}
% Test whether the current character is a valid character for a real
% number (say a digit or a decimal sign).
%    \begin{macrocode}
  \nprt@IfCharInString{#2}{\nprt@numberlist\nprt@dotlist}{%
%    \end{macrocode}
% If this is the case, continue testing.
% If the current character is a decimal sign, set the boolean
% \cs{ifnprt@\meta{Number type}@decimalfound} that a decimal
% sign has been found.
% If this has been done before, the number contains two decimal signs
% which is not allowed, thus, generate an error message.
%    \begin{macrocode}
    \nprt@IfCharInString{#2}{\nprt@dotlist}{%
      \csname ifnprt@#1@decimalfound\endcsname
        \nprt@error{More than one decimal sign used}{The mantissa
          or the exponent may only contain a maximum of one decimal
          sign (one of the list `\nprt@dotlist')}%
      \else
        \csname nprt@#1@decimalfoundtrue\endcsname
      \fi
    }{%
%    \end{macrocode}
% If the current character is no decimal sign it has to be a digit.
% If the decimal sign has been found before, this digit is in the real
% part of the number.
% Then, add it at the end of the after-decimal-sign part.
% Also, increase the number of found digits.
%    \begin{macrocode}
      \csname ifnprt@#1@decimalfound\endcsname
        \expandafter\g@addto@macro\csname nprt@#1@after\endcsname{#2}%
        \advance\csname c@nprt@#1@digitsafter\endcsname by 1\relax
      \else
%    \end{macrocode}
% If the decimal sign has not been found before, this digit is in the
% integer part of the number.
% Then, add it at the end of the before-decimal-sign part.
%    \begin{macrocode}
        \expandafter\g@addto@macro\csname nprt@#1@before\endcsname{#2}%
        \advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
      \fi
    }%
%    \end{macrocode}
% If the next character is not \cs{@empty} and thus, the end of the
% number is not reached, start \cs{nprt@testnumber} resursively to
% parse the next character.
%    \begin{macrocode}
    \ifx\nprt@argthree\@empty
    \else
      \expandafter\nprt@testnumber\expandafter\nprt@commandname#3\@empty
    \fi
  }{%
%    \end{macrocode}
% The current character is neither a digit nor a decimal sign.
% Thus, it is a invalid character; produce an error message.
%    \begin{macrocode}
    \nprt@error{Invalid number format. Printing the
      argument\MessageBreak
      verbatim}{Something is wrong in the format of the number}%
  }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@testcharacter}
% This macro parses the whole mandatory argument of \cs{numprint}.
% This means it is tested on invalid characters and on a mantissa and
% an exponent.
% The first argument is the current character while |#2| is the rest
% of the argument, not parsed yet.
%    \begin{macrocode}
\def\nprt@testcharacter#1#2\@empty{%
%    \end{macrocode}
% Store the second argument to a macro.
%    \begin{macrocode}
  \edef\nprt@argtwo{#2}%
%    \end{macrocode}
% Test whether the current character is a valid one.
%    \begin{macrocode}
  \nprt@IfCharInString{#1}{%
    \nprt@numberlist\nprt@dotlist\nprt@explist\nprt@signlist\nprt@ignorelist}{%
%    \end{macrocode}
% Yes, it is valid.
%
% Now, test whether it is one of the ignored characters.
%    \begin{macrocode}
    \nprt@IfCharInString{#1}{\nprt@ignorelist}{%
      \nprt@debug{Character `\noexpand#1' ignored}%
  }{%
%    \end{macrocode}
% Yes, it is valid.
%
% Now, test whether it is one of the characters that start the
% exponent.
% If yes, set \cs{ifnprt@expfound} to ``true''.
% If in addition, this has been done before, you have used more than
% one exponent starting character; produce an error message.
%    \begin{macrocode}
      \nprt@IfCharInString{#1}{\nprt@explist}{%
        \ifnprt@expfound
          \nprt@error{Character for exponent (`\nprt@explist') used
            more than once}{The argument of \string\numprint\space may
            only contain one of following characters: `\nprt@explist'}% 
        \fi
        \nprt@expfoundtrue
      }{%
%    \end{macrocode}
% If the current character is not an exponent-starting character it
% is either a part of the mantissa or the exponent, depending on
% whether the exponent has been started before.
% Add the current character to the corresponding command that stores
% the mantissa resp.\ the exponent.
%    \begin{macrocode}
        \ifnprt@expfound
          \g@addto@macro\nprt@exponent{#1}%
        \else
          \g@addto@macro\nprt@mantissa{#1}%
        \fi
      }%
    }%
%    \end{macrocode}
% If we have not reached the end of the argument, call
% \cs{nprt@testcharacter} recursively.
%    \begin{macrocode}
    \ifx\nprt@argtwo\@empty
    \else
      \nprt@testcharacter#2\@empty\@empty\@empty
    \fi
  }{%
%    \end{macrocode}
% If the character is not valid produce an error message.
%    \begin{macrocode}
    \nprt@error{Invalid characters `#1' in mandatory argument
      of\MessageBreak
      \string\numprint. Allowed are\MessageBreak
      `\nprt@numberlist\nprt@dotlist\nprt@explist\nprt@signlist\nprt@ignorelist'}{%
      You may only use the specified characters in the argument.}%
  }%
}
%    \end{macrocode}
% \end{macro}
% 
%
% \subsection{Table alignment}
%
% \subsubsection{Aligned numbers, also for ordinary text}
%
% Define some lengths that help to calculate the width of a number.
%    \begin{macrocode}
\newlength{\nprt@digitwidth}%
\newlength{\nprt@sepwidth}%
\newlength{\nprt@decimalwidth}%
\newlength{\nprt@blockwidth}%
%    \end{macrocode}
% \begin{macro}{\nprt@calcblockwidth}
% Define \cs{nprt@calcblockwidth\marg{Number
% type}\marg{Position}\marg{Math mode}}, where
% \meta{Number type} is either ``mantissa'' or ``exponent'',
% \meta{Position} is the position relative to the decimal sign
% (``before'' or ``after''), \meta{Math mode} is a math mode command
% (\cs{displaystyle}, \cs{textstyle}, \cs{scriptstyle}, or
% \cs{scriptscriptstyle}).
%
% This macro calculates the width of a block if aligned output is
% requested.
% The resulted width is stored in the length \cs{nprt@blockwidth}.
%    \begin{macrocode}
\newcommand*\nprt@calcblockwidth[3]{%
%    \end{macrocode}
% Store the arguments in macros.
%    \begin{macrocode}
  \edef\nprt@argone{#1}%
  \edef\nprt@argtwo{#2}%
  \edef\nprt@argthree{#3}%
%    \end{macrocode}
% Define a macro with the contents ``mantissa'' to be able to compare
% it.
%    \begin{macrocode}
  \edef\nprt@mantissaname{mantissa}%
%    \end{macrocode}
% Define a macro with the contents ``after'' to be able to compare
% it.
%    \begin{macrocode}
  \edef\nprt@aftername{after}%
%    \end{macrocode}
% If the width for the mantissa is to be calculated, enter this code
% part.
%    \begin{macrocode}
  \ifx\nprt@argone\nprt@mantissaname
%    \end{macrocode}
% The width of the digits and separators changes between text and
% math mode.
% If math mode is active, proceed here.
%    \begin{macrocode}
    \ifmmode
%    \end{macrocode}
% Calculate the width of digits.
% It is assumed that all digits have the same width as a zero.
% First, execute parameter \verb|#3| to switch to the current math
% style.
% This is be done that way since it is not possible to export length
% values from \cs{mathchoice}.
%    \begin{macrocode}
      \settowidth{\nprt@digitwidth}{$#3%
        0$}%
%    \end{macrocode}
% Calculate the width of the separators.
% This may differ from before and after the decimal sign.
%    \begin{macrocode}
      \settowidth{\nprt@sepwidth}{$#3%
        \csname nprt@separator@#2\endcsname$}%
%    \end{macrocode}
% Calculate the width of the decimal sign.
%    \begin{macrocode}
      \settowidth{\nprt@decimalwidth}{$#3%
        \nprt@decimal$}%
    \else
%    \end{macrocode}
% Do the same for text mode.
%    \begin{macrocode}
      \settowidth{\nprt@digitwidth}{0}%
      \settowidth{\nprt@sepwidth}{\csname nprt@separator@#2\endcsname}%
      \settowidth{\nprt@decimalwidth}{\nprt@decimal}%
    \fi
%    \end{macrocode}
% The same for the exponent.
%    \begin{macrocode}
  \else
    \ifmmode
      \settowidth{\nprt@digitwidth}{$#3%
        {}^{0}$}%
      \settowidth{\nprt@sepwidth}{$#3%
        {}^{\csname nprt@separator@#2\endcsname}$}%
      \settowidth{\nprt@decimalwidth}{$#3%
        {}^{\nprt@decimal}$}%
    \else
      \settowidth{\nprt@digitwidth}{\textsuperscript{0}}%
      \settowidth{\nprt@sepwidth}{%
        \textsuperscript{\csname nprt@separator@#2\endcsname}}%
      \settowidth{\nprt@decimalwidth}{\textsuperscript{\nprt@decimal}}%
    \fi
  \fi
%    \end{macrocode}
% Output to the log file.
%    \begin{macrocode}
  \nprt@debug{Widths for #1 #2 decimal sign
    (\ifx\nprt@argthree\@empty text mode\else math mode #3\fi):\MessageBreak
    digits \the\nprt@digitwidth, 
    separators \the\nprt@sepwidth,\MessageBreak
    decimal sign \the\nprt@decimalwidth}%
%    \end{macrocode}
% Produce a warning if the current number exceeds the reserved space.
% Signs ($+-\pm$) are not taken into account.
%    \begin{macrocode}
  \ifnum\csname nprt@#1@fixeddigits@#2\endcsname<%
    \csname thenprt@#1@digits#2\endcsname
    \PackageWarning{numprint}{#1 exceeds reserved space
      #2\MessageBreak
      decimal sign}%
  \fi
%    \end{macrocode}
% \changes{1.34}{2004/12/13}{Fix a bug invoked in version~1.33. Found
%   by Stefan Salewski}%
% Calculate the width of the given number of digits without
% separators.
%    \begin{macrocode}
  \setlength{\nprt@blockwidth}{%
    \csname nprt@#1@fixeddigits@#2\endcsname\nprt@digitwidth}%
%    \end{macrocode}
% Calculate how many separators are put into the number.
%    \begin{macrocode}
  \setcounter{nprt@blockcnt}{\csname nprt@#1@fixeddigits@#2\endcsname}%
  \advance\c@nprt@blockcnt by -1\relax
  \divide\c@nprt@blockcnt 3%
%    \end{macrocode}
% If four-digit length numbers are not separated, delete the number of
% separators again.
%    \begin{macrocode}
  \ifnprt@numsepfour
  \else
    \ifnum\csname nprt@#1@fixeddigits@before\endcsname<5
      \ifnum\csname nprt@#1@fixeddigits@after\endcsname<5
        \setcounter{nprt@blockcnt}{0}%
      \fi
    \fi
  \fi
%    \end{macrocode}
% Add the width of the separators to the width.
%    \begin{macrocode}
  \addtolength{\nprt@blockwidth}{\thenprt@blockcnt\nprt@sepwidth}%
%    \end{macrocode}
% Add the width of the decimal sign to the width if it is after the
% decimal sign and there shall be digits after the decimal sign.
%    \begin{macrocode}
  \ifx\nprt@argtwo\nprt@aftername
    \expandafter\ifnum\csname nprt@#1@fixeddigits@after\endcsname>0
      \addtolength{\nprt@blockwidth}{\the\nprt@decimalwidth}%
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\npunit}
% The \cs{npunit} command takes as argument a unit that is printed in
% every cell of a table when using the (new) |n| or |N| column types.
%    \begin{macrocode}
\newcommand*\npunit[1]{\def\nprt@unit{#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npnounit}
% Initialize \cs{nprt@unit}.
%    \begin{macrocode}
\edef\nprt@unit{\@empty}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\npafternum}
% The \cs{npunit} command takes as argument some text that is printed
% after the number in every cell of a table when using the (new) |n|
% or |N| column types.
%    \begin{macrocode}
\newcommand*\npafternum[1]{\def\nprt@afternum{#1}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@afternum}
% Initialize \cs{nprt@afternum}.
%    \begin{macrocode}
\edef\nprt@afternum{\@empty}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npmakebox}
% \changes{1.10}{2003/10/12}{Declare \cs{npmakebox} command}%
% The \cs{npmakebox} is similar to the \cs{makebox} command but it
% takes a text as first optional argument instead of a length.
% The width of the box is calculated by the width of this text.
%    \begin{macrocode}
\DeclareRobustCommand*\npmakebox{%
  \@ifnextchar[% ]
  {\nprt@makebox}{\makebox}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@makebox}
% The internal part of the \cs{npmakebox} command.
%    \begin{macrocode}
\newcommand*\nprt@makebox{}
\def\nprt@makebox[#1]{%
  \settowidth\@tempdima{#1}%
  \makebox[\@tempdima]%
}
%    \end{macrocode}
% \end{macro}
%
% \changes{1.10}{2003/10/12}{Define math version \texttt{npbold}}%
% Declare a bold math alphabet |npbold| that aligns with normal
% digits.
%    \begin{macrocode}
\ifnprt@npbold
  \DeclareMathVersion{npbold}
  \SetSymbolFont{operators}{npbold}{OT1}{cmr} {b}{n}
  \SetSymbolFont{letters}  {npbold}{OML}{cmm} {b}{it}
  \SetSymbolFont{symbols}  {npbold}{OMS}{cmsy}{b}{n}
  \SetMathAlphabet\mathsf{npbold}{OT1}{cmss}{b}{n}
  \SetMathAlphabet\mathit{npbold}{OT1}{cmr}{b}{it}
%    \end{macrocode}
% \begin{macro}{\npboldmath}
% Switch to that bold math alphabet.
%    \begin{macrocode}
  \def\npboldmath{\@nomath\npboldmath
                \mathversion{npbold}}
\fi
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{Auxilliary routines for the new column types}
%
% This code has been developed starting from the \texttt{rccol}
% package by Eckhart Guth\"ohrlein~\cite{guthoehrlein2000a}.
% Some small bugs of that package have been corrected here, too.
%
% \begin{macro}{\nprt@digittoks}
% Token list that will contain all characters of a tabular cell that
% are allowed for \cs{numprint}.
%    \begin{macrocode}
\newtoks\nprt@digittoks
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@pretoks}
% Token list with all tokens before the number itself.
%    \begin{macrocode}
\newtoks\nprt@pretoks
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@posttoks}
% Token list with all tokens after the number itself.
%    \begin{macrocode}
\newtoks\nprt@posttoks
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ifnprt@numfound}
% Has the number already been found in the parsing of the tabular
% cell?
%    \begin{macrocode}
\newif\ifnprt@numfound
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@begin}
% This macro is executed at the begin of each tabular cell.
%    \begin{macrocode}
\def\nprt@begin{%
%    \end{macrocode}
% Initialize the tokens and macros.
%    \begin{macrocode}
  \nprt@digittoks={}%
  \nprt@pretoks={}%
  \nprt@posttoks={}%
  \edef\nprt@unit{\@empty}%
  \edef\nprt@afternum{\@empty}%
  \nprt@numfoundfalse
%    \end{macrocode}
% Set the allowed characters.
% This macro is made empty when the number itself is read-in totally.
%    \begin{macrocode}
  \edef\nprt@allowedchars{\nprt@numberlist\nprt@dotlist\nprt@explist
    \nprt@signlist\nprt@ignorelist}%
%    \end{macrocode}
% Start to parse the tabular cell.
%    \begin{macrocode}
  \nprt@getnexttok
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@saveothertok}
% Adds the current token to the list of tokens before or after the
% number.
%    \begin{macrocode}
\def\nprt@saveothertok#1{%
  \ifnprt@numfound
%    \end{macrocode}
% If the number has already been found it is ended now.
% This is marked by clearing the list of allowed characters.
%    \begin{macrocode}
    \def\nprt@allowedchars{}%
    \nprt@posttoks=\expandafter{\the\nprt@posttoks#1}%
  \else
    \nprt@pretoks=\expandafter{\the\nprt@pretoks#1}%
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@getnexttok}
% \changes{1.31}{2004/08/18}{Bugfix: The numprint column types did not
%   like empty cells in the last column of a tabular}%
% Parse the tabular cell.
% The argument is the next token of the tabular cell.
% Inside this command, the end of the tabular cell is detected by
% different possibilities to end a cell.
%    \begin{macrocode}
\def\nprt@getnexttok#1{%
%    \end{macrocode}
% If the current token is \cs{tabularnewline} or |\\|
% (which is the same) the tabular cell is finished.
%    \begin{macrocode}
  \ifx\tabularnewline#1%
%    \end{macrocode}
% Redefine the \cs{nprt@next} command that is called at the end of
% this command to execute the found \cs{tabularnewline} command.
%    \begin{macrocode}
    \let\nprt@next\tabularnewline
  \else
%    \end{macrocode}
% If this tabular cell is not in the last column and a |&| is found,
% the \cs{nprt@end} command is found that is inserted into this cell
% using the |<| specifier by the columnn types.
%    \begin{macrocode}
    \ifx\end#1%
%    \end{macrocode}
% Redefine \cs{nprt@next} to execute \cs{nprt@end} at the end of this
% command.
%    \begin{macrocode}
      \let\nprt@next\end
    \else
%    \end{macrocode}
% If this is the last cell of the tabular, the \cs{end} part of
% \cs{end\{tabular\}} or \cs{end\{tabular*\}} is found.
%    \begin{macrocode}
      \ifx\nprt@end#1%
%    \end{macrocode}
% Test whether it is the normal or the star version of the
% environment.
% Is this really necessary?
%    \begin{macrocode}
        \let\nprt@next\nprt@end
      \else
%    \end{macrocode}
% If this is the last cell of the tabular and the tabular has been
% called using \cs{tabular} \ldots\ \cs{endtabular} instead of using
% the environment call, \cs{endtabular} is found.
%    \begin{macrocode}
        \ifx\endtabular#1%
          \let\nprt@next\endtabular
        \else
%    \end{macrocode}
% For |tabularx|, a test on \cs{csname} has to be added.
%    \begin{macrocode}
          \ifx\csname#1%
            \let\nprt@next\csname
          \else
%    \end{macrocode}
% If the last cell of a line is empty, \cs{relax} will be found.
%    \begin{macrocode}
            \ifx\relax#1%
              \let\nprt@next\relax
            \else
%    \end{macrocode}
% If no command is found that ends the tabular cell, we are not yet at
% the end of the cell.
% Redefine \cs{nprt@next} to start this command recursively for
% parsing the next token.
%    \begin{macrocode}
              \let\nprt@next\nprt@getnexttok
%    \end{macrocode}
% Test if this token is one of the allowed characters of a number.
%    \begin{macrocode}
              \nprt@IfCharInString{#1}{\nprt@allowedchars}{%
%    \end{macrocode}
% If yes, append this character to the token list of the number and
% set the flag that the number has been found.
%    \begin{macrocode}
                \nprt@numfoundtrue
                \nprt@digittoks=\expandafter{\the\nprt@digittoks#1}%
              }{%
%    \end{macrocode}
% If it is no character of a number, store it for the tokens before or
% after the number.
%    \begin{macrocode}
                \nprt@saveothertok{#1}%
              }%
            \fi % \relax
          \fi % \csname
        \fi % \endtabular
      \fi % \nprt@end
    \fi % \end
  \fi % \tabularnewline
%    \end{macrocode}
% Call the previously saved command (recursion or end of the tabular
% cell).
%    \begin{macrocode}
  \nprt@next
}
%    \end{macrocode}
% Boolean to decide if math mode is active outside the tabular cell.
% This is true for the |array| environment.
%    \begin{macrocode}
\newif\ifnprt@mathtabular
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@end}
% This macro is called at the end of each tabular cell.
% The arguments are used as follows: \meta{digits before},
% \meta{digits after} the decimal sign for the mantissa;
% \meta{digits before}, \meta{digits after} the decimal sign for the
% exponent; commands inserted \meta{before} and \meta{after} the
% \cs{numprint} command.
% The arguments five and six are empty for printing the number in text
% mode and contain ``|$|'' both for printing the number in math mode.
%    \begin{macrocode}
\def\nprt@end#1#2#3#4#5#6{%
%    \end{macrocode}
% First, print the tokens before the number.
%    \begin{macrocode}
  \the\nprt@pretoks
%    \end{macrocode}
% Print the number in a group in order to save the tokens before and
% after the number to be influenced by its settings.
%    \begin{macrocode}
  \begingroup
%    \end{macrocode}
% Set the digits for the alignment of the mantissa.
%    \begin{macrocode}
%    \npnodigits
    \npdigits{#1}{#2}%
%    \end{macrocode}
% Set the digits for the alignment of the exponent if given.
% If no number of digits is given, they are set negativ.
%    \begin{macrocode}
    \npnoexponentdigits
    \ifnum#3<0
      \nprt@debug{no exponent alignment in tabular}%
    \else
      \ifnum#4<0
        \nprt@debug{exponent alignment in tabular with #3 digits}%
        \npexponentdigits{#3}%
      \else
        \nprt@debug{exponent alignment in tabular with #3.#4 digits}%
        \npexponentdigits[#4]{#3}%
      \fi
    \fi
%    \end{macrocode}
% Omit the section that prints the number if no number has been
% given.
%    \begin{macrocode}
    \ifnprt@numfound
%    \end{macrocode}
% Print the pre-command if defined.
% Since the pre-command is fixed to nothing or ``|$|'' to switch to
% math mode, this is only done if the math mode is not active,
% before.
% Set the boolean \cs{ifnprt@mathtabular} according to the previous
% status in order to close the math mode if necessary.
%    \begin{macrocode}
      \ifmmode
        \nprt@mathtabulartrue
      \else
        \nprt@mathtabularfalse
        #5%
      \fi
%    \end{macrocode}
% Print the number, with unit if one has been given.
%    \begin{macrocode}
      \ifx\nprt@unit\@empty
        \numprint{\the\nprt@digittoks}%
      \else
        \numprint[\nprt@unit]{\the\nprt@digittoks}%
      \fi
%    \end{macrocode}
% Switch off math mode if it has not been active before.
%    \begin{macrocode}
      \ifnprt@mathtabular
      \else
        #6%
      \fi
%    \end{macrocode}
% Print a message to the log file if no number has been specified.
%    \begin{macrocode}
    \else
      \PackageInfo{numprint}{No number in tabular cell}%
    \fi
%    \end{macrocode}
% Do the rest outside the group in order to prevent the post-texts
% from being formatted as the number.
%    \begin{macrocode}
  \endgroup
%    \end{macrocode}
% Print the tokens after the number.
%    \begin{macrocode}
  \the\nprt@posttoks
%    \end{macrocode}
% Print the contents defined with \cs{npafternum}.
%    \begin{macrocode}
  \ifx\nprt@afternum\@empty
  \else
    \nprt@afternum
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{New column types}
% \changes{1.10}{2003/10/12}{New tabular alignment mechanism}%
%
% Define the new column types.
%    \begin{macrocode}
\ifnprt@newcolumntype
%    \end{macrocode}
%
% Declare a new column type |N| which prints a number in text mode and
% does not need to repeat \cs{numprint} in each tabular cell.
% This is declared empty because all executing macros are redefined
% anyway.
%    \begin{macrocode}
  \newcolumntype{N}{}
%    \end{macrocode}
% \begin{macro}{\NC@rewrite@N}
% Redefine this command to parse the declaration of the |N| column
% type to look for an optional argument.
% If none is given, set both optional arguments to ``|-1|''.
%    \begin{macrocode}
  \def\NC@rewrite@N{%
    \nprt@digittoks{}%
    \nprt@pretoks{}%
%    \end{macrocode}
% If no optional argument is given, set both optional arguments to
% ``|-1|''.
%    \begin{macrocode}
    \@ifnextchar[{% ]
      \nprt@rewrite@{}{}%
    }{%
      \nprt@rewrite@@{}{}{-1}[-1]%
    }%
  }
%    \end{macrocode}
%    \end{macro}
% Declare a new column type |n| which prints a number and does not
% need to repeat \cs{numprint} in each tabular cell.
% This is declared empty because all executing macros are redefined
% anyway.
%    \begin{macrocode}
  \newcolumntype{n}{}
%    \end{macrocode}
% \begin{macro}{\NC@rewrite@n}
% Same as \cs{NC@rewrite@N}, but give ``|$|'' twice for math mode.
%    \begin{macrocode}
  \def\NC@rewrite@n{%
    \nprt@digittoks{}%
    \nprt@pretoks{}%
    \@ifnextchar[{% ]
      \nprt@rewrite@{$}{$}%
    }{%
      \nprt@rewrite@@{$}{$}{-1}[-1]%
    }%
  }
%    \end{macrocode}
%    \end{macro}
% \begin{macro}{\nprt@rewrite@}
% Look for the second optional argument.
%    \begin{macrocode}
  \def\nprt@rewrite@#1#2[#3]{%
    \@ifnextchar[{%]
      \nprt@rewrite@@{#1}{#2}{#3}%
    }{%
      \nprt@rewrite@@{#1}{#2}{#3}[-1]%
    }%
  }
%    \end{macrocode}
%    \end{macro}
% \begin{macro}{\nprt@rewrite@@}
% The arguments are used as follows: 
% commands inserted \meta{before} and \meta{after} the
% \cs{numprint} command; \meta{digits before}, \meta{digits after} the
% decimal sign for the mantissa; \meta{digits before}, \meta{digits
% after} the decimal sign for the exponent.
%    \begin{macrocode}
  \def\nprt@rewrite@@#1#2#3[#4]#5#6{%
%    \end{macrocode}
% Add the definition for the current column to the already made column
% definitions that are stored in \cs{@temptokena}.
% Before the column itself, the starting command for the parsing,
% \cs{nprt@begin}, is inserted.
% At the end of the column, start the final work, command
% \cs{nprt@end}.
% These commands shall not be expanded, yet.
%    \begin{macrocode}
    \edef\nprt@rewrite@scratch{\the\@temptokena
      >{\noexpand\nprt@begin\noexpand\ignorespaces}l%
      <{\noexpand\nprt@end{#5}{#6}{#3}{#4}{#1}{#2}}%
    }%
%    \end{macrocode}
% Set \cs{@temptokena} to the preceding and the current column
% definition.
% This is implicitely used by the |array| package.
%    \begin{macrocode}
    \@temptokena\expandafter{\nprt@rewrite@scratch}%
%    \end{macrocode}
% Parse for next column in the definition.
%    \begin{macrocode}
    \NC@find
  }
%    \end{macrocode}
%    \end{macro}
%
%
% \subsubsection{Old column types for compatibility}
%
% Define the old column types.
%    \begin{macrocode}
\else
%    \end{macrocode}
% The column type \verb|n| aligns the base number but not the exponent.
%    \begin{macrocode}
  \newcolumntype{n}[2]{>{\npdigits{#1}{#2}$}l<{$}}
%    \end{macrocode}
% The column type \verb|N| aligns the base number as well as the exponent.
%    \begin{macrocode}
  \newcolumntype{N}[3]{%
    >{\npdigits{#1}{#2}\npexponentdigits{#3}$}l<{$}%
  }
%    \end{macrocode}
% End of column type section.
%    \begin{macrocode}
\fi
%    \end{macrocode}
%
%
% \subsection{Round numbers}%
% \label{sec:code:round}%
%
% Stores if the currenct digit has to be rounded up.
%    \begin{macrocode}
\newif\ifnprt@roundup
%    \end{macrocode}
% Declare the counter used inside \cs{nprt@round@after} and
% \cs{nprt@round@before}.
%    \begin{macrocode}
\newcount\nprt@thisdigit
%    \end{macrocode}
% \begin{macro}{\nprt@round@after}
% Does the rounding of the number after the decimal sign.
% The first argument contains the current digit, the second the rest
% of the number.
%
% This routine is a little bit complicated.
% It is called recursively. 
% In the forward rund, it just counts the number of digits, it has
% parsed already.
% In the backward rund the rounding is done.
%    \begin{macrocode}
\def\nprt@round@after#1#2\@empty{%
%    \end{macrocode}
% Store the arguments in macros.
%    \begin{macrocode}
  \edef\nprt@argone{#1}%
  \edef\nprt@argtwo{#2}%
%    \end{macrocode}
% Count the parsed digits.
%    \begin{macrocode}
  \advance \nprt@curpos by 1
%    \end{macrocode}
% If the end of the number is reached an internal error has been
% occured since enough zeros are appended to the number before.
%    \begin{macrocode}
  \ifx\nprt@argone\@empty
    \nprt@error{Rounding: End of number has been reached}{This may
      not happen}%
  \else
%    \end{macrocode}
% If the current digit is one behind the last digit to be printed it
% decides if the last printed digit is rounded or not.
% This decision is stored in \cs{ifnprt@roundup}.
% If this position is reached, stop the recursion.
%    \begin{macrocode}
    \ifnum\nprt@curpos>\nprt@rndpos
      \ifnum\nprt@argone>4
        \nprt@rounduptrue
      \fi
    \else
%    \end{macrocode}
% The position has not been reached, yet.
% Thus, call this routine recursively.
%    \begin{macrocode}
      \expandafter\nprt@round@after#2\@empty\@empty
%    \end{macrocode}
% The following lines are executed in the backward run when rounding.
%
% Store the current digit in a number in order to be able to calculate
% with it.
%    \begin{macrocode}
      \nprt@thisdigit=#1
%    \end{macrocode}
% If this number is to be rounded up do it by advancing it by one.
%    \begin{macrocode}
      \ifnprt@roundup
        \advance \nprt@thisdigit by 1
%    \end{macrocode}
% Reset \cs{ifnprt@roundup} since the preceeding digit is not to be
% rounded, normally.
%    \begin{macrocode}
        \nprt@roundupfalse
%    \end{macrocode}
% If the digit has been rounded from 9 to 10, it has to be a ``0'' and
% the preceeding digit has to be rounded up.
%    \begin{macrocode}
        \ifnum\nprt@thisdigit=10
          \nprt@thisdigit=0
          \nprt@rounduptrue
        \fi
      \fi
%    \end{macrocode}
% Store the modificated current digit to the new number by putting it
% into \cs{nprt@newnum} before all digits that have been stored
% before.
%    \begin{macrocode}
      \expandafter\xdef\expandafter\nprt@newnum{%
        \the\nprt@thisdigit\nprt@newnum}%
    \fi
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@round@before}
% Does the rounding of the number after the decimal sign.
% The first argument contains the current digit, the second the rest
% of the number.
% This routine works as \cs{nprt@round@after} but stops at its end in
% contrast to a given number.
%    \begin{macrocode}
\def\nprt@round@before#1#2\@empty{%
%    \end{macrocode}
% Store the arguments.
%    \begin{macrocode}
  \edef\nprt@argone{#1}%
  \edef\nprt@argtwo{#2}%
%    \end{macrocode}
% Do the recursion until the end of the number.
% This routine does not have to decide whether the number has to be
% rounded since it knows that by \cs{ifnprt@roundup}, set by
% \cs{nprt@round@after}.
%    \begin{macrocode}
  \ifx\nprt@argtwo\@empty
  \else
    \expandafter\nprt@round@before#2\@empty
  \fi
%    \end{macrocode}
% Store the current digit into a counter and use zero if the number
% before the decimal sign is empty.
%    \begin{macrocode}
  \ifx\nprt@argone\@empty
    \nprt@thisdigit=0
  \else
    \nprt@thisdigit=#1
  \fi
%    \end{macrocode}
% Add one to the number if it has to be rounded.
%    \begin{macrocode}
  \ifnprt@roundup
    \advance \nprt@thisdigit by 1
%    \end{macrocode}
% Reset the rounding of the next number.
%    \begin{macrocode}
    \nprt@roundupfalse
%    \end{macrocode}
% If rounded from 9 to 10, set this digit to ``0'' and give the
% information to the next digit.
%    \begin{macrocode}
    \ifnum\nprt@thisdigit=10
      \nprt@thisdigit=0
      \nprt@rounduptrue
    \fi
  \fi
%    \end{macrocode}
% If the number is empty, the new number has to be added and the
% counter adjusted.
%    \begin{macrocode}
  \ifx\nprt@argone\@empty
    \xdef\nprt@newnum{\the\nprt@thisdigit}%
%    \stepcounter{nprt@\nprt@numname @digitsbefore}%
    \advance\csname c@nprt@\nprt@numname @digitsbefore\endcsname 1\relax
  \else
%    \end{macrocode}
% Insert the current digit before the already stored digits in
% \cs{nprt@newnum}.
%    \begin{macrocode}
    \expandafter\xdef\expandafter\nprt@newnum{%
      \the\nprt@thisdigit\nprt@newnum}%
  \fi
}
%    \end{macrocode}
% \end{macro}
% Two new counters for the round position and the current postion in
% \cs{nprt@round@after}.
%    \begin{macrocode}
\newcount\nprt@curpos
\newcount\nprt@rndpos
%    \end{macrocode}
% \begin{macro}{\nprt@round}
% Round a number.
% The first argument is the Number type (``mantissa'' resp.\
% ``exponent''), the second is the number of digits to be printed
% after the decimal sign.
%    \begin{macrocode}
\newcommand*\nprt@round[2]{%
  \begingroup
%    \end{macrocode}
% Store the Number type for use in \cs{nprt@round@before} and
% \cs{nprt@round@after}.
%    \begin{macrocode}
    \edef\nprt@numname{#1}%
%    \end{macrocode}
% If the number of printed digits after the decimal sign is negative,
% no rounding will be performed.
%    \begin{macrocode}
    \ifnum#2<0
    \else
%    \end{macrocode}
% Print a debug message.
%    \begin{macrocode}
      \nprt@debug{\string\nprt@round: Round after #2 digits for #1}%
%    \end{macrocode}
% Set the number of digits after the decimal sign to the given value
% since this number of digits will be printed later.
%    \begin{macrocode}
      \setcounter{nprt@#1@digitsafter}{#2}%
%    \end{macrocode}
% Append enough zeros to the after-decimal-sign part in order to have
% enough digits that \cs{nprt@round@after} will not reach the end of
% the number.
%    \begin{macrocode}
      \expandafter\g@addto@macro\csname nprt@#1@after\endcsname{%
        \nprt@roundnull}%
%    \end{macrocode}
% Set the number of digits after the decimal sign.
%    \begin{macrocode}
      \nprt@rndpos=#2
%    \end{macrocode}
% Default not to round.
%    \begin{macrocode}
      \nprt@roundupfalse
%    \end{macrocode}
% Define the ``working'' number for the subroutines.
%    \begin{macrocode}
      \edef\nprt@tmpnum{\csname nprt@#1@after\endcsname}%
%    \end{macrocode}
% The new number starts empty and will be filled by
% \cs{nprt@round@after}.
%    \begin{macrocode}
      \edef\nprt@newnum{}%
%    \end{macrocode}
% Do the rounding after the decimal sign.
%    \begin{macrocode}
      \expandafter\nprt@round@after\nprt@tmpnum\@empty\@empty
%    \end{macrocode}
% Copy the new number after the decimal sign to the ``official''
% command storing it.
%    \begin{macrocode}
      \expandafter\xdef\csname nprt@#1@after\endcsname{\nprt@newnum}%
%    \end{macrocode}
% If the integer part has to be modificated, too, do it.
%    \begin{macrocode}
      \ifnprt@roundup
%    \end{macrocode}
% Copy the number to the working number.
%    \begin{macrocode}
        \edef\nprt@tmpnum{\csname nprt@#1@before\endcsname}%
%    \end{macrocode}
% Clear the new number.
%    \begin{macrocode}
        \edef\nprt@newnum{}%
%    \end{macrocode}
% Do the rounding before the decimal sign.
%    \begin{macrocode}
        \expandafter\nprt@round@before\nprt@tmpnum\@empty\@empty
%    \end{macrocode}
% If the first digit has been rounded up from 9 a new digit ``1'' has
% to be inserted before the number.
%    \begin{macrocode}
        \ifnprt@roundup
          \expandafter\xdef\expandafter\nprt@newnum{1\nprt@newnum}%
%          \stepcounter{nprt@#1@digitsbefore}%
          \advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
        \fi
%    \end{macrocode}
% Copy the new number before the decimal sign to the ``official''
% command storing it.
%    \begin{macrocode}
        \expandafter\xdef\csname nprt@#1@before\endcsname{\nprt@newnum}%
      \fi
    \fi
  \endgroup
%    \end{macrocode}
% Set the boolean for a found decimal sign according to the number of
% printed decimals.
%    \begin{macrocode}
  \ifnum#2<0
  \else
%    \end{macrocode}
% If rounded to no digits after the decimal sign, switch off printing
% of it.
%    \begin{macrocode}
    \ifnum#2=0
      \csname nprt@#1@decimalfoundfalse\endcsname
    \else
%    \end{macrocode}
% If one or more digits are printed, a decimal sign has to be printed.
%    \begin{macrocode}
      \csname nprt@#1@decimalfoundtrue\endcsname
    \fi
  \fi
}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@lpad}
% Pad a number with a character on the left side.
% The first argument contains the number, the second is the desired length
% and the third the padding character.
%    \begin{macrocode}
\newcommand*\nprt@lpad[3]{%
%    \end{macrocode}
% If the count of digits is negative, no padding will be performed.
%    \begin{macrocode}
  \ifnum#2<0
  \else
%    \end{macrocode}
% Print a debug message.
%    \begin{macrocode}
    \nprt@debug{\string\nprt@lpad: Padding #1 with #3 to a length of #2}%
%    \end{macrocode}
% If the number has less than the desired length, add the padding character
% to the left and call this function recursively.
%    \begin{macrocode}
    \ifnum\csname thenprt@#1@digitsbefore\endcsname<#2
      \expandafter\xdef\csname nprt@#1@before\endcsname{%
        #3\csname nprt@#1@before\endcsname}%
%      \stepcounter{nprt@#1@digitsbefore}%
      \advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
      \nprt@lpad{#1}{#2}{#3}%
    \fi
  \fi
}%
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Print the numbers}
%
% \begin{macro}{\nprt@sign@+}
% \begin{macro}{\nprt@sign@-}
% \begin{macro}{\nprt@sign@+-}
% 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{1.39}{2012/08/20}{Move group around sign into the specific
%   sign macros in order to allow colour again}%
%    \begin{macrocode}
\expandafter\newcommand\csname nprt@sign@+\endcsname{{\ensuremath{+}}}
\expandafter\newcommand\csname nprt@sign@-\endcsname{{\ensuremath{-}}}
\expandafter\newcommand\csname nprt@sign@+-\endcsname{{\ensuremath{\pm}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\nprt@printsign}
% Print a sign.
% The first argument contains the number type (``mantissa'' or
% ``exponent'').
% The second argument contains the sign as in source code.
%    \begin{macrocode}
\newcommand*\nprt@printsign[2]{%
%    \end{macrocode}
% Write sign to log file.
%    \begin{macrocode}
  \nprt@debug{\string\nprt@printsign: `#2'}%
%    \end{macrocode}
% Set command in a group to prevent the defined macros from being
% global.
%    \begin{macrocode}
    \edef\nprt@marg{#2}%
%    \end{macrocode}
% If a plus is to be added do it if no sign given.
%    \begin{macrocode}
    \csname ifnprt@addplus@#1\endcsname
      \ifx\nprt@marg\@empty
        \edef\nprt@marg{+}%
      \fi
    \fi
%    \end{macrocode}
% Do nothing if still no sign given.
%    \begin{macrocode}
    \ifx\nprt@marg\@empty
    \else
%    \end{macrocode}
% If a macro \cs{nprt@sign@\meta{sign}} is defined for the given sign,
% e.g., \cs{nprt@sign@+}, print it; if not, print the sign itself.
% \changes{1.22}{2004/08/08}{Print sign in a group to avoid additional space
%   for an operator (for nbaseprt)}%
% \changes{1.39}{2012/08/20}{Move group around sign into the specific
%   sign macros in order to allow colour again}%
%    \begin{macrocode}
      \@ifundefined{nprt@sign@\nprt@marg}{%
        \PackageWarning{numprint}{%
          Unknown sign `\nprt@marg'. Print as typed in}%
        \nprt@marg
      }{%
        \csname nprt@sign@\nprt@marg\endcsname%
      }%
    \fi
}
%    \end{macrocode}
% \end{macro}
% Internal counters for printing.
%    \begin{macrocode}
\newcounter{nprt@digitsfirstblock}
\newcounter{nprt@blockcnt}
%    \end{macrocode}
% Internal boolean.
%    \begin{macrocode}
\newif\ifnprt@shortnumber
%    \end{macrocode}
% \begin{macro}{\nprt@printbefore}
% Print the number before the decimal sign.
% The argument is the Number type (``mantissa'' or ``exponent'').
% When this macro is called, everything is parsed already.
% Thus, it is known whether a decimal sign has been found, which and
% how many digits are before resp.\ after the decimal sign etc.
%    \begin{macrocode}
\newcommand*\nprt@printbefore[1]{%
%    \end{macrocode}
% If missing zeros shall be added and there is no digit before the
% decimal sign store that ``0'' into the corresponding command and
% store in the counter that the number of digits before the decimal
% sign is one, know.
%    \begin{macrocode}
  \ifnprt@addmissingzero
    \ifnum\csname thenprt@#1@digitsbefore\endcsname=0
      \expandafter\edef\csname nprt@#1@before\endcsname{0}%
%      \stepcounter{nprt@#1@digitsbefore}%
      \advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
    \fi
  \fi
%    \end{macrocode}
% I'm not sure why I have added the group here. 
% But it works and I won't change it, therefore.
%    \begin{macrocode}
  \begingroup
%    \end{macrocode}
% Store the number to be printed in \cs{nprt@numbertoprint} in order
% to have simpler calls in this routine than using \cs{csname}\ldots
%    \begin{macrocode}
    \edef\nprt@numbertoprint{\csname nprt@#1@before\endcsname}%
%    \end{macrocode}
% If four-digit numbers are not to be separated and both, the integer
% and the real parts, are shorter than 5 digits, set the boolean
% \cs{ifnprt@shortnumber} to ``true'' that the number is printed
% without separators, later.
%    \begin{macrocode}
    \ifnprt@numsepfour
    \else
      \ifnum\csname thenprt@#1@digitsbefore\endcsname<5
        \ifnum\csname thenprt@#1@digitsafter\endcsname<5
          \nprt@shortnumbertrue
        \fi
      \fi
    \fi
%    \end{macrocode}
% If the number is short according to the preceeding code, just print
% that number by calling \cs{nprt@numbertoprint}.
%    \begin{macrocode}
    \ifnprt@shortnumber
      \nprt@numbertoprint
    \else
%    \end{macrocode}
% If the number will get separators, calculate how many separators
% will be inserted.
%    \begin{macrocode}
      % ganze Bloecke
      \setcounter{nprt@blockcnt}{%
        \csname thenprt@#1@digitsbefore\endcsname}%
      \advance\c@nprt@blockcnt by -1\relax
      \divide\c@nprt@blockcnt 3%
%    \end{macrocode}
% Then, calculate how many digits are in the first block (one, two, or
% three).
% Use \cs{c@nprt@cntprint} as temporary variable.
%    \begin{macrocode}
      \setcounter{nprt@digitsfirstblock}{%
        \csname thenprt@#1@digitsbefore\endcsname}%
      \setcounter{nprt@cntprint}{\thenprt@blockcnt}%
      \multiply \c@nprt@cntprint 3%
      \advance\c@nprt@digitsfirstblock by -\thenprt@cntprint\relax
%    \end{macrocode}
% Depending on that number, call \cs{nprt@printone},
% \cs{nprt@printtwo}, resp.\ \cs{nprt@printthree} which do what you
% may expect with that names.
%    \begin{macrocode}
      \ifnum\thenprt@digitsfirstblock=1
        \expandafter\nprt@printone\nprt@numbertoprint\@empty
      \else
        \ifnum\thenprt@digitsfirstblock=2
          \expandafter\nprt@printtwo\nprt@numbertoprint\@empty
        \else
          \ifnum\thenprt@digitsfirstblock=3
            \expandafter\nprt@printthree\nprt@numbertoprint\@empty
          \else
            \ifnum\thenprt@digitsfirstblock=0
            \else
              \PackageError{numprint}{internal error}{}%
            \fi
          \fi
        \fi
      \fi
    \fi
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@printthree}
% Print three digits.
% If the command has not reached the end of the string, print a
% separator \cs{nprt@separator@before} and call this routine
% recursively.
% Surprisingly, this routine does not work if |#1#2#3| is the first
% command in some cases.
% Thus, \cs{def}cs{nprt@tmp} has been moved in front of it.
% Make sure that this works in all cases. 
% Same applies for \cs{nprt@printtwo}, \cs{nprt@printone}, and
% \cs{nprt@printthreeafter}.
%    \begin{macrocode}
\def\nprt@printthree#1#2#3#4\@empty{%
  \def\nprt@tmp{#4}%
  #1#2#3%
  \ifx\nprt@tmp\empty
  \else
    \nprt@separator@before%
    \nprt@printthree#4\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@printtwo}
% The same but start with two instead of three digits.
%    \begin{macrocode}
\def\nprt@printtwo#1#2#3\@empty{%
  \def\nprt@tmp{#3}%
  #1#2%
  \ifx\nprt@tmp\empty
  \else
    \nprt@separator@before%
    \nprt@printthree#3\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@printone}
% The same but start with one instead of three digits.
%    \begin{macrocode}
\def\nprt@printone#1#2\@empty{%
  \def\nprt@tmp{#2}%
  #1%
  \ifx\nprt@tmp\empty
  \else
    \nprt@separator@before%
    \nprt@printthree#2\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@printafter}
% Print the number after the decimal sign.
% The argument is the Number type (``mantissa'' or ``exponent'').
% This macro works similarly as \cs{nprt@printbefore}.
%    \begin{macrocode}
\newcommand*\nprt@printafter[1]{%
%    \end{macrocode}
% If a missing zero shall be added do it if no digits are given after
% the decimal sign if a decimal sign has been given.
% If no decimal sign has been given, the number is pure integer and
% does not get a real part.
%    \begin{macrocode}
  \csname ifnprt@#1@decimalfound\endcsname
    \ifnprt@addmissingzero
      \ifnum\csname thenprt@#1@digitsafter\endcsname=0
        \expandafter\edef\csname nprt@#1@after\endcsname{0}%
%        \stepcounter{nprt@#1@digitsafter}%
        \advance\csname c@nprt@#1@digitsafter\endcsname by 1\relax
      \fi
    \fi
%    \end{macrocode}
% If a after-decimal zero will be replaced by another command but the
% real part is empty, put a ``0'' after the comma (same as
% ``addmissingzero'', but here it is just a hack in order to enable
% the replacement command to take effect later).
%    \begin{macrocode}
    \ifx\nprt@replacenull\@empty
    \else
      \ifnum\csname thenprt@#1@digitsafter\endcsname=0
        \expandafter\edef\csname nprt@#1@after\endcsname{0}%
%        \stepcounter{nprt@#1@digitsafter}%
        \advance\csname c@nprt@#1@digitsafter\endcsname by 1\relax
      \fi
    \fi
  \fi
%    \end{macrocode}
% Store the number in \cs{nprt@numbertoprint} and continue only if it
% is not empty.
%    \begin{macrocode}
  \begingroup
    \edef\nprt@numbertoprint{\csname nprt@#1@after\endcsname}%
    \ifx\nprt@numbertoprint\@empty
    \else
%    \end{macrocode}
% Find out whether separators have to be inserted.
%    \begin{macrocode}
      \ifnprt@numsepfour
      \else
        \ifnum\csname thenprt@#1@digitsbefore\endcsname<5
          \ifnum\csname thenprt@#1@digitsafter\endcsname<5
            \nprt@shortnumbertrue
          \fi
        \fi
      \fi
%    \end{macrocode}
% If a zero has to be replaced by a replacement text, and if the after
% comma part has the numerical value ``0'' (= it contains of zeros
% only), do the replacement.
%    \begin{macrocode}
      \ifx\nprt@replacenull\@empty
      \else
        \ifnum\nprt@numbertoprint=0
          \nprt@shortnumbertrue
          \edef\nprt@numbertoprint{\nprt@replacenull}%
        \fi
      \fi
%    \end{macrocode}
% If the number is short (without separators) just print it.
%    \begin{macrocode}
      \ifnprt@shortnumber
        \nprt@numbertoprint
      \else
%    \end{macrocode}
% Print the number with separators. 
% The choice between different block sizes does not have to be done
% because the after-decimal-sign part starts with three-digit block
% from the left end.
%    \begin{macrocode}
        \expandafter\nprt@printthree@after%
          \nprt@numbertoprint\@empty\@empty\@empty
      \fi
    \fi
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@printthree@after}
% The same as \cs{nprt@printthree} but with another separator.
%    \begin{macrocode}
\def\nprt@printthree@after#1#2#3#4\@empty{%
  \def\nprt@tmp{#4}%
  #1#2#3%
  \ifx\nprt@tmp\empty
  \else
    \nprt@separator@after
    \nprt@printthree@after#4\@empty\@empty\@empty
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% 
% \subsection{The main command}%
% \label{sec:code:main}%
%
% \begin{macro}{\numprint}
% The main macro of the package.
% The mandatory argument takes a number and prints it as described
% above.
% The optional argument may contain a unit which then is printed,
% too.
%    \begin{macrocode}
\DeclareRobustCommand*\numprint[2][\@empty]{%
%    \end{macrocode}
% Switch off the error flag.
% This should not be necessary but is done for stability reasons.
%    \begin{macrocode}
  \nprt@argumenterrorfalse
%    \end{macrocode}
% Clear the mantissa and the exponent.
%    \begin{macrocode}
  \xdef\nprt@exponent{\@empty}%
  \xdef\nprt@mantissa{\@empty}%
%    \end{macrocode}
% Do everything inside a group to avoid defining too many temporary
% macros that are not deleted after the macro.
%    \begin{macrocode}
  \begingroup
%    \end{macrocode}
% Store the mandatory argument into a macro.
% Redefine \cs{,} and |~| to do nothing as to ignore them.
% Because the argument is expanded this does not work with the ignore
% list for characters.
% This again has to be done inside a group to preserve the two macros
% for later usage.
%    \begin{macrocode}
    \begingroup
      \def\,{}%
      \catcode`\~=\active % tilde is active
      \def~{}%
      \xdef\nprt@marg{#2}%
    \endgroup
%    \end{macrocode}
% Don't expand the unit because that may cause trouble.
%    \begin{macrocode}
    \def\nprt@oarg{#1}%
%    \end{macrocode}
% Declare some commands to detect empty arguments.
%    \begin{macrocode}
    \def\nprt@@empty{\@empty}%
    \def\nprt@nix{}%
    \def\nprt@nixleer{ }%
%    \end{macrocode}
% Some debug information.
%    \begin{macrocode}
    \ifx\nprt@oarg\nprt@@empty
      \nprt@debug{\string\numprint{\protect#2}}%
    \else
      \nprt@debug{\string\numprint[\protect#1]{\protect#2}}%
    \fi
%    \end{macrocode}
% Test for an empty mandatory argument.
%    \begin{macrocode}
    \ifx\nprt@marg\nprt@nix
      \nprt@error{empty argument}{You have to specify a number in
        the argument of \string\numprint}%
    \fi
    \ifx\nprt@marg\nprt@nixleer
      \nprt@error{empty argument}{You have to specify a number in
        the argument of \string\numprint}%
    \fi
%    \end{macrocode}
% Test whether only valid characters have been used and devide the
% argument in the mantissa and the exponent.
%    \begin{macrocode}
    \expandafter\nprt@testcharacter\nprt@marg\@empty\@empty
%    \end{macrocode}
% If there are invalid characters in the argument, just print the
% argument without formatting it.
% Redefine \cs{pm} to avoid an additional error in text mode.
%    \begin{macrocode}
    \ifnprt@argumenterror
      \begingroup\def\pm{+-}#2\endgroup
    \else
%    \end{macrocode}
% If everything is okay, proceed with parsing.
%
% \changes{1.31}{2004/08/18}{Bugfix: \cs{numprint\{e123\}} reprinted the
%   last used sign}%
% If the mantissa is empty don't work on it but reset the sign of the
% mantissa to avoid to reprint the old sign when using
% \cs{numprint\{e123\}}.
% If it is not empty, parse it for a sign and a number.
%    \begin{macrocode}
      \ifx\nprt@mantissa\@empty
        \def\nprt@mantissa@sign{\@empty}%
      \else
        \nprt@testsign{mantissa}{\nprt@mantissa}%
      \fi
%    \end{macrocode}
% If the mantissa contains only a sign, \cs{nprt@mantissa} is set to
% \cs{@empty} and thus empty even if it wasn't 4 lines above.
% If the mantissa only contains of a sign and an exponent is given,
% everything is fine.
% If no exponent is given, the input format is invalid.
%    \begin{macrocode}
      \ifx\nprt@mantissa\@empty
        \ifx\nprt@exponent\@empty
          \nprt@error{Invalid number format. Printing the
            argument\MessageBreak
            verbatim}{Something is wrong in the format of the number}%
        \else
          \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
        \fi
      \else
%    \end{macrocode}
% Round the mantissa if necessary.
%    \begin{macrocode}
        \nprt@round{mantissa}{\nprt@rounddigits}%
%    \end{macrocode}
% Pad the mantissa if necessary.
%    \begin{macrocode}
        \nprt@lpad{mantissa}{\nprt@lpaddigits}{\nprt@lpadchar}%
      \fi
%    \end{macrocode}
% If an exponent has been found, parse this like the mantissa.
%    \begin{macrocode}
      \ifnprt@expfound
%    \end{macrocode}
% Test whether an exponent character was given but no exponent.
%    \begin{macrocode}
        \ifx\nprt@exponent\@empty
          \nprt@error{Empty exponent}{If you specify an exponent
            using one of the characters `\nprt@explist' you
            have\MessageBreak
            to give an exponent, too.}%
        \else
          \nprt@testsign{exponent}{\nprt@exponent}%
          \nprt@round{exponent}{\nprt@roundexpdigits}%
        \fi
      \fi
%    \end{macrocode}
% If either the mantissa or the exponent produces an error, just print
% the argument as is.
% Redefine \cs{pm} to avoid an additional error in text mode.
%    \begin{macrocode}
      \ifnprt@argumenterror
        \begingroup\def\pm{+-}#2\endgroup
      \else
%    \end{macrocode}
% Print the mantissa if present.
%    \begin{macrocode}
        \ifx\nprt@mantissa\@empty
        \else
%    \end{macrocode}
% Print the part before the decimal sign.
% 
% If the number shall be printed in a box (table alignment) some
% special things have to be done.
%    \begin{macrocode}
          \ifnprt@mantissa@fixeddigits
            \ifmmode
%    \end{macrocode}
% In math mode, it must be decided which math style is active because
% the width of the box depends on that.
% The \cs{mathchoice} command does the formatting for all styles and
% typesets the active one then.
%    \begin{macrocode}
              \mathchoice{%
%    \end{macrocode}
% Calculate the width of the block for the \cs{displaystyle}.
%    \begin{macrocode}
                \nprt@calcblockwidth{mantissa}{before}{\displaystyle}%
%    \end{macrocode}
% Generate a box with the calculated width and the corresponding math
% style.
%    \begin{macrocode}
                \makebox[\the\nprt@blockwidth][r]{$\displaystyle
%    \end{macrocode}
% Print the sign if present.
%    \begin{macrocode}
                  \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
%    \end{macrocode}
% Print the integer part into the box.
%    \begin{macrocode}
                  \nprt@printbefore{mantissa}$}%
              }{%
%    \end{macrocode}
% Do the same for \cs{textstyle}.
%    \begin{macrocode}
                \nprt@calcblockwidth{mantissa}{before}{\textstyle}%
                \makebox[\the\nprt@blockwidth][r]{$\textstyle
                  \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
                  \nprt@printbefore{mantissa}$}%
              }{%
%    \end{macrocode}
% Do the same for \cs{scriptstyle}.
%    \begin{macrocode}
                \nprt@calcblockwidth{mantissa}{before}{\scriptstyle}%
                \makebox[\the\nprt@blockwidth][r]{$\scriptstyle
                  \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
                  \nprt@printbefore{mantissa}$}%
              }{%
%    \end{macrocode}
% Do the same for \cs{scriptscriptstyle}.
%    \begin{macrocode}
                \nprt@calcblockwidth{mantissa}{before}{\scriptscriptstyle}%
                \makebox[\the\nprt@blockwidth][r]{$\scriptscriptstyle
                  \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
                  \nprt@printbefore{mantissa}$}%
              }%
            \else
%    \end{macrocode}
% If the number is printed in text mode, the size is preserved inside
% the box. 
% Thus, no hack as for math mode is necessary.
%    \begin{macrocode}
              \nprt@calcblockwidth{mantissa}{before}{\@empty}%
              \makebox[\the\nprt@blockwidth][r]{%
                \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
                \nprt@printbefore{mantissa}%
              }%
            \fi
          \else
%    \end{macrocode}
% If the number is printed without fixed width, just print it.
%    \begin{macrocode}
            \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
            \nprt@printbefore{mantissa}%
          \fi
%    \end{macrocode}
% Print the after-decimal-sign digits.
% This works exactly as the integer part.
%    \begin{macrocode}
          \ifnprt@mantissa@fixeddigits
            \ifmmode
              \mathchoice{%
                \nprt@calcblockwidth{mantissa}{after}{\displaystyle}%
                \makebox[\the\nprt@blockwidth][l]{$\displaystyle
                  \ifnprt@mantissa@decimalfound
                    \nprt@decimal
                  \fi
                  \nprt@printafter{mantissa}$}%
              }{%
                \nprt@calcblockwidth{mantissa}{after}{\textstyle}%
                \makebox[\the\nprt@blockwidth][l]{$\textstyle
                  \ifnprt@mantissa@decimalfound
                    \nprt@decimal
                  \fi
                  \nprt@printafter{mantissa}$}%
              }{%
                \nprt@calcblockwidth{mantissa}{after}{\scriptstyle}%
                \makebox[\the\nprt@blockwidth][l]{$\scriptstyle
                  \ifnprt@mantissa@decimalfound
                    \nprt@decimal
                  \fi
                  \nprt@printafter{mantissa}$}%
              }{%
                \nprt@calcblockwidth{mantissa}{after}{\scriptscriptstyle}%
                \makebox[\the\nprt@blockwidth][l]{$\scriptscriptstyle
                  \ifnprt@mantissa@decimalfound
                    \nprt@decimal
                  \fi
                  \nprt@printafter{mantissa}$}%
              }%
            \else
              \nprt@calcblockwidth{mantissa}{after}{\@empty}%
              \makebox[\the\nprt@blockwidth][l]{%
                \ifnprt@mantissa@decimalfound
                  \nprt@decimal
                \fi
                \nprt@printafter{mantissa}%
              }%
            \fi
          \else
            \ifnprt@mantissa@decimalfound
              \nprt@decimal
            \fi
            \nprt@printafter{mantissa}%
          \fi
        \fi
%    \end{macrocode}
% If an exponent is defined it has to be printed later.
% Therefore, define the command \cs{nprt@printexp} that just prints
% its argument.
%    \begin{macrocode}
        \ifnprt@expfound
          \def\nprt@printexp##1{##1}%
%    \end{macrocode}
% If a sign but no number has been given for the exponent
% \cs{nprt@exponent} is empty but \cs{ifnprt@expfound} true.
% Test for this case here.
%    \begin{macrocode}
          \ifx\nprt@exponent\@empty
            \nprt@error{Invalid number format in
              exponent. Printing\MessageBreak 
              garbage}{Something is wrong in the format of the exponent}%
          \fi
        \else
%    \end{macrocode}
% If there is no exponent but digits reserved for it, define the
% \cs{nprt@printexp} so that is just needs that space but does not
% print anything.
%    \begin{macrocode}
          \ifnprt@exponent@fixeddigits
            \def\nprt@printexp##1{\hphantom{##1}}%
          \else
%    \end{macrocode}
% If there is no exponent and no reserved digits, don't print the
% exponent.
%    \begin{macrocode}
            \def\nprt@printexp##1{}%
          \fi
        \fi
%    \end{macrocode}
% If\label{page:code:color} negative numbers are printed in red (as
% shown in section~\ref{sec:negative-red}), a positive mantissa with a
% negative exponent would normally lead to a black mantissa with a
% red exponent.
% To avoid that the \cs{color} command is redefined to do nothing
% here.
% Do it in a group to restrain this to the exponent itself.
% \changes{1.22}{2004/08/08}{Restrain empty \cs{color} command to
%   exponent}%
%    \begin{macrocode}
        \begingroup
        \def\color##1{}%
%    \end{macrocode}
% Call the command that either print the exponent, reserves space as
% it were printed or does nothing.
%    \begin{macrocode}
        \nprt@printexp{%
%    \end{macrocode}
% If not mantissa is specified, print the short version, e.g.,
% $10^{123}$ and thus leave out the product sign.
%    \begin{macrocode}
          \ifx\nprt@mantissa\@empty
          \else
%    \end{macrocode}
% Print out the product sign, if there is a mantissa.
%    \begin{macrocode}
            \nprt@prod
          \fi
%    \end{macrocode}
% Print ``10'' and the exponent.
% This is different between text and math mode.
%    \begin{macrocode}
          \ifmmode 10^\else 10\expandafter\textsuperscript\fi{%
%    \end{macrocode}
% Print the number before the decimal sign.
% As the mantissa.
%    \begin{macrocode}
            \ifnprt@exponent@fixeddigits
              \ifmmode
                \mathchoice{%
                  \nprt@calcblockwidth{exponent}{before}{\displaystyle}%
                  \makebox[\the\nprt@blockwidth][r]{$\displaystyle
                    \nprt@printsign{exponent}{\nprt@exponent@sign}%
                    \nprt@printbefore{exponent}$}%
                }{%
                  \nprt@calcblockwidth{exponent}{before}{\textstyle}%
                  \makebox[\the\nprt@blockwidth][r]{$\textstyle
                    \nprt@printsign{exponent}{\nprt@exponent@sign}%
                    \nprt@printbefore{exponent}$}%
                }{%
                  \nprt@calcblockwidth{exponent}{before}{\scriptstyle}%
                  \makebox[\the\nprt@blockwidth][r]{$\scriptstyle
                    \nprt@printsign{exponent}{\nprt@exponent@sign}%
                    \nprt@printbefore{exponent}$}%
                }{%
                  \nprt@calcblockwidth{exponent}{before}{\scriptscriptstyle}%
                  \makebox[\the\nprt@blockwidth][r]{$\scriptscriptstyle
                    \nprt@printsign{exponent}{\nprt@exponent@sign}%
                    \nprt@printbefore{exponent}$}%
                }%
              \else
                \nprt@calcblockwidth{exponent}{before}{\@empty}%
                \makebox[\the\nprt@blockwidth][r]{%
                  \nprt@printsign{exponent}{\nprt@exponent@sign}%
                  \nprt@printbefore{exponent}%
                }%
              \fi
            \else
              \nprt@printsign{exponent}{\nprt@exponent@sign}%
              \nprt@printbefore{exponent}%
            \fi
%    \end{macrocode}
% Produce a warning since this is uncommon in exponents.
%    \begin{macrocode}
            \ifnprt@exponent@decimalfound
              \PackageWarning{numprint}{Non-integer exponent}%
            \fi
%    \end{macrocode}
% Print the part after the decimal sign.
%    \begin{macrocode}
            \ifnprt@exponent@fixeddigits
              \ifmmode
                \mathchoice{%
                  \nprt@calcblockwidth{exponent}{after}{\displaystyle}%
                  \makebox[\the\nprt@blockwidth][l]{$\displaystyle
                    \ifnprt@exponent@decimalfound
                      \nprt@decimal
                    \fi
                    \nprt@printafter{exponent}$}%
                }{%
                  \nprt@calcblockwidth{exponent}{after}{\textstyle}%
                  \makebox[\the\nprt@blockwidth][l]{$\textstyle
                    \ifnprt@exponent@decimalfound
                      \nprt@decimal
                    \fi
                    \nprt@printafter{exponent}$}%
                }{%
                  \nprt@calcblockwidth{exponent}{after}{\scriptstyle}%
                  \makebox[\the\nprt@blockwidth][l]{$\scriptstyle
                    \ifnprt@exponent@decimalfound
                      \nprt@decimal
                    \fi
                    \nprt@printafter{exponent}$}%
                }{%
                  \nprt@calcblockwidth{exponent}{after}{\scriptscriptstyle}%
                  \makebox[\the\nprt@blockwidth][l]{$\scriptscriptstyle
                    \ifnprt@exponent@decimalfound
                      \nprt@decimal
                    \fi
                    \nprt@printafter{exponent}$}%
                }%
              \else
                \nprt@calcblockwidth{exponent}{after}{\@empty}%
                \makebox[\the\nprt@blockwidth][l]{%
                  \ifnprt@exponent@decimalfound
                    \nprt@decimal
                  \fi
                  \nprt@printafter{exponent}%
                }%
              \fi
            \else
              \ifnprt@exponent@decimalfound
                \nprt@decimal
              \fi
              \nprt@printafter{exponent}%
            \fi
          }% 10^
        }% \nprt@printexp
        \endgroup
      \fi
    \fi
%    \end{macrocode}
% If the unit is not empty, print it, too.
%    \begin{macrocode}
    \ifx\nprt@oarg\nprt@@empty
    \else
%    \end{macrocode}
% All units expect the degree symbol are separated from the number.
% Detect whether the degree symbol is used.
% 
% \changes{1.22}{2004/08/08}{Produce a warning rather than an error
%   when using \cs{textdegree} as unit}%
% The \cs{textdegree} command is not useable in math mode.
% Redeclare it to generate a warning and to use \cs{tcdegree}
% instead.
%    \begin{macrocode}
      \def\textdegree{%
        \PackageWarning{numprint}{The unit is typeset in mathmode. Use
          \string\tcdegree\space of\MessageBreak
          the mathcomp package or \string\degree\space of the
          gensymb\MessageBreak
          package}%
%    \end{macrocode}
% Call \cs{tcdegree} via \cs{csname} in order to avoid a second error
% message if \cs{tcdegree} is not present (because of not loading
% |mathcomp.sty|.
%    \begin{macrocode}
        \csname tcdegree\endcsname
      }%
%    \end{macrocode}
% \changes{1.22}{2004/08/08}{Enable to use \cs{textcelsius},
%   \cs{textohm}, \cs{textmu}, and \cs{textperthousand} in the unit}%
% \changes{1.32}{2004/09/13}{Produce an error rather than a warning
%   when using \texttt{textcomp} symbols in the unit if
%   \texttt{mathcomp} or \texttt{gensymb} is not loaded}%
% Handle \cs{textcelsius}, \cs{textohm}, \cs{textmu}, and
% \cs{textperthousand} in the same way as \cs{textdegree}.
%    \begin{macrocode}
      \def\nprt@PackageError##1##2{\PackageWarning{numprint}{##1}}%
      \def\textcelsius{%
        \begingroup
        \@ifundefined{tccelsius}{\@ifundefined{celsius}{%
            \def\nprt@PackageError####1####2{%
              \PackageError{numprint}{####1}{####2}}%
          }{\celsius}}{\tccelsius}%
        \nprt@PackageError{The unit is typeset in
          mathmode. Use \string\tccelsius\space of\MessageBreak
          the mathcomp package or \string\celsius\space of the
          gensymb\MessageBreak
          package}{If you load the mathcomp package
          \string\textcelsius\space is substituted by
          \string\tccelsius. If you load the gensymb package
          \string\textcelsius\space is substituted by \string\celsius.}%
        \endgroup
      }%
      \def\textohm{%
        \begingroup
        \@ifundefined{tcohm}{\@ifundefined{ohm}{%
            \def\nprt@PackageError####1####2{%
              \PackageError{numprint}{####1}{####2}}%
          }{\ohm}}{\tcohm}%
        \nprt@PackageError{The unit is typeset in
          mathmode. Use \string\tcohm\space of\MessageBreak
          the mathcomp package or \string\ohm\space of the
          gensymb\MessageBreak
          package}{If you load the mathcomp package
          \string\textohm\space is substituted by
          \string\tcohm. If you load the gensymb package
          \string\textohm\space is substituted by \string\ohm.}%
        \endgroup
      }%
      \def\textmu{%
        \begingroup
        \@ifundefined{tcmu}{%
          \def\nprt@PackageError####1####2{%
            \PackageError{numprint}{####1}{####2}}%
        }{\tcmu}%
        \nprt@PackageError{The unit is typeset in
          mathmode. Use \string\tcmu\space of\MessageBreak
          the mathcomp package}{If you load the mathcomp package
          \string\textmu\space is substituted by \string\tcmu.}%
        \endgroup
      }%
      \def\textperthousand{%
        \begingroup
        \@ifundefined{tcperthousand}{\@ifundefined{perthousand}{%
            \def\nprt@PackageError####1####2{%
              \PackageError{numprint}{####1}{####2}}%
          }{\perthousand}}{\tcperthousand}%
        \nprt@PackageError{The unit is typeset in
          mathmode. Use \string\tcperthousand\MessageBreak
          of the mathcomp package or \string\perthousand\space of
          the\MessageBreak
          gensymb package}{If you load the mathcomp package
          \string\textperthousand\space is substituted by
          \string\tcperthousand. If you load the gensymb package
          \string\textperthousand\space is substituted by
          \string\perthousand.}%
        \endgroup
      }%
%    \end{macrocode}
% If the unit is \cs{tcdegree} from the \texttt{mathcomp} package, the
% unit is a degree sign.
% Then print the separator \cs{nprt@degreesep} instead of
% \cs{nprt@unitsep}.
%    \begin{macrocode}
      \def\nprt@tmpunit{\tcdegree}%
      \ifx\nprt@oarg\nprt@tmpunit
        \ensuremath{\nprt@degreesep}%
      \else
%    \end{macrocode}
% If the unit is \cs{degree} from the \texttt{gensymb} package, the
% unit is a degree sign.
% Then print the separator \cs{nprt@degreesep} instead of
% \cs{nprt@unitsep}.
%    \begin{macrocode}
        \def\nprt@tmpunit{\degree}%
        \ifx\nprt@oarg\nprt@tmpunit
          \ensuremath{\nprt@degreesep}%
        \else
%    \end{macrocode}
% If the unit is \cs{textdegree} from the \texttt{textcomp} package, the
% unit is a degree sign.
% Then print the separator \cs{nprt@degreesep} instead of
% \cs{nprt@unitsep}.
%    \begin{macrocode}
          \def\nprt@tmpunit{\textdegree}%
          \ifx\nprt@oarg\nprt@tmpunit
            \ensuremath{\nprt@degreesep}%
          \else
%    \end{macrocode}
% If the unit is \cs{tccelsius} from the \texttt{mathcomp} package, the
% unit is degree centigrade.
% Then print the separator \cs{nprt@celsiussep} instead of
% \cs{nprt@unitsep}.
%    \begin{macrocode}
            \def\nprt@tmpunit{\tccelsius}%
            \ifx\nprt@oarg\nprt@tmpunit
              \ensuremath{\nprt@celsiussep}%
            \else
%    \end{macrocode}
% If the unit is \cs{celsius} from the \texttt{gensymb} package, the
% unit is degree centigrade.
% Then print the separator \cs{nprt@celsiussep} instead of
% \cs{nprt@unitsep}.
%    \begin{macrocode}
              \def\nprt@tmpunit{\celsius}%
              \ifx\nprt@oarg\nprt@tmpunit
                \ensuremath{\nprt@celsiussep}%
              \else
%    \end{macrocode}
% If the unit is \cs{textcelsius} from the \texttt{textcomp} package, the
% unit is degree centigrade.
% Then print the separator \cs{nprt@celsiussep} instead of
% \cs{nprt@unitsep}.
%    \begin{macrocode}
                \def\nprt@tmpunit{\textcelsius}%
                \ifx\nprt@oarg\nprt@tmpunit
                  \ensuremath{\nprt@celsiussep}%
                \else
%    \end{macrocode}
% If the unit is \cs{\%}, the unit is a percent sign.
% Then print the separator \cs{nprt@percentsep} instead of
% \cs{nprt@unitsep}.
%    \begin{macrocode}
                  \def\nprt@tmpunit{\%}%
                  \ifx\nprt@oarg\nprt@tmpunit
                    \ensuremath{\nprt@percentsep}%
                  \else
%    \end{macrocode}
% If the unit is \cs{tcperthousand} from the \texttt{mathcomp} package, the
% unit is a permil sign.
% Then print the separator \cs{nprt@percentsep} instead of
% \cs{nprt@unitsep}.
%    \begin{macrocode}
                    \def\nprt@tmpunit{\tcperthousand}%
                    \ifx\nprt@oarg\nprt@tmpunit
                      \ensuremath{\nprt@percentsep}%
                    \else
%    \end{macrocode}
% If the unit is \cs{perthousand} from the \texttt{gensymb} package, the
% unit is a permil sign.
% Then print the separator \cs{nprt@percentsep} instead of
% \cs{nprt@unitsep}.
%    \begin{macrocode}
                      \def\nprt@tmpunit{\perthousand}%
                      \ifx\nprt@oarg\nprt@tmpunit
                        \ensuremath{\nprt@percentsep}%
                      \else
%    \end{macrocode}
% If the unit is \cs{textperthousand} from the \texttt{textcomp} package, the
% unit is a permil sign.
% Then print the separator \cs{nprt@percentsep} instead of
% \cs{nprt@unitsep}.
%    \begin{macrocode}
                        \def\nprt@tmpunit{\textperthousand}%
                        \ifx\nprt@oarg\nprt@tmpunit
                          \ensuremath{\nprt@percentsep}%
                        \else
%    \end{macrocode}
% Else, print \cs{nprt@unitsep}.
%    \begin{macrocode}
                          \ensuremath{\nprt@unitsep}%
                        \fi
                      \fi
                    \fi
                  \fi
                \fi
              \fi
            \fi
          \fi
        \fi
      \fi
%    \end{macrocode}
% Finally, print the unit.
%    \begin{macrocode}
      \npunitcommand{\nprt@oarg}%
    \fi
  \endgroup
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Print lengths and counters}%
% \label{sec:code:lenprint}%
%
% \begin{macro}{\cntprint}
% The macro for printing counters.
% The mandatory argument takes a \LaTeX\ counter.
% The optional argument may contain a unit which is printed, too.
%    \begin{macrocode}
\newcounter{nprt@cntprint}
\DeclareRobustCommand*\cntprint[2][\@empty]{%
  \@ifundefined{c@#2}{\@nocounterr{#2}}{%
    \numprint[#1]{\arabic{#2}}%
  }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\lenprint}
% The macro for printing lengths.
% The mandatory argument takes a \TeX\ dimension or a counter.
% The optional argument may contain a unit that is used to convert the
% unit from |pt| to the given value and which then is printed, too.
%    \begin{macrocode}
\DeclareRobustCommand*\lenprint[2][\@empty]{%
%    \end{macrocode}
% Do everything in a group to avoid macros to resist outside.
%    \begin{macrocode}
  \begingroup
%    \end{macrocode}
% Save the optional argument in \cs{nprt@oarg} and expand it.
%    \begin{macrocode}
    \edef\nprt@oarg{#1}%
%    \end{macrocode}
% If no optional argument has been given, change it to |pt|. 
% This cannot be done as default argument in the
% \cs{DeclareRobustCommand*} definition since printing of counters
% does not have |pt| as default.
%    \begin{macrocode}
    \edef\nprt@tmp{\@empty}%
    \ifx\nprt@oarg\nprt@tmp
      \def\nprt@oarg{pt}%
    \fi
%    \end{macrocode}
% If the chosen unit is not defined produce an error message and fall
% back to |pt|.
%    \begin{macrocode}
    \@ifundefined{nprt@factor@\nprt@oarg}{%
      \PackageError{numprint}{Invalid unit `#1'}{%
        The requested unit is not defined using \string\npdefunit.^^J%
        Using `pt' instead.}%
      \def\nprt@oarg{pt}%
    }{}%
%    \end{macrocode}
% For later printing, a length is used that is fixed to |pt| as
% length.
% If another unit has been chosen a fake length has to be calculated
% that is as many |pt| long as the original length is in the given
% unit.
% Thus, multiply the mandatory argument by the specific factor for the
% given unit.
%    \begin{macrocode}
    \setlength{\@tempdima}{#2}%
    \setlength{\@tempdima}{\csname nprt@factor@\nprt@oarg\endcsname\@tempdima}%
%    \end{macrocode}
% If the unit name for the given unit is not defined but the factor
% is an internal error has occured.
% Produce an error message.
%    \begin{macrocode}
    \@ifundefined{nprt@unit@\nprt@oarg}{%
      \PackageError{numprint}{Unknown unit name `\nprt@oarg'}{%
        Send a bug report to harald.harders@tu-bs.de with a short
        example showing this bug.}%
    }{%
%    \end{macrocode}
% Store the unit name in \cs{nprt@oarg}.
%    \begin{macrocode}
      \edef\nprt@oarg{\csname nprt@unit@\nprt@oarg\endcsname}%
    }%
%    \end{macrocode}
% Finally, call \cs{numprint}.
% The two \cs{expandafter} are necessary since \cs{numprint} also uses
% \cs{nprt@oarg} and produces an infinite loop otherwise.
%    \begin{macrocode}
    \expandafter\numprint\expandafter[\nprt@oarg]{\strip@pt\@tempdima}%
  \endgroup
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npdefunit}
% Define a new unit for usage with \cs{lenprint}.
% First argument: name in the sourcecode.
% Second argument: printed unit.
% Third argument: factor from |pt| to the new unit or |*| to preserve
% old factor.
%    \begin{macrocode}
\newcommand*\npdefunit[3]{%
%    \end{macrocode}
% If the third argument is not |*| define the factor for this unit in
% \cs{nprt@factor@\meta{\#1}}. 
%    \begin{macrocode}
  \if#3*
  \else
    \expandafter\def\csname nprt@factor@#1\endcsname{#3}%
  \fi
%    \end{macrocode}
% Define the unit name for this unit in \cs{nprt@unit@\meta{\#1}}.
%    \begin{macrocode}
  \expandafter\def\csname nprt@unit@#1\endcsname{#2}%
}
%    \end{macrocode}
% \end{macro}
% Declare the standard units.
% \cs{!} is used to delete the unit separator again. 
% This is a hack and does not work in all cases correctly.
%    \begin{macrocode}
\npdefunit{pt}{pt}{1.00000000000}
\npdefunit{bp}{bp}{0.99626400996}
\npdefunit{in}{in}{0.01383700013}
\npdefunit{ft}{ft}{0.00115308334}
\npdefunit{mm}{mm}{0.35145980351}
\npdefunit{cm}{cm}{0.03514598035}
\npdefunit{m}{m}{0.0003514598035}
\npdefunit{km}{km}{0.0000003514598035}
%    \end{macrocode}
%
%
% \subsection{Internationalization}
%
% \begin{macro}{\nprt@ifundefined}
% The normal \cs{@ifundefined} command defines the tested macro as
% side effect.
% This command is better.
% Sometimes it will hopefully be unnecessary and supported by the
% standard (with a different name, of course).
%    \begin{macrocode}
\newcommand*\nprt@ifundefined[1]{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname #1\endcsname\relax
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nprt@addto}
% Adds the code of the second argument to the macro defined in the
% first argument.
% This argument has to be specified without the preceeding backslash.
% The code is added only if the command is defined, already.
%    \begin{macrocode}
\newcommand\nprt@addto[2]{%
  \expandafter\nprt@ifundefined{#1}{}{%
    \expandafter\addto\expandafter{\csname #1\endcsname}{#2}%
  }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npaddtolanguage}
% Define \cs{npaddtolanguage\marg{Language}\marg{Language
% definitions}}.
% Adds the \meta{Language definitions} specified in argument two to
% the \meta{Language} of argument one.
% The language definitions have to be provided in a command with the
% name \cs{npstyle}\meta{Language definitions}.
% The switching-on command is added to \cs{extras\meta{Language}}
% while the switching-off command \cs{npstyledefault} is added to
% \cs{noextras\meta{Language}}.
%
% For example, \cs{npaddtolanguage\{UKenglish\}\{english\}} adds the
% command \cs{npstyleenglish} to \cs{extrasUKenglish} and
% \cs{npstyledefault} to \cs{noextrasUKenglish}.
%
% The \cs{npstyle\meta{Language definitions}} commands are described
% below.
%    \begin{macrocode}
\newcommand\npaddtolanguage[2]{%
  \nprt@addto{extras#1}{\csname npstyle#2\endcsname}%
  \nprt@addto{noextras#1}{\npstyledefault}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npstyledefault}
% Set the default values for the separators. 
% They are set to the German language because of compatibility with
% older versions.
%    \begin{macrocode}
\newcommand*\npstyledefault{%
  \npthousandsep{\,}%
  \npdecimalsign{,}%
  \npproductsign{\cdot}%
  \npunitseparator{\,}%
  \npdegreeseparator{}%
  \npcelsiusseparator{\nprt@unitsep}%
  \nppercentseparator{\nprt@unitsep}%
}
%    \end{macrocode}
% \end{macro}
% Set the default settings (that are actually the same as German).
%    \begin{macrocode}
    \npstyledefault
%    \end{macrocode}
% \begin{macro}{\npstylegerman}
% Sets the parameters to German habit.
%    \begin{macrocode}
\newcommand*\npstylegerman{%
  \npthousandsep{\,}%
  \npdecimalsign{,}%
  \npproductsign{\cdot}%
  \npunitseparator{\,}%
  \npdegreeseparator{}%
  \npcelsiusseparator{\nprt@unitsep}%
  \nppercentseparator{\nprt@unitsep}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npstyleenglish}
% Sets the parameters to English habit.
%    \begin{macrocode}
\newcommand*\npstyleenglish{%
  \npthousandsep{,}%
  \npdecimalsign{.}%
  \npproductsign{\times}%
  \npunitseparator{\,}%
  \npdegreeseparator{}%
  \npcelsiusseparator{\nprt@unitsep}%
  \nppercentseparator{\nprt@unitsep}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npstyleportuguese}
% \changes{1.37}{2007/01/08}{Change thousand separator for Portuguese
%   from ``\cs{,}'' to ``\texttt{.}''}%
% Sets the parameters to Portuguese habit.
%    \begin{macrocode}
\newcommand*\npstyleportuguese{%
  \npthousandsep{.}%
  \npdecimalsign{,}%
  \npproductsign{\cdot}%
  \npunitseparator{\,}%
  \npdegreeseparator{}%
  \npcelsiusseparator{\nprt@unitsep}%
  \nppercentseparator{\nprt@unitsep}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npstyledutch}
% Sets the parameters to Dutch habit.
%    \begin{macrocode}
\newcommand*\npstyledutch{%
  \npthousandsep{\,}%
  \npdecimalsign{,}%
  \npproductsign{\cdot}%
  \npunitseparator{\,}%
  \npdegreeseparator{}%
  \npcelsiusseparator{\nprt@unitsep}%
  \nppercentseparator{}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\npstylefrench}
% Sets the parameters to French habit.
%    \begin{macrocode}
\newcommand*\npstylefrench{%
  \npthousandsep{~}%
  \npdecimalsign{,}%
  \npproductsign{\cdot}%
  \npunitseparator{\,}%
  \npdegreeseparator{}%
  \npcelsiusseparator{\nprt@unitsep}%
  \nppercentseparator{\nprt@unitsep}%
}
%    \end{macrocode}
% \end{macro}
% Do the following actions at \cs{begin\{document\}} to ensure that it
% is done after loading \texttt{babel.sty} if it is loaded at all.
%    \begin{macrocode}
\AtBeginDocument{%
%    \end{macrocode}
% By default, automatic language support is switched off for
% compatiblity reasons.
% Proceed only if it is switched on.
%    \begin{macrocode}
  \ifnprt@autolanguage
%    \end{macrocode}
% Automatic language support only works with babel.
%    \begin{macrocode}
    \@ifpackageloaded{babel}{%
%    \end{macrocode}
% Adds the language settings to the known languages if they are
% provided by babel.
% The current version knows all German, English, Portuguese, Dutch,
% and French dialects.
%    \begin{macrocode}
      \npaddtolanguage{UKenglish}{english}%
      \npaddtolanguage{USenglish}{english}%
      \npaddtolanguage{afrikaans}{dutch}%
      \npaddtolanguage{american}{english}%
      \npaddtolanguage{austrian}{german}%
      \npaddtolanguage{british}{english}%
      \npaddtolanguage{canadian}{english}%
      \npaddtolanguage{dutch}{dutch}%
      \npaddtolanguage{english}{english}%
      \npaddtolanguage{german}{german}%
      \npaddtolanguage{naustrian}{german}%
      \npaddtolanguage{ngerman}{german}%
      \npaddtolanguage{brazil}{portuguese}%
      \npaddtolanguage{brazilian}{portuguese}%
      \npaddtolanguage{portuges}{portuguese}%
      \npaddtolanguage{portuguese}{portuguese}%
      \npaddtolanguage{francais}{french}%
      \npaddtolanguage{canadien}{french}%
      \npaddtolanguage{acadian}{french}%
      \npaddtolanguage{french}{french}%
      \npaddtolanguage{frenchb}{french}%
%    \end{macrocode}
% Set the active language again to activate the extras section.
%    \begin{macrocode}
      \expandafter\selectlanguage\expandafter{\languagename}%
    }{%
%    \end{macrocode}
% If |babel| is not loaded but automatic language support is
% activated, switch to English as default:
%    \begin{macrocode}
      \npstyleenglish
    }%
  \fi
}
%    \end{macrocode}
% Load configuration file if present.
%    \begin{macrocode}
\InputIfFileExists{numprint.cfg}{%
  \message{Configuration file `numprint.cfg' loaded.}%
}{%
  \message{No configuration file `numprint.cfg' found.}%
}
%    \end{macrocode}
% \begin{macro}{\nprt@renameerror}
% A command for producing an error message for redefined macros.
%    \begin{macrocode}
\newcommand*\nprt@renameerror[1]{%
  \expandafter\def\csname #1\endcsname{%
    \PackageError{numprint}{This command has been renamed
      to\MessageBreak
      \string\np #1}{In order to avoid problems with other
      packages and for consistency, this\MessageBreak
      command has been renamed in this version.}%
  }%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\fourdigitsep}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npfourdigitsep}}%
% \begin{macro}{\fourdigitnosep}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npfourdigitnosep}}%
% \begin{macro}{\addmissingzero}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npaddmissingzero}}%
% \begin{macro}{\noaddmissingzero}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npnoaddmissingzero}}%
% \begin{macro}{\digits}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npdigits}}%
% \begin{macro}{\nodigits}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npnodigits}}%
% \begin{macro}{\exponentdigits}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npexponentdigits}}%
% \begin{macro}{\noexponentdigits}
% \changes{1.00}{2003/10/07}{Renamed to \cs{npnoexponentdigits}}%
% Define replacements for the old commands that produce error
% messages.
%    \begin{macrocode}
\nprt@renameerror{fourdigitsep}
\nprt@renameerror{fourdigitnosep}
\nprt@renameerror{addmissingzero}
\nprt@renameerror{noaddmissingzero}
\nprt@renameerror{digits}
\nprt@renameerror{nodigits}
\nprt@renameerror{exponentdigits}
\nprt@renameerror{noexponentdigits}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \iffalse
%</package>
% \fi
% \Finale

