Debian Codegraph @

texmf-dist/tex/latex/ctex/ctexbook.cls

raw
1 %%
2 %% This is file `ctexbook.cls',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% ctex.dtx (with options: `class,book')
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 \input{ctexbackend.cfg}
29 \RequirePackage{expl3}
30 \GetIdInfo$Id: ctex.dtx 13a2256 2022-07-14 18:54:09 +0800 Qing Lee <[email protected]> $
31 {Chinese adapter for class book (CTEX)}
32 \ProvidesExplClass{ctexbook}
33 {\ExplFileDate}{2.5.10}{\ExplFileDescription}
34 \cs_if_exist:NF \NewDocumentCommand
35 { \RequirePackage { xparse } }
36 \prop_gput:Nnn \g_msg_module_type_prop { ctex } { Class }
37 \prop_gput:Nnn \g_msg_module_name_prop { ctex } { ctexbook }
38 \msg_new:nnnn { ctex } { l3-too-old }
39 { Support~package~`#1'~too~old. }
40 {
41 Please~update~an~up-to-date~version~of~the~bundles\\\\
42 `l3kernel'~and~`l3packages'\\\\
43 using~your~TeX~package~manager~or~from~CTAN.
44 }
45 \@ifpackagelater { expl3 } { 2021/02/10 } { }
46 { \msg_error:nnn { ctex } { l3-too-old } { expl3 } }
47 \str_const:Nx \c__ctex_engine_str
48 { \cs_if_exist:NTF \ngostype { aptex } { \c_sys_engine_str } }
49 \msg_new:nnnn { ctex } { engine-not-supported }
50 { Engine~`#1'~is~not~yet~supported,~ctex~will~abort! }
51 { You~can~switch~to~xelatex,~lualatex,~pdflatex,~uplatex,~or~aplatex. }
52 \file_if_exist:nTF { ctex-engine- \c__ctex_engine_str .def }
53 {
54 \str_const:Nx \c__ctex_engine_file_str
55 { ctex-engine- \c__ctex_engine_str .def }
56 }
57 { \msg_critical:nnx { ctex } { engine-not-supported } { \c__ctex_engine_str } }
58 \RequirePackage { ctexhook , ctexpatch }
59 \RequirePackage { fix-cm }
60 \ctex_disable_package:n { ctex }
61 \ctex_disable_package:n { ctexcap }
62 \ctex_disable_package:n { ctexsize }
63 \ctex_disable_package:n { ctexheading }
64 \ctex_if_format_at_least:nTF { 2021/06/01 }
65 { \bool_const:Nn \c__ctex_everysel_loaded_bool { \c_false_bool } }
66 {
67 \RequirePackage { everysel }
68 \bool_const:Nn \c__ctex_everysel_loaded_bool { \c_true_bool }
69 }
70 \tl_clear_new:N \l__ctex_tmp_tl
71 \int_new:N \l__ctex_tmp_int
72 \box_new:N \l__ctex_tmp_box
73 \dim_new:N \l__ctex_tmp_dim
74 \cs_new_protected:Npn \ctex_define_option:n
75 { \keys_define:nn { ctex / option } }
76 \cs_new_protected:Npn \ctex_define:n
77 { \keys_define:nn { ctex } }
78 \cs_new_protected:Npn \ctex_set:n
79 { \keys_set:nn { ctex } }
80 \cs_new_protected:Npn \ctex_set:nn #1
81 { \keys_set:nn { ctex / #1 } }
82 \cs_new_protected:Npn \ctex_scheme_input:n #1
83 {
84 \ctex_push_file:
85 \tl_if_exist:NTF \c__ctex_class_tl
86 {
87 \file_if_exist_input:nF { ctex-scheme- #1 - \c__ctex_class_tl .def }
88 { \file_input:n { ctex-scheme- #1 .def } }
89 }
90 { \file_input:n { ctex-scheme- #1 .def } }
91 \ctex_pop_file:
92 }
93 \cs_generate_variant:Nn \ctex_scheme_input:n { o }
94 \int_new:N \g__ctex_section_depth_int
95 \int_gset:Nn \g__ctex_section_depth_int { 2 }
96 \msg_new:nnnn { ctex } { package-too-old }
97 { Support~package~`#1'~too~old. }
98 {
99 Please~update~an~up-to-date~version~of~the~package~`#1'\\
100 using~your~TeX~package~manager~or~from~CTAN.
101 }
102 \sys_if_output_pdf:TF
103 { \cs_new_eq:NN \ifctexpdf \if_true: }
104 { \cs_new_eq:NN \ifctexpdf \if_false: }
105 \cs_new_eq:NN \ctex_if_preamble:TF \use_i:nn
106 \ctex_after_end_preamble:n { \cs_set_eq:NN \ctex_if_preamble:TF \use_ii:nn }
107 \cs_new_protected:Npn \ctex_set_default_ccwd:Nn #1#2
108 { \tl_set:Nx #1 { \__ctex_default_ccwd_aux:n {#2} } }
109 \cs_new:Npn \__ctex_default_ccwd_aux:n #1
110 {
111 \exp_not:n {#1}
112 \exp_after:wN \__ctex_default_ccwd_aux:w
113 \dim_use:N \tex_dimexpr:D #1 pt \scan_stop: \q_stop
114 }
115 \exp_last_unbraced:NNNNo
116 \cs_new:Npn \__ctex_default_ccwd_aux:w #1 { \tl_to_str:n { pt } } #2 \q_stop
117 { \tl_if_empty:nT {#2} { \ccwd } }
118 \tl_new:N \g__ctex_encoding_tl
119 \bool_new:N \g__ctex_zhmCJK_bool
120 \tl_new:N \l__ctex_autoindent_tl
121 \cs_new_eq:NN \ctex_if_autoindent_touched:F \use:n
122 \cs_new_eq:NN \ctex_zhmap_case:nnn \use_ii:nnn
123 \cs_new_protected:Npn \ctex_at_end:n { \AtEndOfClass }
124 \cs_new_protected:Npn \ctex_load_std_class:n #1
125 {
126 \tl_const:Nn \c__ctex_class_tl {#1}
127 \exp_args:No \PassOptionsToClass
128 { \g__ctex_std_options_clist }
129 {#1}
130 \LoadClass {#1}
131 }
132 \clist_new:N \g__ctex_std_options_clist
133 \msg_new:nnn { ctex } { invalid-option }
134 { Option~`\l_keys_key_tl'~is~invalid~in~current~mode. }
135 \msg_new:nnn { ctex } { invalid-value }
136 { Value~`#1'~is~invalid~for~the~key~`\l_keys_key_tl'. }
137 \cs_new_protected:Npn \ctex_deprecated_option:n
138 { \msg_warning:nnn { ctex } { deprecated-option } }
139 \cs_new_protected:Npn \ctex_set_deprecated_option:n #1
140 {
141 \ctex_deprecated_option:n { Option~`#1'~is~set. }
142 \ctex_set:nn { option } {#1}
143 }
144 \cs_new_protected:Npn \ctex_deprecated_command:Nn #1#2
145 {
146 \msg_warning:nnxx { ctex } { deprecated-command }
147 { \token_to_str:N #1 } { \exp_not:n {#2} }
148 }
149 \msg_new:nnn { ctex } { deprecated-option }
150 { Option~`\l_keys_key_tl'~is~deprecated.\\ #1 }
151 \msg_new:nnn { ctex } { deprecated-command }
152 { Command~`#1'~is~deprecated.\\ #2 }
153 \int_new:N \g__ctex_font_size_int
154 \int_gset:Nn \g__ctex_font_size_int { -1 }
155 \ctex_define_option:n
156 {
157 zihao .choice: ,
158 zihao .value_required:n = true ,
159 zihao / 5 .code:n = { \int_gset:Nn \g__ctex_font_size_int { 0 } } ,
160 zihao / -4 .code:n = { \int_gset:Nn \g__ctex_font_size_int { 1 } } ,
161 zihao / false .code:n = { \int_gset:Nn \g__ctex_font_size_int { 2 } } ,
162 c5size .code:n = { \ctex_set_deprecated_option:n { zihao = 5 } } ,
163 cs4size .code:n = { \ctex_set_deprecated_option:n { zihao = -4 } } ,
164 c5size .value_forbidden:n = true ,
165 cs4size .value_forbidden:n = true ,
166 linespread .fp_set:N = \l__ctex_line_spread_fp ,
167 linespread .initial:n = { \c_nan_fp } ,
168 linespread .value_required:n = true ,
169 autoindent .choice: ,
170 autoindent .default:n = { true } ,
171 autoindent / true .code:n =
172 {
173 \tl_set:Nn \l__ctex_autoindent_tl { 2 \ccwd }
174 \cs_set_eq:NN \ctex_if_autoindent_touched:F \use_none:n
175 } ,
176 autoindent / false .code:n =
177 {
178 \tl_clear:N \l__ctex_autoindent_tl
179 \cs_set_eq:NN \ctex_if_autoindent_touched:F \use_none:n
180 } ,
181 autoindent / unknown .code:n =
182 {
183 \ctex_set_default_ccwd:Nn \l__ctex_autoindent_tl {#1}
184 \cs_set_eq:NN \ctex_if_autoindent_touched:F \use_none:n
185 } ,
186 indent .code:n =
187 {
188 \ctex_deprecated_option:n
189 {
190 The~functionality~has~been~removed.\\
191 It's~better~to~set~the~heading~styles~via~`afterindent'~option.
192 }
193 } ,
194 indent .value_forbidden:n = true ,
195 noindent .code:n =
196 {
197 \ctex_deprecated_option:n
198 {
199 The~functionality~has~been~removed.\\
200 It's~better~to~set~the~heading~styles~via~`afterindent'~option.
201 }
202 } ,
203 noindent .value_forbidden:n = true ,
204 GBK .code:n =
205 {
206 \sys_if_engine_pdftex:TF
207 { \tl_gset:Nn \g__ctex_encoding_tl { GBK } }
208 {
209 \msg_warning:nn { ctex } { invalid-option }
210 \tl_gset:Nn \g__ctex_encoding_tl { UTF8 }
211 }
212 } ,
213 UTF8 .code:n = { \tl_gset:Nn \g__ctex_encoding_tl { UTF8 } } ,
214 GBK .value_forbidden:n = true ,
215 UTF8 .value_forbidden:n = true ,
216 fontset .tl_gset:N = \g__ctex_fontset_tl ,
217 nofonts .code:n = { \ctex_set_deprecated_option:n { fontset = none } } ,
218 adobefonts .code:n = { \ctex_set_deprecated_option:n { fontset = adobe } } ,
219 winfonts .code:n = { \ctex_set_deprecated_option:n { fontset = windows } } ,
220 nofonts .value_forbidden:n = true ,
221 winfonts .value_forbidden:n = true ,
222 adobefonts .value_forbidden:n = true ,
223 zhmap .choice: ,
224 zhmap .default:n = { true } ,
225 zhmap / zhmCJK .code:n =
226 {
227 \bool_gset_true:N \g__ctex_zhmCJK_bool
228 \cs_gset_eq:NN \ctex_zhmap_case:nnn \use_i:nnn
229 } ,
230 zhmap / true .code:n =
231 {
232 \bool_gset_false:N \g__ctex_zhmCJK_bool
233 \cs_gset_eq:NN \ctex_zhmap_case:nnn \use_ii:nnn
234 } ,
235 zhmap / false .code:n =
236 {
237 \bool_gset_false:N \g__ctex_zhmCJK_bool
238 \cs_gset_eq:NN \ctex_zhmap_case:nnn \use_iii:nnn
239 } ,
240 nozhmap .code:n =
241 { \ctex_set_deprecated_option:n { zhmap = false } } ,
242 nozhmap .value_forbidden:n = true ,
243 punct .tl_set:N = \l__ctex_punct_tl ,
244 punct .default:n = { quanjiao } ,
245 punct .initial:n = { quanjiao } ,
246 nopunct .code:n = \ctex_set_deprecated_option:n { punct = plain } ,
247 nopunct .value_forbidden:n = true ,
248 space .choices:nn =
249 { true , auto , false }
250 {
251 \exp_args:Ne \ctex_at_end:n
252 { \ctex_set:n { space = \l_keys_choice_tl } }
253 } ,
254 space .default:n = { true } ,
255 nospace .code:n = { \ctex_deprecated_option:nn { space = false } } ,
256 nospace .value_forbidden:n = true ,
257 heading .bool_set:N = \l__ctex_heading_bool ,
258 sub3section .code:n =
259 { \int_gset:Nn \g__ctex_section_depth_int { 3 } } ,
260 sub4section .code:n =
261 { \int_gset:Nn \g__ctex_section_depth_int { 4 } } ,
262 sub3section .value_forbidden:n = true ,
263 sub4section .value_forbidden:n = true ,
264 scheme .tl_set:N = \l__ctex_scheme_tl ,
265 scheme .default:n = { chinese } ,
266 scheme .initial:n = { chinese } ,
267 cap .code:n = { \ctex_set_deprecated_option:n { scheme = chinese } } ,
268 nocap .code:n = { \ctex_set_deprecated_option:n { scheme = plain } } ,
269 cap .value_forbidden:n = true ,
270 nocap .value_forbidden:n = true ,
271 fntef .code:n =
272 {
273 \sys_if_engine_xetex:TF
274 {
275 \ctex_deprecated_option:n { `xeCJKfntef'~package~is~loaded. }
276 \ctex_at_end:n { \RequirePackage { xeCJKfntef } }
277 }
278 {
279 \sys_if_engine_pdftex:TF
280 {
281 \ctex_deprecated_option:n { `CJKfntef'~package~is~loaded. }
282 \ctex_at_end:n { \RequirePackage { CJKfntef } }
283 }
284 {
285 \ctex_deprecated_option:n
286 { Furthermore,~option~`fntef'~is~invalid~in~current~mode. }
287 }
288 }
289 } ,
290 fancyhdr .code:n =
291 {
292 \ctex_deprecated_option:n { `fancyhdr'~package~is~loaded. }
293 \ctex_at_end:n { \RequirePackage { fancyhdr } }
294 } ,
295 hyperref .code:n =
296 {
297 \ctex_deprecated_option:n { `hyperref'~package~will~be~loaded. }
298 \ctex_at_end:n
299 {
300 \cs_if_exist:NF \hypersetup
301 { \cs_new_eq:NN \hypersetup \ctex_hypersetup:n }
302 }
303 \ctex_at_end_preamble:n { \RequirePackage { hyperref } }
304 } ,
305 }
306 \tl_clear_new:N \l__ctex_tmp_tl
307 \clist_map_inline:nn
308 {
309 10pt , 11pt , 12pt ,
310 8pt , 9pt , 14pt , 17pt , 20pt , 25pt , 30pt , 36pt , 48pt , 60pt
311 }
312 {
313 \tl_put_right:Nn \l__ctex_tmp_tl
314 {
315 #1 .code:n =
316 {
317 \int_gset:Nn \g__ctex_font_size_int { 2 }
318 \clist_gput_right:Nn \g__ctex_std_options_clist {#1}
319 } ,
320 #1 .value_forbidden:n = true ,
321 }
322 }
323 \exp_args:No \ctex_define_option:n { \l__ctex_tmp_tl }
324 \tl_clear:N \l__ctex_tmp_tl
325 \ctex_define_option:n
326 {
327 unknown .code:n =
328 { \clist_gput_right:No \g__ctex_std_options_clist { \CurrentOption } }
329 }
330 \ctex_file_input:n { ctexopts.cfg }
331 \cs_if_exist:NTF \ProcessKeyOptions
332 { \ProcessKeyOptions [ ctex / option ] }
333 {
334 \RequirePackage { l3keys2e }
335 \ProcessKeysOptions { ctex / option }
336 }
337 \msg_new:nnn { ctex } { pdftex-utf8 }
338 { UTF8~will~be~used~as~the~default~encoding. }
339 \tl_if_empty:NT \g__ctex_encoding_tl
340 {
341 \sys_if_engine_pdftex:T
342 { \msg_warning:nn { ctex } { pdftex-utf8 } }
343 \tl_gset:Nn \g__ctex_encoding_tl { UTF8 }
344 }
345 \int_case:nn { \g__ctex_font_size_int }
346 {
347 { 0 } { \clist_gput_right:Nn \g__ctex_std_options_clist { 10pt } }
348 { 1 } { \clist_gput_right:Nn \g__ctex_std_options_clist { 12pt } }
349 }
350 \ctex_load_std_class:n { book }
351 \@ifpackageloaded { hyperref }
352 {
353 \cs_new_protected:Npn \ctex_hypersetup:n #1
354 { \hypersetup {#1} }
355 }
356 {
357 \cs_new_protected:Npn \ctex_hypersetup:n #1
358 { \PassOptionsToPackage {#1} { hyperref } }
359 }
360 \ctex_file_input:n { \c__ctex_engine_file_str }
361 \NewDocumentCommand \ctexset { } { \ctex_set:n }
362 \NewDocumentCommand \CTEXsetup { +O { } > { \TrimSpaces } m }
363 {
364 \tl_if_blank:nTF {#1}
365 { \ctex_deprecated_command:Nn \CTEXsetup { } }
366 {
367 \ctex_deprecated_command:Nn \CTEXsetup
368 { \ctexset {~#2~=~{~#1~}~}~is~set. }
369 \ctex_set:nn {#2} {#1}
370 }
371 }
372 \NewDocumentCommand \CTEXoptions { +O { } }
373 {
374 \tl_if_blank:nTF {#1}
375 { \ctex_deprecated_command:Nn \CTEXoptions { } }
376 {
377 \ctex_deprecated_command:Nn \CTEXoptions
378 { \ctexset {~#1~}~is~set. }
379 \ctex_set:n {#1}
380 }
381 }
382 \ctex_define:n
383 {
384 autoindent .choice: ,
385 autoindent .default:n = { true } ,
386 autoindent / true .code:n =
387 {
388 \tl_set:Nn \l__ctex_autoindent_tl { 2 \ccwd }
389 \ctex_select_size:
390 } ,
391 autoindent / false .code:n =
392 { \tl_clear:N \l__ctex_autoindent_tl } ,
393 autoindent / unknown .code:n =
394 {
395 \ctex_set_default_ccwd:Nn \l__ctex_autoindent_tl {#1}
396 \ctex_select_size:
397 }
398 }
399 \NewDocumentCommand \CTEXsetfont { } { \ctex_select_size: }
400 \cs_new_protected:Npn \ctex_select_size:
401 { \cs_if_free:NTF \size@update { \ctex_update_size: } { \selectfont } }
402 \cs_new_protected:Npn \ctex_update_size:
403 {
404 \tl_if_eq:NNTF \l__ctex_ziju_tl \c__ctex_zero_tl
405 {
406 \ctex_update_stretch:
407 \ctex_update_parindent:
408 }
409 { \ctex_update_ziju: }
410 }
411 \tl_const:Nx \c__ctex_zero_tl { \fp_use:N \c_zero_fp }
412 \tl_new:N \l__ctex_ziju_tl
413 \tl_set_eq:NN \l__ctex_ziju_tl \c__ctex_zero_tl
414 \ctex_add_to_selectfont:n
415 { \cs_if_free:NF \size@update { \ctex_update_size: } }
416 \ctex_define:n
417 {
418 linestretch .code:n =
419 {
420 \ctex_set_default_ccwd:Nn \l__ctex_line_stretch_tl {#1}
421 \ctex_select_size:
422 } ,
423 linestretch .value_required:n = true
424 }
425 \tl_new:N \l__ctex_line_stretch_tl
426 \tl_set:Nn \l__ctex_line_stretch_tl { \ccwd }
427 \cs_new_protected:Npn \ctex_update_stretch:
428 {
429 \ctex_update_em_unit:
430 \dim_set:Nn \l__ctex_tmp_dim { \l__ctex_line_stretch_tl }
431 \dim_compare:nNnTF \l__ctex_tmp_dim = \c_max_dim
432 { \__ctex_update_stretch_auxi: }
433 { \__ctex_update_stretch_auxii: }
434 }
435 \cs_new_protected:Npn \__ctex_update_stretch_auxi:
436 {
437 \ctex_if_ccglue_touched:TF
438 { \ctex_update_ccwd: }
439 {
440 \dim_set:Nn \l__ctex_tmp_dim
441 { \baselinestretch \tex_glueexpr:D \f@baselineskip \scan_stop: }
442 \skip_set:Nn \l__ctex_ccglue_skip
443 { \c_zero_dim plus .08 \l__ctex_tmp_dim }
444 \ctex_update_ccglue:
445 }
446 }
447 \cs_new_protected:Npn \__ctex_update_stretch_auxii:
448 {
449 \int_set:Nn \l__ctex_tmp_int
450 { \tex_dimexpr:D \linewidth - \ccwd - \l__ctex_tmp_dim \scan_stop: }
451 \tex_divide:D \l__ctex_tmp_int \ccwd
452 \int_compare:nNnTF \l__ctex_tmp_int > \c_zero_int
453 {
454 \skip_set:Nn \l__ctex_ccglue_skip
455 {
456 \c_zero_dim plus \dim_eval:n
457 {
458 ( \linewidth - \ccwd - \l__ctex_tmp_int \ccwd ) /
459 \l__ctex_tmp_int
460 }
461 }
462 }
463 { \skip_zero:N \l__ctex_ccglue_skip }
464 \ctex_update_ccglue:
465 }
466 \cs_new_protected:Npn \ctex_update_parindent:
467 {
468 \tl_if_empty:NF \l__ctex_autoindent_tl
469 {
470 \dim_compare:nNnF \parindent = \c_zero_dim
471 { \dim_set:Nn \parindent { \l__ctex_autoindent_tl } }
472 }
473 }
474 \NewDocumentCommand \ziju { m }
475 { \exp_args:Nx \ctex_ziju:n {#1} \tex_ignorespaces:D }
476 \cs_new_protected:Npn \ctex_ziju:n #1
477 {
478 \tl_set:Nx \l__ctex_ziju_tl { \fp_eval:n {#1} }
479 \ctex_select_size:
480 }
481 \cs_new_protected:Npn \ctex_update_ziju:
482 {
483 \ctex_update_em_unit:
484 \dim_set:Nn \l__ctex_ziju_dim { \l__ctex_ziju_tl \ccwd }
485 \dim_add:Nn \ccwd { \l__ctex_ziju_dim }
486 \dim_compare:nNnTF \ccwd > \c_zero_dim
487 {
488 \dim_set:Nn \l__ctex_tmp_dim
489 { \linewidth - \ccwd + \l__ctex_ziju_dim }
490 \int_set:Nn \l__ctex_tmp_int { \l__ctex_tmp_dim }
491 \tex_divide:D \l__ctex_tmp_int \ccwd
492 \dim_sub:Nn \l__ctex_tmp_dim { \l__ctex_tmp_int \ccwd }
493 \dim_compare:nNnF \parindent = \c_zero_dim
494 {
495 \int_compare:nNnF \l__ctex_tmp_int < 3
496 { \int_sub:Nn \l__ctex_tmp_int { 2 } }
497 }
498 \skip_set:Nn \l__ctex_ccglue_skip
499 {
500 \l__ctex_ziju_dim
501 plus \dim_eval:n { \l__ctex_tmp_dim / \l__ctex_tmp_int }
502 minus \dim_min:nn { \dim_abs:n { \l__ctex_ziju_dim } }
503 { ( \ccwd - \l__ctex_tmp_dim ) / ( \l__ctex_tmp_int + 1 ) }
504 }
505 }
506 { \skip_set:Nn \l__ctex_ccglue_skip { \l__ctex_ziju_dim } }
507 \ctex_update_ccglue:
508 \ctex_update_parindent:
509 }
510 \dim_new:N \l__ctex_ziju_dim
511 \NewDocumentCommand \CTEXindent { }
512 {
513 \ctex_deprecated_command:Nn \CTEXindent
514 { \parindent is~set~to~2\ccwd. }
515 \ctex_update_ccwd:
516 \dim_set:Nn \parindent { 2 \ccwd }
517 }
518 \NewDocumentCommand \CTEXnoindent { }
519 {
520 \ctex_deprecated_command:Nn \CTEXnoindent
521 { \parindent is~set~to~0pt. }
522 \dim_zero:N \parindent
523 }
524 \exp_args:Ne \PassOptionsToPackage
525 { encoding = \g__ctex_encoding_tl }
526 { zhnumber }
527 \RequirePackage { zhnumber }
528 \cs_new:Npn \chinese { \zhnum_counter:n }
529 \cs_new_eq:NN \@chinese \@zhnum
530 \cs_new_eq:NN \Chinese \chinese
531 \cs_new_eq:NN \CTEXcounter \use_none:n
532 \ctex_at_end_package:nn { enumitem }
533 {
534 \cs_if_free:NF \AddEnumerateCounter
535 {
536 \AddEnumerateCounter * { \zhnum } { \@zhnum } { 1 }
537 \AddEnumerateCounter * { \zhdig } { \@zhdig } { 1 }
538 \AddEnumerateCounter * { \chinese } { \@chinese } { 1 }
539 }
540 }
541 \NewDocumentCommand \CTEXnumber { m m }
542 { \protected@edef #1 { \zhnumber {#2} } }
543 \NewDocumentCommand \CTEXdigits { m m }
544 { \protected@edef #1 { \zhdigits {#2} } }
545 \cs_set_eq:NN \CTEX@todayold \today
546 \ctex_define:n
547 {
548 today .choice: ,
549 today / old .code:n =
550 { \cs_set_eq:NN \today \CTEX@todayold } ,
551 today / small .code:n =
552 {
553 \cs_set_eq:NN \today \zhtoday
554 \zhnumsetup { time = Arabic }
555 } ,
556 today / big .code:n =
557 {
558 \cs_set_eq:NN \today \zhtoday
559 \zhnumsetup { time = Chinese }
560 } ,
561 today / unknown .code:n =
562 { \msg_error:nnx { ctex } { today-undef } {#1} }
563 }
564 \msg_new:nnnn { ctex } { today-undef }
565 { Today~format~`#1'~is~undefined. }
566 { Available~today~formats~are~`old',~`small',~and~`big'. }
567 \tl_if_exist:NF \proofname
568 {
569 \tl_new:N \proofname
570 \tl_set:Nn \proofname { Proof }
571 }
572 \ctex_define:n
573 {
574 contentsname .tl_set:N = \contentsname ,
575 listfigurename .tl_set:N = \listfigurename ,
576 listtablename .tl_set:N = \listtablename ,
577 figurename .tl_set:N = \figurename ,
578 tablename .tl_set:N = \tablename ,
579 abstractname .tl_set:N = \abstractname ,
580 indexname .tl_set:N = \indexname ,
581 appendixname .tl_set:N = \appendixname ,
582 proofname .tl_set:N = \proofname ,
583 bibname .tl_set:N = \bibname
584 }
585 \seq_const_from_clist:Nn \c__ctex_section_headings_seq
586 { section , subsection , subsubsection , paragraph , subparagraph }
587 \seq_new:N \c__ctex_headings_seq
588 \seq_gset_eq:NN \c__ctex_headings_seq \c__ctex_section_headings_seq
589 \seq_gput_left:Nn \c__ctex_headings_seq { chapter }
590 \seq_gput_left:Nn \c__ctex_headings_seq { part }
591 \cs_new_protected:Npn \__ctex_initial_heading:n #1
592 {
593 \tl_new:c { CTEX@pre#1 }
594 \tl_new:c { CTEX@post#1 }
595 \tl_const:cx { CTEXthe#1 }
596 {
597 \exp_not:c { CTEX@pre#1 }
598 \exp_not:c { CTEX@the#1 }
599 \exp_not:c { CTEX@post#1 }
600 }
601 \tl_const:cx { CTEX@#1name }
602 {
603 \group_begin:
604 \exp_not:c { CTEX@#1@nameformat }
605 {
606 \exp_not:c { CTEX@pre#1 }
607 \exp_not:N \tl_if_empty:NTF
608 \exp_not:c { CTEX@#1@numberformat }
609 { \exp_not:c { CTEX@the#1 } }
610 {
611 \group_begin:
612 \exp_not:c { CTEX@#1@numberformat }
613 \exp_not:c { CTEX@the#1 }
614 \group_end:
615 }
616 \exp_not:c { CTEX@post#1 }
617 }
618 \group_end:
619 }
620 }
621 \cs_new_protected:Npn \__ctex_def_heading_keys:n #1
622 {
623 \exp_args:NNe \tl_put_right:Nn \l__ctex_tmp_tl
624 {
625 #1 .meta:nn = { ctex / #1 } { ##1 } ,
626 #1 / name .code:n =
627 { \ctex_assign_heading_name:nn {#1} { ##1 } } ,
628 #1 / number .tl_set:N = \exp_not:c { CTEX@the#1 } ,
629 #1 / beforeskip .tl_set:N = \exp_not:c { CTEX@#1@beforeskip } ,
630 #1 / afterskip .tl_set:N = \exp_not:c { CTEX@#1@afterskip} ,
631 #1 / indent .tl_set:N = \exp_not:c { CTEX@#1@indent } ,
632 #1 / numbering .bool_set:N = \exp_not:c { CTEX@#1@numbering } ,
633 #1 / numbering .initial:n = true ,
634 #1 / beforeskip .initial:n = \c_zero_skip ,
635 #1 / afterskip .initial:n = \c_zero_skip ,
636 #1 / indent .initial:n = \c_zero_dim ,
637 #1 / beforeskip .value_required:n = true ,
638 #1 / afterskip .value_required:n = true ,
639 #1 / indent .value_required:n = true ,
640 #1 / afterindent .bool_set:N = \exp_not:c { CTEX@#1@afterindent } ,
641 #1 / fixskip .bool_set:N = \exp_not:c { CTEX@#1@fixskip } ,
642 #1 / hang .bool_set:N = \exp_not:c { CTEX@#1@hang } ,
643 #1 / hang .initial:n = true ,
644 #1 / runin .bool_set:N = \exp_not:c { CTEX@#1@runin } ,
645 #1 / tocline .cs_set:Np = \exp_not:c { CTEX@#1@tocline } ##1##2 ,
646 \__ctex_plus_key_aux:nn {#1} { break } ,
647 \__ctex_plus_key_aux:nn {#1} { format } ,
648 \__ctex_plus_key_aux:nn {#1} { nameformat } ,
649 \__ctex_plus_key_aux:nn {#1} { numberformat } ,
650 \__ctex_plus_key_aux:nn {#1} { titleformat } ,
651 \__ctex_plus_key_aux:nn {#1} { aftername } ,
652 \__ctex_plus_key_aux:nn {#1} { aftertitle } ,
653 }
654 }
655 \cs_new:Npn \__ctex_plus_key_aux:nn #1#2
656 {
657 #1 / #2 .tl_set:N = \exp_not:c { CTEX@#1@#2 } ,
658 #1 / #2 + .code:n =
659 { \tl_put_right:Nn \exp_not:c { CTEX@#1@#2 } { ##1 } } ,
660 #1 / #2 ~ + .code:n =
661 { \tl_put_right:Nn \exp_not:c { CTEX@#1@#2 } { ##1 } }
662 }
663 \NewDocumentCommand \ctex_assign_heading_name:nn
664 { m > { \SplitArgument { 1 } { , } } +m }
665 { \__ctex_assign_heading_name:nnn {#1} #2 }
666 \cs_new_protected:Npn \__ctex_assign_heading_name:nnn #1#2#3
667 {
668 \tl_set:cn { CTEX@pre#1 } {#2}
669 \tl_if_novalue:nTF {#3}
670 { \tl_clear:c { CTEX@post#1 } }
671 { \tl_set:cn { CTEX@post#1 } {#3} }
672 }
673 \group_begin:
674 \tl_set:Nn \l__ctex_tmp_tl
675 {
676 part / pagestyle .tl_set:N = \CTEX@part@pagestyle ,
677 chapter / pagestyle .tl_set:N = \CTEX@chapter@pagestyle ,
678 chapter / lofskip .tl_set:N = \CTEX@chapter@lofskip ,
679 chapter / lotskip .tl_set:N = \CTEX@chapter@lotskip ,
680 chapter / lofskip .initial:n = \c_zero_skip ,
681 chapter / lotskip .initial:n = \c_zero_skip ,
682 chapter / lofskip .value_required:n = true ,
683 chapter / lotskip .value_required:n = true ,
684 }
685 \seq_map_inline:Nn \c__ctex_headings_seq
686 {
687 \__ctex_initial_heading:n {#1}
688 \__ctex_def_heading_keys:n {#1}
689 }
690 \exp_args:NNo \group_end: \ctex_define:n { \l__ctex_tmp_tl }
691 \cs_new_protected:Npn \CTEX@heading@format@initial
692 {
693 \normalfont
694 \tl_clear:N \l__ctex_autoindent_tl
695 \int_set:Nn \tex_interlinepenalty:D { 10 000 }
696 \tex_noindent:D
697 }
698 \cs_new_protected:Npn \ctex_indent_box:n #1
699 {
700 \dim_set:Nn \tex_parindent:D {#1}
701 \__ctex_insert_indent:
702 }
703 \cs_new_protected:Npn \__ctex_insert_indent:
704 {
705 \dim_compare:nNnF \tex_parindent:D = \c_zero_dim
706 { \tex_indent:D }
707 }
708 \cs_new_eq:NN \CTEX@indentbox \ctex_indent_box:n
709 \cs_new_protected:Npn \CTEX@fixtopskip
710 {
711 \CTEX@fixheadingskip
712 \dim_compare:nNnF \tex_pagegoal:D < \c_max_dim
713 { \skip_sub:Nn \l__ctex_heading_skip { \tex_topskip:D } }
714 }
715 \cs_new_protected:Npn \CTEX@fixheadingskip
716 {
717 \par
718 \dim_set:Nn \tex_prevdepth:D { -1000pt }
719 \skip_sub:Nn \l__ctex_heading_skip { \tex_parskip:D }
720 }
721 \skip_new:N \l__ctex_heading_skip
722 \cs_new_protected:Npn \CTEX@setheadingskip
723 { \skip_set:Nn \l__ctex_heading_skip }
724 \cs_new_eq:NN \CTEX@headingskip \l__ctex_heading_skip
725 \cs_new_protected:Npn \CTEX@setthispagestyle #1
726 { \exp_args:Ne \thispagestyle { \use:c { CTEX@#1@pagestyle } } }
727 \ProvideDocumentCommand \partmark { m }
728 { \markboth { } { } }
729 \cs_new_eq:NN \CTEXifname \use_ii:nn
730 \cs_new_protected:Npn \CTEX@ifnametrue
731 { \cs_set_eq:NN \CTEXifname \use_i:nn }
732 \cs_new_protected:Npn \CTEX@ifnamefalse
733 { \cs_set_eq:NN \CTEXifname \use_ii:nn }
734 \cs_new_protected:Npn \CTEX@addloflotskip #1
735 {
736 \skip_set:Nn \l__ctex_heading_skip { \use:c { CTEX@#1@lofskip } }
737 \skip_if_eq:nnF { \l__ctex_heading_skip } { \c_zero_skip }
738 {
739 \addtocontents { lof }
740 { \protect \addvspace { \skip_use:N \l__ctex_heading_skip } }
741 }
742 \skip_set:Nn \l__ctex_heading_skip { \use:c { CTEX@#1@lotskip } }
743 \skip_if_eq:nnF { \l__ctex_heading_skip } { \c_zero_skip }
744 {
745 \addtocontents { lot }
746 { \protect \addvspace { \skip_use:N \l__ctex_heading_skip } }
747 }
748 }
749 \cs_new_protected:Npn \CTEX@addtocline #1#2
750 { \addcontentsline { toc } {#1} { \use:c { CTEX@#1@tocline } {#1} {#2} } }
751 \renewcommand\part{%
752 \CTEX@part@break
753 \CTEX@setthispagestyle{part}%
754 \if@twocolumn
755 \onecolumn
756 \@tempswatrue
757 \else
758 \@tempswafalse
759 \fi
760 \CTEX@setheadingskip \CTEX@part@beforeskip
761 \ifodd \CTEX@part@fixskip \CTEX@fixtopskip \fi
762 \vspace*{\CTEX@headingskip}%
763 \secdef\@part\@spart}
764 \def\@part[#1]#2{%
765 \ifnum \c@secnumdepth >-2\relax
766 \ifodd \CTEX@part@numbering
767 \CTEX@ifnametrue
768 \refstepcounter{part}%
769 \else
770 \CTEX@ifnamefalse
771 \CTEX@makeanchor{part*}%
772 \fi
773 \else
774 \CTEX@ifnamefalse
775 \CTEX@makeanchor{part*}%
776 \fi
777 \CTEX@gettitle{#1}%
778 \CTEX@addtocline{part}{#1}%
779 \partmark{#1}%
780 \begingroup
781 \CTEX@heading@format@initial
782 \CTEX@part@format{%
783 \CTEX@headinghang{part}%
784 {\CTEXifname{\CTEX@partname\CTEX@part@aftername}{}}%
785 \CTEX@part@titleformat{#2}%
786 \CTEX@part@aftertitle}\par
787 \endgroup
788 \@endpart}
789 \def\@spart#1{%
790 \CTEX@ifnamefalse
791 \CTEX@makeanchor@spart{part*}%
792 \CTEX@gettitle{#1}%
793 \begingroup
794 \CTEX@heading@format@initial
795 \CTEX@part@format{%
796 \CTEX@headinghang{part}{}%
797 \CTEX@part@titleformat{#1}%
798 \CTEX@part@aftertitle}\par
799 \endgroup
800 \@endpart}
801 \def\@endpart{%
802 \CTEX@setheadingskip \CTEX@part@afterskip
803 \ifodd \CTEX@part@fixskip \CTEX@fixheadingskip \fi
804 \vskip \CTEX@headingskip
805 \newpage
806 \if@twoside
807 \if@openright
808 \null
809 \thispagestyle{empty}%
810 \newpage
811 \fi
812 \fi
813 \if@tempswa
814 \twocolumn
815 \fi}
816 \renewcommand\chapter{%
817 \CTEX@chapter@break
818 \CTEX@setthispagestyle{chapter}%
819 \global\@topnum\z@
820 \ifodd \CTEX@chapter@afterindent
821 \@afterindenttrue
822 \else
823 \@afterindentfalse
824 \fi
825 \secdef\@chapter\@schapter}
826 \def\@chapter[#1]#2{%
827 \ifnum \c@secnumdepth >\m@ne
828 \if@mainmatter
829 \ifodd \CTEX@chapter@numbering
830 \CTEX@ifnametrue
831 \refstepcounter{chapter}%
832 \typeout{\CTEXthechapter}%
833 \else
834 \CTEX@ifnamefalse
835 \CTEX@makeanchor{\Hy@chapapp*}%
836 \fi
837 \else
838 \CTEX@ifnamefalse
839 \CTEX@makeanchor@chapter{\Hy@chapapp*}%
840 \fi
841 \else
842 \CTEX@ifnamefalse
843 \CTEX@makeanchor@chapter{\Hy@chapapp*}%
844 \fi
845 \CTEX@gettitle{#1}%
846 \CTEX@addtocline{chapter}{#1}%
847 \chaptermark{#1}%
848 \CTEX@addloflotskip{chapter}%
849 \if@twocolumn
850 \@topnewpage[\@makechapterhead{#2}]%
851 \else
852 \@makechapterhead{#2}%
853 \@afterheading
854 \fi}
855 \def\@schapter#1{%
856 \CTEX@ifnamefalse
857 \CTEX@makeanchor@schapter{\Hy@chapapp*}%
858 \CTEX@gettitle{#1}%
859 \if@twocolumn
860 \@topnewpage[\@makeschapterhead{#1}]%
861 \else
862 \@makeschapterhead{#1}%
863 \@afterheading
864 \fi}
865 \def\@makechapterhead#1{%
866 \CTEX@setheadingskip \CTEX@chapter@beforeskip
867 \ifodd \CTEX@chapter@fixskip \CTEX@fixtopskip \fi
868 \vspace*{\CTEX@headingskip}%
869 \begingroup
870 \CTEX@heading@format@initial
871 \CTEX@chapter@format{%
872 \CTEX@headinghang{chapter}%
873 {\CTEXifname{\CTEX@chaptername\CTEX@chapter@aftername}{}}%
874 \CTEX@chapter@titleformat{#1}%
875 \CTEX@chapter@aftertitle}\par
876 \endgroup
877 \nobreak
878 \CTEX@setheadingskip \CTEX@chapter@afterskip
879 \ifodd \CTEX@chapter@fixskip \CTEX@fixheadingskip \fi
880 \vskip \CTEX@headingskip}
881 \def\@makeschapterhead#1{%
882 \CTEX@setheadingskip \CTEX@chapter@beforeskip
883 \ifodd \CTEX@chapter@fixskip \CTEX@fixtopskip \fi
884 \vspace*{\CTEX@headingskip}%
885 \begingroup
886 \CTEX@heading@format@initial
887 \CTEX@chapter@format{%
888 \CTEX@headinghang{chapter}{}%
889 \CTEX@chapter@titleformat{#1}%
890 \CTEX@chapter@aftertitle}\par
891 \endgroup
892 \nobreak
893 \CTEX@setheadingskip \CTEX@chapter@afterskip
894 \ifodd \CTEX@chapter@fixskip \CTEX@fixheadingskip \fi
895 \vskip \CTEX@headingskip}
896 \def\@startsection#1#2#3#4#5#6{%
897 \if@noskipsec \leavevmode \fi
898 \par
899 \CTEX@update@sectionformat@n{#1}%
900 \ifodd \CTEX@afterindent
901 \@afterindenttrue
902 \else
903 \@afterindentfalse
904 \fi
905 \if@nobreak
906 \everypar{}%
907 \else
908 \csname CTEX@#1@break\endcsname
909 \CTEX@setheadingskip{#4}%
910 \ifodd \CTEX@fixskip \CTEX@fixheadingskip \fi
911 \addvspace \CTEX@headingskip
912 \fi
913 \@ifstar
914 {\CTEX@makeanchor@ssect{#1*}\@ssect{#3}{#4}{#5}{#6}}%
915 {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
916 \def\@seccntformat#1{%
917 \csname CTEX@#1name\endcsname
918 \csname CTEX@#1@aftername\endcsname}
919 \def\@sect#1#2#3#4#5#6[#7]#8{%
920 \ifnum #2>\c@secnumdepth
921 \CTEX@ifnamefalse
922 \CTEX@makeanchor@sect{#1*}%
923 \let\@svsec\@empty
924 \else
925 \ifodd \csname CTEX@#1@numbering\endcsname
926 \CTEX@ifnametrue
927 \refstepcounter{#1}%
928 \protected@edef\@svsec{\@seccntformat{#1}\relax}%
929 \else
930 \CTEX@ifnamefalse
931 \CTEX@makeanchor{#1*}%
932 \let\@svsec\@empty
933 \fi
934 \fi
935 \CTEX@gettitle{#7}%
936 \unless \ifodd \CTEX@runin
937 \begingroup
938 \CTEX@heading@format@initial
939 #6{%
940 \CTEX@sectionhang{#3}{\@svsec}%
941 \csname CTEX@#1@titleformat\endcsname{#8}%
942 \csname CTEX@#1@aftertitle\endcsname}\par
943 \endgroup
944 \csname #1mark\endcsname{#7}%
945 \CTEX@addtocline{#1}{#7}%
946 \else
947 \def\@svsechd{%
948 #6{%
949 {\CTEX@indentbox{#3}}\@svsec
950 \csname CTEX@#1@titleformat\endcsname{#8}%
951 \csname CTEX@#1@aftertitle\endcsname}%
952 \csname #1mark\endcsname{#7}%
953 \CTEX@addtocline{#1}{#7}}%
954 \fi
955 \@xsect{#5}}
956 \def\@ssect#1#2#3#4#5{%
957 \CTEX@ifnamefalse
958 \CTEX@gettitle{#5}%
959 \unless \ifodd \CTEX@runin
960 \begingroup
961 \CTEX@heading@format@initial
962 #4{%
963 \CTEX@sectionhang{#1}{}%
964 \CTEX@titleformat@n{#5}%
965 \CTEX@aftertitle}\par
966 \endgroup
967 \else
968 \def\@svsechd{#4{{\CTEX@indentbox{#1}}%
969 \CTEX@titleformat@n{#5}\CTEX@aftertitle}}%
970 \fi
971 \@xsect{#3}}
972 \def\@xsect#1{%
973 \unless \ifodd \CTEX@runin
974 \par \nobreak
975 \CTEX@setheadingskip{#1}%
976 \ifodd \CTEX@fixskip \CTEX@fixheadingskip \fi
977 \vskip \CTEX@headingskip
978 \@afterheading
979 \else
980 \@nobreakfalse
981 \global\@noskipsectrue
982 \everypar{%
983 \if@noskipsec
984 \global\@noskipsecfalse
985 {\setbox\z@\lastbox}%
986 \clubpenalty\@M
987 \begingroup \@svsechd \endgroup
988 \unskip
989 \CTEX@heading@glue{#1}%
990 \else
991 \clubpenalty \@clubpenalty
992 \everypar{}%
993 \fi}%
994 \fi
995 \ignorespaces}
996 \cs_new_protected:Npn \CTEX@headinghang #1
997 {
998 \ctex_heading_hang:cnn
999 { CTEX@#1@hang }
1000 { \use:c { CTEX@#1@indent } }
1001 }
1002 \cs_new_protected:Npn \CTEX@sectionhang
1003 { \ctex_heading_hang:Nnn \CTEX@hang }
1004 \cs_new_protected:Npn \ctex_heading_hang:Nnn #1#2#3
1005 {
1006 \dim_set:Nn \tex_parindent:D {#2}
1007 \bool_if:NTF #1
1008 { \ctex_hang_from:n }
1009 { \use:n }
1010 { \__ctex_insert_indent: #3 }
1011 }
1012 \cs_new_protected:Npn \ctex_hang_from:n #1
1013 {
1014 \tex_noindent:D
1015 \hbox_set:Nn \l__ctex_tmp_box {#1}
1016 \tex_hangindent:D = \box_wd:N \l__ctex_tmp_box
1017 \box_use_drop:N \l__ctex_tmp_box
1018 }
1019 \cs_generate_variant:Nn \ctex_heading_hang:Nnn { c }
1020 \cs_new_protected:Npn \ctex_heading_glue:n #1
1021 {
1022 \group_begin:
1023 \skip_set:Nn \l__ctex_heading_skip {#1}
1024 \dim_compare:nNnF \l__ctex_heading_skip = \c_zero_dim
1025 { \skip_horizontal:N \l__ctex_heading_skip }
1026 \group_end:
1027 }
1028 \cs_new_eq:NN \CTEX@heading@glue \ctex_heading_glue:n
1029 \cs_new_protected:Npn \CTEX@update@sectionformat@n #1
1030 {
1031 \cs_set_eq:Nc \CTEX@titleformat@n { CTEX@#1@titleformat }
1032 \cs_set_eq:Nc \CTEX@aftertitle { CTEX@#1@aftertitle }
1033 \cs_set_eq:Nc \CTEX@afterindent { CTEX@#1@afterindent }
1034 \cs_set_eq:Nc \CTEX@fixskip { CTEX@#1@fixskip }
1035 \cs_set_eq:Nc \CTEX@hang { CTEX@#1@hang }
1036 \cs_set_eq:Nc \CTEX@runin { CTEX@#1@runin }
1037 }
1038 \cs_new_eq:NN \CTEX@titleformat@n \use:n
1039 \cs_new_eq:NN \CTEX@aftertitle \prg_do_nothing:
1040 \cs_new_eq:NN \CTEX@afterindent \c_true_bool
1041 \cs_new_eq:NN \CTEX@fixskip \c_false_bool
1042 \cs_new_eq:NN \CTEX@hang \c_true_bool
1043 \cs_new_eq:NN \CTEX@runin \c_false_bool
1044 \cs_new:Npn \CTEX@part@tocline #1#2
1045 {
1046 \CTEXifname
1047 { \CTEXthepart \hspace { 1em } }
1048 { }
1049 #2
1050 }
1051 \cs_new:Npn \CTEX@chapter@tocline #1#2
1052 {
1053 \CTEXifname
1054 { \protect \numberline { \CTEXthechapter \hspace { .3em } } }
1055 { }
1056 #2
1057 }
1058 \cs_new:Npn \CTEXnumberline #1
1059 {
1060 \CTEXifname
1061 { \protect \numberline { \use:c { CTEXthe #1 } } }
1062 { }
1063 }
1064 \int_zero:N \l__ctex_tmp_int
1065 \seq_map_inline:Nn \c__ctex_section_headings_seq
1066 {
1067 \int_incr:N \l__ctex_tmp_int
1068 \cs_gset_protected:cpx {#1}
1069 {
1070 \exp_not:N \@startsection {#1}
1071 { \int_use:N \l__ctex_tmp_int }
1072 { \exp_not:c { CTEX@#1@indent } }
1073 { \exp_not:c { CTEX@#1@beforeskip } }
1074 { \exp_not:c { CTEX@#1@afterskip } }
1075 { \exp_not:N \normalfont \exp_not:c { CTEX@#1@format } }
1076 }
1077 \cs_new:cpn { CTEX@#1@tocline } ##1##2
1078 { \CTEXnumberline { ##1 } ##2 }
1079 }
1080 \ctex_define:n
1081 {
1082 appendix .meta:nn = { ctex / appendix } {#1} ,
1083 appendix / name .code:n =
1084 { \ctex_assign_heading_name:nn { appendix } {#1} } ,
1085 appendix / number .tl_set:N = \CTEX@appendix@number ,
1086 appendix / numbering .bool_set:N = \CTEX@appendix@numbering ,
1087 appendix / numbering .initial:n = true
1088 }
1089 \tl_new:N \CTEX@preappendix
1090 \tl_new:N \CTEX@postappendix
1091 \cs_new_eq:NN \CTEX@save@appendix \appendix
1092 \cs_gset_protected:Npn \appendix
1093 {
1094 \CTEX@save@appendix
1095 \gdef \CTEX@prechapter { \CTEX@preappendix }
1096 \gdef \CTEX@thechapter { \CTEX@appendix@number }
1097 \gdef \CTEX@postchapter { \CTEX@postappendix }
1098 \gdef \CTEX@chapter@numbering { \CTEX@appendix@numbering }
1099 }
1100 \cs_new_protected:Npn \CTEX@makeanchor #1
1101 { }
1102 \seq_const_from_clist:Nn \c__ctex_headings_cs_seq
1103 { part , spart , chapter , schapter , sect , ssect }
1104 \seq_map_inline:Nn \c__ctex_headings_cs_seq
1105 {
1106 \cs_new_eq:cc { CTEX@ #1 } { @ #1 }
1107 \cs_new_eq:cN { CTEX@makeanchor@ #1 } \CTEX@makeanchor
1108 }
1109 \cs_new_protected:Npn \CTEX@hyperheadinghook
1110 {
1111 \group_begin:
1112 \legacy_if:nTF { Hy@implicit }
1113 {
1114 \cs_set_eq:NN \H@old@chapter \Hy@org@chapter
1115 \seq_map_inline:Nn \c__ctex_headings_cs_seq
1116 {
1117 \cs_if_eq:ccT { H@old@ ##1 } { CTEX@ ##1 }
1118 {
1119 \cs_gset_eq:cc { @ ##1 } { CTEX@ ##1 }
1120 \cs_gset_eq:cN { CTEX@makeanchor@ ##1 } \CTEX@makeanchor
1121 }
1122 }
1123 }
1124 {
1125 \seq_map_inline:Nn \c__ctex_headings_cs_seq
1126 { \cs_gset_eq:cN { CTEX@makeanchor@ ##1 } \CTEX@makeanchor }
1127 }
1128 \group_end:
1129 }
1130 \ctex_at_end_package:nn { hyperref }
1131 {
1132 \cs_gset_protected:Npn \CTEX@makeanchor #1
1133 {
1134 \Hy@MakeCurrentHrefAuto {#1}
1135 \Hy@raisedlink
1136 {
1137 \hyper@anchorstart { \@currentHref }
1138 \hyper@anchorend
1139 }
1140 }
1141 \CTEX@hyperheadinghook
1142 }
1143 \cs_new_protected:Npn \CTEX@gettitle #1
1144 { }
1145 \ctex_at_end_package:nn { nameref }
1146 {
1147 \cs_gset_protected:Npn \CTEX@gettitle { \NR@gettitle }
1148 \seq_map_inline:Nn \c__ctex_headings_cs_seq
1149 {
1150 \cs_if_eq:ccT { NR@ #1 } { CTEX@ #1 }
1151 { \cs_gset_eq:cc { @ #1 } { CTEX@ #1 } }
1152 }
1153 }
1154 \cs_new_protected:Npn \ctex_titlesec_hook:
1155 {
1156 \@ifpackagewith { titlesec } { explicit }
1157 {
1158 \cs_set_eq:NN \__ctex_titlesec_format:Nn
1159 \__ctex_titlesec_format_explicit:Nn
1160 }
1161 { }
1162 \clist_map_inline:nn
1163 { indentafter , noindentafter , indentfirst , nonindentfirst }
1164 {
1165 \@ifpackagewith { titlesec } { ##1 }
1166 {
1167 \clist_map_break:n
1168 { \cs_set_eq:NN \__ctex_titlesec_hook:n \__ctex_titlesec_format:n }
1169 }
1170 { }
1171 }
1172 \seq_map_function:NN \c__ctex_section_headings_seq \__ctex_titlesec_hook:n
1173 }
1174 \cs_new_protected:Npn \__ctex_titlesec_hook:n #1
1175 {
1176 \__ctex_titlesec_format:n {#1}
1177 \exp_args:Nc \__ctex_titlesec_spacing:Nn { ttls@#1 } {#1}
1178 }
1179 \cs_new_protected:Npn \__ctex_titlesec_format:n #1
1180 {
1181 \cs_if_free:cF { ttlf@#1 }
1182 { \exp_args:Nc \__ctex_titlesec_format:Nn { ttlf@#1 } {#1} }
1183 }
1184 \cs_new_protected:Npn \__ctex_titlesec_format:Nn #1#2
1185 {
1186 \tl_set:Nx #1
1187 {
1188 \bool_if:cTF { CTEX@#2@runin }
1189 { \exp_not:N \ttlh@runin }
1190 { \exp_not:N \ttlh@hang }
1191 \tl_tail:N #1
1192 }
1193 }
1194 \cs_new_protected:Npn \__ctex_titlesec_format_explicit:Nn #1#2
1195 {
1196 \cs_set_nopar:Npx #1 ##1
1197 {
1198 \bool_if:cTF { CTEX@#2@runin }
1199 { \exp_not:N \ttlh@runin }
1200 { \exp_not:N \ttlh@hang }
1201 \exp_args:No \tl_tail:n { #1 { } }
1202 }
1203 }
1204 \cs_new_protected:Npn \__ctex_titlesec_spacing:Nn #1#2
1205 { \tl_set:Nx #1 { \exp_after:wN \__ctex_titlesec_spacing:nnnnnn #1 {#2} } }
1206 \cs_new:Npn \__ctex_titlesec_spacing:nnnnnn #1#2#3#4#5#6
1207 {
1208 \exp_not:n { {#1} {#2} {#3} {#4} }
1209 { \bool_if:cTF { CTEX@#6@afterindent } { \@ne } { \z@ } }
1210 }
1211 \@ifpackageloaded { titlesec }
1212 { }
1213 {
1214 \ctex_at_end_package:nn { titlesec }
1215 {
1216 \@ifpackagewith { titlesec } { loadonly }
1217 { }
1218 { \ctex_titlesec_hook: }
1219 }
1220 }
1221 \ctex_at_end_package:nn { titlesec }
1222 {
1223 \tl_set:Nn \ttl@chapterout { \typeout { \CTEXthechapter } }
1224 \cs_if_free:NF \ttl@tocpart
1225 {
1226 \cs_set_protected:Npn \ttl@tocpart
1227 { \tl_set:Nn \ttl@a { \CTEXthepart \hspace { 1em } } }
1228 }
1229 \seq_map_inline:Nn \c__ctex_headings_seq
1230 {
1231 \cs_if_exist:cF { ttl@toc #1 }
1232 {
1233 \cs_new_protected:cpx { ttl@toc #1 }
1234 {
1235 \tl_set:Nn \exp_not:N \ttl@a
1236 {
1237 \exp_not:N \protect
1238 \exp_not:N \numberline { \exp_not:c { CTEXthe #1 } }
1239 }
1240 }
1241 }
1242 }
1243 }
1244 \ctex_at_end_package:nn { titlesec }
1245 {
1246 \ctex_patch_cmd:Nnn \ttl@labelling
1247 { \let \ifttl@toclabel \ifttl@label }
1248 {
1249 \let \ifttl@toclabel \ifttl@label
1250 \CTEX@updatettlifname
1251 }
1252 \cs_new_protected:Npn \CTEX@updatettlifname
1253 { \legacy_if:nTF { ttl@label } { \CTEX@ifnametrue } { \CTEX@ifnamefalse } }
1254 }
1255 \group_begin:
1256 \char_set_catcode_other:N \#
1257 \cs_new_protected:Npn \ctex_titleps_hook:
1258 {
1259 \ctex_patch_cmd:Nnn \ttl@settopmark
1260 { \protect \@namedef { the#1 } { \@nameuse { the#1 } } }
1261 {
1262 \protect \@namedef { the#1 } { \@nameuse { the#1 } }
1263 \CTEX@titlepslabel@set {#1}
1264 }
1265 \ctex_patch_cmd:Nnn \ttl@setsubmark
1266 { \protect \@namedef { the#1 } { } }
1267 {
1268 \protect \@namedef { the#1 } { }
1269 \CTEX@titlepslabel@clear {#1}
1270 }
1271 \ctex_patch_cmd:Nnn \ttl@setsubmark
1272 { \protect \@namedef { the#2 } { \@nameuse { the#2 } } }
1273 {
1274 \protect \@namedef { the#2 } { \@nameuse { the#2 } }
1275 \CTEX@titlepslabel@set {#2}
1276 }
1277 }
1278 \group_end:
1279 \cs_new:Npn \CTEX@titlepslabel@set #1
1280 {
1281 \cs_if_free:cF { CTEXthe#1 }
1282 { \protect \@namedef { CTEXthe#1 } { \@nameuse { CTEXthe#1 } } }
1283 }
1284 \cs_new:Npn \CTEX@titlepslabel@clear #1
1285 {
1286 \cs_if_free:cF { CTEXthe#1 }
1287 { \protect \@namedef { CTEXthe#1 } { } }
1288 }
1289 \ctex_at_end_package:nn { titlesec }
1290 { \cs_if_free:NF \ttl@settopmark { \ctex_titleps_hook: } }
1291 \ctex_at_end_package:nn { titleps } { \ctex_titleps_hook: }
1292 \ctex_at_end_package:nn { titleps }
1293 {
1294 \cs_set_protected:Npn \ttl@setifthe #1
1295 {
1296 \exp_args:Nco \cs_set:Npn { ifthe #1 }
1297 {
1298 \CTEXifname
1299 { \protect \@firstoftwo }
1300 { \protect \@secondoftwo }
1301 }
1302 }
1303 \seq_map_function:NN \c__ctex_headings_seq \ttl@setifthe
1304 }
1305 \cs_new_protected:Npn \CTEX@toc@width@n #1
1306 {
1307 \hbox_set:Nn \l__ctex_tmp_box {#1}
1308 \dim_set:Nn \@tempdima
1309 {
1310 \dim_max:nn { \@tempdima }
1311 { \box_wd:N \l__ctex_tmp_box + \f@size \p@ / 2 }
1312 }
1313 }
1314 \group_begin:
1315 \char_set_catcode_other:N \#
1316 \use:n
1317 {
1318 \group_end:
1319 \ctex_preto_cmd:NnnTF \numberline { \ExplSyntaxOff }
1320 { \CTEX@toc@width@n {#1} }
1321 { }
1322 { \ctex_patch_failure:N \numberline }
1323 \cs_new_protected:Npn \__ctex_patch_toc_width:n \c_parameter_token 1
1324 {
1325 \@ifpackageloaded { \c_parameter_token 1 }
1326 { }
1327 {
1328 \ctex_at_end_package:nn { \c_parameter_token 1 }
1329 {
1330 \ctex_preto_cmd:NnnTF \numberline
1331 { \char_set_catcode_letter:n { 64 } }
1332 { \CTEX@toc@width@n {#1} }
1333 { }
1334 { \ctex_patch_failure:N \numberline }
1335 }
1336 }
1337 }
1338 }
1339 \__ctex_patch_toc_width:n { tocloft }
1340 \__ctex_patch_toc_width:n { titletoc }
1341 \ctex_patch_cmd:Nnn \ps@headings
1342 {
1343 \ifnum \c@secnumdepth > \m@ne \if@mainmatter
1344 \@chapapp \ \thechapter . ~ \ %
1345 \fi \fi
1346 }
1347 { \CTEXifname { \CTEXthechapter \quad } { } }
1348 \legacy_if:nT { @twoside }
1349 {
1350 \ctex_patch_cmd:Nnn \ps@headings
1351 { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
1352 { \CTEXifname { \CTEXthesection \quad } { } }
1353 }
1354 \ctex_at_end_package:nn { fancyhdr }
1355 {
1356 \ctex_patch_cmd:Nnn \f@nch@initialise
1357 { \ifnum \c@secnumdepth > \z@ \thesection \hskip 1em \relax \fi }
1358 { \CTEXifname { \CTEXthesection \quad } { } }
1359 \ctex_patch_cmd:Nnn \f@nch@initialise
1360 { \ifnum \c@secnumdepth > \@ne \thesubsection \hskip 1em \relax \fi }
1361 { \CTEXifname { \CTEXthesubsection \quad } { } }
1362 \ctex_patch_cmd:Nnn \f@nch@initialise
1363 { \ifnum \c@secnumdepth > \m@ne \@chapapp\ \thechapter . ~ \ \fi }
1364 { \CTEXifname { \CTEXthechapter \quad } { } }
1365 \ctex_patch_cmd:Nnn \f@nch@initialise
1366 { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
1367 { \CTEXifname { \CTEXthesection \quad } { } }
1368 \f@nch@initialise
1369 \@ifpackagewith { fancyhdr } { headings }
1370 {
1371 \ctex_patch_cmd:Nnn \ps@headings
1372 {
1373 \ifnum \c@secnumdepth > \m@ne \if@mainmatter
1374 \@chapapp \ \thechapter . ~ \ %
1375 \fi \fi
1376 }
1377 { \CTEXifname { \CTEXthechapter \quad } { } }
1378 \legacy_if:nT { @twoside }
1379 {
1380 \ctex_patch_cmd:Nnn \ps@headings
1381 { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
1382 { \CTEXifname { \CTEXthesection \quad } { } }
1383 }
1384 }
1385 { }
1386 }
1387 \ctex_define:n
1388 {
1389 secnumdepth .code:n = \ctex_heading_depth:ne { secnumdepth } {#1} ,
1390 secnumdepth .value_required:n = true ,
1391 tocdepth .code:n = \ctex_heading_depth:ne { tocdepth } {#1} ,
1392 tocdepth .value_required:n = true
1393 }
1394 \cs_new_protected:Npn \ctex_heading_depth:nn #1#2
1395 {
1396 \prop_get:NnNTF \c__ctex_heading_level_prop {#2} \l__ctex_tmp_tl
1397 { \setcounter {#1} { \l__ctex_tmp_tl } }
1398 { \setcounter {#1} { \int_eval:n {#2} } }
1399 }
1400 \cs_generate_variant:Nn \ctex_heading_depth:nn { ne }
1401 \prop_const_from_keyval:Nn \c__ctex_heading_level_prop
1402 {
1403 part = -1 ,
1404 chapter = 0 ,
1405 section = 1 ,
1406 subsection = 2 ,
1407 subsubsection = 3 ,
1408 paragraph = 4 ,
1409 subparagraph = 5
1410 }
1411 \cs_new_protected:Npn \CTEX@setcurrentlabel@n #1
1412 {
1413 \protected@edef \@currentlabel
1414 {
1415 \cs_if_exist:cTF { CTEX@the#1 }
1416 { \exp_args:cc { p@#1 } { CTEX@the#1 } }
1417 { \exp_not:o { \@currentlabel } }
1418 }
1419 }
1420 \cs_new_protected:Npn \ctex_varioref_hook:
1421 {
1422 \seq_map_inline:Nn \c__ctex_headings_seq
1423 { \ctex_fix_varioref_label:n { ##1 } }
1424 \ctex_at_end_package:nn { cleveref } { \ctex_cleveref_hook: }
1425 }
1426 \cs_new_protected:Npn \ctex_fix_varioref_label:n #1
1427 {
1428 \tl_if_empty:cT { p@#1 }
1429 { \exp_args:Nnx \labelformat {#1} { \exp_not:c { CTEX@the#1 } } }
1430 }
1431 \cs_new_protected:Npn \ctex_cleveref_hook:
1432 {
1433 \@ifpackageloaded { hyperref }
1434 {
1435 \@ifpackagewith { hyperref } { implicit = false }
1436 { }
1437 { \__ctex_cleveref_hook_aux:N \H@refstepcounter }
1438 }
1439 {
1440 \__ctex_cleveref_hook_aux:N \refstepcounter@noarg
1441 \__ctex_cleveref_hook_aux:N \refstepcounter@optarg
1442 }
1443 \__ctex_cleveref_hook_aux:N \appendix
1444 }
1445 \cs_new_protected:Npn \__ctex_cleveref_hook_aux:N #1
1446 {
1447 \ctex_patch_cmd_all:NnnnTF #1
1448 {
1449 \ExplSyntaxOff
1450 \char_set_catcode_letter:n { 64 }
1451 }
1452 { \endcsname \csname the }
1453 { \expandafter \endcsname \csname the }
1454 { }
1455 { \ctex_patch_failure:N #1 }
1456 }
1457 \cs_if_exist:NTF \labelformat
1458 { \ctex_varioref_hook: }
1459 {
1460 \cs_new_eq:NN \CTEX@save@refstepcounter \refstepcounter
1461 \RenewDocumentCommand \refstepcounter { m }
1462 {
1463 \CTEX@save@refstepcounter {#1}
1464 \CTEX@setcurrentlabel@n {#1}
1465 }
1466 \ctex_at_end_package:nn { varioref } { \ctex_varioref_hook: }
1467 }
1468 \ctex_scheme_input:o { \l__ctex_scheme_tl }
1469 \NewDocumentCommand \zihao { m }
1470 { \exp_args:Nx \ctex_zihao:n {#1} \tex_ignorespaces:D }
1471 \cs_new_protected:Npn \ctex_zihao:n #1
1472 {
1473 \prop_get:NnNTF \c__ctex_font_size_prop {#1} \l__ctex_font_size_tl
1474 { \exp_after:wN \fontsize \l__ctex_font_size_tl \selectfont }
1475 { \msg_error:nnn { ctex } { fontsize } {#1} }
1476 }
1477 \msg_new:nnnn { ctex } { fontsize }
1478 { Undefined~Chinese~font~size~`#1'~in~command~\token_to_str:N \zihao.}
1479 {
1480 The~old~font~size~is~used~if~you~continue.\\
1481 The~available~font~sizes~are~listed~as~follow.\\
1482 \seq_use:Nnnn \c__ctex_font_size_seq { ~and~ } { ,~ } { ,~and~ }.
1483 }
1484 \prop_new:N \c__ctex_font_size_prop
1485 \seq_new:N \c__ctex_font_size_seq
1486 \cs_new_protected:Npn \__ctex_save_font_size:nn #1#2
1487 {
1488 \use:e
1489 {
1490 \prop_gput:Nnn \exp_not:N \c__ctex_font_size_prop {#1}
1491 {
1492 { \dim_to_decimal:n {#2} }
1493 { \dim_to_decimal:n { (#2) * 6 / 5 } }
1494 }
1495 }
1496 \seq_gput_right:Nn \c__ctex_font_size_seq {#1}
1497 }
1498 \clist_map_inline:nn
1499 {
1500 { 8 } { 5 bp } ,
1501 { 7 } { 5.5 bp } ,
1502 { -6 } { 6.5 bp } ,
1503 { 6 } { 7.5 bp } ,
1504 { -5 } { 9 bp } ,
1505 { 5 } { 10.5 bp } ,
1506 { -4 } { 12 bp } ,
1507 { 4 } { 14 bp } ,
1508 { -3 } { 15 bp } ,
1509 { 3 } { 16 bp } ,
1510 { -2 } { 18 bp } ,
1511 { 2 } { 22 bp } ,
1512 { -1 } { 24 bp } ,
1513 { 1 } { 26 bp } ,
1514 { -0 } { 36 bp } ,
1515 { 0 } { 42 bp }
1516 }
1517 { \__ctex_save_font_size:nn #1 }
1518 \cs_new_protected:Npn \ctex_declare_math_sizes:nnnn #1#2#3#4
1519 {
1520 \__ctex_get_font_sizes:Nn \l__ctex_font_size_tl { {#1} {#2} {#3} {#4} }
1521 \exp_after:wN \DeclareMathSizes \l__ctex_font_size_tl
1522 }
1523 \cs_new_protected:Npn \__ctex_get_font_sizes:Nn #1#2
1524 {
1525 \tl_clear:N #1
1526 \tl_map_inline:nn {#2}
1527 {
1528 \prop_get:NnNTF \c__ctex_font_size_prop {##1} \l__ctex_tmp_tl
1529 { \tl_put_right:Nx #1 { { \tl_head:N \l__ctex_tmp_tl } } }
1530 { \tl_put_right:Nx #1 { { \dim_to_decimal:n { ##1 } } } }
1531 }
1532 }
1533 \clist_map_inline:nn
1534 {
1535 { 8 }{ 8 }{ 5pt }{ 5pt } ,
1536 { 7 }{ 7 }{ 5pt }{ 5pt } ,
1537 { -6 }{ -6 }{ 5pt }{ 5pt } ,
1538 { 6 }{ 6 }{ 5pt }{ 5pt } ,
1539 { -5 }{ -5 }{ 6pt }{ 5pt } ,
1540 { 5 }{ 5 }{ 7pt }{ 5pt } ,
1541 { -4 }{ -4 }{ 8pt }{ 6pt } ,
1542 { 4 }{ 4 }{ 5 }{ 6 } ,
1543 { -3 }{ -3 }{ -4 }{ -5 } ,
1544 { 3 }{ 3 }{ 4 }{ 5 } ,
1545 { -2 }{ -2 }{ -3 }{ -4 } ,
1546 { 2 }{ 2 }{ 3 }{ 4 } ,
1547 { -1 }{ -1 }{ -2 }{ -3 } ,
1548 { 1 }{ 1 }{ 2 }{ 3 } ,
1549 { -0 }{ -0 }{ -1 }{ -2 } ,
1550 { 0 }{ 0 }{ 1 }{ 2 }
1551 }
1552 { \ctex_declare_math_sizes:nnnn #1 }
1553 \cs_new_protected:Npn \ctex_set_font_size:Nnn #1#2#3
1554 {
1555 \prop_get:NnNTF \c__ctex_font_size_prop {#2} \l__ctex_font_size_tl
1556 { \exp_after:wN \__ctex_set_font_size:nnNn \l__ctex_font_size_tl #1 {#3} }
1557 { \msg_error:nnn { ctex } { fontsize } {#2} }
1558 }
1559 \cs_new_protected:Npn \__ctex_set_font_size:nnNn #1#2#3#4
1560 { \cs_set_protected:Npn #3 { \@setfontsize #3 {#1} {#2} #4 } }
1561 \int_case:nn { \g__ctex_font_size_int }
1562 {
1563 { 0 } { \file_input:n { ctex-c5size.clo } }
1564 { 1 } { \file_input:n { ctex-cs4size.clo } }
1565 }
1566 \fp_if_nan:nF { \l__ctex_line_spread_fp }
1567 {
1568 \exp_args:Nx \linespread { \fp_use:N \l__ctex_line_spread_fp }
1569 \group_begin: \footnotesize \exp_args:NNNo \group_end:
1570 \dim_set:Nn \footnotesep { \dim_use:N \box_ht:N \strutbox }
1571 }
1572 \normalsize
1573 \NewDocumentCommand \CTeX { }
1574 { C \TeX }
1575 \ctex_at_end_package:nn { hyperref }
1576 { \pdfstringdefDisableCommands { \tl_set:Nn \CTeX { CTeX } } }
1577 \ctex_define:n
1578 {
1579 captiondelimiter .code:n =
1580 {
1581 \ctex_deprecated_option:n
1582 { You~can~load~the~package~`caption'~to~get~its~functionality. }
1583 }
1584 }
1585 \cs_new_protected:Npn \ctex_fontset_error:n #1
1586 { \msg_critical:nnn { ctex } { fontset-unavailable } {#1} }
1587 \msg_new:nnn { ctex } { fontset-unavailable }
1588 { CTeX~fontset~`#1'~is~unavailable~in~current~mode. }
1589 \cs_new:Npx \ctex_fontset_case:nnn #1#2#3
1590 {
1591 \sys_if_engine_pdftex:TF
1592 {#1}
1593 { \sys_if_engine_uptex:TF {#2} {#3} }
1594 }
1595 \cs_new:Npx \ctex_fontset_case:nnnn #1#2#3#4
1596 {
1597 \sys_if_engine_pdftex:TF
1598 { \sys_if_output_pdf:TF {#1} {#2} }
1599 { \sys_if_engine_uptex:TF {#3} {#4} }
1600 }
1601 \cs_new_protected:Npn \ctex_detect_platform:
1602 {
1603 \sys_if_platform_windows:TF
1604 { \tl_gset:Nn \g__ctex_fontset_tl { windows } }
1605 {
1606 \ctex_if_platform_macos:TF
1607 { \tl_gset:Nn \g__ctex_fontset_tl { mac } }
1608 { \tl_gset:Nn \g__ctex_fontset_tl { fandol } }
1609 }
1610 }
1611 \cs_new_protected:Npn \ctex_if_platform_macos:TF
1612 { \file_if_exist:nTF { /System/Library/Fonts/Menlo.ttc } }
1613 \cs_new_protected:Npn \ctex_load_fontset:
1614 {
1615 \tl_if_empty:NTF \g__ctex_fontset_tl
1616 { \ctex_detect_platform: }
1617 {
1618 \bool_lazy_or:nnTF
1619 { \str_if_eq_p:on { \g__ctex_fontset_tl } { windowsnew } }
1620 { \str_if_eq_p:on { \g__ctex_fontset_tl } { windowsold } }
1621 {
1622 \msg_warning:nnxx { ctex } { deprecated-fontset }
1623 { \g__ctex_fontset_tl } { windows }
1624 \tl_gset:Nn \g__ctex_fontset_tl { windows }
1625 }
1626 {
1627 \file_if_exist:nF { ctex-fontset- \g__ctex_fontset_tl .def }
1628 {
1629 \use:e
1630 {
1631 \ctex_detect_platform:
1632 \msg_error:nnxx { ctex } { fontset-not-found }
1633 { \g__ctex_fontset_tl } { \exp_not:N \g__ctex_fontset_tl }
1634 }
1635 }
1636 }
1637 }
1638 \ctex_file_input:n { ctex-fontset- \g__ctex_fontset_tl .def }
1639 }
1640 \msg_new:nnn { ctex } { deprecated-fontset }
1641 { CTeX~fontset~`#1'~is~deprecated.\\ Fontset~`#2'~will~be~used~instead. }
1642 \msg_new:nnnn { ctex } { fontset-not-found }
1643 { CTeX~fontset~`#1'~could~not~be~found.\\ Fontset~`#2'~will~be~used~instead. }
1644 { You~may~run~`mktexlsr'~firstly. }
1645 \@onlypreamble \ctex_load_fontset:
1646 \ctex_define:n
1647 {
1648 fontset .code:n =
1649 {
1650 \ctex_if_preamble:TF
1651 {
1652 \str_if_eq:eeTF {#1} { none }
1653 { \msg_warning:nnn { ctex } { invalid-value } {#1} }
1654 {
1655 \str_if_eq:onTF { \g__ctex_fontset_tl } { none }
1656 {
1657 \tl_gset:Nx \g__ctex_fontset_tl {#1}
1658 \ctex_load_fontset:
1659 }
1660 {
1661 \msg_error:nnxx { ctex } { fontset-loaded }
1662 { \g__ctex_fontset_tl } {#1}
1663 }
1664 }
1665 }
1666 { \msg_error:nn { ctex } { fontset-only-preamble } }
1667 }
1668 }
1669 \msg_new:nnnn { ctex } { fontset-loaded }
1670 {
1671 CTeX~fontset~`#1'~has~been~loaded.
1672 \str_if_eq:nnF {#1} {#2} { \\ Fontset~`#2'~will~be~ignored. }
1673 }
1674 { Only~one~fontset~can~be~loaded~in~the~preamble. }
1675 \msg_new:nnn { ctex } { fontset-only-preamble }
1676 { The~`fontset'~option~can~be~used~only~in~preamble. }
1677 \str_if_eq:onF { \g__ctex_fontset_tl } { none }
1678 { \ctex_load_fontset: }
1679 \ctex_at_end:n { \ctex_file_input:n { ctex.cfg } }
1680 %%
1681 %% This package consists of the files ctex.dtx,
1682 %% ctxdoc.cls,
1683 %% ctxdocstrip.tex,
1684 %% ctex-zhconv.lua,
1685 %% ctex-zhconv-make.lua,
1686 %% and the derived files ctex.pdf,
1687 %% ctex.ins,
1688 %% ctex.sty,
1689 %% ctexsize.sty,
1690 %% ctexheading.sty,
1691 %% ctexart.cls,
1692 %% ctexbook.cls,
1693 %% ctexrep.cls,
1694 %% ctexbeamer.cls,
1695 %% ctexcap.sty,
1696 %% ctexhook.sty,
1697 %% ctexpatch.sty,
1698 %% ctex-c5size.clo,
1699 %% ctex-cs4size.clo,
1700 %% ctex-heading-article.def,
1701 %% ctex-heading-book.def,
1702 %% ctex-heading-report.def,
1703 %% ctex-heading-beamer.def,
1704 %% ctex-scheme-plain.def,
1705 %% ctex-scheme-plain-article.def,
1706 %% ctex-scheme-plain-book.def,
1707 %% ctex-scheme-plain-report.def,
1708 %% ctex-scheme-plain-beamer.def,
1709 %% ctex-scheme-chinese.def,
1710 %% ctex-scheme-chinese-article.def,
1711 %% ctex-scheme-chinese-book.def,
1712 %% ctex-scheme-chinese-report.def,
1713 %% ctex-scheme-chinese-beamer.def,
1714 %% ctex-name-gbk.cfg,
1715 %% ctex-name-utf8.cfg,
1716 %% ctex.cfg,
1717 %% ctexopts.cfg,
1718 %% ctexbackend.cfg,
1719 %% ctex-engine-pdftex.def,
1720 %% ctex-engine-xetex.def,
1721 %% ctex-engine-luatex.def,
1722 %% ctex-engine-aptex.def,
1723 %% ctex-engine-uptex.def,
1724 %% c19rm.fd,
1725 %% c19sf.fd,
1726 %% c19tt.fd,
1727 %% c70rm.fd,
1728 %% c70sf.fd,
1729 %% c70tt.fd,
1730 %% jy2zhrm.fd,
1731 %% jy2zhsf.fd,
1732 %% jy2zhtt.fd,
1733 %% jt2zhrm.fd,
1734 %% jt2zhsf.fd,
1735 %% jt2zhtt.fd,
1736 %% ctex-fontset-adobe.def,
1737 %% ctex-fontset-fandol.def,
1738 %% ctex-fontset-founder.def,
1739 %% ctex-fontset-mac.def,
1740 %% ctex-fontset-macnew.def,
1741 %% ctex-fontset-macold.def,
1742 %% ctex-fontset-ubuntu.def,
1743 %% ctex-fontset-windows.def,
1744 %% ctexspa.def,
1745 %% ctexpunct.spa,
1746 %% ctex-spa-make.tex,
1747 %% ctex-spa-macro.tex,
1748 %% ctex-zhmap-adobe.tex,
1749 %% ctex-zhmap-fandol.tex,
1750 %% ctex-zhmap-founder.tex,
1751 %% ctex-zhmap-mac.tex,
1752 %% ctex-zhmap-ubuntu.tex,
1753 %% ctex-zhmap-windows.tex,
1754 %% ctex-zhconv-index.lua,
1755 %% translator-theorem-dictionary-ChineseGBK.dict,
1756 %% translator-theorem-dictionary-ChineseUTF8.dict, and
1757 %% README.md.
1758 %%
1759 %% End of file `ctexbook.cls'.