Debian Codegraph @

texmf-dist/source/latex/numprint/numprint.dtx

raw
1 % \iffalse meta comment
2 % File: numprint.dtx Copyright (C) 2000--2005, 2007, 2008, 2012 Harald Harders
3 % \fi
4 %
5 % \iffalse
6 %
7 %<*driver>
8 \listfiles
9 \documentclass[ngerman,english,a4paper]{ltxdoc}
10 \usepackage[T1]{fontenc}
11 \IfFileExists{numprint.sty}{%
12 \usepackage[warning,debug,autolanguage,boldmath,np]{numprint}
13 }{%
14 \GenericWarning{numprint.dtx}{Package file numprint.sty not found
15 (Documentation will be messed up!^^J^^A
16 Generate numprint.sty by (La)TeXing numprint.ins, process
17 numprint.dtx again)^^J}\stop
18 }
19 \IfFileExists{eco.sty}{%
20 \usepackage{eco}
21 \renewcommand*\ttdefault{cmtt}
22 }{%
23 \GenericWarning{numprint.dtx}{Package file eco.sty not found
24 (Documentation will be less clear than possible)}
25 }
26 \usepackage{longtable}
27 \usepackage{mathcomp}
28 \usepackage{babel}
29 \usepackage{url}
30 \usepackage{color}
31 \IfFileExists{booktabs.sty}{\usepackage{booktabs}}{%
32 \GenericWarning{numprint.dtx}{Package file booktabs.sty not
33 found. Documentation formatting will be poor}%
34 \def\toprule\hline
35 \def\midrule\hline
36 \def\bottomrule\hline}
37 \GlossaryPrologue{\section*{{Change History}}%
38 \markboth{{Change History}}{{Change History}}%
39 Since the version~1.00 is an entirely new implementation, the Change
40 History prior version~1.00 has been lost in this document. Have a
41 look to \texttt{numprint032.dtx} or \texttt{README} to get it.
42 }
43 \GetFileInfo{numprint.sty}
44 \title{The numprint package}
45 \author{Harald Harders\\\texttt{[email protected]}}
46 \date{Version \fileversion, \filedate; printed \today}
47 \npdecimalsign{.}%
48 \newlength{\tempdima}%
49 \makeatletter
50 \renewenvironment{table}[1][]{%
51 \@float{table}[#1]%
52 \centering%
53 \setlength{\tempdima}{\abovecaptionskip}%
54 \setlength{\abovecaptionskip}{\belowcaptionskip}%
55 \setlength{\belowcaptionskip}{\tempdima}%
56 }{%
57 \end@float
58 }
59 \def\meta@font@select{\normalfont\itshape}
60 \makeatother
61 %%
62 \EnableCrossrefs
63 \CodelineIndex
64 \DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter}
65 \DoNotIndex{\setcounter,\space,\if,\else,\fi,\empty,\@empty,\ifx,\fi}
66 \DoNotIndex{\ifnum,\fi,\expandafter,\csname,\endcsname,\the}
67 \DoNotIndex{\MessageBreak,\message,\newlength,\newif,\xdef,\newcount}
68 \DoNotIndex{\begingroup,\endgroup,\,,\@tempcnta,\@tempdima,\advance}
69 \DoNotIndex{\ensuremath,\filedate,\fileversion,\docdate}
70 \DoNotIndex{\mathit,\mathrm,\mathsf,\nprt@tmp,\nprt@tmpnum,\relax}
71 \DoNotIndex{\protect,\renewcommand,\setlength,\settowidth,\stepcounter}
72 \DoNotIndex{\string}
73 \CodelineNumbered
74 \RecordChanges
75 \CheckSum{2257}
76 \begin{document}
77 \DocInput{numprint.dtx}
78 \end{document}
79 %</driver>
80 % \fi
81 %
82 % \changes{1.38}{2008/02/17}{Replaced \cs{stepcounter} and
83 % \cs{addtocounter} by \cs{advance}
84 % because otherwhise, \cs{numprint} does not work inside
85 % \cs{ensuremath}\{\cs{text}\{\$\ldots\$\}\}.}%
86 % \changes{1.38}{2008/02/17}{Moved counters \cs{nprt@curpos} and
87 % \cs{nprt@rndpos} outside the macro definitions to avoid an overflow
88 % of counters}%
89 % \changes{1.37}{2007/01/08}{Add support for French}%
90 % \changes{1.37}{2007/01/08}{Add an own separator for \textcelsius}%
91 % \changes{1.37}{2007/01/08}{Use separator for percent also for permil}%
92 % \changes{1.36}{2005/07/12}{Add support for Dutch}%
93 % \changes{1.36}{2005/07/12}{Improve documentation}%
94 % \changes{1.35}{2005/07/11}{Support not to separate percent sign from
95 % number}%
96 % \changes{1.30}{2004/08/11}{Add the commands \cs{lenprint} and
97 % \cs{cntprint} that print lengths and counters.}%
98 % \changes{1.22}{2004/08/08}{Use \cs{npunitcommand} to typeset units}%
99 % \changes{1.21}{2004/08/01}{Add support for Portuguese}%
100 % \changes{1.20}{2004/07/27}{Remove the reduction in font sizes in
101 % documentation}%
102 % \changes{1.20}{2004/07/27}{Allow \cs{numprint\{-e5\}} in addition to
103 % \cs{numprint\{e5\}}}%
104 % \changes{1.20}{2004/07/27}{Add padding a number on the left side}%
105 % \changes{1.13}{2004/04/01}{Small fix in documentation}%
106 % \changes{1.12}{2004/02/12}{Adapt Makefile to \TeX Live}%
107 % \changes{1.11}{2003/11/09}{Avoid use of \cs{fileversion} etc.}%
108 % \changes{1.00}{2003/10/07}{Total new implementation}%
109 %
110 % \maketitle
111 % \begin{abstract}
112 % \noindent
113 % This package prints numbers with a separator every three digits and
114 % convert numbers given as |12345.6e789| to
115 % {\npstylegerman\numprint{12345,6e789}}.
116 % Numbers are printed in the current mode (text or math) in order to use
117 % the correct font.
118 %
119 % Many things, including the decimal sign, the thousand separator, as
120 % well as the product sign can be changed by the user, e.g., to reach
121 % \numprint{12,345.6e789}.
122 % If requested, numprint can round numbers to a given number of digits.
123 %
124 % If an optional argument is given it is printed upright as unit.
125 % Numbers can be rounded to a given number of digits.
126 %
127 % The package supports an automatic, language-dependent change of the
128 % number format.
129 %
130 % Tabular alignment using the |tabular|(|*|), |array|, |tabularx|, and
131 % |longtable| environments (similar to the |dcolumn| and |rccol| packages)
132 % is supported using all features of numprint. Additional text can be
133 % added before and after the formatted number.
134 %
135 % If you want to print numbers with different bases (octal,
136 % hexadecimal, etc.) use the |nbaseprt| package which comes with the
137 % |numprint| package.
138 % \end{abstract}
139 %
140 % \tableofcontents
141 %
142 % \section*{Copyright}
143 % Copyright 2000--2005, 2007, 2008, 2012 Harald Harders.
144 %
145 % This program can be redistributed and/or modified under the terms
146 % of the LaTeX Project Public License Distributed from CTAN
147 % archives in directory macros/latex/base/lppl.txt; either
148 % version 1 of the License, or any later version.
149 %
150 % \section*{Remarks}
151 %
152 % \begingroup
153 % \itshape
154 % \sloppypar
155 % The \cs{fourdigitsep}, \cs{fourdigitnosep},
156 % \cs{addmissingzero}, \cs{noaddmissingzero}, \cs{digits},
157 % \marginpar{\raggedleft\bfseries\Huge !}%
158 % \cs{nodigits}, \cs{exponentsdigits}, and \cs{noexponentdigits}
159 % commands have been renamed to \cs{npfourdigitsep},
160 % \cs{npfourdigitnosep}, \cs{npaddmissingzero},
161 % \cs{npnoaddmissingzero}, \cs{npdigits}, \cs{npnodigits},
162 % \cs{npexponentsdigits}, resp.\ \cs{npnoexponentdigits}.
163 %
164 % From version 1.00 to 1.10, the column types have been changed; see
165 % section~\ref{sec:tabular}.
166 % \marginpar{\raggedleft\bfseries\Huge !}%
167 % If you want to preserve the old column types, use the package option
168 % |oldcolumntypes|.
169 % \endgroup
170 %
171 % For typesetting this documentation, the usage of different font
172 % shapes has been reduced as much as possible in order to save disk
173 % memory and download times.
174 % Thus, for nearly all characters, the design size 10\,pt has been
175 % used.
176 % This reduced the size of the PDF file for version 1.10 from 858\,KB
177 % to 396\,KB.
178 % Please excuse that shortcoming in the typography.
179 %
180 %
181 % \section{Load the package}
182 %
183 % To use this package place
184 % \begin{verbatim}
185 %\usepackage{numprint}\end{verbatim}
186 % in the preamble of your document.
187 % No options are necessary but some are available.
188 % They are mentioned where their usage is described and in
189 % section~\ref{sec:package-options}.
190 %
191 % \section{Print numbers in text and math mode}
192 %
193 % \DescribeMacro{\numprint}%
194 % This package provides the command
195 % \cs{numprint\oarg{unit}\marg{number}} that prints the \meta{number}
196 % given in the required argument.
197 % The number is printed in the current mode (math or text mode) so
198 % that an eventual chosen difference between mathematical and text
199 % numbers stays visible (e.g., by using the eco package).
200 %
201 % Numbers may contain of these characters:
202 % ``|+-\pm0123456789.,eEdD|''.
203 % Spaces, ``\cs{,}'' as well as ``\texttt{\~}'' in the argument are
204 % ignored.
205 % Either a ``|,|'' or a ''|.|'' can be used as decimal sign.
206 % By default, no thousand separators are allowed in the
207 % argument.\footnote{Section~\ref{sec:custom-parsing} describes how
208 % this can be changed.}
209 % ``|E|'', ``|e|'', ``|D|'', or ``|d|''\footnote{This is useful for
210 % FORTRAN produced numbers.} is converted to an exponential format
211 % (e.g., $x\cdot 10^{y}$ or $x\times 10^{y}$, depending on the
212 % format settings described later).
213 % ``|\pm|'' and ``|+-|'' produce a $\pm$.
214 %
215 % For example, typing
216 % \begin{verbatim}
217 %\numprint{-123456}; \numprint{\pm 123456}; \numprint{+-3,1415927e-3.1}\end{verbatim}
218 % leads to ``\numprint{-123456}; \numprint{\pm 123456};
219 % \numprint{+-3,1415927e-3.1}''.
220 % Notice that ``|.|'' and ``|,|'' can be mixed within one number and
221 % are converted to the chosen decimal sign for the output.
222 %
223 % The number is printed in the active mode (text mode resp.\ math
224 % mode).
225 % This may be important if the digits are different in text and math
226 % mode as in this document that uses old-style figures in text and
227 % lining figures in math mode.\footnote{This is only the case if the
228 % \texttt{eco} package is available on your system.}
229 % See the difference between
230 % ``\numprint{123456.134e123}'' and ``$\numprint{123456.134e123}$'',
231 % produced by
232 % \begin{verbatim}
233 %``\numprint{123456.134e123}'' and ``$\numprint{123456.134e123}$''\end{verbatim}
234 %
235 % If no number is given before the exponential characters ``|e|'',
236 % ``|E|'', ``|d|'', resp.\ ``|D|'', a pure exponential format is
237 % generated.
238 % For example, typing
239 % \begin{verbatim}
240 %\numprint{e4.3242}\end{verbatim}
241 % leads to ``\numprint{e4.3242}''.
242 % This also works with given signs, e.g.,
243 % \begin{verbatim}
244 %\numprint{-e4.3242}, \numprint{+-e4.3242} \end{verbatim}
245 % leads to ``\numprint{-e4.3242}, \numprint{+-e4.3242}''.
246 %
247 % Since \cs{numprint} expands the argument before typesetting it you
248 % may also use commands inside the argument, e.g.,
249 % \begin{verbatim}
250 %\def\numberbefore{1234}%
251 %\def\totalnumber{\numberbefore.5678}%
252 %\numprint{\totalnumber}\end{verbatim}
253 % leads to
254 % ``{\def\numberbefore{1234}\def\totalnumber
255 % {\numberbefore.5678}\numprint{\totalnumber}}''.
256 %
257 % If the optional argument is given it is printed as a \meta{unit} in
258 % math mode with an upright font (\verb|\mathrm|), e.g.,
259 % \begin{verbatim}
260 %\numprint[N/mm^2]{-123456}\end{verbatim}
261 % leads to ``\numprint[N/mm^2]{-123456}''.
262 %
263 % \changes{1.00}{2003/10/07}{Automatically don't separate degree sign
264 % from number}%
265 % By default, the space between the number and the unit is \cs{,}.
266 % One exception is the degree symbol which is typeset without a
267 % distance to the number, e.g., $\numprint[\tcdegree]{360}$ in
268 % contrast to $\numprint[\tccelsius]{273,15}$ (only a single degree
269 % symbol is typeset without a separator).
270 % The |numprint| package detects this automatically if the
271 % \cs{tcdegree} command of the |mathcomp| package, the \cs{textdegree}
272 % command of the |textcomp| package, or the \cs{degree} command of the
273 % |gensymb| package is used, e.g.,
274 % \begin{verbatim}
275 %\numprint[\tcdegree]{360}, \numprint[\degree]{360}\end{verbatim}
276 % Unfortunately, typing in the ``\texttt{\textdegree}'' sign directly
277 % cannot be detected (any help welcome).
278 %
279 % You can change the spacing between the number and units, percent
280 % signs, or degree symbols.
281 % Have a look to Section~\ref{sec:changing-output}.
282 %
283 %
284 % \changes{1.32}{2004/09/13}{Improve documentation about
285 % \texttt{textcomp} symbols}%
286 % If you want to use one of the |textcomp| symbols \textcelsius\
287 % (\cs{textcelsius}), \textohm\ (\cs{textohm}), \textmu\
288 % (\cs{textmu}), or \textperthousand\ (\cs{textperthousand})\ you have
289 % to load either the |mathcomp| or the |gensymb| package because the
290 % unit is printed in math mode.
291 % If you decide to use the |textomp| package use \cs{tc\meta{name}}
292 % instead of \cs{text\meta{name}}, e.g., \cs{tccelsius} instead of
293 % \cs{textcelsius}.
294 % If using |gensymb| just use \cs{\meta{name}}, e.g.,
295 % \cs{celsius}.\footnote{If you still use \cs{text\meta{name}}
296 % numprint uses \cs{tc\meta{name}} or \cs{\meta{name}} and generates a
297 % warning if one of these commands is available, and produces an error
298 % if not.}
299 %
300 %
301 % \DescribeMacro{\np}
302 % Since it is timeconsuming to type in the long command \cs{numprint}
303 % for every number in a text the shortcut \cs{np} can be defined by
304 % specifying the package option~\texttt{np}.
305 %
306 % By default, numbers are written in the format
307 % \begingroup
308 % \npstyledefault
309 % \numprint{12345,12345e12345},
310 % \endgroup
311 % for instance.
312 % This means, decimal sign ``\texttt{,}'', thousand
313 % separator ``\cs{,}'', and product sign
314 % ``\texttt{\{\}\cs{cdot}\{\}}''.
315 % This accords to German number formats and is a result of the history
316 % of this package.
317 % How you can change this is described in the following sections.
318 % Especially, have a look at the |autolanguage| package option in
319 % section~\ref{sec:international}.
320 %
321 %
322 % \subsection{Print counters and lengths}
323 %
324 % If you want to print a counter or a length, you may of course use
325 % \begin{verbatim}
326 %\numprint{\arabic{page}}\end{verbatim}
327 % resp.
328 % \begin{verbatim}
329 %\makeatletter
330 %\numprint[pt]{\strip@pt\textwidth}
331 %\makeatother\end{verbatim}
332 % But these methods are not really nice.
333 %
334 % \DescribeMacro{\cntprint}%
335 % For printing counters, you may use
336 % \cs{cntprint\oarg{unit}\marg{counter}} where \meta{unit} is an
337 % optional unit that is printed as by \cs{numprint}.
338 % \meta{counter} is the name of a \LaTeX\ counter, for example,
339 % \begin{verbatim}
340 %$\cntprint{page}$\end{verbatim}
341 % leads to ``$\cntprint{page}$''.
342 %
343 % \DescribeMacro{\lenprint}%
344 % Lengths can be printed using \cs{lenprint\oarg{unit}\marg{length}}.
345 % \meta{length} is the macro containing a \LaTeX\ length or a \TeX\
346 % dimension, e.g., \cs{textwidth}.
347 % \meta{unit} is a different thing here.
348 % If the unit is not given \cs{lenprint} uses \LaTeX's standard and
349 % prints the length in |pt|:
350 % \begin{verbatim}
351 %$\lenprint{\textwidth}$\end{verbatim}
352 % leads to ``$\lenprint{\textwidth}$''.
353 % Giving |pt| does not change anything.
354 % But if you use other units, e.g., |mm|, |cm|, or |in|, the length is
355 % written using the given unit:
356 % \begin{verbatim}
357 %$\lenprint[pt]{\textwidth}$,
358 %$\lenprint[in]{\textwidth}$,
359 %$\lenprint[bp]{\textwidth}$,
360 %$\lenprint[mm]{\textwidth}$,
361 %$\lenprint[cm]{3\textwidth}$\end{verbatim}
362 % gives ``$\lenprint[pt]{\textwidth}$,
363 % $\lenprint[in]{\textwidth}$,
364 % $\lenprint[bp]{\textwidth}$,
365 % $\lenprint[mm]{\textwidth}$,
366 % $\lenprint[cm]{3\textwidth}$''.
367 %
368 % As you can see in the example, it is also possible to specify a
369 % factor in the argument, e.g. |3\textwidth|.
370 % When printing lengths, it is often desirable not to print all
371 % decimal places.
372 % |numprint| can round numbers, described in section~\ref{sec:round}.
373 %
374 % \cs{lenprint} knows the units |pt|, |bp|, |in|, |ft|, |mm|, |cm|,
375 % |m|, and |km|.
376 % Section~\ref{sec:more-units} describes how to add or change units.
377 %
378 %
379 % \section{Customization}
380 %
381 % \subsection{Eliminate separators for four-digit numbers}
382 %
383 % At least in German it is common not to add a separator to four-digit
384 % numbers in non-technical texts, e.g., to typeset
385 % {\npfourdigitnosep``\numprint{1234}''} instead of ``\numprint{1234}'',
386 % but longer numbers are separated: ``\numprint{12345}''.
387 % If a number, in contrast, has less than five digits on one side of
388 % the decimal sign but five or more digits on the other side,
389 % separators are inserted on both sides, e.g.,
390 % {\npfourdigitnosep``\numprint{1234,1234}'' but
391 % ``\numprint{1234,12345}''}.
392 %
393 % \DescribeMacro{\npfourdigitsep}%
394 % \DescribeMacro{\npfourdigitnosep}%
395 % This behaviour can be achieved using the command
396 % \cs{npfourdigitnosep}.
397 % If using this switch inside a group the change is local.
398 % You can switch back to separating with \cs{npfourdigitsep}.
399 % An example:
400 % \begin{verbatim}
401 %\npfourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ --
402 %\npfourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$\end{verbatim}
403 % Leads to
404 % {``\npfourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ --
405 % \npfourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$''.}
406 % Default values can be set by the package options |sepfour| and
407 % |nosepfour|.
408 %
409 %
410 % \subsection{Add missing zeros before or after decimal sign}
411 %
412 % \DescribeMacro{\npaddmissingzero}%
413 % \DescribeMacro{\npnoaddmissingzero}%
414 % Sometimes people let out a leading zero or a zero after the
415 % decimalsign, e.g., ``|123.|'' or ``|.123|''.
416 % Numprint can add the left out zero, when \cs{addmissingzero} is
417 % used.
418 % If, however, no decimal sign is given, e.g., ``|123|'', no decimal
419 % sign or zero is appended.
420 % Adding zeros can be switched off with \cs{noaddmissingzero}.
421 % The corresponding package options are |addmissingzero| and
422 % |noaddmissinzero|.
423 % The default is |addmissingzero|.
424 %
425 %
426 % \subsection{Add a plus sign}%
427 % \changes{1.00}{2003/10/07}{Support for adding a plus to a number}%
428 %
429 % \DescribeMacro{\npaddplus}%
430 % \DescribeMacro{\npnoaddplus}%
431 % Using the \cs{npaddplus} command or the package option |addplus|, a
432 % plus sign can be added to a number that is specified without a
433 % sign.
434 % This can be switched off using \cs{npnoaddplus} resp.\ |noaddplus|.
435 %
436 % \DescribeMacro{\npaddplusexponent}%
437 % \DescribeMacro{\npnoaddplusexponent}%
438 % The commands \cs{npaddplusexponent} and \cs{npnoaddplusexponent}
439 % resp.\ the package options |addplusexponent| and |noaddplusexponent|
440 % do the same for the exponents that the commands/options described
441 % above do for the number.
442 %
443 %
444 % \subsection{Rounding numbers}%
445 % \label{sec:round}%
446 %
447 % \DescribeMacro{\nprounddigits}%
448 % \DescribeMacro{\nproundexpdigits}%
449 % \DescribeMacro{\npnoround}%
450 % \DescribeMacro{\npnoroundexp}%
451 % By default, as many digits are printed after the decimal sign, as
452 % the \cs{numprint} command gets as argument.
453 % This behaviour can be changed to print a given number of digits
454 % where the number is rounded resp.\ filled with zeros.
455 %
456 % This can be switched on using the
457 % \cs{nprounddigits\marg{digits}} command for ordinary
458 % numbers and the \cs{nproundexpdigits\marg{digits}}
459 % command for exponents.
460 % Rounding is switched off with \cs{npnoround} resp.\
461 % \cs{npnoroundexp}.
462 % For example,
463 % \begin{verbatim}
464 %\nprounddigits{2}$\numprint{1.123}$, $\numprint{1.149}$,
465 %$\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$ --
466 %\npnoround$\numprint{1.123}$, $\numprint{1.149}$,
467 %$\numprint{1}$, $\numprint{9.999}$, $\numprint{-9.999}$\end{verbatim}
468 % leads to
469 % ``\nprounddigits{2}$\numprint{1.123}$, $\numprint{1.149}$,
470 % $\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$ --
471 % \npnoround$\numprint{1.123}$, $\numprint{1.149}$,
472 % $\numprint{1}$, $\numprint{9.999}$, $\numprint{-9.999}$''
473 %
474 %
475 % \subsection{Padding a number on the left side}%
476 %
477 % \DescribeMacro{\nplpadding}%
478 % \DescribeMacro{\npnolpadding}%
479 % Sometimes it is desireable to have a number of a fixed length with
480 % the missing digits filled with a character (mostly the character
481 % ``0'', so this is the default).
482 % This can be achieved calling
483 % \cs{nplpadding\oarg{character}\marg{digits}}.
484 % This affects only the mantissa, the part after the decimal sign and
485 % signs are not counted!
486 % If the orginal number has more digits than \meta{digits} no
487 % characters will be inserted.
488 % For example,
489 % \begin{verbatim}
490 %\nplpadding{6}%
491 %$\numprint{1234}$, $\numprint{-1234}$,
492 %$\numprint{12345678}$, $\numprint{1234.5678}$ --
493 %\nplpadding[x]{6}%
494 %$\numprint{1234}$, $\numprint{-1234}$,
495 %$\numprint{12345678}$, $\numprint{1234.5678}$\end{verbatim}
496 % leads to \begingroup
497 % ``\nplpadding{6}$\numprint{1234}$, $\numprint{-1234}$,
498 % $\numprint{12345678}$, $\numprint{1234.5678}$ --
499 % \nplpadding[x]{6}$\numprint{1234}$, $\numprint{-1234}$,
500 % $\numprint{12345678}$, $\numprint{1234.5678}$''
501 % \endgroup
502 %
503 % \cs{npnolpadding} switches padding off.
504 %
505 %
506 % \subsection{Replace zeros by other characters}
507 %
508 % \DescribeMacro{\npreplacenull}%
509 % \DescribeMacro{\npprintnull}%
510 % For amounts of money, sometimes a zero after the decimal sign is
511 % replaced by different symbols, as for example ``---''.
512 % This can be done by calling the command
513 % \cs{npreplacenull\marg{replacement}}, e.g.,
514 % \begin{verbatim}
515 %\npreplacenull{\mbox{---}}\end{verbatim}
516 % Here, \cs{mbox} guarantees that ``---'' is printed in text
517 % mode.\footnote{You should better use \texttt{amsmath} and the
518 % command \cs{text} which preserves the correct text size, too.}
519 %
520 % It can be switched off using \cs{npprintnull}.
521 %
522 %
523 % \subsection{Change the format of units}
524 %
525 % \DescribeMacro{\npunitcommand}%
526 % By default, the unit is printed in math mode with an upright font.
527 % This is reached by using the \cs{npunitcommand} macro which by
528 % default is defined as follows:
529 % \begin{verbatim}
530 %\newcommand*\npunitcommand[1]{\ensuremath{\mathrm{#1}}}\end{verbatim}
531 % If you want to change this, redefine the \cs{npunitcommand}.
532 % You really should use either \cs{ensuremath} or
533 % \cs{text}\footnote{Provided by \texttt{amsmath}.} to ensure math or
534 % text mode respectively.
535 % \cs{npunitcommand} has to take one mandatory argument.
536 %
537 % For example, a blue unit is reached by
538 % \begin{verbatim}
539 %\renewcommand*\npunitcommand[1]{\ensuremath{\color{blue}\mathrm{#1}}}\end{verbatim}
540 % And here is the result:
541 %\begingroup
542 %\renewcommand*\npunitcommand[1]{\ensuremath{\color{blue}\mathrm{#1}}}%
543 %\numprint[N/mm^2]{300}
544 %\endgroup
545 %
546 %
547 % \section{Add more units to \cs{lenprint}}%
548 % \label{sec:more-units}%
549 %
550 % \DescribeMacro{\npdefunit}%
551 % The command \cs{npdefunit\marg{unitname}\marg{unit}\marg{scale}} can
552 % be used to define new units or to redefine existing ones.
553 % For example, |mm| is defined as follows:
554 % \begin{verbatim}
555 %\npdefunit{mm}{mm}{0.35145980351}\end{verbatim}
556 % The first argument \meta{unitname} is the \LaTeX\ internal name that
557 % will be given as unit in the \cs{lenprint} command.
558 % The second argument \meta{unit} is the text that will be printed
559 % out.
560 %
561 % The \meta{scale} arises from the fact that the default unit
562 % $\mathrm{pt}$ is defined as $\np[pt]{1} = 1/\np[in]{72,27} =
563 % \np[in]{0,01383700013}$ and $\np[in]{1} = \np[mm]{25,4}$.
564 % Thus, $\np[pt]{1} = \np{0,01383700013} \times \np[mm]{25,4} =
565 % \np[mm]{0.35145980351}$.
566 % For defining a new unit, the factor from $\mathrm{pt}$ to the
567 % desired unit has to be calculated and given as third argument of
568 % \cs{npdefunit}.
569 % To redefine a unit with unchanged scale, use |*| instead.
570 % For example,
571 % \begin{verbatim}
572 %\npdefunit{in}{\!''}{*}\end{verbatim}
573 % redefines |in| to print $\mathrm{''}$ as unit instead of the default
574 % $\mathrm{in}$.
575 % The \cs{!} is used to remove the separator between number and unit
576 % (\cs{,}) again.
577 % This only works correctly if \cs{,} and \cs{!} use the same
578 % measure.
579 % \begin{verbatim}
580 %$\lenprint[in]{\textwidth}$,
581 %\npdefunit{in}{\!''}{*}%
582 %$\lenprint[in]{\textwidth}$\end{verbatim}
583 % leads to \begingroup
584 % ``$\lenprint[in]{\textwidth}$,
585 % \npdefunit{in}{\!''}{*}$\lenprint[in]{\textwidth}$''.
586 % \endgroup
587 %
588 %
589 %
590 % \section{International support}%
591 % \label{sec:international}%
592 % \changes{1.00}{2003/10/07}{Automatic support for different number
593 % formats in different languages}%
594 %
595 % As mentioned above, |numprint| uses German settings for numbers:
596 % thousand separator ``\cs{,}'', decimal sign ``\texttt{,}'', product
597 % sign ``\cs{cdot}'', unit separator \cs{,}, and no degree separator,
598 % by default.
599 % This will stay stable for compatibility with older versions even if
600 % its unlogical since the default language of \LaTeX\ is English.
601 %
602 % Using the package option |autolanguage| this can be fixed.
603 % If you are using this option without the |babel| package the
604 % settings are switched to English at \cs{begin\{document\}}.
605 % See Table~\ref{tab:defaults}.
606 %
607 % \begin{table}%
608 % \centering
609 % \caption{Default values for language settings}%
610 % \label{tab:defaults}%
611 % \begin{tabular}{lllllll}
612 % \toprule
613 % language& thousand& decimal& product& unit& percent& degree \\
614 % & sep.& sign& sign& sep.& sep.& sep. \\
615 % \midrule
616 % English& \texttt{,}& \texttt{.}& \cs{times}& \cs{,}& \cs{,}& none \\
617 % German& \cs{,}& \texttt{,}& \cs{cdot}& \cs{,}& \cs{,}& none \\
618 % Portuguese& \texttt{.}& \texttt{,}& \cs{cdot}& \cs{,}& \cs{,}& none \\
619 % Dutch& \cs{,}& \texttt{,}& \cs{cdot}& \cs{,}& none& none \\
620 % French& \texttt{\texttildelow}& \texttt{,}& \cs{cdot}& \cs{,}& \cs{,}& none \\
621 % \bottomrule
622 % \end{tabular}%
623 % \end{table}
624 %
625 % \DescribeMacro{\selectlanguage}
626 % If you are using the |babel| package in conjunction with the
627 % |autolanguage| package option, the behaviour of \cs{numprint} alters
628 % with the active language.
629 % If you, for instance, use
630 % \begin{verbatim}
631 %\selectlanguage{ngerman}\end{verbatim}
632 % the German settings are selected.
633 % If you then switch back to English, the English settings are active
634 % again.
635 %
636 % The current version supports English, German, Portuguese, Dutch, and
637 % French.
638 % Unfortunately, I don't really know how to write numbers in other
639 % languages than German.
640 % I am quite sure that the English version also is
641 % correct.\footnote{Maybe, the percent sign separator \cs{,} is not
642 % common, but I will leave its value unchanged to preserve
643 % compatibility with older versions.}
644 % But please help me to add other languages.
645 %
646 % If you want other settings than the default ones, listed in
647 % Table~\ref{tab:defaults}, please refer to
648 % Section~\ref{sec:advanced:international}.
649 %
650 % As long as |numprint| does not support your language you may add the
651 % definitions by yourself.
652 % How this can be done is also described in
653 % Section~\ref{sec:advanced:international}.
654 %
655 %
656 % \section{Print aligned numbers in tabulars}%
657 % \label{sec:tabular}%
658 % \changes{1.10}{2003/10/12}{New tabular alignment mechanism}%
659 %
660 % Aligning numbers in tabulars is providede by the \texttt{dcolumn}
661 % and \texttt{rccol} packages.
662 % But they have two disadvantages.
663 % First, they do not support typesetting numbers in the same way as
664 % \cs{numprint} does.
665 % Second, they force the numbers to be typeset in math mode.
666 % Thus, this packages provides own mechanisms to gain aligned
667 % numbers.
668 %
669 % In former versions up to 1.00, the align mechanism in tabulars has
670 % been somehow weak because the author had to repeat the \cs{numprint}
671 % call in every table cell.
672 % This has been improved in version~1.10.
673 % For compatibility reasons, the old column types |n| and |N| have
674 % been preserved if you specify the |oldcolumntypes| package option;
675 % they will be discussed in section~{sec:column:old}.
676 %
677 %
678 % \subsection{The new column types}%
679 % \label{sec:column:new}%
680 %
681 % \DescribeMacro{column type n}
682 % The |numprint| package provides the column type |n| that takes two
683 % mandatory arguments.
684 % They define the number of digits before and the number of digits
685 % after the decimal sign.
686 % The results can be seen in the left column of the tabular below.
687 % You can use this column type as the normal column types, e.g.,
688 % \begin{verbatim}
689 % \begin{tabular}{n{3}{4}n{4}{2}}\end{verbatim}
690 % The numbers are printed in a reserved space with the necessary width
691 % for the specified numbers, aligned at the decimal sign.
692 % If a column contains numbers that have an exponent it is appended
693 % left-aligned while the width of the column is extended by the
694 % required space.
695 % This is shown in the first column in the example below.
696 %
697 % If you, in addition, want to reserve space for digits in the
698 % exponent you can insert one (specify numbers of digits before the
699 % decimal sign) or two (number of digits before and after the decimal
700 % sign) optional arguments, as can be seen in columns 2 and 3 in the
701 % example below.
702 % If you reserve space for the exponent, too long exponents may exceed
703 % the tabular cell (as can be seen in the second column).
704 %
705 % This example tabular\footnote{The tabulars are ugly here. But the
706 % only important thing is to show the effects of the alignments.}
707 %\par\medskip\noindent
708 % {\tabcolsep0mm\small
709 % \begin{tabular}{|n{5}{3}|n[3]{5}{3}|n[3][1]{5}{3}|N{5}{3}|}
710 % \hline
711 % 123.45e12& 123.45e12& 123.45e12& 123.45e12 \\
712 % 12345.678e123& 12345.678e123& 12345.678e123& 12345.678e123 \\
713 % 123.45e12.3& 123.45e12.3& 123.45e12.3& 123.45e12.3 \\
714 % 12345.678e123.3& 12345.678e123.3& 12345.678e123.3& 12345.678e123.3 \\
715 % \hline
716 % \end{tabular}}
717 % \par\medskip\noindent
718 % is produced by the following code:
719 % \begin{verbatim}
720 %\tabcolsep0mm\small
721 %\begin{tabular}{|n{5}{3}|n[3]{5}{3}|n[3][1]{5}{3}|N{5}{3}|}
722 % \hline
723 % 123.45e12& 123.45e12& 123.45e12 & 123.45e12 \\
724 % 12345.678e123& 12345.678e123& 12345.678e123& 12345.678e123 \\
725 % 123.45e12.3& 123.45e12.3& 123.45e12.3& 123.45e12.3 \\
726 % 12345.678e123.3& 12345.678e123.3& 12345.678e123.3& 12345.678e123.3 \\
727 % \hline
728 %\end{tabular}\end{verbatim}
729 % The |n| column type prints the number in math mode.
730 % Thus, the first three columns in the example are printed with lining
731 % figures.
732 % \DescribeMacro{column type N}
733 % To print numbers in text mode, you can use the |N| column type as
734 % shown in column four of the tabular.\footnote{If you use a tabular
735 % environment that prints its arguments in math mode, e.g., the
736 % \texttt{array} environment, also \texttt{N} prints the numbers in
737 % math mode.}
738 % It takes the same arguments as the |n| column type.
739 %
740 % You may put additional text into tabular cells.
741 % The numprint package uses an algorithm to determine which part is
742 % the number and which is additional text.
743 % In order to preserve spaces and to use characters as text that could
744 % also be part of a number (e.g., digits or the characters ``e'',
745 % ``E'', ``d'', or ``D'') you have to enclose the text in
746 % braces, for example ``\texttt{\{hello\} 1234}'' instead of
747 % ``\texttt{hello 1234}''.
748 % (In some rare cases, even two pairs of braces is necessary.
749 % This is the case if you want to use a single character that may also
750 % be used in a number, e.g., ``\texttt{\{\{3\}\}
751 % 1234}''.\footnote{It is the same if the text starts with one of some
752 % special commands that normally don't occur at the beginning of
753 % tabular cells, \cs{end}, \cs{tabularnewline}, \cs{nprt@end},
754 % \cs{endtabular}, \cs{csname}, and \cs{relax}.})
755 % If you don't use these enclosing braces strange results may appear.
756 % For preceding text, you have to ensure that it has the same width
757 % for all lines of the same column.
758 % Have a look at the following example:
759 %\begin{verbatim}
760 %\begin{tabular}{n{2}{1}n{2}{1}n{2}{1}n[1]{2}{1}}
761 % \toprule
762 % {without braces}&
763 % {with braces}&
764 % {with braces and box}&
765 % \multicolumn{1}{l}{with braces, exp, and box}
766 % \\
767 % \midrule
768 % abc def 12,3e3 rt&
769 % {abc def } 12,3e3 { rt}&
770 % {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}&
771 % {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}
772 % \\
773 % more 45,1 txt&
774 % {more } 45,1 { txt}&
775 % {\npmakebox[abc def ][l]{more }} 45,1 { txt}&
776 % {\npmakebox[abc def ][l]{more }} 45,1 { txt}
777 % \\
778 % \midrule
779 % not blue 45,1 txt&
780 % {\color{blue}blue } 45,1 { txt}&
781 % {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}&
782 % {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}
783 % \\
784 % \bottomrule
785 %\end{tabular}
786 %\end{verbatim}
787 % The result looks as follows:
788 % \par\medskip\noindent
789 %{\footnotesize
790 %\begin{tabular}{n{2}{1}n{2}{1}n{2}{1}n[1]{2}{1}}
791 % \toprule
792 % {without braces}&
793 % {with braces}&
794 % {with braces and box}&
795 % \multicolumn{1}{l}{with braces, exp, and box}
796 % \\
797 % \midrule
798 % abc def 12,3e3 rt&
799 % {abc def } 12,3e3 { rt}&
800 % {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}&
801 % {\npmakebox[abc def ][l]{abc def }} 12,3e3 { rt}
802 % \\
803 % more 45,1 txt&
804 % {more } 45,1 { txt}&
805 % {\npmakebox[abc def ][l]{more }} 45,1 { txt}&
806 % {\npmakebox[abc def ][l]{more }} 45,1 { txt}
807 % \\
808 % \midrule
809 % not blue 45,1 txt&
810 % {\color{blue}blue } 45,1 { txt}&
811 % {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}&
812 % {\color{blue}\npmakebox[abc def ][l]{blue }} 45,1 { txt}
813 % \\
814 % \bottomrule
815 %\end{tabular}}
816 % \par\medskip\noindent
817 % In the first column, the texts before and after the number are
818 % not enlosed by braces.
819 % Then, strange results appear:
820 % In the first line, ``\texttt{de}'' is interpreted as number.
821 % Thus, it is printed in math mode, and the rest of the cell,
822 % ``\texttt{f 12,3e3 rt}'' is printed as text, again.
823 % In the second line, the part ``\texttt{e 45,1}'' is printed as
824 % number.
825 %
826 % This strange behaviour can be avoided by enclosing the texts by
827 % braces, as mentioned above and shown in the second column.
828 % Thus, the texts are printed correctly.
829 % A space in the enclosed texts can separate the text from the number,
830 % as done in the example.
831 % Since the left texts have different widths the alignment of the
832 % numbers is broken, here.
833 %
834 % This can be fixed by putting the contents in boxes, using the
835 % \cs{makebox} or \cs{npmakebox} command, as shown in the third
836 % column.
837 % \DescribeMacro{\npmakebox}
838 % The \cs{npmakebox} has a similar syntax as the \cs{makebox} command
839 % but uses a text instead of a length to determine the width of the
840 % box: \cs{npmakebox\oarg{text 1}\oarg{justification}\marg{text 2}}.
841 % The command determines which width \meta{text 1} would have and
842 % typesets \meta{text 2} into a box of this width.
843 %
844 % If you put the preceding text in each line in such a box the number
845 % will be aligned as desired.
846 %
847 % Still, the text on the right-hand side of the numbers is not
848 % aligned.
849 % This can be fixed by specifying the number of digits of the
850 % exponent, as shown in the fourth column.
851 %
852 % The third line is a little bit different from the others.
853 % Here, not only text is inserted but also a command that changes the
854 % output of the numbers.
855 % Even such commands have to be enclosed by braces.
856 %
857 % \DescribeMacro{\multicolumn}
858 % For producing tabular cells that don't contain a number, you either
859 % have to enclose the cell contents by braces or to use the
860 % \cs{multicolumn} command as shown in the first line of the example
861 % above.
862 %
863 % If you want to print a line in bold letters using the \cs{boldmath}
864 % command in math resp.\ \cs{bfseries} in text mode the alignment is
865 % not correct anymore.
866 % This is due to the fact that the bold letters are wider than the
867 % normal ones.
868 % You can avoid that problem if the font family provides a bold font
869 % shape that has the same width as the normal one.
870 % For the Computer Modern fonts, such a font shape exists.
871 % In text mode, you can access it by using
872 % \changes{1.10}{2003/10/12}{Define math version \texttt{npbold}}%
873 % \begin{verbatim}
874 % \fontseries{b}\selectfont\end{verbatim}
875 % \DescribeMacro{\mathversion}
876 % \DescribeMacro{\npboldmath}
877 % If you also want to use that font in math mode, you may use the math
878 % version |npbold| by using \cs{mathversion\{npbold\}} or
879 % \cs{npboldmath}.
880 % In order to save memory, these commands and the |npbold| math
881 % version are only available if you call |numprint.sty| using the
882 % |boldmath| package option.
883 %
884 % An example:
885 % \begin{verbatim}
886 %\begin{tabular}{lN{12}{3}n{12}{3}}
887 % \toprule
888 % normal:&
889 % 123456123456.123e12&
890 % 123456123456.123e12
891 % \\
892 % bold:&
893 % {\fontseries{b}\selectfont} 123456123456.123e12&
894 % {\npboldmath} 123456123456.123e12
895 % \\
896 % bold extended:&
897 % {\bfseries} 123456123456.123e12&
898 % {\boldmath} 123456123456.123e12
899 % \\
900 % \bottomrule
901 %\end{tabular}\end{verbatim}
902 % This produces:
903 % \par\medskip\noindent
904 %{\small
905 %\begin{tabular}{lN{12}{3}n{12}{3}}
906 % \toprule
907 % normal:&
908 % 123456123456.123e12&
909 % 123456123456.123e12
910 % \\
911 % bold:&
912 % {\fontseries{b}\selectfont} 123456123456.123e12&
913 % {\npboldmath} 123456123456.123e12
914 % \\
915 % bold extended:&
916 % {\bfseries} 123456123456.123e12&
917 % {\boldmath} 123456123456.123e12
918 % \\
919 % \bottomrule
920 %\end{tabular}}
921 %\par\medskip
922 %
923 % If you want to add the same text or commands to all lines of a
924 % tabular column, you can use the ``|>|'' specifier in the declaration
925 % of the tabular column, as usual.
926 % You have to enclose its argument in an additional pair of braces, as
927 % shown in the example below.
928 % Unfortunately, the ``|<|'' specifier does not work properly.
929 % \DescribeMacro{\npafternum}
930 % Therefore, the \cs{npafternum} command is defined that takes one
931 % argument which is printed after the number.
932 % The following example shows text before and after the number:
933 % \begin{verbatim}
934 %\begin{tabular}{%
935 % >{{before \npafternum{ after}}}n[2]{12}{3}%
936 % >{{\nprounddigits{4}}}n{3}{4}%
937 % >{{\color{blue}}}n{12}{3}}
938 % \toprule
939 % 123456123456.123e12&
940 % 12.12345&
941 % 123456.23e1
942 % \\
943 % 12345.123e12&
944 % 12.1&
945 % 14561234.562e12
946 % \\
947 % \bottomrule
948 %\end{tabular}\end{verbatim}
949 % This produces:
950 % \par\medskip\noindent
951 %{\small
952 %\begin{tabular}{%
953 % >{{before \npafternum{ after}}}n[2]{12}{3}%
954 % >{{\nprounddigits{3}}}n{3}{3}%
955 % >{{\color{blue}}}n{8}{3}}
956 % \toprule
957 % 123456123456.123e12&
958 % 12.12353&
959 % 123456.23e1
960 % \\
961 % 12345.123e12&
962 % 12.1&
963 % 14561234.562e12
964 % \\
965 % \bottomrule
966 %\end{tabular}}
967 %\par\medskip
968 % As can be seen in the second column, numbers can be rounded in
969 % special columns by inserting \cs{nproundigits} into a ``|>|''
970 % specification.
971 % This can be said for all other commands that influence the format of
972 % numbers, too.
973 %
974 % \DescribeMacro{\npunit}
975 % Normally, units should not be typeset in the cells of a tabular.
976 % But if this is needed, it may be realized using the \cs{npunit}
977 % command, as shown here:
978 % \begin{verbatim}
979 %\begin{tabular}{>{{\npunit{N/mm^2}}}n{5}{3}}
980 % \toprule
981 % 12345.123\\
982 % 12.12\\
983 % {\npunit{psi}} 234.4\\
984 % 4.3\\
985 % \bottomrule
986 %\end{tabular}\end{verbatim}
987 % This produces:
988 % \par\medskip\noindent
989 %{\small
990 %\begin{tabular}{>{{\npunit{N/mm^2}}}n{5}{3}}
991 % \toprule
992 % 12345.123\\
993 % 12.12\\
994 % {\npunit{psi}} 234.4\\
995 % 4.3\\
996 % \bottomrule
997 %\end{tabular}}
998 %\par\medskip
999 %
1000 % The tabular alignment of the |numprint| package has been tested with
1001 % the |tabular|, |tabular*|, |array|, |tabularx|~\cite{carlisle1999a},
1002 % and |longtable|~\cite{carlisle2000a} environments.
1003 % It may or may not run with other packages and environments.
1004 %
1005 %
1006 % \subsection{The old column types}%
1007 % \label{sec:column:old}%
1008 %
1009 % \newcolumntype{m}[2]{>{\npdigits{#1}{#2}$}l<{$}}%
1010 % \newcolumntype{M}[3]{>{\npdigits{#1}{#2}\npexponentdigits{#3}$}l<{$}}%
1011 %
1012 % \DescribeMacro{column type N}
1013 % If the |oldcolumntype| package option is specified the column types
1014 % |n| and |N| are defined differently than described in the previous
1015 % section.
1016 % \DescribeMacro{column type n}
1017 % The |n| column type alignes the base number to the decimal sign, the
1018 % |N| column type additionaly alignes the exponent.
1019 %
1020 % Use these commands as follows:
1021 % \begin{verbatim}
1022 %\tabcolsep0mm
1023 %\begin{tabular}{|n{5}{3}|N{5}{3}{3}|}
1024 % \hline
1025 % \numprint{123.45e12}& \numprint{123.45e12}\\
1026 % \numprint{12345.678e123}& \numprint{12345.678e123}\\
1027 % \numprint{123.45e12.3}& \numprint{123.45e12.3}\\
1028 % \numprint{12345.678e123.3}& \numprint{12345.678e123.3}\\
1029 % \hline
1030 %\end{tabular}\end{verbatim}
1031 % This leads to\par\medskip\noindent
1032 % {\tabcolsep0mm
1033 % \begin{tabular}{|m{5}{3}|M{5}{3}{3}|}
1034 % \hline
1035 % \numprint{123.45e12}& \numprint{123.45e12}\\
1036 % \numprint{12345.678e123}& \numprint{12345.678e123}\\
1037 % \numprint{123.45e12.3}& \numprint{123.45e12.3}\\
1038 % \numprint{12345.678e123.3}& \numprint{12345.678e123.3}\\
1039 % \hline
1040 % \end{tabular}}
1041 % \medskip
1042 %
1043 % The first argument defines the number of digits before the decimal
1044 % sign, the second the number after.
1045 % In case of the type \verb|N| the third option defines the number of
1046 % digits before the decimal sign in the exponent.
1047 % It is not possible to define the numbers of digits after the decimal
1048 % sign in the exponent; they are set to zero.
1049 % Notice that the command \verb|\numprint| has to be written again in
1050 % each tabular entry, using the old column types.
1051 %
1052 %
1053 % \subsection{Alignment in normal text}%
1054 %
1055 % The alignment of the numbers in tabulars is realized by writing the
1056 % number inside a box with the specified width.
1057 % This functionality can also be used outside tabular environments.
1058 % \DescribeMacro{\npdigits}
1059 % The \cs{npdigits\marg{before}\marg{after}} command switches on the
1060 % alignment of numbers printed by \cs{numprint}.
1061 % The first argument defines the number of digits before the decimal
1062 % sign while the second argument defines the number of digits after
1063 % it for the mantissa.
1064 % \DescribeMacro{\npexponentdigits}
1065 % Since exponents are normally integer numbers the syntax of the
1066 % corresponding \cs{npexponentdigits} command is slightly different.
1067 % Its syntax is \cs{npexponentdigits\oarg{after}\marg{before}}.
1068 % The mandatory argument defines the number of digits before the
1069 % decimal sign of the exponent.
1070 % If no optional argument is given, the number of digits after the
1071 % decimal sign is set to zero.
1072 % If it is given it defines the number of digits after the decimal
1073 % sign.
1074 %
1075 % If the \cs{npdigits} or \cs{npexponentdigits} commands have been
1076 % used inside a group the values are reset at the end of the group.
1077 % \DescribeMacro{\npnodigits}
1078 % \DescribeMacro{\npnoexponentdigits}
1079 % Alignment can also be switched off using the \cs{npnodigits} resp.\
1080 % \cs{npnoexponentdigits} commands.
1081 %
1082 %
1083 % \section{Error messages etc.}
1084 %
1085 % By default, \cs{numprint} produces an error message if the argument
1086 % uses some invalid characters or if the number format is invalid.
1087 % Some people use \cs{numprint} to do strange things and thus use
1088 % invalid arguments designedly.
1089 % These people may switch off these error messages by using the
1090 % package option |warning|.
1091 %
1092 % If you want some debug messages to be written into the log file, use
1093 % the package option |debug|.
1094 %
1095 %
1096 % \section{Advanced customization}%
1097 % \label{sec:advanced}%
1098 %
1099 % \subsection{Changing the output}%
1100 % \label{sec:changing-output}%
1101 %
1102 % Most of the things described in this section are not necessary to be
1103 % done by hand because the feature ``automatic language support'',
1104 % described in section~\ref{sec:international} does this
1105 % automatically.
1106 %
1107 % \subsubsection{Without the \textmd{\texttt{autolanguage}} option}
1108 %
1109 % \DescribeMacro{\npthousandsep}%
1110 % \DescribeMacro{\npthousandthpartsep}%
1111 % \DescribeMacro{\npdecimalsign}%
1112 % \DescribeMacro{\npproductsign}%
1113 % By using the commands
1114 % \cs{npdecimalsign\marg{Sign}},
1115 % \cs{npthousandsep\marg{Separator}},
1116 % \cs{npthousandthpartsep\marg{Separator}}, and
1117 % \cs{npproductsign\marg{Sign}},\footnote{These command did
1118 % not have the
1119 % ``np'' in older versions. This had to be changed in order to avoid
1120 % an incompatibiliby with the french language of babel.} several
1121 % separators and symbols can be changed, e.g.,
1122 % \begin{verbatim}
1123 %\npdecimalsign{\ensuremath{\cdot}}\npthousandsep{,}\npproductsign{*}%
1124 %\numprint{-123456}; \numprint{3,1415927e-3.2}\end{verbatim}
1125 % leads to ``{\npdecimalsign{\ensuremath{\cdot}}%
1126 % \npthousandsep{,}\npproductsign{*}%
1127 % \numprint{-123456}; \numprint{3,1415927e-3.2}}''.
1128 %
1129 % The \cs{npthousandsep} both changes the separators before and after
1130 % the decimal sign.
1131 % If you want to use different separators, you have to call
1132 % \cs{npthousandthpartsep} \emph{after} \cs{npthousandsep}.
1133 %
1134 % The separators as well as the decimal sign are typeset in the same
1135 % mode as the number itself (math or text).
1136 % If you want to guarantee a special mode, you have to use
1137 % \cs{ensuremath} for math or either \cs{mbox}, \cs{textrm}, or
1138 % \cs{text}\footnote{Provided by \texttt{amsmath}.} for text mode.
1139 %
1140 % The product sign, in contrast, is always printed in math mode.
1141 % Thus, you don't have to add \cs{ensuremath} to use math commands.
1142 %
1143 % \DescribeMacro{\global}%
1144 % If using these commands inside a group (|{|\ldots|}|,
1145 % \cs{begingroup}\ldots\cs{endgroup}, or an environment)
1146 % the behaviour of the \verb|\numprint| command is changed
1147 % only locally (inside the current group).
1148 % By preceding \verb|\global| the change can be made global inside a
1149 % group.
1150 % For example:
1151 % \begin{verbatim}
1152 %Local:
1153 %\numprint{123e4},
1154 %{\npproductsign{\cdot}\numprint{123e4}},
1155 %\numprint{123e4}.
1156 %Global:
1157 %\numprint{123e4},
1158 %{\global\npproductsign{\cdot}\numprint{123e4}},
1159 %\numprint{123e4}\end{verbatim}
1160 % leads to the following:
1161 %
1162 % \noindent Local:
1163 % \numprint{123e4},
1164 % {\npproductsign{\cdot}\numprint{123e4}},
1165 % \numprint{123e4}.
1166 % Global:
1167 % \numprint{123e4},
1168 % {\npproductsign{\cdot}\numprint{123e4},
1169 % \numprint{123e4}}
1170 %
1171 % The current version has the following defaults:
1172 % \begin{verbatim}
1173 %\npthousandsep{\,}
1174 %\npdecimalsign{,}
1175 %\npproductsign{\cdot}
1176 %\npunitseparator{\,}\end{verbatim}
1177 %
1178 % \DescribeMacro{\npunitseparator}%
1179 % The space between the number and the unit is ``\cs{,}'' by
1180 % default. It can be changed using the command
1181 % \cs{npunitseparator\marg{Separator}},
1182 % e.g.,
1183 % \begin{verbatim}
1184 %\npunitseparator{~}\end{verbatim}
1185 %
1186 % \DescribeMacro{\npdegreeseparator}%
1187 % By default, no space is added between the number an a degree symbol.
1188 % You may specify a separator for that using
1189 % \cs{npdegreeseparator\marg{Separator}}.
1190 %
1191 % \DescribeMacro{\npcelsiusseparator}%
1192 % By default, the same space as for normal units is added between the
1193 % number an \textcelsius.
1194 % You may specify a different separator for that using
1195 % \cs{npcelsiusseparator\marg{Separator}}.
1196 % Note that \cs{tccentigrade} is not supported by |numprint|.
1197 %
1198 % \DescribeMacro{\nppercentseparator}%
1199 % By default, the same space as for normal units is added between the
1200 % number and a percent sign.
1201 % You may specify a different separator for that using
1202 % \cs{nppercentseparator\marg{Separator}}.
1203 %
1204 %
1205 %
1206 % \subsubsection{With the \textmd{\texttt{autolanguage}} option}%
1207 % \label{sec:advanced:international}%
1208 %
1209 % If you are using the |autolanguage| option changes made with the
1210 % commands described in the previous section get lost at the next
1211 % change of the language or at \cs{begin\{document\}}.
1212 % Thus, they cannot be used with this option in the way described
1213 % there.
1214 %
1215 % Thus, you have to redefine the commands that set the
1216 % language-dependent numprint settings.
1217 % For each known language, a command \cs{npstyle\meta{language}} is
1218 % defined that does the changes, e.g., \cs{npstyleenglish} for
1219 % English.
1220 % \DescribeMacro{\npstyleenglish}
1221 % This command is defined as follows:
1222 % \begin{verbatim}
1223 %\newcommand*\npstyleenglish{%
1224 % \npthousandsep{,}%
1225 % \npdecimalsign{.}%
1226 % \npproductsign{\times}%
1227 % \npunitseparator{\,}%
1228 % \npdegreeseparator{}%
1229 % \npcelsiusseparator{\nprt@unitsep}%
1230 % \nppercentseparator{\nprt@unitsep}%
1231 %}\end{verbatim}
1232 %
1233 % If you want to use different settings for this language, you have
1234 % two possibilities:
1235 % \begin{enumerate}
1236 % \item
1237 % Copy the definition for \cs{npstyle\meta{language}} from the style
1238 % file and change it according to your wishes, for
1239 % example:\footnote{Notice that you have to use \cs{renewcommand*}
1240 % instead of \cs{newcommand*}.}
1241 % \begin{verbatim}
1242 %\renewcommand*\npstyleenglish{%
1243 % \npthousandsep{,}%
1244 % \npdecimalsign{{\cdot}}%
1245 % \npproductsign{\times}%
1246 % \npunitseparator{\,}%
1247 % \npdegreeseparator{}%
1248 % \npcelsiusseparator{\nprt@unitsep}%
1249 % \nppercentseparator{\nprt@unitsep}%
1250 %}\end{verbatim}
1251 % \item
1252 % Another way to add different settings to a language is to use
1253 % \cs{g@addto@macro} to append commands to an existing
1254 % \cs{npstyle\meta{language}} command, e.g.,
1255 % \begin{verbatim}
1256 %\makeatletter
1257 %\g@addto@macro\npstyleenglish{%
1258 % \nppercentseparator{}%
1259 %}%
1260 %\makeatother\end{verbatim}
1261 % This has the advantage that changes in the original command are not
1262 % lost by using a copy.
1263 % The disadvantage is that some commands may be called twice which is
1264 % slightly slower.
1265 % \end{enumerate}
1266 % The changes take effect when the style command is called the next
1267 % time; this is when the language is changed the next time or at
1268 % \cs{begin\{document\}}.
1269 %
1270 %
1271 % If the language you are using is not yet supported by |numprint| you
1272 % may add support for it in the preamble of your document.
1273 %
1274 % \DescribeMacro{\npaddtolanguage}
1275 % The simplest case is a language that uses the same settings as one
1276 % of the languages, already supported.
1277 % If, for instance, you want to use Danish with the same settings as
1278 % German, you just have to add
1279 % \begin{verbatim}
1280 %\npaddtolanguage{danish}{german}\end{verbatim}
1281 % to the preamble of your document.
1282 %
1283 % If you, instead, want to use different settings, define a
1284 % corresponding style command.
1285 % Let's take Danish as an example, again.
1286 % Define a command \cs{npstyledanish} which defines
1287 % everything you want to change against the default (I choose some
1288 % strange values for clearness):
1289 % \begin{verbatim}
1290 %\newcommand*\npstyledanish{%
1291 % \npthousandsep{.}%
1292 % \npdecimalsign{\ensuremath{\cdot}}%
1293 % \npproductsign{*}%
1294 % \npunitseparator{~}%
1295 % \npdegreeseparator{}%
1296 % \npcelsiusseparator{\nprt@unitsep}%
1297 % \nppercentseparator{\nprt@unitsep}%
1298 %}\end{verbatim}
1299 % In addition, append the call of this command to the
1300 % language-switching command for Danish:
1301 % \begin{verbatim}
1302 %\npaddtolanguage{danish}{danish}\end{verbatim}
1303 %
1304 %
1305 % \subsection{Changing the argument parsing}%
1306 % \label{sec:custom-parsing}%
1307 %
1308 % It has been said above that thousand separators are not allowed in
1309 % the argument of the \cs{numprint} command.
1310 % This can be customized by the user.
1311 %
1312 % For most elements in the input, \cs{numprint} uses lists that
1313 % contain the corresponding characters.
1314 % \DescribeMacro{\nprt@dotlist}
1315 % The macro \cs{nprt@dotlist} contains the characters interpreted as
1316 % decimal signs.
1317 % It is defined as followed:
1318 % \begin{verbatim}
1319 %\newcommand*\nprt@dotlist{.,}\end{verbatim}
1320 % If you, for example, only want to allow the dot as decimal sign,
1321 % redefined the list:
1322 % \begin{verbatim}
1323 %\renewcommand*\nprt@dotlist{.}\end{verbatim}
1324 % If you want to do this in your document rather than in the
1325 % configureation file \texttt{numprint.cfg}---see
1326 % section~\ref{sec:configuration}--- you have to enclose this by
1327 % \cs{makeatletter} and \cs{makeatother}.
1328 %
1329 % \DescribeMacro{\nprt@explist}%
1330 % The \cs{nprt@explist} command contains the characters interpreted as
1331 % delimiter between mantissa and exponent.
1332 % By default it contains ``\texttt{eEdD}''.
1333 % Redefine it as \cs{nprt@dotlist}.
1334 %
1335 % \DescribeMacro{\nprt@ignorelist}%
1336 % The \cs{nprt@ignorelist} command contains a list of characters that
1337 % are ignored in the input (in addition to spaces, ``\cs{,}'', and
1338 % ``\texttt{\~}'').
1339 % It is empty by default.
1340 % If you, for example, only want to allow dots as decimal sign and
1341 % commas may occur as thousand separators in the input, you may use
1342 % following redefinition:
1343 % \begin{verbatim}
1344 %\renewcommand*\nprt@dotlist{.}
1345 %\renewcommand*\nprt@ignorelist{,}\end{verbatim}
1346 % Then, ``\texttt{,}'' is ignored in the input and ``\texttt{.}'' is
1347 % interpreted as decimal sign.
1348 % For example,
1349 % \begin{verbatim}
1350 %\makeatletter
1351 %{\renewcommand*\nprt@dotlist{.}%
1352 %\renewcommand*\nprt@ignorelist{,}%
1353 %\numprint{12,234.123,45e1,2,3.0}}
1354 %\makeatother\end{verbatim}
1355 % leads to
1356 % \makeatletter%
1357 % {\def\nprt@dotlist{.}\def\nprt@ignorelist{,}``\numprint{12,234.123,45e1,2,3.0}}''.
1358 % \makeatother
1359 %
1360 % \DescribeMacro{\nprt@signlist}%
1361 % The \cs{nprt@signlist} command contains the list of known signs.
1362 % By default, it is set to ``\texttt{+-}\cs{pm}''.
1363 % You may change the list of accepted signs by redefining
1364 % \cs{nprt@signlist}.
1365 % If, for instance, the letter ``\texttt{*}'' is intended to be a
1366 % sign, just type in
1367 % \begin{verbatim}
1368 %\renewcommand*\nprt@signlist{+-\pm *}\end{verbatim}
1369 % This character is typeset when using it as sign.
1370 % But this indicates one problem: The sign might differ between text
1371 % and math mode, as show in the following example:
1372 % {\makeatletter\def\nprt@signlist{+-\pm *}\makeatother
1373 % In text mode, \cs{numprint\{*1234\}} occurs as ``\numprint{*1234}''
1374 % while is is typeset as ``$\numprint{*1234}$'' in math mode.}
1375 % To avoid that, you may define a command that prints the sign.
1376 % This command must have a name according to
1377 % \cs{nprt@list@\meta{sign}}.
1378 % \DescribeMacro{\nprt@sign@*}%
1379 % In this case, you have to define \cs{nprt@list@*}.
1380 % Since the sign might be arbitrary characters, you should define the
1381 % command as follows:
1382 % \begin{verbatim}
1383 %\expandafter\newcommand\csname nprt@sign@*\endcsname{{\ensuremath{*}}}\end{verbatim}
1384 % {\makeatletter\expandafter\def\csname nprt@sign@*\endcsname{{\ensuremath{*}}}%
1385 % \def\nprt@signlist{+-\pm *}\makeatother
1386 % With this command, \cs{numprint\{*1234\}} occurs as
1387 % ``\numprint{*1234}'' in text mode and as ``$\numprint{*1234}$'' in
1388 % math mode.}
1389 %
1390 % Because of this mechanism to print a sign, it is not possible to use
1391 % other macro names than \cs{pm} for signs.\footnote{\cs{pm} is
1392 % handled separately.}
1393 % You have to use single characters as the shown ``\texttt{*}''.
1394 %
1395 %
1396 % \section{Some tricks}
1397 %
1398 % \subsection{Let the signs depend on the mode}
1399 %
1400 % \DescribeMacro{\nprt@sign@+}%
1401 % \DescribeMacro{\nprt@sign@-}%
1402 % \DescribeMacro{\nprt@sign@+-}%
1403 % The default signs are typeset in math mode independently of the mode
1404 % the number ist printed.
1405 % If you are using a font in which the sings of text and math mode
1406 % differ much, this may be unsatisfactory.
1407 % Then, you can typeset different signs for text and math mode.
1408 % Therefore, it is used that the default signs use the same macros as
1409 % user signs, described in section~\ref{sec:custom-parsing}.
1410 % They are defined as follows:
1411 % \begin{verbatim}
1412 %\expandafter\newcommand\csname nprt@sign@+\endcsname{{\ensuremath{+}}}
1413 %\expandafter\newcommand\csname nprt@sign@-\endcsname{{\ensuremath{-}}}
1414 %\expandafter\newcommand\csname nprt@sign@+-\endcsname{{\ensuremath{\pm}}}\end{verbatim}
1415 % If you, for instance, don't want to use the math minus for numbers
1416 % in text mode but another character, you may redefine
1417 % \cs{nprt@sign@-}:
1418 % \begin{verbatim}
1419 %\expandafter\renewcommand\csname nprt@sign@-\endcsname{%
1420 % \ifmmode {-}\else {---}\fi}\end{verbatim}
1421 %{\makeatletter\expandafter\def\csname nprt@sign@-\endcsname
1422 % {\ifmmode {-}\else {---}\fi}\makeatother
1423 % With this definition, \cs{numprint\{-1234\}} leads to
1424 % ``\numprint{-1234}'' resp.\ ``$\numprint{-1234}$'' in text resp.\
1425 % math mode.}
1426 %
1427 %
1428 % \subsection{Typing negative numbers in red}%
1429 % \label{sec:negative-red}%
1430 %
1431 % If you want to print negative number in red colors, you can use the
1432 % \cs{nprt@sign@-} command, too.
1433 % The following example shows how to do it:
1434 % \begin{verbatim}
1435 %\usepackage{color}
1436 %\makeatletter
1437 %\expandafter\renewcommand\csname nprt@sign@-\endcsname{%
1438 % \color{red}{\ensuremath{-}}}
1439 %\makeatother\end{verbatim}
1440 % With this definition,
1441 % \begin{verbatim}
1442 %\numprint{1234}, \numprint{-1234},
1443 %\numprint{1234e-123}, \numprint{-1234e123}.\end{verbatim}
1444 % {\makeatletter\expandafter\def\csname nprt@sign@-\endcsname
1445 % {\color{red}{\ensuremath{-}}}\makeatother
1446 % leads to ``\numprint{1234}, \numprint{-1234}, \numprint{1234e-123},
1447 % \numprint{-1234e123}.''}\footnote{Whether you can see the effect in
1448 % the output depends on the viewer; in PostScript and PDF the red
1449 % color works, in many dvi viewers, it doesn't.}
1450 % To avoid a negative exponent beeing printed in red for a positive
1451 % mantissa, a hack is included in the page which is described in
1452 % appendix~\ref{sec:code:main}, page~\pageref{page:code:color}.
1453 %
1454 %
1455 %
1456 % \subsection{Configuration file}%
1457 % \label{sec:configuration}%
1458 %
1459 % If your \LaTeX\ installation provides a file \texttt{numprint.cfg}
1460 % in the \TeX\ search path, it is loaded by \texttt{numprint.sty} as
1461 % last action.
1462 % Thus, you may add all changes and extensions, new languages for
1463 % instance, into this file.
1464 %
1465 %
1466 % \appendix
1467 %
1468 % \section{Compatiblity to older versions}
1469 %
1470 % In most cases, the user macros of this package (the macros not
1471 % containing a ``|@|'' in their name) should be compatible to older
1472 % versions.
1473 % The parsing of the argument has been improved that some arguments of
1474 % \cs{numprint} may be accepted or not in contrast to the older
1475 % version.
1476 %
1477 % The spacing of aligned numbers has also been corrected.
1478 % Thus, this is be incompatible to the older version if you are using
1479 % alignment in the exponent or math environmens other than
1480 % \cs{textstyle}.
1481 %
1482 %
1483 % \section{Lists of options and commands}
1484 %
1485 % This section contains lists of all package options resp.\ available
1486 % commands.
1487 % Items that belong together and may be exclusive are printed in
1488 % groups together.
1489 %
1490 % \subsection{Package options}%
1491 % \label{sec:package-options}%
1492 %
1493 % \begingroup
1494 % \newcommand*\default{$^{*}$}%
1495 % The default values are marked by \default.
1496 % \begin{longtable}[l]{%
1497 % @{}>{\ttfamily}p{0.30\linewidth}@{}p{0.70\linewidth}@{}}
1498 % warning& Produce warnings rather than error messages. \\
1499 % error\default& Produce error messages rather than
1500 % warnings. \\[\medskipamount]
1501 % autolanguage& Switch the settings language dependent.\\
1502 % noautolanguage\default& Fixed settings.\\[\medskipamount]
1503 % sepfour\default& Separator for four-digit numbers.\\
1504 % nosepfour& No separator for four-digit numbers.\\[\medskipamount]
1505 % addmissingzero\default& Add missings zeros before or after the
1506 % decimal sign.\\
1507 % noaddmissingzero& Don't do that.\\[\medskipamount]
1508 % addplus& Add a plus to a number without a sign.\\
1509 % noaddplus\default& Don't do that.\\[\medskipamount]
1510 % addplusexponent& Add a plus to a number without a sign in
1511 % exponents.\\
1512 % noaddplusexponent\default& Don't do that.\\[\medskipamount]
1513 % oldcolumntypes& Define the old column types that need to use the
1514 % \cs{numprint} inside the tabular.\\
1515 % newcolumntypes\default& Use the new column types.\\[\medskipamount]
1516 % boldmath& Define the \texttt{npbold} math version.\\[\medskipamount]
1517 % np& Define the shortcut \cs{np} for
1518 % \cs{numprint}.\\[\medskipamount]
1519 % debug& Produce debug information in the log file.
1520 % \end{longtable}
1521 % \endgroup
1522 %
1523 % \subsection{Commands}
1524 %
1525 % \begin{longtable}[l]{%
1526 % @{}>{\ttfamily \char`\\}p{0.3\linewidth}@{}p{0.7\linewidth}@{}}
1527 % npfourdigitsep& Switch on separating four-digit numbers.\\
1528 % npfourdigitnosep& Switch off separating four-digit
1529 % numbers.\\[\medskipamount]
1530 % npaddmissingzero& Switch on adding missings zeros before or after the
1531 % decimal sign.\\
1532 % npnoaddmissingzero& Switch off adding missings zeros before or after
1533 % the decimal sign.\\[\medskipamount]
1534 % npaddplus& Add a plus to a number without a sign.\\
1535 % npnoaddplus& Don't do that.\\[\medskipamount]
1536 % npaddplusexponent& Add a plus to the exponent when it has no sign.\\
1537 % npnoaddplusexponent& Don't do that.\\[\medskipamount]
1538 % np& Shortcut for \cs{numprint} (only available with package
1539 % option~\texttt{np}).\\
1540 % numprint& Typesets a number (the package's main
1541 % command).\\[\medskipamount]
1542 % npdecimalsign& Change the decimal sign.\\
1543 % npthousandsep& Change the thousand separator (before and after the
1544 % decimal sign).\\
1545 % npthousandthpartsep& Change the thousand separator (only after the
1546 % decimal sign).\\
1547 % npproductsign& Change the product sign.\\
1548 % npunitseparator& Change the separator between a number and a
1549 % unit.\\
1550 % npdegreeseparator& Change the separator between a number and a
1551 % degree symbol.\\[\medskipamount]
1552 % npcelsiusseparator& Change the separator between a number and
1553 % \textcelsius.\\[\medskipamount]
1554 % nppercentseparator& Change the separator between a number and a
1555 % percent sign.\\[\medskipamount]
1556 % nprounddigits& Declare how many digits will be printed after the
1557 % decimal sign.\\
1558 % npnoround& Switch off rounding and print numbers as given.\\
1559 % nproundexpdigits& Declare how many digits will be printed after the
1560 % decimal sign in the exponent.\\
1561 % npnoroundexp& Switch off rounding for the
1562 % exponent.\\[\medskipamount]
1563 % nplpadding& Declare up to how many digits the number will be padded at
1564 % the lefthand side. \\
1565 % npnolpadding& Switch off padding. \\[\medskipamount]
1566 % npreplacenull& Replace the after-decimal-sign part by another text
1567 % if it is zero.\\
1568 % npprintnull& Print zeros after the decimal sign.\\[\medskipamount]
1569 % npdigits& Switch on aligned number printing with given digits before
1570 % and after the decimal sign.\\
1571 % npnodigits& Print numbers in a box that is as wide as needed by the
1572 % number.\\
1573 % npexponentdigits& Switch on aligned printing of the exponent.\\
1574 % npnoexponentdigits& Switch alignment off for the
1575 % exponent.\\[\medskipamount]
1576 % npaddtolanguage& Adds language definitions to the extras section
1577 % of a \texttt{babel} language.\\
1578 % npstyledefault& Defines the settings in standard format.\\
1579 % npstylegerman& Defines the German number format.\\
1580 % npstyleenglish& Defines the English number
1581 % format.\\[\medskipamount]
1582 % npmakebox& Command similar to \cs{makebox} but with text instead
1583 % of length in first optional argument.\\[\medskipamount]
1584 % npboldmath& Bold math version with digits with the same width as
1585 % normal digits.\\[\medskipamount]
1586 % npafternum& Puts text after the number in
1587 % tabulars.\\[\medskipamount]
1588 % npunit& Sets the unit in tabulars.\\[\medskipamount]
1589 % \end{longtable}
1590 %
1591 % \section{Known bugs}
1592 %
1593 % \begin{itemize}
1594 % \item When aligning the exponent for tabulars, the distance between
1595 % the ``10'' and the exponent is too small.
1596 % \item Printing negative numbers in red does not work.
1597 % Only the minus sign is printed in red.
1598 % When was this bug introduced?
1599 % \end{itemize}
1600 %
1601 % \section{To do}
1602 %
1603 % \begin{itemize}
1604 % \item Add more languages to the automatic international support.
1605 % \item Add support for ``|<|'' in tabular definitions.
1606 % \item Avoid many of the temporary variables.
1607 % \item Add support for numbers in tabulars that are right aligned or
1608 % centered.
1609 % \end{itemize}
1610 %
1611 % \section{Acknowledgements}
1612 %
1613 % \begin{itemize}
1614 % \item
1615 % Tilman Finke, had the idea of rounding numbers.
1616 % \item
1617 % Stephan Helma has implemented padding numbers on the left side.
1618 % This function has been slightly changed by me.
1619 % \item
1620 % Portuguese support by Vilar Camara Neto and Luis.
1621 % \item
1622 % Dutch support by Ralph Hendriks.
1623 % \item
1624 % French support by Daniel Flipo.
1625 % \item
1626 % Ignacio Fern\'andez Galv\'an has reported a couple of bugs and
1627 % suggestions (which parly still have to be implemented\ldots)
1628 % \end{itemize}
1629 %
1630 % \begin{thebibliography}{1}
1631 % \bibitem{carlisle1999a}
1632 % Carlisle, David: \emph{The \texttt{tabularx} package},
1633 % version~2.07, 1999.\newblock
1634 % \url{CTAN:macros/latex/contrib/tabularx/}.
1635 % \bibitem{carlisle2000a}
1636 % Carlisle, David: \emph{The \texttt{longtable} package},
1637 % version~4.10, 2000.\newblock
1638 % \url{CTAN:macros/latex/contrib/longtable/}.
1639 % \bibitem{guthoehrlein2000a}
1640 % Guth\"ohrlein, Eckhart: \emph{The \texttt{rccol} package},
1641 % version~1.1a, 2000.\newblock
1642 % \url{CTAN:macros/latex/contrib/rccol/}.
1643 % \end{thebibliography}
1644 %
1645 % \StopEventually{\PrintChanges \PrintIndex}
1646 %
1647 % \section{The implementation}
1648 % \iffalse
1649 %<*package>
1650 % \fi
1651 % Heading of the package:
1652 % \begin{macrocode}
1653 \NeedsTeXFormat{LaTeX2e}
1654 \ProvidesPackage{numprint}
1655 [2012/08/20 v1.39 Print numbers (HH)]
1656 % \end{macrocode}
1657 %
1658 % \subsection{Load packages}
1659 %
1660 % \changes{1.33}{2004/11/19}{Avoid to use the \texttt{calc} package
1661 % since it causes problems with many other packages}%
1662 %
1663 % Load package array.sty for the new column types.
1664 % \begin{macrocode}
1665 \RequirePackage{array}
1666 % \end{macrocode}
1667 % \changes{1.10}{2003/10/12}{Avoid use of \texttt{substr} package}%
1668 %
1669 % \subsection{Package options and settings}
1670 %
1671 % Define a boolean if the first digit is separated in a four digit
1672 % number. Default is true for compatibility with older versions.
1673 % \begin{macrocode}
1674 \newif\ifnprt@numsepfour
1675 % \end{macrocode}
1676 % Show warnings or errors?
1677 % \begin{macrocode}
1678 \newif\ifnprt@errormessage
1679 % \end{macrocode}
1680 % Add missing zeros?
1681 % \begin{macrocode}
1682 \newif\ifnprt@addmissingzero
1683 % \end{macrocode}
1684 % Add missing plus signs?
1685 % \begin{macrocode}
1686 \newif\ifnprt@addplus@mantissa
1687 \newif\ifnprt@addplus@exponent
1688 % \end{macrocode}
1689 % Switch the style depending on the language automatically?
1690 % \begin{macrocode}
1691 \newif\ifnprt@autolanguage
1692 % \end{macrocode}
1693 % Old or new column types?
1694 % \begin{macrocode}
1695 \newif\ifnprt@newcolumntype
1696 % \end{macrocode}
1697 % Declare new math type?
1698 % \begin{macrocode}
1699 \newif\ifnprt@npbold
1700 % \end{macrocode}
1701 % \begin{macro}{\npfourdigitsep}
1702 % Switch separating of the fourth digit on.
1703 % \begin{macrocode}
1704 \newcommand*\npfourdigitsep{\nprt@numsepfourtrue}%
1705 % \end{macrocode}
1706 % \end{macro}
1707 % \begin{macro}{\npfourdigitnosep}
1708 % Switch separating of the fourth digit off.
1709 % \begin{macrocode}
1710 \newcommand*\npfourdigitnosep{\nprt@numsepfourfalse}%
1711 % \end{macrocode}
1712 % \end{macro}
1713 % \begin{macro}{\npaddmissingzero}
1714 % Add a missing zero before or after decimalsign.
1715 % \begin{macrocode}
1716 \newcommand*\npaddmissingzero{\nprt@addmissingzerotrue}%
1717 % \end{macrocode}
1718 % \end{macro}
1719 % \begin{macro}{\npnoaddmissingzero}
1720 % Don't add a missing zero before or after decimalsign.
1721 % \begin{macrocode}
1722 \newcommand*\npnoaddmissingzero{\nprt@addmissingzerofalse}%
1723 % \end{macrocode}
1724 % \end{macro}
1725 % \begin{macro}{\npaddplus}
1726 % Add a plus to the mantissa if no sign is given.
1727 % \begin{macrocode}
1728 \newcommand*\npaddplus{\nprt@addplus@mantissatrue}%
1729 % \end{macrocode}
1730 % \end{macro}
1731 % \begin{macro}{\npnoaddplus}
1732 % Don't add a plus to the mantissa if no sign is given.
1733 % \begin{macrocode}
1734 \newcommand*\npnoaddplus{\nprt@addplus@mantissafalse}%
1735 % \end{macrocode}
1736 % \end{macro}
1737 % \begin{macro}{\npaddplusexponent}
1738 % Add a plus to the exponent if no sign is given.
1739 % \begin{macrocode}
1740 \newcommand*\npaddplusexponent{\nprt@addplus@exponenttrue}%
1741 % \end{macrocode}
1742 % \end{macro}
1743 % \begin{macro}{\npnoaddplusexponent}
1744 % Don't add a plus to the exponent if no sign is given.
1745 % \begin{macrocode}
1746 \newcommand*\npnoaddplusexponent{\nprt@addplus@exponentfalse}%
1747 % \end{macrocode}
1748 % \end{macro}
1749 % Declare options. \verb|nosepfour| switches seperating of the fourth
1750 % digit off, \verb|sepfour| switches it on. Default is on four
1751 % compatibility reasons with older versions.
1752 % \begin{macrocode}
1753 \DeclareOption{nosepfour}{\npfourdigitnosep}
1754 \DeclareOption{sepfour}{\npfourdigitsep}
1755 % \end{macrocode}
1756 % Add missing zeros after decimal sign?
1757 % \begin{macrocode}
1758 \DeclareOption{noaddmissingzero}{\npnoaddmissingzero}
1759 \DeclareOption{addmissingzero}{\npaddmissingzero}
1760 % \end{macrocode}
1761 % Add a plus sign to the mantissa if no sign is given?
1762 % \begin{macrocode}
1763 \DeclareOption{noaddplus}{\npnoaddplus}
1764 \DeclareOption{addplus}{\npaddplus}
1765 % \end{macrocode}
1766 % Add a plus sign to the exponent if no sign is given?
1767 % \begin{macrocode}
1768 \DeclareOption{noaddplusexponent}{\npnoaddplusexponent}
1769 \DeclareOption{addplusexponent}{\npaddplusexponent}
1770 % \end{macrocode}
1771 % Add missing zeros after decimal sign?
1772 % \begin{macrocode}
1773 \DeclareOption{noautolanguage}{\nprt@autolanguagefalse}
1774 \DeclareOption{autolanguage}{\nprt@autolanguagetrue}
1775 % \end{macrocode}
1776 % \begin{macro}{\np}
1777 % \changes{1.00}{2003/10/07}{Add shortcut for \cs{numprint}}%
1778 % Define a shortcut for the \cs{numprint} command?
1779 % \begin{macrocode}
1780 \DeclareOption{np}{\newcommand*\np{\numprint}}
1781 % \end{macrocode}
1782 % \end{macro}
1783 % Produce warnings or errors?
1784 % \begin{macrocode}
1785 \DeclareOption{oldcolumntypes}{\nprt@newcolumntypefalse}
1786 \DeclareOption{newcolumntypes}{\nprt@newcolumntypetrue}
1787 % \end{macrocode}
1788 % Declare new math type?
1789 % \begin{macrocode}
1790 \DeclareOption{boldmath}{\nprt@npboldtrue}
1791 % \end{macrocode}
1792 % Produce warnings or errors?
1793 % \begin{macrocode}
1794 \DeclareOption{warning}{\nprt@errormessagefalse}
1795 \DeclareOption{error}{\nprt@errormessagetrue}
1796 % \end{macrocode}
1797 % Generate some debug information to the log file?
1798 % \begin{macrocode}
1799 \newcommand*\nprt@debug[1]{}
1800 \DeclareOption{debug}{%
1801 \renewcommand*\nprt@debug[1]{\PackageInfo{numprint}{#1}}%
1802 }
1803 % \end{macrocode}
1804 % Execute default options and the given options.
1805 % \begin{macrocode}
1806 \ExecuteOptions{sepfour,addmissingzero,error,noautolanguage,newcolumntypes}
1807 \ProcessOptions\relax
1808 % \end{macrocode}
1809 % Define commands to change the output of the \verb|\numprint|
1810 % command.
1811 %
1812 % \begin{macro}{\npdecimalsign}
1813 % Change the decimal sign. In English it is normally ``.'', in German
1814 % ``,''.
1815 % The additional pair of braces \verb|{}| prevents from inserting
1816 % additional space in math mode, e.g., $1,2$ versus $1{,}2$.
1817 % \begin{macrocode}
1818 \newcommand*\npdecimalsign[1]{\def\nprt@decimal{{#1}}}
1819 % \end{macrocode}
1820 % \end{macro}
1821 % \begin{macro}{\npthousandsep}
1822 % Change the thousand separator. In English it often is ``,'', in
1823 % German ``.'' or ``\,'' (\verb|\,|).
1824 % Here again the additional \verb|{}| is used as above.
1825 % This command changes both the sign before and after the decimal
1826 % sign.
1827 % If you want a different sign after the comma you have to call
1828 % \verb|\npthousandthpartsep| after \verb|\npthousandsep|.
1829 % \begin{macrocode}
1830 \newcommand*\npthousandsep[1]{\def\nprt@separator@before{{#1}}%
1831 \def\nprt@separator@after{{#1}}}
1832 % \end{macrocode}
1833 % \end{macro}%
1834 % \begin{macro}{\npthousandthpartsep}
1835 % Change the thousand separator after the decismal sign.
1836 % \begin{macrocode}
1837 \newcommand*\npthousandthpartsep[1]{\def\nprt@separator@after{{#1}}}
1838 % \end{macrocode}
1839 % \end{macro}
1840 % \begin{macro}{\npproductsign}
1841 % Change the product sign that is printed in numbers with exponent
1842 % like $\numprint{123e4}$. Normally it is \verb|\cdot|. In American
1843 % texts sometimes \verb|\times|.
1844 % The two pairs of braces \verb|{}| ensure the correct spacing on the
1845 % left and right side of the product sign, e.g., 3$\cdot$4 versus
1846 % 3${}\cdot{}$4.
1847 % \begin{macrocode}
1848 \newcommand*\npproductsign[1]{\def\nprt@prod{\ensuremath{{}#1{}}}}
1849 % \end{macrocode}
1850 % \end{macro}
1851 % \begin{macro}{\npunitseparator}
1852 % Change the separator between number and unit.
1853 % Here again the additional \verb|{}| is used as above.
1854 % \begin{macrocode}
1855 \newcommand*\npunitseparator[1]{\def\nprt@unitsep{{#1}}}
1856 % \end{macrocode}
1857 % \end{macro}
1858 % \begin{macro}{\npdegreeseparator}
1859 % Change the separator between number and \textdegree.
1860 % Here again the additional \verb|{}| is used as above.
1861 % \begin{macrocode}
1862 \newcommand*\npdegreeseparator[1]{\def\nprt@degreesep{{#1}}}
1863 % \end{macrocode}
1864 % \end{macro}
1865 % \begin{macro}{\npcelsiusseparator}
1866 % Change the separator between number and \textcelsius.
1867 % Here again the additional \verb|{}| is used as above.
1868 % \begin{macrocode}
1869 \newcommand*\npcelsiusseparator[1]{\def\nprt@celsiussep{{#1}}}
1870 % \end{macrocode}
1871 % \end{macro}
1872 % \begin{macro}{\nppercentseparator}
1873 % Change the separator between number and \%.
1874 % Here again the additional \verb|{}| is used as above.
1875 % \begin{macrocode}
1876 \newcommand*\nppercentseparator[1]{\def\nprt@percentsep{{#1}}}
1877 % \end{macrocode}
1878 % \end{macro}
1879 % \begin{macro}{\nprt@fillnull}
1880 % Defines command |#1| with a number of |#2| zeros filled.
1881 % This should reside in Sect.~\ref{sec:code:round} but is called
1882 % before.
1883 % \begin{macrocode}
1884 \def\nprt@fillnull#1#2{%
1885 \@tempcnta=-1
1886 \loop
1887 \g@addto@macro{#1}{0}%
1888 \advance\@tempcnta by 1
1889 \ifnum\@tempcnta<#2
1890 \repeat
1891 }
1892 % \end{macrocode}
1893 % \end{macro}
1894 % \begin{macro}{\nprounddigits}
1895 % Define a command that sets a count of digits after which the number
1896 % is rounded.
1897 % This command defines \cs{nprt@rounddigits} that stores the count and
1898 % \cs{nprt@roundnull} that contains of \cs{nprt@rounddigits} ``0''
1899 % digits.
1900 % \begin{macrocode}
1901 \newcommand\nprounddigits[1]{%
1902 \def\nprt@rounddigits{#1}%
1903 \def\nprt@roundnull{}%
1904 \nprt@fillnull{\nprt@roundnull}{#1}%
1905 }
1906 % \end{macrocode}
1907 % \end{macro}
1908 % \begin{macro}{\npnoround}
1909 % A command to switch off rounding.
1910 % \begin{macrocode}
1911 \newcommand\npnoround{\nprounddigits{-1}}
1912 % \end{macrocode}
1913 % \end{macro}
1914 % Don't round by default.
1915 % \begin{macrocode}
1916 \npnoround
1917 % \end{macrocode}
1918 % \begin{macro}{\nproundexpdigits}
1919 % \begin{macro}{\npnoroundexp}
1920 % The same for exponents.
1921 % \begin{macrocode}
1922 \newcommand\nproundexpdigits[1]{%
1923 \def\nprt@roundexpdigits{#1}%
1924 \def\nprt@roundexpnull{}%
1925 \nprt@fillnull{\nprt@roundexpnull}{#1}%
1926 }
1927 \newcommand\npnoroundexp{\nproundexpdigits{-1}}
1928 \npnoroundexp
1929 % \end{macrocode}
1930 % \end{macro}
1931 % \end{macro}
1932 % \begin{macro}{\nplpadding}
1933 % This command sets the total counts of digits a number should contain.
1934 % The missing digits are filled with the character from the second
1935 % argument (which is 0 by default).
1936 % \begin{macrocode}
1937 \newcommand\nplpadding[2][0]{%
1938 \def\nprt@lpaddigits{#2}%
1939 \def\nprt@lpadchar{#1}%
1940 }
1941 % \end{macrocode}
1942 % \end{macro}
1943 % \begin{macro}{\npnolpadding}
1944 % The command to switch of padding.
1945 % \begin{macrocode}
1946 \newcommand*\npnolpadding{\nplpadding[\@empty]{-1}}
1947 % \end{macrocode}
1948 % \end{macro}
1949 % Don't pad by default.
1950 % \begin{macrocode}
1951 \npnolpadding
1952 % \end{macrocode}
1953 % \begin{macro}{\npreplacenull}
1954 % Optionally, one or more zeros after the decimal sign can be replaced
1955 % by other text, e.g., ``---'''.
1956 % \begin{macrocode}
1957 \newcommand*\npreplacenull[1]{\def\nprt@replacenull{#1}}
1958 % \end{macrocode}
1959 % \end{macro}
1960 % \begin{macro}{\npprintnull}
1961 % Switch off replacement, again.
1962 % \begin{macrocode}
1963 \newcommand*\npprintnull{\let\nprt@replacenull=\@empty}
1964 % \end{macrocode}
1965 % \end{macro}
1966 % Print the zero by default.
1967 % \begin{macrocode}
1968 \npprintnull
1969 % \end{macrocode}
1970 % \begin{macro}{\npunitcommand}
1971 % This command is used to typeset the unit.
1972 % \begin{macrocode}
1973 \newcommand*\npunitcommand[1]{\ensuremath{\mathrm{#1}}}
1974 % \end{macrocode}
1975 % \end{macro}
1976 % \begin{macro}{\npdigits}
1977 % With this command the user can switch to aligned printing.
1978 % The first parameter stands for the digits before the decimal sign
1979 % and the second for the digits after it.
1980 % \begin{macrocode}
1981 \newif\ifnprt@mantissa@fixeddigits
1982 \newcommand*\npdigits[2]{%
1983 \edef\nprt@mantissa@fixeddigits@before{#1}%
1984 \edef\nprt@mantissa@fixeddigits@after{#2}%
1985 \nprt@mantissa@fixeddigitstrue
1986 }
1987 % \end{macrocode}
1988 % Initialize the numbers.
1989 % \begin{macrocode}
1990 \def\nprt@mantissa@fixeddigits@before{-1}%
1991 \def\nprt@mantissa@fixeddigits@after{-1}%
1992 % \end{macrocode}
1993 % \end{macro}
1994 % \begin{macro}{\npnodigits}
1995 % Switch back to normal printing.
1996 % \begin{macrocode}
1997 \newcommand*\npnodigits{\nprt@mantissa@fixeddigitsfalse}
1998 % \end{macrocode}
1999 % \end{macro}
2000 % \begin{macro}{\npexponentdigits}
2001 % With this command the user can switch to aligned printing of the
2002 % exponent.
2003 % The parameter stands for the digits before the decimal sign.
2004 % \begin{macrocode}
2005 \newif\ifnprt@exponent@fixeddigits
2006 \newcommand*\npexponentdigits[2][0]{%
2007 \edef\nprt@exponent@fixeddigits@before{#2}%
2008 \edef\nprt@exponent@fixeddigits@after{#1}%
2009 \nprt@exponent@fixeddigitstrue
2010 }
2011 % \end{macrocode}
2012 % Initialize the numbers.
2013 % \begin{macrocode}
2014 \def\nprt@exponent@fixeddigits@before{-1}%
2015 \def\nprt@exponent@fixeddigits@after{-1}%
2016 % \end{macrocode}
2017 % \end{macro}
2018 % \begin{macro}{\npnoexponentdigits}
2019 % Switch back to normal printing.
2020 % \begin{macrocode}
2021 \newcommand*\npnoexponentdigits{\nprt@exponent@fixeddigitsfalse}
2022 % \end{macrocode}
2023 % \end{macro}
2024 %
2025 %
2026 % \subsection{Error and warning messages}
2027 %
2028 % Define a boolean which helps \cs{numprint} to detect errors.
2029 % \begin{macrocode}
2030 \newif\ifnprt@argumenterror
2031 % \end{macrocode}
2032 % \begin{macro}{\nprt@error}
2033 % Define \cs{nprt@error\marg{Message}\marg{Help text}} which prints
2034 % a warning resp.\ an error message, depending on the package options
2035 % |warning| and |error|.
2036 % \begin{macrocode}
2037 \newcommand\nprt@error[2]{%
2038 \ifnprt@errormessage
2039 \PackageError{numprint}{#1}{#2}%
2040 \else
2041 \PackageWarning{numprint}{#1}%
2042 \fi
2043 % \end{macrocode}
2044 % The boolean is set to ``true''.
2045 % Then, \cs{numprint} knows that an error occured.
2046 % \begin{macrocode}
2047 \nprt@argumenterrortrue
2048 }
2049 % \end{macrocode}
2050 % \end{macro}
2051 %
2052 %
2053 % \subsection{String parsing}
2054 %
2055 % \changes{1.10}{2003/10/12}{Avoid use of \texttt{substr} package}%
2056 % The \cs{IfCharInString} package does not work in the tabular
2057 % alignment context.
2058 % Thus, define an own command \cs{nprt@IfCharInString} that does the
2059 % same.
2060 % \begin{macro}{\nprt@charfound}
2061 % \begin{macrocode}
2062 \newif\ifnprt@charfound
2063 % \end{macrocode}
2064 % \end{macro}
2065 % \begin{macro}{\nprt@IfCharInString}
2066 % ????
2067 % \begin{macrocode}
2068 \newcommand*\nprt@IfCharInString[2]{%
2069 \nprt@charfoundfalse
2070 \begingroup
2071 \def\nprt@searchfor{#1}%
2072 \edef\nprt@argtwo{#2}%
2073 \expandafter\nprt@@IfCharInString\nprt@argtwo\@empty\@empty
2074 \endgroup
2075 \ifnprt@charfound
2076 \expandafter\@firstoftwo
2077 \else
2078 \expandafter\@secondoftwo
2079 \fi
2080 }
2081 % \end{macrocode}
2082 % \end{macro}
2083 % \begin{macro}{\nprt@@IfCharInString}
2084 % ????
2085 % \begin{macrocode}
2086 \def\nprt@@IfCharInString#1#2\@empty{%
2087 \def\nprt@argone{#1}%
2088 \edef\nprt@argtwo{#2}%
2089 \ifx\nprt@searchfor\nprt@argone
2090 \global\nprt@charfoundtrue
2091 \else
2092 \ifx\nprt@argtwo\@empty
2093 \else
2094 \nprt@@IfCharInString#2\@empty
2095 \fi
2096 \fi
2097 }
2098 % \end{macrocode}
2099 % \end{macro}
2100 %
2101 %
2102 % \subsection{Parsing of the \textmd{\cs{numprint}} argument}
2103 %
2104 % \begin{macro}{\nprt@plus@test}
2105 % \begin{macro}{\nprt@minus@test}
2106 % \begin{macro}{\nprt@plusminus@test}
2107 % Define the signs as commands. This is necessary to be able to
2108 % compare them with other characters.
2109 % \begin{macrocode}
2110 \newcommand*\nprt@plus@test{+}
2111 \newcommand*\nprt@minus@test{-}
2112 \newcommand*\nprt@plusminus@test{\pm}
2113 % \end{macrocode}
2114 % \end{macro}
2115 % \end{macro}
2116 % \end{macro}
2117 % \begin{macro}{\nprt@numberlist}
2118 % \begin{macro}{\nprt@dotlist}
2119 % \begin{macro}{\nprt@epxlist}
2120 % \begin{macro}{\nprt@signlist}
2121 % Define lists of valid characters for different elements of numbers
2122 % for parsing the mandatory argument of the \cs{numprint} command.
2123 % It has nothing to do with the output.
2124 % \cs{nprt@numberlist} contains digits, \cs{nprt@dotlist} valid
2125 % decimal signs, \cs{nprt@explist} the characters that start the
2126 % exponent, and \cs{nprt@signlist} the valid signs, where
2127 % ``\texttt{+-}'' as alias for ``\cs{pm}'' does not have to be
2128 % specified seperately.
2129 % \begin{macrocode}
2130 \newcommand*\nprt@numberlist{0123456789}
2131 \newcommand*\nprt@dotlist{.,}
2132 \newcommand*\nprt@explist{eEdD}
2133 \newcommand*\nprt@signlist{+-\pm}
2134 \newcommand*\nprt@ignorelist{}
2135 % \end{macrocode}
2136 % \end{macro}
2137 % \end{macro}
2138 % \end{macro}
2139 % \end{macro}
2140 % Counters for the number of digits before and after the decimal sign
2141 % of the mantissa.
2142 % \begin{macrocode}
2143 \newcounter{nprt@mantissa@digitsbefore}%
2144 \newcounter{nprt@mantissa@digitsafter}%
2145 % \end{macrocode}
2146 % Counters for the number of digits before and after the decimal sign
2147 % of the exponent.
2148 % \begin{macrocode}
2149 \newcounter{nprt@exponent@digitsbefore}%
2150 \newcounter{nprt@exponent@digitsafter}%
2151 % \end{macrocode}
2152 % Boolean to store if an exponent will be printed.
2153 % \begin{macrocode}
2154 \newif\ifnprt@expfound
2155 % \end{macrocode}
2156 % Boolean to store if mantissa resp.\ exponent contain a decimal
2157 % sign.
2158 % \begin{macrocode}
2159 \newif\ifnprt@mantissa@decimalfound
2160 \newif\ifnprt@exponent@decimalfound
2161 % \end{macrocode}
2162 % \begin{macro}{\nprt@testsign}
2163 % Define \cs{nprt@testsign\marg{Number type}\marg{Number}} which tests
2164 % whether a sign is given and then starts \cs{nprt@testnumber} (the
2165 % call actually is done by \cs{nprt@@testsign}).
2166 % \begin{macrocode}
2167 \newcommand*\nprt@testsign[2]{%
2168 % \end{macrocode}
2169 % First, store the expanded arguments in macros.
2170 % \begin{macrocode}
2171 \edef\nprt@commandname{#1}%
2172 \edef\nprt@tmp{#2}%
2173 % \end{macrocode}
2174 % Call the working command \cs{nprt@@testsign}.
2175 % The large number of \cs{expandafter} calls is necessary to ensure
2176 % that the second to fourth argument are already expanded (thus, |#2|
2177 % and |#3| are single characters).
2178 % Append enough \cs{@empty} to ensure the argument-end marker is found
2179 % even for an empty number.
2180 % \begin{macrocode}
2181 \expandafter\nprt@@testsign\expandafter{%
2182 \expandafter\nprt@commandname\expandafter}%
2183 \nprt@tmp\@empty\@empty\@empty\@empty
2184 }
2185 % \end{macrocode}
2186 % \end{macro}
2187 % \begin{macro}{\nprt@@testsign}
2188 % The first argument is the Number type (``mantissa'' or
2189 % ``exponent'').
2190 % Because it is longer than one character, it has to be enclosed in
2191 % braces when calling this function (see the previous code line).
2192 % The arguments |#2| to |#4| are the given number, where |#2| and |#3|
2193 % contain of the first resp.\ second character of the number, while
2194 % |#4| contains the rest.
2195 % \begin{macrocode}
2196 \def\nprt@@testsign#1#2#3#4\@empty{%
2197 % \end{macrocode}
2198 % Store the first argument to a macro.
2199 % \begin{macrocode}
2200 \edef\nprt@commandname{#1}%
2201 % \end{macrocode}
2202 % Define the macros that store the digits before respectivly after the
2203 % decimal sign.
2204 % They are filled digit by digit and start empty.
2205 % \begin{macrocode}
2206 \expandafter\xdef\csname nprt@#1@before\endcsname{\@empty}%
2207 \expandafter\xdef\csname nprt@#1@after\endcsname{\@empty}%
2208 % \end{macrocode}
2209 % Yet, no digits are stored.
2210 % \begin{macrocode}
2211 \setcounter{nprt@#1@digitsbefore}{0}%
2212 \setcounter{nprt@#1@digitsafter}{0}%
2213 % \end{macrocode}
2214 % Test whether the first character of the number, |#2|, contains a
2215 % sign symbol which is listed in \cs{nprt@signlist}.
2216 % \begin{macrocode}
2217 \nprt@IfCharInString{#2}{\nprt@signlist}{%
2218 % \end{macrocode}
2219 % If yes, store that sign in the command
2220 % \cs{nprt@\meta{\#2}@sign}.
2221 % \begin{macrocode}
2222 \expandafter\xdef\csname nprt@#1@sign\endcsname{#2}%
2223 % \end{macrocode}
2224 % If the sign is a ``+'' the second character of the number may be a
2225 % ``-'' to replace that combination by \cs{pm}.
2226 % Thus, do an extra handling of that case.
2227 % \begin{macrocode}
2228 \expandafter\ifx\csname nprt@#1@sign\endcsname\nprt@plus@test
2229 \def\nprt@tmp{#3}%
2230 \ifx\nprt@tmp\nprt@minus@test
2231 % \end{macrocode}
2232 % The second character, |#3|, \emph{is} a ``-'', thus redefine
2233 % \cs{nprt@\meta{\#2}@sign} to \cs{pm}.
2234 % \begin{macrocode}
2235 \expandafter\xdef\csname nprt@#1@sign\endcsname{+-}%
2236 % \end{macrocode}
2237 % The digits start at the third character of the number string which
2238 % is |#4|.
2239 % Start \cs{nprt@testnumber} to parse the digits of the number if a
2240 % number is given after the given sign ``+-''.
2241 % If not, empty \cs{nprt@\meta{\#1}} that \cs{numprint} can determine
2242 % that only a sign has been given.
2243 % \begin{macrocode}
2244 \def\nprt@tmp{#4}%
2245 \ifx\nprt@tmp\@empty
2246 \expandafter\edef\csname nprt@#1\endcsname{\@empty}%
2247 \else
2248 \expandafter\nprt@testnumber\expandafter\nprt@commandname#4\@empty
2249 \fi
2250 \else
2251 % \end{macrocode}
2252 % If there is a single sign character ``+'', the digits start at |#3|.
2253 % Start \cs{nprt@testnumber} to parse the digits of the number if a
2254 % number is given after the given sign ``+''.
2255 % If not, empty \cs{nprt@\meta{\#1}} that \cs{numprint} can determine
2256 % that only a sign has been given.
2257 % \begin{macrocode}
2258 \ifx#3\@empty
2259 \expandafter\edef\csname nprt@#1\endcsname{\@empty}%
2260 \else
2261 \expandafter\nprt@testnumber\expandafter\nprt@commandname#3#4\@empty
2262 \fi
2263 \fi
2264 \else
2265 % \end{macrocode}
2266 % If the sign is a ``\cs{pm}'' store ``\texttt{+-} as sign.
2267 % \begin{macrocode}
2268 \expandafter\ifx\csname nprt@#1@sign\endcsname\nprt@plusminus@test
2269 \expandafter\xdef\csname nprt@#1@sign\endcsname{+-}%
2270 \fi
2271 % \end{macrocode}
2272 % If there is a single sign character other than ``+'', the digits
2273 % start at |#3|.
2274 % Start \cs{nprt@testnumber} to parse the digits of the number if a
2275 % number is given after the given sign.
2276 % If not, empty \cs{nprt@\meta{\#1}} that \cs{numprint} can determine
2277 % that only a sign has been given.
2278 % \begin{macrocode}
2279 \ifx#3\@empty
2280 \expandafter\edef\csname nprt@#1\endcsname{\@empty}%
2281 \else
2282 \expandafter\nprt@testnumber\expandafter\nprt@commandname#3#4\@empty
2283 \fi
2284 \fi
2285 }{%
2286 % \end{macrocode}
2287 % If there is no sign, set \cs{nprt@\meta{\#2}@sign} empty.
2288 % \begin{macrocode}
2289 \expandafter\xdef\csname nprt@#1@sign\endcsname{\@empty}%
2290 % \end{macrocode}
2291 % The digits start at |#2|.
2292 % Start \cs{nprt@testnumber} to parse the digits of the number.
2293 % \begin{macrocode}
2294 \expandafter\nprt@testnumber\expandafter\nprt@commandname#2#3#4\@empty
2295 }%
2296 }
2297 % \end{macrocode}
2298 % \end{macro}
2299 % \begin{macro}{\nprt@testnumber}
2300 % As with \cs{nprt@@testsign}, the first argument is the Number type,
2301 % while the second and third arguments contain the number.
2302 % |#2| contains the first character of the remaining number string,
2303 % |#3| the rest.
2304 % \begin{macrocode}
2305 \def\nprt@testnumber#1#2#3\@empty{%
2306 % \end{macrocode}
2307 % Store the arguments in macros.
2308 % \begin{macrocode}
2309 \edef\nprt@commandname{#1}%
2310 \edef\nprt@argthree{#3}%
2311 % \end{macrocode}
2312 % Test whether the current character is a valid character for a real
2313 % number (say a digit or a decimal sign).
2314 % \begin{macrocode}
2315 \nprt@IfCharInString{#2}{\nprt@numberlist\nprt@dotlist}{%
2316 % \end{macrocode}
2317 % If this is the case, continue testing.
2318 % If the current character is a decimal sign, set the boolean
2319 % \cs{ifnprt@\meta{Number type}@decimalfound} that a decimal
2320 % sign has been found.
2321 % If this has been done before, the number contains two decimal signs
2322 % which is not allowed, thus, generate an error message.
2323 % \begin{macrocode}
2324 \nprt@IfCharInString{#2}{\nprt@dotlist}{%
2325 \csname ifnprt@#1@decimalfound\endcsname
2326 \nprt@error{More than one decimal sign used}{The mantissa
2327 or the exponent may only contain a maximum of one decimal
2328 sign (one of the list `\nprt@dotlist')}%
2329 \else
2330 \csname nprt@#1@decimalfoundtrue\endcsname
2331 \fi
2332 }{%
2333 % \end{macrocode}
2334 % If the current character is no decimal sign it has to be a digit.
2335 % If the decimal sign has been found before, this digit is in the real
2336 % part of the number.
2337 % Then, add it at the end of the after-decimal-sign part.
2338 % Also, increase the number of found digits.
2339 % \begin{macrocode}
2340 \csname ifnprt@#1@decimalfound\endcsname
2341 \expandafter\g@addto@macro\csname nprt@#1@after\endcsname{#2}%
2342 \advance\csname c@nprt@#1@digitsafter\endcsname by 1\relax
2343 \else
2344 % \end{macrocode}
2345 % If the decimal sign has not been found before, this digit is in the
2346 % integer part of the number.
2347 % Then, add it at the end of the before-decimal-sign part.
2348 % \begin{macrocode}
2349 \expandafter\g@addto@macro\csname nprt@#1@before\endcsname{#2}%
2350 \advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
2351 \fi
2352 }%
2353 % \end{macrocode}
2354 % If the next character is not \cs{@empty} and thus, the end of the
2355 % number is not reached, start \cs{nprt@testnumber} resursively to
2356 % parse the next character.
2357 % \begin{macrocode}
2358 \ifx\nprt@argthree\@empty
2359 \else
2360 \expandafter\nprt@testnumber\expandafter\nprt@commandname#3\@empty
2361 \fi
2362 }{%
2363 % \end{macrocode}
2364 % The current character is neither a digit nor a decimal sign.
2365 % Thus, it is a invalid character; produce an error message.
2366 % \begin{macrocode}
2367 \nprt@error{Invalid number format. Printing the
2368 argument\MessageBreak
2369 verbatim}{Something is wrong in the format of the number}%
2370 }%
2371 }
2372 % \end{macrocode}
2373 % \end{macro}
2374 % \begin{macro}{\nprt@testcharacter}
2375 % This macro parses the whole mandatory argument of \cs{numprint}.
2376 % This means it is tested on invalid characters and on a mantissa and
2377 % an exponent.
2378 % The first argument is the current character while |#2| is the rest
2379 % of the argument, not parsed yet.
2380 % \begin{macrocode}
2381 \def\nprt@testcharacter#1#2\@empty{%
2382 % \end{macrocode}
2383 % Store the second argument to a macro.
2384 % \begin{macrocode}
2385 \edef\nprt@argtwo{#2}%
2386 % \end{macrocode}
2387 % Test whether the current character is a valid one.
2388 % \begin{macrocode}
2389 \nprt@IfCharInString{#1}{%
2390 \nprt@numberlist\nprt@dotlist\nprt@explist\nprt@signlist\nprt@ignorelist}{%
2391 % \end{macrocode}
2392 % Yes, it is valid.
2393 %
2394 % Now, test whether it is one of the ignored characters.
2395 % \begin{macrocode}
2396 \nprt@IfCharInString{#1}{\nprt@ignorelist}{%
2397 \nprt@debug{Character `\noexpand#1' ignored}%
2398 }{%
2399 % \end{macrocode}
2400 % Yes, it is valid.
2401 %
2402 % Now, test whether it is one of the characters that start the
2403 % exponent.
2404 % If yes, set \cs{ifnprt@expfound} to ``true''.
2405 % If in addition, this has been done before, you have used more than
2406 % one exponent starting character; produce an error message.
2407 % \begin{macrocode}
2408 \nprt@IfCharInString{#1}{\nprt@explist}{%
2409 \ifnprt@expfound
2410 \nprt@error{Character for exponent (`\nprt@explist') used
2411 more than once}{The argument of \string\numprint\space may
2412 only contain one of following characters: `\nprt@explist'}%
2413 \fi
2414 \nprt@expfoundtrue
2415 }{%
2416 % \end{macrocode}
2417 % If the current character is not an exponent-starting character it
2418 % is either a part of the mantissa or the exponent, depending on
2419 % whether the exponent has been started before.
2420 % Add the current character to the corresponding command that stores
2421 % the mantissa resp.\ the exponent.
2422 % \begin{macrocode}
2423 \ifnprt@expfound
2424 \g@addto@macro\nprt@exponent{#1}%
2425 \else
2426 \g@addto@macro\nprt@mantissa{#1}%
2427 \fi
2428 }%
2429 }%
2430 % \end{macrocode}
2431 % If we have not reached the end of the argument, call
2432 % \cs{nprt@testcharacter} recursively.
2433 % \begin{macrocode}
2434 \ifx\nprt@argtwo\@empty
2435 \else
2436 \nprt@testcharacter#2\@empty\@empty\@empty
2437 \fi
2438 }{%
2439 % \end{macrocode}
2440 % If the character is not valid produce an error message.
2441 % \begin{macrocode}
2442 \nprt@error{Invalid characters `#1' in mandatory argument
2443 of\MessageBreak
2444 \string\numprint. Allowed are\MessageBreak
2445 `\nprt@numberlist\nprt@dotlist\nprt@explist\nprt@signlist\nprt@ignorelist'}{%
2446 You may only use the specified characters in the argument.}%
2447 }%
2448 }
2449 % \end{macrocode}
2450 % \end{macro}
2451 %
2452 %
2453 % \subsection{Table alignment}
2454 %
2455 % \subsubsection{Aligned numbers, also for ordinary text}
2456 %
2457 % Define some lengths that help to calculate the width of a number.
2458 % \begin{macrocode}
2459 \newlength{\nprt@digitwidth}%
2460 \newlength{\nprt@sepwidth}%
2461 \newlength{\nprt@decimalwidth}%
2462 \newlength{\nprt@blockwidth}%
2463 % \end{macrocode}
2464 % \begin{macro}{\nprt@calcblockwidth}
2465 % Define \cs{nprt@calcblockwidth\marg{Number
2466 % type}\marg{Position}\marg{Math mode}}, where
2467 % \meta{Number type} is either ``mantissa'' or ``exponent'',
2468 % \meta{Position} is the position relative to the decimal sign
2469 % (``before'' or ``after''), \meta{Math mode} is a math mode command
2470 % (\cs{displaystyle}, \cs{textstyle}, \cs{scriptstyle}, or
2471 % \cs{scriptscriptstyle}).
2472 %
2473 % This macro calculates the width of a block if aligned output is
2474 % requested.
2475 % The resulted width is stored in the length \cs{nprt@blockwidth}.
2476 % \begin{macrocode}
2477 \newcommand*\nprt@calcblockwidth[3]{%
2478 % \end{macrocode}
2479 % Store the arguments in macros.
2480 % \begin{macrocode}
2481 \edef\nprt@argone{#1}%
2482 \edef\nprt@argtwo{#2}%
2483 \edef\nprt@argthree{#3}%
2484 % \end{macrocode}
2485 % Define a macro with the contents ``mantissa'' to be able to compare
2486 % it.
2487 % \begin{macrocode}
2488 \edef\nprt@mantissaname{mantissa}%
2489 % \end{macrocode}
2490 % Define a macro with the contents ``after'' to be able to compare
2491 % it.
2492 % \begin{macrocode}
2493 \edef\nprt@aftername{after}%
2494 % \end{macrocode}
2495 % If the width for the mantissa is to be calculated, enter this code
2496 % part.
2497 % \begin{macrocode}
2498 \ifx\nprt@argone\nprt@mantissaname
2499 % \end{macrocode}
2500 % The width of the digits and separators changes between text and
2501 % math mode.
2502 % If math mode is active, proceed here.
2503 % \begin{macrocode}
2504 \ifmmode
2505 % \end{macrocode}
2506 % Calculate the width of digits.
2507 % It is assumed that all digits have the same width as a zero.
2508 % First, execute parameter \verb|#3| to switch to the current math
2509 % style.
2510 % This is be done that way since it is not possible to export length
2511 % values from \cs{mathchoice}.
2512 % \begin{macrocode}
2513 \settowidth{\nprt@digitwidth}{$#3%
2514 0$}%
2515 % \end{macrocode}
2516 % Calculate the width of the separators.
2517 % This may differ from before and after the decimal sign.
2518 % \begin{macrocode}
2519 \settowidth{\nprt@sepwidth}{$#3%
2520 \csname nprt@separator@#2\endcsname$}%
2521 % \end{macrocode}
2522 % Calculate the width of the decimal sign.
2523 % \begin{macrocode}
2524 \settowidth{\nprt@decimalwidth}{$#3%
2525 \nprt@decimal$}%
2526 \else
2527 % \end{macrocode}
2528 % Do the same for text mode.
2529 % \begin{macrocode}
2530 \settowidth{\nprt@digitwidth}{0}%
2531 \settowidth{\nprt@sepwidth}{\csname nprt@separator@#2\endcsname}%
2532 \settowidth{\nprt@decimalwidth}{\nprt@decimal}%
2533 \fi
2534 % \end{macrocode}
2535 % The same for the exponent.
2536 % \begin{macrocode}
2537 \else
2538 \ifmmode
2539 \settowidth{\nprt@digitwidth}{$#3%
2540 {}^{0}$}%
2541 \settowidth{\nprt@sepwidth}{$#3%
2542 {}^{\csname nprt@separator@#2\endcsname}$}%
2543 \settowidth{\nprt@decimalwidth}{$#3%
2544 {}^{\nprt@decimal}$}%
2545 \else
2546 \settowidth{\nprt@digitwidth}{\textsuperscript{0}}%
2547 \settowidth{\nprt@sepwidth}{%
2548 \textsuperscript{\csname nprt@separator@#2\endcsname}}%
2549 \settowidth{\nprt@decimalwidth}{\textsuperscript{\nprt@decimal}}%
2550 \fi
2551 \fi
2552 % \end{macrocode}
2553 % Output to the log file.
2554 % \begin{macrocode}
2555 \nprt@debug{Widths for #1 #2 decimal sign
2556 (\ifx\nprt@argthree\@empty text mode\else math mode #3\fi):\MessageBreak
2557 digits \the\nprt@digitwidth,
2558 separators \the\nprt@sepwidth,\MessageBreak
2559 decimal sign \the\nprt@decimalwidth}%
2560 % \end{macrocode}
2561 % Produce a warning if the current number exceeds the reserved space.
2562 % Signs ($+-\pm$) are not taken into account.
2563 % \begin{macrocode}
2564 \ifnum\csname nprt@#1@fixeddigits@#2\endcsname<%
2565 \csname thenprt@#1@digits#2\endcsname
2566 \PackageWarning{numprint}{#1 exceeds reserved space
2567 #2\MessageBreak
2568 decimal sign}%
2569 \fi
2570 % \end{macrocode}
2571 % \changes{1.34}{2004/12/13}{Fix a bug invoked in version~1.33. Found
2572 % by Stefan Salewski}%
2573 % Calculate the width of the given number of digits without
2574 % separators.
2575 % \begin{macrocode}
2576 \setlength{\nprt@blockwidth}{%
2577 \csname nprt@#1@fixeddigits@#2\endcsname\nprt@digitwidth}%
2578 % \end{macrocode}
2579 % Calculate how many separators are put into the number.
2580 % \begin{macrocode}
2581 \setcounter{nprt@blockcnt}{\csname nprt@#1@fixeddigits@#2\endcsname}%
2582 \advance\c@nprt@blockcnt by -1\relax
2583 \divide\c@nprt@blockcnt 3%
2584 % \end{macrocode}
2585 % If four-digit length numbers are not separated, delete the number of
2586 % separators again.
2587 % \begin{macrocode}
2588 \ifnprt@numsepfour
2589 \else
2590 \ifnum\csname nprt@#1@fixeddigits@before\endcsname<5
2591 \ifnum\csname nprt@#1@fixeddigits@after\endcsname<5
2592 \setcounter{nprt@blockcnt}{0}%
2593 \fi
2594 \fi
2595 \fi
2596 % \end{macrocode}
2597 % Add the width of the separators to the width.
2598 % \begin{macrocode}
2599 \addtolength{\nprt@blockwidth}{\thenprt@blockcnt\nprt@sepwidth}%
2600 % \end{macrocode}
2601 % Add the width of the decimal sign to the width if it is after the
2602 % decimal sign and there shall be digits after the decimal sign.
2603 % \begin{macrocode}
2604 \ifx\nprt@argtwo\nprt@aftername
2605 \expandafter\ifnum\csname nprt@#1@fixeddigits@after\endcsname>0
2606 \addtolength{\nprt@blockwidth}{\the\nprt@decimalwidth}%
2607 \fi
2608 \fi
2609 }
2610 % \end{macrocode}
2611 % \end{macro}
2612 %
2613 % \begin{macro}{\npunit}
2614 % The \cs{npunit} command takes as argument a unit that is printed in
2615 % every cell of a table when using the (new) |n| or |N| column types.
2616 % \begin{macrocode}
2617 \newcommand*\npunit[1]{\def\nprt@unit{#1}}
2618 % \end{macrocode}
2619 % \end{macro}
2620 % \begin{macro}{\npnounit}
2621 % Initialize \cs{nprt@unit}.
2622 % \begin{macrocode}
2623 \edef\nprt@unit{\@empty}
2624 % \end{macrocode}
2625 % \end{macro}
2626 %
2627 % \begin{macro}{\npafternum}
2628 % The \cs{npunit} command takes as argument some text that is printed
2629 % after the number in every cell of a table when using the (new) |n|
2630 % or |N| column types.
2631 % \begin{macrocode}
2632 \newcommand*\npafternum[1]{\def\nprt@afternum{#1}}
2633 % \end{macrocode}
2634 % \end{macro}
2635 % \begin{macro}{\nprt@afternum}
2636 % Initialize \cs{nprt@afternum}.
2637 % \begin{macrocode}
2638 \edef\nprt@afternum{\@empty}
2639 % \end{macrocode}
2640 % \end{macro}
2641 % \begin{macro}{\npmakebox}
2642 % \changes{1.10}{2003/10/12}{Declare \cs{npmakebox} command}%
2643 % The \cs{npmakebox} is similar to the \cs{makebox} command but it
2644 % takes a text as first optional argument instead of a length.
2645 % The width of the box is calculated by the width of this text.
2646 % \begin{macrocode}
2647 \DeclareRobustCommand*\npmakebox{%
2648 \@ifnextchar[% ]
2649 {\nprt@makebox}{\makebox}%
2650 }
2651 % \end{macrocode}
2652 % \end{macro}
2653 % \begin{macro}{\nprt@makebox}
2654 % The internal part of the \cs{npmakebox} command.
2655 % \begin{macrocode}
2656 \newcommand*\nprt@makebox{}
2657 \def\nprt@makebox[#1]{%
2658 \settowidth\@tempdima{#1}%
2659 \makebox[\@tempdima]%
2660 }
2661 % \end{macrocode}
2662 % \end{macro}
2663 %
2664 % \changes{1.10}{2003/10/12}{Define math version \texttt{npbold}}%
2665 % Declare a bold math alphabet |npbold| that aligns with normal
2666 % digits.
2667 % \begin{macrocode}
2668 \ifnprt@npbold
2669 \DeclareMathVersion{npbold}
2670 \SetSymbolFont{operators}{npbold}{OT1}{cmr} {b}{n}
2671 \SetSymbolFont{letters} {npbold}{OML}{cmm} {b}{it}
2672 \SetSymbolFont{symbols} {npbold}{OMS}{cmsy}{b}{n}
2673 \SetMathAlphabet\mathsf{npbold}{OT1}{cmss}{b}{n}
2674 \SetMathAlphabet\mathit{npbold}{OT1}{cmr}{b}{it}
2675 % \end{macrocode}
2676 % \begin{macro}{\npboldmath}
2677 % Switch to that bold math alphabet.
2678 % \begin{macrocode}
2679 \def\npboldmath{\@nomath\npboldmath
2680 \mathversion{npbold}}
2681 \fi
2682 % \end{macrocode}
2683 % \end{macro}
2684 %
2685 %
2686 % \subsubsection{Auxilliary routines for the new column types}
2687 %
2688 % This code has been developed starting from the \texttt{rccol}
2689 % package by Eckhart Guth\"ohrlein~\cite{guthoehrlein2000a}.
2690 % Some small bugs of that package have been corrected here, too.
2691 %
2692 % \begin{macro}{\nprt@digittoks}
2693 % Token list that will contain all characters of a tabular cell that
2694 % are allowed for \cs{numprint}.
2695 % \begin{macrocode}
2696 \newtoks\nprt@digittoks
2697 % \end{macrocode}
2698 % \end{macro}
2699 % \begin{macro}{\nprt@pretoks}
2700 % Token list with all tokens before the number itself.
2701 % \begin{macrocode}
2702 \newtoks\nprt@pretoks
2703 % \end{macrocode}
2704 % \end{macro}
2705 % \begin{macro}{\nprt@posttoks}
2706 % Token list with all tokens after the number itself.
2707 % \begin{macrocode}
2708 \newtoks\nprt@posttoks
2709 % \end{macrocode}
2710 % \end{macro}
2711 % \begin{macro}{\ifnprt@numfound}
2712 % Has the number already been found in the parsing of the tabular
2713 % cell?
2714 % \begin{macrocode}
2715 \newif\ifnprt@numfound
2716 % \end{macrocode}
2717 % \end{macro}
2718 % \begin{macro}{\nprt@begin}
2719 % This macro is executed at the begin of each tabular cell.
2720 % \begin{macrocode}
2721 \def\nprt@begin{%
2722 % \end{macrocode}
2723 % Initialize the tokens and macros.
2724 % \begin{macrocode}
2725 \nprt@digittoks={}%
2726 \nprt@pretoks={}%
2727 \nprt@posttoks={}%
2728 \edef\nprt@unit{\@empty}%
2729 \edef\nprt@afternum{\@empty}%
2730 \nprt@numfoundfalse
2731 % \end{macrocode}
2732 % Set the allowed characters.
2733 % This macro is made empty when the number itself is read-in totally.
2734 % \begin{macrocode}
2735 \edef\nprt@allowedchars{\nprt@numberlist\nprt@dotlist\nprt@explist
2736 \nprt@signlist\nprt@ignorelist}%
2737 % \end{macrocode}
2738 % Start to parse the tabular cell.
2739 % \begin{macrocode}
2740 \nprt@getnexttok
2741 }
2742 % \end{macrocode}
2743 % \end{macro}
2744 % \begin{macro}{\nprt@saveothertok}
2745 % Adds the current token to the list of tokens before or after the
2746 % number.
2747 % \begin{macrocode}
2748 \def\nprt@saveothertok#1{%
2749 \ifnprt@numfound
2750 % \end{macrocode}
2751 % If the number has already been found it is ended now.
2752 % This is marked by clearing the list of allowed characters.
2753 % \begin{macrocode}
2754 \def\nprt@allowedchars{}%
2755 \nprt@posttoks=\expandafter{\the\nprt@posttoks#1}%
2756 \else
2757 \nprt@pretoks=\expandafter{\the\nprt@pretoks#1}%
2758 \fi
2759 }
2760 % \end{macrocode}
2761 % \end{macro}
2762 % \begin{macro}{\nprt@getnexttok}
2763 % \changes{1.31}{2004/08/18}{Bugfix: The numprint column types did not
2764 % like empty cells in the last column of a tabular}%
2765 % Parse the tabular cell.
2766 % The argument is the next token of the tabular cell.
2767 % Inside this command, the end of the tabular cell is detected by
2768 % different possibilities to end a cell.
2769 % \begin{macrocode}
2770 \def\nprt@getnexttok#1{%
2771 % \end{macrocode}
2772 % If the current token is \cs{tabularnewline} or |\\|
2773 % (which is the same) the tabular cell is finished.
2774 % \begin{macrocode}
2775 \ifx\tabularnewline#1%
2776 % \end{macrocode}
2777 % Redefine the \cs{nprt@next} command that is called at the end of
2778 % this command to execute the found \cs{tabularnewline} command.
2779 % \begin{macrocode}
2780 \let\nprt@next\tabularnewline
2781 \else
2782 % \end{macrocode}
2783 % If this tabular cell is not in the last column and a |&| is found,
2784 % the \cs{nprt@end} command is found that is inserted into this cell
2785 % using the |<| specifier by the columnn types.
2786 % \begin{macrocode}
2787 \ifx\end#1%
2788 % \end{macrocode}
2789 % Redefine \cs{nprt@next} to execute \cs{nprt@end} at the end of this
2790 % command.
2791 % \begin{macrocode}
2792 \let\nprt@next\end
2793 \else
2794 % \end{macrocode}
2795 % If this is the last cell of the tabular, the \cs{end} part of
2796 % \cs{end\{tabular\}} or \cs{end\{tabular*\}} is found.
2797 % \begin{macrocode}
2798 \ifx\nprt@end#1%
2799 % \end{macrocode}
2800 % Test whether it is the normal or the star version of the
2801 % environment.
2802 % Is this really necessary?
2803 % \begin{macrocode}
2804 \let\nprt@next\nprt@end
2805 \else
2806 % \end{macrocode}
2807 % If this is the last cell of the tabular and the tabular has been
2808 % called using \cs{tabular} \ldots\ \cs{endtabular} instead of using
2809 % the environment call, \cs{endtabular} is found.
2810 % \begin{macrocode}
2811 \ifx\endtabular#1%
2812 \let\nprt@next\endtabular
2813 \else
2814 % \end{macrocode}
2815 % For |tabularx|, a test on \cs{csname} has to be added.
2816 % \begin{macrocode}
2817 \ifx\csname#1%
2818 \let\nprt@next\csname
2819 \else
2820 % \end{macrocode}
2821 % If the last cell of a line is empty, \cs{relax} will be found.
2822 % \begin{macrocode}
2823 \ifx\relax#1%
2824 \let\nprt@next\relax
2825 \else
2826 % \end{macrocode}
2827 % If no command is found that ends the tabular cell, we are not yet at
2828 % the end of the cell.
2829 % Redefine \cs{nprt@next} to start this command recursively for
2830 % parsing the next token.
2831 % \begin{macrocode}
2832 \let\nprt@next\nprt@getnexttok
2833 % \end{macrocode}
2834 % Test if this token is one of the allowed characters of a number.
2835 % \begin{macrocode}
2836 \nprt@IfCharInString{#1}{\nprt@allowedchars}{%
2837 % \end{macrocode}
2838 % If yes, append this character to the token list of the number and
2839 % set the flag that the number has been found.
2840 % \begin{macrocode}
2841 \nprt@numfoundtrue
2842 \nprt@digittoks=\expandafter{\the\nprt@digittoks#1}%
2843 }{%
2844 % \end{macrocode}
2845 % If it is no character of a number, store it for the tokens before or
2846 % after the number.
2847 % \begin{macrocode}
2848 \nprt@saveothertok{#1}%
2849 }%
2850 \fi % \relax
2851 \fi % \csname
2852 \fi % \endtabular
2853 \fi % \nprt@end
2854 \fi % \end
2855 \fi % \tabularnewline
2856 % \end{macrocode}
2857 % Call the previously saved command (recursion or end of the tabular
2858 % cell).
2859 % \begin{macrocode}
2860 \nprt@next
2861 }
2862 % \end{macrocode}
2863 % Boolean to decide if math mode is active outside the tabular cell.
2864 % This is true for the |array| environment.
2865 % \begin{macrocode}
2866 \newif\ifnprt@mathtabular
2867 % \end{macrocode}
2868 % \end{macro}
2869 % \begin{macro}{\nprt@end}
2870 % This macro is called at the end of each tabular cell.
2871 % The arguments are used as follows: \meta{digits before},
2872 % \meta{digits after} the decimal sign for the mantissa;
2873 % \meta{digits before}, \meta{digits after} the decimal sign for the
2874 % exponent; commands inserted \meta{before} and \meta{after} the
2875 % \cs{numprint} command.
2876 % The arguments five and six are empty for printing the number in text
2877 % mode and contain ``|$|'' both for printing the number in math mode.
2878 % \begin{macrocode}
2879 \def\nprt@end#1#2#3#4#5#6{%
2880 % \end{macrocode}
2881 % First, print the tokens before the number.
2882 % \begin{macrocode}
2883 \the\nprt@pretoks
2884 % \end{macrocode}
2885 % Print the number in a group in order to save the tokens before and
2886 % after the number to be influenced by its settings.
2887 % \begin{macrocode}
2888 \begingroup
2889 % \end{macrocode}
2890 % Set the digits for the alignment of the mantissa.
2891 % \begin{macrocode}
2892 % \npnodigits
2893 \npdigits{#1}{#2}%
2894 % \end{macrocode}
2895 % Set the digits for the alignment of the exponent if given.
2896 % If no number of digits is given, they are set negativ.
2897 % \begin{macrocode}
2898 \npnoexponentdigits
2899 \ifnum#3<0
2900 \nprt@debug{no exponent alignment in tabular}%
2901 \else
2902 \ifnum#4<0
2903 \nprt@debug{exponent alignment in tabular with #3 digits}%
2904 \npexponentdigits{#3}%
2905 \else
2906 \nprt@debug{exponent alignment in tabular with #3.#4 digits}%
2907 \npexponentdigits[#4]{#3}%
2908 \fi
2909 \fi
2910 % \end{macrocode}
2911 % Omit the section that prints the number if no number has been
2912 % given.
2913 % \begin{macrocode}
2914 \ifnprt@numfound
2915 % \end{macrocode}
2916 % Print the pre-command if defined.
2917 % Since the pre-command is fixed to nothing or ``|$|'' to switch to
2918 % math mode, this is only done if the math mode is not active,
2919 % before.
2920 % Set the boolean \cs{ifnprt@mathtabular} according to the previous
2921 % status in order to close the math mode if necessary.
2922 % \begin{macrocode}
2923 \ifmmode
2924 \nprt@mathtabulartrue
2925 \else
2926 \nprt@mathtabularfalse
2927 #5%
2928 \fi
2929 % \end{macrocode}
2930 % Print the number, with unit if one has been given.
2931 % \begin{macrocode}
2932 \ifx\nprt@unit\@empty
2933 \numprint{\the\nprt@digittoks}%
2934 \else
2935 \numprint[\nprt@unit]{\the\nprt@digittoks}%
2936 \fi
2937 % \end{macrocode}
2938 % Switch off math mode if it has not been active before.
2939 % \begin{macrocode}
2940 \ifnprt@mathtabular
2941 \else
2942 #6%
2943 \fi
2944 % \end{macrocode}
2945 % Print a message to the log file if no number has been specified.
2946 % \begin{macrocode}
2947 \else
2948 \PackageInfo{numprint}{No number in tabular cell}%
2949 \fi
2950 % \end{macrocode}
2951 % Do the rest outside the group in order to prevent the post-texts
2952 % from being formatted as the number.
2953 % \begin{macrocode}
2954 \endgroup
2955 % \end{macrocode}
2956 % Print the tokens after the number.
2957 % \begin{macrocode}
2958 \the\nprt@posttoks
2959 % \end{macrocode}
2960 % Print the contents defined with \cs{npafternum}.
2961 % \begin{macrocode}
2962 \ifx\nprt@afternum\@empty
2963 \else
2964 \nprt@afternum
2965 \fi
2966 }
2967 % \end{macrocode}
2968 % \end{macro}
2969 %
2970 %
2971 % \subsubsection{New column types}
2972 % \changes{1.10}{2003/10/12}{New tabular alignment mechanism}%
2973 %
2974 % Define the new column types.
2975 % \begin{macrocode}
2976 \ifnprt@newcolumntype
2977 % \end{macrocode}
2978 %
2979 % Declare a new column type |N| which prints a number in text mode and
2980 % does not need to repeat \cs{numprint} in each tabular cell.
2981 % This is declared empty because all executing macros are redefined
2982 % anyway.
2983 % \begin{macrocode}
2984 \newcolumntype{N}{}
2985 % \end{macrocode}
2986 % \begin{macro}{\NC@rewrite@N}
2987 % Redefine this command to parse the declaration of the |N| column
2988 % type to look for an optional argument.
2989 % If none is given, set both optional arguments to ``|-1|''.
2990 % \begin{macrocode}
2991 \def\NC@rewrite@N{%
2992 \nprt@digittoks{}%
2993 \nprt@pretoks{}%
2994 % \end{macrocode}
2995 % If no optional argument is given, set both optional arguments to
2996 % ``|-1|''.
2997 % \begin{macrocode}
2998 \@ifnextchar[{% ]
2999 \nprt@rewrite@{}{}%
3000 }{%
3001 \nprt@rewrite@@{}{}{-1}[-1]%
3002 }%
3003 }
3004 % \end{macrocode}
3005 % \end{macro}
3006 % Declare a new column type |n| which prints a number and does not
3007 % need to repeat \cs{numprint} in each tabular cell.
3008 % This is declared empty because all executing macros are redefined
3009 % anyway.
3010 % \begin{macrocode}
3011 \newcolumntype{n}{}
3012 % \end{macrocode}
3013 % \begin{macro}{\NC@rewrite@n}
3014 % Same as \cs{NC@rewrite@N}, but give ``|$|'' twice for math mode.
3015 % \begin{macrocode}
3016 \def\NC@rewrite@n{%
3017 \nprt@digittoks{}%
3018 \nprt@pretoks{}%
3019 \@ifnextchar[{% ]
3020 \nprt@rewrite@{$}{$}%
3021 }{%
3022 \nprt@rewrite@@{$}{$}{-1}[-1]%
3023 }%
3024 }
3025 % \end{macrocode}
3026 % \end{macro}
3027 % \begin{macro}{\nprt@rewrite@}
3028 % Look for the second optional argument.
3029 % \begin{macrocode}
3030 \def\nprt@rewrite@#1#2[#3]{%
3031 \@ifnextchar[{%]
3032 \nprt@rewrite@@{#1}{#2}{#3}%
3033 }{%
3034 \nprt@rewrite@@{#1}{#2}{#3}[-1]%
3035 }%
3036 }
3037 % \end{macrocode}
3038 % \end{macro}
3039 % \begin{macro}{\nprt@rewrite@@}
3040 % The arguments are used as follows:
3041 % commands inserted \meta{before} and \meta{after} the
3042 % \cs{numprint} command; \meta{digits before}, \meta{digits after} the
3043 % decimal sign for the mantissa; \meta{digits before}, \meta{digits
3044 % after} the decimal sign for the exponent.
3045 % \begin{macrocode}
3046 \def\nprt@rewrite@@#1#2#3[#4]#5#6{%
3047 % \end{macrocode}
3048 % Add the definition for the current column to the already made column
3049 % definitions that are stored in \cs{@temptokena}.
3050 % Before the column itself, the starting command for the parsing,
3051 % \cs{nprt@begin}, is inserted.
3052 % At the end of the column, start the final work, command
3053 % \cs{nprt@end}.
3054 % These commands shall not be expanded, yet.
3055 % \begin{macrocode}
3056 \edef\nprt@rewrite@scratch{\the\@temptokena
3057 >{\noexpand\nprt@begin\noexpand\ignorespaces}l%
3058 <{\noexpand\nprt@end{#5}{#6}{#3}{#4}{#1}{#2}}%
3059 }%
3060 % \end{macrocode}
3061 % Set \cs{@temptokena} to the preceding and the current column
3062 % definition.
3063 % This is implicitely used by the |array| package.
3064 % \begin{macrocode}
3065 \@temptokena\expandafter{\nprt@rewrite@scratch}%
3066 % \end{macrocode}
3067 % Parse for next column in the definition.
3068 % \begin{macrocode}
3069 \NC@find
3070 }
3071 % \end{macrocode}
3072 % \end{macro}
3073 %
3074 %
3075 % \subsubsection{Old column types for compatibility}
3076 %
3077 % Define the old column types.
3078 % \begin{macrocode}
3079 \else
3080 % \end{macrocode}
3081 % The column type \verb|n| aligns the base number but not the exponent.
3082 % \begin{macrocode}
3083 \newcolumntype{n}[2]{>{\npdigits{#1}{#2}$}l<{$}}
3084 % \end{macrocode}
3085 % The column type \verb|N| aligns the base number as well as the exponent.
3086 % \begin{macrocode}
3087 \newcolumntype{N}[3]{%
3088 >{\npdigits{#1}{#2}\npexponentdigits{#3}$}l<{$}%
3089 }
3090 % \end{macrocode}
3091 % End of column type section.
3092 % \begin{macrocode}
3093 \fi
3094 % \end{macrocode}
3095 %
3096 %
3097 % \subsection{Round numbers}%
3098 % \label{sec:code:round}%
3099 %
3100 % Stores if the currenct digit has to be rounded up.
3101 % \begin{macrocode}
3102 \newif\ifnprt@roundup
3103 % \end{macrocode}
3104 % Declare the counter used inside \cs{nprt@round@after} and
3105 % \cs{nprt@round@before}.
3106 % \begin{macrocode}
3107 \newcount\nprt@thisdigit
3108 % \end{macrocode}
3109 % \begin{macro}{\nprt@round@after}
3110 % Does the rounding of the number after the decimal sign.
3111 % The first argument contains the current digit, the second the rest
3112 % of the number.
3113 %
3114 % This routine is a little bit complicated.
3115 % It is called recursively.
3116 % In the forward rund, it just counts the number of digits, it has
3117 % parsed already.
3118 % In the backward rund the rounding is done.
3119 % \begin{macrocode}
3120 \def\nprt@round@after#1#2\@empty{%
3121 % \end{macrocode}
3122 % Store the arguments in macros.
3123 % \begin{macrocode}
3124 \edef\nprt@argone{#1}%
3125 \edef\nprt@argtwo{#2}%
3126 % \end{macrocode}
3127 % Count the parsed digits.
3128 % \begin{macrocode}
3129 \advance \nprt@curpos by 1
3130 % \end{macrocode}
3131 % If the end of the number is reached an internal error has been
3132 % occured since enough zeros are appended to the number before.
3133 % \begin{macrocode}
3134 \ifx\nprt@argone\@empty
3135 \nprt@error{Rounding: End of number has been reached}{This may
3136 not happen}%
3137 \else
3138 % \end{macrocode}
3139 % If the current digit is one behind the last digit to be printed it
3140 % decides if the last printed digit is rounded or not.
3141 % This decision is stored in \cs{ifnprt@roundup}.
3142 % If this position is reached, stop the recursion.
3143 % \begin{macrocode}
3144 \ifnum\nprt@curpos>\nprt@rndpos
3145 \ifnum\nprt@argone>4
3146 \nprt@rounduptrue
3147 \fi
3148 \else
3149 % \end{macrocode}
3150 % The position has not been reached, yet.
3151 % Thus, call this routine recursively.
3152 % \begin{macrocode}
3153 \expandafter\nprt@round@after#2\@empty\@empty
3154 % \end{macrocode}
3155 % The following lines are executed in the backward run when rounding.
3156 %
3157 % Store the current digit in a number in order to be able to calculate
3158 % with it.
3159 % \begin{macrocode}
3160 \nprt@thisdigit=#1
3161 % \end{macrocode}
3162 % If this number is to be rounded up do it by advancing it by one.
3163 % \begin{macrocode}
3164 \ifnprt@roundup
3165 \advance \nprt@thisdigit by 1
3166 % \end{macrocode}
3167 % Reset \cs{ifnprt@roundup} since the preceeding digit is not to be
3168 % rounded, normally.
3169 % \begin{macrocode}
3170 \nprt@roundupfalse
3171 % \end{macrocode}
3172 % If the digit has been rounded from 9 to 10, it has to be a ``0'' and
3173 % the preceeding digit has to be rounded up.
3174 % \begin{macrocode}
3175 \ifnum\nprt@thisdigit=10
3176 \nprt@thisdigit=0
3177 \nprt@rounduptrue
3178 \fi
3179 \fi
3180 % \end{macrocode}
3181 % Store the modificated current digit to the new number by putting it
3182 % into \cs{nprt@newnum} before all digits that have been stored
3183 % before.
3184 % \begin{macrocode}
3185 \expandafter\xdef\expandafter\nprt@newnum{%
3186 \the\nprt@thisdigit\nprt@newnum}%
3187 \fi
3188 \fi
3189 }
3190 % \end{macrocode}
3191 % \end{macro}
3192 % \begin{macro}{\nprt@round@before}
3193 % Does the rounding of the number after the decimal sign.
3194 % The first argument contains the current digit, the second the rest
3195 % of the number.
3196 % This routine works as \cs{nprt@round@after} but stops at its end in
3197 % contrast to a given number.
3198 % \begin{macrocode}
3199 \def\nprt@round@before#1#2\@empty{%
3200 % \end{macrocode}
3201 % Store the arguments.
3202 % \begin{macrocode}
3203 \edef\nprt@argone{#1}%
3204 \edef\nprt@argtwo{#2}%
3205 % \end{macrocode}
3206 % Do the recursion until the end of the number.
3207 % This routine does not have to decide whether the number has to be
3208 % rounded since it knows that by \cs{ifnprt@roundup}, set by
3209 % \cs{nprt@round@after}.
3210 % \begin{macrocode}
3211 \ifx\nprt@argtwo\@empty
3212 \else
3213 \expandafter\nprt@round@before#2\@empty
3214 \fi
3215 % \end{macrocode}
3216 % Store the current digit into a counter and use zero if the number
3217 % before the decimal sign is empty.
3218 % \begin{macrocode}
3219 \ifx\nprt@argone\@empty
3220 \nprt@thisdigit=0
3221 \else
3222 \nprt@thisdigit=#1
3223 \fi
3224 % \end{macrocode}
3225 % Add one to the number if it has to be rounded.
3226 % \begin{macrocode}
3227 \ifnprt@roundup
3228 \advance \nprt@thisdigit by 1
3229 % \end{macrocode}
3230 % Reset the rounding of the next number.
3231 % \begin{macrocode}
3232 \nprt@roundupfalse
3233 % \end{macrocode}
3234 % If rounded from 9 to 10, set this digit to ``0'' and give the
3235 % information to the next digit.
3236 % \begin{macrocode}
3237 \ifnum\nprt@thisdigit=10
3238 \nprt@thisdigit=0
3239 \nprt@rounduptrue
3240 \fi
3241 \fi
3242 % \end{macrocode}
3243 % If the number is empty, the new number has to be added and the
3244 % counter adjusted.
3245 % \begin{macrocode}
3246 \ifx\nprt@argone\@empty
3247 \xdef\nprt@newnum{\the\nprt@thisdigit}%
3248 % \stepcounter{nprt@\nprt@numname @digitsbefore}%
3249 \advance\csname c@nprt@\nprt@numname @digitsbefore\endcsname 1\relax
3250 \else
3251 % \end{macrocode}
3252 % Insert the current digit before the already stored digits in
3253 % \cs{nprt@newnum}.
3254 % \begin{macrocode}
3255 \expandafter\xdef\expandafter\nprt@newnum{%
3256 \the\nprt@thisdigit\nprt@newnum}%
3257 \fi
3258 }
3259 % \end{macrocode}
3260 % \end{macro}
3261 % Two new counters for the round position and the current postion in
3262 % \cs{nprt@round@after}.
3263 % \begin{macrocode}
3264 \newcount\nprt@curpos
3265 \newcount\nprt@rndpos
3266 % \end{macrocode}
3267 % \begin{macro}{\nprt@round}
3268 % Round a number.
3269 % The first argument is the Number type (``mantissa'' resp.\
3270 % ``exponent''), the second is the number of digits to be printed
3271 % after the decimal sign.
3272 % \begin{macrocode}
3273 \newcommand*\nprt@round[2]{%
3274 \begingroup
3275 % \end{macrocode}
3276 % Store the Number type for use in \cs{nprt@round@before} and
3277 % \cs{nprt@round@after}.
3278 % \begin{macrocode}
3279 \edef\nprt@numname{#1}%
3280 % \end{macrocode}
3281 % If the number of printed digits after the decimal sign is negative,
3282 % no rounding will be performed.
3283 % \begin{macrocode}
3284 \ifnum#2<0
3285 \else
3286 % \end{macrocode}
3287 % Print a debug message.
3288 % \begin{macrocode}
3289 \nprt@debug{\string\nprt@round: Round after #2 digits for #1}%
3290 % \end{macrocode}
3291 % Set the number of digits after the decimal sign to the given value
3292 % since this number of digits will be printed later.
3293 % \begin{macrocode}
3294 \setcounter{nprt@#1@digitsafter}{#2}%
3295 % \end{macrocode}
3296 % Append enough zeros to the after-decimal-sign part in order to have
3297 % enough digits that \cs{nprt@round@after} will not reach the end of
3298 % the number.
3299 % \begin{macrocode}
3300 \expandafter\g@addto@macro\csname nprt@#1@after\endcsname{%
3301 \nprt@roundnull}%
3302 % \end{macrocode}
3303 % Set the number of digits after the decimal sign.
3304 % \begin{macrocode}
3305 \nprt@rndpos=#2
3306 % \end{macrocode}
3307 % Default not to round.
3308 % \begin{macrocode}
3309 \nprt@roundupfalse
3310 % \end{macrocode}
3311 % Define the ``working'' number for the subroutines.
3312 % \begin{macrocode}
3313 \edef\nprt@tmpnum{\csname nprt@#1@after\endcsname}%
3314 % \end{macrocode}
3315 % The new number starts empty and will be filled by
3316 % \cs{nprt@round@after}.
3317 % \begin{macrocode}
3318 \edef\nprt@newnum{}%
3319 % \end{macrocode}
3320 % Do the rounding after the decimal sign.
3321 % \begin{macrocode}
3322 \expandafter\nprt@round@after\nprt@tmpnum\@empty\@empty
3323 % \end{macrocode}
3324 % Copy the new number after the decimal sign to the ``official''
3325 % command storing it.
3326 % \begin{macrocode}
3327 \expandafter\xdef\csname nprt@#1@after\endcsname{\nprt@newnum}%
3328 % \end{macrocode}
3329 % If the integer part has to be modificated, too, do it.
3330 % \begin{macrocode}
3331 \ifnprt@roundup
3332 % \end{macrocode}
3333 % Copy the number to the working number.
3334 % \begin{macrocode}
3335 \edef\nprt@tmpnum{\csname nprt@#1@before\endcsname}%
3336 % \end{macrocode}
3337 % Clear the new number.
3338 % \begin{macrocode}
3339 \edef\nprt@newnum{}%
3340 % \end{macrocode}
3341 % Do the rounding before the decimal sign.
3342 % \begin{macrocode}
3343 \expandafter\nprt@round@before\nprt@tmpnum\@empty\@empty
3344 % \end{macrocode}
3345 % If the first digit has been rounded up from 9 a new digit ``1'' has
3346 % to be inserted before the number.
3347 % \begin{macrocode}
3348 \ifnprt@roundup
3349 \expandafter\xdef\expandafter\nprt@newnum{1\nprt@newnum}%
3350 % \stepcounter{nprt@#1@digitsbefore}%
3351 \advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
3352 \fi
3353 % \end{macrocode}
3354 % Copy the new number before the decimal sign to the ``official''
3355 % command storing it.
3356 % \begin{macrocode}
3357 \expandafter\xdef\csname nprt@#1@before\endcsname{\nprt@newnum}%
3358 \fi
3359 \fi
3360 \endgroup
3361 % \end{macrocode}
3362 % Set the boolean for a found decimal sign according to the number of
3363 % printed decimals.
3364 % \begin{macrocode}
3365 \ifnum#2<0
3366 \else
3367 % \end{macrocode}
3368 % If rounded to no digits after the decimal sign, switch off printing
3369 % of it.
3370 % \begin{macrocode}
3371 \ifnum#2=0
3372 \csname nprt@#1@decimalfoundfalse\endcsname
3373 \else
3374 % \end{macrocode}
3375 % If one or more digits are printed, a decimal sign has to be printed.
3376 % \begin{macrocode}
3377 \csname nprt@#1@decimalfoundtrue\endcsname
3378 \fi
3379 \fi
3380 }%
3381 % \end{macrocode}
3382 % \end{macro}
3383 % \begin{macro}{\nprt@lpad}
3384 % Pad a number with a character on the left side.
3385 % The first argument contains the number, the second is the desired length
3386 % and the third the padding character.
3387 % \begin{macrocode}
3388 \newcommand*\nprt@lpad[3]{%
3389 % \end{macrocode}
3390 % If the count of digits is negative, no padding will be performed.
3391 % \begin{macrocode}
3392 \ifnum#2<0
3393 \else
3394 % \end{macrocode}
3395 % Print a debug message.
3396 % \begin{macrocode}
3397 \nprt@debug{\string\nprt@lpad: Padding #1 with #3 to a length of #2}%
3398 % \end{macrocode}
3399 % If the number has less than the desired length, add the padding character
3400 % to the left and call this function recursively.
3401 % \begin{macrocode}
3402 \ifnum\csname thenprt@#1@digitsbefore\endcsname<#2
3403 \expandafter\xdef\csname nprt@#1@before\endcsname{%
3404 #3\csname nprt@#1@before\endcsname}%
3405 % \stepcounter{nprt@#1@digitsbefore}%
3406 \advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
3407 \nprt@lpad{#1}{#2}{#3}%
3408 \fi
3409 \fi
3410 }%
3411 % \end{macrocode}
3412 % \end{macro}
3413 %
3414 %
3415 % \subsection{Print the numbers}
3416 %
3417 % \begin{macro}{\nprt@sign@+}
3418 % \begin{macro}{\nprt@sign@-}
3419 % \begin{macro}{\nprt@sign@+-}
3420 % Define commands for printing the signs in math mode. This ensures
3421 % that the printed signs really are signs and not hyphens. Compare
3422 % ``-'' to ``\ensuremath{-}''.
3423 % \changes{1.39}{2012/08/20}{Move group around sign into the specific
3424 % sign macros in order to allow colour again}%
3425 % \begin{macrocode}
3426 \expandafter\newcommand\csname nprt@sign@+\endcsname{{\ensuremath{+}}}
3427 \expandafter\newcommand\csname nprt@sign@-\endcsname{{\ensuremath{-}}}
3428 \expandafter\newcommand\csname nprt@sign@+-\endcsname{{\ensuremath{\pm}}}
3429 % \end{macrocode}
3430 % \end{macro}
3431 % \end{macro}
3432 % \end{macro}
3433 % \begin{macro}{\nprt@printsign}
3434 % Print a sign.
3435 % The first argument contains the number type (``mantissa'' or
3436 % ``exponent'').
3437 % The second argument contains the sign as in source code.
3438 % \begin{macrocode}
3439 \newcommand*\nprt@printsign[2]{%
3440 % \end{macrocode}
3441 % Write sign to log file.
3442 % \begin{macrocode}
3443 \nprt@debug{\string\nprt@printsign: `#2'}%
3444 % \end{macrocode}
3445 % Set command in a group to prevent the defined macros from being
3446 % global.
3447 % \begin{macrocode}
3448 \edef\nprt@marg{#2}%
3449 % \end{macrocode}
3450 % If a plus is to be added do it if no sign given.
3451 % \begin{macrocode}
3452 \csname ifnprt@addplus@#1\endcsname
3453 \ifx\nprt@marg\@empty
3454 \edef\nprt@marg{+}%
3455 \fi
3456 \fi
3457 % \end{macrocode}
3458 % Do nothing if still no sign given.
3459 % \begin{macrocode}
3460 \ifx\nprt@marg\@empty
3461 \else
3462 % \end{macrocode}
3463 % If a macro \cs{nprt@sign@\meta{sign}} is defined for the given sign,
3464 % e.g., \cs{nprt@sign@+}, print it; if not, print the sign itself.
3465 % \changes{1.22}{2004/08/08}{Print sign in a group to avoid additional space
3466 % for an operator (for nbaseprt)}%
3467 % \changes{1.39}{2012/08/20}{Move group around sign into the specific
3468 % sign macros in order to allow colour again}%
3469 % \begin{macrocode}
3470 \@ifundefined{nprt@sign@\nprt@marg}{%
3471 \PackageWarning{numprint}{%
3472 Unknown sign `\nprt@marg'. Print as typed in}%
3473 \nprt@marg
3474 }{%
3475 \csname nprt@sign@\nprt@marg\endcsname%
3476 }%
3477 \fi
3478 }
3479 % \end{macrocode}
3480 % \end{macro}
3481 % Internal counters for printing.
3482 % \begin{macrocode}
3483 \newcounter{nprt@digitsfirstblock}
3484 \newcounter{nprt@blockcnt}
3485 % \end{macrocode}
3486 % Internal boolean.
3487 % \begin{macrocode}
3488 \newif\ifnprt@shortnumber
3489 % \end{macrocode}
3490 % \begin{macro}{\nprt@printbefore}
3491 % Print the number before the decimal sign.
3492 % The argument is the Number type (``mantissa'' or ``exponent'').
3493 % When this macro is called, everything is parsed already.
3494 % Thus, it is known whether a decimal sign has been found, which and
3495 % how many digits are before resp.\ after the decimal sign etc.
3496 % \begin{macrocode}
3497 \newcommand*\nprt@printbefore[1]{%
3498 % \end{macrocode}
3499 % If missing zeros shall be added and there is no digit before the
3500 % decimal sign store that ``0'' into the corresponding command and
3501 % store in the counter that the number of digits before the decimal
3502 % sign is one, know.
3503 % \begin{macrocode}
3504 \ifnprt@addmissingzero
3505 \ifnum\csname thenprt@#1@digitsbefore\endcsname=0
3506 \expandafter\edef\csname nprt@#1@before\endcsname{0}%
3507 % \stepcounter{nprt@#1@digitsbefore}%
3508 \advance\csname c@nprt@#1@digitsbefore\endcsname by 1\relax
3509 \fi
3510 \fi
3511 % \end{macrocode}
3512 % I'm not sure why I have added the group here.
3513 % But it works and I won't change it, therefore.
3514 % \begin{macrocode}
3515 \begingroup
3516 % \end{macrocode}
3517 % Store the number to be printed in \cs{nprt@numbertoprint} in order
3518 % to have simpler calls in this routine than using \cs{csname}\ldots
3519 % \begin{macrocode}
3520 \edef\nprt@numbertoprint{\csname nprt@#1@before\endcsname}%
3521 % \end{macrocode}
3522 % If four-digit numbers are not to be separated and both, the integer
3523 % and the real parts, are shorter than 5 digits, set the boolean
3524 % \cs{ifnprt@shortnumber} to ``true'' that the number is printed
3525 % without separators, later.
3526 % \begin{macrocode}
3527 \ifnprt@numsepfour
3528 \else
3529 \ifnum\csname thenprt@#1@digitsbefore\endcsname<5
3530 \ifnum\csname thenprt@#1@digitsafter\endcsname<5
3531 \nprt@shortnumbertrue
3532 \fi
3533 \fi
3534 \fi
3535 % \end{macrocode}
3536 % If the number is short according to the preceeding code, just print
3537 % that number by calling \cs{nprt@numbertoprint}.
3538 % \begin{macrocode}
3539 \ifnprt@shortnumber
3540 \nprt@numbertoprint
3541 \else
3542 % \end{macrocode}
3543 % If the number will get separators, calculate how many separators
3544 % will be inserted.
3545 % \begin{macrocode}
3546 % ganze Bloecke
3547 \setcounter{nprt@blockcnt}{%
3548 \csname thenprt@#1@digitsbefore\endcsname}%
3549 \advance\c@nprt@blockcnt by -1\relax
3550 \divide\c@nprt@blockcnt 3%
3551 % \end{macrocode}
3552 % Then, calculate how many digits are in the first block (one, two, or
3553 % three).
3554 % Use \cs{c@nprt@cntprint} as temporary variable.
3555 % \begin{macrocode}
3556 \setcounter{nprt@digitsfirstblock}{%
3557 \csname thenprt@#1@digitsbefore\endcsname}%
3558 \setcounter{nprt@cntprint}{\thenprt@blockcnt}%
3559 \multiply \c@nprt@cntprint 3%
3560 \advance\c@nprt@digitsfirstblock by -\thenprt@cntprint\relax
3561 % \end{macrocode}
3562 % Depending on that number, call \cs{nprt@printone},
3563 % \cs{nprt@printtwo}, resp.\ \cs{nprt@printthree} which do what you
3564 % may expect with that names.
3565 % \begin{macrocode}
3566 \ifnum\thenprt@digitsfirstblock=1
3567 \expandafter\nprt@printone\nprt@numbertoprint\@empty
3568 \else
3569 \ifnum\thenprt@digitsfirstblock=2
3570 \expandafter\nprt@printtwo\nprt@numbertoprint\@empty
3571 \else
3572 \ifnum\thenprt@digitsfirstblock=3
3573 \expandafter\nprt@printthree\nprt@numbertoprint\@empty
3574 \else
3575 \ifnum\thenprt@digitsfirstblock=0
3576 \else
3577 \PackageError{numprint}{internal error}{}%
3578 \fi
3579 \fi
3580 \fi
3581 \fi
3582 \fi
3583 \endgroup
3584 }
3585 % \end{macrocode}
3586 % \end{macro}
3587 % \begin{macro}{\nprt@printthree}
3588 % Print three digits.
3589 % If the command has not reached the end of the string, print a
3590 % separator \cs{nprt@separator@before} and call this routine
3591 % recursively.
3592 % Surprisingly, this routine does not work if |#1#2#3| is the first
3593 % command in some cases.
3594 % Thus, \cs{def}cs{nprt@tmp} has been moved in front of it.
3595 % Make sure that this works in all cases.
3596 % Same applies for \cs{nprt@printtwo}, \cs{nprt@printone}, and
3597 % \cs{nprt@printthreeafter}.
3598 % \begin{macrocode}
3599 \def\nprt@printthree#1#2#3#4\@empty{%
3600 \def\nprt@tmp{#4}%
3601 #1#2#3%
3602 \ifx\nprt@tmp\empty
3603 \else
3604 \nprt@separator@before%
3605 \nprt@printthree#4\@empty\@empty\@empty
3606 \fi
3607 }
3608 % \end{macrocode}
3609 % \end{macro}
3610 % \begin{macro}{\nprt@printtwo}
3611 % The same but start with two instead of three digits.
3612 % \begin{macrocode}
3613 \def\nprt@printtwo#1#2#3\@empty{%
3614 \def\nprt@tmp{#3}%
3615 #1#2%
3616 \ifx\nprt@tmp\empty
3617 \else
3618 \nprt@separator@before%
3619 \nprt@printthree#3\@empty\@empty\@empty
3620 \fi
3621 }
3622 % \end{macrocode}
3623 % \end{macro}
3624 % \begin{macro}{\nprt@printone}
3625 % The same but start with one instead of three digits.
3626 % \begin{macrocode}
3627 \def\nprt@printone#1#2\@empty{%
3628 \def\nprt@tmp{#2}%
3629 #1%
3630 \ifx\nprt@tmp\empty
3631 \else
3632 \nprt@separator@before%
3633 \nprt@printthree#2\@empty\@empty\@empty
3634 \fi
3635 }
3636 % \end{macrocode}
3637 % \end{macro}
3638 % \begin{macro}{\nprt@printafter}
3639 % Print the number after the decimal sign.
3640 % The argument is the Number type (``mantissa'' or ``exponent'').
3641 % This macro works similarly as \cs{nprt@printbefore}.
3642 % \begin{macrocode}
3643 \newcommand*\nprt@printafter[1]{%
3644 % \end{macrocode}
3645 % If a missing zero shall be added do it if no digits are given after
3646 % the decimal sign if a decimal sign has been given.
3647 % If no decimal sign has been given, the number is pure integer and
3648 % does not get a real part.
3649 % \begin{macrocode}
3650 \csname ifnprt@#1@decimalfound\endcsname
3651 \ifnprt@addmissingzero
3652 \ifnum\csname thenprt@#1@digitsafter\endcsname=0
3653 \expandafter\edef\csname nprt@#1@after\endcsname{0}%
3654 % \stepcounter{nprt@#1@digitsafter}%
3655 \advance\csname c@nprt@#1@digitsafter\endcsname by 1\relax
3656 \fi
3657 \fi
3658 % \end{macrocode}
3659 % If a after-decimal zero will be replaced by another command but the
3660 % real part is empty, put a ``0'' after the comma (same as
3661 % ``addmissingzero'', but here it is just a hack in order to enable
3662 % the replacement command to take effect later).
3663 % \begin{macrocode}
3664 \ifx\nprt@replacenull\@empty
3665 \else
3666 \ifnum\csname thenprt@#1@digitsafter\endcsname=0
3667 \expandafter\edef\csname nprt@#1@after\endcsname{0}%
3668 % \stepcounter{nprt@#1@digitsafter}%
3669 \advance\csname c@nprt@#1@digitsafter\endcsname by 1\relax
3670 \fi
3671 \fi
3672 \fi
3673 % \end{macrocode}
3674 % Store the number in \cs{nprt@numbertoprint} and continue only if it
3675 % is not empty.
3676 % \begin{macrocode}
3677 \begingroup
3678 \edef\nprt@numbertoprint{\csname nprt@#1@after\endcsname}%
3679 \ifx\nprt@numbertoprint\@empty
3680 \else
3681 % \end{macrocode}
3682 % Find out whether separators have to be inserted.
3683 % \begin{macrocode}
3684 \ifnprt@numsepfour
3685 \else
3686 \ifnum\csname thenprt@#1@digitsbefore\endcsname<5
3687 \ifnum\csname thenprt@#1@digitsafter\endcsname<5
3688 \nprt@shortnumbertrue
3689 \fi
3690 \fi
3691 \fi
3692 % \end{macrocode}
3693 % If a zero has to be replaced by a replacement text, and if the after
3694 % comma part has the numerical value ``0'' (= it contains of zeros
3695 % only), do the replacement.
3696 % \begin{macrocode}
3697 \ifx\nprt@replacenull\@empty
3698 \else
3699 \ifnum\nprt@numbertoprint=0
3700 \nprt@shortnumbertrue
3701 \edef\nprt@numbertoprint{\nprt@replacenull}%
3702 \fi
3703 \fi
3704 % \end{macrocode}
3705 % If the number is short (without separators) just print it.
3706 % \begin{macrocode}
3707 \ifnprt@shortnumber
3708 \nprt@numbertoprint
3709 \else
3710 % \end{macrocode}
3711 % Print the number with separators.
3712 % The choice between different block sizes does not have to be done
3713 % because the after-decimal-sign part starts with three-digit block
3714 % from the left end.
3715 % \begin{macrocode}
3716 \expandafter\nprt@printthree@after%
3717 \nprt@numbertoprint\@empty\@empty\@empty
3718 \fi
3719 \fi
3720 \endgroup
3721 }
3722 % \end{macrocode}
3723 % \end{macro}
3724 % \begin{macro}{\nprt@printthree@after}
3725 % The same as \cs{nprt@printthree} but with another separator.
3726 % \begin{macrocode}
3727 \def\nprt@printthree@after#1#2#3#4\@empty{%
3728 \def\nprt@tmp{#4}%
3729 #1#2#3%
3730 \ifx\nprt@tmp\empty
3731 \else
3732 \nprt@separator@after
3733 \nprt@printthree@after#4\@empty\@empty\@empty
3734 \fi
3735 }
3736 % \end{macrocode}
3737 % \end{macro}
3738 %
3739 %
3740 % \subsection{The main command}%
3741 % \label{sec:code:main}%
3742 %
3743 % \begin{macro}{\numprint}
3744 % The main macro of the package.
3745 % The mandatory argument takes a number and prints it as described
3746 % above.
3747 % The optional argument may contain a unit which then is printed,
3748 % too.
3749 % \begin{macrocode}
3750 \DeclareRobustCommand*\numprint[2][\@empty]{%
3751 % \end{macrocode}
3752 % Switch off the error flag.
3753 % This should not be necessary but is done for stability reasons.
3754 % \begin{macrocode}
3755 \nprt@argumenterrorfalse
3756 % \end{macrocode}
3757 % Clear the mantissa and the exponent.
3758 % \begin{macrocode}
3759 \xdef\nprt@exponent{\@empty}%
3760 \xdef\nprt@mantissa{\@empty}%
3761 % \end{macrocode}
3762 % Do everything inside a group to avoid defining too many temporary
3763 % macros that are not deleted after the macro.
3764 % \begin{macrocode}
3765 \begingroup
3766 % \end{macrocode}
3767 % Store the mandatory argument into a macro.
3768 % Redefine \cs{,} and |~| to do nothing as to ignore them.
3769 % Because the argument is expanded this does not work with the ignore
3770 % list for characters.
3771 % This again has to be done inside a group to preserve the two macros
3772 % for later usage.
3773 % \begin{macrocode}
3774 \begingroup
3775 \def\,{}%
3776 \catcode`\~=\active % tilde is active
3777 \def~{}%
3778 \xdef\nprt@marg{#2}%
3779 \endgroup
3780 % \end{macrocode}
3781 % Don't expand the unit because that may cause trouble.
3782 % \begin{macrocode}
3783 \def\nprt@oarg{#1}%
3784 % \end{macrocode}
3785 % Declare some commands to detect empty arguments.
3786 % \begin{macrocode}
3787 \def\nprt@@empty{\@empty}%
3788 \def\nprt@nix{}%
3789 \def\nprt@nixleer{ }%
3790 % \end{macrocode}
3791 % Some debug information.
3792 % \begin{macrocode}
3793 \ifx\nprt@oarg\nprt@@empty
3794 \nprt@debug{\string\numprint{\protect#2}}%
3795 \else
3796 \nprt@debug{\string\numprint[\protect#1]{\protect#2}}%
3797 \fi
3798 % \end{macrocode}
3799 % Test for an empty mandatory argument.
3800 % \begin{macrocode}
3801 \ifx\nprt@marg\nprt@nix
3802 \nprt@error{empty argument}{You have to specify a number in
3803 the argument of \string\numprint}%
3804 \fi
3805 \ifx\nprt@marg\nprt@nixleer
3806 \nprt@error{empty argument}{You have to specify a number in
3807 the argument of \string\numprint}%
3808 \fi
3809 % \end{macrocode}
3810 % Test whether only valid characters have been used and devide the
3811 % argument in the mantissa and the exponent.
3812 % \begin{macrocode}
3813 \expandafter\nprt@testcharacter\nprt@marg\@empty\@empty
3814 % \end{macrocode}
3815 % If there are invalid characters in the argument, just print the
3816 % argument without formatting it.
3817 % Redefine \cs{pm} to avoid an additional error in text mode.
3818 % \begin{macrocode}
3819 \ifnprt@argumenterror
3820 \begingroup\def\pm{+-}#2\endgroup
3821 \else
3822 % \end{macrocode}
3823 % If everything is okay, proceed with parsing.
3824 %
3825 % \changes{1.31}{2004/08/18}{Bugfix: \cs{numprint\{e123\}} reprinted the
3826 % last used sign}%
3827 % If the mantissa is empty don't work on it but reset the sign of the
3828 % mantissa to avoid to reprint the old sign when using
3829 % \cs{numprint\{e123\}}.
3830 % If it is not empty, parse it for a sign and a number.
3831 % \begin{macrocode}
3832 \ifx\nprt@mantissa\@empty
3833 \def\nprt@mantissa@sign{\@empty}%
3834 \else
3835 \nprt@testsign{mantissa}{\nprt@mantissa}%
3836 \fi
3837 % \end{macrocode}
3838 % If the mantissa contains only a sign, \cs{nprt@mantissa} is set to
3839 % \cs{@empty} and thus empty even if it wasn't 4 lines above.
3840 % If the mantissa only contains of a sign and an exponent is given,
3841 % everything is fine.
3842 % If no exponent is given, the input format is invalid.
3843 % \begin{macrocode}
3844 \ifx\nprt@mantissa\@empty
3845 \ifx\nprt@exponent\@empty
3846 \nprt@error{Invalid number format. Printing the
3847 argument\MessageBreak
3848 verbatim}{Something is wrong in the format of the number}%
3849 \else
3850 \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
3851 \fi
3852 \else
3853 % \end{macrocode}
3854 % Round the mantissa if necessary.
3855 % \begin{macrocode}
3856 \nprt@round{mantissa}{\nprt@rounddigits}%
3857 % \end{macrocode}
3858 % Pad the mantissa if necessary.
3859 % \begin{macrocode}
3860 \nprt@lpad{mantissa}{\nprt@lpaddigits}{\nprt@lpadchar}%
3861 \fi
3862 % \end{macrocode}
3863 % If an exponent has been found, parse this like the mantissa.
3864 % \begin{macrocode}
3865 \ifnprt@expfound
3866 % \end{macrocode}
3867 % Test whether an exponent character was given but no exponent.
3868 % \begin{macrocode}
3869 \ifx\nprt@exponent\@empty
3870 \nprt@error{Empty exponent}{If you specify an exponent
3871 using one of the characters `\nprt@explist' you
3872 have\MessageBreak
3873 to give an exponent, too.}%
3874 \else
3875 \nprt@testsign{exponent}{\nprt@exponent}%
3876 \nprt@round{exponent}{\nprt@roundexpdigits}%
3877 \fi
3878 \fi
3879 % \end{macrocode}
3880 % If either the mantissa or the exponent produces an error, just print
3881 % the argument as is.
3882 % Redefine \cs{pm} to avoid an additional error in text mode.
3883 % \begin{macrocode}
3884 \ifnprt@argumenterror
3885 \begingroup\def\pm{+-}#2\endgroup
3886 \else
3887 % \end{macrocode}
3888 % Print the mantissa if present.
3889 % \begin{macrocode}
3890 \ifx\nprt@mantissa\@empty
3891 \else
3892 % \end{macrocode}
3893 % Print the part before the decimal sign.
3894 %
3895 % If the number shall be printed in a box (table alignment) some
3896 % special things have to be done.
3897 % \begin{macrocode}
3898 \ifnprt@mantissa@fixeddigits
3899 \ifmmode
3900 % \end{macrocode}
3901 % In math mode, it must be decided which math style is active because
3902 % the width of the box depends on that.
3903 % The \cs{mathchoice} command does the formatting for all styles and
3904 % typesets the active one then.
3905 % \begin{macrocode}
3906 \mathchoice{%
3907 % \end{macrocode}
3908 % Calculate the width of the block for the \cs{displaystyle}.
3909 % \begin{macrocode}
3910 \nprt@calcblockwidth{mantissa}{before}{\displaystyle}%
3911 % \end{macrocode}
3912 % Generate a box with the calculated width and the corresponding math
3913 % style.
3914 % \begin{macrocode}
3915 \makebox[\the\nprt@blockwidth][r]{$\displaystyle
3916 % \end{macrocode}
3917 % Print the sign if present.
3918 % \begin{macrocode}
3919 \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
3920 % \end{macrocode}
3921 % Print the integer part into the box.
3922 % \begin{macrocode}
3923 \nprt@printbefore{mantissa}$}%
3924 }{%
3925 % \end{macrocode}
3926 % Do the same for \cs{textstyle}.
3927 % \begin{macrocode}
3928 \nprt@calcblockwidth{mantissa}{before}{\textstyle}%
3929 \makebox[\the\nprt@blockwidth][r]{$\textstyle
3930 \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
3931 \nprt@printbefore{mantissa}$}%
3932 }{%
3933 % \end{macrocode}
3934 % Do the same for \cs{scriptstyle}.
3935 % \begin{macrocode}
3936 \nprt@calcblockwidth{mantissa}{before}{\scriptstyle}%
3937 \makebox[\the\nprt@blockwidth][r]{$\scriptstyle
3938 \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
3939 \nprt@printbefore{mantissa}$}%
3940 }{%
3941 % \end{macrocode}
3942 % Do the same for \cs{scriptscriptstyle}.
3943 % \begin{macrocode}
3944 \nprt@calcblockwidth{mantissa}{before}{\scriptscriptstyle}%
3945 \makebox[\the\nprt@blockwidth][r]{$\scriptscriptstyle
3946 \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
3947 \nprt@printbefore{mantissa}$}%
3948 }%
3949 \else
3950 % \end{macrocode}
3951 % If the number is printed in text mode, the size is preserved inside
3952 % the box.
3953 % Thus, no hack as for math mode is necessary.
3954 % \begin{macrocode}
3955 \nprt@calcblockwidth{mantissa}{before}{\@empty}%
3956 \makebox[\the\nprt@blockwidth][r]{%
3957 \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
3958 \nprt@printbefore{mantissa}%
3959 }%
3960 \fi
3961 \else
3962 % \end{macrocode}
3963 % If the number is printed without fixed width, just print it.
3964 % \begin{macrocode}
3965 \nprt@printsign{mantissa}{\nprt@mantissa@sign}%
3966 \nprt@printbefore{mantissa}%
3967 \fi
3968 % \end{macrocode}
3969 % Print the after-decimal-sign digits.
3970 % This works exactly as the integer part.
3971 % \begin{macrocode}
3972 \ifnprt@mantissa@fixeddigits
3973 \ifmmode
3974 \mathchoice{%
3975 \nprt@calcblockwidth{mantissa}{after}{\displaystyle}%
3976 \makebox[\the\nprt@blockwidth][l]{$\displaystyle
3977 \ifnprt@mantissa@decimalfound
3978 \nprt@decimal
3979 \fi
3980 \nprt@printafter{mantissa}$}%
3981 }{%
3982 \nprt@calcblockwidth{mantissa}{after}{\textstyle}%
3983 \makebox[\the\nprt@blockwidth][l]{$\textstyle
3984 \ifnprt@mantissa@decimalfound
3985 \nprt@decimal
3986 \fi
3987 \nprt@printafter{mantissa}$}%
3988 }{%
3989 \nprt@calcblockwidth{mantissa}{after}{\scriptstyle}%
3990 \makebox[\the\nprt@blockwidth][l]{$\scriptstyle
3991 \ifnprt@mantissa@decimalfound
3992 \nprt@decimal
3993 \fi
3994 \nprt@printafter{mantissa}$}%
3995 }{%
3996 \nprt@calcblockwidth{mantissa}{after}{\scriptscriptstyle}%
3997 \makebox[\the\nprt@blockwidth][l]{$\scriptscriptstyle
3998 \ifnprt@mantissa@decimalfound
3999 \nprt@decimal
4000 \fi
4001 \nprt@printafter{mantissa}$}%
4002 }%
4003 \else
4004 \nprt@calcblockwidth{mantissa}{after}{\@empty}%
4005 \makebox[\the\nprt@blockwidth][l]{%
4006 \ifnprt@mantissa@decimalfound
4007 \nprt@decimal
4008 \fi
4009 \nprt@printafter{mantissa}%
4010 }%
4011 \fi
4012 \else
4013 \ifnprt@mantissa@decimalfound
4014 \nprt@decimal
4015 \fi
4016 \nprt@printafter{mantissa}%
4017 \fi
4018 \fi
4019 % \end{macrocode}
4020 % If an exponent is defined it has to be printed later.
4021 % Therefore, define the command \cs{nprt@printexp} that just prints
4022 % its argument.
4023 % \begin{macrocode}
4024 \ifnprt@expfound
4025 \def\nprt@printexp##1{##1}%
4026 % \end{macrocode}
4027 % If a sign but no number has been given for the exponent
4028 % \cs{nprt@exponent} is empty but \cs{ifnprt@expfound} true.
4029 % Test for this case here.
4030 % \begin{macrocode}
4031 \ifx\nprt@exponent\@empty
4032 \nprt@error{Invalid number format in
4033 exponent. Printing\MessageBreak
4034 garbage}{Something is wrong in the format of the exponent}%
4035 \fi
4036 \else
4037 % \end{macrocode}
4038 % If there is no exponent but digits reserved for it, define the
4039 % \cs{nprt@printexp} so that is just needs that space but does not
4040 % print anything.
4041 % \begin{macrocode}
4042 \ifnprt@exponent@fixeddigits
4043 \def\nprt@printexp##1{\hphantom{##1}}%
4044 \else
4045 % \end{macrocode}
4046 % If there is no exponent and no reserved digits, don't print the
4047 % exponent.
4048 % \begin{macrocode}
4049 \def\nprt@printexp##1{}%
4050 \fi
4051 \fi
4052 % \end{macrocode}
4053 % If\label{page:code:color} negative numbers are printed in red (as
4054 % shown in section~\ref{sec:negative-red}), a positive mantissa with a
4055 % negative exponent would normally lead to a black mantissa with a
4056 % red exponent.
4057 % To avoid that the \cs{color} command is redefined to do nothing
4058 % here.
4059 % Do it in a group to restrain this to the exponent itself.
4060 % \changes{1.22}{2004/08/08}{Restrain empty \cs{color} command to
4061 % exponent}%
4062 % \begin{macrocode}
4063 \begingroup
4064 \def\color##1{}%
4065 % \end{macrocode}
4066 % Call the command that either print the exponent, reserves space as
4067 % it were printed or does nothing.
4068 % \begin{macrocode}
4069 \nprt@printexp{%
4070 % \end{macrocode}
4071 % If not mantissa is specified, print the short version, e.g.,
4072 % $10^{123}$ and thus leave out the product sign.
4073 % \begin{macrocode}
4074 \ifx\nprt@mantissa\@empty
4075 \else
4076 % \end{macrocode}
4077 % Print out the product sign, if there is a mantissa.
4078 % \begin{macrocode}
4079 \nprt@prod
4080 \fi
4081 % \end{macrocode}
4082 % Print ``10'' and the exponent.
4083 % This is different between text and math mode.
4084 % \begin{macrocode}
4085 \ifmmode 10^\else 10\expandafter\textsuperscript\fi{%
4086 % \end{macrocode}
4087 % Print the number before the decimal sign.
4088 % As the mantissa.
4089 % \begin{macrocode}
4090 \ifnprt@exponent@fixeddigits
4091 \ifmmode
4092 \mathchoice{%
4093 \nprt@calcblockwidth{exponent}{before}{\displaystyle}%
4094 \makebox[\the\nprt@blockwidth][r]{$\displaystyle
4095 \nprt@printsign{exponent}{\nprt@exponent@sign}%
4096 \nprt@printbefore{exponent}$}%
4097 }{%
4098 \nprt@calcblockwidth{exponent}{before}{\textstyle}%
4099 \makebox[\the\nprt@blockwidth][r]{$\textstyle
4100 \nprt@printsign{exponent}{\nprt@exponent@sign}%
4101 \nprt@printbefore{exponent}$}%
4102 }{%
4103 \nprt@calcblockwidth{exponent}{before}{\scriptstyle}%
4104 \makebox[\the\nprt@blockwidth][r]{$\scriptstyle
4105 \nprt@printsign{exponent}{\nprt@exponent@sign}%
4106 \nprt@printbefore{exponent}$}%
4107 }{%
4108 \nprt@calcblockwidth{exponent}{before}{\scriptscriptstyle}%
4109 \makebox[\the\nprt@blockwidth][r]{$\scriptscriptstyle
4110 \nprt@printsign{exponent}{\nprt@exponent@sign}%
4111 \nprt@printbefore{exponent}$}%
4112 }%
4113 \else
4114 \nprt@calcblockwidth{exponent}{before}{\@empty}%
4115 \makebox[\the\nprt@blockwidth][r]{%
4116 \nprt@printsign{exponent}{\nprt@exponent@sign}%
4117 \nprt@printbefore{exponent}%
4118 }%
4119 \fi
4120 \else
4121 \nprt@printsign{exponent}{\nprt@exponent@sign}%
4122 \nprt@printbefore{exponent}%
4123 \fi
4124 % \end{macrocode}
4125 % Produce a warning since this is uncommon in exponents.
4126 % \begin{macrocode}
4127 \ifnprt@exponent@decimalfound
4128 \PackageWarning{numprint}{Non-integer exponent}%
4129 \fi
4130 % \end{macrocode}
4131 % Print the part after the decimal sign.
4132 % \begin{macrocode}
4133 \ifnprt@exponent@fixeddigits
4134 \ifmmode
4135 \mathchoice{%
4136 \nprt@calcblockwidth{exponent}{after}{\displaystyle}%
4137 \makebox[\the\nprt@blockwidth][l]{$\displaystyle
4138 \ifnprt@exponent@decimalfound
4139 \nprt@decimal
4140 \fi
4141 \nprt@printafter{exponent}$}%
4142 }{%
4143 \nprt@calcblockwidth{exponent}{after}{\textstyle}%
4144 \makebox[\the\nprt@blockwidth][l]{$\textstyle
4145 \ifnprt@exponent@decimalfound
4146 \nprt@decimal
4147 \fi
4148 \nprt@printafter{exponent}$}%
4149 }{%
4150 \nprt@calcblockwidth{exponent}{after}{\scriptstyle}%
4151 \makebox[\the\nprt@blockwidth][l]{$\scriptstyle
4152 \ifnprt@exponent@decimalfound
4153 \nprt@decimal
4154 \fi
4155 \nprt@printafter{exponent}$}%
4156 }{%
4157 \nprt@calcblockwidth{exponent}{after}{\scriptscriptstyle}%
4158 \makebox[\the\nprt@blockwidth][l]{$\scriptscriptstyle
4159 \ifnprt@exponent@decimalfound
4160 \nprt@decimal
4161 \fi
4162 \nprt@printafter{exponent}$}%
4163 }%
4164 \else
4165 \nprt@calcblockwidth{exponent}{after}{\@empty}%
4166 \makebox[\the\nprt@blockwidth][l]{%
4167 \ifnprt@exponent@decimalfound
4168 \nprt@decimal
4169 \fi
4170 \nprt@printafter{exponent}%
4171 }%
4172 \fi
4173 \else
4174 \ifnprt@exponent@decimalfound
4175 \nprt@decimal
4176 \fi
4177 \nprt@printafter{exponent}%
4178 \fi
4179 }% 10^
4180 }% \nprt@printexp
4181 \endgroup
4182 \fi
4183 \fi
4184 % \end{macrocode}
4185 % If the unit is not empty, print it, too.
4186 % \begin{macrocode}
4187 \ifx\nprt@oarg\nprt@@empty
4188 \else
4189 % \end{macrocode}
4190 % All units expect the degree symbol are separated from the number.
4191 % Detect whether the degree symbol is used.
4192 %
4193 % \changes{1.22}{2004/08/08}{Produce a warning rather than an error
4194 % when using \cs{textdegree} as unit}%
4195 % The \cs{textdegree} command is not useable in math mode.
4196 % Redeclare it to generate a warning and to use \cs{tcdegree}
4197 % instead.
4198 % \begin{macrocode}
4199 \def\textdegree{%
4200 \PackageWarning{numprint}{The unit is typeset in mathmode. Use
4201 \string\tcdegree\space of\MessageBreak
4202 the mathcomp package or \string\degree\space of the
4203 gensymb\MessageBreak
4204 package}%
4205 % \end{macrocode}
4206 % Call \cs{tcdegree} via \cs{csname} in order to avoid a second error
4207 % message if \cs{tcdegree} is not present (because of not loading
4208 % |mathcomp.sty|.
4209 % \begin{macrocode}
4210 \csname tcdegree\endcsname
4211 }%
4212 % \end{macrocode}
4213 % \changes{1.22}{2004/08/08}{Enable to use \cs{textcelsius},
4214 % \cs{textohm}, \cs{textmu}, and \cs{textperthousand} in the unit}%
4215 % \changes{1.32}{2004/09/13}{Produce an error rather than a warning
4216 % when using \texttt{textcomp} symbols in the unit if
4217 % \texttt{mathcomp} or \texttt{gensymb} is not loaded}%
4218 % Handle \cs{textcelsius}, \cs{textohm}, \cs{textmu}, and
4219 % \cs{textperthousand} in the same way as \cs{textdegree}.
4220 % \begin{macrocode}
4221 \def\nprt@PackageError##1##2{\PackageWarning{numprint}{##1}}%
4222 \def\textcelsius{%
4223 \begingroup
4224 \@ifundefined{tccelsius}{\@ifundefined{celsius}{%
4225 \def\nprt@PackageError####1####2{%
4226 \PackageError{numprint}{####1}{####2}}%
4227 }{\celsius}}{\tccelsius}%
4228 \nprt@PackageError{The unit is typeset in
4229 mathmode. Use \string\tccelsius\space of\MessageBreak
4230 the mathcomp package or \string\celsius\space of the
4231 gensymb\MessageBreak
4232 package}{If you load the mathcomp package
4233 \string\textcelsius\space is substituted by
4234 \string\tccelsius. If you load the gensymb package
4235 \string\textcelsius\space is substituted by \string\celsius.}%
4236 \endgroup
4237 }%
4238 \def\textohm{%
4239 \begingroup
4240 \@ifundefined{tcohm}{\@ifundefined{ohm}{%
4241 \def\nprt@PackageError####1####2{%
4242 \PackageError{numprint}{####1}{####2}}%
4243 }{\ohm}}{\tcohm}%
4244 \nprt@PackageError{The unit is typeset in
4245 mathmode. Use \string\tcohm\space of\MessageBreak
4246 the mathcomp package or \string\ohm\space of the
4247 gensymb\MessageBreak
4248 package}{If you load the mathcomp package
4249 \string\textohm\space is substituted by
4250 \string\tcohm. If you load the gensymb package
4251 \string\textohm\space is substituted by \string\ohm.}%
4252 \endgroup
4253 }%
4254 \def\textmu{%
4255 \begingroup
4256 \@ifundefined{tcmu}{%
4257 \def\nprt@PackageError####1####2{%
4258 \PackageError{numprint}{####1}{####2}}%
4259 }{\tcmu}%
4260 \nprt@PackageError{The unit is typeset in
4261 mathmode. Use \string\tcmu\space of\MessageBreak
4262 the mathcomp package}{If you load the mathcomp package
4263 \string\textmu\space is substituted by \string\tcmu.}%
4264 \endgroup
4265 }%
4266 \def\textperthousand{%
4267 \begingroup
4268 \@ifundefined{tcperthousand}{\@ifundefined{perthousand}{%
4269 \def\nprt@PackageError####1####2{%
4270 \PackageError{numprint}{####1}{####2}}%
4271 }{\perthousand}}{\tcperthousand}%
4272 \nprt@PackageError{The unit is typeset in
4273 mathmode. Use \string\tcperthousand\MessageBreak
4274 of the mathcomp package or \string\perthousand\space of
4275 the\MessageBreak
4276 gensymb package}{If you load the mathcomp package
4277 \string\textperthousand\space is substituted by
4278 \string\tcperthousand. If you load the gensymb package
4279 \string\textperthousand\space is substituted by
4280 \string\perthousand.}%
4281 \endgroup
4282 }%
4283 % \end{macrocode}
4284 % If the unit is \cs{tcdegree} from the \texttt{mathcomp} package, the
4285 % unit is a degree sign.
4286 % Then print the separator \cs{nprt@degreesep} instead of
4287 % \cs{nprt@unitsep}.
4288 % \begin{macrocode}
4289 \def\nprt@tmpunit{\tcdegree}%
4290 \ifx\nprt@oarg\nprt@tmpunit
4291 \ensuremath{\nprt@degreesep}%
4292 \else
4293 % \end{macrocode}
4294 % If the unit is \cs{degree} from the \texttt{gensymb} package, the
4295 % unit is a degree sign.
4296 % Then print the separator \cs{nprt@degreesep} instead of
4297 % \cs{nprt@unitsep}.
4298 % \begin{macrocode}
4299 \def\nprt@tmpunit{\degree}%
4300 \ifx\nprt@oarg\nprt@tmpunit
4301 \ensuremath{\nprt@degreesep}%
4302 \else
4303 % \end{macrocode}
4304 % If the unit is \cs{textdegree} from the \texttt{textcomp} package, the
4305 % unit is a degree sign.
4306 % Then print the separator \cs{nprt@degreesep} instead of
4307 % \cs{nprt@unitsep}.
4308 % \begin{macrocode}
4309 \def\nprt@tmpunit{\textdegree}%
4310 \ifx\nprt@oarg\nprt@tmpunit
4311 \ensuremath{\nprt@degreesep}%
4312 \else
4313 % \end{macrocode}
4314 % If the unit is \cs{tccelsius} from the \texttt{mathcomp} package, the
4315 % unit is degree centigrade.
4316 % Then print the separator \cs{nprt@celsiussep} instead of
4317 % \cs{nprt@unitsep}.
4318 % \begin{macrocode}
4319 \def\nprt@tmpunit{\tccelsius}%
4320 \ifx\nprt@oarg\nprt@tmpunit
4321 \ensuremath{\nprt@celsiussep}%
4322 \else
4323 % \end{macrocode}
4324 % If the unit is \cs{celsius} from the \texttt{gensymb} package, the
4325 % unit is degree centigrade.
4326 % Then print the separator \cs{nprt@celsiussep} instead of
4327 % \cs{nprt@unitsep}.
4328 % \begin{macrocode}
4329 \def\nprt@tmpunit{\celsius}%
4330 \ifx\nprt@oarg\nprt@tmpunit
4331 \ensuremath{\nprt@celsiussep}%
4332 \else
4333 % \end{macrocode}
4334 % If the unit is \cs{textcelsius} from the \texttt{textcomp} package, the
4335 % unit is degree centigrade.
4336 % Then print the separator \cs{nprt@celsiussep} instead of
4337 % \cs{nprt@unitsep}.
4338 % \begin{macrocode}
4339 \def\nprt@tmpunit{\textcelsius}%
4340 \ifx\nprt@oarg\nprt@tmpunit
4341 \ensuremath{\nprt@celsiussep}%
4342 \else
4343 % \end{macrocode}
4344 % If the unit is \cs{\%}, the unit is a percent sign.
4345 % Then print the separator \cs{nprt@percentsep} instead of
4346 % \cs{nprt@unitsep}.
4347 % \begin{macrocode}
4348 \def\nprt@tmpunit{\%}%
4349 \ifx\nprt@oarg\nprt@tmpunit
4350 \ensuremath{\nprt@percentsep}%
4351 \else
4352 % \end{macrocode}
4353 % If the unit is \cs{tcperthousand} from the \texttt{mathcomp} package, the
4354 % unit is a permil sign.
4355 % Then print the separator \cs{nprt@percentsep} instead of
4356 % \cs{nprt@unitsep}.
4357 % \begin{macrocode}
4358 \def\nprt@tmpunit{\tcperthousand}%
4359 \ifx\nprt@oarg\nprt@tmpunit
4360 \ensuremath{\nprt@percentsep}%
4361 \else
4362 % \end{macrocode}
4363 % If the unit is \cs{perthousand} from the \texttt{gensymb} package, the
4364 % unit is a permil sign.
4365 % Then print the separator \cs{nprt@percentsep} instead of
4366 % \cs{nprt@unitsep}.
4367 % \begin{macrocode}
4368 \def\nprt@tmpunit{\perthousand}%
4369 \ifx\nprt@oarg\nprt@tmpunit
4370 \ensuremath{\nprt@percentsep}%
4371 \else
4372 % \end{macrocode}
4373 % If the unit is \cs{textperthousand} from the \texttt{textcomp} package, the
4374 % unit is a permil sign.
4375 % Then print the separator \cs{nprt@percentsep} instead of
4376 % \cs{nprt@unitsep}.
4377 % \begin{macrocode}
4378 \def\nprt@tmpunit{\textperthousand}%
4379 \ifx\nprt@oarg\nprt@tmpunit
4380 \ensuremath{\nprt@percentsep}%
4381 \else
4382 % \end{macrocode}
4383 % Else, print \cs{nprt@unitsep}.
4384 % \begin{macrocode}
4385 \ensuremath{\nprt@unitsep}%
4386 \fi
4387 \fi
4388 \fi
4389 \fi
4390 \fi
4391 \fi
4392 \fi
4393 \fi
4394 \fi
4395 \fi
4396 % \end{macrocode}
4397 % Finally, print the unit.
4398 % \begin{macrocode}
4399 \npunitcommand{\nprt@oarg}%
4400 \fi
4401 \endgroup
4402 }
4403 % \end{macrocode}
4404 % \end{macro}
4405 %
4406 %
4407 % \subsection{Print lengths and counters}%
4408 % \label{sec:code:lenprint}%
4409 %
4410 % \begin{macro}{\cntprint}
4411 % The macro for printing counters.
4412 % The mandatory argument takes a \LaTeX\ counter.
4413 % The optional argument may contain a unit which is printed, too.
4414 % \begin{macrocode}
4415 \newcounter{nprt@cntprint}
4416 \DeclareRobustCommand*\cntprint[2][\@empty]{%
4417 \@ifundefined{c@#2}{\@nocounterr{#2}}{%
4418 \numprint[#1]{\arabic{#2}}%
4419 }%
4420 }
4421 % \end{macrocode}
4422 % \end{macro}
4423 % \begin{macro}{\lenprint}
4424 % The macro for printing lengths.
4425 % The mandatory argument takes a \TeX\ dimension or a counter.
4426 % The optional argument may contain a unit that is used to convert the
4427 % unit from |pt| to the given value and which then is printed, too.
4428 % \begin{macrocode}
4429 \DeclareRobustCommand*\lenprint[2][\@empty]{%
4430 % \end{macrocode}
4431 % Do everything in a group to avoid macros to resist outside.
4432 % \begin{macrocode}
4433 \begingroup
4434 % \end{macrocode}
4435 % Save the optional argument in \cs{nprt@oarg} and expand it.
4436 % \begin{macrocode}
4437 \edef\nprt@oarg{#1}%
4438 % \end{macrocode}
4439 % If no optional argument has been given, change it to |pt|.
4440 % This cannot be done as default argument in the
4441 % \cs{DeclareRobustCommand*} definition since printing of counters
4442 % does not have |pt| as default.
4443 % \begin{macrocode}
4444 \edef\nprt@tmp{\@empty}%
4445 \ifx\nprt@oarg\nprt@tmp
4446 \def\nprt@oarg{pt}%
4447 \fi
4448 % \end{macrocode}
4449 % If the chosen unit is not defined produce an error message and fall
4450 % back to |pt|.
4451 % \begin{macrocode}
4452 \@ifundefined{nprt@factor@\nprt@oarg}{%
4453 \PackageError{numprint}{Invalid unit `#1'}{%
4454 The requested unit is not defined using \string\npdefunit.^^J%
4455 Using `pt' instead.}%
4456 \def\nprt@oarg{pt}%
4457 }{}%
4458 % \end{macrocode}
4459 % For later printing, a length is used that is fixed to |pt| as
4460 % length.
4461 % If another unit has been chosen a fake length has to be calculated
4462 % that is as many |pt| long as the original length is in the given
4463 % unit.
4464 % Thus, multiply the mandatory argument by the specific factor for the
4465 % given unit.
4466 % \begin{macrocode}
4467 \setlength{\@tempdima}{#2}%
4468 \setlength{\@tempdima}{\csname nprt@factor@\nprt@oarg\endcsname\@tempdima}%
4469 % \end{macrocode}
4470 % If the unit name for the given unit is not defined but the factor
4471 % is an internal error has occured.
4472 % Produce an error message.
4473 % \begin{macrocode}
4474 \@ifundefined{nprt@unit@\nprt@oarg}{%
4475 \PackageError{numprint}{Unknown unit name `\nprt@oarg'}{%
4476 Send a bug report to [email protected] with a short
4477 example showing this bug.}%
4478 }{%
4479 % \end{macrocode}
4480 % Store the unit name in \cs{nprt@oarg}.
4481 % \begin{macrocode}
4482 \edef\nprt@oarg{\csname nprt@unit@\nprt@oarg\endcsname}%
4483 }%
4484 % \end{macrocode}
4485 % Finally, call \cs{numprint}.
4486 % The two \cs{expandafter} are necessary since \cs{numprint} also uses
4487 % \cs{nprt@oarg} and produces an infinite loop otherwise.
4488 % \begin{macrocode}
4489 \expandafter\numprint\expandafter[\nprt@oarg]{\strip@pt\@tempdima}%
4490 \endgroup
4491 }
4492 % \end{macrocode}
4493 % \end{macro}
4494 % \begin{macro}{\npdefunit}
4495 % Define a new unit for usage with \cs{lenprint}.
4496 % First argument: name in the sourcecode.
4497 % Second argument: printed unit.
4498 % Third argument: factor from |pt| to the new unit or |*| to preserve
4499 % old factor.
4500 % \begin{macrocode}
4501 \newcommand*\npdefunit[3]{%
4502 % \end{macrocode}
4503 % If the third argument is not |*| define the factor for this unit in
4504 % \cs{nprt@factor@\meta{\#1}}.
4505 % \begin{macrocode}
4506 \if#3*
4507 \else
4508 \expandafter\def\csname nprt@factor@#1\endcsname{#3}%
4509 \fi
4510 % \end{macrocode}
4511 % Define the unit name for this unit in \cs{nprt@unit@\meta{\#1}}.
4512 % \begin{macrocode}
4513 \expandafter\def\csname nprt@unit@#1\endcsname{#2}%
4514 }
4515 % \end{macrocode}
4516 % \end{macro}
4517 % Declare the standard units.
4518 % \cs{!} is used to delete the unit separator again.
4519 % This is a hack and does not work in all cases correctly.
4520 % \begin{macrocode}
4521 \npdefunit{pt}{pt}{1.00000000000}
4522 \npdefunit{bp}{bp}{0.99626400996}
4523 \npdefunit{in}{in}{0.01383700013}
4524 \npdefunit{ft}{ft}{0.00115308334}
4525 \npdefunit{mm}{mm}{0.35145980351}
4526 \npdefunit{cm}{cm}{0.03514598035}
4527 \npdefunit{m}{m}{0.0003514598035}
4528 \npdefunit{km}{km}{0.0000003514598035}
4529 % \end{macrocode}
4530 %
4531 %
4532 % \subsection{Internationalization}
4533 %
4534 % \begin{macro}{\nprt@ifundefined}
4535 % The normal \cs{@ifundefined} command defines the tested macro as
4536 % side effect.
4537 % This command is better.
4538 % Sometimes it will hopefully be unnecessary and supported by the
4539 % standard (with a different name, of course).
4540 % \begin{macrocode}
4541 \newcommand*\nprt@ifundefined[1]{%
4542 \begingroup\expandafter\expandafter\expandafter\endgroup
4543 \expandafter\ifx\csname #1\endcsname\relax
4544 \expandafter\@firstoftwo
4545 \else
4546 \expandafter\@secondoftwo
4547 \fi
4548 }
4549 % \end{macrocode}
4550 % \end{macro}
4551 % \begin{macro}{\nprt@addto}
4552 % Adds the code of the second argument to the macro defined in the
4553 % first argument.
4554 % This argument has to be specified without the preceeding backslash.
4555 % The code is added only if the command is defined, already.
4556 % \begin{macrocode}
4557 \newcommand\nprt@addto[2]{%
4558 \expandafter\nprt@ifundefined{#1}{}{%
4559 \expandafter\addto\expandafter{\csname #1\endcsname}{#2}%
4560 }%
4561 }
4562 % \end{macrocode}
4563 % \end{macro}
4564 % \begin{macro}{\npaddtolanguage}
4565 % Define \cs{npaddtolanguage\marg{Language}\marg{Language
4566 % definitions}}.
4567 % Adds the \meta{Language definitions} specified in argument two to
4568 % the \meta{Language} of argument one.
4569 % The language definitions have to be provided in a command with the
4570 % name \cs{npstyle}\meta{Language definitions}.
4571 % The switching-on command is added to \cs{extras\meta{Language}}
4572 % while the switching-off command \cs{npstyledefault} is added to
4573 % \cs{noextras\meta{Language}}.
4574 %
4575 % For example, \cs{npaddtolanguage\{UKenglish\}\{english\}} adds the
4576 % command \cs{npstyleenglish} to \cs{extrasUKenglish} and
4577 % \cs{npstyledefault} to \cs{noextrasUKenglish}.
4578 %
4579 % The \cs{npstyle\meta{Language definitions}} commands are described
4580 % below.
4581 % \begin{macrocode}
4582 \newcommand\npaddtolanguage[2]{%
4583 \nprt@addto{extras#1}{\csname npstyle#2\endcsname}%
4584 \nprt@addto{noextras#1}{\npstyledefault}%
4585 }
4586 % \end{macrocode}
4587 % \end{macro}
4588 % \begin{macro}{\npstyledefault}
4589 % Set the default values for the separators.
4590 % They are set to the German language because of compatibility with
4591 % older versions.
4592 % \begin{macrocode}
4593 \newcommand*\npstyledefault{%
4594 \npthousandsep{\,}%
4595 \npdecimalsign{,}%
4596 \npproductsign{\cdot}%
4597 \npunitseparator{\,}%
4598 \npdegreeseparator{}%
4599 \npcelsiusseparator{\nprt@unitsep}%
4600 \nppercentseparator{\nprt@unitsep}%
4601 }
4602 % \end{macrocode}
4603 % \end{macro}
4604 % Set the default settings (that are actually the same as German).
4605 % \begin{macrocode}
4606 \npstyledefault
4607 % \end{macrocode}
4608 % \begin{macro}{\npstylegerman}
4609 % Sets the parameters to German habit.
4610 % \begin{macrocode}
4611 \newcommand*\npstylegerman{%
4612 \npthousandsep{\,}%
4613 \npdecimalsign{,}%
4614 \npproductsign{\cdot}%
4615 \npunitseparator{\,}%
4616 \npdegreeseparator{}%
4617 \npcelsiusseparator{\nprt@unitsep}%
4618 \nppercentseparator{\nprt@unitsep}%
4619 }
4620 % \end{macrocode}
4621 % \end{macro}
4622 % \begin{macro}{\npstyleenglish}
4623 % Sets the parameters to English habit.
4624 % \begin{macrocode}
4625 \newcommand*\npstyleenglish{%
4626 \npthousandsep{,}%
4627 \npdecimalsign{.}%
4628 \npproductsign{\times}%
4629 \npunitseparator{\,}%
4630 \npdegreeseparator{}%
4631 \npcelsiusseparator{\nprt@unitsep}%
4632 \nppercentseparator{\nprt@unitsep}%
4633 }
4634 % \end{macrocode}
4635 % \end{macro}
4636 % \begin{macro}{\npstyleportuguese}
4637 % \changes{1.37}{2007/01/08}{Change thousand separator for Portuguese
4638 % from ``\cs{,}'' to ``\texttt{.}''}%
4639 % Sets the parameters to Portuguese habit.
4640 % \begin{macrocode}
4641 \newcommand*\npstyleportuguese{%
4642 \npthousandsep{.}%
4643 \npdecimalsign{,}%
4644 \npproductsign{\cdot}%
4645 \npunitseparator{\,}%
4646 \npdegreeseparator{}%
4647 \npcelsiusseparator{\nprt@unitsep}%
4648 \nppercentseparator{\nprt@unitsep}%
4649 }
4650 % \end{macrocode}
4651 % \end{macro}
4652 % \begin{macro}{\npstyledutch}
4653 % Sets the parameters to Dutch habit.
4654 % \begin{macrocode}
4655 \newcommand*\npstyledutch{%
4656 \npthousandsep{\,}%
4657 \npdecimalsign{,}%
4658 \npproductsign{\cdot}%
4659 \npunitseparator{\,}%
4660 \npdegreeseparator{}%
4661 \npcelsiusseparator{\nprt@unitsep}%
4662 \nppercentseparator{}%
4663 }
4664 % \end{macrocode}
4665 % \end{macro}
4666 % \begin{macro}{\npstylefrench}
4667 % Sets the parameters to French habit.
4668 % \begin{macrocode}
4669 \newcommand*\npstylefrench{%
4670 \npthousandsep{~}%
4671 \npdecimalsign{,}%
4672 \npproductsign{\cdot}%
4673 \npunitseparator{\,}%
4674 \npdegreeseparator{}%
4675 \npcelsiusseparator{\nprt@unitsep}%
4676 \nppercentseparator{\nprt@unitsep}%
4677 }
4678 % \end{macrocode}
4679 % \end{macro}
4680 % Do the following actions at \cs{begin\{document\}} to ensure that it
4681 % is done after loading \texttt{babel.sty} if it is loaded at all.
4682 % \begin{macrocode}
4683 \AtBeginDocument{%
4684 % \end{macrocode}
4685 % By default, automatic language support is switched off for
4686 % compatiblity reasons.
4687 % Proceed only if it is switched on.
4688 % \begin{macrocode}
4689 \ifnprt@autolanguage
4690 % \end{macrocode}
4691 % Automatic language support only works with babel.
4692 % \begin{macrocode}
4693 \@ifpackageloaded{babel}{%
4694 % \end{macrocode}
4695 % Adds the language settings to the known languages if they are
4696 % provided by babel.
4697 % The current version knows all German, English, Portuguese, Dutch,
4698 % and French dialects.
4699 % \begin{macrocode}
4700 \npaddtolanguage{UKenglish}{english}%
4701 \npaddtolanguage{USenglish}{english}%
4702 \npaddtolanguage{afrikaans}{dutch}%
4703 \npaddtolanguage{american}{english}%
4704 \npaddtolanguage{austrian}{german}%
4705 \npaddtolanguage{british}{english}%
4706 \npaddtolanguage{canadian}{english}%
4707 \npaddtolanguage{dutch}{dutch}%
4708 \npaddtolanguage{english}{english}%
4709 \npaddtolanguage{german}{german}%
4710 \npaddtolanguage{naustrian}{german}%
4711 \npaddtolanguage{ngerman}{german}%
4712 \npaddtolanguage{brazil}{portuguese}%
4713 \npaddtolanguage{brazilian}{portuguese}%
4714 \npaddtolanguage{portuges}{portuguese}%
4715 \npaddtolanguage{portuguese}{portuguese}%
4716 \npaddtolanguage{francais}{french}%
4717 \npaddtolanguage{canadien}{french}%
4718 \npaddtolanguage{acadian}{french}%
4719 \npaddtolanguage{french}{french}%
4720 \npaddtolanguage{frenchb}{french}%
4721 % \end{macrocode}
4722 % Set the active language again to activate the extras section.
4723 % \begin{macrocode}
4724 \expandafter\selectlanguage\expandafter{\languagename}%
4725 }{%
4726 % \end{macrocode}
4727 % If |babel| is not loaded but automatic language support is
4728 % activated, switch to English as default:
4729 % \begin{macrocode}
4730 \npstyleenglish
4731 }%
4732 \fi
4733 }
4734 % \end{macrocode}
4735 % Load configuration file if present.
4736 % \begin{macrocode}
4737 \InputIfFileExists{numprint.cfg}{%
4738 \message{Configuration file `numprint.cfg' loaded.}%
4739 }{%
4740 \message{No configuration file `numprint.cfg' found.}%
4741 }
4742 % \end{macrocode}
4743 % \begin{macro}{\nprt@renameerror}
4744 % A command for producing an error message for redefined macros.
4745 % \begin{macrocode}
4746 \newcommand*\nprt@renameerror[1]{%
4747 \expandafter\def\csname #1\endcsname{%
4748 \PackageError{numprint}{This command has been renamed
4749 to\MessageBreak
4750 \string\np #1}{In order to avoid problems with other
4751 packages and for consistency, this\MessageBreak
4752 command has been renamed in this version.}%
4753 }%
4754 }
4755 % \end{macrocode}
4756 % \end{macro}
4757 % \begin{macro}{\fourdigitsep}
4758 % \changes{1.00}{2003/10/07}{Renamed to \cs{npfourdigitsep}}%
4759 % \begin{macro}{\fourdigitnosep}
4760 % \changes{1.00}{2003/10/07}{Renamed to \cs{npfourdigitnosep}}%
4761 % \begin{macro}{\addmissingzero}
4762 % \changes{1.00}{2003/10/07}{Renamed to \cs{npaddmissingzero}}%
4763 % \begin{macro}{\noaddmissingzero}
4764 % \changes{1.00}{2003/10/07}{Renamed to \cs{npnoaddmissingzero}}%
4765 % \begin{macro}{\digits}
4766 % \changes{1.00}{2003/10/07}{Renamed to \cs{npdigits}}%
4767 % \begin{macro}{\nodigits}
4768 % \changes{1.00}{2003/10/07}{Renamed to \cs{npnodigits}}%
4769 % \begin{macro}{\exponentdigits}
4770 % \changes{1.00}{2003/10/07}{Renamed to \cs{npexponentdigits}}%
4771 % \begin{macro}{\noexponentdigits}
4772 % \changes{1.00}{2003/10/07}{Renamed to \cs{npnoexponentdigits}}%
4773 % Define replacements for the old commands that produce error
4774 % messages.
4775 % \begin{macrocode}
4776 \nprt@renameerror{fourdigitsep}
4777 \nprt@renameerror{fourdigitnosep}
4778 \nprt@renameerror{addmissingzero}
4779 \nprt@renameerror{noaddmissingzero}
4780 \nprt@renameerror{digits}
4781 \nprt@renameerror{nodigits}
4782 \nprt@renameerror{exponentdigits}
4783 \nprt@renameerror{noexponentdigits}
4784 % \end{macrocode}
4785 % \end{macro}
4786 % \end{macro}
4787 % \end{macro}
4788 % \end{macro}
4789 % \end{macro}
4790 % \end{macro}
4791 % \end{macro}
4792 % \end{macro}
4793 %
4794 % \iffalse
4795 %</package>
4796 % \fi
4797 % \Finale
4798