| 1 |
% \iffalse meta comment |
| 2 |
% File: numprint032.dtx Copyright (C) 2000--2004 Harald Harders |
| 3 |
% \fi |
| 4 |
% |
| 5 |
% \iffalse |
| 6 |
% |
| 7 |
%<*package> |
| 8 |
\def\packagename{numprint} |
| 9 |
\def\nprtfileversion{0.32} |
| 10 |
\def\nprtfiledate{2003/09/18} |
| 11 |
\def\nprtdocdate{2003/09/18} |
| 12 |
%</package> |
| 13 |
%<*driver> |
| 14 |
\documentclass{ltxdoc} |
| 15 |
\IfFileExists{numprint.sty}{\usepackage{numprint} |
| 16 |
\let\numprintSTYfound\active}{\GenericWarning{numprint.dtx}{Package |
| 17 |
file numprint.sty not found (Documentation will be messed up!^^J^^A |
| 18 |
Generate numprint.sty by (La)TeXing numprint.ins, process |
| 19 |
numprint.dtx again)^^J}\stop} |
| 20 |
\usepackage{longtable} |
| 21 |
\title{The \texttt{numprint} package\thanks{This file has version |
| 22 |
\nprtfileversion\ last revised \nprtfiledate, documentation dated |
| 23 |
\nprtdocdate.}} |
| 24 |
\author{Harald Harders\\\texttt{[email protected]}} |
| 25 |
\date{File Date \nprtfiledate, Printed \today} |
| 26 |
\npdecimalsign{.}% |
| 27 |
\newlength{\tempdima}% |
| 28 |
\makeatletter |
| 29 |
\renewenvironment{table}[1][]{% |
| 30 |
\@float{table}[#1]% |
| 31 |
\centering% |
| 32 |
\setlength{\tempdima}{\abovecaptionskip}% |
| 33 |
\setlength{\abovecaptionskip}{\belowcaptionskip}% |
| 34 |
\setlength{\belowcaptionskip}{\tempdima}% |
| 35 |
}{% |
| 36 |
\end@float |
| 37 |
} |
| 38 |
\makeatother |
| 39 |
\EnableCrossrefs |
| 40 |
\CodelineIndex |
| 41 |
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter} |
| 42 |
\DoNotIndex{\setcounter,\space,\if,\else,\fi,\empty,\@empty,\ifx,\fi} |
| 43 |
\DoNotIndex{\ifnum,\fi,\expandafter} |
| 44 |
\CodelineNumbered |
| 45 |
\RecordChanges |
| 46 |
%\CheckSum{1016} |
| 47 |
\begin{document} |
| 48 |
\DocInput{numprint.dtx} |
| 49 |
\end{document} |
| 50 |
%</driver> |
| 51 |
% \fi |
| 52 |
% |
| 53 |
% \changes{0.01}{2000/08/30}{Changed to dtx format} |
| 54 |
% \changes{0.08}{2001/01/08}{Preceed ``np'' to some commands due to |
| 55 |
% incompatibility with babel french} |
| 56 |
% |
| 57 |
% \maketitle |
| 58 |
% \begin{abstract} |
| 59 |
% \noindent This package prints numbers with a separator every three |
| 60 |
% digits and it convert numbers given as |12345.6e789| to |
| 61 |
% $12\,345{,}6\cdot 10^{789}$. |
| 62 |
% The decimal sign, the thousand separator, as well as the product |
| 63 |
% sign can be changed by the user, e.g. to reach |
| 64 |
% $12{,}345.6\times 10^{789}$. |
| 65 |
% If an optional argument is given it is printed upright as unit. |
| 66 |
% \changes{0.21}{2003/02/25}{Abstract changed} |
| 67 |
% \end{abstract} |
| 68 |
% |
| 69 |
% \tableofcontents |
| 70 |
% |
| 71 |
% \section*{Copyright} |
| 72 |
% Copyright 2000--2004 Harald Harders. |
| 73 |
% |
| 74 |
% This program can be redistributed and/or modified under the terms |
| 75 |
% of the LaTeX Project Public License Distributed from CTAN |
| 76 |
% archives in directory macros/latex/base/lppl.txt; either |
| 77 |
% version 1 of the License, or any later version. |
| 78 |
% |
| 79 |
% \section{The user interface} |
| 80 |
% |
| 81 |
% To use this package place |
| 82 |
% \begin{verbatim} |
| 83 |
%\usepackage{numprint} |
| 84 |
% \end{verbatim} |
| 85 |
% in the preamble of your document. No options are necessary. |
| 86 |
% |
| 87 |
% \subsection{Print numbers in text and math mode} |
| 88 |
% |
| 89 |
% \DescribeMacro{\numprint}% |
| 90 |
% The package provides the command \verb|\numprint[#1]{#2}| that prints |
| 91 |
% the number given in the required argument. The number is printed in the |
| 92 |
% active mode (math or text) so that an eventual chosen difference |
| 93 |
% between mathematical and text numbers stays visible (e.g. by using |
| 94 |
% the eco-package. |
| 95 |
% |
| 96 |
% Numbers may contain of these characters: |
| 97 |
% ``|+-\pm0123456789.,eE|''. Either a ``,'' or a ''.'' can be used as |
| 98 |
% decimal sign. No thousand separators are allowed in the |
| 99 |
% argument. ``E'' or ``e'' is converted to $\cdot 10^{x}$. |
| 100 |
% |\pm| produces a $\pm$. |
| 101 |
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}% |
| 102 |
% From version 0.30 on, \cs{numprint} is stricter with the argument. |
| 103 |
% It tests wheather the argument contains of supported characters |
| 104 |
% only. |
| 105 |
% |
| 106 |
% For example typing |
| 107 |
% \begin{verbatim} |
| 108 |
%\numprint{-123456}; \numprint[N/mm^2]{-123456}; \numprint{3,1415927e-3.1} |
| 109 |
% \end{verbatim} |
| 110 |
% leads to ``\numprint{-123456}; \numprint[N/mm^2]{-123456}; |
| 111 |
% \numprint{3,1415927e-3.1}''. Notice |
| 112 |
% that ``.'' and ``,'' can be mixed within one number. |
| 113 |
% |
| 114 |
% If no number is given before the exponential character ``e'' |
| 115 |
% resp. ``E'' a pure exponential format is generated. |
| 116 |
% For example typing |
| 117 |
% \begin{verbatim} |
| 118 |
%\numprint{e4.3242} |
| 119 |
% \end{verbatim} |
| 120 |
% leads to ``\numprint{e4.3242}''. |
| 121 |
% \changes{0.04}{2001/03/06}{Added support for pure $10^x$ format}% |
| 122 |
% |
| 123 |
% \changes{0.02}{2000/08/30}{Added optional argument for units}% |
| 124 |
% If the optional argument is given it is printed as a unit in math |
| 125 |
% mode with an upright font (\verb|\mathrm|). The space between the |
| 126 |
% number and the unit is \verb|\,| by default. It can be changed using |
| 127 |
% the command |\npunitseparator|. |
| 128 |
% |
| 129 |
% \DescribeMacro{\npthousandsep}% |
| 130 |
% \DescribeMacro{\npthousandthpartsep}% |
| 131 |
% \DescribeMacro{\npdecimalsign}% |
| 132 |
% \DescribeMacro{\npproductsign}% |
| 133 |
% By using the three commands \verb|\npthousandsep{#1}|, |
| 134 |
% \verb|\npdecimalsign{#1}|, and |
| 135 |
% \verb|\npproductsign{#1}|\footnote{These command did not have the |
| 136 |
% ``np'' in older versions. This had to be changed in order to avoid |
| 137 |
% an incompatibiliby with the french language of babel.} several |
| 138 |
% separators can be changed. E.g. |
| 139 |
% \begin{verbatim} |
| 140 |
%\npdecimalsign{\ensuremath{\cdot}}\npthousandsep{,}\npproductsign{\times}% |
| 141 |
%\numprint{-123456}; \numprint{3,1415927e-3.1} |
| 142 |
% \end{verbatim} |
| 143 |
% leads to ``{\npdecimalsign{\ensuremath{\cdot}}% |
| 144 |
% \npthousandsep{,}\npproductsign{\times}% |
| 145 |
% \numprint{-123456}; \numprint{3,1415927e-3.1}}''. |
| 146 |
% |
| 147 |
% \DescribeMacro{\global}% |
| 148 |
% These commands change the behaviour of the \verb|\numprint| command |
| 149 |
% only locally (inside the current group). By preceding \verb|\global| |
| 150 |
% the change can be made global inside a group. For example: |
| 151 |
% \begin{verbatim} |
| 152 |
%Local: |
| 153 |
%\numprint{123e4}, |
| 154 |
%{\npproductsign{\times}\numprint{123e4}}, |
| 155 |
%\numprint{123e4}. |
| 156 |
%Global: |
| 157 |
%\numprint{123e4}, |
| 158 |
%{\global\npproductsign{\times}\numprint{123e4}}, |
| 159 |
%\numprint{123e4} |
| 160 |
% \end{verbatim} |
| 161 |
% leads to the following: |
| 162 |
% |
| 163 |
% \noindent Local: |
| 164 |
% \numprint{123e4}, |
| 165 |
% {\npproductsign{\times}\numprint{123e4}}, |
| 166 |
% \numprint{123e4}. |
| 167 |
% Global: |
| 168 |
% \numprint{123e4}, |
| 169 |
% {\global\npproductsign{\times}\numprint{123e4}}, |
| 170 |
% \numprint{123e4} |
| 171 |
% \npproductsign{\cdot} |
| 172 |
% |
| 173 |
% The current version has the following defaults: |
| 174 |
% \begin{verbatim} |
| 175 |
%\npthousandsep{\,} |
| 176 |
%\npthousandthpartsep{\,} |
| 177 |
%\npdecimalsign{,} |
| 178 |
%\npproductsign{{}\cdot{}} |
| 179 |
%\npunitseparator{\,} |
| 180 |
% \end{verbatim} |
| 181 |
% These will surely change in a new version when I add automatic |
| 182 |
% international support. Then the defaults will by language dependent. |
| 183 |
% |
| 184 |
% \changes{0.31}{2003/09/16}{Describe automatic language-dependent |
| 185 |
% switch of decimal sign}% |
| 186 |
% If you are using the |babel| package you may reach an automatic |
| 187 |
% change of the parameters by using the \cs{addto} command of |babel|, |
| 188 |
% e.g.: |
| 189 |
% \begin{verbatim} |
| 190 |
%\addto\extrasenglish{% |
| 191 |
% \npthousandsep{,}% |
| 192 |
% \npthousandthpartsep{,}% |
| 193 |
% \npdecimalsign{.}% |
| 194 |
% \npproductsign{{}\times{}}% |
| 195 |
%} |
| 196 |
%\addto\extrasngerman{% |
| 197 |
% \npthousandsep{\,}% |
| 198 |
% \npthousandthpartsep{\,}% |
| 199 |
% \npdecimalsign{,}% |
| 200 |
% \npproductsign{{}\cdot{}}% |
| 201 |
%} |
| 202 |
% \end{verbatim} |
| 203 |
% |
| 204 |
% \subsection{Change the behaviour} |
| 205 |
% \subsubsection{Eliminate separators for four-digit numbers} |
| 206 |
% |
| 207 |
% \DescribeMacro{\fourdigitsep}% |
| 208 |
% \DescribeMacro{\fourdigitnosep}% |
| 209 |
% \changes{0.06}{2002/09/18}{Add description for not separating four |
| 210 |
% digit numbers}% |
| 211 |
% Some people want numbers with four digits not to be devided by a |
| 212 |
% thousand separator. |
| 213 |
% This can be achieved using the command |\fourdigitnosep|. |
| 214 |
% You can switch back to separating with |\fourdigitsep|. |
| 215 |
% An example: |
| 216 |
% \begin{verbatim} |
| 217 |
%\fourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ -- |
| 218 |
%\fourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$ |
| 219 |
% \end{verbatim} |
| 220 |
% Leads to |
| 221 |
% ``\fourdigitnosep$\numprint{1234.1234}$, $\numprint{12345.12345}$ -- |
| 222 |
% \fourdigitsep$\numprint{1234.1234}$, $\numprint{12345.12345}$''. |
| 223 |
% Default values can be set by the package options |sepfour| and |
| 224 |
% |nosepfour|. |
| 225 |
% |
| 226 |
% If a number has four digits before the decimal sign, but more than |
| 227 |
% four digits after it, or vice versa, the fourth digit is seperated |
| 228 |
% \emph{before and after} the digital sign for consistency. |
| 229 |
% An example: |
| 230 |
% \begin{verbatim} |
| 231 |
%\fourdigitnosep$\numprint{1234.1234}$, $\numprint{1234.12345}$, |
| 232 |
%$\numprint{12345.1234}$ |
| 233 |
% \end{verbatim} |
| 234 |
% Leads to |
| 235 |
% ``\fourdigitnosep$\numprint{1234.1234}$, $\numprint{1234.12345}$, |
| 236 |
% $\numprint{12345.1234}$''. |
| 237 |
% |
| 238 |
% \subsubsection{Add missing zeros before or after decimal sign} |
| 239 |
% |
| 240 |
% \DescribeMacro{\addmissingzero}% |
| 241 |
% \DescribeMacro{\noaddmissingzero}% |
| 242 |
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before |
| 243 |
% and after decimalsign}% |
| 244 |
% Sometimes people let out a leading zero or a zero after the |
| 245 |
% decimalsign, e.g. |123.| or |.123|. |
| 246 |
% Numprint can add the left out zero, when |\addmissingzero| is |
| 247 |
% used. This behaviour can be switched of with |\noaddmissingzero|. |
| 248 |
% Corresponding package options are |addmissingzero| and |
| 249 |
% |noaddmissinzero|. Default is |addmissingzero|. |
| 250 |
% |
| 251 |
% |
| 252 |
% \subsubsection[Rounding numbers]{Rounding numbers\footnote{This was |
| 253 |
% an idea of Tilman Finke, [email protected]}}% |
| 254 |
% \changes{0.30}{2003/05/19}{Add rounding of numbers}% |
| 255 |
% |
| 256 |
% \DescribeMacro{\nprounddigits}% |
| 257 |
% \DescribeMacro{\nproundexpdigits}% |
| 258 |
% \DescribeMacro{\npnoround}% |
| 259 |
% \DescribeMacro{\npnoroundexp}% |
| 260 |
% By default, as many digits are printed after the decimal sign, as |
| 261 |
% the \cs{numprint} command gets as argument. |
| 262 |
% This behaviour can be changed to print a given number of digits |
| 263 |
% where the number is rounded resp.\ filled with zeros. |
| 264 |
% |
| 265 |
% This can be switched of using the |
| 266 |
% \cs{nprounddigits\{\meta{\normalfont digits}\}} command for ordinary |
| 267 |
% numbers and the \cs{nproundexpdigits\{\meta{\normalfont digits}\}} |
| 268 |
% command for exponents. |
| 269 |
% Rounding is switched off with \cs{npnoround} resp.\ |
| 270 |
% \cs{npnoroundexp}. |
| 271 |
% For example, |
| 272 |
% \begin{verbatim} |
| 273 |
%\nprounddigits{2}$\numprint{1.123}$, $\numprint{1.149}$, |
| 274 |
%$\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$ -- |
| 275 |
%\npnoround$\numprint{1.123}$, $\numprint{1.149}$, |
| 276 |
%$\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$ |
| 277 |
% \end{verbatim} |
| 278 |
% leads to |
| 279 |
% ``\nprounddigits{2}$\numprint{1.123}$, $\numprint{1.149}$, |
| 280 |
% $\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$ -- |
| 281 |
% \npnoround$\numprint{1.123}$, $\numprint{1.149}$, |
| 282 |
% $\numprint{1}$, $\numprint{9.999}$ $\numprint{-9.999}$'' |
| 283 |
% |
| 284 |
% \DescribeMacro{\npreplacenull}% |
| 285 |
% \DescribeMacro{\npprintnull}% |
| 286 |
% For amounts of money, sometimes a zero after the decimal sign is |
| 287 |
% replaced by different signs, as for example ``---''. |
| 288 |
% If rounding is switched on, this can be done by calling |
| 289 |
% \cs{npreplacenull\{\meta{\normalfont replacement}\}}, e.g. |
| 290 |
% \begin{verbatim} |
| 291 |
%\npreplacenull{\mbox{---}} |
| 292 |
% \end{verbatim} |
| 293 |
% Here, \cs{mbox} guarantees that ``---'' is printed in text mode. |
| 294 |
% It can be switched off using \cs{npprintnull}. |
| 295 |
% |
| 296 |
% |
| 297 |
% \subsection{Print aligned numbers in tabulars}% |
| 298 |
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular |
| 299 |
% entries}% |
| 300 |
% |
| 301 |
% The aim of this function is to combine the functionality of the |
| 302 |
% \verb|dcolumn| package with this one. This has not been achieved by |
| 303 |
% this version. But a first step is done. |
| 304 |
% |
| 305 |
% \DescribeMacro{columntype n} |
| 306 |
% \DescribeMacro{columntype N} |
| 307 |
% This package defines two new column types \verb|n| and \verb|N|. The |
| 308 |
% first one alignes the base number to the decimal sign, the second |
| 309 |
% additionaly alignes the exponent. |
| 310 |
% Use these commands like follows: |
| 311 |
% \begin{verbatim} |
| 312 |
%\begin{tabular}{|n{5}{3}|N{5}{3}{3}|} |
| 313 |
% \hline |
| 314 |
% \numprint{123.45e12.12}& \numprint{123.45e12.12}\\ |
| 315 |
% \numprint{12345.678e123.123}& \numprint{12345.678e123.123}\\ |
| 316 |
% \hline |
| 317 |
%\end{tabular} |
| 318 |
% \end{verbatim} |
| 319 |
% This leads to\par |
| 320 |
% \begin{tabular}{|n{5}{3}|N{5}{3}{3}|} |
| 321 |
% \hline |
| 322 |
% \numprint{123.45e12.12}& \numprint{123.45e12.12}\\ |
| 323 |
% \numprint{12345.678e123.123}& \numprint{12345.678e123.123}\\ |
| 324 |
% \hline |
| 325 |
% \end{tabular} |
| 326 |
% |
| 327 |
% The first option defines the number of digits before the decimal |
| 328 |
% sign, the second the number after. |
| 329 |
% In case of the type \verb|N| the third option defines the number of |
| 330 |
% digits before the decimal sign in the exponent. |
| 331 |
% Unfortunately the number of digits can not be calculated |
| 332 |
% automatically. |
| 333 |
% Notice that the command \verb|\numprint| has to be written again in |
| 334 |
% each tabular entry. This will hopefully be changed in a future version. |
| 335 |
% |
| 336 |
% \section{To Do} |
| 337 |
% |
| 338 |
% \begin{itemize} |
| 339 |
% \item Add automatic international support using babel, german, or ngerman: |
| 340 |
% |
| 341 |
% German: \npdecimalsign{,}\npthousandsep{\,}\npproductsign{\cdot}% |
| 342 |
% \numprint{3,1415927e-3.1} |
| 343 |
% |
| 344 |
% American: \npdecimalsign{.}\npthousandsep{,}\npproductsign{\times}% |
| 345 |
% \numprint{3,1415927e-3.1} |
| 346 |
% \item Combine the packages dcolumn and numprint. |
| 347 |
% \item Fix spacing in aligned exponents (spacing is too large). |
| 348 |
% \end{itemize} |
| 349 |
% |
| 350 |
% \StopEventually{\PrintChanges \PrintIndex} |
| 351 |
% |
| 352 |
% |
| 353 |
% \section{The implementation} |
| 354 |
% \iffalse |
| 355 |
%<*package> |
| 356 |
% \fi |
| 357 |
% Heading of the package: |
| 358 |
% \begin{macrocode} |
| 359 |
\NeedsTeXFormat{LaTeX2e} |
| 360 |
\ProvidesPackage{numprint032}[\nprtfiledate\space v\nprtfileversion\space |
| 361 |
Print numbers] |
| 362 |
\message{Package `numprint032', Version \nprtfileversion\space of \nprtfiledate.} |
| 363 |
\message{Compatiblity version of numprint for versions prior 1.00} |
| 364 |
% \end{macrocode} |
| 365 |
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}% |
| 366 |
% Load package calc.sty for calculating widths of boxes. |
| 367 |
% \begin{macrocode} |
| 368 |
\RequirePackage{calc} |
| 369 |
% \end{macrocode} |
| 370 |
% Load package array.sty for the new column types. |
| 371 |
% \begin{macrocode} |
| 372 |
\RequirePackage{array} |
| 373 |
% \end{macrocode} |
| 374 |
% Define a boolean if the first digit is separated in a four digit |
| 375 |
% number. Default is true for compatibility with older versions. |
| 376 |
% \begin{macrocode} |
| 377 |
\newif\if@numsepfour |
| 378 |
% \end{macrocode} |
| 379 |
% Define a command which helds the zero to be added if necessary. |
| 380 |
% \begin{macrocode} |
| 381 |
\newcommand\@addmissingzero{} |
| 382 |
% \end{macrocode} |
| 383 |
% \begin{macro}{\fourdigitsep} |
| 384 |
% Switch separating of the fourth digit on. |
| 385 |
% \begin{macrocode} |
| 386 |
\newcommand*{\fourdigitsep}{\@numsepfourtrue}% |
| 387 |
% \end{macrocode} |
| 388 |
% \end{macro} |
| 389 |
% \begin{macro}{\fourdigitnosep} |
| 390 |
% Switch separating of the fourth digit off. |
| 391 |
% \begin{macrocode} |
| 392 |
\newcommand*{\fourdigitnosep}{\@numsepfourfalse}% |
| 393 |
% \end{macrocode} |
| 394 |
% \end{macro} |
| 395 |
% \begin{macro}{\addmissingzero} |
| 396 |
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before |
| 397 |
% and after decimalsign}% |
| 398 |
% Add a missing zero before or after decimalsign. |
| 399 |
% \begin{macrocode} |
| 400 |
\newcommand*{\addmissingzero}{\def\@addmissingzero{0}}% |
| 401 |
% \end{macrocode} |
| 402 |
% \end{macro} |
| 403 |
% \begin{macro}{\noaddmissingzero} |
| 404 |
% Don't add a missing zero before or after decimalsign. |
| 405 |
% \begin{macrocode} |
| 406 |
\newcommand*{\noaddmissingzero}{\def\@addmissingzero{}}% |
| 407 |
% \end{macrocode} |
| 408 |
% \end{macro} |
| 409 |
% Declare options. \verb|nosepfour| switches seperating of the fourth |
| 410 |
% digit off, \verb|sepfour| switches it on. Default is on four |
| 411 |
% compatibility reasons with older versions. |
| 412 |
% \begin{macrocode} |
| 413 |
\DeclareOption{nosepfour}{\fourdigitnosep} |
| 414 |
\DeclareOption{sepfour}{\fourdigitsep} |
| 415 |
\DeclareOption{noaddmissingzero}{\noaddmissingzero} |
| 416 |
\DeclareOption{addmissingzero}{\addmissingzero} |
| 417 |
\ExecuteOptions{sepfour,addmissingzero} |
| 418 |
\ProcessOptions\relax |
| 419 |
% \end{macrocode} |
| 420 |
% Define commands to change the output of the \verb|\numprint| |
| 421 |
% command. |
| 422 |
% |
| 423 |
% \begin{macro}{\npdecimalsign} |
| 424 |
% Change the decimal sign. In English it is normally ``.'', in German |
| 425 |
% ``,''. |
| 426 |
% The additional pair of braces \verb|{}| prevents from inserting |
| 427 |
% additional space in math mode, e.g. $1,2$ versus $1{,}2$. |
| 428 |
% \begin{macrocode} |
| 429 |
\newcommand{\npdecimalsign}[1]{\def\nprt@decimal{{#1}}} |
| 430 |
% \end{macrocode} |
| 431 |
% \end{macro} |
| 432 |
% \begin{macro}{\npthousandsep} |
| 433 |
% Change the thousand separator. In English it often is ``,'', in |
| 434 |
% German ``.'' or ``\,'' (\verb|\,|). |
| 435 |
% Here again the additional \verb|{}| is used as above. |
| 436 |
% This command changes both the sign before and after the comma. If |
| 437 |
% you want a different sign after the comma you have to call |
| 438 |
% \verb|\npthousandthpartsep| after \verb|\npthousandsep|. |
| 439 |
% \begin{macrocode} |
| 440 |
\newcommand{\npthousandsep}[1]{\def\nprt@thousand{{#1}}% |
| 441 |
\def\nprt@thousandthpart{{#1}}} |
| 442 |
% \end{macrocode} |
| 443 |
% \end{macro}% |
| 444 |
% \begin{macro}{\npthousandthpartsep} |
| 445 |
% \begin{macrocode} |
| 446 |
\newcommand{\npthousandthpartsep}[1]{\def\nprt@thousandthpart{{#1}}} |
| 447 |
% \end{macrocode} |
| 448 |
% \end{macro} |
| 449 |
% \begin{macro}{\npproductsign} |
| 450 |
% Change the product sign that is printed in numbers with exponent |
| 451 |
% like $\numprint{123e4}$. Normally it is \verb|\cdot|. In American |
| 452 |
% texts sometimes \verb|\times|. |
| 453 |
% The two pairs of braces \verb|{}| ensure the correct spacing on the |
| 454 |
% left and right side of the product sign, e.g. 3$\cdot$4 versus |
| 455 |
% 3${}\cdot{}$4. |
| 456 |
% \begin{macrocode} |
| 457 |
\newcommand{\npproductsign}[1]{\def\nprt@prod{\ensuremath{{}#1{}}}} |
| 458 |
% \end{macrocode} |
| 459 |
% \end{macro} |
| 460 |
% \begin{macro}{\npunitseparator} |
| 461 |
% Change the separator between number an unit. |
| 462 |
% Here again the additional \verb|{}| is used as above. |
| 463 |
% \changes{0.03}{2001/02/10}{Fixed bug with units}% |
| 464 |
% \begin{macrocode} |
| 465 |
\newcommand{\npunitseparator}[1]{\def\nprt@unitsep{{#1}}} |
| 466 |
% \end{macrocode} |
| 467 |
% \end{macro} |
| 468 |
% Set the default values for the separators. They will surely change |
| 469 |
% in a new version with automatic international support. At the moment |
| 470 |
% the defaults match the German language. |
| 471 |
% \begin{macrocode} |
| 472 |
\npthousandsep{\,}% |
| 473 |
\npthousandthpartsep{\,}% |
| 474 |
\npdecimalsign{,}% |
| 475 |
\npproductsign{{}\cdot{}}% |
| 476 |
\npunitseparator{\,}% |
| 477 |
% \end{macrocode} |
| 478 |
% \changes{0.30}{2003/05/19}{Add rounding of numbers}% |
| 479 |
% \begin{macro}{\@fillnull} |
| 480 |
% Defines command |#1| with a number of |#2| zeros filled. |
| 481 |
% \begin{macrocode} |
| 482 |
\def\@fillnull#1#2{% |
| 483 |
\@tempcnta=0 |
| 484 |
\loop |
| 485 |
\g@addto@macro{#1}{0}% |
| 486 |
\advance\@tempcnta by 1 |
| 487 |
\ifnum\@tempcnta<#2 |
| 488 |
\repeat |
| 489 |
} |
| 490 |
% \end{macrocode} |
| 491 |
% \end{macro} |
| 492 |
% \begin{macro}{\nprounddigits} |
| 493 |
% Define a command that sets a count of digits after which the number |
| 494 |
% is rounded. |
| 495 |
% This command defines \cs{nprt@rounddigits} that stores the count and |
| 496 |
% \cs{nprt@roundnull} that contains of \cs{nprt@rounddigits} ``0'' |
| 497 |
% digits. |
| 498 |
% \begin{macrocode} |
| 499 |
\newcommand\nprounddigits[1]{% |
| 500 |
\def\nprt@rounddigits{#1}% |
| 501 |
\def\nprt@roundnull{}% |
| 502 |
\@fillnull{\nprt@roundnull}{#1}% |
| 503 |
} |
| 504 |
% \end{macrocode} |
| 505 |
% \end{macro} |
| 506 |
% \begin{macro}{\npnoround} |
| 507 |
% A command to switch off rounding. |
| 508 |
% \begin{macrocode} |
| 509 |
\newcommand\npnoround{\nprounddigits{-1}} |
| 510 |
% \end{macrocode} |
| 511 |
% \end{macro} |
| 512 |
% Don't round by default. |
| 513 |
% \begin{macrocode} |
| 514 |
\npnoround |
| 515 |
% \end{macrocode} |
| 516 |
% \begin{macro}{\nproundexpdigits} |
| 517 |
% \begin{macro}{\npnoroundexp} |
| 518 |
% The same for exponents. |
| 519 |
% \begin{macrocode} |
| 520 |
\newcommand\nproundexpdigits[1]{% |
| 521 |
\def\nprt@roundexpdigits{#1}% |
| 522 |
\def\nprt@roundexpnull{}% |
| 523 |
\@fillnull{\nprt@roundexpnull}{#1}% |
| 524 |
} |
| 525 |
\newcommand\npnoroundexp{\nproundexpdigits{-1}} |
| 526 |
\npnoroundexp |
| 527 |
% \end{macrocode} |
| 528 |
% \end{macro} |
| 529 |
% \end{macro} |
| 530 |
% \changes{0.30}{2003/05/19}{Optionally replace zero after decimal sign}% |
| 531 |
% \begin{macro}{\npreplacenull} |
| 532 |
% Optionally, one or more zeros after the decimal sign can be replaced |
| 533 |
% by other text, e.g.\ ``---'''. |
| 534 |
% \begin{macrocode} |
| 535 |
\newcommand\npreplacenull[1]{\def\nprt@replacenull{#1}} |
| 536 |
% \end{macrocode} |
| 537 |
% \end{macro} |
| 538 |
% \begin{macro}{\npprintnull} |
| 539 |
% Switch off replacement, again. |
| 540 |
% \begin{macrocode} |
| 541 |
\newcommand\npprintnull{\let\nprt@replacenull=\@empty} |
| 542 |
% \end{macrocode} |
| 543 |
% \end{macro} |
| 544 |
% Print the zero by default. |
| 545 |
% \begin{macrocode} |
| 546 |
\npprintnull |
| 547 |
% \end{macrocode} |
| 548 |
% Define the signs as commands. This is necessary to be able to |
| 549 |
% compare them with other characters. |
| 550 |
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}% |
| 551 |
% \begin{macrocode} |
| 552 |
\def\nprt@plus@test{+} |
| 553 |
\def\nprt@minus@test{-} |
| 554 |
\def\nprt@plusminus@test{\pm} |
| 555 |
% \end{macrocode} |
| 556 |
% Define commands for printing the signs in math mode. This ensures |
| 557 |
% that the printed signs really are signs and not hyphens. Compare |
| 558 |
% ``-'' to ``\ensuremath{-}''. |
| 559 |
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}% |
| 560 |
% \begin{macrocode} |
| 561 |
\def\nprt@plus{\ensuremath{+}} |
| 562 |
\def\nprt@minus{\ensuremath{-}} |
| 563 |
\def\nprt@plusminus{\ensuremath{\pm}} |
| 564 |
% \end{macrocode} |
| 565 |
% \begin{macro}{\nprt@printdigit} |
| 566 |
% Print a digit. If this digit is a sign (\verb|+| or \verb|-|) it is |
| 567 |
% printed in math mode, else it is printed in the active mode. |
| 568 |
% \begin{macrocode} |
| 569 |
\def\nprt@printdigit#1{% |
| 570 |
\def\nprt@tmp{#1}% |
| 571 |
\ifx\nprt@tmp\nprt@plus@test |
| 572 |
\nprt@plus |
| 573 |
\else |
| 574 |
\ifx\nprt@tmp\nprt@minus@test |
| 575 |
\nprt@minus |
| 576 |
\else |
| 577 |
\ifx\nprt@tmp\nprt@plusminus@test |
| 578 |
\nprt@plusminus |
| 579 |
\else |
| 580 |
#1% |
| 581 |
\fi |
| 582 |
\fi |
| 583 |
\fi |
| 584 |
} |
| 585 |
% \end{macrocode} |
| 586 |
% \end{macro} |
| 587 |
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}% |
| 588 |
% Define some booleans. |
| 589 |
% \verb|\ifnprt@block| decides whether the number is centered to the |
| 590 |
% decimal sign. |
| 591 |
% \verb|\ifnprt@blockexp| does the same for the exponent. |
| 592 |
% \verb|\ifnprt@exponent| is true when printing the exponent and false |
| 593 |
% otherwise. |
| 594 |
% \verb|\ifnprt@inmath| is set to true when using the command in math |
| 595 |
% mode. |
| 596 |
% \begin{macrocode} |
| 597 |
\newif\ifnprt@block |
| 598 |
\newif\ifnprt@blockexp |
| 599 |
\newif\ifnprt@exponent |
| 600 |
\newif\ifnprt@inmath |
| 601 |
% \end{macrocode} |
| 602 |
% \begin{macro}{\digits} |
| 603 |
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}% |
| 604 |
% With this command the user can switch to aligned printing. |
| 605 |
% The first parameter stands for the digits before the decimal sign |
| 606 |
% and the second for the digits after it. |
| 607 |
% \begin{macrocode} |
| 608 |
\newcommand{\digits}[2]{% |
| 609 |
\xdef\nprt@blockbefore{#1}% |
| 610 |
\xdef\nprt@blockafter{#2}% |
| 611 |
\nprt@blocktrue}% |
| 612 |
% \end{macrocode} |
| 613 |
% \end{macro} |
| 614 |
% \begin{macro}{\nodigits} |
| 615 |
% Switch back to normal printing. |
| 616 |
% \begin{macrocode} |
| 617 |
\newcommand{\nodigits}{\nprt@blockfalse}% |
| 618 |
% \end{macrocode} |
| 619 |
% \end{macro} |
| 620 |
% \begin{macro}{\exponentdigits} |
| 621 |
% With this command the user can switch to aligned printing of the |
| 622 |
% exponent. |
| 623 |
% The parameter stands for the digits before the decimal sign. |
| 624 |
% \begin{macrocode} |
| 625 |
\newcommand{\exponentdigits}[1]{% |
| 626 |
\xdef\nprt@blockexpbefore{#1}% |
| 627 |
\nprt@blockexptrue}% |
| 628 |
% \end{macrocode} |
| 629 |
% \end{macro} |
| 630 |
% \begin{macro}{\noexponentdigits} |
| 631 |
% Switch back to normal printing. |
| 632 |
% \begin{macrocode} |
| 633 |
\newcommand{\noexponentdigits}{\nprt@blockexpfalse}% |
| 634 |
% \end{macrocode} |
| 635 |
% \end{macro} |
| 636 |
% \begin{macro}{\nprt@three} |
| 637 |
% Print up to three digits and call this command again recursively if there |
| 638 |
% are more digits to print. |
| 639 |
% |
| 640 |
% The command must be called in a different way than normal \LaTeX\ |
| 641 |
% commands. Braces must not be used but at the end of the command |
| 642 |
% list \verb|\@empty| has to appear in the source code. The command |
| 643 |
% gets four arguments where the first three are single digits and the |
| 644 |
% fourth contains the rest of the text preceding the \verb|\@empty|. |
| 645 |
% \begin{macrocode} |
| 646 |
\def\nprt@three#1#2#3#4\@empty{% |
| 647 |
% \end{macrocode} |
| 648 |
% Print the three digits. |
| 649 |
% \begin{macrocode} |
| 650 |
\nprt@printdigit#1% |
| 651 |
\nprt@printdigit#2% |
| 652 |
\nprt@printdigit#3% |
| 653 |
% \end{macrocode} |
| 654 |
% Define a temporary variable containing the rest string for testing |
| 655 |
% if there is a rest at all. |
| 656 |
% \begin{macrocode} |
| 657 |
\def\nprt@tmp{#4}% |
| 658 |
\ifx\nprt@tmp\empty |
| 659 |
\else |
| 660 |
% \end{macrocode} |
| 661 |
% If there is a rest string insert the thousand separator \dots |
| 662 |
% \begin{macrocode} |
| 663 |
\nprt@thousand% |
| 664 |
% \end{macrocode} |
| 665 |
% \dots\ and call this command recursively. |
| 666 |
% Append enough \verb|\@empty| statements to ensure that the command |
| 667 |
% gets four arguments. |
| 668 |
% \begin{macrocode} |
| 669 |
\nprt@three#4\@empty\@empty\@empty |
| 670 |
\fi |
| 671 |
} |
| 672 |
% \end{macrocode} |
| 673 |
% \end{macro} |
| 674 |
% \begin{macro}{\nprt@threeafter} |
| 675 |
% Print up to three digits and call this command again recursively if there |
| 676 |
% are more digits to print. For use after the decimal sign. |
| 677 |
% \begin{macrocode} |
| 678 |
\def\nprt@threeafter#1#2#3#4\@empty{% |
| 679 |
% \end{macrocode} |
| 680 |
% Print the three digits. |
| 681 |
% \begin{macrocode} |
| 682 |
\nprt@printdigit#1% |
| 683 |
\nprt@printdigit#2% |
| 684 |
\nprt@printdigit#3% |
| 685 |
% \end{macrocode} |
| 686 |
% Define a temporary variable containing the rest string for testing |
| 687 |
% if there is a rest at all. |
| 688 |
% \begin{macrocode} |
| 689 |
\def\nprt@tmp{#4}% |
| 690 |
\ifx\nprt@tmp\empty |
| 691 |
\else |
| 692 |
% \end{macrocode} |
| 693 |
% If there is a rest string insert the thousand separator \dots |
| 694 |
% \begin{macrocode} |
| 695 |
\nprt@thousandthpart% |
| 696 |
% \end{macrocode} |
| 697 |
% \dots\ and call this command recursively. |
| 698 |
% Append enough \verb|\@empty| statements to ensure that the command |
| 699 |
% gets four arguments. |
| 700 |
% \begin{macrocode} |
| 701 |
\nprt@threeafter#4\@empty\@empty\@empty |
| 702 |
\fi |
| 703 |
} |
| 704 |
% \end{macrocode} |
| 705 |
% \end{macro} |
| 706 |
% \begin{macro}{\nprt@two} |
| 707 |
% Print two digits and call \verb|\nprt@three| if there |
| 708 |
% are more digits to print. This command is maximally used once at the |
| 709 |
% beginning of the number when it contains 2, 5, 8, 11, \dots\ digits |
| 710 |
% before the decimal sign. For a description have a look at |
| 711 |
% \verb|\nprt@three|. |
| 712 |
% \begin{macrocode} |
| 713 |
\def\nprt@two#1#2#3\@empty{% |
| 714 |
\nprt@printdigit#1% |
| 715 |
\nprt@printdigit#2% |
| 716 |
\def\nprt@tmp{#3}% |
| 717 |
\ifx\nprt@tmp\empty |
| 718 |
\else |
| 719 |
\nprt@thousand\nprt@three#3\@empty\@empty\@empty |
| 720 |
\fi |
| 721 |
} |
| 722 |
% \end{macrocode} |
| 723 |
% \end{macro} |
| 724 |
% \begin{macro}{\nprt@one} |
| 725 |
% Print one digit and call \verb|\nprt@three| if there |
| 726 |
% are more digits to print. This command is maximally used once at the |
| 727 |
% beginning of the number when it contains 1, 4, 7, 10, \dots\ digits |
| 728 |
% before the decimal sign. For a description watch \verb|\nprt@three|. |
| 729 |
% \begin{macrocode} |
| 730 |
\def\nprt@one#1#2\@empty{% |
| 731 |
\nprt@printdigit#1% |
| 732 |
\def\nprt@tmp{#2}% |
| 733 |
\ifx\nprt@tmp\empty |
| 734 |
\else |
| 735 |
% \end{macrocode} |
| 736 |
% Test if the first character was a sign. The thousand separator may |
| 737 |
% only be printed if the first character is no sign. |
| 738 |
% \changes{0.20}{2003/02/24}{Added support for $\pm$ sign}% |
| 739 |
% \begin{macrocode} |
| 740 |
\def\nprt@tmp{#1}% |
| 741 |
\ifx\nprt@tmp\nprt@plus@test |
| 742 |
\else |
| 743 |
\ifx\nprt@tmp\nprt@minus@test |
| 744 |
\else |
| 745 |
\ifx\nprt@tmp\nprt@plusminus@test |
| 746 |
\else |
| 747 |
\nprt@thousand |
| 748 |
\fi |
| 749 |
\fi |
| 750 |
\fi |
| 751 |
\nprt@three#2\@empty\@empty\@empty |
| 752 |
\fi |
| 753 |
} |
| 754 |
% \end{macrocode} |
| 755 |
% \end{macro} |
| 756 |
% Define routines to test if a character is included in a string. If |
| 757 |
% yes the command \verb|\nprt@tmp| returns a nonempty string. If the |
| 758 |
% string does not contain the character \verb|\nprt@tmp| returns |
| 759 |
% nothing. To achieve this functionality the commands have to be |
| 760 |
% called in a special way. For example to test for a comma in a command |
| 761 |
% \verb|\str| you have to write |
| 762 |
% \verb|\nprt@commatest\str,\@empty|. So you always have to |
| 763 |
% append the character you are searching for (e.g. \verb|,|) and |
| 764 |
% \verb|\@empty| to your search string. |
| 765 |
% \begin{macrocode} |
| 766 |
\def\nprt@exptest#1e#2\@empty{\gdef\nprt@tmp{#2}} |
| 767 |
\def\nprt@Exptest#1E#2\@empty{\gdef\nprt@tmp{#2}} |
| 768 |
\def\nprt@commatest#1,#2\@empty{\gdef\nprt@tmp{#2}} |
| 769 |
\def\nprt@dottest#1.#2\@empty{\gdef\nprt@tmp{#2}} |
| 770 |
% \end{macrocode} |
| 771 |
% \begin{macro}{\nprt@exp} |
| 772 |
% Print number in the exponential format with an argument containing a |
| 773 |
% small ``e''. Call: \verb|\nprt@exp| number\verb|\@empty|, |
| 774 |
% e.g. \verb|\nprt@exp 123.2e4,3\@empty|. Both numbers containing a comma or |
| 775 |
% a dot work. |
| 776 |
% \begin{macrocode} |
| 777 |
\def\nprt@exp#1e#2\@empty{\expnumprint{#1}{#2}} |
| 778 |
% \end{macrocode} |
| 779 |
% \end{macro} |
| 780 |
% \begin{macro}{\nprt@Exp} |
| 781 |
% Print number in the exponential format with an argument containing a |
| 782 |
% capital ``E''. Call: \verb|\nprt@Exp| number\verb|\@empty|, |
| 783 |
% e.g. \verb|\nprt@Exp 123.2E4,3\@empty|. Both numbers containing a comma or |
| 784 |
% a dot work. |
| 785 |
% \begin{macrocode} |
| 786 |
\def\nprt@Exp#1E#2\@empty{\expnumprint{#1}{#2}} |
| 787 |
% \end{macrocode} |
| 788 |
% \end{macro} |
| 789 |
% \begin{macro}{\nprt@comma} |
| 790 |
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before |
| 791 |
% and after decimalsign}% |
| 792 |
% Print a number without exponential part containing a comma. Call: |
| 793 |
% \verb|\nprt@comma| number\verb|\@empty|, e.g. |
| 794 |
% \verb|\nprt@comma 123,2\@empty|. |
| 795 |
% \begin{macrocode} |
| 796 |
\def\nprt@comma#1,#2\@empty{% |
| 797 |
\nprt@dotcomma{#1}{#2}} |
| 798 |
% \end{macrocode} |
| 799 |
% \end{macro} |
| 800 |
% \begin{macro}{\nprt@dot} |
| 801 |
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before |
| 802 |
% and after decimalsign}% |
| 803 |
% Print a number without exponential part containing a comma. Call: |
| 804 |
% \verb|\nprt@dot| number\verb|\@empty|, e.g. |
| 805 |
% \verb|\nprt@dot 123.2\@empty|. |
| 806 |
% \begin{macrocode} |
| 807 |
\def\nprt@dot#1.#2\@empty{% |
| 808 |
\nprt@dotcomma{#1}{#2}} |
| 809 |
% \end{macrocode} |
| 810 |
% \end{macro} |
| 811 |
% \begin{macro}{\nprt@dotcomma} |
| 812 |
% \changes{0.06}{2002/09/18}{Add handling for missing numbers before |
| 813 |
% and after decimalsign}% |
| 814 |
% \changes{0.30}{2003/05/19}{Add support for rounding}% |
| 815 |
% Print a number without exponential part containing a dot or a comma. Call: |
| 816 |
% \verb|\nprt@dotcomma{before}{after}|, e.g.\ |
| 817 |
% \verb|\nprt@dot{123}{2}|. |
| 818 |
% \begin{macrocode} |
| 819 |
\def\nprt@dotcomma#1#2{% |
| 820 |
\begingroup |
| 821 |
% \end{macrocode} |
| 822 |
% If \cs{nprt@dotcomma} is called for printing an exponent, copy the |
| 823 |
% routines for exponents to the ordinary ones. This has to be done |
| 824 |
% between \cs{begingroup} and \cs{endgroup} to preserve the normal |
| 825 |
% settings. |
| 826 |
% \begin{macrocode} |
| 827 |
\ifnprt@exponent |
| 828 |
\edef\nprt@rounddigits{\nprt@roundexpdigits}% |
| 829 |
\edef\nprt@roundnull{\nprt@roundexpnull}% |
| 830 |
\fi |
| 831 |
\ifnum\nprt@rounddigits<0 |
| 832 |
% \end{macrocode} |
| 833 |
% If no rounding is done, just use the given arguments for printing. |
| 834 |
% \begin{macrocode} |
| 835 |
\def\nprt@charsbeforecomma{#1}% |
| 836 |
\def\nprt@charsaftercomma{#2}% |
| 837 |
\else |
| 838 |
% \end{macrocode} |
| 839 |
% If rounding, do it. |
| 840 |
% First, provide empty strings for the parts before and after the |
| 841 |
% digit sign. |
| 842 |
% \begin{macrocode} |
| 843 |
\def\nprt@charsbeforecomma{}% |
| 844 |
\def\nprt@charsaftercomma{}% |
| 845 |
% \end{macrocode} |
| 846 |
% Append enough zeros after the decimal sign that all digits are |
| 847 |
% surely printed. |
| 848 |
% \begin{macrocode} |
| 849 |
\edef\zwei{#2\nprt@roundnull}% |
| 850 |
% \end{macrocode} |
| 851 |
% Call the command \cs{nprt@roundaftercomma} that does the rounding |
| 852 |
% for the part after the decimal sign. |
| 853 |
% \begin{macrocode} |
| 854 |
\expandafter\nprt@roundaftercomma\zwei\empty |
| 855 |
% \end{macrocode} |
| 856 |
% If the first digit after the comma is rounded from 9 to 0, rounding |
| 857 |
% has to be continued before the decimal sign by calling |
| 858 |
% \cs{nprt@roundbeforecomma}. |
| 859 |
% \begin{macrocode} |
| 860 |
\if@@roundup |
| 861 |
\nprt@roundbeforecomma#1\empty |
| 862 |
% \end{macrocode} |
| 863 |
% If the first digit has to be rounded from 9 to 0, a 1 has to be |
| 864 |
% inserted before the number. |
| 865 |
% \begin{macrocode} |
| 866 |
\if@@roundup |
| 867 |
\expandafter\xdef\expandafter\nprt@charsbeforecomma{% |
| 868 |
1\nprt@charsbeforecomma}% |
| 869 |
\fi |
| 870 |
\else |
| 871 |
\def\nprt@charsbeforecomma{#1}% |
| 872 |
\fi |
| 873 |
\fi |
| 874 |
% \end{macrocode} |
| 875 |
% Count the digits after the comma. |
| 876 |
% \begin{macrocode} |
| 877 |
\nprt@@hassignfalse |
| 878 |
\expandafter\nprt@count\nprt@charsaftercomma\@empty\@empty\@empty |
| 879 |
% \end{macrocode} |
| 880 |
% Copy the result which is stored in |nprt@digitsbeforedecimal| to |
| 881 |
% |nprt@digitsafterdecimal|. |
| 882 |
% \begin{macrocode} |
| 883 |
\setcounter{nprt@digitsafterdecimal}{\thenprt@digitsbeforedecimal}% |
| 884 |
% \end{macrocode} |
| 885 |
% Count the digits before the comma. |
| 886 |
% \begin{macrocode} |
| 887 |
\expandafter\nprt@hassign\nprt@charsbeforecomma\@empty\@empty |
| 888 |
\expandafter\nprt@count\nprt@charsbeforecomma\@empty\@empty\@empty |
| 889 |
% \end{macrocode} |
| 890 |
% Typeset the digits before the comma. |
| 891 |
% \begin{macrocode} |
| 892 |
\ifnum\the\c@nprt@digitsbeforedecimal=0 |
| 893 |
\@addmissingzero |
| 894 |
\else |
| 895 |
\expandafter\beforecomma\nprt@charsbeforecomma\@empty\@empty |
| 896 |
\fi |
| 897 |
% \end{macrocode} |
| 898 |
% Typeset the part after the decimal sign, if necessary. |
| 899 |
% \begin{macrocode} |
| 900 |
\ifnum\nprt@rounddigits=0 |
| 901 |
\else |
| 902 |
% \end{macrocode} |
| 903 |
% Typeset the decimal sign. |
| 904 |
% \begin{macrocode} |
| 905 |
\nprt@decimal |
| 906 |
% \end{macrocode} |
| 907 |
% Typeset the digits after the comma. |
| 908 |
% \begin{macrocode} |
| 909 |
\ifnum\the\c@nprt@digitsafterdecimal>0 |
| 910 |
\aftercomma{\nprt@charsaftercomma}% |
| 911 |
\else |
| 912 |
\ifx\nprt@replacenull\@empty |
| 913 |
\@addmissingzero |
| 914 |
\else |
| 915 |
\nprt@replacenull |
| 916 |
\fi |
| 917 |
\fi |
| 918 |
\fi |
| 919 |
\endgroup |
| 920 |
} |
| 921 |
% \end{macrocode} |
| 922 |
% \end{macro} |
| 923 |
% \begin{macro}{\expnumprint} |
| 924 |
% Print number in the exponential format. This function is called by |
| 925 |
% \verb|\nprt@exp| and \verb|\nprt@Exp|. It just calls |
| 926 |
% \verb|\numprint| for the number itself, prints $\cdot 10$, and |
| 927 |
% calls \verb|\numprint| for the exponent. It is distinguished between |
| 928 |
% text and math mode to ensure the usage of the right fonts. |
| 929 |
% \changes{0.04}{2001/03/06}{Added support for pure $10^x$ format}% |
| 930 |
% \begin{macrocode} |
| 931 |
\newcommand{\expnumprint}[2]{% |
| 932 |
\def\nprt@tmp{#1}% |
| 933 |
\ifx\nprt@tmp\@empty |
| 934 |
\nprt@exponenttrue |
| 935 |
\ifmmode |
| 936 |
10^{\numprint{#2}}% |
| 937 |
\else |
| 938 |
10\textsuperscript{\numprint{#2}}% |
| 939 |
\fi |
| 940 |
\else |
| 941 |
\ifmmode |
| 942 |
\numprint{#1}% |
| 943 |
\nprt@exponenttrue |
| 944 |
\nprt@prod 10^{\numprint{#2}}% |
| 945 |
\else |
| 946 |
\numprint{#1}% |
| 947 |
\nprt@exponenttrue |
| 948 |
\nprt@prod 10\textsuperscript{\numprint{#2}}% |
| 949 |
\fi |
| 950 |
\fi |
| 951 |
\nprt@exponentfalse |
| 952 |
} |
| 953 |
% \end{macrocode} |
| 954 |
% \end{macro} |
| 955 |
% Define a macro that includes |\@empty|. This seems to be necesarry since |
| 956 |
% the optional argument of |\numprint| is not expanded before printing it. |
| 957 |
% \changes{0.22}{2003/02/27}{Bugfix with invalid spacing after the number}% |
| 958 |
% \begin{macrocode} |
| 959 |
\def\nprt@empty{\@empty}% |
| 960 |
% \end{macrocode} |
| 961 |
% \begin{macro}{\numprint} |
| 962 |
% This is the main command of this package. It gets a number in the |
| 963 |
% argument and prints it. |
| 964 |
% \begin{macrocode} |
| 965 |
\DeclareRobustCommand*\numprint[2][\@empty]{% |
| 966 |
% \end{macrocode} |
| 967 |
% \changes{0.32}{2003/09/28}{Reset the number of digits before and |
| 968 |
% after the decimal sign (Bugfix for nosepfour)}% |
| 969 |
% Reset the number of digits before and after the decimal sign. |
| 970 |
% Without doing it, \texttt{nosepfour} is broken by one number with |
| 971 |
% more than 4 digits. |
| 972 |
% \begin{macrocode} |
| 973 |
\setcounter{nprt@digitsafterdecimal}{0}% |
| 974 |
\setcounter{nprt@digitsbeforedecimal}{0}% |
| 975 |
% \end{macrocode} |
| 976 |
% \changes{0.31}{2003/09/16}{Expand the mandatory argument of the |
| 977 |
% \cs{numprint} command before parsing it}% |
| 978 |
% Expand argument first. |
| 979 |
% \begin{macrocode} |
| 980 |
\edef\nprt@marg{#2}% |
| 981 |
% \end{macrocode} |
| 982 |
% Call \verb|\nprt@Exptest| to test the argument for an ``E''. |
| 983 |
% \begin{macrocode} |
| 984 |
\expandafter\nprt@Exptest\nprt@marg E\@empty |
| 985 |
% \end{macrocode} |
| 986 |
% If the argument contains no ``E'' proceed here. |
| 987 |
% \begin{macrocode} |
| 988 |
\ifx\nprt@tmp\empty |
| 989 |
% \end{macrocode} |
| 990 |
% Call \verb|\nprt@exptest| to test the argument for an ``e''. |
| 991 |
% \begin{macrocode} |
| 992 |
\expandafter\nprt@exptest\nprt@marg e\@empty |
| 993 |
% \end{macrocode} |
| 994 |
% If the argument contains no ``e'' the argument contains a simple |
| 995 |
% number. Then proceed here. |
| 996 |
% \begin{macrocode} |
| 997 |
\ifx\nprt@tmp\empty |
| 998 |
% \end{macrocode} |
| 999 |
% Call \verb|\nprt@commatest| to test the argument for a ``,''. |
| 1000 |
% \begin{macrocode} |
| 1001 |
\expandafter\nprt@commatest\nprt@marg,\@empty |
| 1002 |
% \end{macrocode} |
| 1003 |
% If the argument contains no ``,'' proceed here. |
| 1004 |
% \begin{macrocode} |
| 1005 |
\ifx\nprt@tmp\empty |
| 1006 |
% \end{macrocode} |
| 1007 |
% Call \verb|\nprt@commatest| to test the argument for a ``.''. |
| 1008 |
% \begin{macrocode} |
| 1009 |
\expandafter\nprt@dottest\nprt@marg.\@empty |
| 1010 |
% \end{macrocode} |
| 1011 |
% If the argument contains no ``.'' the number has no decimal |
| 1012 |
% places. Then proceed here. |
| 1013 |
% \begin{macrocode} |
| 1014 |
\ifx\nprt@tmp\empty |
| 1015 |
% \end{macrocode} |
| 1016 |
% Count the digits of the integer number. |
| 1017 |
% \begin{macrocode} |
| 1018 |
\expandafter\nprt@hassign\nprt@marg\@empty |
| 1019 |
\expandafter\nprt@count\nprt@marg\@empty\@empty\@empty |
| 1020 |
% \end{macrocode} |
| 1021 |
% Print the number. |
| 1022 |
% \begin{macrocode} |
| 1023 |
\begingroup |
| 1024 |
% \end{macrocode} |
| 1025 |
% If \cs{nprt@dotcomma} is called for printing an exponent, copy the |
| 1026 |
% routines for exponents to the ordinary ones. This has to be done |
| 1027 |
% between \cs{begingroup} and \cs{endgroup} to preserve the normal |
| 1028 |
% settings. |
| 1029 |
% \begin{macrocode} |
| 1030 |
\ifnprt@exponent |
| 1031 |
\def\nprt@rounddigits{\nprt@roundexpdigits}% |
| 1032 |
\def\nprt@roundnull{\nprt@roundexpnull}% |
| 1033 |
\fi |
| 1034 |
% \end{macrocode} |
| 1035 |
% If rounding is switched on with at least on digit, the part |
| 1036 |
% after the decimal sign has to be printed. |
| 1037 |
% Set the number of digits, then. |
| 1038 |
% \begin{macrocode} |
| 1039 |
\ifnum\nprt@rounddigits>0 |
| 1040 |
\setcounter{nprt@digitsafterdecimal}{\nprt@rounddigits}% |
| 1041 |
\fi |
| 1042 |
% \end{macrocode} |
| 1043 |
% Print the integer part. |
| 1044 |
% \begin{macrocode} |
| 1045 |
\expandafter\beforecomma\nprt@marg\@empty\@empty |
| 1046 |
% \end{macrocode} |
| 1047 |
% Print the part after the decimal sign. |
| 1048 |
% \begin{macrocode} |
| 1049 |
\ifnum\nprt@rounddigits>0 |
| 1050 |
\nprt@decimal |
| 1051 |
\aftercomma{\nprt@roundnull}% |
| 1052 |
\fi |
| 1053 |
\endgroup |
| 1054 |
% \end{macrocode} |
| 1055 |
% If the argument contains a ``.'' proceed here. |
| 1056 |
% Call \verb|\nprt@dot| to print the whole number. |
| 1057 |
% \begin{macrocode} |
| 1058 |
\else |
| 1059 |
\expandafter\nprt@dot\nprt@marg\@empty |
| 1060 |
\fi |
| 1061 |
% \end{macrocode} |
| 1062 |
% If the argument contains a ``,'' proceed here. |
| 1063 |
% Call \verb|\nprt@comma| to print the whole number. |
| 1064 |
% \begin{macrocode} |
| 1065 |
\else |
| 1066 |
\expandafter\nprt@comma\nprt@marg\@empty |
| 1067 |
\fi |
| 1068 |
% \end{macrocode} |
| 1069 |
% If the argument contains a ``e'' proceed here. |
| 1070 |
% Call \verb|\nprt@exp| to print the whole number. |
| 1071 |
% \begin{macrocode} |
| 1072 |
\else |
| 1073 |
\expandafter\nprt@exp\nprt@marg\@empty |
| 1074 |
\fi |
| 1075 |
% \end{macrocode} |
| 1076 |
% If the argument contains a ``E'' proceed here. |
| 1077 |
% Call \verb|\nprt@Exp| to print the whole number. |
| 1078 |
% \begin{macrocode} |
| 1079 |
\else |
| 1080 |
\expandafter\nprt@Exp\nprt@marg\@empty |
| 1081 |
\fi |
| 1082 |
% \end{macrocode} |
| 1083 |
% \changes{0.02}{2000/08/30}{Added optional argument for units}% |
| 1084 |
% \changes{0.03}{2001/02/10}{Fixed bug with units}% |
| 1085 |
% \changes{0.20}{2003/02/24}{Fixed bug which made units fragile}% |
| 1086 |
% \changes{0.22}{2003/02/27}{Bugfix with invalid spacing after the number}% |
| 1087 |
% Handle optional argument and print the unit only when specified. |
| 1088 |
% \begin{macrocode} |
| 1089 |
\def\nprt@unit{#1}% |
| 1090 |
\ifx\nprt@unit\nprt@empty |
| 1091 |
\else |
| 1092 |
\ensuremath{\nprt@unitsep\mathrm{\nprt@unit}}% |
| 1093 |
\fi |
| 1094 |
} |
| 1095 |
% \end{macrocode} |
| 1096 |
% \end{macro} |
| 1097 |
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}% |
| 1098 |
% Counters for counting digits: \verb|nprt@countblocks| counts number |
| 1099 |
% of blocks before the decimal sign. \verb|nprt@digitsfirstblock| |
| 1100 |
% counts the digits in the first block (0 to 2). |
| 1101 |
% \verb|nprt@digitsbeforedecimal| counts the total number of |
| 1102 |
% digits before the decimal sign. |
| 1103 |
% \begin{macrocode} |
| 1104 |
\newcounter{nprt@countblocksbefore}% |
| 1105 |
\newcounter{nprt@digitsfirstblock}% |
| 1106 |
\newcounter{nprt@digitsafterdecimal}% |
| 1107 |
\newcounter{nprt@digitsbeforedecimal}% |
| 1108 |
% \end{macrocode} |
| 1109 |
% \begin{macro}{nprt@hassign} |
| 1110 |
% Tests weather the first character of a string is not a digit. |
| 1111 |
% \begin{macrocode} |
| 1112 |
\newif\ifnprt@@hassign |
| 1113 |
\def\nprt@hassign#1#2\@empty{% |
| 1114 |
\ifnum-9>-1#1 |
| 1115 |
\nprt@@hassignfalse |
| 1116 |
\else |
| 1117 |
\nprt@@hassigntrue |
| 1118 |
\fi |
| 1119 |
} |
| 1120 |
% \end{macrocode} |
| 1121 |
% \end{macro} |
| 1122 |
% \begin{macro}{\nprt@count} |
| 1123 |
% Count the number of digits of the argument. This is done recursively |
| 1124 |
% by taking one character of the string and counting the runs of this |
| 1125 |
% command. Every three digits the counter is resetted to zero because |
| 1126 |
% only the modulus (Rest??) of the number of digits devided by 3 is |
| 1127 |
% important. |
| 1128 |
% |
| 1129 |
% If the optional parameter contains anything other than |
| 1130 |
% \verb|\@empty| the number of digits after the comma is counted. |
| 1131 |
% \begin{macrocode} |
| 1132 |
\def\nprt@count#1#2\@empty{% |
| 1133 |
\setcounter{nprt@digitsbeforedecimal}{0}% |
| 1134 |
\edef\nprt@arg{#1}% |
| 1135 |
% \end{macrocode} |
| 1136 |
% Handle an empty argument. |
| 1137 |
% \begin{macrocode} |
| 1138 |
\ifx\nprt@arg\@empty |
| 1139 |
\else |
| 1140 |
% \end{macrocode} |
| 1141 |
% Count the digits. |
| 1142 |
% \begin{macrocode} |
| 1143 |
\ifnprt@@hassign |
| 1144 |
\nprt@@count#2\@empty\@empty |
| 1145 |
\else |
| 1146 |
\nprt@@count#1#2\@empty\@empty |
| 1147 |
\fi |
| 1148 |
\fi |
| 1149 |
% \end{macrocode} |
| 1150 |
% \begin{macrocode} |
| 1151 |
\setcounter{nprt@countblocksbefore}{\arabic{nprt@digitsbeforedecimal}/3}% |
| 1152 |
\setcounter{nprt@digitsfirstblock}{% |
| 1153 |
\arabic{nprt@digitsbeforedecimal}-3*\arabic{nprt@countblocksbefore}}% |
| 1154 |
} |
| 1155 |
% \end{macrocode} |
| 1156 |
% \end{macro} |
| 1157 |
% \begin{macro}{\nprt@@count} |
| 1158 |
% \changes{0.32}{2003/09/28}{Only one error message per \cs{numprint}}% |
| 1159 |
% Do the counting itself. |
| 1160 |
% \begin{macrocode} |
| 1161 |
\def\nprt@@count#1#2\@empty{% |
| 1162 |
\ifnum-9>-1#1 |
| 1163 |
\addtocounter{nprt@digitsbeforedecimal}{1}% |
| 1164 |
\def\nprt@tmp{#2}% |
| 1165 |
\ifx\nprt@tmp\empty |
| 1166 |
\else |
| 1167 |
\nprt@@count#2\@empty\@empty |
| 1168 |
\fi |
| 1169 |
\else |
| 1170 |
\PackageError{numprint}{Incorrect number format in |
| 1171 |
\string\numprint}{% |
| 1172 |
The main argument of the \string\numprint\space command may only |
| 1173 |
be started\MessageBreak |
| 1174 |
with \string"+\string", \string"-\string", or |
| 1175 |
\string"\string\pm\string" and then contain of\MessageBreak |
| 1176 |
digits \string"0\string" to \string"9\string", |
| 1177 |
\string",\string", \string".\string", \string"e\string", and |
| 1178 |
\string"E\string".}% |
| 1179 |
% \setcounter{nprt@digitsbeforedecimal}{-1}% |
| 1180 |
\fi |
| 1181 |
% \end{macrocode} |
| 1182 |
% Count number of characters |
| 1183 |
% \begin{macrocode} |
| 1184 |
} |
| 1185 |
% \end{macrocode} |
| 1186 |
% \end{macro} |
| 1187 |
% Print the digits before the decimal sign. Depending on the number of |
| 1188 |
% digits either \verb|\nprt@one|, \verb|\nprt@two|, or |
| 1189 |
% \verb|\nprt@three| is called. |
| 1190 |
% \begin{macrocode} |
| 1191 |
\newlength{\nprt@digitwidth}% |
| 1192 |
\newlength{\nprt@sepwidth}% |
| 1193 |
\newcounter{nprt@digitcount}% |
| 1194 |
\newcounter{nprt@sepcount}% |
| 1195 |
\newlength{\nprt@blockwidth}% |
| 1196 |
% \end{macrocode} |
| 1197 |
% \begin{macro}{beforecomma} |
| 1198 |
% Prints the number before the decimal sign. |
| 1199 |
% \begin{macrocode} |
| 1200 |
\def\beforecomma#1#2\@empty{% |
| 1201 |
% \end{macrocode} |
| 1202 |
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}% |
| 1203 |
% If the number should be printed aligned generate a block with the |
| 1204 |
% correct size. |
| 1205 |
% \begin{macrocode} |
| 1206 |
\ifnprt@block |
| 1207 |
\ifnprt@exponent |
| 1208 |
\else |
| 1209 |
\settowidth{\nprt@digitwidth}{1}% |
| 1210 |
\settowidth{\nprt@sepwidth}{\nprt@thousand}% |
| 1211 |
\setcounter{nprt@digitcount}{\nprt@blockbefore}% |
| 1212 |
\setcounter{nprt@sepcount}{(\nprt@blockbefore-1)/3}% |
| 1213 |
\setlength{\nprt@blockwidth}{% |
| 1214 |
\arabic{nprt@digitcount}\nprt@digitwidth+% |
| 1215 |
\arabic{nprt@sepcount}\nprt@sepwidth}% |
| 1216 |
% \end{macrocode} |
| 1217 |
% If block length is four digits and fourth digit is not to be |
| 1218 |
% separated adjust new width. |
| 1219 |
% \begin{macrocode} |
| 1220 |
\if@numsepfour |
| 1221 |
\else |
| 1222 |
\ifnum\nprt@blockbefore=4 |
| 1223 |
\ifnum\nprt@blockafter<5 |
| 1224 |
\setlength{\nprt@blockwidth}{4\nprt@digitwidth}% |
| 1225 |
\fi |
| 1226 |
\fi |
| 1227 |
\fi |
| 1228 |
% \end{macrocode} |
| 1229 |
% If math mode switch to math mode again after invoking box. |
| 1230 |
% \begin{macrocode} |
| 1231 |
\ifmmode\nprt@inmathtrue\fi |
| 1232 |
\makebox[\nprt@blockwidth][r]{% |
| 1233 |
\ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs) |
| 1234 |
\fi |
| 1235 |
\fi |
| 1236 |
\ifnprt@blockexp |
| 1237 |
\ifnprt@exponent |
| 1238 |
\settowidth{\nprt@digitwidth}{1}% |
| 1239 |
\settowidth{\nprt@sepwidth}{\nprt@thousand}% |
| 1240 |
\setcounter{nprt@digitcount}{\nprt@blockexpbefore}% |
| 1241 |
\setcounter{nprt@sepcount}{(\nprt@blockexpbefore-1)/3}% |
| 1242 |
\setlength{\nprt@blockwidth}{% |
| 1243 |
\arabic{nprt@digitcount}\nprt@digitwidth+% |
| 1244 |
\arabic{nprt@sepcount}\nprt@sepwidth}% |
| 1245 |
% \end{macrocode} |
| 1246 |
% If block length is four digits and fourth digit is not to be |
| 1247 |
% separated adjust new width. |
| 1248 |
% \begin{macrocode} |
| 1249 |
\if@numsepfour |
| 1250 |
\else |
| 1251 |
\ifnum\nprt@blockexpbefore=4 |
| 1252 |
\setlength{\nprt@blockwidth}{4\nprt@digitwidth}% |
| 1253 |
\fi |
| 1254 |
\fi |
| 1255 |
\ifmmode\nprt@inmathtrue\fi |
| 1256 |
\makebox[\nprt@blockwidth][r]{% |
| 1257 |
% \end{macrocode} |
| 1258 |
% asdf |
| 1259 |
% To do: correct font size (normalstyle, scriptstyle, scriptscriptstyle) |
| 1260 |
% \begin{macrocode} |
| 1261 |
\ifnprt@inmath$\scriptstyle\fi %$ (only for syntax highlighing in emacs) |
| 1262 |
\fi |
| 1263 |
\fi |
| 1264 |
% \end{macrocode} |
| 1265 |
% \changes{0.31}{2003/09/16}{Bug Fix: With four-digit numbers, print |
| 1266 |
% everything instead of first digit only}% |
| 1267 |
% Print the number itself. |
| 1268 |
% \begin{macrocode} |
| 1269 |
\ifnprt@@hassign |
| 1270 |
\nprt@printdigit{#1}% |
| 1271 |
\edef\nprt@tmp{#2}% |
| 1272 |
\else |
| 1273 |
\edef\nprt@tmp{#1#2}% |
| 1274 |
\fi |
| 1275 |
\ifnum\thenprt@digitsfirstblock=1 |
| 1276 |
\ifnum\thenprt@digitsbeforedecimal=4 |
| 1277 |
\if@numsepfour |
| 1278 |
\expandafter\nprt@one\nprt@tmp\@empty\@empty\@empty |
| 1279 |
\else |
| 1280 |
\ifnum\thenprt@digitsafterdecimal<5 |
| 1281 |
\nprt@tmp\ignorespaces |
| 1282 |
\else |
| 1283 |
\expandafter\nprt@one\nprt@tmp\@empty\@empty\@empty |
| 1284 |
\fi |
| 1285 |
\fi |
| 1286 |
\else |
| 1287 |
\expandafter\nprt@one\nprt@tmp\@empty\@empty\@empty |
| 1288 |
\fi |
| 1289 |
\fi |
| 1290 |
\ifnum\thenprt@digitsfirstblock=2 |
| 1291 |
\expandafter\nprt@two\nprt@tmp\@empty\@empty\@empty |
| 1292 |
\fi |
| 1293 |
\ifnum\thenprt@digitsfirstblock=0 |
| 1294 |
\expandafter\nprt@three\nprt@tmp\@empty\@empty\@empty\@empty |
| 1295 |
\fi |
| 1296 |
% \end{macrocode} |
| 1297 |
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}% |
| 1298 |
% Close the block if necessary. |
| 1299 |
% \begin{macrocode} |
| 1300 |
\ifnprt@blockexp |
| 1301 |
\ifnprt@exponent |
| 1302 |
\ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs) |
| 1303 |
}% |
| 1304 |
\fi |
| 1305 |
\fi |
| 1306 |
\ifnprt@block |
| 1307 |
\ifnprt@exponent |
| 1308 |
\else |
| 1309 |
\ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs) |
| 1310 |
}% |
| 1311 |
\fi |
| 1312 |
\fi |
| 1313 |
} |
| 1314 |
% \end{macrocode} |
| 1315 |
% \end{macro} |
| 1316 |
% \begin{macro}{aftercomma} |
| 1317 |
% Print the digits after the decimal sign. |
| 1318 |
% \begin{macrocode} |
| 1319 |
\newcommand{\aftercomma}[1]{% |
| 1320 |
% \end{macrocode} |
| 1321 |
% Count number of digits. |
| 1322 |
% \begin{macrocode} |
| 1323 |
% \expandafter\nprt@count\expandafter{#1}% |
| 1324 |
% \end{macrocode} |
| 1325 |
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}% |
| 1326 |
% If the number should be printed aligned generate a block with the |
| 1327 |
% correct size. |
| 1328 |
% \begin{macrocode} |
| 1329 |
\ifnprt@block |
| 1330 |
\ifnprt@exponent |
| 1331 |
\else |
| 1332 |
\settowidth{\nprt@digitwidth}{1}% |
| 1333 |
\settowidth{\nprt@sepwidth}{\nprt@thousand}% |
| 1334 |
\setcounter{nprt@digitcount}{\nprt@blockafter}% |
| 1335 |
\setcounter{nprt@sepcount}{(\nprt@blockafter-1)/3}% |
| 1336 |
\setlength{\nprt@blockwidth}{% |
| 1337 |
\arabic{nprt@digitcount}\nprt@digitwidth+% |
| 1338 |
\arabic{nprt@sepcount}\nprt@sepwidth}% |
| 1339 |
% \end{macrocode} |
| 1340 |
% If block length is four digits and fourth digit is not to be |
| 1341 |
% separated adjust new width. |
| 1342 |
% \begin{macrocode} |
| 1343 |
\if@numsepfour |
| 1344 |
\else |
| 1345 |
\ifnum\nprt@blockafter=4 |
| 1346 |
\ifnum\nprt@blockbefore<5 |
| 1347 |
\setlength{\nprt@blockwidth}{4\nprt@digitwidth}% |
| 1348 |
\fi |
| 1349 |
\fi |
| 1350 |
\fi |
| 1351 |
\ifmmode\nprt@inmathtrue\fi |
| 1352 |
\makebox[\nprt@blockwidth][l]{% |
| 1353 |
\ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs) |
| 1354 |
\fi |
| 1355 |
\fi |
| 1356 |
% \end{macrocode} |
| 1357 |
% If a zero after the decimal sign is replaced, don't test on 4 digits |
| 1358 |
% after comma. |
| 1359 |
% Therefor, set |nprt@digitsafterdecimalsign| to zero. |
| 1360 |
% \begin{macrocode} |
| 1361 |
\ifx\nprt@replacenull\@empty |
| 1362 |
\else |
| 1363 |
\ifnum#1=0 |
| 1364 |
\setcounter{nprt@digitsafterdecimal}{0}% |
| 1365 |
\fi |
| 1366 |
\fi |
| 1367 |
% \end{macrocode} |
| 1368 |
% Print the number itself. |
| 1369 |
% \begin{macrocode} |
| 1370 |
\ifnum\thenprt@digitsafterdecimal=4 |
| 1371 |
\if@numsepfour |
| 1372 |
\expandafter\nprt@threeafter#1\@empty\@empty\@empty |
| 1373 |
\else |
| 1374 |
\ifnum\thenprt@digitsbeforedecimal<5 |
| 1375 |
#1\ignorespaces |
| 1376 |
\else |
| 1377 |
\expandafter\nprt@threeafter#1\@empty\@empty\@empty |
| 1378 |
\fi |
| 1379 |
\fi |
| 1380 |
\else |
| 1381 |
% \end{macrocode} |
| 1382 |
% Replace the zero after the comma by \cs{nprt@replacenull} if this is |
| 1383 |
% wanted. |
| 1384 |
% Otherwise, print the digits. |
| 1385 |
% \begin{macrocode} |
| 1386 |
\ifx\nprt@replacenull\@empty |
| 1387 |
\expandafter\nprt@threeafter#1\@empty\@empty\@empty |
| 1388 |
\else |
| 1389 |
\ifnum#1=0 |
| 1390 |
\nprt@replacenull |
| 1391 |
\else |
| 1392 |
\expandafter\nprt@threeafter#1\@empty\@empty\@empty |
| 1393 |
\fi |
| 1394 |
\fi |
| 1395 |
\fi |
| 1396 |
% \end{macrocode} |
| 1397 |
% \changes{0.05}{2001/03/12}{Added basic support for aligned tabular entries}% |
| 1398 |
% Close the block if necessary. |
| 1399 |
% \begin{macrocode} |
| 1400 |
\ifnprt@block |
| 1401 |
\ifnprt@exponent |
| 1402 |
\else |
| 1403 |
\ifnprt@inmath$\fi %$ (only for syntax highlighing in emacs) |
| 1404 |
}% |
| 1405 |
\fi |
| 1406 |
\fi |
| 1407 |
} |
| 1408 |
% \end{macrocode} |
| 1409 |
% \end{macro} |
| 1410 |
% New counter which shows the digit position for finding the digit |
| 1411 |
% where to round. |
| 1412 |
% \begin{macrocode} |
| 1413 |
\newcounter{nprt@position} |
| 1414 |
% \end{macrocode} |
| 1415 |
% Boolean that shows if a 9 has been rounded to 0. |
| 1416 |
% \begin{macrocode} |
| 1417 |
\newif\if@@roundup |
| 1418 |
% \end{macrocode} |
| 1419 |
% Current digit to be able to add 1 to it. |
| 1420 |
% \begin{macrocode} |
| 1421 |
\newcounter{nprt@thisdigit} |
| 1422 |
% \end{macrocode} |
| 1423 |
% \begin{macro}{\nprt@roundaftercomma} |
| 1424 |
% Command that rounds at the argument |#1#2| at the digit |
| 1425 |
% \cs{nprt@rounddigits}. |
| 1426 |
% This routine calls itself recursively. |
| 1427 |
% \begin{macrocode} |
| 1428 |
\def\nprt@roundaftercomma#1#2\empty{% |
| 1429 |
\addtocounter{nprt@position}{1}% |
| 1430 |
\edef\zwei{#2}% |
| 1431 |
\ifx\zwei\empty |
| 1432 |
\else |
| 1433 |
\expandafter\ifnum\thenprt@position<\nprt@rounddigits |
| 1434 |
\nprt@roundaftercomma#2\empty |
| 1435 |
\else |
| 1436 |
\nprt@roundup#2\empty |
| 1437 |
\fi |
| 1438 |
\fi |
| 1439 |
\setcounter{nprt@thisdigit}{#1}% |
| 1440 |
\if@@roundup |
| 1441 |
\addtocounter{nprt@thisdigit}{1}% |
| 1442 |
\ifnum\thenprt@thisdigit>9 |
| 1443 |
\@@rounduptrue |
| 1444 |
\setcounter{nprt@thisdigit}{0}% |
| 1445 |
\else |
| 1446 |
\@@roundupfalse |
| 1447 |
\fi |
| 1448 |
\fi |
| 1449 |
\expandafter\xdef\expandafter\nprt@charsaftercomma{% |
| 1450 |
\thenprt@thisdigit\nprt@charsaftercomma}% |
| 1451 |
\addtocounter{nprt@position}{-1}% |
| 1452 |
} |
| 1453 |
% \end{macrocode} |
| 1454 |
% \end{macro} |
| 1455 |
% \begin{macro}{\nprt@roundup} |
| 1456 |
% \begin{macrocode} |
| 1457 |
\def\nprt@roundup#1#2\empty{% |
| 1458 |
\ifnum#1>4 |
| 1459 |
\@@rounduptrue |
| 1460 |
\else |
| 1461 |
\@@roundupfalse |
| 1462 |
\fi |
| 1463 |
} |
| 1464 |
% \end{macrocode} |
| 1465 |
% \end{macro} |
| 1466 |
% \begin{macro}{\nprt@roundbeforecomma} |
| 1467 |
% \begin{macrocode} |
| 1468 |
\def\nprt@roundbeforecomma#1#2\empty{% |
| 1469 |
\edef\zwei{#2}% |
| 1470 |
\ifx\zwei\empty |
| 1471 |
\else |
| 1472 |
\nprt@roundbeforecomma#2\empty |
| 1473 |
\fi |
| 1474 |
\edef\eins{#1}% |
| 1475 |
% \ifx\eins\nprt@minus@test |
| 1476 |
% \expandafter\xdef\expandafter\nprt@charsbeforecomma{% |
| 1477 |
% #1\nprt@charsbeforecomma}% |
| 1478 |
% \else |
| 1479 |
% \setcounter{nprt@thisdigit}{#1}% |
| 1480 |
% \if@@roundup |
| 1481 |
% \addtocounter{nprt@thisdigit}{1}% |
| 1482 |
% \ifnum\thenprt@thisdigit>9 |
| 1483 |
% \@@rounduptrue |
| 1484 |
% \setcounter{nprt@thisdigit}{0}% |
| 1485 |
% \else |
| 1486 |
% \@@roundupfalse |
| 1487 |
% \fi |
| 1488 |
% \fi |
| 1489 |
\ifnum-9>-1#1 |
| 1490 |
\setcounter{nprt@thisdigit}{#1}% |
| 1491 |
\if@@roundup |
| 1492 |
\addtocounter{nprt@thisdigit}{1}% |
| 1493 |
\ifnum\thenprt@thisdigit>9 |
| 1494 |
\@@rounduptrue |
| 1495 |
\setcounter{nprt@thisdigit}{0}% |
| 1496 |
\else |
| 1497 |
\@@roundupfalse |
| 1498 |
\fi |
| 1499 |
\fi |
| 1500 |
\expandafter\xdef\expandafter\nprt@charsbeforecomma{% |
| 1501 |
\thenprt@thisdigit\nprt@charsbeforecomma}% |
| 1502 |
\else |
| 1503 |
\if@@roundup |
| 1504 |
\expandafter\xdef\expandafter\nprt@charsbeforecomma{% |
| 1505 |
1\nprt@charsbeforecomma}% |
| 1506 |
\@@roundupfalse |
| 1507 |
\fi |
| 1508 |
\expandafter\xdef\expandafter\nprt@charsbeforecomma{% |
| 1509 |
#1\nprt@charsbeforecomma}% |
| 1510 |
\fi |
| 1511 |
} |
| 1512 |
% \end{macrocode} |
| 1513 |
% \end{macro} |
| 1514 |
% |
| 1515 |
% Define two new column types. |
| 1516 |
% |
| 1517 |
% The column type \verb|n| aligns the base number but not the exponent. |
| 1518 |
% \begin{macrocode} |
| 1519 |
\newcolumntype{n}[2]{>{\digits{#1}{#2}$}l<{$\nodigits}} |
| 1520 |
% \end{macrocode} |
| 1521 |
% Define two new column types. |
| 1522 |
% |
| 1523 |
% The column type \verb|n| aligns the base number as well as the exponent. |
| 1524 |
% \begin{macrocode} |
| 1525 |
\newcolumntype{N}[3]{% |
| 1526 |
>{\digits{#1}{#2}\exponentdigits{#3}$}l<{$\nodigits\noexponentdigits}} |
| 1527 |
% \end{macrocode} |
| 1528 |
% \iffalse |
| 1529 |
%</package> |
| 1530 |
% \fi |
| 1531 |
% \Finale |
| 1532 |
|