summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/numprint/nbaseprt.dtx
blob: f8119ad2089ac7ccc058d74efea2290959f62c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
% \iffalse meta comment
% File: nbaseprt.dtx Copyright (C) 2004 Harald Harders
% \fi
%
% \iffalse
%
%<*driver>
\listfiles
\documentclass[ngerman,english,a4paper]{ltxdoc}
\usepackage[T1]{fontenc}
\IfFileExists{nbaseprt.sty}{%
  \usepackage{nbaseprt}
}{%
  \GenericWarning{nbaseprt.dtx}{Package file nbaseprt.sty not found
    (Documentation will be messed up!^^J^^A 
    Generate nbaseprt.sty by (La)TeXing numprint.ins, process
    nbaseprt.dtx again)^^J}\stop
}
\IfFileExists{eco.sty}{%
  \usepackage{eco}
  \renewcommand*\ttdefault{cmtt}
}{%
  \GenericWarning{nbaseprt.dtx}{Package file eco.sty not found
    (Documentation will be less clear than possible)}
}
\usepackage{longtable}
\usepackage{mathcomp}
\usepackage{babel}
\usepackage{url}
\usepackage{color}
\IfFileExists{booktabs.sty}{\usepackage{booktabs}}{%
  \GenericWarning{nbaseprt.dtx}{Package file booktabs.sty not
    found. Documentation formatting will be poor}%
  \def\toprule\hline
  \def\midrule\hline
  \def\bottomrule\hline}
\GetFileInfo{nbaseprt.sty}
\title{The nbaseprt package}
\author{Harald Harders\\\texttt{harald.harders@gmx.de}}
\date{Version \fileversion, \filedate; printed \today}
\newlength{\tempdima}%
\makeatletter
\renewenvironment{table}[1][]{%
  \@float{table}[#1]%
  \centering%
  \setlength{\tempdima}{\abovecaptionskip}%
  \setlength{\abovecaptionskip}{\belowcaptionskip}%
  \setlength{\belowcaptionskip}{\tempdima}%
  }{%
\end@float
}
\def\meta@font@select{\normalfont\itshape}
\makeatother
%%
\EnableCrossrefs
\CodelineIndex
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter}
\DoNotIndex{\setcounter,\space,\if,\else,\fi,\empty,\@empty,\ifx,\fi}
\DoNotIndex{\ifnum,\fi,\expandafter,\csname,\endcsname,\the}
\DoNotIndex{\MessageBreak,\message,\newlength,\newif,\xdef,\newcount}
\DoNotIndex{\begingroup,\endgroup,\,,\@tempcnta,\@tempdima,\advance}
\DoNotIndex{\ensuremath,\filedate,\fileversion,\docdate}
\DoNotIndex{\mathit,\mathrm,\mathsf,\nprt@tmp,\nprt@tmpnum,\relax}
\DoNotIndex{\protect,\renewcommand,\setlength,\settowidth,\stepcounter}
\DoNotIndex{\string}
\CodelineNumbered
\RecordChanges
\CheckSum{343}
\begin{document}
 \DocInput{nbaseprt.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{0.11}{2004/12/14}{Usage of \texttt{eco.sty} in
%   \texttt{nbaseprttest.tex} only if available}%
% \changes{0.10}{2004/08/08}{Total new implementation}%
%
% \maketitle
% \begin{abstract}
% \noindent
% This package prints integer numbers in different bases (octal,
% decimal, hexadecimal, binary) similarly to the |numprint| package.
% But here, the number of digits within one group depends on the
% base.
% 
% \textbf{This version of |nbaseprt.sty| is a BETA VERSION.
% The main command \cs{nbaseprint} will stay stable but
% all configuration commands and the output of
% \cs{nbaseprint} may change in future.
% Please give me feedback what can be improved and if the
% abbreviations for the different number bases are correct.}
% \end{abstract}
%
% \tableofcontents
%
% \section*{Copyright}
% Copyright 2004 Harald Harders.
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.
%
%
% \section{Load the package}
%
% To use this package place
% \begin{verbatim}
%\usepackage{nbaseprt}\end{verbatim}
% in the preamble of your document.
% The |nbaseprt| package calls the |numprint| package and parses all
% package options to it.
% Please read the documentation for the |numprint| package for
% details.
% If you want to use both the |numprint| and the |nbaseprt| package
% either load |numprint| first given all options, e.g.,
% \begin{verbatim}
%\usepackage[autolanguage,nosepfour]{numprint}
%\usepackage{nbaseprt}\end{verbatim}
% or only load the |nbaseprt| package, giving it the options for
% |numprint|:
% \begin{verbatim}
%\usepackage[autolanguage,nosepfour]{nbaseprt}\end{verbatim}
%
%
% \section{Print numbers}
%
% \DescribeMacro{\nbaseprint}%
% Numbers are printed using the \cs{nbaseprint\marg{number}} command.
% Which number base is used is determined by parsing the
% \meta{number}.
%
% The type can be given by preceding the number by ``|0x|'', ``|0o|'',
% ``|0d|'', or ``|0b|'' (or the uppercase characters) for hexadecimal,
% octal, decimal, or binary numbers, respectively.
% For example,
% \begin{verbatim}
%$\nbaseprint{0x1A0E3F}$, $\nbaseprint{0o377377}$,
%$\nbaseprint{0d192314}$, $\nbaseprint{0b11010110}$\end{verbatim}
%
% Alternatively, hexadecimal and octal numbers can be given by
% appending ``h'', ``H'', ``o'', or ``O'':
% \begin{verbatim}
%$\nbaseprint{1A0E3Fh}$, $\nbaseprint{377377o}$\end{verbatim}
%
% If neither is given, the number defaults to decimal.
%
% The format of the printed numbers is similar to the possible input
% formats.
% By default, the numbers are preceded by ``|0x|'', ``|0o|'',
% ``|0d|'', or ``|0b|'', e.g.
%
% \begin{quotation}
%   $\nbaseprint{0x1A0E3F}$, $\nbaseprint{0o377377}$,
%   $\nbaseprint{0d192314}$, $\nbaseprint{0b11010110}$
% \end{quotation}
%
% \DescribeMacro{\nbaseposttext}%
% You can change this by using \cs{nbaseposttext}.
% This leads to 
% \begin{quotation}
%   \nbaseposttext
%   $\nbaseprint{0x1A0E3F}$, $\nbaseprint{0o377377}$,
%   $\nbaseprint{0d192314}$, $\nbaseprint{0b11010110}$
% \end{quotation}
%
% \DescribeMacro{\nbasepretext}%
% You can switch back to the default behaviour using \cs{nbasepretext}
% or by using \cs{nbaseposttext} inside a group.
%
%
% If you want to print negative numbers the sign may be written before
% or after ``|0x|'', ``|0o|'', ``|0d|'', or ``|0b|''.
% Some examples:
% \begin{verbatim}
%$\nbaseprint{-0x1A0E3F}$, $\nbaseprint{0o-377377}$,
%$\nbaseprint{0d+-192314}$, $\nbaseprint{0b\pm 11010110}$\end{verbatim}
% which lead to
% \begin{quotation}
% $\nbaseprint{-0x1A0E3F}$, $\nbaseprint{0o-377377}$,
% $\nbaseprint{0d+-192314}$, $\nbaseprint{0b\pm 11010110}$
% \end{quotation}
% In the printout, the sign always is written after the base-specific
% string. (is this correct?)
%
%
% \section{Customization}
%
% \subsection{Padding a number on the left side}%
% 
% \DescribeMacro{\nplpadding}%
% \DescribeMacro{\npnolpadding}%
% Sometimes it is desireable to have a number of a fixed length with
% the missing digits filled with a character (mostly the character
% ``0'', so this is the default).
% This can be achieved calling
% \cs{nplpadding\oarg{character}\marg{digits}} borrowed from the
% |numprint| package.
% For example,
% \begin{verbatim}
%\nplpadding{6}%
%$\nbaseprint{0xA03E}$, $\nbaseprint{0o1234}$\end{verbatim}
% leads to \begingroup
% ``\nplpadding{6}$\nbaseprint{0xA03E}$, $\nbaseprint{0o1234}$''
% \endgroup
% 
% \cs{npnolpadding} switches padding off.
%
%
% \section{International support}%
% \label{sec:international}%
%
% |nbaseprt| uses the thousand separator from |numprint|.
% Since this package uses the German ``\cs{,}'' by default |nbaseprt|
% does this, too.
% Using the package option |autolanguage| this can be fixed.
% If you are using this option without the |babel| package the
% settings are switched to English at \cs{begin\{document\}}:
% separator ``\texttt{,}''.
% If using |babel| the separator is changed automatically when
% switching to a supported language.
%
% If you do not want to use the |autolanguage| option you may use the
% |numprint| command \cs{npthousandsep} command to change the
% separator.
%
%
% \section{Print aligned numbers in tabulars}%
% \label{sec:tabular}%
%
% Sorry, not programmed, yet.
%
%
%
% \appendix
%
% \section{Lists of options and commands}
%
% This section contains lists of all package options resp.\ available
% commands. 
% Items that belong together and may be exclusive are printed in
% groups together.
%
% \subsection{Package options}%
% \label{sec:package-options}%
%
% |nbaseprt| supports all options of the |numprint| package.
% In this list, only the ones that are new or have a different meaning
% are listed.
%
% \begingroup
% \newcommand*\default{$^{*}$}%
% The default values are marked by \default.
% \begin{longtable}[l]{%
%     @{}>{\ttfamily}p{0.30\linewidth}@{}p{0.70\linewidth}@{}}
%   np& Define the shortcuts \cs{np} for \cs{numprint} and \cs{nbp}
%   for \cs{nbaseprint}.
% \end{longtable}
% \endgroup
%
% \subsection{Commands}
%
% Commands that begin with \cs{np} are borrowed from |numprint|.
% Here, the new commands and |numprint| commands that have a special
% meaning for |nbaseprt| are listed here.
%
% \begin{longtable}[l]{%
%     @{}>{\ttfamily \char`\\}p{0.3\linewidth}@{}p{0.7\linewidth}@{}}
%   npaddplus& Add a plus to a number without a sign.\\
%   npnoaddplus& Don't do that.\\[\medskipamount]
%   nbp& Shortcut for \cs{nbaseprint} (only available with package
%   option~\texttt{np}).\\
%   nbaseprint& Typesets a number (the package's main
%   command).\\[\medskipamount]
%   npthousandsep& Change the separator between the digit
%   groups.\\[\medskipamount]
%   nplpadding& Declare up to how many digits the number will be padded at
%   the lefthand side. \\
%   npnolpadding& Switch off padding. \\[\medskipamount]
%   nbaserpretext& Switches on to precede the number by ``0x'',
%   ``0o'', or ``0d''. \\
%   nbaserposttext& Switches on to append ``h'', ``o'', or nothing to
%   the number.
% \end{longtable}
%
%
% \section{To do}
%
% \begin{itemize}
% \item Add table support.
% \item Better customization for the pre and the post text.
% \item Parse the argument for invalid numbers.
% \item Proof output format of numbers.
% \end{itemize}
%
%
% \StopEventually{\PrintChanges \PrintIndex}
%
% \section{The implementation}
% \iffalse
%<*package>
% \fi
% Heading of the package:
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{nbaseprt}
  [2004/12/14  v0.11  Print numbers with numerical bases (HH)]
%    \end{macrocode}
% Warning, that this is a beta version.
%    \begin{macrocode}
\typeout{^^J*************************************************************}
\PackageWarningNoLine{nbaseprt}{This version of nbaseprt.sty is a BETA
  VERSION.\MessageBreak
  The main command \string\nbaseprint\space will stay stable
  but\MessageBreak
  all configuration commands and the output of\MessageBreak
  \string\nbaseprint\space may change in future.\MessageBreak
  Please give me feedback what can be improved and if\MessageBreak
  the abbreviations for the different number bases are\MessageBreak
  correct}
\typeout{*************************************************************^^J}
%    \end{macrocode}
% Pass all unknown options to |numprint.sty| to avoid conflicts when
% loading |numprint| seperately.
%    \begin{macrocode}
\DeclareOption{np}{%
  \newcommand*\nbp{\nbaseprint}%
  \PassOptionsToPackage{np}{numprint}%
}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{numprint}}
\ProcessOptions\relax
%    \end{macrocode}
% Load package |numprint| because |nbaseprt| shares some commands with
% it.
%    \begin{macrocode}
\RequirePackage{numprint}
%    \end{macrocode}
% Easier if-then clauses.
%    \begin{macrocode}
\RequirePackage{ifthen}
%    \end{macrocode}
% Dummy definitions to get an error in case of incompatibility with
% other packages.
%    \begin{macrocode}
\newcommand*\nbprt@base{}
\newcommand*\nbprt@number{}
%    \end{macrocode}
% \begin{macro}{\nbprt@testbase}
% Test which numeric base is used in the argument of \cs{nbaseprt}.
%    \begin{macrocode}
\newcommand*\nbprt@testbase{}
\def\nbprt@testbase#1#2#3\@empty{%
%    \end{macrocode}
% Test if number begins with ``|0x|'', ``|0X|'', or ``|"|'' which all mean
% that it is given as hexadecimal number.
%    \begin{macrocode}
  \ifthenelse{\equal{#1#2}{0x}\or\equal{#1#2}{0X}\or\equal{#1}{"}}{%
    \gdef\nbprt@base{hex}%
%    \end{macrocode}
% Store the rest of the argument as number in \cs{nbprt@number}.
%    \begin{macrocode}
    \ifthenelse{\equal{#1}{"}}{%
      \edef\nbprt@number{#2#3}%
    }{%
      \edef\nbprt@number{#3}%
    }%
  }{%
%    \end{macrocode}
% Test if number begins with ``|0o|'', ``|0O|'', or ``|'|'' which all
% mean that it is given as octal number.
%    \begin{macrocode}
    \ifthenelse{\equal{#1#2}{0o}\or\equal{#1#2}{0O}\or\equal{#1}{'}}{%
      \gdef\nbprt@base{oct}%
%    \end{macrocode}
% Store the rest of the argument as number in \cs{nbprt@number}.
%    \begin{macrocode}
      \ifthenelse{\equal{#1}{'}}{%
        \edef\nbprt@number{#2#3}%
      }{%
        \edef\nbprt@number{#3}%
      }%
    }{%
%    \end{macrocode}
% Test if number begins with ``|0d|'' or ``|0D|'' which means that it
% is given as decimal number.
%    \begin{macrocode}
      \ifthenelse{\equal{#1#2}{0d}\or\equal{#1#2}{0D}}{%
        \gdef\nbprt@base{dec}%
%    \end{macrocode}
% Store the rest of the argument as number in \cs{nbprt@number}.
%    \begin{macrocode}
        \edef\nbprt@number{#3}%
      }{%
%    \end{macrocode}
% Test if number begins with ``|0b|'' or ``|0B|'' which means that it
% is given as decimal number.
%    \begin{macrocode}
        \ifthenelse{\equal{#1#2}{0b}\or\equal{#1#2}{0B}}{%
          \gdef\nbprt@base{bin}%
%    \end{macrocode}
% Store the rest of the argument as number in \cs{nbprt@number}.
%    \begin{macrocode}
          \edef\nbprt@number{#3}%
        }{%
%    \end{macrocode}
% If none of the above is the case the number defaults to decimal.
%    \begin{macrocode}
          \def\nbprt@base{dec}%
          \edef\nbprt@number{#1#2#3}%
%    \end{macrocode}
% But there are also other possibilities to mark the number as
% hexadecimal or octal, by appending ``|h|'', ``|H|'', ``|o|'', or
% ``|O|''.
% These tests are performed by seperate macros.
%    \begin{macrocode}
          \nbprt@ishex#1#2#3h\@empty\@empty
          \nbprt@isHex#1#2#3H\@empty\@empty
          \nbprt@isoct#1#2#3o\@empty\@empty
          \nbprt@isOct#1#2#3O\@empty\@empty
        }%
      }%
    }%
  }%
%    \end{macrocode}
% Test for a sign before the number.
%    \begin{macrocode}
  \expandafter\nbprt@testsign\nbprt@number\@empty\@empty\@empty
%    \end{macrocode}
% Reset \cs{nbprt@string} that holds the number in formatted form.
%    \begin{macrocode}
  \def\nbprt@string{}%
%    \end{macrocode}
% Reset the counters that help formatting the number.
%    \begin{macrocode}
  \@tempcnta=0
  \@tempcntb=0
%    \end{macrocode}
% Parse the number, done by \cs{nbprt@parsenum}.
%    \begin{macrocode}
  \expandafter\nbprt@parsenum\nbprt@number\@empty
%    \end{macrocode}
% If left padding is switched on, add the leading characters to gain
% the specified length.
% See \cs{nbprt@parsenum} for explanation of the algorithm.
%    \begin{macrocode}
  \whiledo{\the\@tempcntb<\nprt@lpaddigits}{%
    \ifnum\@tempcnta=\csname nbprt@digitgroup@\nbprt@base\endcsname\relax
      \edef\nbprt@string{\nprt@separator@before\nbprt@string}%
      \@tempcnta=0
    \fi
    \edef\nbprt@string{\nprt@lpadchar\nbprt@string}%
    \advance\@tempcntb 1
    \advance\@tempcnta 1
  }%
%    \end{macrocode}
% Print the text that marks the base of the number before the number
% itself.
%    \begin{macrocode}
  \ifnbprt@pretext
    \csname nbprt@pretext@\nbprt@base\endcsname
    \nbprt@presep
  \fi
%    \end{macrocode}
% Print the sign (use routine of |numprint|).
%    \begin{macrocode}
  \nprt@printsign{mantissa}\nbprt@sign\@empty
%    \end{macrocode}
% Print the modified number with separators.
%    \begin{macrocode}
  \nbprt@string
%    \end{macrocode}
% Print the text that marks the base of the number after the number
% itself.
%    \begin{macrocode}
  \ifnbprt@pretext
  \else
    \nbprt@postsep
    \csname nbprt@posttext@\nbprt@base\endcsname
  \fi
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nbprt@testsign}
%    \begin{macrocode}
\def\nbprt@testsign#1#2#3\@empty{%
%  ``#1'', ``#2'', ``#3'':
  \nprt@IfCharInString{#1}{\nprt@signlist}{%
    \edef\nbprt@number{#2#3}%
    \edef\nbprt@sign{#1}%
    \ifx\nbprt@sign\nprt@plus@test
      \def\nprt@tmp{#2}%
      \ifx\nprt@tmp\nprt@minus@test
        \edef\nbprt@sign{+-}%
        \edef\nbprt@number{#3}%
      \fi
    \else
      \ifx\nbprt@sign\nprt@plusminus@test
        \edef\nbprt@sign{+-}%
      \fi
    \fi
  }{%
    \edef\nbprt@number{#1#2#3}%
  }%
}
%    \end{macrocode}
% \end{macro}
% Test if the number is marked as hexadecimal by appending an ``|h|''.
%    \begin{macrocode}
\def\nbprt@ishex#1h#2\@empty{%
%    \end{macrocode}
% If |#2| is |h|, the number has ended with an |h| because this macro
% has been called with an appended |h| in addition to the |h| that is
% the last character of the number.
%    \begin{macrocode}
  \ifthenelse{\equal{#2}{h}}{%
%    \end{macrocode}
% Set the base and redefine the number.
%    \begin{macrocode}
    \def\nbprt@base{hex}%
    \edef\nbprt@number{#1}%
  }{}%
}    
%    \end{macrocode}
% Test if the number is marked as hexadecimal by appending an ``|H|''.
%    \begin{macrocode}
\def\nbprt@isHex#1H#2\@empty{%
  \ifthenelse{\equal{#2}{H}}{%
    \def\nbprt@base{hex}%
    \edef\nbprt@number{#1}%
  }{}%
}    
%    \end{macrocode}
% Test if the number is marked as octal by appending an ``|o|'' or an
% ''|O|''.
%    \begin{macrocode}
\def\nbprt@isoct#1o#2\@empty{%
  \ifthenelse{\equal{#2}{o}}{%
    \def\nbprt@base{oct}%
    \edef\nbprt@number{#1}%
  }{}%
}    
\def\nbprt@isOct#1O#2\@empty{%
  \ifthenelse{\equal{#2}{O}}{%
    \def\nbprt@base{oct}%
    \edef\nbprt@number{#1}%
  }{}%
}    
%    \end{macrocode}
% \begin{macro}{\nbprt@parsenum}
% Parses the given number and generates the formatted string in
% \cs{nbprt@string}, working recursively.
% |#1| is the first character in the left number, |#2| is the rest.
%    \begin{macrocode}
\def\nbprt@parsenum#1#2\@empty{%
%    \end{macrocode}
% If |#2| is not \cs{@empty} call \cs{nbprt@parsenum} recursively to
% parse the number backwards.
%    \begin{macrocode}
  \ifthenelse{\equal{#2}{\@empty}}{}{%
    \expandafter\nbprt@parsenum#2\@empty
  }%
%    \end{macrocode}
% Test if \cs{@tempcnta} has reached the number of digits that are
% printed as group for the given number base (stored in
% \cs{nbprt@digitgroup@}\meta{\cs{nbprt@base}}).
%    \begin{macrocode}
  \ifnum\@tempcnta=\csname nbprt@digitgroup@\nbprt@base\endcsname\relax
%    \end{macrocode}
% Precede the formatted number by the separator
% \cs{nprt@separator@before}, taken from |numprint.sty|.
%    \begin{macrocode}
    \edef\nbprt@string{\nprt@separator@before\nbprt@string}%
%    \end{macrocode}
% Reset the number of handled characters in this group.
%    \begin{macrocode}
    \@tempcnta=0
  \fi
%    \end{macrocode}
% Precede the formatted number by the current character while forcing
% uppercase hexadecimal numbers.
%    \begin{macrocode}
  \edef\nbprt@string{%
    \uppercase{\ifmmode\mathrm{#1}\else#1\fi}%
    \nbprt@string}%
%    \end{macrocode}
% Count this digit for the current group (\cs{@tempcnta}) and for the
% total number of digits (\cs{@tempcntb}).
%    \begin{macrocode}
  \advance\@tempcntb 1
  \advance\@tempcnta 1
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nbasepretext}
% Provide a command that switches to marking the numbers before the
% number itself.
%    \begin{macrocode}
\newif\ifnbprt@pretext
\newcommand*\nbasepretext{\nbprt@pretexttrue}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\nbaseposttext}
% Provide a command that switches to marking the numbers after the
% number itself.
%    \begin{macrocode}
\newcommand*\nbaseposttext{\nbprt@pretextfalse}
%    \end{macrocode}
% \end{macro}
% Provide the commands that print the text before or after the number.
%    \begin{macrocode}
\def\nbprt@pretext@hex{0\ifmmode\mathrm{x}\else x\fi}%
\def\nbprt@pretext@oct{0\ifmmode\mathrm{o}\else o\fi}%
\def\nbprt@pretext@dec{0\ifmmode\mathrm{d}\else d\fi}%
\def\nbprt@pretext@bin{0\ifmmode\mathrm{b}\else b\fi}%
\def\nbprt@presep{\,}%
\def\nbprt@posttext@hex{\ifmmode\mathrm{h}\else h\fi}%
\def\nbprt@posttext@oct{\ifmmode\mathrm{o}\else o\fi}%
\def\nbprt@posttext@dec{\ifmmode\mathrm{d}\else d\fi}%
\def\nbprt@posttext@bin{\ifmmode\mathrm{b}\else b\fi}%
\def\nbprt@postsep{\,}%
%    \end{macrocode}
% By default, use the marker before the number.
%    \begin{macrocode}
\nbasepretext
%    \end{macrocode}
% Define how many numbers are grouped together, depending on the
% number base.
%    \begin{macrocode}
\def\nbprt@digitgroup@hex{2}%
\def\nbprt@digitgroup@oct{3}%
\def\nbprt@digitgroup@dec{3}%
\def\nbprt@digitgroup@bin{4}%
%    \end{macrocode}
% \begin{macro}{\nbaseprint}
% Define the man command \cs{nbaseprint} which takes the printed
% number as mandatory argument.
%    \begin{macrocode}
\DeclareRobustCommand*\nbaseprint[1]{%
%    \end{macrocode}
% First, expand the number to allow to use macros in the argument.
%    \begin{macrocode}
  \edef\nbprt@number{#1}%
%    \end{macrocode}
% Test if the number begins with a sign.
%    \begin{macrocode}
  \def\nbprt@sign{}%
  \expandafter\nbprt@testsign\nbprt@number\@empty\@empty\@empty
%    \end{macrocode}
% Call \cs{nbprt@testbase} which tests for the number base and prints
% the number.
%    \begin{macrocode}
  \expandafter\nbprt@testbase\nbprt@number\@empty\@empty\@empty
}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</package>
% \fi
% \Finale