| 1 |
% |
| 2 |
% \iffalse |
| 3 |
% |
| 4 |
%% fancynum.dtx Copyright (C) J.J.Green 1999, 2000. |
| 5 |
%% $Id: fancynum.dtx,v 1.8 2000/08/08 22:28:38 jjg Exp $ |
| 6 |
%% |
| 7 |
%% This file is part of the fancynum package. |
| 8 |
%% |
| 9 |
%% It may be distributed under the terms of the LaTeX Project Public |
| 10 |
%% License, as described in lppl.txt in the base LaTeX distribution. |
| 11 |
%% Either version 1.0 or, at your option, any later version. |
| 12 |
%% |
| 13 |
%<*dtx> |
| 14 |
\ProvidesFile{fancynum.dtx} |
| 15 |
%</dtx> |
| 16 |
%<package>\NeedsTeXFormat{LaTeX2e}[1995/12/01] |
| 17 |
%<package>\ProvidesPackage{fancynum} |
| 18 |
%<driver> \ProvidesFile{fancynum.sty} |
| 19 |
% \fi |
| 20 |
% \ProvidesFile{fancynum.dtx} |
| 21 |
[2000/08/08 0.92 Fancynum package] |
| 22 |
% |
| 23 |
% \iffalse |
| 24 |
%<*driver> |
| 25 |
\documentclass{ltxdoc} |
| 26 |
\newenvironment{option}[1]{\expandafter\macro\expandafter{% |
| 27 |
\csname ds@#1\endcsname}}{\endmacro} |
| 28 |
\begin{document} |
| 29 |
\DocInput{fancynum.dtx} |
| 30 |
\end{document} |
| 31 |
%</driver> |
| 32 |
% \fi |
| 33 |
% |
| 34 |
% \CheckSum{0} |
| 35 |
% |
| 36 |
% \GetFileInfo{fancynum.dtx} |
| 37 |
% |
| 38 |
% \title{The \textsf{fancynum} package\thanks{This file |
| 39 |
% has version number \fileversion, last |
| 40 |
% revised \filedate.}} |
| 41 |
% \author{J. J. Green} |
| 42 |
% \date{\filedate} |
| 43 |
% \maketitle% |
| 44 |
% |
| 45 |
% \changes{0.5}{2000/04/01}{Beta release} |
| 46 |
% |
| 47 |
% \def\star{{\ttfamily*}} |
| 48 |
% \makeatletter |
| 49 |
% \def\Describe@Macro#1{\endgroup |
| 50 |
% \setbox0=\lastbox\llap{\PrintDescribeMacro{#1}}}% |
| 51 |
% \makeatother |
| 52 |
% \marginparsep0pt |
| 53 |
% |
| 54 |
% \section{Introduction} |
| 55 |
% |
| 56 |
% The fancynum package is designed to aid the typesetting of numbers, |
| 57 |
% particularly (but not exclusively) the ASCII representation of |
| 58 |
% floating point numbers as written by computers. |
| 59 |
% |
| 60 |
% In the sequel we refer to the glyph used to separate the |
| 61 |
% integer and decimal parts of a decimal number as the |
| 62 |
% \emph{decimal symbol}, and that used to group the |
| 63 |
% digits of the integer and decimal parts as the |
| 64 |
% \emph{group symbol}. |
| 65 |
% |
| 66 |
% The author invites suggestions on improvements to the package. |
| 67 |
% In particular, any information on the typographic conventions |
| 68 |
% for setting numbers in different languages would be most |
| 69 |
% welcome. |
| 70 |
% |
| 71 |
% \section{Usage} |
| 72 |
% |
| 73 |
% The fancynum package is quite standard in its usage. After |
| 74 |
% including the package in the preamble, |
| 75 |
% the macro |\fnum| is available in mathematics mode. A call to |
| 76 |
% |$\fnum{3.141593e+05}$| will be set as $3{\cdot}141{,}593\times10^{5}$, |
| 77 |
% and so on. Further examples can be found in the file |examples.tex| |
| 78 |
% included in the distribution. |
| 79 |
% |
| 80 |
% The operation of the |\fnum| macro can be modified with |
| 81 |
% the commands |\setfnumdsym|, |\setfnumgsym| and |\setfnummsym|, |
| 82 |
% which set the value of the decimal, group and multiplication |
| 83 |
% symbols, respectively. |
| 84 |
% |
| 85 |
%\section{Limitations} |
| 86 |
% |
| 87 |
% The |\fnum| has some limitations on the form of its |
| 88 |
% argument: |
| 89 |
% \begin{itemize} |
| 90 |
% \item A decimal must have at least one digit either |
| 91 |
% side of the decimal symbol; |
| 92 |
% \item The optional exponential symbol must be |e|; |
| 93 |
% \item If the exponent must have at least one digit. |
| 94 |
% \end{itemize} |
| 95 |
% Consequently the strings |.312e20|, |312.e20| |
| 96 |
% and |3.142E20| are not acceptable arguments. |
| 97 |
% I hope to remove these restrictions at some point. |
| 98 |
% |
| 99 |
% \section{Package Options} |
| 100 |
% The package supports a small number of options. The |
| 101 |
% locale-specific options set default values for all of |
| 102 |
% the typographic parameters. The \textbf{english} option |
| 103 |
% uses the centred dot as the decimal symbol and a comma |
| 104 |
% as the group symbol. |
| 105 |
% The \textbf{french} option uses the comma as the decimal |
| 106 |
% symbol and a lower dot as the group symbol. Compare |
| 107 |
% the English $3{\cdot}141{,}593$ against the French $3{,}141.593$. |
| 108 |
% If no local-specific option is specified then English will |
| 109 |
% be taken as the default. |
| 110 |
% |
| 111 |
% The remaining options give specific values over the |
| 112 |
% typographic parameters, and override the locale-specific |
| 113 |
% options. |
| 114 |
% |
| 115 |
% The \textbf{tight} and \textbf{loose} options specify |
| 116 |
% space around the $\times$ in the setting of numbers in |
| 117 |
% exponential form. Compare the loose $2.3\times 10^{3}$ with |
| 118 |
% the tight $2.3{\times}10^{3}$. This option is useful where space |
| 119 |
% is at a premium, or may be preferred for {\ae}sthetic reasons. |
| 120 |
% |
| 121 |
% The \textbf{commas}, \textbf{thinspaces} and \textbf{plain} options |
| 122 |
% specify the group symbol to be used, respectively |
| 123 |
% |{,}|, |\,| and |\relax|. |
| 124 |
% |
| 125 |
% \section{Thanks} |
| 126 |
% I am grateful to Heiko Oberdiek, Norman Gray, Michael Downes |
| 127 |
% and Donald Arseneau for their assistance on |comp.text.tex|, |
| 128 |
% and to Jerzy Kucharczyk for providing a bug report. |
| 129 |
% |
| 130 |
% \section{Implementation} |
| 131 |
% |
| 132 |
% \begin{macrocode} |
| 133 |
%<*package> |
| 134 |
% \end{macrocode} |
| 135 |
% |
| 136 |
% \subsection{Typographic parameters} |
| 137 |
% |
| 138 |
% The decimal, group and multiplication symbols are stored in the |
| 139 |
% global variables |\fn@decimalsym| etc. |
| 140 |
% The following macros give access to the values used in the package. |
| 141 |
% \begin{macrocode} |
| 142 |
\def\setfnumdsym#1{\gdef\fn@decimalsym{#1}} |
| 143 |
\def\setfnumgsym#1{\gdef\fn@groupsym{#1}} |
| 144 |
\def\setfnummsym#1{\gdef\fn@multsym{#1}} |
| 145 |
% \end{macrocode} |
| 146 |
% |
| 147 |
% \subsection{Package options} |
| 148 |
% |
| 149 |
% The package options are simply calls the macro for the appropriate |
| 150 |
% parameter. |
| 151 |
% \begin{macrocode} |
| 152 |
\DeclareOption{english}{\setfnumdsym{{\cdot}}\setfnumgsym{{,}}} |
| 153 |
\DeclareOption{french}{\setfnumdsym{{,}}\setfnumgsym{{.}}} |
| 154 |
\DeclareOption{tight}{\setfnummsym{{\times}}} |
| 155 |
\DeclareOption{loose}{\setfnummsym{\times}} |
| 156 |
\DeclareOption{commas}{\setfnumgsym{{,}}} |
| 157 |
\DeclareOption{thinspaces}{\setfnumgsym{\,}} |
| 158 |
\DeclareOption{plain}{\setfnumgsym{\relax}} |
| 159 |
% \end{macrocode} |
| 160 |
% We set the default values before processing the options |
| 161 |
% \begin{macrocode} |
| 162 |
\ExecuteOptions{english,loose} |
| 163 |
\ProcessOptions\relax |
| 164 |
% \end{macrocode} |
| 165 |
% |
| 166 |
% \subsection{Utility macros} |
| 167 |
% |
| 168 |
% \begin{macro}{\fn@length} |
| 169 |
% Find the length of a string mod 3 (taken directly |
| 170 |
% from the example on p.~219 of the \TeX{}book). Here |
| 171 |
% though, a call to |\fn@length| assigns the calculated |
| 172 |
% value the (global) variable |\fn@strlen|. |
| 173 |
% \begin{macrocode} |
| 174 |
\newcount\fn@strlen |
| 175 |
\def\fn@length#1{\fn@strlen=0 \fn@getlength#1\end} |
| 176 |
\def\fn@getlength#1{\ifx #1\end \let\next=\relax \else |
| 177 |
\advance\fn@strlen by1 |
| 178 |
\ifnum\fn@strlen=3 \fn@strlen=0 \fi |
| 179 |
\let\next=\fn@getlength\fi \next} |
| 180 |
% \end{macrocode} |
| 181 |
% \end{macro} |
| 182 |
% |
| 183 |
% \subsection{Typesetting} |
| 184 |
% |
| 185 |
% \subsubsection{The decimal} |
| 186 |
% |
| 187 |
% \begin{macro}{\fn@fracpunct} |
| 188 |
% Punctuate the fractional part of a decimal. An |
| 189 |
% easy cyclic recursion. |
| 190 |
% \begin{macrocode} |
| 191 |
\def\fn@fracpunct#1{\fn@fpa#1@ } |
| 192 |
\def\fn@fpa#1#2#3 {#1\if #2@ \else \fn@fpb#2#3 \fi} |
| 193 |
\def\fn@fpb#1#2#3 {#1\if #2@ \else \fn@fpc#2#3 \fi} |
| 194 |
\def\fn@fpc#1#2#3 {#1\if #2@ \else \fn@groupsym\fn@fpa#2#3 \fi} |
| 195 |
% \end{macrocode} |
| 196 |
% \end{macro} |
| 197 |
% |
| 198 |
% \begin{macro}{\fn@intpunct} |
| 199 |
% Punctuate the integer part of a decimal. This is not as |
| 200 |
% easy as the fractional part since we need to know the length |
| 201 |
% before we start (no doubt there is a direct recursive method |
| 202 |
% to do this, but I'm not clever enough to work it out). |
| 203 |
% \begin{macrocode} |
| 204 |
\def\fn@intpunct#1{\fn@ipa#1 } |
| 205 |
% \end{macrocode} |
| 206 |
% The macro |\fn@ipa| prints the string's initial $\pm$ and passes |
| 207 |
% on the rest of the string to the |\fn@ipb| macro. It might be |
| 208 |
% worthwhile stripping the redundant `+' here, but I am minded not |
| 209 |
% to do this since whether it is present is the choice of the user |
| 210 |
% (unlike the redundancy in the sign of the exponent --- see below). |
| 211 |
% \begin{macrocode} |
| 212 |
\def\fn@ipa#1#2 {% |
| 213 |
\if +#1 +\fn@ipb#2 \else |
| 214 |
\if -#1 -\fn@ipb#2 \else |
| 215 |
\fn@ipb#1#2 \fi \fi} |
| 216 |
% \end{macrocode} |
| 217 |
% The |\fn@ipab| macro finds the length (modulo 3) with |\fn@strlen| |
| 218 |
% and calls the appropriate output macro. |
| 219 |
% \begin{macrocode} |
| 220 |
\def\fn@ipb#1 {\fn@length{#1} |
| 221 |
\ifcase\fn@strlen |
| 222 |
\fn@ipc#1 \or |
| 223 |
\fn@ipd#1 \or |
| 224 |
\fn@ipe#1 \fi} |
| 225 |
% \end{macrocode} |
| 226 |
% The |\fn@ip[cde]| macro prints the first couple of characters |
| 227 |
% and then calls |\fn@ipf| which calls |\fn@fpa| (see above) to |
| 228 |
% finish the job. |
| 229 |
% \begin{macrocode} |
| 230 |
\def\fn@ipc#1#2#3#4 {#1#2#3\fn@ipf#4@ } |
| 231 |
\def\fn@ipd#1#2 {#1\fn@ipf#2@ } |
| 232 |
\def\fn@ipe#1#2#3 {#1#2\fn@ipf#3@ } |
| 233 |
\def\fn@ipf#1#2 {\if #1@ \else \fn@groupsym\fn@fpa#1#2 \fi} |
| 234 |
% \end{macrocode} |
| 235 |
% \end{macro} |
| 236 |
% |
| 237 |
% \begin{macro}{\fn@decimal} |
| 238 |
% Set a proper decimal. |
| 239 |
% The pattern matching trick used here (and for the |
| 240 |
% exponent) is due to a conversation between |
| 241 |
% Heiko Oberdiek and Michael Downs on |comp.text.tex|. |
| 242 |
% See the file |ctt.txt| included in the distribution for details. |
| 243 |
% \begin{macrocode} |
| 244 |
\def\fn@propdecimal#1#2{\fn@intpunct{#1}\fn@decimalsym\fn@fracpunct{#2}} |
| 245 |
\def\fn@impropdecimal#1#2{\fn@intpunct{#1}} |
| 246 |
\def\fn@decimalsplit#1.#2.#3#4#5{#4{#1}{#2}} |
| 247 |
\def\fn@decimal#1{\fn@decimalsplit#1..\fn@propdecimal\fn@impropdecimal\empty} |
| 248 |
% \end{macrocode} |
| 249 |
% \end{macro} |
| 250 |
% |
| 251 |
% \subsubsection{The exponent} |
| 252 |
% |
| 253 |
% \begin{macro}{\fn@signedint} |
| 254 |
% Set a signed exponent. |
| 255 |
% The C standard I/O library functions \textit{printf}, |
| 256 |
% \textit{fprintf}, etc., as well as many Fortran compilers, |
| 257 |
% write a `+' in the exponent if it is positive. |
| 258 |
% Since this is superfluous, both typographically |
| 259 |
% and mathematically, we remove it if we find it. |
| 260 |
% \begin{macrocode} |
| 261 |
\def\fn@signedint#1#2 {% |
| 262 |
\if +#1 |
| 263 |
\fn@unsignedint#2\relax |
| 264 |
\else |
| 265 |
\if -#1 |
| 266 |
-\fn@unsignedint#2\relax |
| 267 |
\else |
| 268 |
\fn@unsignedint#1#2\relax |
| 269 |
\fi |
| 270 |
\fi} |
| 271 |
% \end{macrocode} |
| 272 |
% \end{macro} |
| 273 |
% |
| 274 |
% \begin{macro}{\fn@unsignedint} |
| 275 |
% Set an unsigned exponent. Here we remove leading zeros. |
| 276 |
% \begin{macrocode} |
| 277 |
\def\fn@unsignedint#1#2{% |
| 278 |
\ifx #2\relax \let\next=#1 |
| 279 |
\else |
| 280 |
\ifx 0#1 \let\next=\fn@unsignedint |
| 281 |
\else |
| 282 |
\let\next=#1 |
| 283 |
\fi |
| 284 |
\fi |
| 285 |
\next #2} |
| 286 |
% \end{macrocode} |
| 287 |
% \end{macro} |
| 288 |
% |
| 289 |
% \subsubsection{The general number} |
| 290 |
% |
| 291 |
% \begin{macro}{\fnum} |
| 292 |
% The setting of an floating point number. |
| 293 |
% Our processing is dependent on whether the argument contains |
| 294 |
% the letter `e'. |
| 295 |
% \begin{macrocode} |
| 296 |
\def\fn@exp#1#2{\fn@decimal{#1}\fn@multsym10^{\fn@signedint#2 }} |
| 297 |
\def\fn@noexp#1#2{\fn@decimal{#1}} |
| 298 |
\def\fn@realsplit#1e#2e#3#4#5{#4{#1}{#2}} |
| 299 |
\def\fnum#1{\fn@realsplit#1ee\fn@exp\fn@noexp\empty} |
| 300 |
% \end{macrocode} |
| 301 |
% \end{macro} |
| 302 |
% |
| 303 |
% \begin{macrocode} |
| 304 |
%</package> |
| 305 |
% \end{macrocode} |
| 306 |
% |
| 307 |
% \Finale |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|