summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/fnumprint/fnumprint.dtx
blob: 88eccd6e4593db90ccd0472b7cf3230db428238f (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
% \iffalse meta-comment
%
% Copyright (C) 2012-2013 by Robin Schneider <ypid23@aol.de>
%
% 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 2005/12/01 or later.
%
% The Current Maintainer of this work is Robin Schneider.
%
% This work consists of the files fnumprint.dtx and fnumprint.ins
% and the derived filebase fnumprint.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{fnumprint.dtx}
%</driver>
%<package>%% See file 'fnumprint.dtx' for copyright and licence.
%<package>\NeedsTeXFormat{LaTeX2e}[1998/12/01]
%<package>\ProvidesPackage{fnumprint}
%<*package>
    [2012/08/27 v1.1a Printing fancy numbers]
%</package>
%
%<*driver>
\documentclass[english]{ltxdoc}
\newcommand{\PackageURL}{https://github.com/ypid/latex-packages/tree/master/fnumprint}
\newcommand{\PackageCTANURL}{http://www.ctan.org/pkg/fnumprint}
\newcommand{\PackageAuthor}{Robin Schneider}
\newcommand{\PackageAuthorEmail}{ypid23@aol.de}
\newcommand{\PackageName}{\PrintPackage{fnumprint}}
\newcommand{\PrintPackage}[1]{\textsf{#1}}
\usepackage{fnumprint}
\usepackage{
  babel,
  csquotes,
  xcolor,
  url,
  hypdoc,
}
\GetFileInfo{fnumprint.dtx}
\hypersetup{
  pdftitle={A manual for \PackageName},
  pdfauthor={\PackageAuthor{} <\PackageAuthorEmail>},
  pdfsubject={\fileinfo},
  baseurl={\PackageURL},
  pdfkeywords={This document corresponds to \PackageName~\fileversion,
    dated \filedate}
}

\title{The \PackageName{} package\thanks{This document
corresponds to \PackageName~\fileversion, dated \filedate.}}
\author{\PackageAuthor \\
  \texttt{\href{mailto:\PackageAuthorEmail?subject=LaTeX package fnumprint%
    \&body=Dear Robin Schneider,}%
    {\PackageAuthorEmail}%
  }%
}

\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{fnumprint.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{101}
% \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         \~}
%
% \changes{v0.1}{2011/06/12}{Initial version} %% ^^A date guessed
% \changes{v1.0}{2012/08/22}{Wrote this documentation and the \LaTeX{}-package
% and added support for English}
% \changes{v1.1}{2012/08/27}{Added optional parameter \enquote{ein}}
% \changes{v1.1a}{2012/08/27}{Added support for real numbers}
%
% \DoNotIndex{\RequirePackage, \DeclareOption, \ProcessOptions}
% \DoNotIndex{\PackageWarning, \MessageBreak}
% \DoNotIndex{\DeclareRobustCommand, \newcommand, \renewcommand}
% \DoNotIndex{\newenvironment}
% \DoNotIndex{\if, \else, \fi, \ifcase, \or, \ifthenelse, \AND, \value, \relax}
% \DoNotIndex{\equal, \@currname, \newcounter, \setcounter, \(, \), \NOT, \OR}
% \DoNotIndex{\endinput}
%
% \maketitle
%
% \phantomsection
% \addcontentsline{toc}{section}{\abstractname}
% \begin{abstract}
% The \PrintPackage{fnumprint} package can decide to typeset a
% number either as number or as word name (only in English or German). \\
% Information site on CTAN: \url{\PackageCTANURL} \\
% Fork me on GitHub: \url{\PackageURL} \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
% The \PackageName{} package defines two macros which decide to
% typeset a number either as Arabic number or as word name for the number. If
% the number is between zero and twelve (including zero and twelve) then the
% word name will be used. This package uses the \PrintPackage{zahl2string}
% package to convert a number in the word name in German. The conversion of a
% number (0--12) to the English word name is implemented by this package. If
% the number is outside of the range then it will be typesetted with the
% \PrintPackage{numprint} package.
%
% \section{Usage}
% Just load the package placing
% \begin{quote}
%   |\usepackage{fnumprint}|
% \end{quote}
% in the preamble of your \LaTeXe{} source file. In this case the last by
% \PackageName{} supported language given as class option will be
% used. You can overwrite this with a package option like
% this:
% \begin{quote}
%   |\usepackage[english]{fnumprint}|
% \end{quote}
%
% \DescribeMacro{\fnumprintc}
% The macro |\fnumprintc| \oarg{eins} \marg{\LaTeX{} counter name} takes a
% name of a LaTeX counter as not optional parameter and typesets it's
% value. The optional parameter is only active if the German language was
% selected. In this case it can be used to typeset \enquote{ein} instead of
% \enquote{eins}. This is for example necessary if you would like to typeset
% \enquote{ein Jahr}.
%
% \DescribeMacro{\fnumprint}
% The macro |\fnumprint| \oarg{eins} \marg{number} is like the |\fnumprintc|
% macro but it takes a number or a macro that expands to a number. A \TeX{}
% counter can also be used with this macro.
%
% \section{Examples}
% \begin{tabular}{ll}
%   \textbf{macro}           & \textbf{expanded macro} \\
%   |\fnumprint{-1}|         & \fnumprint{-1} \\
%   |\fnumprint{0}|          & \fnumprint{0} \\
%   |\fnumprint{1}|          & \fnumprint{1} \\
%   |\fnumprint{3.14}|       & \fnumprint{3.14} \\
%   |\fnumprint{10}|         & \fnumprint{10} \\
%   |\fnumprint{12}|         & \fnumprint{12} \\
%   |\fnumprint{13}|         & \fnumprint{13} \\
%   |\fnumprint{\the\month}| & \fnumprint{\the\month} \\
%   |\fnumprint{\the\day}|   & \fnumprint{\the\day} \\
%   |\fnumprintc{page}|      & \fnumprintc{page} \\
% \end{tabular}
%
% \section{ToDo}
% Here are some things that could be useful.
% \begin{itemize}
%   \item Provide more features implemented by the \PrintPackage{zahl2string}
%     package and create macros which implement these features for the
%     English language.
% \end{itemize}
%
% \StopEventually{}
%
% \section{Implementation}
% \iffalse
%<*package>
% \fi
% This package depends on these packages.
%    \begin{macrocode}
\RequirePackage{xifthen}
\RequirePackage[autolanguage]{numprint}
%    \end{macrocode}
% \subsection{Language checking}
% I used the counter |fnumprint@language| to save the (last) selected language.
% Meaning from the counter values:
%
% \begin{tabular}{rl}
%   \textbf{value}   & \textbf{meaning} \\
%   0   & no supported language selected \\
%   1   & German selected \\
%   2   & English selected \\
% \end{tabular}
%    \begin{macrocode}
\newcounter{fnumprint@language}
\setcounter{fnumprint@language}{0}
\DeclareOption{german}{\setcounter{fnumprint@language}{1}}
\DeclareOption{ngerman}{\setcounter{fnumprint@language}{1}}
\DeclareOption{english}{\setcounter{fnumprint@language}{2}}
\DeclareOption{USenglish}{\setcounter{fnumprint@language}{2}}
\DeclareOption{american}{\setcounter{fnumprint@language}{2}}
\DeclareOption{UKenglish}{\setcounter{fnumprint@language}{2}}
\DeclareOption{british}{\setcounter{fnumprint@language}{2}}
\DeclareOption{canadian}{\setcounter{fnumprint@language}{2}}
\DeclareOption{australian}{\setcounter{fnumprint@language}{2}}
\DeclareOption{newzealand}{\setcounter{fnumprint@language}{2}}
\ProcessOptions\relax
%    \end{macrocode}
% If none of the supported languages was selected a package warning will appear.
%    \begin{macrocode}
\ifcase\value{fnumprint@language}
  \PackageWarning{\@currname}{No supported language selected
    \MessageBreak
    This package supports only English and German
    \MessageBreak
    There will be no word names printed}
%    \end{macrocode}
% The zahl2string package will only be loaded if it is necessary.
%    \begin{macrocode}
\or
  \RequirePackage{zahl2string}
%    \end{macrocode}
% \begin{macro}{\ns@en@neunzehn}
% This internal marco expands to the English word name for a number.
% It only goes from 0 to 19. It will only be defined if it is necessary.
%    \begin{macrocode}
\or
  \newcommand{\ns@en@neunzehn}[1]{%
    \ifcase#1 zero\or one\or two\or three\or four\or five\or six\or%
    seven\or eight\or nine\or ten\or eleven\or twelve\or thirteen\or%
    fourteen\or fifteen\or sixteen\or seventeen\or%
    eighteen\or nineteen\fi%
  }
\fi
%    \end{macrocode}
% \end{macro}
% \subsection{Macro definition}
% \begin{macro}{\fnumprint}
% Here is the |\fnumprint| macro definition.
% It takes one not optional parameter.
% The parameter must be a number or a macro which expands to a number.
% It can also take a optional parameter which replaces the German word
% \enquote{eins} with \enquote{ein}.
%    \begin{macrocode}
\DeclareRobustCommand{\fnumprint}[2][]{%
  \ifthenelse{\NOT \(\isin{,}{#2} \OR \isin{.}{#2} \)
  \AND -1 < #2 \AND #2 < 13}{%
    \ifthenelse{\value{fnumprint@language} = 1}{%
      \ifthenelse{\equal{#1}{ein} \AND #2 = 1}{ein}{\numstr{#2}}%
    }{%
      \ifthenelse{\value{fnumprint@language} = 2}{%
        \ns@en@neunzehn{#2}%
      }{\numprint{#2}}%
    }%
  }{\numprint{#2}}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\fnumprintc}
% Here is the |\fnumprintc| macro definition.
% It takes one not optional parameter.
% The parameter must be the name of a \LaTeX{} counter.
% It can also take a optional parameter which replaces the German word
% \enquote{eins} with \enquote{ein}.
%    \begin{macrocode}
\DeclareRobustCommand{\fnumprintc}[2][]{%
  \ifthenelse{-1 < \value{#2} \AND \value{#2} < 13}{%
    \ifthenelse{\value{fnumprint@language} = 1}{%
    \ifthenelse{\equal{#1}{ein} \AND \value{#2} = 1}{ein}{\numstring{#2}}}{%
      \ifthenelse{\value{fnumprint@language} = 2}{%
        \ns@en@neunzehn{\value{#2}}%
      }{\cntprint{#2}}%
    }%
  }{\cntprint{#2}}%
}
\endinput
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput