Debian Codegraph @

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

raw
1 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % \iffalse meta-comment
3 %
4 % DocStrip file for ionumbers package
5 %
6 % Copyright 2007-2009,2011,2012,2014
7 % Christian Schneider <software(at)chschneider(dot)eu>
8 %
9 % idea and parts of this package based on: ziffer.sty v2.1
10 % Copyright Martin Vaeth <[email protected]>
11 %
12 % ion@addto@macro: identical to l@addto@macro from koma-script
13 % bundle v2.9t
14 % Copyright 1994-2004 Markus Kohm and Frank Neukam
15 %
16 % Thanks to Martin Vaeth and Markus Kohm for permitting to use their
17 % code in this package. Please do not bother Martin, Markus, or Frank
18 % with questions or bugs concering this package!
19 %
20 % This file is part of ionumbers.
21 %
22 % ionumbers is free software: you can redistribute it and/or modify
23 % it under the terms of the GNU General Public License version 3 as
24 % published by the Free Software Foundation, not any later version.
25 %
26 % ionumbers is distributed in the hope that it will be useful,
27 % but WITHOUT ANY WARRANTY; without even the implied warranty of
28 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 % GNU General Public License for more details.
30 %
31 % You should have received a copy of the GNU General Public License
32 % along with ionumbers. If not, see <http://www.gnu.org/licenses/>.
33 %
34 % WARNING: THIS IS ALPHA SOFTWARE AND MAY CONTAIN SERIOUS BUGS!
35 %
36 % \fi
37 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %
39 % \iffalse
40 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
41 %<package>\ProvidesPackage{ionumbers}
42 %<package> [2014/04/06 v0.3.3 restyle numbers in math mode]
43 %<*driver>
44 \documentclass[a4paper]{ltxdoc}
45 \usepackage{ionumbers}
46 \usepackage{hyperref}
47 \EnableCrossrefs
48 \CodelineIndex
49 \RecordChanges
50 %
51 % modified description environment
52 \newcommand{\listmark}{$\bullet$}
53 \newcommand{\listlengths}{%
54 \setlength{\parsep}{0pt}%
55 \setlength{\itemsep}{0pt}%
56 \setlength{\leftmargin}{10.5em}%
57 \setlength{\rightmargin}{0pt}%
58 \setlength{\labelsep}{1em}%
59 \setlength{\labelwidth}{9.5em}}
60 \newenvironment{mydescription}{%
61 \begin{list}{\listmark}{\listlengths}%
62 }{%
63 \end{list}%
64 }
65 %
66 \begin{document}
67 \DocInput{ionumbers.dtx}
68 \end{document}
69 %</driver>
70 % \fi
71 %
72 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %
74 % \changes{v0.2.0-alpha}{2008/10/27}{initial .dtx version}
75 % \changes{v0.2.1-alpha}{2008/11/02}{replaced website by e-mail address in all
76 % fields containing contact information}
77 % \changes{v0.2.2-alpha}{2008/12/21}{fixed problem with single digit numbers
78 % without \{\}-grouping; conflict with \textsf{amsmath}/\textsf{amsopn}
79 % documented and handled with warning messages; thanks to Robert N\"{u}rnberg
80 % for reporting these two problems}
81 % \changes{v0.2.3-alpha}{2008/12/21}{saved one \texttt{\textbackslash if} and
82 % made sign/digit macros a bit clearer}
83 % \changes{v0.2.4-alpha}{2009/07/18}{fixed bug with curly braces in
84 % \texttt{\textbackslash ion@problem@package} macro; thanks to Lars for
85 % reporting this problem}
86 % \changes{v0.3.0-alpha}{2011/06/09}{added options for variable grouping
87 % lengths; extended \LaTeX{} test file}
88 % \changes{v0.3.1-alpha}{2011/06/15}{fix in Makefile of package}
89 % \changes{v0.3.2-alpha}{2012/08/20}{added examples of usage}
90 % \changes{v0.3.3}{2014/04/06}{fixed problem when changing the font,
91 % e.\,g., when loading the \textsf{MnSymbol} package; the original character
92 % definitions are not hard-coded anymore, but copied
93 % from the definitions at the beginning of the document; thanks to Michael
94 % Sebastian Hitziger for his bug report}
95 %
96 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 %
98 % \CheckSum{0}
99 %
100 % \CharacterTable
101 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
102 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
103 % Digits \0\1\2\3\4\5\6\7\8\9
104 % Exclamation \! Double quote \" Hash (number) \#
105 % Dollar \$ Percent \% Ampersand \&
106 % Acute accent \' Left paren \( Right paren \)
107 % Asterisk \* Plus \+ Comma \,
108 % Minus \- Point \. Solidus \/
109 % Colon \: Semicolon \; Less than \<
110 % Equals \= Greater than \> Question mark \?
111 % Commercial at \@ Left bracket \[ Backslash \\
112 % Right bracket \] Circumflex \^ Underscore \_
113 % Grave accent \` Left brace \{ Vertical bar \|
114 % Right brace \} Tilde \~}
115 %
116 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 %
118 % \GetFileInfo{ionumbers.sty}
119 %
120 % \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ }
121 % \DoNotIndex{\@ne}
122 % \DoNotIndex{\advance,\begingroup,\catcode,\closein}
123 % \DoNotIndex{\closeout,\day,\def,\edef,\else,\empty,\endgroup}
124 %
125 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 %
127 % \title{The \textsf{ionumbers} package\thanks{This document corresponds
128 % to \textsf{ionumbers}~\fileversion, dated~\filedate. Copyright
129 % 2007--2009,2011,2012,2014 Christian Schneider
130 % \texttt{<software(at)chschneider(dot)eu>}, \url{http://chschneider.eu}.}}
131 % \author{Christian Schneider\\ \texttt{<software(at)chschneider(dot)eu>}}
132 %
133 % \maketitle
134 %
135 % \begin{center}
136 % \large\textbf{\textsf{Warning: Use with caution and on your own risk!
137 % Check output!}}
138 % \end{center}
139 %
140 % \tableofcontents
141 % \clearpage
142 %
143 % \begin{abstract}
144 % \textsf{ionumbers} stands for `input/output numbers'.
145 %
146 % This package restyles numbers in math mode. If a number in the input file
147 % is written, e.g., as |$3,231.44$| as commonly used in English texts, this
148 % package is able to restyle it to be output as `$3\,231{,}44$' as commonly
149 % used in German texts (and vice versa). This may be very useful, if you have
150 % a large table and want to include it in texts with different output
151 % conventions without the need of changing the table.
152 %
153 % Furthermore this package can automatically group digits left to the decimal
154 % separator (\emph{thousands}) and right to the decimal separator
155 % (\emph{thousandths}) without the need of specifing commas (English) or
156 % points (German) as separators. E.g., the input |$1234.567890$| can be
157 % output as `$1\,234.\,567\,890$'. By default, thousands/thousandths are
158 % grouped in triplets, but the grouping length is configurable, which is
159 % useful for numerical data.
160 %
161 % Finally, an |e| starts the exponent of the number. For example, |$21e6$|
162 % may be output as `$26\times10\,^{6}$'.
163 % \end{abstract}
164 %
165 % \section{Details of number handling}
166 %
167 % \subsection{General rules}
168 %
169 % Every input \emph{in math mode} consisting of the following characters is
170 % treated by this package: |.,+-0123456789|. These characters get macro
171 % definitions. A number is any combination of these characters without
172 % anything---not even white spaces---in between them. There are two
173 % exceptions/special cases:
174 %
175 % \begin{enumerate}
176 % \item The separator characters |.| and |,| are not treated as part of the
177 % number at its end. This avoids problems with comma-separated lists
178 % (see below).
179 % \item The sign characters |+| and |-| will only be considered as part of
180 % the number, if they appear at the begining of a number.
181 % \end{enumerate}
182 %
183 % The lower case letter |e| plays a special role. An |e| immediatly following a
184 % number (as defined above) can be configured as begining of the exponential
185 % part. The letter |e| will be eaten from the input in this case and
186 % substituted by some configurable output. The next number following this |e|
187 % in the same group (even with other characters inbetween the |e| and the
188 % number) will be treated as exponential part and grouped with curly braces
189 % |{}|.
190 %
191 % It is a good practice to always add a space before/after each number such that
192 % \textsf{ionumbers} knows the beginning/end of a number and does not
193 % misinterpret other input as part of it.
194 % Below, you will find a couple of examples that might lead to surprising
195 % output, if this rule is not followed.
196 %
197 % \subsection{Caveats}
198 %
199 % \emph{Comma-separated lists} of numbers must be input with a space after
200 % each comma to prevent |,| to be treated as part of the number. An example is
201 % the list |1, 2, 3, \ldots|, where the commas are not part of in the numbers.
202 % Note, however, that the commas are treated as part of the numbers in the first
203 % two appearances in |1,2,3,\ldots|, as the commas are immediately followed
204 % by a digit. Depending on the configuration, this may lead to strange spaces
205 % between the numbers, disappearing commas etc.
206 %
207 % If you use \emph{indexes consisting of four or more digits} together
208 % with automatic grouping of thousands, the grouping will also apply to the
209 % indexes. So |a_{1234}| might be output as $a_{1,234}$. The simplest way to
210 % prevent undesired automatic grouping is to insert a space after each digit,
211 % e.\,g., as in |a_{1 2 3 4}|.
212 %
213 % Please be aware that the first decimal separator of a number marks the
214 % begining of the thousandths part of a number; every part of a number
215 % appearing left to the first decimal separator is the thousands part. That is
216 % why, the input |$1.234.567$| with (only) the package option
217 % |autothousandths=true| (|.| is the decimal separator; options will be
218 % explained later) will lead to `$1.234.\,567$' in the output. Note the small
219 % space after the second point as a result of |234.567| being treated as
220 % thousandths part. The thousandths separator---by default a small space---will
221 % be output between the third and fourth digit of the thousandths part; the
222 % additional point from the input will not be omitted. The input is
223 % \emph{syntactically incorrect} (there must not be two decimal separators in
224 % one number!) and the output is \emph{not} a bug.
225 %
226 % The number following an |e| which has started the exponential part is treated
227 % as exponential part, \emph{even if there is arbitrary input inbetween}.
228 % Hence, the input |$1e \Pi 2| with package option |exponent=timestento| (will
229 % be explained later) leads to a superscript |2| in the output. In some cases,
230 % e.\,g., |$1e \sqrt 2$| or |$1e^2$| with
231 % |e| configured as begining of the exponential part, even an error occurs.
232 % Again, the input is \emph{syntactically incorrect} and you might want to
233 % prevent |e| from being treated as start of the exponential part by adding
234 % a space: |$1 e \sqrt 2$| or |$1 e^2$|.
235 %
236 % In some rare cases, e.\,g., |$\sqrt ,$| or |$a^.$|, the usage of point and
237 % comma without curly braces |{}| around them will lead to an error. In these
238 % cases please add curly braces |{}| around the point or comma. (The
239 % \textsf{ziffer} package has the same problem, by the way.)
240 %
241 % \section{Conflicts with other packages}
242 %
243 % This package potentially conflicts with any other package that defines a
244 % macro for any of the following characters: |.,+-0123456789|
245 %
246 % There are tests for these cases and warning or error messages may be output.
247 % Please load \textsf{ionumbers} as \emph{last package} to be able to detect as
248 % many conflicts as possible. As there is no way to detect conflicts in any
249 % case, please report any package known to conflict with \textsf{ionumbers} to
250 % the author.
251 %
252 % Packages known to conflict with \textsf{ionumbers} are:
253 % \begin{mydescription}
254 % \item[\textsf{ziffer}] this package can be replaced by \textsf{ionumbers}
255 % except for \textsf{ziffer}'s special handling of |--| enabled by
256 % |\ZifferStrichAn|
257 % \item[\textsf{dcolumn}] workaround: disable \textsf{ionumbers} for tabulars
258 % (e.\,g., put them inside |\ionumbersoff|\marg{\ldots})
259 % \item[\textsf{amsmath}/\textsf{amsopn}] load \textsf{ionumbers} as last
260 % package and disable \textsf{ionumbers} for |\operatorname|\marg{\ldots}
261 % (e.\,g., put it inside\\
262 % |\ionumbersoff|\marg{\ldots})
263 % \end{mydescription}
264 %
265 % \section{Usage}
266 %
267 % Package options are used to globally configure a default behaviour of
268 % \textsf{ionumbers} for the whole document. These options usually consist
269 % of a \meta{key}|=|\meta{value} pair. Local changes from this global
270 % configuration for arbitrary parts of the document can be applied with special
271 % commands.
272 %
273 % \subsection{Package options concerning the separators in the input}
274 % \label{sec:in}
275 %
276 % The following options configure the meaning of separators in the \LaTeX{}
277 % input file:
278 % \begin{mydescription}
279 % \item[\texttt{comma}=\meta{value}] comma `|,|' will be treated as
280 % \meta{value}
281 % \item[\texttt{point}=\meta{value}] point `|.|' will be treated as
282 % \meta{value}
283 % \end{mydescription}
284 %
285 % The following \meta{value}s can be chosen for both of them:
286 % \begin{mydescription}
287 % \item[\texttt{ignore}] the separator will be ignored (no output)
288 % \item[\texttt{decimal}] decimal separator (separating the thousands from
289 % the thousandths part of a number)
290 % \item[\texttt{thousands}] thousands separator (used for grouping of
291 % thousands part)
292 % \item[\texttt{default}] default behaviour of \textsf{ionumbers}
293 % (|decimal| for |point|; |thousands| for |comma|)
294 % \end{mydescription}
295 %
296 % The separator for exponents is always the lowercase letter |e|. A
297 % thousandths separator does not exist in input files; such a separator will
298 % only be output, if automatic grouping of the thousandths part is enabled (see
299 % below).
300 %
301 % \subsection{Package options concerning the separators in the output}
302 % \label{sec:out}
303 %
304 % The previously described options assign a \emph{meaning} to separators in
305 % the input file. The \emph{output} of the \emph{meanings} is configured via
306 % the following options:
307 % \begin{mydescription}
308 % \item[\texttt{thousands}=\meta{value}] thousands separator will be output as
309 % \meta{value}
310 % \item[\texttt{decimal}=\meta{value}] decimal separator will be output as
311 % \meta{value}
312 % \item[\texttt{thousandths}=\meta{value}] thousandths separator will be
313 % \meta{value}
314 % \item[\texttt{exponent}=\meta{value}] exponent separator will be output as
315 % \meta{value}
316 % \end{mydescription}
317 %
318 % The list of valid \meta{value}s for |thousands|, |decimal|, and |thousandths|
319 % is:
320 % \begin{mydescription}
321 % \item[\texttt{none}] will be ignored (no output)
322 % \item[\texttt{point}] normal point; this is the default point without
323 % \textsf{ionumbers}
324 % \item[\texttt{comma}] normal comma
325 % \item[\texttt{punctpoint}] punctuation point (point followed by small space)
326 % \item[\texttt{punctcomma}] punctuation comma (point followed by small
327 % space); this is the default comma without \textsf{ionumbers}
328 % \item[\texttt{apostrophe}] apostrophe (actually |$^\prime$|; \emph{not} for
329 % |decimal|)
330 % \item[\texttt{phantom}] space with width of a point (|$\phantom{.}$|;
331 % \emph{not} for |decimal|)
332 % \item[\texttt{space}] small space (|$\,$|; \emph{not} for |decimal|)
333 % \item[\texttt{default}] default behaviour of \textsf{ionumbers}
334 % (|punctcomma| for |thousands|; |point| for |decimal|; |space| for
335 % |thousandths|)
336 % \end{mydescription}
337 %
338 % If a number is handled as exponent, it will be put into curly braces |{}|
339 % for correct output of, e.\,g., signs without spacing around them (mathord).
340 % In the following list of valid \meta{value}s for |exponent| a number
341 % immediatly following an |e| will be handled as exponent, unless specified
342 % otherwise:
343 % \begin{mydescription}
344 % \item[\texttt{none}] will be ignored (not output; following number
345 % \emph{not} handled as exponent)
346 % \item[\texttt{original}] a simple character `e' (following number
347 % \emph{not} handled as exponent)
348 % \item[\texttt{ite/itE}] italic lower/upper case letter `e'
349 % \item[\texttt{rme/rmE}] roman lower/upper case letter `e'
350 % \item[\texttt{timestento}] |$\times10\,$| with following number output as
351 % superscript
352 % \item[\texttt{cdottento}] |$\cdot10\,$| with following number output as
353 % superscript
354 % \item[\texttt{wedge}] |$^\wedge$|
355 % \item[\texttt{default}] default behaviour of \textsf{ionumbers} (|original|)
356 % \end{mydescription}
357 %
358 % \subsection{Package options concerning automatic grouping}
359 % \label{sec:auto}
360 %
361 % Automatic grouping is a feature that automatically adds the thousands and
362 % thousandths separator, respectively. The separator will by default be added
363 % after each triplet of digits, but this may be changed (see below). Automatic
364 % grouping can be enable or disabled with the
365 % following options:
366 % \begin{mydescription}
367 % \item[\texttt{autothousands}=\meta{value}] automatic grouping of thousands
368 % (digits left to decimal separator)
369 % \item[\texttt{autothousandths}=\meta{value}] automatic grouping of
370 % thousandths (digits right to decimal separator)
371 % \end{mydescription}
372 %
373 % The grouping length for the thousands and thousandths, respectively, can be
374 % changed be the following options:
375 % \begin{mydescription}
376 % \item[\texttt{grplenthousands}=\meta{number}] group lengths for thousands
377 % (\meta{number} must be smaller than |10|; defaults to |3|)
378 % \item[\texttt{grplenthousandths}=\meta{number}] group lengths for thousandths
379 % (\meta{number} must be smaller than |10|; defaults to |3|)
380 % \end{mydescription}
381 %
382 % The available \meta{value}s are |true| and |false| (default).
383 %
384 % Notes on automatic grouping:
385 % \begin{enumerate}
386 % \item Grouping of thousandths requires |autothousandths=true| in any case,
387 % as there is no thousandths separator for explicitly specifing separations
388 % in the input.
389 % \item Automatic grouping of thousands will be skipped in a number, if it
390 % contains a thousands separator in the input.
391 % \end{enumerate}
392 %
393 % \subsection{Local style changes}
394 %
395 % \DescribeMacro{\ionumbersstyle}
396 % The command |\ionumbersstyle|\marg{option list} changes the global style
397 % definitions as specified as package options for the rest of the group.
398 % The \meta{option list} may contain any of the package options described in
399 % sections~\ref{sec:in}--\ref{sec:auto}. An additional \meta{value} for all
400 % \meta{key}s is available inside |\ionumbersstyle| to switch back to the
401 % configuration specified as package options: |reset|.
402 %
403 % \DescribeMacro{\ionumbersresetstyle}
404 % The command |\ionumbersresetstyle| resets all \meta{value}s to the
405 % configuration specified as package options. Actually, it is only a shorthand
406 % for\\
407 % |\ionumbersstyle{comma=reset,point=reset,decimal=reset,...}|.
408 %
409 % \subsection{User-defined values for output separators}
410 % \label{sec:defs}
411 %
412 % A user may specify further output separators. Any user-defined \meta{value}s
413 % for |thousands|, |decimal|, |thousandths|, and |exponent| can be used like
414 % the built-in options in section~\ref{sec:out}.
415 %
416 % \DescribeMacro{\newionumbersthousands}
417 % \DescribeMacro{\newionumbersdecimal}
418 % \DescribeMacro{\newionumbersthousandths}
419 % \DescribeMacro{\newionumbersexponent}
420 % The command |\newionumbersthousands|\marg{value}\marg{definition} has two
421 % mandatory arguments. The first one is the name of the newly defined
422 % \meta{value} for the |thousands| \meta{key} and the second one its
423 % definition. The commands |\newionumbersdecimal|, |\newionumbersthousandths|,
424 % and |\newionumbersexponent| work the same way for the |decimal|,
425 % |thousandths|, and |exponent| \meta{key}, respectively. There is a starred
426 % version of |\newionumbersexponent| (called |\newionumbersexponent*|) that
427 % typesets the following number as superscript.
428 %
429 % \DescribeMacro{\renewionumbersthousands}
430 % \DescribeMacro{\renewionumbersdecimal}
431 % \DescribeMacro{\renewionumbersthousandths}
432 % \DescribeMacro{\renewionumbersexponent}
433 % To redefine an existing \meta{key} definition there are |\renew...| versions
434 % of the previously described commands.
435 %
436 % Notes on definitions:
437 % \begin{enumerate}
438 % \item All \meta{definition}s are set inside |\ionumbersoff| (see
439 % section~\ref{sec:feat}). This means that numbers appearing in the
440 % \meta{definition}s are not treated by this package.
441 % \item The value |curr| has an internal meaning and should \emph{not} be
442 % defined/redefined by the user.
443 % \end{enumerate}
444 %
445 % \subsection{Enabling and disabling features}
446 % \label{sec:feat}
447 %
448 % \DescribeMacro{\ionumbers}
449 % The command |\ionumbers| makes comma, point, signs, and digits active in math
450 % mode. This is equivalent to enabling the features of this package. This
451 % command applies to the end of the current group.
452 %
453 % \DescribeMacro{\endionumbers}
454 % To disable the features by making comma, point, signs, and digits inactive
455 % again the command |\endionumbers| can be used. This command applies to the
456 % end of the current group.
457 %
458 % \DescribeMacro{\ionumbersoff}
459 % The command |\ionumbersoff|\marg{stuff} disables the features only for
460 % \meta{stuff}.
461 %
462 % \section{License}
463 %
464 % \textsf{ionumbers} is free software: you can redistribute it and/or
465 % modify it under the terms of the GNU General Public License version~3 as
466 % published by the Free Software Foundation, not any later version.
467 %
468 % \textsf{ionumbers} is distributed in the hope that it will be useful,
469 % but WITHOUT ANY WARRANTY; without even the implied warranty of
470 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
471 % Public License for more details.
472 %
473 % You should have received a copy of the GNU General Public License along with
474 % ionumbers. If not, see \texttt{<http://www.gnu.org/licenses/>}.
475 %
476 % \section{Acknowledgements}
477 %
478 % The idea and parts of this package are based on \textsf{ziffer.sty}~v2.1 by
479 % Martin V\"ath \texttt{<[email protected]>}.
480 %
481 % Furthermore the |\l@addto@macro| (with changed name) from
482 % \textsf{koma-script bundle}~v2.9t by Markus Kohm and Frank Neukam is
483 % used in this package.
484 %
485 % Thanks to Martin V\"ath and Markus Kohm for permitting to use their code in
486 % this package.
487 %
488 % \section{Bugs, problems, and suggestions}
489 %
490 % Please report bugs and problems or send suggestions for this package to
491 % Christian Schneider. Check for updates before reporting bugs at the website
492 % mentioned above. Do \emph{not} bother Martin V\"ath, Markus Kohm, or Frank
493 % Neukam with bugs, problems or suggestions concerning this package!
494 %
495 % \StopEventually{\PrintChanges\PrintIndex}
496 %
497 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498 %
499 % \section{Implementation}
500 %
501 % The implementation is briefly described in this section. First of all, we
502 % need the \textsf{keyval} package for \meta{key}|=|\meta{value} options:
503 % \begin{macrocode}
504 \RequirePackage{keyval}
505 % \end{macrocode}
506 %
507 % ---------------------------------------------------------------------
508 %
509 % \subsection{Default/global configuration}
510 %
511 % In principle the definitions of all available \meta{key'}|=|\meta{value'}
512 % pairs is contained in the internal macros |\ion@|\meta{key'}|@|\meta{value'}.
513 % Setting a package option \meta{key}|=|\meta{value} defines
514 % |\ion@|\meta{key}|@reset| to be |\ion@|\meta{key}|@|\meta{value}.
515 %
516 % The following |if|s will be required to remember, if automatic grouping is
517 % enabled. The counts will be required for the grouping lengths.
518 % \begin{macrocode}
519 \newif\ifion@autothousands
520 \newif\ifion@autothousandths
521 \newcount\ion@grplenthousands
522 \newcount\ion@grplenthousandths
523 % \end{macrocode}
524 %
525 % The next macro will be used for syntax checks of numerical arguments.
526 % \begin{macrocode}
527 \newcommand*{\ion@grplencheck}[1]{%
528 \ifnum#1>9%
529 \PackageError{ionumbers}%
530 {Group length argument too large (#1).\MessageBreak%
531 Grouping lengths must be smaller than 10.}{}%
532 \fi%
533 }
534 % \end{macrocode}
535 %
536 % These shorthands are used to define the \meta{key}s for package options
537 % and set their \meta{value}s using \textsf{keyval}, respectively.
538 % \begin{macrocode}
539 \newcommand*\ion@defpackopts{\define@key{ion@packopts}}
540 \newcommand*\ion@setpackopts{\setkeys{ion@packopts}}
541 % \end{macrocode}
542 %
543 % Next the \meta{key}s are defined.
544 % \begin{macrocode}
545 \ion@defpackopts{comma}{%
546 \def\ion@comma@reset{\csname ion@comma@#1\endcsname}%
547 \def\ion@aftercomma@reset{\csname ion@aftercomma@#1\endcsname}}
548 \ion@defpackopts{point}{%
549 \def\ion@point@reset{\csname ion@point@#1\endcsname}%
550 \def\ion@afterpoint@reset{\csname ion@afterpoint@#1\endcsname}}
551 \ion@defpackopts{decimal}{\def\ion@decimal@reset{%
552 \csname ion@decimal@#1\endcsname}}
553 \ion@defpackopts{thousands}{\def\ion@thousands@reset{%
554 \csname ion@thousands@#1\endcsname}}
555 \ion@defpackopts{thousandths}{\def\ion@thousandths@reset{%
556 \csname ion@thousandths@#1\endcsname}}
557 \ion@defpackopts{exponent}{\def\ion@exponent@reset{%
558 \csname ion@exponent@#1\endcsname}}
559 \ion@defpackopts{autothousands}[true]{\def\ion@autothousandsreset{%
560 \csname ion@autothousands#1\endcsname}\ion@autothousandsreset}
561 \ion@defpackopts{autothousandths}[true]{\def\ion@autothousandthsreset{%
562 \csname ion@autothousandths#1\endcsname}\ion@autothousandthsreset}
563 \ion@defpackopts{grplenthousands}{\ion@grplencheck{#1}%
564 \def\ion@grplenthousandsreset{\ion@grplenthousands=#1}%
565 \ion@grplenthousandsreset}
566 \ion@defpackopts{grplenthousandths}{\ion@grplencheck{#1}%
567 \def\ion@grplenthousandthsreset{\ion@grplenthousandths=#1}%
568 \ion@grplenthousandthsreset}
569 % \end{macrocode}
570 %
571 % Finally, the default \meta{value}s are set and---if specified by the user as
572 % package option---overwritten with the user's configuration.
573 % \begin{macrocode}
574 \ion@setpackopts{comma=default,point=default,thousands=default,%
575 decimal=default,thousandths=default,exponent=default,autothousands=false,%
576 autothousandths=false,grplenthousands=3,grplenthousandths=3}
577 \DeclareOption*{\expandafter\ion@setpackopts\expandafter{\CurrentOption}}
578 \ProcessOptions\relax
579 % \end{macrocode}
580 %
581 % ---------------------------------------------------------------------
582 %
583 % \subsection{Local style changes}
584 %
585 % The currently active configuration of a \meta{key} is stored in the macro
586 % |\ion@|\meta{key}|@curr|. The |\ion@|\meta{key}|@curr| macros for all
587 % \meta{key}s are defined using the mechanism for local configuration changes.
588 %
589 % The local options are defined and set---analogous to the package option
590 % case---with two shorthands using \textsf{keyval}. The latter is
591 % publically available to the user.
592 % \begin{macrocode}
593 \newcommand*\ion@deflocopts{\define@key{ion@locopts}}
594 % \end{macrocode}
595 % \begin{macro}{\ionumberstyle}
596 % \begin{macrocode}
597 \newcommand*\ionumbersstyle[1]{\setkeys{ion@locopts}{#1}}
598 % \end{macrocode}
599 % \end{macro}
600 %
601 % Now the \meta{key}s for the local options are defined (just as in the case of
602 % the package options):
603 % \begin{macrocode}
604 \ion@deflocopts{comma}{%
605 \def\ion@comma@curr{\csname ion@comma@#1\endcsname}%
606 \def\ion@aftercomma@curr{\csname ion@aftercomma@#1\endcsname}}
607 \ion@deflocopts{point}{%
608 \def\ion@point@curr{\csname ion@point@#1\endcsname}%
609 \def\ion@afterpoint@curr{\csname ion@afterpoint@#1\endcsname}}
610 \ion@deflocopts{decimal}{\def\ion@decimal@curr{%
611 \csname ion@decimal@#1\endcsname}}
612 \ion@deflocopts{thousands}{\def\ion@thousands@curr{%
613 \csname ion@thousands@#1\endcsname}}
614 \ion@deflocopts{thousandths}{\def\ion@thousandths@curr{%
615 \csname ion@thousandths@#1\endcsname}}
616 \ion@deflocopts{exponent}{\def\ion@exponent@curr{%
617 \csname ion@exponent@#1\endcsname}}
618 \ion@deflocopts{autothousands}[true]{\csname ion@autothousands#1\endcsname}
619 \ion@deflocopts{autothousandths}[true]{\csname ion@autothousandths#1\endcsname}
620 \ion@deflocopts{grplenthousands}{%
621 \def\@tempa{#1}%
622 \def\@tempb{reset}%
623 \ifx\@tempa\@tempb%
624 \ion@grplenthousandsreset%
625 \else%
626 \ion@grplencheck{#1}%
627 \ion@grplenthousands=#1%
628 \fi%
629 }
630 \ion@deflocopts{grplenthousandths}{%
631 \def\@tempa{#1}%
632 \def\@tempb{reset}%
633 \ifx\@tempa\@tempb%
634 \ion@grplenthousandthsreset%
635 \else%
636 \ion@grplencheck{#1}%
637 \ion@grplenthousandths=#1%
638 \fi%
639 }
640 % \end{macrocode}
641 %
642 % Finally, the command for resetting all \meta{key}s is defined.
643 % \begin{macro}{\ionumbersresetstyle}
644 % \begin{macrocode}
645 \newcommand*\ionumbersresetstyle{%
646 \ionumbersstyle{comma=reset,point=reset,thousands=reset,%
647 decimal=reset,thousandths=reset,exponent=reset,autothousands=reset,%
648 autothousandths=reset,grplenthousands=reset,grplenthousandths=reset}}
649 % \end{macrocode}
650 % \end{macro}
651 % This command is issued at the end of the package to make the configuration
652 % of the package options active (and have no undefined |\ion@|\meta{key}|@curr|
653 % macros).
654 % \begin{macrocode}
655 \AtEndOfPackage{\ionumbersresetstyle}
656 % \end{macrocode}
657 %
658 % ---------------------------------------------------------------------
659 %
660 % \subsection{User-defined values for output separators}
661 %
662 % The commands for user-defined \meta{value}s for output separators just
663 % (re)define the internal macro |\ion@|\meta{key}|@|\meta{value} storing
664 % the definition for the \meta{key}|=|\meta{value} pair.
665 %
666 % \begin{macro}{\newionumbersthousands}
667 % \begin{macrocode}
668 \newcommand*\newionumbersthousands[2]{\expandafter\newcommand%
669 \expandafter*\csname ion@thousands@#1\endcsname{\ionumbersoff{#2}}}
670 % \end{macrocode}
671 % \end{macro}
672 % \begin{macro}{\newionumbersdecimal}
673 % \begin{macrocode}
674 \newcommand*\newionumbersdecimal[2]{\expandafter\newcommand%
675 \expandafter*\csname ion@decimal@#1\endcsname{\ionumbersoff{#2}}}
676 % \end{macrocode}
677 % \end{macro}
678 % \begin{macro}{\newionumbersthousandths}
679 % \begin{macrocode}
680 \newcommand*\newionumbersthousandths[2]{\expandafter\newcommand%
681 \expandafter*\csname ion@thousandths@#1\endcsname{\ionumbersoff{#2}}}
682 % \end{macrocode}
683 % \end{macro}
684 % \begin{macro}{\newionumbersexponent}
685 % \begin{macrocode}
686 \newcommand*\newionumbersexponent{%
687 \@ifstar{\newionumbersexponent@@}{\newionumbersexponent@}}
688 \newcommand*\newionumbersexponent@[2]{\expandafter\newcommand%
689 \expandafter*\csname ion@exponent@#1\endcsname{\ionumbersoff{#2}}}
690 \newcommand*\newionumbersexponent@@[2]{\expandafter\newcommand%
691 \expandafter*\csname ion@exponent@#1\endcsname{\ionumbersoff{#2}%
692 \ion@exponent@superscripttrue}}
693 % \end{macrocode}
694 % \end{macro}
695 % \begin{macro}{\renewionumbersthousands}
696 % \begin{macrocode}
697 \newcommand*\renewionumbersthousands[2]{\expandafter\renewcommand%
698 \expandafter*\csname ion@thousands@#1\endcsname{\ionumbersoff{#2}}}
699 % \end{macrocode}
700 % \end{macro}
701 % \begin{macro}{\renewionumbersdecimal}
702 % \begin{macrocode}
703 \newcommand*\renewionumbersdecimal[2]{\expandafter\renewcommand%
704 \expandafter*\csname ion@decimal@#1\endcsname{\ionumbersoff{#2}}}
705 % \end{macrocode}
706 % \end{macro}
707 % \begin{macro}{\renewionumbersthousandths}
708 % \begin{macrocode}
709 \newcommand*\renewionumbersthousandths[2]{\expandafter\renewcommand%
710 \expandafter*\csname ion@thousandths@#1\endcsname{\ionumbersoff{#2}}}
711 % \end{macrocode}
712 % \end{macro}
713 % \begin{macro}{\renewionumbersexponent}
714 % \begin{macrocode}
715 \newcommand*\renewionumbersexponent{%
716 \@ifstar{\renewionumbersexponent@@}{\renewionumbersexponent@}}
717 \newcommand*\renewionumbersexponent@[2]{\expandafter\renewcommand%
718 \expandafter*\csname ion@exponent@#1\endcsname{\ionumbersoff{#2}%
719 \ion@currnum@exponent}}
720 \newcommand*\renewionumbersexponent@@[2]{\expandafter\renewcommand%
721 \expandafter*\csname ion@exponent@#1\endcsname{\ionumbersoff{#2}%
722 \ion@currnum@exponent\ion@exponent@superscripttrue}}
723 % \end{macrocode}
724 % \end{macro}
725 %
726 % ---------------------------------------------------------------------
727 %
728 % \subsection{Internal macros holding definitions for \meta{key}=\meta{value}
729 % pairs}
730 %
731 % First of all, macros with the original character definitions are defined.
732 % \begin{macrocode}
733 \AtBeginDocument{
734 \mathchardef\ion@point@original=\the\mathcode`.
735 \mathchardef\ion@comma@original=\the\mathcode`,
736 \mathchardef\ion@plus@original=\the\mathcode`+
737 \mathchardef\ion@minus@original=\the\mathcode`-
738 \mathchardef\ion@zero@original=\the\mathcode`0
739 \mathchardef\ion@one@original=\the\mathcode`1
740 \mathchardef\ion@two@original=\the\mathcode`2
741 \mathchardef\ion@three@original=\the\mathcode`3
742 \mathchardef\ion@four@original=\the\mathcode`4
743 \mathchardef\ion@five@original=\the\mathcode`5
744 \mathchardef\ion@six@original=\the\mathcode`6
745 \mathchardef\ion@seven@original=\the\mathcode`7
746 \mathchardef\ion@eight@original=\the\mathcode`8
747 \mathchardef\ion@nine@original=\the\mathcode`9
748 \mathchardef\ion@e@original=\the\mathcode`e
749 \mathchardef\ion@E@original=\the\mathcode`E
750 }
751 % \end{macrocode}
752 %
753 % Here the |\ion@|\meta{key}|@|\meta{value} macros are defined, begining with
754 % the definitions for the comma as input separator.
755 % \begin{macrocode}
756 \def\ion@comma@ignore{}
757 \def\ion@comma@decimal{\ion@decimal@curr}
758 \def\ion@comma@thousands{\ion@thousands@curr}
759 \def\ion@comma@default{\ion@comma@thousands}
760 % \end{macrocode}
761 % The macros |\ion@comma@|\meta{value} contain the output for a comma appearing
762 % in the input. Actually, a second set of |\ion@|aftercomma|@|\meta{value}
763 % macros is required containing commands to be issued whenever a comma appears.
764 % If comma is the decimal separator, the appearance of comma in the input will
765 % mean that input of the thousands part is complete and the thousandths
766 % thousandths part starts (|\ion@beforedecimalfalse| must be issued). If comma
767 % is the thousands separator, the automatic grouping of thousands will be
768 % switched of for that number (|\ion@noexplicitthousandsfalse| must be issued).
769 % \begin{macrocode}
770 \def\ion@aftercomma@ignore{}
771 \def\ion@aftercomma@decimal{\ion@beforedecimalfalse}
772 \def\ion@aftercomma@thousands{\ion@noexplicitthousandsfalse}
773 \def\ion@aftercomma@default{\ion@aftercomma@thousands}
774 % \end{macrocode}
775 %
776 % An analogous set of macros is defined for the point as input separator.
777 % \begin{macrocode}
778 \def\ion@point@ignore{}
779 \def\ion@point@decimal{\ion@decimal@curr}
780 \def\ion@point@thousands{\ion@thousands@curr}
781 \def\ion@point@default{\ion@point@decimal}
782 % \end{macrocode}
783 % For the same reasons as mentioned before a set of
784 % |\ion@|afterpoint|@|\meta{value} macros is required.
785 % \begin{macrocode}
786 \def\ion@afterpoint@ignore{}
787 \def\ion@afterpoint@decimal{\ion@beforedecimalfalse}
788 \def\ion@afterpoint@thousands{\ion@noexplicitthousandsfalse}
789 \def\ion@afterpoint@default{\ion@afterpoint@decimal}
790 % \end{macrocode}
791 %
792 % Next the definitions for the decimal output separator, \ldots
793 % \begin{macrocode}
794 \def\ion@decimal@point{\mathord{\ion@point@original}}
795 \def\ion@decimal@comma{\mathord{\ion@comma@original}}
796 \def\ion@decimal@punctpoint{\mathpunct{\ion@decimal@point}}
797 \def\ion@decimal@punctcomma{\mathpunct{\ion@decimal@comma}}
798 \def\ion@decimal@default{\ion@decimal@point}
799 % \end{macrocode}
800 %
801 % \ldots{} the thousands output separator, \ldots
802 % \begin{macrocode}
803 \def\ion@thousands@none{}
804 \def\ion@thousands@point{\mathord{\ion@point@original}}
805 \def\ion@thousands@comma{\mathord{\ion@comma@original}}
806 \def\ion@thousands@punctpoint{\mathpunct{\ion@decimal@point}}
807 \def\ion@thousands@punctcomma{\mathpunct{\ion@decimal@comma}}
808 \def\ion@thousands@apostrophe{^\prime}
809 \def\ion@thousands@phantom{\phantom{\ion@point@original}}
810 \def\ion@thousands@space{\,}
811 \def\ion@thousands@default{\ion@thousands@punctcomma}
812 % \end{macrocode}
813 %
814 % \ldots{} the thousandths output separator, \ldots
815 % \begin{macrocode}
816 \def\ion@thousandths@none{}
817 \def\ion@thousandths@point{\mathord{\ion@point@original}}
818 \def\ion@thousandths@comma{\mathord{\ion@comma@original}}
819 \def\ion@thousandths@punctpoint{\mathpunct{\ion@decimal@point}}
820 \def\ion@thousandths@punctcomma{\mathpunct{\ion@decimal@comma}}
821 \def\ion@thousandths@apostrophe{^\prime}
822 \def\ion@thousandths@phantom{\phantom{\ion@point@original}}
823 \def\ion@thousandths@space{\,}
824 \def\ion@thousandths@default{\ion@thousandths@space}
825 % \end{macrocode}
826 %
827 % \ldots{} and the exponent output separator are given.
828 % \begin{macrocode}
829 \def\ion@exponent@none{}
830 \def\ion@exponent@original{\ion@e@original}
831 \def\ion@exponent@ite{\mathit{\ion@e@original}\ion@currnum@exponenttrue}
832 \def\ion@exponent@itE{\mathit{\ion@E@original}\ion@currnum@exponenttrue}
833 \def\ion@exponent@rme{\mathrm{\ion@e@original}\ion@currnum@exponenttrue}
834 \def\ion@exponent@rmE{\mathrm{\ion@E@original}\ion@currnum@exponenttrue}
835 \def\ion@exponent@timestento{\times10\,\ion@currnum@exponenttrue%
836 \ion@exponent@superscripttrue}
837 \def\ion@exponent@cdottento{\cdot10\,\ion@currnum@exponenttrue%
838 \ion@exponent@superscripttrue}
839 \def\ion@exponent@wedge{^\wedge\ion@currnum@exponenttrue}
840 \def\ion@exponent@default{\ion@exponent@original}
841 % \end{macrocode}
842 %
843 % ---------------------------------------------------------------------
844 %
845 % \subsection{Enabling and disabling features}
846 %
847 % The following helper macros make different subsets of |.,+-0123456789|
848 % active.
849 % \begin{macrocode}
850 \def\ion@separators@active{\catcode`\,=\active\catcode`\.=\active\relax}
851 \def\ion@signs@active{\catcode`\+=\active\catcode`\-=\active\relax}
852 \def\ion@digits@active{\catcode`\,=\active\catcode`\.=\active%
853 \catcode`\0=\active\catcode`\1=\active\catcode`\2=\active%
854 \catcode`\3=\active\catcode`\4=\active\catcode`\5=\active%
855 \catcode`\6=\active\catcode`\7=\active\catcode`\8=\active%
856 \catcode`\9=\active\relax}
857 % \end{macrocode}
858 %
859 % An analogous set of macros makes subsets of these characters active/inactive
860 % in math mode.
861 % \begin{macrocode}
862 \def\ion@separators@math@active{\mathcode`,="8000\mathcode`.="8000\relax}
863 \def\ion@signs@math@active{\mathcode`+="8000\mathcode`-="8000\relax}
864 \def\ion@digits@math@active{\mathcode`0="8000\mathcode`1="8000\mathcode`2="8000%
865 \mathcode`3="8000\mathcode`4="8000\mathcode`5="8000\mathcode`6="8000%
866 \mathcode`7="8000\mathcode`8="8000\mathcode`9="8000\relax}
867 \def\ion@separators@math@inactive{%
868 \mathcode`,=\the\ion@comma@original%
869 \mathcode`.=\the\ion@point@original%
870 \relax}
871 \def\ion@signs@math@inactive{%
872 \mathcode`+=\the\ion@plus@original%
873 \mathcode`-=\the\ion@minus@original%
874 \relax}
875 \def\ion@digits@math@inactive{%
876 \mathcode`0=\the\ion@zero@original%
877 \mathcode`1=\the\ion@one@original%
878 \mathcode`2=\the\ion@two@original%
879 \mathcode`3=\the\ion@three@original%
880 \mathcode`4=\the\ion@four@original%
881 \mathcode`5=\the\ion@five@original%
882 \mathcode`6=\the\ion@six@original%
883 \mathcode`7=\the\ion@seven@original%
884 \mathcode`8=\the\ion@eight@original%
885 \mathcode`9=\the\ion@nine@original%
886 \relax}
887 % \end{macrocode}
888 %
889 % Next the user interface for making |.,+-0123456789| active/inactive follows.
890 % \begin{macro}{\ionumbers}
891 % \begin{macrocode}
892 \def\ionumbers{\ion@separators@math@active\ion@signs@math@active%
893 \ion@digits@math@active}
894 % \end{macrocode}
895 % \end{macro}
896 % \begin{macro}{\endionumbers}
897 % \begin{macrocode}
898 \def\endionumbers{\ion@separators@math@inactive\ion@signs@math@inactive%
899 \ion@digits@math@inactive}
900 % \end{macrocode}
901 % \end{macro}
902 % \begin{macro}{\ionumbersoff}
903 % \begin{macrocode}
904 \newcommand\ionumbersoff[1]{\begingroup\endionumbers#1\ionumbers\endgroup}
905 % \end{macrocode}
906 % \end{macro}
907 %
908 % Of course, at the begining of the document the charactars shall be active
909 % by default.
910 % \begin{macrocode}
911 \AtBeginDocument{\ionumbers}
912 % \end{macrocode}
913 %
914 % ---------------------------------------------------------------------
915 %
916 % \subsection{Definitions of active characters}
917 %
918 % The macro definitions for the characters |.,+-0123456789| are hold in the
919 % following macros. Number processing works by looking at the next character
920 % and performing one or more from the following actions:
921 % \begin{itemize}
922 % \item the currently configured output for the character will be added to
923 % the end of |\ion@currnum| by |\ion@currnum@append|;
924 % |\ion@currnum| stores the currently processed number
925 % \item only for comma/point: the corresponding |after...| macro will be
926 % issued
927 % \item the currently processed number will be output via
928 % |\ion@currnum@output|
929 % \item the |e| will be eaten and replaced by its configured output
930 % \end{itemize}
931 % The conditions in the macro definitions should be self-explanatory for each
932 % character. The extra |\ion@startnumber| is required to avoid problems with
933 % input like |$a_0$| or |$\sqrt 2$|, where curly braces around |0| and |2| have
934 % been omitted.
935 % \begin{macrocode}
936 \def\ion@comma{%
937 \ion@ifnextdigit{%
938 \ion@currnum@append*{\ion@comma@curr}\ion@aftercomma@curr%
939 }{%
940 \ion@ifnextseparator{%
941 \ion@currnum@append*{\ion@comma@curr}\ion@aftercomma@curr%
942 \@warning{Too many separators}%
943 }{%
944 \ion@ifnextchar e{%
945 \ion@currnum@append*{\ion@comma@curr}\ion@aftercomma@curr%
946 \ion@currnum@output\ion@exponent@curr\@gobble%
947 }{%
948 \ion@currnum@output\ion@comma@original%
949 }%
950 }%
951 }%
952 }
953 \def\ion@point{%
954 \ion@ifnextdigit{%
955 \ion@currnum@append*{\ion@point@curr}\ion@afterpoint@curr%
956 }{%
957 \ion@ifnextseparator{%
958 \ion@currnum@append*{\ion@point@curr}\ion@afterpoint@curr%
959 \@warning{Too many separators}%
960 }{%
961 \ion@ifnextchar e{%
962 \ion@currnum@append*{\ion@point@curr}\ion@afterpoint@curr%
963 \ion@currnum@output\ion@exponent@curr\@gobble%
964 }{%
965 \ion@currnum@output\ion@point@original%
966 }%
967 }%
968 }%
969 }
970 \def\ion@plus{%
971 \ion@iffirstchar{%
972 \ion@plus@original%
973 }{%
974 \ion@currnum@append*{\ion@plus@original}%
975 }%
976 \ion@ifnextdigit{%
977 %% nothing
978 }{%
979 \ion@ifnextseparator{%
980 %% nothing
981 }{%
982 \ion@ifnextsign{%
983 \@warning{Too many signs}%
984 }{%
985 \ion@currnum@output%
986 }%
987 }%
988 }%
989 }
990 \def\ion@minus{%
991 \ion@iffirstchar{%
992 \ion@minus@original%
993 }{%
994 \ion@currnum@append*{\ion@minus@original}%
995 }%
996 \ion@ifnextdigit{%
997 %% nothing
998 }{%
999 \ion@ifnextseparator{%
1000 %% nothing
1001 }{%
1002 \ion@ifnextsign{%
1003 \@warning{Too many signs}%
1004 }{%
1005 \ion@currnum@output%
1006 }%
1007 }%
1008 }%
1009 }
1010 \def\ion@zero{%
1011 \ion@iffirstchar{%
1012 \ion@zero@original\ion@currnum@append{}%
1013 }{%
1014 \ion@currnum@append{\ion@zero@original}%
1015 }%
1016 \ion@ifnextdigit{%
1017 %% nothing
1018 }{%
1019 \ion@ifnextseparator{%
1020 %% nothing
1021 }{%
1022 \ion@ifnextchar e{%
1023 \ion@currnum@output\ion@exponent@curr\@gobble%
1024 }{%
1025 \ion@currnum@output%
1026 }%
1027 }%
1028 }%
1029 }
1030 \def\ion@one{%
1031 \ion@iffirstchar{%
1032 \ion@one@original\ion@currnum@append{}%
1033 }{%
1034 \ion@currnum@append{\ion@one@original}%
1035 }%
1036 \ion@ifnextdigit{%
1037 %% nothing
1038 }{%
1039 \ion@ifnextseparator{%
1040 %% nothing
1041 }{%
1042 \ion@ifnextchar e{%
1043 \ion@currnum@output\ion@exponent@curr\@gobble%
1044 }{%
1045 \ion@currnum@output%
1046 }%
1047 }%
1048 }%
1049 }
1050 \def\ion@two{%
1051 \ion@iffirstchar{%
1052 \ion@two@original\ion@currnum@append{}%
1053 }{%
1054 \ion@currnum@append{\ion@two@original}%
1055 }%
1056 \ion@ifnextdigit{%
1057 %% nothing
1058 }{%
1059 \ion@ifnextseparator{%
1060 %% nothing
1061 }{%
1062 \ion@ifnextchar e{%
1063 \ion@currnum@output\ion@exponent@curr\@gobble%
1064 }{%
1065 \ion@currnum@output%
1066 }%
1067 }%
1068 }%
1069 }
1070 \def\ion@three{%
1071 \ion@iffirstchar{%
1072 \ion@three@original\ion@currnum@append{}%
1073 }{%
1074 \ion@currnum@append{\ion@three@original}%
1075 }%
1076 \ion@ifnextdigit{%
1077 %% nothing
1078 }{%
1079 \ion@ifnextseparator{%
1080 %% nothing
1081 }{%
1082 \ion@ifnextchar e{%
1083 \ion@currnum@output\ion@exponent@curr\@gobble%
1084 }{%
1085 \ion@currnum@output%
1086 }%
1087 }%
1088 }%
1089 }
1090 \def\ion@four{%
1091 \ion@iffirstchar{%
1092 \ion@four@original\ion@currnum@append{}%
1093 }{%
1094 \ion@currnum@append{\ion@four@original}%
1095 }%
1096 \ion@ifnextdigit{%
1097 %% nothing
1098 }{%
1099 \ion@ifnextseparator{%
1100 %% nothing
1101 }{%
1102 \ion@ifnextchar e{%
1103 \ion@currnum@output\ion@exponent@curr\@gobble%
1104 }{%
1105 \ion@currnum@output%
1106 }%
1107 }%
1108 }%
1109 }
1110 \def\ion@five{%
1111 \ion@iffirstchar{%
1112 \ion@five@original\ion@currnum@append{}%
1113 }{%
1114 \ion@currnum@append{\ion@five@original}%
1115 }%
1116 \ion@ifnextdigit{%
1117 %% nothing
1118 }{%
1119 \ion@ifnextseparator{%
1120 %% nothing
1121 }{%
1122 \ion@ifnextchar e{%
1123 \ion@currnum@output\ion@exponent@curr\@gobble%
1124 }{%
1125 \ion@currnum@output%
1126 }%
1127 }%
1128 }%
1129 }
1130 \def\ion@six{%
1131 \ion@iffirstchar{%
1132 \ion@six@original\ion@currnum@append{}%
1133 }{%
1134 \ion@currnum@append{\ion@six@original}%
1135 }%
1136 \ion@ifnextdigit{%
1137 %% nothing
1138 }{%
1139 \ion@ifnextseparator{%
1140 %% nothing
1141 }{%
1142 \ion@ifnextchar e{%
1143 \ion@currnum@output\ion@exponent@curr\@gobble%
1144 }{%
1145 \ion@currnum@output%
1146 }%
1147 }%
1148 }%
1149 }
1150 \def\ion@seven{%
1151 \ion@iffirstchar{%
1152 \ion@seven@original\ion@currnum@append{}%
1153 }{%
1154 \ion@currnum@append{\ion@seven@original}%
1155 }%
1156 \ion@ifnextdigit{%
1157 %% nothing
1158 }{%
1159 \ion@ifnextseparator{%
1160 %% nothing
1161 }{%
1162 \ion@ifnextchar e{%
1163 \ion@currnum@output\ion@exponent@curr\@gobble%
1164 }{%
1165 \ion@currnum@output%
1166 }%
1167 }%
1168 }%
1169 }
1170 \def\ion@eight{%
1171 \ion@iffirstchar{%
1172 \ion@eight@original\ion@currnum@append{}%
1173 }{%
1174 \ion@currnum@append{\ion@eight@original}%
1175 }%
1176 \ion@ifnextdigit{%
1177 %% nothing
1178 }{%
1179 \ion@ifnextseparator{%
1180 %% nothing
1181 }{%
1182 \ion@ifnextchar e{%
1183 \ion@currnum@output\ion@exponent@curr\@gobble%
1184 }{%
1185 \ion@currnum@output%
1186 }%
1187 }%
1188 }%
1189 }
1190 \def\ion@nine{%
1191 \ion@iffirstchar{%
1192 \ion@nine@original\ion@currnum@append{}%
1193 }{%
1194 \ion@currnum@append{\ion@nine@original}%
1195 }%
1196 \ion@ifnextdigit{%
1197 %% nothing
1198 }{%
1199 \ion@ifnextseparator{%
1200 %% nothing
1201 }{%
1202 \ion@ifnextchar e{%
1203 \ion@currnum@output\ion@exponent@curr\@gobble%
1204 }{%
1205 \ion@currnum@output%
1206 }%
1207 }%
1208 }%
1209 }
1210 % \end{macrocode}
1211 %
1212 % The macro |\ion@define@charmacros| is used to assign the above macros to the
1213 % (active) characters |.,+-0123456789|. It will be executed later in the
1214 % conflict test section.
1215 % \begin{macrocode}
1216 \begingroup
1217 \ion@separators@active\ion@signs@active\ion@digits@active
1218 \gdef\ion@define@charmacros{%
1219 \global\let,=\ion@comma%
1220 \global\let.=\ion@point%
1221 \global\let+=\ion@plus%
1222 \global\let-=\ion@minus%
1223 \global\let0=\ion@zero%
1224 \global\let1=\ion@one%
1225 \global\let2=\ion@two%
1226 \global\let3=\ion@three%
1227 \global\let4=\ion@four%
1228 \global\let5=\ion@five%
1229 \global\let6=\ion@six%
1230 \global\let7=\ion@seven%
1231 \global\let8=\ion@eight%
1232 \global\let9=\ion@nine%
1233 }
1234 \endgroup
1235 % \end{macrocode}
1236 %
1237 % If one of |+-0123456789| is the first character of a number and this number
1238 % not part of an exponent, then argument `1' will be used; otherwise argument
1239 % `2' will be used. This macro is required to handle single characters not
1240 % grouped in curly braces |{}| in expressions like |$a^0$| or |$\sqrt 2$|
1241 % correctly.
1242 % \begin{macrocode}
1243 \def\ion@iffirstchar#1#2{%
1244 \ifion@currnum@exponent%
1245 #2%
1246 \else%
1247 \ifion@currnum@firstchar%
1248 #1%
1249 \else
1250 #2%
1251 \fi%
1252 \fi%
1253 \ion@currnum@firstcharfalse%
1254 }
1255 % \end{macrocode}
1256 %
1257 % Now the macros for the conditions in the above definitions follow. There are
1258 % tests for a digit |0123456789|, \ldots
1259 % \begin{macrocode}
1260 \long\def\ion@ifnextdigit#1#2{%
1261 \def\reserved@a{#1}%
1262 \def\reserved@b{#2}%
1263 \futurelet\@let@token\ion@ifnextdigit@}
1264 \def\ion@ifnextdigit@{%
1265 \ifx\@let@token1\let\reserved@c\reserved@a\else%
1266 \ifx\@let@token2\let\reserved@c\reserved@a\else%
1267 \ifx\@let@token3\let\reserved@c\reserved@a\else%
1268 \ifx\@let@token4\let\reserved@c\reserved@a\else%
1269 \ifx\@let@token5\let\reserved@c\reserved@a\else%
1270 \ifx\@let@token6\let\reserved@c\reserved@a\else%
1271 \ifx\@let@token7\let\reserved@c\reserved@a\else%
1272 \ifx\@let@token8\let\reserved@c\reserved@a\else%
1273 \ifx\@let@token9\let\reserved@c\reserved@a\else%
1274 \ifx\@let@token0\let\reserved@c\reserved@a\else%
1275 \let\reserved@c\reserved@b%
1276 \fi%
1277 \fi%
1278 \fi%
1279 \fi%
1280 \fi%
1281 \fi%
1282 \fi%
1283 \fi%
1284 \fi%
1285 \fi%
1286 \reserved@c}
1287 % \end{macrocode}
1288 %
1289 % \ldots{} for a separator |.,|, \ldots
1290 % \begin{macrocode}
1291 \long\def\ion@ifnextseparator#1#2{%
1292 \def\reserved@a{#1}%
1293 \def\reserved@b{#2}%
1294 \futurelet\@let@token\ion@ifnextseparator@}
1295 \def\ion@ifnextseparator@{%
1296 \ifx\@let@token,\let\reserved@c\reserved@a\else%
1297 \ifx\@let@token.\let\reserved@c\reserved@a\else%
1298 \let\reserved@c\reserved@b%
1299 \fi%
1300 \fi%
1301 \reserved@c}
1302 % \end{macrocode}
1303 %
1304 % \ldots{} and for a sign |+-| as next character.
1305 % \begin{macrocode}
1306 \long\def\ion@ifnextsign#1#2{%
1307 \def\reserved@a{#1}%
1308 \def\reserved@b{#2}%
1309 \futurelet\@let@token\ion@ifnextsign@}
1310 \def\ion@ifnextsign@{%
1311 \ifx\@let@token+\let\reserved@c\reserved@a\else%
1312 \ifx\@let@token-\let\reserved@c\reserved@a\else%
1313 \let\reserved@c\reserved@b%
1314 \fi%
1315 \fi%
1316 \reserved@c}
1317 % \end{macrocode}
1318 %
1319 % An additional test for an arbitrary character is also added. It obeys white
1320 % spaces in contrast to \LaTeX{}'s |\@ifnextchar|.
1321 % \begin{macrocode}
1322 \long\def\ion@ifnextchar#1#2#3{%
1323 \let\reserved@d=#1%
1324 \def\reserved@a{#2}%
1325 \def\reserved@b{#3}%
1326 \futurelet\@let@token\ion@ifnextchar@}
1327 \def\ion@ifnextchar@{%
1328 \ifx\@let@token\reserved@d%
1329 \let\reserved@c\reserved@a%
1330 \else%
1331 \let\reserved@c\reserved@b%
1332 \fi%
1333 \reserved@c}
1334 % \end{macrocode}
1335 %
1336 % ---------------------------------------------------------------------
1337 %
1338 % \subsection{Test for conflicts with other packages}
1339 %
1340 % First of all we test for some packages known to conflict with
1341 % \textsf{ionumbers}. This will be done by checking at the begining of the
1342 % document, if one of these packages has been loaded and an error/warning will
1343 % be issued.
1344 % \begin{macrocode}
1345 \newcommand*{\ion@conflict@package}[1]{%
1346 \@ifpackageloaded{#1}{%
1347 \PackageError{ionumbers}%
1348 {Packages #1 and ionumbers conflict!\MessageBreak%
1349 Do not load both packages in the same document}{}%
1350 }{}%
1351 }
1352 \newcommand*{\ion@problem@package}[2]{%
1353 \@ifpackageloaded{#1}{%
1354 \PackageWarning{ionumbers}%
1355 {Loading #1 and ionumbers is problematic!\MessageBreak#2}%
1356 }{}%
1357 }
1358
1359 \AtBeginDocument{%
1360 \ion@conflict@package{ziffer}%
1361 \ion@problem@package{dcolumn}{Use `tabular's inside \string\ionumbersoff}%
1362 \ion@problem@package{amsmath}{Load ionumbers after amsmath}%
1363 \ion@problem@package{amsmath}{Use \string\operatorname\space inside
1364 \string\ionumbersoff}%
1365 \ion@problem@package{amsopn}{Use \string\operatorname\space inside
1366 \string\ionumbersoff}%
1367 }
1368 % \end{macrocode}
1369 %
1370 % Next the characters |.,+-0123456789| are checked for macro definitions (by
1371 % other packages). This way conflicts with other packages may be detected with
1372 % some probability (but only if the conflicting package has already been
1373 % loaded).
1374 % \begin{macrocode}
1375 \newcommand*\ion@conflict@definedtest[1]{%
1376 \ifx#1\@undefined\else\PackageWarning{ionumbers}%
1377 {Potential conflict with other package(s) detected.\MessageBreak%
1378 `\string#1' has already been defined. I will redefine it.\MessageBreak%
1379 This might break other package(s)!\MessageBreak}\fi}
1380 \begingroup
1381 \ion@separators@active\ion@signs@active\ion@digits@active
1382 \ion@conflict@definedtest{,}
1383 \ion@conflict@definedtest{.}
1384 \ion@conflict@definedtest{+}
1385 \ion@conflict@definedtest{-}
1386 \ion@conflict@definedtest{0}
1387 \ion@conflict@definedtest{1}
1388 \ion@conflict@definedtest{2}
1389 \ion@conflict@definedtest{3}
1390 \ion@conflict@definedtest{4}
1391 \ion@conflict@definedtest{5}
1392 \ion@conflict@definedtest{6}
1393 \ion@conflict@definedtest{7}
1394 \ion@conflict@definedtest{8}
1395 \ion@conflict@definedtest{9}
1396 \endgroup
1397 % \end{macrocode}
1398 %
1399 % After the above test the definitions of the characters of
1400 % \textsf{ionumbers} can be applied.
1401 % \begin{macrocode}
1402 \ion@define@charmacros
1403 % \end{macrocode}
1404 %
1405 % Additionally, \textsf{ionumbers} tests for redefinitions of the macros
1406 % of the characters at the begining of the document.
1407 % \begin{macrocode}
1408 \newcommand*{\ion@conflict@redefinedtest}[2]{%
1409 \ifx#1#2\else\PackageWarning{ionumbers}%
1410 {Potential conflict with other package(s) detected.\MessageBreak%
1411 `\string#1' has been redefined. This might break ionumbers!\MessageBreak}%
1412 \fi}
1413 \begingroup
1414 \ion@separators@active\ion@signs@active\ion@digits@active
1415 \gdef\ion@conflict@redefinedtest@macro{%
1416 \ion@conflict@redefinedtest{,}{\ion@comma}%
1417 \ion@conflict@redefinedtest{.}{\ion@point}%
1418 \ion@conflict@redefinedtest{+}{\ion@plus}%
1419 \ion@conflict@redefinedtest{-}{\ion@minus}%
1420 \ion@conflict@redefinedtest{0}{\ion@zero}%
1421 \ion@conflict@redefinedtest{1}{\ion@one}%
1422 \ion@conflict@redefinedtest{2}{\ion@two}%
1423 \ion@conflict@redefinedtest{3}{\ion@three}%
1424 \ion@conflict@redefinedtest{4}{\ion@four}%
1425 \ion@conflict@redefinedtest{5}{\ion@five}%
1426 \ion@conflict@redefinedtest{6}{\ion@six}%
1427 \ion@conflict@redefinedtest{7}{\ion@seven}%
1428 \ion@conflict@redefinedtest{8}{\ion@eight}%
1429 \ion@conflict@redefinedtest{9}{\ion@nine}%
1430 }
1431 \endgroup
1432 \AtBeginDocument{\ion@conflict@redefinedtest@macro}
1433 % \end{macrocode}
1434 %
1435 % ---------------------------------------------------------------------
1436 %
1437 % \subsection{Commands for current number}
1438 %
1439 % Numbers are processed by first storing one character after the other in an
1440 % internal macro to be able to automatically group digits. The basic idea when
1441 % adding single characters is
1442 % \begin{itemize}
1443 % \item remember, whether we are processing the thousands or the thousandths
1444 % part of a number (|\ifion@beforedecimal|)
1445 % \item calculate the number of digits processed modulo 3 plus 1 in the
1446 % current part and
1447 % \begin{itemize}
1448 % \item for the thousands part: add |\ion@thousands@sepa| for 1,
1449 % |\ion@thousands@sepb| for 2, |\ion@thousands@sepc| for 3, \ldots{}
1450 % after a digit
1451 % \item for the thousandths part: add |\ion@thousandths@sep| after each
1452 % third digit
1453 % \end{itemize}
1454 % \end{itemize}
1455 % The macros |\ion@thousands@sep...| and |\ion@thousandths@sep| are empty by
1456 % default. Before outputting the number, the number of digits in the thousands
1457 % part is known and the correct |\ion@thousands@sep...| macro can be set to the
1458 % thousands separator for correct grouping.
1459 %
1460 % First of all, the |if|s, counters and empty separator macros are initialized.
1461 % \begin{macrocode}
1462 \newif\ifion@currnum@firstchar\ion@currnum@firstchartrue
1463 \newif\ifion@beforedecimal\ion@beforedecimaltrue
1464 \newif\ifion@noexplicitthousands\ion@noexplicitthousandstrue
1465 \newif\ifion@currnum@exponent\ion@currnum@exponentfalse
1466 \newif\ifion@exponent@superscript\ion@exponent@superscriptfalse
1467 \newcount\ion@thousands@currpos\ion@thousands@currpos=0
1468 \newcount\ion@thousandths@currpos\ion@thousandths@currpos=0
1469 \def\ion@currnum{}
1470 \def\ion@thousands@sepa{}
1471 \def\ion@thousands@sepb{}
1472 \def\ion@thousands@sepc{}
1473 \def\ion@thousands@sepd{}
1474 \def\ion@thousands@sepe{}
1475 \def\ion@thousands@sepf{}
1476 \def\ion@thousands@sepg{}
1477 \def\ion@thousands@seph{}
1478 \def\ion@thousands@sepi{}
1479 \def\ion@thousandths@sep{}
1480 % \end{macrocode}
1481 %
1482 % The macro |\ion@currnum@append| adds the character in its argument to the
1483 % end of |\ion@currnum|. In the starred version adding of an empty separator
1484 % macros is omitted.
1485 % \begin{macrocode}
1486 \newcommand{\ion@currnum@append}{%
1487 \ion@currnum@firstcharfalse%
1488 \@ifstar{\ion@currnum@append@@}{\ion@currnum@append@}%
1489 }
1490 \newcommand*{\ion@currnum@append@@}[1]{%
1491 \ion@addto@macro{\ion@currnum}{#1}%
1492 }
1493 \newcommand*{\ion@currnum@append@}[1]{%
1494 \ifion@beforedecimal%
1495 %% push back (empty) separator and character
1496 \ifcase\ion@thousands@currpos%
1497 \ion@addto@macro{\ion@currnum}{#1}%
1498 \or%
1499 \ion@addto@macro{\ion@currnum}{\ion@thousands@sepa#1}%
1500 \or%
1501 \ion@addto@macro{\ion@currnum}{\ion@thousands@sepb#1}%
1502 \or%
1503 \ion@addto@macro{\ion@currnum}{\ion@thousands@sepc#1}%
1504 \or%
1505 \ion@addto@macro{\ion@currnum}{\ion@thousands@sepd#1}%
1506 \or%
1507 \ion@addto@macro{\ion@currnum}{\ion@thousands@sepe#1}%
1508 \or%
1509 \ion@addto@macro{\ion@currnum}{\ion@thousands@sepf#1}%
1510 \or%
1511 \ion@addto@macro{\ion@currnum}{\ion@thousands@sepg#1}%
1512 \or%
1513 \ion@addto@macro{\ion@currnum}{\ion@thousands@seph#1}%
1514 \or%
1515 \ion@addto@macro{\ion@currnum}{\ion@thousands@sepi#1}%
1516 \fi%
1517 %% advance thousands counter
1518 \advance\ion@thousands@currpos by1\relax%
1519 \ifnum\ion@thousands@currpos>\ion@grplenthousands%
1520 \ion@thousands@currpos=1%
1521 \fi%
1522 \else%
1523 %% push back (empty) separator and character
1524 \ifnum\ion@thousandths@currpos=\ion@grplenthousandths%
1525 \ion@addto@macro{\ion@currnum}{\ion@thousandths@sep#1}%
1526 \else%
1527 \ion@addto@macro{\ion@currnum}{#1}%
1528 \fi%
1529 %% advance thousandths counter
1530 \advance\ion@thousandths@currpos by1\relax%
1531 \ifnum\ion@thousandths@currpos>\ion@grplenthousandths%
1532 \ion@thousandths@currpos=1%
1533 \fi%
1534 \fi%
1535 }
1536 % \end{macrocode}
1537 %
1538 % The |\ion@currnum@output| macro defines the empty separator macros (depending
1539 % on the current configuration), outputs the current number, and resets
1540 % everything for the next number.
1541 % \begin{macrocode}
1542 \newcommand*{\ion@currnum@output}{%
1543 \begingroup%
1544 %% set automatic thousands separator
1545 \ifion@autothousands%
1546 \ifion@noexplicitthousands%
1547 \ifcase\ion@thousands@currpos%
1548 %% do nothing
1549 \or%
1550 \def\ion@thousands@sepa{\ion@thousands@curr}%
1551 \or%
1552 \def\ion@thousands@sepb{\ion@thousands@curr}%
1553 \or%
1554 \def\ion@thousands@sepc{\ion@thousands@curr}%
1555 \or%
1556 \def\ion@thousands@sepd{\ion@thousands@curr}%
1557 \or%
1558 \def\ion@thousands@sepe{\ion@thousands@curr}%
1559 \or%
1560 \def\ion@thousands@sepf{\ion@thousands@curr}%
1561 \or%
1562 \def\ion@thousands@sepg{\ion@thousands@curr}%
1563 \or%
1564 \def\ion@thousands@seph{\ion@thousands@curr}%
1565 \or%
1566 \def\ion@thousands@sepi{\ion@thousands@curr}%
1567 \fi%
1568 \fi%
1569 \fi%
1570 %% set automatic thousandths separator
1571 \ifion@autothousandths%
1572 \def\ion@thousandths@sep{\ion@thousandths@curr}%
1573 \fi%
1574 %% output number
1575 \ifion@currnum@exponent%
1576 \ifion@exponent@superscript%
1577 ^{\ion@currnum}%
1578 \else%
1579 {\ion@currnum}%
1580 \fi%
1581 \else
1582 \ion@currnum%
1583 \fi
1584 \endgroup%
1585 %% reset stuff for next number
1586 \ion@thousands@currpos=0%
1587 \ion@thousandths@currpos=0%
1588 \def\ion@currnum{}%
1589 \ion@currnum@firstchartrue%
1590 \ion@beforedecimaltrue%
1591 \ion@noexplicitthousandstrue%
1592 \ion@currnum@exponentfalse%
1593 \ion@exponent@superscriptfalse%
1594 }
1595 % \end{macrocode}
1596 %
1597 % This macro is identical to |\l@addto@macro| from \textsf{koma-script bundle}.
1598 % \begin{macrocode}
1599 \newcommand{\ion@addto@macro}[2]{%
1600 \begingroup\toks@\expandafter{#1#2}%
1601 \edef\@tempa{\endgroup\def\noexpand#1{\the\toks@}}%
1602 \@tempa}
1603 % \end{macrocode}
1604 %
1605 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1606 %
1607 % \Finale
1608 %
1609 \endinput