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