| 1 |
%% |
| 2 |
%% This is file `ctexpatch.sty', |
| 3 |
%% generated with the docstrip utility. |
| 4 |
%% |
| 5 |
%% The original source files were: |
| 6 |
%% |
| 7 |
%% ctex.dtx (with options: `ctexpatch') |
| 8 |
%% |
| 9 |
%% Copyright (C) 2003--2022 |
| 10 |
%% CTEX.ORG and any individual authors listed in the documentation. |
| 11 |
%% --------------------------------------------------------------------- |
| 12 |
%% |
| 13 |
%% This work may be distributed and/or modified under the |
| 14 |
%% conditions of the LaTeX Project Public License, either |
| 15 |
%% version 1.3c of this license or (at your option) any later |
| 16 |
%% version. This version of this license is in |
| 17 |
%% http://www.latex-project.org/lppl/lppl-1-3c.txt |
| 18 |
%% and the latest version of this license is in |
| 19 |
%% http://www.latex-project.org/lppl.txt |
| 20 |
%% and version 1.3 or later is part of all distributions of |
| 21 |
%% LaTeX version 2005/12/01 or later. |
| 22 |
%% |
| 23 |
%% This work has the LPPL maintenance status "maintained". |
| 24 |
%% |
| 25 |
%% --------------------------------------------------------------------- |
| 26 |
%% |
| 27 |
\NeedsTeXFormat{LaTeX2e} |
| 28 |
\RequirePackage{expl3} |
| 29 |
\GetIdInfo$Id: ctex.dtx 13a2256 2022-07-14 18:54:09 +0800 Qing Lee <[email protected]> $ |
| 30 |
{Patching commands (CTEX)} |
| 31 |
\ProvidesExplPackage{ctexpatch} |
| 32 |
{\ExplFileDate}{2.5.10}{\ExplFileDescription} |
| 33 |
\cs_new_protected:Npn \ctex_patch_cmd_once:NnnnTF #1#2 |
| 34 |
{ |
| 35 |
\ctex_patch_boot:NNnnTF \__ctex_patch_cmd:Nnnnnw #1 |
| 36 |
{ once } {#2} { \use_i:nn } { \use_ii:nn } |
| 37 |
} |
| 38 |
\cs_new_protected:Npn \ctex_patch_cmd_all:NnnnTF #1#2 |
| 39 |
{ |
| 40 |
\ctex_patch_boot:NNnnTF \__ctex_patch_cmd:Nnnnnw #1 |
| 41 |
{ all } {#2} { \use_i:nn } { \use_ii:nn } |
| 42 |
} |
| 43 |
\cs_new_protected:Npn \ctex_patch_cmd:Nnn #1 |
| 44 |
{ |
| 45 |
\ctex_patch_boot:NNnnTF \__ctex_patch_cmd:Nnnnnw #1 |
| 46 |
{ once } |
| 47 |
{ |
| 48 |
\ExplSyntaxOff |
| 49 |
\char_set_catcode_letter:n { 64 } |
| 50 |
} |
| 51 |
{ } |
| 52 |
{ \ctex_patch_failure:N #1 } |
| 53 |
} |
| 54 |
\cs_new_protected:Npn \ctex_patch_failure:N #1 |
| 55 |
{ \msg_warning:nnx { ctexpatch } { patch-failure } { \token_to_str:N #1 } } |
| 56 |
\msg_new:nnn { ctexpatch } { patch-failure } |
| 57 |
{ Oops!~Command~`#1'~is~NOT~patchable.\\ } |
| 58 |
\cs_new_protected:Npn \ctex_preto_cmd:NnnTF #1#2 |
| 59 |
{ |
| 60 |
\ctex_patch_boot:NNnnTF \__ctex_hookto_cmd:Nnnnw #1 |
| 61 |
{ left } {#2} { \use_i:nn } { \use_ii:nn } |
| 62 |
} |
| 63 |
\cs_new_protected:Npn \ctex_appto_cmd:NnnTF #1#2 |
| 64 |
{ |
| 65 |
\ctex_patch_boot:NNnnTF \__ctex_hookto_cmd:Nnnnw #1 |
| 66 |
{ right } {#2} { \use_i:nn } { \use_ii:nn } |
| 67 |
} |
| 68 |
\cs_new_protected:Npn \ctex_patch_boot:NNnnTF #1#2#3#4#5#6 |
| 69 |
{ |
| 70 |
\cs_set_protected:Npx \__ctex_patch_true:w { \exp_not:n {#5} } |
| 71 |
\cs_set_protected:Npx \__ctex_patch_false:w { \exp_not:n {#6} } |
| 72 |
\group_begin: |
| 73 |
\char_set_catcode_other:n { 35 } |
| 74 |
\ctex_parse_name:NN #1 #2 {#3} {#4} |
| 75 |
} |
| 76 |
\cs_new_eq:NN \__ctex_patch_true:w \use_i:nn |
| 77 |
\cs_new_eq:NN \__ctex_patch_false:w \use_ii:nn |
| 78 |
\cs_new_protected:Npn \ctex_parse_name:NN #1#2 |
| 79 |
{ \ctex_parse_name:NNx #1#2 { \cs_to_str:N #2 } } |
| 80 |
\group_begin: |
| 81 |
\cs_set_protected:Npn \__ctex_tmp:w #1#2#3 |
| 82 |
{ |
| 83 |
\cs_new_protected:Npn \ctex_parse_name:NNn ##1##2##3 |
| 84 |
{ |
| 85 |
\bool_lazy_or:nnTF |
| 86 |
{ \cs_if_exist_p:c { ##3 ~ } } |
| 87 |
{ \cs_if_exist_p:c { #1##3 } } |
| 88 |
{ |
| 89 |
\group_begin: |
| 90 |
\use:e |
| 91 |
{ |
| 92 |
\group_end: |
| 93 |
\__ctex_parse_name:nNNNnN |
| 94 |
{ \cs_replacement_spec:N ##2 } |
| 95 |
\exp_not:N ##2 |
| 96 |
\exp_not:c { ##3 ~ } |
| 97 |
\exp_not:c { #1##3 } |
| 98 |
} { ##3 } ##1 |
| 99 |
} |
| 100 |
{ ##1##2 } |
| 101 |
} |
| 102 |
\cs_new_protected:Npn \__ctex_parse_name:nNNNnN ##1##2##3##4##5##6 |
| 103 |
{ |
| 104 |
\exp_args:Nc ##6 |
| 105 |
{ |
| 106 |
\str_case:nnTF {##1} |
| 107 |
{ |
| 108 |
{ \protect ##3 } { } |
| 109 |
{ \x@protect ##2 \protect ##3 } { } |
| 110 |
} |
| 111 |
{ |
| 112 |
\str_if_eq:eeTF |
| 113 |
{ \exp_not:n { #1@protected@ ##3 #1##3 } } |
| 114 |
{ |
| 115 |
\exp_last_unbraced:Ne \__ctex_parse_name:w |
| 116 |
{ \cs_replacement_spec:N ##3 } #3 ~ #2 \q_stop |
| 117 |
} |
| 118 |
{ #1##5 ~ } { ##5 ~ } |
| 119 |
} |
| 120 |
{ |
| 121 |
\str_case:onTF { \__ctex_parse_name:w ##1 #3 ~ #2 \q_stop } |
| 122 |
{ |
| 123 |
{ #1@protected@ ##2 ##4 } { } |
| 124 |
{ #1@ ##4 } { } |
| 125 |
} |
| 126 |
{ #1##5 } {##5} |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
\cs_new:Npn \__ctex_parse_name:w ##1 #3 ~ ##2 #2 ##3 \q_stop { ##1##2 } |
| 131 |
} |
| 132 |
\use:e |
| 133 |
{ |
| 134 |
\__ctex_tmp:w |
| 135 |
{ \c_backslash_str } |
| 136 |
{ \c_left_brace_str } |
| 137 |
{ \tl_to_str:n { testopt } } |
| 138 |
} |
| 139 |
\group_end: |
| 140 |
\cs_generate_variant:Nn \ctex_parse_name:NNn { NNx } |
| 141 |
\str_new:N \l__ctex_prefix_str |
| 142 |
\str_new:N \l__ctex_parameter_str |
| 143 |
\str_new:N \l__ctex_replacement_str |
| 144 |
\group_begin: |
| 145 |
\cs_set_protected:Npn \__ctex_tmp:w #1 |
| 146 |
{ |
| 147 |
\prg_new_protected_conditional:Npnn |
| 148 |
\ctex_get_macro_meaning:N ##1 { TF } |
| 149 |
{ |
| 150 |
\exp_after:wN \__ctex_get_macro_meaning:w |
| 151 |
\token_to_meaning:N ##1 \q_mark #1 -> \q_mark \q_stop |
| 152 |
} |
| 153 |
\cs_new_protected:Npn \__ctex_get_macro_meaning:w |
| 154 |
##1 #1 ##2 -> ##3 \q_mark ##4 \q_stop |
| 155 |
{ |
| 156 |
\tl_if_empty:nTF { ##4 } |
| 157 |
{ \prg_return_false: } |
| 158 |
{ |
| 159 |
\str_set:Nn \l__ctex_prefix_str { ##1 } |
| 160 |
\str_set:Nn \l__ctex_parameter_str { ##2 } |
| 161 |
\str_set:Nn \l__ctex_replacement_str { ##3 } |
| 162 |
\prg_return_true: |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
\exp_args:No \__ctex_tmp:w { \tl_to_str:n { macro: } } |
| 167 |
\group_end: |
| 168 |
\cs_new_protected:Npn \ctex_if_rescanable:NnTF #1#2#3#4 |
| 169 |
{ |
| 170 |
\ctex_get_macro_meaning:NTF #1 |
| 171 |
{ |
| 172 |
\__ctex_patch_rebuild:Nn \__ctex_rebuild_cmd:w {#2} |
| 173 |
\cs_if_eq:NNTF #1 \__ctex_rebuild_cmd:w {#3} {#4} |
| 174 |
} |
| 175 |
{#4} |
| 176 |
} |
| 177 |
\cs_new_eq:NN \__ctex_rebuild_cmd:w \prg_do_nothing: |
| 178 |
\cs_new_protected:Npn \__ctex_patch_rebuild:Nn #1#2 |
| 179 |
{ |
| 180 |
\__ctex_patch_rescan:NNn \l__ctex_prefix_tl \l__ctex_prefix_str {#2} |
| 181 |
\__ctex_patch_rescan:NNn \l__ctex_parameter_tl \l__ctex_parameter_str {#2} |
| 182 |
\__ctex_patch_rescan:NNn \l__ctex_replacement_tl \l__ctex_replacement_str {#2} |
| 183 |
\use:e |
| 184 |
{ |
| 185 |
\exp_not:o { \l__ctex_prefix_tl } \tex_def:D \exp_not:N #1 |
| 186 |
\exp_not:o { \l__ctex_parameter_tl } |
| 187 |
{ \exp_not:o { \l__ctex_replacement_tl } } |
| 188 |
} |
| 189 |
} |
| 190 |
\cs_new_protected:Npn \__ctex_patch_rescan:NNn #1#2#3 |
| 191 |
{ |
| 192 |
\str_if_empty:NTF #2 |
| 193 |
{ \tl_clear:N #1 } |
| 194 |
{ \tl_set_rescan:Nno #1 {#3} {#2} } |
| 195 |
} |
| 196 |
\tl_new:N \l__ctex_prefix_tl |
| 197 |
\tl_new:N \l__ctex_parameter_tl |
| 198 |
\tl_new:N \l__ctex_replacement_tl |
| 199 |
\cs_new_protected:Npn \__ctex_patch_cmd:Nnnnnw #1#2#3#4#5 |
| 200 |
{ |
| 201 |
\group_end: |
| 202 |
\ctex_if_rescanable:NnTF #1 {#3} |
| 203 |
{ |
| 204 |
\use:e |
| 205 |
{ |
| 206 |
\__ctex_patch_replace:nnnTF {#2} |
| 207 |
{ \tl_to_str:n {#4} } |
| 208 |
{ \tl_to_str:n {#5} } |
| 209 |
} |
| 210 |
{ |
| 211 |
\__ctex_patch_rebuild:Nn #1 {#3} |
| 212 |
\__ctex_patch_true:w |
| 213 |
} |
| 214 |
{ \__ctex_patch_false:w } |
| 215 |
} |
| 216 |
{ \__ctex_patch_false:w } |
| 217 |
} |
| 218 |
\cs_new_protected:Npn \__ctex_patch_replace:nnnTF #1#2#3#4 |
| 219 |
{ |
| 220 |
\tl_if_in:NnTF \l__ctex_replacement_str {#2} |
| 221 |
{ \use:c { tl_replace_ #1 :Nnn } \l__ctex_replacement_str {#2} {#3} #4 } |
| 222 |
} |
| 223 |
\cs_new_protected:Npn \__ctex_hookto_cmd:Nnnnw #1#2#3#4 |
| 224 |
{ |
| 225 |
\group_end: |
| 226 |
\ctex_get_macro_meaning:NTF #1 |
| 227 |
{ |
| 228 |
\str_if_empty:NTF \l__ctex_parameter_str |
| 229 |
{ \__ctex_hookto_cmd_parameterless:Nnnnw } |
| 230 |
{ \__ctex_hookto_cmd_parameter:Nnnnw } |
| 231 |
#1 {#2} {#3} {#4} |
| 232 |
} |
| 233 |
{ \__ctex_patch_false:w } |
| 234 |
} |
| 235 |
\cs_new_protected:Npn \__ctex_hookto_cmd_parameterless:Nnnnw #1#2#3#4 |
| 236 |
{ |
| 237 |
\str_if_empty:NF \l__ctex_prefix_str |
| 238 |
{ \tl_rescan:no {#3} { \l__ctex_prefix_str } } |
| 239 |
\tex_edef:D #1 |
| 240 |
{ |
| 241 |
\use:c { __ctex_ #2 _hook_aux:nn } |
| 242 |
{ \exp_not:o {#1} } |
| 243 |
{ \exp_not:n {#4} } |
| 244 |
} |
| 245 |
\__ctex_patch_true:w |
| 246 |
} |
| 247 |
\cs_generate_variant:Nn \tl_rescan:nn { no } |
| 248 |
\cs_new:Npn \__ctex_left_hook_aux:nn #1#2 { #2#1 } |
| 249 |
\cs_new_eq:NN \__ctex_right_hook_aux:nn \use:nn |
| 250 |
\cs_new_protected:Npn \__ctex_hookto_cmd_parameter:Nnnnw #1#2#3#4 |
| 251 |
{ |
| 252 |
\__ctex_patch_rebuild:Nn \__ctex_rebuild_cmd:w {#3} |
| 253 |
\cs_if_eq:NNTF #1 \__ctex_rebuild_cmd:w |
| 254 |
{ |
| 255 |
\use:c { str_put_ #2 :Nn } \l__ctex_replacement_str {#4} |
| 256 |
\__ctex_patch_rebuild:Nn #1 {#3} |
| 257 |
\__ctex_patch_true:w |
| 258 |
} |
| 259 |
{ \__ctex_patch_false:w } |
| 260 |
} |
| 261 |
%% |
| 262 |
%% |
| 263 |
%% End of file `ctexpatch.sty'. |