diff options
author | Karl Berry <karl@freefriends.org> | 2016-02-03 22:59:51 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-02-03 22:59:51 +0000 |
commit | 1290d7454b9754f3c7a7e4a229981e18f58ea6f6 (patch) | |
tree | aa01beb72d34acd81690358b54be7493a5244544 /Master/texmf-dist/tex/latex/ctex/ctexpatch.sty | |
parent | e5ef88072190f4f0e310c900fd626db1dd7dc096 (diff) |
ctex (3feb16)
git-svn-id: svn://tug.org/texlive/trunk@39559 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/ctex/ctexpatch.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/ctex/ctexpatch.sty | 178 |
1 files changed, 97 insertions, 81 deletions
diff --git a/Master/texmf-dist/tex/latex/ctex/ctexpatch.sty b/Master/texmf-dist/tex/latex/ctex/ctexpatch.sty index c0e571bfd26..fdb205421df 100644 --- a/Master/texmf-dist/tex/latex/ctex/ctexpatch.sty +++ b/Master/texmf-dist/tex/latex/ctex/ctexpatch.sty @@ -28,10 +28,11 @@ %% \NeedsTeXFormat{LaTeX2e} \RequirePackage{expl3} -\GetIdInfo$Id: ctex.dtx 6255367 2015-07-01 01:15:24 +0800 Qing Lee <sobenlee@gmail.com> $ +\GetIdInfo$Id: ctex.dtx 4e02493 2016-02-02 17:10:17 +0800 Qing Lee <sobenlee@gmail.com> $ {Patching commands (CTEX)} \ProvidesExplPackage{ctexpatch} - {\ExplFileDate}{2.2}{\ExplFileDescription} + {\ExplFileDate}{2.3}{\ExplFileDescription} +\cs_if_exist:NF \str_new:N { \RequirePackage { l3str } } \cs_new_protected:Npn \ctex_patch_cmd_once:NnnnTF #1#2 { \ctex_patch_boot:NNnnTF \__ctex_patch_cmd:Nnnnnw #1 @@ -80,111 +81,127 @@ \cs_new_protected:Npn \ctex_parse_name:NN #1#2 { \ctex_parse_name:NNx #1#2 { \cs_to_str:N #2 } } \group_begin: -\char_set_lccode:nn { `\< } { `\{ } -\char_set_lccode:nn { `\/ } { `\\ } -\char_set_lccode:nn { `\A } { `\t } -\tl_map_function:nN { \A \E \S \O \P } \char_set_catcode_other:N -\tex_lowercase:D +\cs_set_protected:Npn \__ctex_tmp:w #1#2#3 { - \group_end: - \cs_new_protected:Npn \ctex_parse_name:NNn #1#2#3 + \cs_new_protected:Npn \ctex_parse_name:NNn ##1##2##3 { - \bool_if:nTF { \cs_if_exist_p:c { #3 ~ } || \cs_if_exist_p:c { /#3 } } + \bool_if:nTF + { + \cs_if_exist_p:c { ##3 ~ } || + \cs_if_exist_p:c { #1##3 } + } { \group_begin: \use:x { \group_end: - \__ctex_parse_name:nNNNnN { \token_get_replacement_spec:N #2 } - \exp_not:N #2 \exp_not:c { #3 ~ } \exp_not:c { /#3 } - } {#3} #1 + \__ctex_parse_name:nNNNnN + { \token_get_replacement_spec:N ##2 } + \exp_not:N ##2 + \exp_not:c { ##3 ~ } + \exp_not:c { #1##3 } + } {##3} ##1 } - { #1#2 } + { ##1##2 } } - \cs_new_protected:Npn \__ctex_parse_name:nNNNnN #1#2#3#4#5#6 + \cs_new_protected:Npn \__ctex_parse_name:nNNNnN ##1##2##3##4##5##6 { - \exp_args:Nc #6 + \exp_args:Nc ##6 { - \str_case:nnTF {#1} + \str_case:nnTF {##1} { - { \protect #3 } { } - { \x@protect #2 \protect #3 } { } + { \protect ##3 } { } + { \x@protect ##2 \protect ##3 } { } } { - \str_if_eq_x:nnTF { \exp_not:n { /@protected@ #3 /#3 } } + \str_if_eq_x:nnTF + { \exp_not:n { #1@protected@ ##3 #1##3 } } { \exp_last_unbraced:Nf \__ctex_parse_name:w - \token_get_replacement_spec:N #3 AESAOPA ~ < \q_stop + \token_get_replacement_spec:N ##3 #2 ~ #1 \q_stop } - { /#5 ~ } { #5 ~ } + { #1##5 ~ } { ##5 ~ } } { - \str_case:onTF { \__ctex_parse_name:w #1 AESAOPA ~ < \q_stop } + \str_case:onTF { \__ctex_parse_name:w ##1 #2 ~ #1 \q_stop } { - { /@protected@ #2 #4 } { } - { /@ #4 } { } + { #1@protected@ ##2 ##4 } { } + { #1@ ##4 } { } } - { /#5 } {#5} + { #1##5 } {##5} } } } - \cs_new:Npn \__ctex_parse_name:w #1 AESAOPA ~ #2 < #3 \q_stop { #1#2 } + \cs_new:Npn \__ctex_parse_name:w ##1 #2 ~ ##2 #1 ##3 \q_stop { ##1##2 } } -\cs_generate_variant:Nn \ctex_parse_name:NNn { NNx } -\tl_new:N \l__ctex_prefix_tl -\tl_new:N \l__ctex_parameter_tl -\tl_new:N \l__ctex_replacement_tl -\group_begin: - \char_set_lccode:nn { `\; } { `\: } - \tl_map_function:nN { \M \A \C \R \O \; } \char_set_catcode_other:N -\tex_lowercase:D +\use:x { - \group_end: - \cs_new_protected:Npn \ctex_get_macro_meaning:NTF #1 - { - \exp_after:wN \__ctex_get_macro_meaning:w - \token_to_meaning:N #1 \q_stop MACRO ; -> \q_no_value \q_stop - } - \cs_new_protected:Npn \__ctex_get_macro_meaning:w #1 MACRO ; #2 -> #3 \q_stop - { - \tl_set:Nn \l__ctex_replacement_tl {#3} - \quark_if_no_value:NTF \l__ctex_replacement_tl - { \use_ii:nn } - { - \tl_set:Nn \l__ctex_prefix_tl {#1} - \tl_set:Nn \l__ctex_parameter_tl {#2} - \use_i_delimit_by_q_stop:nw { \use_i:nn } - } - } + \__ctex_tmp:w + { \c_backslash_str } + { \c_left_brace_str } + { \tl_to_str:n { testopt } } } +\group_end: +\cs_generate_variant:Nn \ctex_parse_name:NNn { NNx } +\str_new:N \l__ctex_prefix_str +\str_new:N \l__ctex_parameter_str +\str_new:N \l__ctex_replacement_str +\group_begin: + \cs_set_protected:Npn \__ctex_tmp:w #1 + { + \prg_new_protected_conditional:Npnn + \ctex_get_macro_meaning:N ##1 { TF } + { + \exp_after:wN \__ctex_get_macro_meaning:w + \token_to_meaning:N ##1 \q_mark #1 -> \q_no_value \q_mark \q_stop + } + \cs_new_protected:Npn \__ctex_get_macro_meaning:w + ##1 #1 ##2 -> ##3 \q_mark ##4 \q_stop + { + \tl_set:Nn \l__ctex_replacement_tl {##3} + \quark_if_no_value:NTF \l__ctex_replacement_tl + { \prg_return_false: } + { + \str_set:Nn \l__ctex_prefix_str {##1} + \str_set:Nn \l__ctex_parameter_str {##2} + \str_set:Nn \l__ctex_replacement_str {##3} + \prg_return_true: + } + } + } + \exp_args:No \__ctex_tmp:w { \tl_to_str:n { macro: } } +\group_end: \cs_new_protected:Npn \ctex_if_rescanable:NnTF #1#2#3#4 { \ctex_get_macro_meaning:NTF #1 { - \__ctex_patch_rebuild:Nn \CTEXPATCHRESCANCMD {#2} - \cs_if_eq:NNTF #1 \CTEXPATCHRESCANCMD {#3} {#4} + \__ctex_patch_rebuild:Nn \__ctex_rebuild_cmd:w {#2} + \cs_if_eq:NNTF #1 \__ctex_rebuild_cmd:w {#3} {#4} } {#4} } -\cs_new_eq:NN \CTEXPATCHRESCANCMD \prg_do_nothing: +\cs_new_eq:NN \__ctex_rebuild_cmd:w \prg_do_nothing: \cs_new_protected:Npn \__ctex_patch_rebuild:Nn #1#2 { - \tl_if_empty:nTF {#2} - { \tl_rescan:nx {#2} } - { - \tl_rescan:nx - { - #2 \scan_stop: - \int_set_eq:NN \tex_endlinechar:D \c_minus_one - \int_set_eq:NN \tex_newlinechar:D \c_minus_one - } - } + \__ctex_patch_rescan:NNn \l__ctex_prefix_tl \l__ctex_prefix_str {#2} + \__ctex_patch_rescan:NNn \l__ctex_parameter_tl \l__ctex_parameter_str {#2} + \__ctex_patch_rescan:NNn \l__ctex_replacement_tl \l__ctex_replacement_str {#2} + \use:x { - \l__ctex_prefix_tl \exp_not:N \def \exp_not:N #1 \l__ctex_parameter_tl - { \l__ctex_replacement_tl } + \exp_not:o { \l__ctex_prefix_tl } \tex_def:D \exp_not:N #1 + \exp_not:o { \l__ctex_parameter_tl } + { \exp_not:o { \l__ctex_replacement_tl } } } } -\cs_generate_variant:Nn \tl_rescan:nn { nx } +\cs_new_protected:Npn \__ctex_patch_rescan:NNn #1#2#3 + { + \str_if_empty:NTF #2 + { \tl_clear:N #1 } + { \tl_set_rescan:Nnx #1 {#3} {#2} } + } +\tl_new:N \l__ctex_prefix_tl +\tl_new:N \l__ctex_parameter_tl +\tl_new:N \l__ctex_replacement_tl \cs_new_protected:Npn \__ctex_patch_cmd:Nnnnnw #1#2#3#4#5 { \group_end: @@ -197,8 +214,7 @@ { \tl_to_str:n {#5} } } { - \__ctex_patch_rebuild:Nn \CTEXPATCHRESCANCMD {#3} - \cs_set_eq:NN #1 \CTEXPATCHRESCANCMD + \__ctex_patch_rebuild:Nn #1 {#3} \__ctex_patch_true:w } { \__ctex_patch_false:w } @@ -207,15 +223,15 @@ } \cs_new_protected:Npn \__ctex_patch_replace:nnnTF #1#2#3#4 { - \tl_if_in:NnTF \l__ctex_replacement_tl {#2} - { \use:c { tl_replace_ #1 :Nnn } \l__ctex_replacement_tl {#2} {#3} #4 } + \tl_if_in:NnTF \l__ctex_replacement_str {#2} + { \use:c { tl_replace_ #1 :Nnn } \l__ctex_replacement_str {#2} {#3} #4 } } \cs_new_protected:Npn \__ctex_hookto_cmd:Nnnnw #1#2#3#4 { \group_end: \ctex_get_macro_meaning:NTF #1 { - \tl_if_empty:NTF \l__ctex_parameter_tl + \str_if_empty:NTF \l__ctex_parameter_str { \__ctex_hookto_cmd_parameterless:Nnnw #1 {#2} {#4} } { \__ctex_hookto_cmd_parameter:Nnnnw #1 {#2} {#3} {#4} } } @@ -223,9 +239,9 @@ } \cs_new_protected:Npn \__ctex_hookto_cmd_parameterless:Nnnw #1#2#3 { - \tl_if_empty:NF \l__ctex_prefix_tl - { \tl_rescan:nx { } { \l__ctex_prefix_tl } } - \edef #1 + \str_if_empty:NF \l__ctex_prefix_str + { \tl_rescan:nx { } { \l__ctex_prefix_str } } + \tex_edef:D #1 { \use:c { __ctex_ #2 _hook_aux:nn } { \exp_not:o {#1} } @@ -233,16 +249,16 @@ } \__ctex_patch_true:w } +\cs_generate_variant:Nn \tl_rescan:nn { nx } \cs_new:Npn \__ctex_left_hook_aux:nn #1#2 { #2#1 } \cs_new_eq:NN \__ctex_right_hook_aux:nn \use:nn \cs_new_protected:Npn \__ctex_hookto_cmd_parameter:Nnnnw #1#2#3#4 { - \__ctex_patch_rebuild:Nn \CTEXPATCHRESCANCMD {#3} - \cs_if_eq:NNTF #1 \CTEXPATCHRESCANCMD + \__ctex_patch_rebuild:Nn \__ctex_rebuild_cmd:w {#3} + \cs_if_eq:NNTF #1 \__ctex_rebuild_cmd:w { - \use:c { tl_put_ #2 :Nx } \l__ctex_replacement_tl { \tl_to_str:n {#4} } - \__ctex_patch_rebuild:Nn \CTEXPATCHRESCANCMD {#3} - \cs_set_eq:NN #1 \CTEXPATCHRESCANCMD + \use:c { str_put_ #2 :Nn } \l__ctex_replacement_str {#4} + \__ctex_patch_rebuild:Nn #1 {#3} \__ctex_patch_true:w } { \__ctex_patch_false:w } |