summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/sauerj/zahl2string.dtx
blob: c332c1d0879937e0d0e23ba19cdd553e1086bb1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
% \iffalse meta-comment
% Line endings: UNIX
% Tab size:     4
%
% Copyright 2004 Jonathan Sauer
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%
%   http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work is Jonathan Sauer
% (<jonathan.sauer@gmx.de>).
%
% This work consists of the files zahl2string.dtx and zahl2string.ins
% and the derived file zahl2string.sty.
%
% \fi
%
% \iffalse
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{zahl2string}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
% Modification of verbatim for tabs in listings
\makeatletter
{\catcode`\ =\active%
\catcode`\^^I=\active%
\gdef\@vobeyspaces{%
\catcode`\ \active\let \@xobeysp%
\catcode`\^^I\active\def^^I{~~}%
}}%
\makeatother
\begin{document}
	\DocInput{\jobname.dtx}
\end{document}
%</driver>
%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{zahl2string}
%<package>   [2004/11/25 v1.2.1 format a number as german words]
%
% \fi
%
% \CheckSum{331}
% \CharacterTable
%  {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
%   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
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \DoNotIndex{\",\@empty,\@M,\@m,\@tempa,\csname,\DeclareOption}
% \DoNotIndex{\DeclareRobustCommand,\def}
% \DoNotIndex{\else,\endcsname,\expandafter,\fi,\if,\ifcase}
% \DoNotIndex{\ifnum,\let,\MakeUppercase,\newcommand,\number,\or}
% \DoNotIndex{\PackageError,\PackageWarning,\ProcessOptions}
% \DoNotIndex{\protected@edef,\relax,\space,\ss,\string,\z@}
% \DoNotIndex{\@ne,\@nil,\-}
%
% \GetFileInfo{\jobname.sty}
%
% \changes{1.1}{2004/08/08}{Range expanded to 999,999,999.}
% \changes{1.2.1}{2004/10/20}{@Numstring and @Ordstring made robust.}
%
% \title{The \textsf{zahl2string} package\thanks{This document
% corresponds to \textsf{\filename}~\fileversion, dated \filedate.}}
%
% \author{Jonathan Sauer \\ \texttt{jonathan.sauer@gmx.de}}
%
% \date{\filedate}
%
% \maketitle
%
% \begin{abstract}
% This file describes the \textsf{zahl2string} package that provides
% macros for formatting numbers as german words, i.e. `1' gets
% formatted as `eins'.
%
% \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
%
% Sometimes, for example when formatting a chapter title, you do not
% want to say `Kapitel 1' (`Chapter 1') but `Kapitel eins' (`Chapter
% one') or `Erstes Kapitel' (`First chapter'). This package provides
% macros to format a \LaTeX-counter or more generally speaking a
% number as a german word.
%
%
% \section{Description of the macros}
%
% All macros format numbers in the range 0 to 999,999,999. Larger
% numbers are formatted as an arabic number, smaller numbers are
% formatted as zero. This can be changed using the package options
% described on page \pageref{sec:Options}.
%
% \subsection{\LaTeX\ macros}
%
% The four macros |\numstring|, |\Numstring|, |\ordstring| and
% |\Ordstring| are macros taking a \LaTeX-counter as their only
% argument.
%
% \DescribeMacro{\numstring} Usage: |\numstring| \marg{LaTeX counter}.
%
% Formats a \LaTeX\ counter in the range of 0 to 999,999,999 as a
% word.
%
% \DescribeMacro{\Numstring} Usage: |\Numstring| \marg{LaTeX counter}.
%
% Formats a \LaTeX\ counter in the range of 0 to 999,999,999 as words,
% where the first letter is a capital letter.
%
% \DescribeMacro{\ordstring} Usage: |\ordstring| \marg{LaTeX counter}.
%
% Formats a \LaTeX\ counter in the range of 0 to 999,999,999 as an ordinal
% word.
%
% \DescribeMacro{\Ordstring} Usage: |\Ordstring| \marg{LaTeX counter}.
%
% Formats a \LaTeX\ counter in the range of 0 to 999,999,999 as an ordinal
% word, where the first letter is a capital letter.
%
%
%
% \subsection{General macros}
%
% The four macros |\@numstring|, |\@Numstring|, |\@ordstring| and
% |\@Ordstring| as well as their aliases |\numstr|, |\Numstr|,
% |\ordstr| and |\Ordstr| are macros taking a number or a \TeX\ count
% register as their only argument.
%
% \DescribeMacro{\@numstring} \DescribeMacro{\numstr} Usage:
% |\@numstring| \marg{number} / |\numstr| \marg{number}.
%
% Formats a number or a \TeX\ count register in the range of 0 to
% 999,999,999 as words.
%
% \DescribeMacro{\@Numstring} \DescribeMacro{\Numstr} Usage:
% |\@Numstring| \marg{number} / |\Numstr| \marg{number}.
%
% Formats a number or a \TeX\ count register in the range of 0 to
% 999,999,999 as words, where the first letter is a capital letter.
%
% \DescribeMacro{\@ordstring} \DescribeMacro{\ordstr} Usage:
% |\@ordstring| \marg{number} / |\ordstr| \marg{number}.
%
% Formats a number or a \TeX\ count register in the range of 0 to
% 999,999,999 as an ordinal word.
%
% \DescribeMacro{\@Ordstring} \DescribeMacro{\Ordstr} Usage:
% |\@Ordstring| \marg{number} / |\Ordstr| \marg{number}.
%
% Formats a number or a \TeX\ count register in the range of 0 to
% 999,999,999 as an ordinal word, where the first letter is a capital
% letter.
%
% ^^A For debugging discretionary hyphens:
% ^^A\def\-{.\discretionary{}{}{}}
%
%
%
% \section{Examples}
%
% \newcommand{\zahlexamples}[1]{
% 	0 $\Longrightarrow$ #1{0}
%
% 	7 $\Longrightarrow$ #1{7}
%
%	13 $\Longrightarrow$ #1{13}
%
%	23 $\Longrightarrow$ #1{23}
%
%	42 $\Longrightarrow$ #1{42}
%
%	99 $\Longrightarrow$ #1{99}
%
%	127 $\Longrightarrow$ #1{127}
%
%	999 $\Longrightarrow$ #1{999}
%
% 	1000 $\Longrightarrow$ #1{1000}
%
%	1001 $\Longrightarrow$ #1{1001}
%
%	2004 $\Longrightarrow$ #1{2004}
%
%	2017 $\Longrightarrow$ #1{2017}
%
%	2029 $\Longrightarrow$ #1{2029}
%
%	9999 $\Longrightarrow$ #1{9999}
%
%	10000 $\Longrightarrow$ #1{10000}
%
%	101101 $\Longrightarrow$ #1{101101}
%
%	999999 $\Longrightarrow$ #1{999999}
%
%	1000000 $\Longrightarrow$ #1{1000000}
%
%	1234567 $\Longrightarrow$ #1{1234567}
%
%	123456789 $\Longrightarrow$ #1{123456789}
%
%	101101101 $\Longrightarrow$ #1{101101101}
%
%	999999999 $\Longrightarrow$ #1{999999999}
% }
%
% \addvspace{\baselineskip}\noindent Some examples using |\numstring|,
% |\numstr| and |\@numstring|:
%
% \zahlexamples{\numstr}
%
% \addvspace{\baselineskip}\noindent Some examples using |\ordstring|,
% |\ordstr| and |\@ordstring|:
%
% \zahlexamples{\ordstr}
%
%
% \addvspace{\baselineskip}\noindent Formatting the current page
% number (a \LaTeX\ counter) results in: Dies ist Seite
% \numstring{page} (|\numstring{page}|). Dies ist die \ordstring{page}
% Seite (|\ordstring{page}|). Seite: \Numstring{page}
% (|\Numstring{page}|). \Ordstring{page} Seite (|\Ordstring{page}|).
%
%
%
% \section{Options}\label{sec:Options}
%
% The package has the following option:
%
% \begin{description}
% 	\item[showrangeerrors]	If a number larger than 999,999,999
% 							is to be formatted, normally the number
% 							is not formatted as words, but using
% 							arabic digits. This option changes this
% 							behaviour to display an error instead,
% 							thus notifying you when you format too
% 							large a number
%
% \end{description}
%
%
%
% \section{Creating your own formatting}
%
% You can modify output of the \textsf{zahl2string} macros in a
% limited way by providing your own macros for formatting the numbers
% between `1' and `19. \emph{But note} that if you simply want to add
% something to the suffix, , i.e. if you want to format numbers with
% the suffix `tens' (`erstens', `zweitens' \ldots), then you can
% simply say |\ordstr{|\meta{number}|}ns|, resulting in i.e.
% `\ordstr{42}ns'.
%
%
% If on the other hand you want to create a more complicated
% formatting, then you have to do the following:
%
% \begin{itemize}
% 	\item	Create a macro for formatting the numbers `1' to `19',
% 			i.e. |\my@neunzehnte|. See the predefined macros in
% 			section \ref{sec:LabFor} on page \pageref{sec:LabFor},
% 			|\ns@neunzehn|, |\ns@neunzehns|, |\ns@neunzehne| and
% 			|\ns@neunzehnord| for examples and notes.
%
%			This macro has one parameter, the number (up to two
%			digits, in the range of `0' to `19'. `0' must expand to the
%			generic suffix, i.e. `stens'; `19' to `19' simply format
%			the number.
%
%			Do not forget to insert discretionary hyphens using |\-|,
%			or hyphenation will not be perfect!
%
% 	\item	Create another macro you want to call, i.e. |\mynumstring|.
%			This macro takes one parameter, the number, and calls
%			|\ns@numstr| using the following parameters:
%
%			\begin{enumerate}
% 				\item	The number to be formatted (the parameter to
% 						|\mynumstring|).
%
% 				\item	The macro for formatting numbers `1' to `19',
% 						i.e. |\my@neunzehnte|.
%
% 				\item	The value that represents the number zero,
% 						i.e. `nulltens'.
%
% 				\item	The suffix for numbers larger than 999,999,999,
% 						i.e. `tens'.
%
%			\end{enumerate}
%
% 	\item	Call the macro |\mynumstring| with the number to format.
%
% \end{itemize}
% If you want to create a macro to format a \LaTeX-counter, create an
% additional macro, i.e. |\myLnumstring|, that calls |\mynumstring| by
% saying:
%
% \begin{verbatim}
% \newcommand{\myLnumstring}[1]{%
%	\expandafter\mynumstring\csname c@#1\endcsname%
% }
% \end{verbatim}
% See also the notes and predefined macros in section \ref{sec:LabFor}
% on page \pageref{sec:LabFor}.
%
%
%
% \section{Notes/Limitations}
%
% \begin{itemize}
%
%	\item	Ordinal numbers larger than 999999 do not look that
%			good, as i.e. 1000000 gets formatted as
%			`\ordstr{1000000}' instead of `einmillionste'.
%
% \end{itemize}
%
%
%
% \StopEventually{}
%
% \section{Implementation}
%
% \subsection{Main macros}
%
%
% \begin{macro}{\numstring}
%
% Usage: |\numstring| \marg{LaTeX counter}.
%
% Formats a \LaTeX\ counter in the range of 0 to 999,999,999 as words.
%
%    \begin{macrocode}
\newcommand{\numstring}[1]{%
	\expandafter\@numstring\csname c@#1\endcsname%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\Numstring}
%
% Usage: |\Numstring| \marg{LaTeX counter}.
%
% Formats a \LaTeX\ counter in the range of 0 to 999,999,999 as words. The
% first letter is uppercase.
%
%    \begin{macrocode}
\newcommand{\Numstring}[1]{%
	\expandafter\@Numstring\csname c@#1\endcsname%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\ordstring}
%
% Usage: |\ordstring| \marg{LaTeX counter}.
%
% Formats a \LaTeX\ counter in the range of 0 to 999,999,999 as an ordinal
% word.
%
%    \begin{macrocode}
\newcommand{\ordstring}[1]{%
	\expandafter\@ordstring\csname c@#1\endcsname%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\Ordstring}
%
% Usage: |\Ordstring| \marg{LaTeX counter}.
%
% Formats a \LaTeX\ counter in the range of 0 to 999,999,999 as an ordinal
% word. The first letter is uppercase.
%
%    \begin{macrocode}
\newcommand{\Ordstring}[1]{%
	\expandafter\@Ordstring\csname c@#1\endcsname%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@numstring}
%
% Usage: |\@numstring| \marg{number or \TeX\ count register}.
%
% Formats a number or a \TeX\ count register in the range of 0 to
% 999,999,999 as words.
%
%    \begin{macrocode}
\newcommand{\@numstring}[1]{%
	\ns@numstr{#1}\ns@neunzehns{null}{}%
}
%    \end{macrocode}
%
% \end{macro}
%
%
% \begin{macro}{\@Numstring}
%
% Usage: |\@Numstring| \marg{number or \TeX\ count register}.
%
% Formats a number or a \TeX\ count register in the range of 0 to
% 999,999,999 as words. The first letter is uppercase.
%
%    \begin{macrocode}
\newcommand\@Numstring[1]{%
	\expandafter\@@Numstring\expandafter{\number#1}%
}
%    \end{macrocode}
%
% \end{macro}
%
%
% \begin{macro}{\@@Numstring}
%
% Support macro for |\@Numstring| to make |\@Numstring| robust.
%
% \changes{1.2.1}{2004/10/20}{Added}
%
%    \begin{macrocode}
\DeclareRobustCommand{\@@Numstring}[1]{%
	\protected@edef\@tempa{\@numstring{#1}}%
	\expandafter\MakeUppercase\@tempa%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@ordstring}
%
% Usage: |\@ordstring| \marg{number or \TeX\ count register}.
%
% Formats a number or a \TeX\ count register in the range of 0 to
% 999,999,999 as an ordinalword, i.e. `erste', `zweite' et cetera.
%
%    \begin{macrocode}
\newcommand{\@ordstring}[1]{%
	\ns@numstr{#1}\ns@neunzehnord{null\-te}{te}%
}
%    \end{macrocode}
%
% \end{macro}
%
%
% \begin{macro}{\@Ordstring}
%
% Usage: |\@Ordstring| \marg{number or \TeX\ count register}.
%
% Formats a number or a \TeX\ count register in the range of 0 to
% 999,999,999 as an ordinalword, i.e. `Erste', `Zweite' et cetera. The
% first letter is uppercase.
%
%    \begin{macrocode}
\newcommand{\@Ordstring}[1]{%
	\expandafter\@@Ordstring\expandafter{\number#1}%
}
%    \end{macrocode}
%
% \end{macro}
%
%
% \begin{macro}{\@@Ordstring}
%
% Support macro for |\@Ordstring| to make |\@Ordstring| robust.
%
% \changes{1.2.1}{2004/10/20}{Added}
%
%    \begin{macrocode}
\DeclareRobustCommand{\@@Ordstring}[1]{%
	\protected@edef\@tempa{\@ordstring{#1}}%
	\expandafter\MakeUppercase\@tempa%
}
%    \end{macrocode}
% \end{macro}
%
%
%
% We provide public aliases for the macros. The macros beginning with
% |@| are still necessary in order to be able to format the page
% number as a string. (see \textsf{ltpageno.dtx})
%
% \changes{1.2}{2004/09/08}{Added}
%
%    \begin{macrocode}
\let\numstr\@numstring%
\let\Numstr\@Numstring%
\let\ordstr\@ordstring%
\let\Ordstr\@Ordstring%
%    \end{macrocode}
%
%
% \subsection{Option processing}
%
% \changes{1.1}{2004/08/13}{Options `publicnumstr' and `showrangeerrors'
% added.}
% \changes{1.2}{2004/09/08}{Option `publicnumstr' deprecated}
%
%    \begin{macrocode}
\DeclareOption{publicnumstr}{%
	\PackageWarning{zahl2string}{Option `publicnumstr' is %
		deprecated and will be removed in version 1.3}%
}
%    \end{macrocode}
%
%
% \begin{macro}{\ns@numoutofrange}
%
% Formats a number that is too large to be formatted as words.
%
% Usage: |\ns@numoutofrange| \marg{number} \marg{suffix}.
%
% This macro is redefined to show an error message using the package
% option |showrangeerrors|.
%
%    \begin{macrocode}
\def\ns@numoutofrange#1#2{%
	\number#1#2%
}
%    \end{macrocode}
% \end{macro}
%

%    \begin{macrocode}
\DeclareOption{showrangeerrors}{%
	\def\ns@numoutofrange#1#2{%
		\PackageError{zahl2string}{The number `#1' is too large %
			to be formatted using zahl2string}{The largest possible %
			number is 999,999,999.}
	}%
}
%    \end{macrocode}
%
%
%
%    \begin{macrocode}
\ProcessOptions\relax
%    \end{macrocode}
%
%
%
% \subsection{Internal macros}
%
% \subsubsection{Splitting and formatting a number}
%
% \begin{macro}{\ns@numstr}
%
% Base macro for formatting a number.
%
% Usage: |\ns@numstr| \marg{number} \marg{macro} \marg{nullvalue}
% \marg{suffix}, where \meta{macro} is the macro to use for the
% numbers between |1| and |19|, as these require some special
% treatment, \meta{nullvalue} is the value this macro expands to when
% \meta{number} is zero, and \meta{suffix} is text added as a suffix
% to a number larger than 999,999,999.
%
% \changes{1.1}{2004/08/08}{Macro added}
%
%    \begin{macrocode}
\def\ns@numstr#1#2#3#4{%
	\ifnum\number#1<\@ne%
		#3%
	\else\ifnum\number#1<1000000000 %
		\expandafter\ns@numstring\expandafter{\number#1}#2%
	\else%
		\ns@numoutofrange{#1}{#4}%
	\fi\fi%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\ns@numstring}
%
% \changes{1.1}{2004/08/14}{Reimplemented to avoid using up TeX's
% space for control sequences}
%
% Formats a number as words.
%
% Usage: |\ns@numstring| \marg{number} \marg{macro}, where
% \meta{macro} is the macro to use for the numbers between |1| and
% |19|, as these require some special treatment.
%
% \emph{Note: \meta{number} must be a real number consisting of digits
% in the range 0 to 9! It must not be a \TeX\ count register!}
%
% How does this work? Modulo operations are not trivial in \TeX\ as in
% order to achieve $a \bmod b$ you have to calculate $a - (a \div b)
% \times b$. This is complicated and also not expandable, so another
% solution has to be found.
%
% \TeX's capabilities of parsing text using macro arguments are fairly
% strong, so why not use them? It would be much easier if it would be
% possible of defining a macro with, say, six parameters, where each
% parameter is one digit of the number to be formatted. Then it would
% be possible to directly access each digit (or several digits
% combined by grouping several parameters) without having to perform
% lengthy modulo calculations.
%
% Adding leading zeros to a number is easily done by comparing it
% using |\ifnum| and adding zeros if the number is too small. However,
% the macro must not receive the |\ifnum| et.al. tokens as a
% parameter, but the result of the expansion, that is the number with
% leading zeros.
%
% |\expandafter| would not suffice, as it expands a macro only once,
% not fully. |\edef| would accomplish the task at hand, however
% |\edef| is not fully expandable.
%
% So what do we do? We take advantage of the fact that when expanding
% an |\ifcase|, \TeX\ goes on expanding until it has made sure that
% the number for the |\ifcase| is complete. So immediately after the
% |\ifcase| we launch into several nested |\ifnum|s, which \TeX\
% expands dutifully in order to determine the number to use.
%
% What these nested |\ifnum|s do is the following: Depending on the
% length of \meta{number}, they expand to a digit between one and
% nine, one being the digit if \meta{number} is less than 10 and nine
% being the digit if \meta{number} is larger than 99,999,999.
%
% Then \TeX\ uses this digit between one and nine to jump to the
% appropriate part of the |\ifcase|-clause. There \meta{number} is
% prefixed with the necessary amount of zeros to result in a number
% exactly nine digits long: For the digit one (resulting from the
% nested |\ifnum|s), eight leading zeros have to be prefixed, as
% \meta{number} is only one digit long, for the digit two, seven zeros
% are prefixed, as \meta{number} is less than 100 (but more than 9) et
% cetera, until for digit nine no zeros have to be prefixed, as
% \meta{number} is already nine digits long.
%
% Let's have an example: Suppose \meta{number} is 42. Then the result
% of the nested |\ifnum|s is 2, as \meta{number} is not less than 10
% but less than 100 (the second |\ifnum| is true). This 2 leads to
% jumping to part after the second |\or| (before the first |\or| is
% the part for the number 0, in this case left blank, and after the
% first |\or| for the number 1), which is |0000000#1|. |#1| is 42. So
% the result is: |000000042|, a number prefixed with leading zeros and
% exactly nine digits long.
%
% Another example: Suppose \meta{number} is 12,345,678. Then the
% result of the nested |\ifnum|s is 8, as the eigths |\ifnum| is true
% (less than 100,000,000 but not less than 10,000,000). Then only one
% zero is prefixed, resulting in |012345678|.
%
% However, we are not finished yet, as \TeX\ does not expand further.
% So we are left (picking up the second example above) with this:
% |012345678\or12345678\or| (the second incarnation of |12345678| is
% due to the ninth part of the |\ifcase| clause, |\or#1|).
%
% We do not need all this |\or| baggage, we only want the number. But
% \TeX\ is good at matching text using macros with delimited
% parameters, so we just define |\ns@@numstring| in a way that gobbles
% up the first |\or| and whatever follows.
%
% And we are done: We have a number padded perfectly with leading
% zeros to a length of nine digits!
%
% \paragraph{Implementation note} In Version 1.0, we used |\csname|
% \ldots\ |\endcsname| to add the leading zeros, as |\csname| \ldots\
% |\endcsname| expands everything inbetween until only unexpandable
% tokens remain, in this case digits (the |\ifnum|s are expanded).
% Afterwards, the resulting control sequence was converted into
% separate tokens using |\string| and finally, the backslash at the
% beginning was gobbled by |\ns@@numstring| as its first (and unused)
% argument.
%
% Unfortunately, this had its price: For every number we formatted
% using |\ns@numstring| and that had not been formatted before, a new
% entry was inserted into the hash table \TeX\ uses to store all
% control sequences. So if you had a document where you formatted a
% lot of numbers this way, you would run out of hash table space, and
% \TeX\ would complain. (The number of hash table entries used is
% indicated in the |log|-file as `multiletter control sequences'.)
%
% This was less than optimal, so we changed the implementation to this
% |\ifcase|-|\ifnum| construct.
%
%    \begin{macrocode}
\def\ns@numstring#1#2{%
	\expandafter\ns@@numstring%
		\ifcase%
			\ifnum#1<10 1%
%    \end{macrocode}
%
% Why are the constants predefined by the \LaTeX-kernel used instead
% of numbers? Because they save tokens: |1000| are four tokens, |\@m|
% is only one.
%
%    \begin{macrocode}
			\else\ifnum#1<100 2%
			\else\ifnum#1<\@m 3%
			\else\ifnum#1<\@M 4%
			\else\ifnum#1<100000 5%
			\else\ifnum#1<1000000 6%
			\else\ifnum#1<10000000 7%
			\else\ifnum#1<100000000 8%
			\else9%
			\fi\fi\fi\fi\fi\fi\fi\fi %
		\or00000000#1% case 1: Add 8 leading zeros
		\or0000000#1%  case 2: Add 7 leading zeros
		\or000000#1%   case 3: Add 6 leading zeros
		\or00000#1%    case 4: Add 5 leading zeros
		\or0000#1%     case 5: Add 4 leading zeros
		\or000#1%      case 6: Add 3 leading zeros
		\or00#1%       case 7: Add 2 leading zeros
		\or0#1%        case 8: Add 1 leading zero
		\or#1%         case 9: Add no leading zeros
%    \end{macrocode}
%
% The next |\or| is only necessary because |\ns@@numstring| needs an
% |\or| as a delimiter of the number:
%
%    \begin{macrocode}
		\or%
%    \end{macrocode}
%
% The last parameter to |\ns@@numstring| is \meta{macro}; we delimit
% it using |\@nil|:
%
%    \begin{macrocode}
	\@nil#2%
%    \end{macrocode}
%
% Finally we end the |\ifcase| (note that this is \emph{after} the
% number has been formatted):
%
%    \begin{macrocode}
	\fi%
}
%    \end{macrocode}
%
% \end{macro}
%
%
% \begin{macro}{\ns@@numstring}
%
% Expands to a number in words between |1| and |999,999,999|.
%
% Usage: |\ns@@numstring| \marg{9. digit} \marg{8. digit} \marg{7.
% digit} \marg{6. digit} \marg{5. digit} \marg{4. digit} \marg{3rd -
% 1st digit} \marg{(ignored)} \marg{macro}, where \meta{macro} is, as
% is the case with |\ns@numstring|, the macro to use for the numbers
% between |1| and |19|, as these require some special treatment.
%
% |\or| and the following |#8| (\meta{ignored}) gobble up whatever was
% left from the expansion of |\ifcase| in |\ns@numstring|. |\@nil|
% acts as a delimiter for the last parameter, \meta{macro}.
%
% \changes{1.1}{2004/08/08}{Formatting of millions added.}
% \changes{1.1}{2004/08/14}{Changed to match reeimplementation of
% ns@numstring.}
%
%    \begin{macrocode}
\def\ns@@numstring#1#2#3#4#5#6#7\or#8\@nil#9{%
	\ifnum#1#2#3>\z@
		\ns@million#1#2#3%
%    \end{macrocode}
%
% We insert a space if a number follows:
%
%    \begin{macrocode}
		\ifnum#4#5#6>\z@\space\fi%
	\fi%
	\ifnum#4#5#6>\z@%
		\ns@hundred#4#5#6{#1#2#3}{#4#5}\ns@neunzehn%
%    \end{macrocode}
%
% If there has been a number larger than one before the `tausend',
% insert a discretionary hyphen before:
%
%    \begin{macrocode}
		\ifnum#4#5#6>\@ne\-\fi%
		tau\-send%
%    \end{macrocode}
%
% If there will be a number after the `tausend', insert a
% discretionary hyphen after:
%
%    \begin{macrocode}
		\ifnum#7>\z@\-\fi%
	\fi%
	\ns@hundred#7{#4#5#6}1#9%
}
%    \end{macrocode}
%
% \end{macro}
%
%
% \begin{macro}{\ns@million}
%
% Expands to millions.
%
% Usage: |\ns@million| \marg{third digit} \marg{second digit}
% \marg{first digit}.
%
% \changes{1.1}{2004/08/08}{Macro added.}
%
%    \begin{macrocode}
\def\ns@million#1#2#3{%
	\ifnum#1#2#3=\@ne%
		\ns@hundred#1#2#301\ns@neunzehne%
		\space%
		Mil\-lion%
	\else%
		\ns@hundred#1#2#301\ns@neunzehns%
		\space%
		Mil\-lio\-nen%
	\fi%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\ns@hundred}
%
% Expands to a number in words between |1| and |100|.
%
% Usage: |\ns@hundred| \marg{third digit} \marg{second digit}
% \marg{first digit} \marg{shownumber} \marg{showone}
% \marg{macro}.
%
% \meta{shownumber} defines if the number before the |hundert|
% (`hundred') should be shown, i.e. |einhundert| (`onehundred')
% instead of |hundert|. |0| is |false|, everything else |true|.
% Can contain more than one digit.
%
% \meta{showone} defines if \meta{macro} should be called for the
% number |1|. |0| is |false|, everything else |true|. Can contain more
% than one digit.
%
% What does all this code do? First the third digit (`hundred'),
% contained in |#1|, is expanded -- if it is not zero. However, there
% is a catch: If the third digit is one, this digit is only included
% in the result of this macro if |#4| says so. The reason is that
% normally you would say |hunderteins| (`101') instead of
% |einhunderteins| -- but not if there is a fourth digit. Then the
% digit has to be included in the output of the macro, i.e.
% |tausendeinhunderteins|
%
% So we want to include the digit in the output of the macro, if |#3|
% is larger than one \emph{or} |#4| is larger than zero. We could use
% two |\ifnum|s to accomplish this, but it can be combined into a
% single |\ifnum|, saving tokens and time:
%
% We check if |#4#1| is larger than one. That means that if |#1|, the
% third digit, is larger than one, it is included in the output. But
% that also means that if |#4| is not zero, |#4#1| is always at least
% |10|, which is also larger than one and exactly what we want.
%
% After successfully processing the third digit, the remaining last
% two digits (|#2| and |#3|) are not really complicated anymore. We
% perform some special treatment of the numbers between |1| and |19|
% as these numbers are not constructed systematically. Here we have to
% perform a check similar to the one performed for the third digit: We
% have to check if we have to output the number if it is |1|, using
% the same trick for a logical |or| as before, only this time with
% |#5|, |#2| and |#3|.
%
% The macro to output |1| to |19| is parametrized as |#6| in order to
% be able to use different macros for normal numbers and ordinal
% numbers.
%
% If the last two digits are larger than |19|, we first output the
% third digit using |\ns@neunzehn|, followed by |und| (`and') and then
% the second digit. Here we don't have to use the parametrized macro
% as before, as the ordinal suffix is appended at the end of the
% number, not inbetween.
%
% But where to get the suffix from? We could pass it as a macro, but
% that would be tedious. So we simply define the macro to output the
% numbers |1| to |19| (|\ns@neunzehns| for normal numbers and
% |\ns@neunzehnord| for ordinal numbers) to output the suffix if
% called with |0| as its parameter.
%
% And we are done!
%
%    \begin{macrocode}
\def\ns@hundred#1#2#3#4#5#6{%
%    \end{macrocode}
%
% We expand the third digit:
%
%    \begin{macrocode}
	\ifnum#1>\z@%
%    \end{macrocode}
%
% Logical |OR| hidden in |#4#1| (see above):
%
%    \begin{macrocode}
		\ifnum#4#1>\@ne\ns@neunzehn#1\-\fi%
		hun\-dert%
%    \end{macrocode}
%
% We insert a discretionary hyphen, if a number follows:
%
%    \begin{macrocode}
		\ifnum#2#3>\z@\-\fi%
	\fi%
%    \end{macrocode}
%
% We expand the first an second digit:
%
%    \begin{macrocode}
	\ifnum#2#3<20 %
%    \end{macrocode}
%
% Again: Logical |OR| in |#5#2#3|:
%
%    \begin{macrocode}
		\ifnum#5#2#3>\@ne#6{#2#3}\fi%
	\else%
		\ifnum#3>\z@\ns@neunzehn#3\-und\-\fi%
		\ns@neunzig#2%
		#60%
	\fi%
}
%    \end{macrocode}
%
% \end{macro}
%
%
% \subsubsection{Macros for formatting `1' to `19'}\label{sec:LabFor}
%
% Very important: The position for |0| must expand to the suffix of
% the number (\emph{any number}), see the explanations for
% |\ns@hundred| above. If it expands to a text (as opposed to
% |\@empty|), this text must be prefixed by a discretionary hyphen!
%
%
% \begin{macro}{\ns@neunzehn}
%
% Expands to |ein| (`1') to |neunzehn| (`19').
%
% \changes{1.1}{2004/08/08}{Hyphenation added.}
%
%    \begin{macrocode}
\def\ns@neunzehn#1{%
	\ifcase#1\@empty\or ein\or zwei\or drei\or vier\or f\"unf\or sechs\or%
		sie\-ben\or acht\or neun\or zehn\or elf\or zw\"olf\or drei\-zehn\or%
		vier\-zehn\or f\"unf\-zehn\or sech\-zehn\or sieb\-zehn\or%
		acht\-zehn\or neun\-zehn\fi%
}
%    \end{macrocode}
%
% \end{macro}
%
%
% \begin{macro}{\ns@neunzehns}
%
% Expands to |eins| (`1') to |neunzehn| (`19'). |0| expands to
% |\@empty|.
%
% Why |\@empty| instead of nothing? Because then \TeX\ would insert a
% |\relax| before the first |\or| in order to finish expansion of the
% number. This |\relax| would remain in the output and would stay
% there even when |\edef|ed, whereas |\@empty| expands to nothing.
%
% This is necessary for |\Numstring| and |\Ordstring|, as they convert
% the first token of the |\edef|ed result of |\numstring| and
% |\ordstring| to uppercase, and they need this token to be the first
% letter of the number, not |\relax|.
%
%    \begin{macrocode}
\def\ns@neunzehns#1{%
	\ifcase#1\@empty\or eins\else\ns@neunzehn{#1}\fi%
}
%    \end{macrocode}
%
% \end{macro}
%
%
\def\ns@neunzehne#1{%
	\ifcase#1\@empty\or ei\-ne\else\ns@neunzehn{#1}\fi%
}
%
%
% \begin{macro}{\ns@neunzehnord}
%
% Expands to |erste| (`1st') to |neunzehnte| (`19th'). |0| expands to
% |ste|.
%
% \changes{1.1}{2004/08/08}{Hyphenation added.}
%
%    \begin{macrocode}
\def\ns@neunzehnord#1{%
	\ifcase#1\-ste\or er\-ste\or zwei\-te\or drit\-te\or vier\-te\or%
		f\"unf\-te\or sech\-ste\or sieb\-te\or ach\-te\or neun\-te\or%
		zehn\-te\or elf\-te\or zw\"olf\-te\or drei\-zehn\-te\or%
		vier\-zehn\-te\or f\"unf\-zehn\-te\or sech\-zehn\-te\or%
		sieb\-zehn\-te\or acht\-zehn\-te\or neun\-zehn\-te\fi%
}
%    \end{macrocode}
%
% \end{macro}
%
%
% \begin{macro}{\ns@neunzig}
%
% Expands to |zwanzig| (twenty) to |neunzig| (ninety) in steps of ten.
%
% \changes{1.1}{2004/08/08}{Hyphenation added.}
%
%    \begin{macrocode}
\def\ns@neunzig#1{%
	\ifcase#1\or\or zwan\-zig\or drei\ss ig\or vier\-zig\or%
		f\"unf\-zig\or sech\-zig\or sieb\-zig\or acht\-zig\or%
		neun\-zig\fi%
}
%    \end{macrocode}
%
% \end{macro}
%
% \Finale
% \PrintChanges
% \PrintIndex
\endinput