Debian Codegraph @

texmf-dist/tex/latex/ctex/ctexhook.sty

raw
1 %%
2 %% This is file `ctexhook.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% ctex.dtx (with options: `ctexhook')
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 {Document and package hooks (CTEX)}
31 \ProvidesExplPackage{ctexhook}
32 {\ExplFileDate}{2.5.10}{\ExplFileDescription}
33 \cs_new:Npn \ctex_if_format_at_least:nTF
34 { \@ifl@t@r \fmtversion }
35 \cs_new_protected:Npn \ctex_file_input:n #1
36 {
37 \ctex_push_file:
38 \file_input:n {#1}
39 \ctex_pop_file:
40 }
41 \bool_if_exist:NTF \l__kernel_expl_bool
42 {
43 \cs_new_protected:Npn \ctex_push_file:
44 {
45 \seq_gpush:Nx \g__ctex_expl_status_seq
46 { \bool_if:NTF \l__kernel_expl_bool { 1 } { 0 } }
47 \bool_set_false:N \l__kernel_expl_bool
48 \cctab_begin:N \c__ctex_package_cctab
49 }
50 \cs_new_protected:Npn \ctex_pop_file:
51 {
52 \cctab_end:
53 \seq_gpop:NN \g__ctex_expl_status_seq \l__ctex_expl_status_tl
54 \int_if_odd:nTF { \l__ctex_expl_status_tl }
55 { \bool_set_true:N \l__kernel_expl_bool }
56 { \bool_set_false:N \l__kernel_expl_bool }
57 }
58 \tl_new:N \l__ctex_expl_status_tl
59 \seq_new:N \g__ctex_expl_status_seq
60 }
61 {
62 \cs_new_protected:Npn \ctex_push_file:
63 { \cctab_begin:N \c__ctex_package_cctab }
64 \cs_new_protected:Npn \ctex_pop_file:
65 { \cctab_end: }
66 }
67 \cctab_const:Nn \c__ctex_package_cctab
68 {
69 \cctab_select:N \c_document_cctab
70 \char_set_catcode_letter:n { 64 }
71 }
72 \cs_new_protected:Npn \ctex_disable_package:n #1
73 {
74 \@ifpackageloaded {#1}
75 { \msg_error:nnxx }
76 { \__ctex_disable_package_aux:nnnn }
77 { ctexhook } { disable-package } {#1} { \@currname }
78 }
79 \cs_new_protected:Npx \__ctex_disable_package_aux:nnnn #1#2#3#4
80 {
81 \cs_if_exist:NTF \disable@package@load
82 {
83 \exp_args:Nnx \exp_not:N \disable@package@load {#3}
84 { \msg_warning:nnnn {#1} {#2} {#3} {#4} }
85 }
86 { \tl_const:cn { ver@ #3 . \exp_not:N \@pkgextension } { 9999/99/99 } }
87 }
88 \msg_new:nnn { ctexhook } { disable-package }
89 { Package~`#1'~can~not~be~loaded~with~`#2'. }
90 \ctex_if_format_at_least:nTF { 2020/10/01 }
91 {
92 \cs_new_protected:Npn \ctex_replace_package:nn #1#2
93 {
94 \declare@file@substitution
95 { #1 . \@pkgextension }
96 { #2 . \@pkgextension }
97 }
98 }
99 {
100 \cs_new_protected:Npn \ctex_replace_package:nn
101 { \msg_warning:nnnn { ctexhook } { replace-package-invalid } }
102 \msg_new:nnn { ctexhook } { replace-package-invalid }
103 {
104 \token_to_str:N \ctex_replace_package:nn \{#1\}\{#2\}~is~invalid~
105 before~LaTeX~2020-10-01.
106 }
107 }
108 \cs_new_protected:Npn \ctex_at_begin_package:nn #1
109 {
110 \@ifpackageloaded {#1}
111 { \__ctex_package_loaded_warning:nn {#1} }
112 { \ctex_gadd_package_hook:nnn { before } {#1} }
113 }
114 \cs_new_protected:Npn \__ctex_package_loaded_warning:nn #1#2
115 { \msg_warning:nnx { ctexhook } { invalid-hook } {#1} }
116 \msg_new:nnn { ctexhook } { invalid-hook }
117 {
118 Package~`#1'~is~loaded. \\
119 \token_to_str:N \ctex_at_begin_package:nn \{#1\}\{...\}~is~invalid.
120 }
121 \cs_new_protected:Npn \ctex_at_end_package:nn #1
122 {
123 \@ifpackageloaded {#1}
124 { \use:n }
125 { \ctex_gadd_package_hook:nnn { after } {#1} }
126 }
127 \ctex_if_format_at_least:nTF { 2020/10/01 }
128 {
129 \cs_new_protected:Npx \ctex_gadd_ltxhook:nn #1
130 { \hook_gput_code:nnn {#1} { \c_novalue_tl } }
131 \cs_new_protected:Npn \ctex_at_end_preamble:n
132 { \ctex_gadd_ltxhook:nn { begindocument/before } }
133 \cs_new_protected:Npn \ctex_after_end_preamble:n
134 { \ctex_gadd_ltxhook:nn { begindocument/end } }
135 \cs_new_protected:Npx \ctex_gadd_package_hook:nnn #1#2
136 {
137 \ctex_if_format_at_least:nTF { 2021/11/15 }
138 { \ctex_gadd_ltxhook:nn { package/#2/#1 } }
139 { \ctex_gadd_ltxhook:nn { package/#1/#2 } }
140 }
141 \file_input_stop:
142 }
143 { }
144 \cs_new_protected:Npn \ctex_at_end_preamble:n
145 { \tl_gput_right:Nn \g__ctex_end_preamble_hook_tl }
146 \cs_new_protected:Npn \ctex_after_end_preamble:n
147 { \tl_gput_right:Nn \g__ctex_after_end_preamble_hook_tl }
148 \cs_new_protected:Npn \CTEX@document@left@hook
149 { \group_end: \g__ctex_end_preamble_hook_tl \group_begin: }
150 \cs_new_protected:Npn \CTEX@document@right@hook
151 { \scan_stop: \g__ctex_after_end_preamble_hook_tl \tex_ignorespaces:D }
152 \cs_set_nopar:Npx \document
153 {
154 \CTEX@document@left@hook
155 \exp_not:o { \document }
156 \CTEX@document@right@hook
157 }
158 \tl_new:N \g__ctex_end_preamble_hook_tl
159 \tl_new:N \g__ctex_after_end_preamble_hook_tl
160 \cs_new_protected:Npn \ctex_gadd_package_hook:nnn #1#2
161 { \ctex_gadd_hook:cn { g__ctex_at_ #1 _ #2 _hook_tl } }
162 \cs_new_protected:Npn \ctex_gadd_hook:Nn #1
163 {
164 \tl_if_exist:NF #1 { \tl_new:N #1 }
165 \tl_gput_right:Nn #1
166 }
167 \cs_generate_variant:Nn \ctex_gadd_hook:Nn { c }
168 \cs_new_protected:Npn \ctex_use_package_hook:nn #1#2
169 {
170 \group_begin: \exp_args:NNc \group_end:
171 \__ctex_use_package_hook_aux:N { g__ctex_at_ #1 _ #2 _hook_tl }
172 }
173 \cs_new_protected:Npn \__ctex_use_package_hook_aux:N #1
174 { \cs_if_exist_use:NT #1 { \cs_undefine:N #1 } }
175 \tl_put_right:Nn \@reset@ptions { \CTEX@reset@ptions@hook }
176 \cs_new_protected:Npn \CTEX@reset@ptions@hook
177 {
178 \cs_if_eq:NNT \@currext \@pkgextension
179 { \ctex_use_package_hook:nn { before } { \@currname } }
180 }
181 \tl_put_left:Nn \@popfilename { \CTEX@popfilename@hook }
182 \cs_new_protected:Npn \CTEX@popfilename@hook
183 {
184 \cs_if_eq:NNT \@currext \@pkgextension
185 { \ctex_use_package_hook:nn { after } { \@currname } }
186 }
187 %%
188 %%
189 %% End of file `ctexhook.sty'.