summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/currency/currency.sty
blob: 5e2baf8f882952c62b401c5c19b6bc06616831a1 (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
%%
%% This is file `currency.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% currency.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2018 by Scott Lejay
%% 
%% This file 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.
%% 
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{currency}
    [2018/10/22 v0.4 .dtx currency file]
\RequirePackage{siunitx}
\RequirePackage{pgfkeys}
\RequirePackage{etoolbox}
\RequirePackage{xparse}
\RequirePackage{expl3}
\RequirePackage{textcomp}
\RequirePackage{eurosym}
\newif\ifcurrencynumber
\pgfkeys{/currency/.cd,number/.is if=currencynumber,number=true}
\newif\ifprintbefore
\pgfkeys{/currency/pre/.is if=printbefore}
\pgfkeys{/currency/name/.initial=ZZZ}
\pgfkeys{/currency/symbol/.initial=\textcurrency}

\pgfkeys{/currency/currency/.style={}}
\newcommand{\CurrencySetup}[1]{%
    \pgfkeys{/currency/currency/.style={#1}}%
}
\newcommand{\CurrencySetupAppend}[1]{%
    \pgfkeys{/currency/currency/.append style={#1}}%
}
\pgfkeys{/currency/name/.store in=\currencyName}
\pgfkeys{/currency/plural/.store in=\currencyNames}
\pgfkeys{/currency/plural/.initial=\currencyName s}
\pgfkeys{/currency/iso/.store in=\currencyISO}
\pgfkeys{/currency/symbol/.store in=\currencySymbol}
\pgfkeys{/currency/pre-between/.initial={~}}
\pgfkeys{/currency/post-between/.initial={~}}
\pgfkeys{/currency/before/.initial={}}
\pgfkeys{/currency/before+/.code={\pgfkeys{/currency/before/.append={#1}}}}
\pgfkeys{/currency/before</.code={\pgfkeys{/currency/before/.prefix={#1}}}}
\pgfkeys{/currency/after/.initial={}} % tokens that are inserted after
\pgfkeys{/currency/after+/.code={\pgfkeys{/currency/after/.append={#1}}}}
\pgfkeys{/currency/after</.code={\pgfkeys{/currency/after/.prefix={#1}}}}
\pgfkeys{/currency/font/.initial={}} % for setting up the fonts
\pgfkeys{/currency/font+/.code={\pgfkeys{/currency/font/.append={#1}}}}
\pgfkeys{/currency/prefix/.initial={}}
\pgfkeys{/currency/kind/.is choice}
\pgfkeys{/currency/kind/iso/.code=%
    {\def\currencyunit{\currencyISO}}}
\pgfkeys{/currency/kind/plural/.code=%
    {\def\currencyunit{\currencyNames}\printbeforefalse}}
\pgfkeys{/currency/kind/name/.code=%
    {\def\currencyunit{\currencyName}\printbeforefalse}}
\pgfkeys{/currency/kind/symbol/.code=%
    {\def\currencyunit{\currencySymbol}}}
\pgfkeys{/currency/kind=iso}
\pgfkeys{/currency/cents/.is choice}
\pgfkeys{/currency/cents/true/.code=%
    {\sisetup{zero-decimal-to-integer=true}}}
\pgfkeys{/currency/cents/false/.code=%
    {\sisetup{zero-decimal-to-integer=true,round-precision=0}}}
\pgfkeys{/currency/cents/always/.code=%
    {\sisetup{zero-decimal-to-integer=false,round-integer-to-decimal=true}}}
\pgfkeys{/currency/cents=true}
\ExplSyntaxOn
\pgfkeys{/currency/.unknown/.code={%
\edef\Unknown{\pgfkeyscurrentname=\pgfkeyscurrentvalue}%
\keys_set:nV {siunitx} {\Unknown}%
    }}%
\ExplSyntaxOff
\ExplSyntaxOn
\pgfkeys{/currency/base/.code={%
\edef\SetPrecision{round-precision=\pgfkeyscurrentvalue}%
\keys_set:nV {siunitx} {\SetPrecision}%
    }}%
\ExplSyntaxOff
\ExplSyntaxOn
\DeclareDocumentCommand{\displayCurrency}{m o m}{
\begingroup%
\sisetup{round-mode=places,round-precision=2}
\IfNoValueTF{#2}%
    {\pgfkeys{/currency/.cd,#1,currency}}%
    {\pgfkeys{/currency/.cd,#1,currency,#2}}%
\ifbool{currencynumber}%
    {\sisetup{parse-numbers=true}}%
    {\sisetup{parse-numbers=false}}%
\edef\value{#3}% store the value of the currency
\ifprintbefore%
\pgfkeys{/currency/font}%
\pgfkeys{/currency/before}%
\text{\pgfkeys{/currency/prefix}\currencyunit}%
\pgfkeys{/currency/pre-between}%
\num{\value}\pgfkeys{/currency/after}%
\else% print the unit after
\pgfkeys{/currency/font}%
\pgfkeys{/currency/before}%
\num{\value}%
\pgfkeys{/currency/post-between}%
\text{\pgfkeys{/currency/prefix}\currencyunit}%
\pgfkeys{/currency/after}%
\fi%
\endgroup%
}
\DeclareDocumentCommand{\displayCurrencySymbol}{m o}{
\begingroup%
    \IfNoValueTF{#2}%
{\pgfkeys{/currency/.cd,#1,currency}}%
{\pgfkeys{/currency/.cd,#1,currency,#2}}%
    \pgfkeys{/currency/font}%
    \pgfkeys{/currency/before}%
    \text{\pgfkeys{/currency/prefix}\currencyunit}%
\pgfkeys{/currency/after}%
\endgroup%
}
\ExplSyntaxOff
\newcommand{\DefineCurrency}[2]{%
\pgfkeys{/currency/#1/.style={#2}}%%
\csgdef{d#1}{\displayCurrency{#1}}
\csgdef{c#1}{\displayCurrencySymbol{#1}}
}%
\pgfkeys{/currency/@iso/.style={kind=iso}}
\pgfkeys{/currency/@symb/.style={kind=symbol}}
\pgfkeys{/currency/@sy/.style={kind=symbol}}
\pgfkeys{/currency/@name/.style={kind=name}}
\pgfkeys{/currency/@na/.style={kind=name}}
\pgfkeys{/currency/@plural/.style={kind=plural}}
\pgfkeys{/currency/@pl/.style={kind=plural}}
\pgfkeys{/currency/no-parse/.style={number=false}}
\endinput
%%
%% End of file `currency.sty'.