summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/zhnumber/zhnumber.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-06-19 22:32:13 +0000
committerKarl Berry <karl@freefriends.org>2015-06-19 22:32:13 +0000
commit28cb2b214ad9bcb5ac65fdf512b438f388a68b1e (patch)
tree227bd9a8b0f9f68f9ecfd2ccb5806418e8f71a40 /Master/texmf-dist/tex/latex/zhnumber/zhnumber.sty
parent4c01004cc15017d68eb0b9697c07010ea62ea23f (diff)
zhnumber (19jun15)
git-svn-id: svn://tug.org/texlive/trunk@37614 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/zhnumber/zhnumber.sty')
-rw-r--r--Master/texmf-dist/tex/latex/zhnumber/zhnumber.sty147
1 files changed, 124 insertions, 23 deletions
diff --git a/Master/texmf-dist/tex/latex/zhnumber/zhnumber.sty b/Master/texmf-dist/tex/latex/zhnumber/zhnumber.sty
index 6d81896fdb3..4223c0743d7 100644
--- a/Master/texmf-dist/tex/latex/zhnumber/zhnumber.sty
+++ b/Master/texmf-dist/tex/latex/zhnumber/zhnumber.sty
@@ -6,7 +6,7 @@
%%
%% zhnumber.dtx (with options: `package')
%%
-%% Copyright (C) 2012, 2014 by Qing Lee <sobenlee@gmail.com>
+%% Copyright (C) 2012, 2014, 2015 by Qing Lee <sobenlee@gmail.com>
%% --------------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
@@ -21,11 +21,11 @@
%%
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}
-\GetIdInfo$Id: zhnumber.dtx 718 2014-09-13 09:13:29Z sobenlee $
+\GetIdInfo$Id: zhnumber.dtx 42dbb38 2015-05-21 23:20:32 +0800 Qing Lee <sobenlee@gmail.com> $
{Typesetting numbers with Chinese glyphs}
\ProvidesExplPackage
{\ExplFileName}
- {\ExplFileDate}{2.1}{\ExplFileDescription}
+ {\ExplFileDate}{2.2}{\ExplFileDescription}
\msg_new:nnn { zhnumber } { l3-too-old }
{
Support~package~'expl3'~too~old. \\\\
@@ -228,7 +228,7 @@
#2 \q_recursion_tail \q_nil \q_nil \q_nil \q_recursion_stop
}
\cs_generate_variant:Nn \zhnum_split_number:nn { f }
-\cs_new:Npn \zhnum_split_number:NNnNNNNw #1#2#3#4#5#6#7#8 \q_recursion_stop
+\cs_new:Npn \zhnum_split_number:NNnNNNNw #1#2#3#4#5#6#7
{
\quark_if_recursion_tail_stop:N #4
\int_compare:nNnTF { #4#5#6#7 } = \c_zero
@@ -241,7 +241,7 @@
}
{ \zhnum_split_number:NNfNNNNw \c_false_bool \c_true_bool }
{ \zhnum_split_number:NNfNNNNw \c_true_bool \c_false_bool }
- { \int_eval:n { #3 - \c_one } } #8 \q_recursion_stop
+ { \int_eval:n { #3 - \c_one } }
}
\cs_generate_variant:Nn \zhnum_split_number:NNnNNNNw { NNf }
\cs_new:Npn \zhnum_process_number:NNNNNN #1#2#3#4#5#6
@@ -475,7 +475,60 @@
{ \int_incr:N \l__zhnum_scale_int }
\tl_set:cn { \l_tmpa_tl } {#1}
}
-
+\cs_new:Npn \zhnum_ganzhi_normal:nnn #1#2#3
+ {
+ \int_compare:nNnF {#1} < \c_one
+ { \cs_if_exist_use:c { c__zhnum_ #2 _ #1 _tl } }
+ }
+\cs_new:Npn \zhnum_ganzhi_cyclic:nnn #1#2#3
+ {
+ \int_compare:nNnF {#1} = \c_zero
+ {
+ \cs_if_exist_use:cF { c__zhnum_ #2 _ #1 _tl }
+ {
+ \__zhnum_ganzhi_cyclic_mod:fnnn
+ { \int_mod:nn {#1} {#3} } {#1} {#2} {#3}
+ }
+ }
+ }
+\cs_new:Npn \__zhnum_ganzhi_cyclic_mod:nnnn #1#2#3#4
+ {
+ \int_compare:nNnTF {#2} > \c_zero
+ { \use:c { c__zhnum_ #3 _ #1 _tl } }
+ {
+ \int_compare:nNnTF {#1} = \c_zero
+ { \use:c { c__zhnum_ #3 _ 1 _tl } }
+ { \use:c { c__zhnum_ #3 _ \int_eval:n { #1 + #4 + 1 } _tl } }
+ }
+ }
+\cs_generate_variant:Nn \__zhnum_ganzhi_cyclic_mod:nnnn { f }
+\cs_new_eq:NN \zhnum_ganzhi:nnn \zhnum_ganzhi_normal:nnn
+\cs_generate_variant:Nn \zhnum_ganzhi:nnn { f }
+\cs_new:Npn \zhtiangan #1
+ { \zhnum_ganzhi:fnn { \int_eval:n {#1} } { tiangan } { 10 } }
+\cs_new:Npn \zhdizhi #1
+ { \zhnum_ganzhi:fnn { \int_eval:n {#1} } { dizhi } { 12 } }
+\cs_new:Npn \zhganzhi #1
+ { \zhnum_ganzhi:fnn { \int_eval:n {#1} } { ganzhi } { 60 } }
+\cs_new:Npn \zhganzhinian #1
+ { \zhnum_ganzhi_nian:f { \int_eval:n {#1} } }
+\cs_new:Npn \zhnum_ganzhi_nian:n #1
+ {
+ \int_compare:nNnTF {#1} > \c_zero
+ { \use:c { c__zhnum_ganzhi_ \int_mod:nn { #1 + 57 } { 60 } _tl } }
+ {
+ \int_compare:nNnF {#1} = \c_zero
+ {
+ \use:c
+ {
+ c__zhnum_ganzhi_
+ \int_eval:n { \int_mod:nn { #1 - 2 } { 60 } + 60 }
+ _tl
+ }
+ }
+ }
+ }
+\cs_generate_variant:Nn \zhnum_ganzhi_nian:n { f }
\group_begin:
\tl_set:Nn \l_tmpa_tl
{
@@ -488,27 +541,40 @@
E3 .tl_set:N = \exp_not:c { l__zhnum_ 1000 _tl } ,
FE2 .tl_set:N = \exp_not:c { l__zhnum_financial_ 100 _tl } ,
FE3 .tl_set:N = \exp_not:c { l__zhnum_financial_ 1000 _tl } ,
+ D11 .tl_set:N = \exp_not:c { l__zhnum_dizhi_ 11 _tl } ,
+ D12 .tl_set:N = \exp_not:c { l__zhnum_dizhi_ 12 _tl } ,
+ E44 .tl_set:N = \exp_not:c { l__zhnum_ s11 _tl } ,
}
- \clist_map_inline:nn
- { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 100 , 1000 }
+ \int_step_inline:nnnn { 1 } { 1 } { 10 }
{
\tl_put_right:Nx \l_tmpa_tl
{
- #1 .tl_set:N = \exp_not:c { l__zhnum_ #1 _tl } ,
- F#1 .tl_set:N = \exp_not:c { l__zhnum_financial_ #1 _tl } ,
+ #1 .tl_set:N = \exp_not:c { l__zhnum_ #1 _tl } ,
+ F#1 .tl_set:N = \exp_not:c { l__zhnum_financial_ #1 _tl } ,
+ T#1 .tl_set:N = \exp_not:c { l__zhnum_tiangan_ #1 _tl } ,
+ D#1 .tl_set:N = \exp_not:c { l__zhnum_dizhi_ #1 _tl } ,
+ GZ#1 .tl_set:N = \exp_not:c { l__zhnum_ganzhi_ #1 _tl } ,
+ E \int_eval:n { #1 * 4 }
+ .tl_set:N = \exp_not:c { l__zhnum_ s#1 _tl } ,
}
}
- \clist_map_inline:nn
- { 20 , 30 , 40 , 200 }
+ \int_step_inline:nnnn { 11 } { 1 } { 60 }
{
\tl_put_right:Nx \l_tmpa_tl
- { #1 .tl_set:N = \exp_not:c { l__zhnum_ #1 _tl } , }
+ { GZ#1 .tl_set:N = \exp_not:c { l__zhnum_ganzhi_ #1 _tl } , }
}
- \clist_map_inline:nn
- { 4 , 8 , 12 , 16 , 20 , 24 , 28 , 32 , 36 , 40 , 44 }
+ \clist_map_inline:nn { 0 , 100 , 1000 }
+ {
+ \tl_put_right:Nx \l_tmpa_tl
+ {
+ #1 .tl_set:N = \exp_not:c { l__zhnum_ #1 _tl } ,
+ F#1 .tl_set:N = \exp_not:c { l__zhnum_financial_ #1 _tl } ,
+ }
+ }
+ \clist_map_inline:nn { 20 , 30 , 40 , 200 }
{
\tl_put_right:Nx \l_tmpa_tl
- { E#1 .tl_set:N = \exp_not:c { l__zhnum_ s \int_eval:n { #1 / 4 } _tl } , }
+ { #1 .tl_set:N = \exp_not:c { l__zhnum_ #1 _tl } , }
}
\clist_map_inline:nn
{
@@ -538,12 +604,18 @@
\prop_put_if_new:Nnn \l__zhnum_cfg_map_finan_prop {#1} {#3}
\prop_put:Nnn \l__zhnum_cfg_map_var_prop { financial_#1_#2 } {#3}
}
+\cs_new_protected:Npn \zhnum_set_tiangan_map:nn #1#2
+ { \prop_put:Nnn \l__zhnum_cfg_map_ganzhi_prop { tiangan_#1 } {#2} }
+\cs_new_protected:Npn \zhnum_set_dizhi_map:nn #1#2
+ { \prop_put:Nnn \l__zhnum_cfg_map_ganzhi_prop { dizhi_#1 } {#2} }
\prop_new:N \l__zhnum_cfg_map_prop
\prop_new:N \l__zhnum_cfg_map_var_prop
\prop_new:N \l__zhnum_cfg_map_finan_prop
+\prop_new:N \l__zhnum_cfg_map_ganzhi_prop
\cs_new_protected_nopar:Npn \zhnum_parse_config:
{
\prop_map_function:NN \l__zhnum_cfg_map_prop \zhnum_check_simp:nn
+ \prop_map_function:NN \l__zhnum_cfg_map_ganzhi_prop \zhnum_assgin_ganzhi:nn
\zhnum_set_zero:
\zhnum_set_week_day:
\bool_if:NF \l__zhnum_reset_bool
@@ -620,9 +692,31 @@
}
\clist_map_inline:nn { mon , tue , wed , thu , fri , sat , sun }
{ \tl_const:cx { c__zhnum_ #1 _tl } { \exp_not:c { l__zhnum_ #1 _tl } } }
+\cs_new_protected:Npn \zhnum_assgin_ganzhi:nn #1#2
+ { \tl_set:cn { l__zhnum_ #1 _tl } {#2} }
+\cs_new:Npn \zhnum_zero_mod:nn #1#2
+ { \exp_args:Nf \__zhnum_zero_mod_aux:nn { \int_mod:nn {#1} {#2} } {#2} }
+\cs_new:Npn \__zhnum_zero_mod_aux:nn #1#2
+ { \int_compare:nNnTF {#1} = \c_zero {#2} {#1} }
+\int_step_inline:nnnn { 1 } { 1 } { 60 }
+ {
+ \tl_const:cx { c__zhnum_ganzhi_ #1 _tl } { \exp_not:c { l__zhnum_ganzhi_ #1 _tl } }
+ \tl_set:cx { l__zhnum_ganzhi_ #1 _tl }
+ {
+ \exp_not:c { l__zhnum_tiangan_ \zhnum_zero_mod:nn {#1} { 10 } _tl }
+ \exp_not:c { l__zhnum_dizhi_ \zhnum_zero_mod:nn {#1} { 12 } _tl }
+ }
+ }
+\cs_new_eq:cc { c__zhnum_ganzhi_ 0 _tl } { c__zhnum_ganzhi_ 60 _tl }
\cs_new_eq:NN \zhnum_assgin_const_tl:cx \tl_const:cx
\AtEndOfPackage
- { \cs_set_eq:NN \zhnum_assgin_const_tl:cx \tl_set:cx }
+ {
+ \prop_map_inline:Nn \l__zhnum_cfg_map_ganzhi_prop
+ { \tl_const:cx { c__zhnum_ #1 _tl } { \exp_not:c { l__zhnum_ #1 _tl } } }
+ \cs_new_eq:cc { c__zhnum_tiangan_ 0 _tl } { c__zhnum_tiangan_ 10 _tl }
+ \cs_new_eq:cc { c__zhnum_dizhi_ 0 _tl } { c__zhnum_dizhi_ 12 _tl }
+ \cs_set_eq:NN \zhnum_assgin_const_tl:cx \tl_set:cx
+ }
\cs_new_eq:NN \zhnum_set_alias:NN \cs_new_eq:NN
\cs_new_protected_nopar:Npx \zhnum_set_alias:
{
@@ -649,7 +743,7 @@
{
\prop_if_exist:cTF { g__zhnum_cfg_ \l__zhnum_cfg_tl _prop }
{ \tl_set_eq:NN \l__zhnum_last_cfg_tl \l__zhnum_cfg_tl }
- { \zhnum_input_cfg:n {#1} }
+ { \zhnum_input_cfg:n {#1} }
\__zhnum_update_cfg_prop:N \prop_set_eq:Nc
}
\cs_new_protected:Npn \zhnum_input_cfg:n #1
@@ -670,9 +764,10 @@
}
\cs_new_protected:Npn \__zhnum_update_cfg_prop:N #1
{
- #1 \l__zhnum_cfg_map_prop { g__zhnum_cfg_ \l__zhnum_cfg_tl _prop }
- #1 \l__zhnum_cfg_map_var_prop { g__zhnum_cfg_var_ \l__zhnum_cfg_tl _prop }
- #1 \l__zhnum_cfg_map_finan_prop { g__zhnum_cfg_finan_ \l__zhnum_cfg_tl _prop }
+ #1 \l__zhnum_cfg_map_prop { g__zhnum_cfg_ \l__zhnum_cfg_tl _prop }
+ #1 \l__zhnum_cfg_map_var_prop { g__zhnum_cfg_var_ \l__zhnum_cfg_tl _prop }
+ #1 \l__zhnum_cfg_map_finan_prop { g__zhnum_cfg_finan_ \l__zhnum_cfg_tl _prop }
+ #1 \l__zhnum_cfg_map_ganzhi_prop { g__zhnum_cfg_ganzhi_ \l__zhnum_cfg_tl _prop }
}
\cs_new_protected:Npn \__zhnum_prop_initial:Nn #1#2
{
@@ -754,8 +849,8 @@
encoding .choices:nn =
{ UTF8 , GBK , Big5 }
{
- \tl_set:Nx \l__zhnum_encoding_tl
- { \exp_args:No \tl_expandable_lowercase:n { \l_keys_choice_tl } }
+ \exp_args:Nx \tex_lowercase:D
+ { \tl_set:Nn \exp_not:N \l__zhnum_encoding_tl { \l_keys_choice_tl } }
\zhnum_load_cfg:o { \l__zhnum_encoding_tl }
} ,
encoding .default:n = { GBK } ,
@@ -788,6 +883,12 @@
time .default:n = { Arabic } ,
reset .code:n = { \zhnum_reset_config: } ,
activechar .bool_set:N = \l__zhnum_active_char_bool ,
+ ganzhi-cyclic .choice: ,
+ ganzhi-cyclic / true .code:n =
+ { \cs_set_eq:NN \zhnum_ganzhi:nnn \zhnum_ganzhi_cyclic:nnn } ,
+ ganzhi-cyclic / false.code:n =
+ { \cs_set_eq:NN \zhnum_ganzhi:nnn \zhnum_ganzhi_normal:nnn } ,
+ ganzhi-cyclic .default:n = { true } ,
}
\tl_new:N \l__zhnum_encoding_tl
\msg_new:nnnn { zhnumber } { encoding-invalid }