Debian Codegraph @

texmf-dist/doc/latex/currency/currency_doc.tex

raw
1 \documentclass[12pt,add-index]{cnltx-doc}
2 \usepackage[T1]{fontenc}
3 \usepackage[english]{babel}
4 \usepackage[utf8]{inputenc}
5 \usepackage{csquotes}
6 \usepackage{currency}
7 \usepackage{enumitem}
8 \usepackage{filecontents}
9 \usepackage[
10 backend=biber,
11 %style=cnltx, % incompatible with biblatex 3.3
12 sortlocale=en_EN,
13 indexing=cite,
14 useprefix]{biblatex}
15 \usepackage{nicefrac}
16
17 \addbibresource{\jobname.bib}
18
19 \newnote*\doccorrectedsinceversion[1]{Documentation corrected in version~#1}
20
21
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23 \begin{filecontents*}{\jobname.bib}
24 @online{iso,
25 author = {{ISO committee}},
26 title = {Currency codes - ISO 4217},
27 url = {http://www.iso.org/iso/home/standards/currency_codes.htm},
28 year = {2015},
29 }
30
31 @online{iso:wikipedia,
32 editor = {Wikipedia},
33 title = {ISO 4217},
34 url = {https://en.wikipedia.org/wiki/ISO_4217},
35 year = {2015},
36 }
37
38 @package{siunitx,
39 author = {Wright, Joseph},
40 title = {\texttt{siunitx} — A comprehensive (SI) units package},
41 date = {2014-10-28},
42 note = {Version 2.6d},
43 }
44
45 @package{translations,
46 author = {Niederberger, Clemens},
47 title = {\texttt{translations}, Internationalization of \LaTeX2e Packages},
48 date = {2017-05-16},
49 note = {Version 1.6},
50 }
51
52 \end{filecontents*}
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
55 \setcnltx{
56 package = {currency},
57 info = {Print monetary units} ,
58 url = https://github.com/antoinelejay/currency.git ,
59 authors = Antoine Lejay,
60 email = [email protected] ,
61 abstract = {%
62 This packages aims at typesetting monetary units in a consistent way.
63 } ,
64 add-cmds =
65 {
66 dXXX,cXXX,CurrencySetup
67 } ,
68 add-silent-cmds = {
69 } ,
70 index-setup = { othercode=\footnotesize, level=\section , noclearpage } ,
71 makeindex-setup = { columns=3, columnsep=1em }
72 }
73
74 % Some currencies definition
75 \DefineCurrency{EUR}{name={euro},plural={euros},symbol={\euro},iso={EUR},kind=iso,base=2}
76 \DefineCurrency{USD}{name={dollar},plural={dollars},symbol={\$},iso={USD},kind=iso,base=2}
77 \DefineCurrency{JPY}{name={yen}, plural={yens}, symbol={\textyen}, iso={JPY}, kind=iso,cents=false}
78 \DefineCurrency{GBP}{name={pound},pre=true,plural={pounds}, symbol={\pounds}, iso={GBP}, kind=iso,base=2}
79
80
81 \begin{document}
82
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 %%% Introduction
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 \section{Introduction}
87
88 Strangely enough, it seems that no package deals with a conveninent,
89 normalized way to print monetary units and values. Built on the top
90 of the \pkg{siunitx}, this package
91 then aims at providing a consistant and coherent way to format such
92 quantities. In particular, we consider printing values and unit
93 \begin{itemize}[noitemsep=0pt,topsep=0pt]
94 \item In the ISO format (ISO 4217),
95 \item In their usual name (dollar, \cEUR[kind=name], ...), singular and plurals,
96 \item Using their ususal symbols (\$, \cEUR[kind=symbol],...).
97 \end{itemize}
98
99 The currency code ISO 4217 specifies the code of the currency as
100 a three-letters code. The first two ones are the code of the country
101 according to ISO 3166. The last one is the name of the currency name.
102
103 This package creates macros for defined currencies which follow
104 the ISO 4217 codes.
105
106 This package is then useful for current monetary units, using
107 the decimal systems and cents, written in western format.
108 Non decimal systems such as
109 the \emph{pound shilling pennies} are not supported.
110
111 \section{Licence and Requirements}
112 \license
113
114 The \pkg*{currency} package needs and thus loads the packages
115 \pkg{siunitx}, \pkg{pgfkeys}, \pkg{etoolbox}, \pkg{xparse},
116 \pkg{expl3}, \pkg{textcomp} and \pkg{eurosym}.
117
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119 %%% Currency definition
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121
122 \section{Currency definition}
123
124 \begin{commands}
125 \command{DefineCurrency}[\marg{ISO}\marg{maps}]
126 defines a new currency (there is no warning if a currency is being redefined).
127 \end{commands}
128
129 A new currency is defined with this command. The argument \Darg{ISO}
130 is the ISO format (a unique code in three letters based on country codes \cite{iso,iso:wikipedia}, \eg, USD
131 for \emph{United States Dollar}), or any suitable name from which commands will be created.
132 Its characteristics are defined through key-values pairs, the so-called \Darg{map}.
133
134 When \verb|XXX| is the ISO code (or any other code), it defines
135 two commands \verb|\dXXX| and \verb|\cXXX| for using these units in the text.
136 These commands are defined globally.
137 See Section~\ref{sec:using}.
138
139
140 For example, to define the US dollars, we set
141
142 \begin{sourcecode}
143 \DefineCurrency{USD}{name={dollar},plural={dollars},iso={USD},kind=iso,symbol={\$}}
144 \end{sourcecode}
145
146
147 Other styles may be defined through \cs*{pgfkeys} by following this example:
148 \begin{example}
149 \pgfkeys{/currency/my style/.style={locale=US,kind=plural}}
150 \dUSD[my style]{100.10}
151 \end{example}
152
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 \paragraph*{Key-values when defining or using a currency.}
155
156 Several key-values pair are defined. Since this package relies on \pkg{siunitx},
157 it is also possible to use any key-values from this latest package, for example
158 to control the ways the values are printed (separators, ...).
159
160 \begin{options}
161 \keyval{name}{name}\Default{ZZZ} The name of the currency (\eg, dollar, yen, ...).
162 \keyval{plural}{plural}\Default{\textit{name} s} The plural form of the name of the currency.
163 \keyval{iso}{iso} The ISO code of the currency.
164 \keyval{symbol}{symbol}\Default{\textcurrency} The symbol for the currency, if any (\eg, \cEUR[kind=symbol], \cUSD[kind=symbol], ...).
165 \keyval{pre-between}{tokens}\Default{no break space}
166 The tokens that are placed between the name and the value when the name
167 is printed before.
168 \keyval{post-between}{tokens}\Default{no break space}
169 The tokens that are placed between the name and the value when the name
170 is printed after.
171 \keyval{before}{tokens}\Default{} What is printed before.
172 \keyval{before+}{tokens} Append the content to \option{before}.
173 \keyval{before<}{tokens} Prepend the content to \option{before}.
174 \keyval{font}{tokens} For setting up the font which is used for both the unit and the amount (previous uses of \option{font} are overrided).
175 \keyval{font+}{tokens} Add the content to \option{font}.
176 \keyval{after}{tokens} What is printed after.
177 \keyval{after+}{tokens} Append to what is print after.
178 \keyval{after<}{tokens} Prepend to what is print after.
179 \keyval{prefix}{tokens}\Default What is printed before the name (\eg, k, M, ...).
180 \keychoice{kind}{\default{iso},plural,name,symbol}
181 The representation of the monetary unit.
182 \keychoice{cents}{\default{true},false,always}
183 Control the way the cents are printed.
184 \keychoice{pre}{true,\default{false}} Select if the unit should be print before or after the value (only for ISO code and symbols).
185 \keybool{number} Parse the values (interface to \option{parse-numbers} from \pkg{siunitx}).
186
187 \keyval{base}{integer}\Default{2} Number of digits for the cents.
188 \end{options}
189
190
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 %%%% Examples
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 \paragraph*{Examples}
195
196 No currency are actually defined in \pkg{currency}.
197 Euros, US dollars, yens and pounds could be defined by
198 \begin{sourcecode}
199 \DefineCurrency{EUR}{name={euro}, plural={euros}, symbol={\euro}, iso={EUR}, kind=iso}
200 \DefineCurrency{USD}{name={dollar}, plural={dollars}, symbol={\$}, iso={USD}, kind=iso}
201 \DefineCurrency{JPY}{name={yen}, plural={yens}, symbol={\textyen}, iso={JPY}, kind=iso,cents=false}
202 \DefineCurrency{GBP}{name={pound},pre=true,plural={pounds}, symbol={\pounds}, iso={GBP}, kind=iso}
203 \end{sourcecode}
204
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 %%%% Using currencies
207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 \section{Using currencies}
209 \label{sec:using}
210
211 \subsection{Using currencies}
212
213 Currencies are used with or without amounts. They could also be changed locally.
214
215 \begin{commands}
216 \command{CurrencySetup}[\marg{maps}]
217 This command defines a \emph{style} in the sense of \pkg{pgfkeys}, that
218 is a series of keys-values pairs.
219 These maps are exectued after
220 the ones defining the format of the currency but before the optional
221 argument passed to \cs{dXXX} or \cs{cXXX} where \texttt{XXX} is
222 the ISO 4217 code of the currency. It could be used to change locally
223 the setting of a currency. Using this command overrides the previous settings of
224 \cs*{CurrencySetup}. The command \cs{CurrencySetupAppend} append to the current style.:w
225 The style is stored in \verbcode|/currency/currency/.style|.
226 \command{CurrencySetupAppend}[\marg{maps}] Similar to \cs{CurrencySetup} but
227 append the style.
228 \doccorrectedsinceversion{0.2}
229 \command{cXXX}[\oarg{maps}] Print only the monetary unit with currency code \texttt{XXX}
230 (mnemonic \textit{c} stands for \textit{currency}).
231 \command{dXXX}[\oarg{maps}\marg{value}] Print the value with the monetary unit with currency code \texttt{XXX} (mnemonic \textit{d} stands for \textit{display}).
232 \command{vXXX}[\oarg{maps}\marg{value}]\sinceversion{0.2}
233 alias for \verbcode|\dXXX| (mnemonic \textit{v} stands for \textit{value}).
234 \end{commands}
235
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 \subsection{How currencies are composed?}
238
239 The commands \cs{cXXX} and \cs{dXXX} are expanded inside a group.
240 The argument \meta{value} for \cs{cXXX} is stored into \cs*{value}.
241 Besides, the unit is stored into \cs*{currencyunit} according
242 to the value of \option{kind}.
243
244 When using \cs{dXXX}, the order in which the elements are composed is
245 \begin{quote}
246 \option{font}\ \option{before}\ \option{prefix}\ \cs*{currencyunit}\ \option{pre-between}\
247 \cs*{value}\ \option{after}
248 \end{quote}
249 when the currency unit is printed before (\code{pre=false}), and
250 \begin{quote}
251 \option{font}\ \option{before}\ \cs*{value}\ \option{post-betwen}\ \option{prefix}\ \cs*{currencyunit}\ \option{after}
252 \end{quote}
253 otherwise (\code{pre=true}).
254
255 The rules are
256 \begin{itemize}[leftmargin=2em,itemsep=0pt]
257 \item The value (mandatory argument) specified by \meta{value} is printed
258 using \verbcode|\num{\value}| using the \cs{num} command from \pkg{siunitx}, and the value
259 is stored locally into \cs*{value}.
260 \item Both \option{prefix} and \option{unit} are enclosed into a \cs{text} command
261 so that they could safely be used in math mode.
262 \end{itemize}
263
264 When using \cs{cXXX}, the order in which the elements are composed is
265 \begin{quote}
266 \option{font}\ \option{before}\ \option{prefix}\ \cs*{currencyunit}\ \option{after}
267 \end{quote}
268 where \option{prefix} and \cs*{currencyunit} are enclosed in a \cs{text} command.
269 The boolean option \option{pre} is useless in this case.
270
271 \subsection{The hierarchy of keys definitions}
272
273 The order in which the keys are defined (and then overwritten) is
274 \begin{itemize}[leftmargin=2em,itemsep=0pt]
275 \item Default options values.
276 \item Command \cs{DefineCurrency}.
277 \item Command \cs{CurrencySetup}, which is a shorthand for defining
278 the pgfkey \verbcode|/currency/currency/.style|.
279 \item Command \cs{cXXX} ou \cs{dXXX} (the commands are executed
280 in a group).
281 \end{itemize}
282
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 %%% Examples
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286 \subsection{Examples}
287
288 \subsubsection{Punctuation.}
289
290 The commands \cs{dXXX} and \cs{cXXX} are defined using
291 the \pkg{xparse} package. The space is preserved after the command
292 so that there is no need to use \verbcode|\| after a command.
293
294 \begin{example}
295 The total gross salary is \dEUR{2000}. A part of \dEUR{1500} forms the net salary.
296 \end{example}
297
298 \subsection*{Using a prefix}
299
300 \begin{example}
301 The total cost of the project is \dEUR[prefix=M,kind=symbol]{0.5}.
302 \end{example}
303
304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 \subsubsection{Changing the base}
306
307 Most of the currencies have \emph{cents}, that is a monetary unit equal to $\nicefrac{1}{100}$
308 of the monetary unit. It is however possible to use another number of digits, either
309 for special purposes, or for monetary units with other bases such as the Kuwaiti dinar
310 which is decomposed in \num{1000} fils.
311
312 \begin{example}
313 \DefineCurrency{KWD}{name={dinar},plural={dinars},symbol={KD},iso={KWD},kind=iso,base=3}
314 $\dUSD{1}=\dKWD{0.29963}$
315 \end{example}
316
317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318 \subsubsection{Changing the font}
319
320 Using the \key{font}{tokens} key, it is possible to change the font which
321 is used for the monetary units (remember that everything is enclosed into a group).
322 When used in the currency definition and in \cs{CurrencySetup},
323 it is however supersed by any other \key{font}{tokens} key used in \cs{dXXX}
324 (A similar result could be obtained with \key{before}{tokens}, which aims
325 at putting some material). To avoid this, \key{font+}{tokens} shall be used.
326
327 Numbers are typesetted using a upright font. The \option*{detect-...}
328 options of \pkg{siunitx} could be used to change \cite[\S~5.2]{siunitx}.
329 However, they should be passed as boolean keys.
330
331
332 \begin{example}
333 \textit{It costs \dUSD{1}}.
334 \textit{It costs \dUSD[font=\normalfont]{1}}.
335 \begin{empty}
336 \CurrencySetup{font=\normalfont}
337 \textit{It costs \dUSD{1}}.
338 \textit{It costs \dUSD[font+=\bfseries]{1}}.
339 \textit{It costs \dUSD[font=\bfseries]{1}}.
340 \textit{It costs \dUSD[font=\bfseries,detect-weight=true]{1}}.
341 \textit{It costs \dUSD[font=\bfseries,detect-all=true]{1}}.
342 \end{empty}
343 \end{example}
344
345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346 \subsubsection{Using options before and after}
347
348 The use of \key{before}{tokens} is similar to the one of \key{font}{tokens}.
349 It is possible to append or to prepend the value to existing ones
350 defined as a higher level through \key{before+}{tokens} and \key{before<}{tokens}.
351 Similarly, one could use \key{after}{tokens}, \key{after+}{tokens} and \key{after<}{tokens}.
352
353 \begin{example}
354 \CurrencySetup{before=X}
355 \dUSD[before+={\color{red}}]{1}
356 \dUSD[before<={\color{red}}]{1}
357 \end{example}
358
359 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361 \subsubsection{Using siunitx's features}
362
363 Any key of the \pkg{siunitx} package could be used.
364 For example, localization may change the unit separator (comma, ...).
365
366 \begin{example}
367 This costs \dEUR{12 345.76}.
368 {\sisetup{locale=FR} Cela co\^ute \dEUR{12 345.76}.}
369 \end{example}
370
371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 \subsubsection{Using raw formula}
374
375 A raw formula could be typeseted using the number option \verbcode|number=false|.
376 Beware, this propagate \verbcode|parse-numbers=false| to \verbcode|\num|
377 so that any inner call to the latter command should specify
378 \verbcode|parse-numbers=true| if needed.
379
380 A style (see Section~\ref{sec:styles}) \verbcode|no-parse| is equivalent
381 to \verbcode|number=false|.
382
383 \begin{example}
384 We get a total of \dEUR[number=false]{2\times \num[parse-numbers=true]{10000}}=\dEUR{20000}.
385
386 We get a total of \dEUR[number=false]{2\times \num{10000}}=\dEUR{20000}.
387 \end{example}
388
389
390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 \subsubsection{Using styles}
393 \label{sec:styles}
394
395 Some styles are aldeary defined to shorten the typesetting.
396 For example, \verbcode|@iso| expands to \verbcode|kind=iso|.
397 It
398 acts similarly for \verbcode|@sy| (or \verbcode|@symb|), \verbcode|@na| (or \verbcode|@name|) and \verbcode|@pl|
399 (or \verbcode|@plural|).
400
401 \begin{example}
402 \dEUR[@iso]{10}; \dEUR[@symb]{10}; \dEUR[@name]{10}; \dEUR[@pl]{10}
403
404 \dGBP{10} ; \dGBP[@symb]{10} ; \dGBP[@pl]{10} ; \dGBP{5}
405 \end{example}
406
407 A style \verbcode|no-parse| is also equivalent to \verbcode|number=false|.
408 \sinceversion{0.2}
409
410
411
412
413
414
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
416 %%%% TODO
417 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418
419 \section{To Do}
420
421 \begin{itemize}
422 \item Store the values to use them later.
423 \item Automatic detection of plurals.
424 \item Perform simple arithmetics.
425 \item Behavior of \verbcode{detect-...} keys from \pkg{siunitx} with default argument.
426 \item Internationalization using the \texttt{translations} packages \cite{translations}.
427 \item Non decimal systems such as pounds, shillings, and pence.
428 \item Column definition for a table.
429 \item ...
430 \end{itemize}
431
432 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
433 %%%% References
434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435
436 \printbibliography
437
438
439 \end{document}