Debian Codegraph @

texmf-dist/source/latex/easybook/easybook.dtx

raw
1 %
2 % Copyright (C) 2021-2025 by Qu Yi <[email protected]>
3 %
4 % This work may be distributed and/or modified under the
5 % conditions of the LaTeX Project Public License, either
6 % version 1.3c of this license or (at your option) any later
7 % version. The latest version of this license is in:
8 %
9 % http://www.latex-project.org/lppl.txt
10 %
11 % and version 1.3 or later is part of all distributions of
12 % LaTeX version 2005/12/01 or later.
13 %
14 % This work has the LPPL maintenance status `maintained'.
15 %<class|package>\NeedsTeXFormat{LaTeX2e}[2021/11/15]
16 %<*class>
17 \ProvidesExplClass{easybook}{2025/08/01}{2025ae}
18 {Easily typesetting Chinese theses or books}
19
20 \bool_new:N \l__eb_compile_draft_bool
21 \bool_new:N \l__eb_title_newline_bool
22 \bool_set_true:N \l__eb_class_mode_book_bool
23 \clist_new:N \g__eb_doc_options_clist
24 \cs_new_protected:Npn \eb_put_ctexbook:n #1
25 { \PassOptionsToClass{#1}{ctexbook} }
26 \cs_generate_variant:Nn \eb_put_ctexbook:n { V }
27
28 \keys_define:nn { easybook }
29 {
30 newline .code:n = \bool_set_true:N \l__eb_title_newline_bool,
31 scheme .code:n = \eb_put_ctexbook:n { scheme = {#1} },
32 enmode .meta:n = { newline,scheme = plain },
33 font .choices:nn =
34 { noto,times,times*,ebgaramond,libertine,palatino,auto }
35 { \tl_set:Nn \l__eb_font_value_tl {#1} },
36 font .value_required:n = true,
37 font .initial:n = auto,
38 cjkfont .code:n = \eb_put_ctexbook:n { fontset = {#1} },
39 mathfont .tl_set:N = \l__eb_mathfont_value_tl,
40 mathfont .initial:n = times,
41 configs .clist_gset:N = \g__eb_configs_file_clist,
42 unknown .code:n = \clist_gput_right:NV \g__eb_doc_options_clist \CurrentOption
43 }
44 \IfFormatAtLeastTF{2024/06/20}{}
45 {
46 \keys_define:nn { easybook }
47 {
48 paper .code:n = { },
49 class .code:n = { },
50 floatpage .code:n = { },
51 theorem .code:n = { },
52 chem .code:n = { }
53 }
54 }
55
56 \cs_if_exist:NTF \ProcessKeyOptions
57 { \ProcessKeyOptions[easybook] }
58 {
59 \RequirePackage{l3keys2e}
60 \ProcessKeysOptions{easybook}
61 }
62 \PassOptionsToPackage{no-math,quiet,CJKmath}{xeCJK}
63 \eb_put_ctexbook:V \g__eb_doc_options_clist
64 \LoadClass[UTF8]{ctexbook}
65
66 \RequirePackage{easybase}
67 \ctex_at_end_preamble:n
68 {
69 \use:c { eb@font@load@\l__eb_font_value_tl }
70 \clist_if_empty:NF \g__eb_configs_file_clist
71 { \clist_map_function:NN \g__eb_configs_file_clist \file_input:n }
72 }
73
74 \sys_if_engine_xetex:TF
75 {
76 \cs_new_eq:NN \eb_set_family:nnn \xeCJK_set_family:nnn
77 \cs_new_eq:NN \eb_switch_family:n \xeCJK_switch_family:n
78 }
79 {
80 \cs_new_eq:NN \eb_set_family:nnn \ctex_ltj_set_family:nnn
81 \cs_new_eq:NN \eb_switch_family:n \ctex_ltj_switch_family:n
82 }
83 \cs_generate_variant:Nn \eb_set_family:nnn { x }
84 \cs_new_protected:Npn \eb_setmainfont:nn #1#2
85 { \__fontspec_main_setmainfont:nn {#2} {#1} }
86 \cs_new_protected:Npn \eb_setsansfont:nn #1#2
87 { \__fontspec_main_setsansfont:nn {#2} {#1} }
88 \cs_new_protected:Npn \eb_setmonofont:nn #1#2
89 { \__fontspec_main_setmonofont:nn {#2} {#1} }
90 \cs_new_protected:Npn \eb_setCJKmainfont:nn #1#2
91 { \eb_set_family:xnn { \CJKrmdefault } {#2} {#1} }
92 \cs_new_protected:Npn \eb_setCJKsansfont:nn #1#2
93 { \eb_set_family:xnn { \CJKsfdefault } {#2} {#1} }
94 \cs_new_protected:Npn \eb_setCJKmonofont:nn #1#2
95 { \eb_set_family:xnn { \CJKttdefault } {#2} {#1} }
96 \clist_map_inline:nn
97 { main,sans,mono,CJKmain,CJKsans,CJKmono }
98 {
99 \exp_args:Nc \RenewDocumentCommand { set#1font }{O{}mO{}}
100 {\use:c { eb_set#1font:nn } {##2} { ##1,##3 }}
101 }
102 \RenewDocumentCommand{\newCJKfontfamily}{omO{}mO{}}
103 {
104 \tl_set:Nx \l_tmpa_tl { \tl_if_novalue:nTF {#1} { \cs_to_str:N #2 } {#1} }
105 \cs_new_protected:Npx #2 { \eb_switch_family:n { \l_tmpa_tl } }
106 \eb_set_family:xnn { \l_tmpa_tl } { #3,#5 } {#4}
107 }
108
109 \cs_new_protected:Npn \eb@font@load@noto
110 {
111 \eb_setmainfont:nn { NotoSerif }
112 {
113 Extension = .ttf,
114 UprightFont = *-Regular,
115 BoldFont = *-Bold,
116 ItalicFont = *-Italic
117 }
118 \eb_setsansfont:nn { NotoSans }
119 {
120 Extension = .ttf,
121 UprightFont = *-Regular,
122 BoldFont = *-Bold,
123 ItalicFont = *-Italic
124 }
125 \eb_setmonofont:nn { NotoSansMono }
126 {
127 Extension = .ttf,
128 UprightFont = *-Regular,
129 BoldFont = *-Bold
130 }
131 }
132 \cs_new_protected:Npn \eb@font@load@times
133 {
134 \eb_setmainfont:nn { XITS }
135 {
136 Extension = .otf,
137 UprightFont = *-regular,
138 BoldFont = *-bold,
139 ItalicFont = *-italic,
140 BoldItalicFont = *-bolditalic
141 }
142 \eb_setsansfont:nn { texgyreheros }
143 {
144 Extension = .otf,
145 UprightFont = *-regular,
146 BoldFont = *-bold,
147 ItalicFont = *-italic,
148 BoldItalicFont = *-bolditalic
149 }
150 \eb_setmonofont:nn { texgyrecursor }
151 {
152 Extension = .otf,
153 UprightFont = *-regular,
154 BoldFont = *-bold,
155 ItalicFont = *-italic,
156 BoldItalicFont = *-bolditalic,
157 Ligatures = CommonOff
158 }
159 }
160 \cs_new_protected:cpn { eb@font@load@times* }
161 {
162 \eb_setmainfont:nn { Times~New~Roman } { }
163 \eb_setsansfont:nn { Arial } { }
164 \eb_setmonofont:nn { Courier~New } { }
165 }
166 \cs_new_protected:Npn \eb@font@load@libertinus@sans
167 {
168 \eb_setsansfont:nn { LibertinusSans }
169 {
170 Extension = .otf,
171 UprightFont = *-Regular,
172 BoldFont = *-Bold,
173 ItalicFont = *-Italic
174 }
175 }
176 \cs_new_protected:Npn \eb@font@load@lmmonolt@mono
177 {
178 \eb_setmonofont:nn { lmmonolt10 }
179 {
180 Extension = .otf,
181 UprightFont = *-regular,
182 BoldFont = *-bold,
183 ItalicFont = *-oblique,
184 BoldItalicFont = *-boldoblique
185 }
186 }
187 \cs_new_protected:Npn \eb@font@load@ebgaramond
188 {
189 \eb_setmainfont:nn { EBGaramond }
190 {
191 Extension = .otf,
192 UprightFont = *-Regular,
193 BoldFont = *-Bold,
194 ItalicFont = *-Italic,
195 BoldItalicFont = *-BoldItalic
196 }
197 \eb@font@load@libertinus@sans
198 \eb@font@load@lmmonolt@mono
199 }
200 \cs_new_protected:Npn \eb@font@load@libertine
201 {
202 \eb_setmainfont:nn { LibertinusSerif }
203 {
204 Extension = .otf,
205 UprightFont = *-Regular,
206 BoldFont = *-Bold,
207 ItalicFont = *-Italic,
208 BoldItalicFont = *-BoldItalic
209 }
210 \eb@font@load@libertinus@sans
211 \eb@font@load@lmmonolt@mono
212 }
213 \cs_new_protected:Npn \eb@font@load@palatino
214 {
215 \eb_setmainfont:nn { texgyrepagella }
216 {
217 Extension = .otf,
218 UprightFont = *-regular,
219 BoldFont = *-bold,
220 ItalicFont = *-italic,
221 BoldItalicFont = *-bolditalic
222 }
223 \eb@font@load@libertinus@sans
224 \eb@font@load@lmmonolt@mono
225 }
226 \cs_new_protected:Npn \eb_put_newtxmath:n #1
227 { \PassOptionsToPackage{#1}{newtxmath} }
228 \cs_generate_variant:Nn \eb_put_newtxmath:n { V }
229 \str_case:VnF \l__eb_mathfont_value_tl
230 {
231 { times } { \RequirePackage{newtxmath,bm} }
232 { none } { }
233 }
234 {
235 \eb_put_newtxmath:V \l__eb_mathfont_value_tl
236 \RequirePackage{newtxmath,bm}
237 }
238
239 \ctex_set:n
240 {
241 secnumdepth = 3,
242 tocdepth = \bool_if:NTF \l__eb_class_mode_book_bool { 1 } { 2 },
243 part =
244 {
245 pagestyle = empty,
246 format = \color{ctex@frame}\sffamily\Huge,
247 nameformat = { },
248 titleformat = { },
249 aftername =
250 {
251 \bool_if:NTF \l__eb_title_newline_bool
252 { \par\nobreak }
253 { \hspace{1em} }
254 }
255 },
256 chapter =
257 {
258 pagestyle = empty,
259 format =
260 {
261 \color{ctex@frame}\sffamily\LARGE
262 \bool_if:NF \l__eb_title_newline_bool { \centering }
263 },
264 nameformat = { },
265 titleformat = { },
266 aftername =
267 {
268 \bool_if:NTF \l__eb_title_newline_bool
269 { \par\nobreak\vskip 1.5pc }
270 { \hspace{1em} }
271 },
272 beforeskip = 0pt,
273 afterskip = 25pt
274 },
275 section =
276 {
277 hang = true,
278 format = \color{ctex@frame}\sffamily\Large,
279 aftername = \hspace{0.5em},
280 beforeskip = 2ex plus .2ex minus .1ex,
281 afterskip = 2ex plus .2ex minus .1ex
282 },
283 subsection =
284 {
285 hang = true,
286 format = \color{ctex@frame}\sffamily\large,
287 aftername = \hspace{0.5em},
288 beforeskip = 1.5ex plus .2ex minus .1ex,
289 afterskip = 1.5ex plus .2ex minus .1ex
290 },
291 subsubsection =
292 {
293 hang = true,
294 format = \color{ctex@frame}\sffamily,
295 aftername = \hspace{0.5em},
296 beforeskip = \parskip,
297 afterskip = \parskip
298 }
299 }
300 \bool_if:NF \l__eb_class_mode_book_bool
301 {
302 \ctex_set:nn { part }
303 {
304 format = \color{ctex@frame}\sffamily\Large,
305 break = \if@noskipsec\leavevmode\fi\par,
306 beforeskip = 3ex,
307 afterskip = 3ex
308 }
309 \def\@endpart
310 {
311 \CTEX@setheadingskip\CTEX@part@afterskip
312 \ifodd\CTEX@part@fixskip\CTEX@fixheadingskip\fi
313 \vskip\CTEX@headingskip
314 \@afterheading
315 }
316 }
317 \bool_if:NF \l__eb_title_newline_bool
318 {
319 \ctex_set:n
320 {
321 part/hang = true,
322 chapter/hang = true
323 }
324 }
325 %</class>
326 %<*package>
327 \RequirePackage{etoolbox}
328 \ProvidesExplPackage{easybase}{2025/08/01}{2025ae}
329 {Easily typesetting Chinese theses or books}
330
331 \cs_generate_variant:Nn \dim_set:Nn { NV }
332 \cs_generate_variant:Nn \dim_sign:n { V }
333 \cs_generate_variant:Nn \int_to_arabic:n { v }
334 \cs_generate_variant:Nn \msg_warning:nnn { nnV }
335 \cs_generate_variant:Nn \skip_set:Nn { NV }
336 \cs_generate_variant:Nn \ctex_define:nn { nx }
337 \cs_generate_variant:Nn \tl_if_novalue:nF { V }
338
339 \cs_set_protected:Npn \ctex_define:nn #1
340 { \keys_define:nn { ctex/#1 } }
341 \cs_new_protected:Npn \eb_patch_cmd:Nnn #1#2#3
342 {
343 \ctex_patch_cmd_once:NnnnTF #1 { } {#2} {#3}
344 { } { \ctex_patch_failure:N #1 }
345 }
346 \cs_new_protected:Npn \eb_preto_cmd:nn #1#2
347 { \AddToHook{cmd/#1/before}{#2} }
348 \cs_new_protected:Npn \eb_appto_cmd:nn #1#2
349 { \AddToHook{cmd/#1/after}{#2} }
350 \cs_set_protected:Npn \ctex_before_end_preamble:n
351 { \BeforeBeginEnvironment{document} }
352 \cs_new_protected:Npn \eb_if_package_loaded:nnF #1#2#3
353 {
354 \IfPackageLoadedTF{#1}
355 {
356 \tl_if_blank:nTF {#2}
357 { \msg_warning:nnn { easybase } { package-repeat-load-ii } {#1} }
358 { \msg_warning:nnnn { easybase } { package-repeat-load-i } {#1} {#2} }
359 }{#3}
360 }
361 \msg_new:nnn { easybase } { package-repeat-load-i }
362 {
363 The~macro~package~'#1'~has~been~loaded~repeatedly. \\
364 Please~pass~the~arguments~by \\
365 the~\string\PassOptionsToPackage{#2}{#1}\ command.
366 }
367 \msg_new:nnn { easybase } { package-repeat-load-ii }
368 { The~macro~package~'#1'~has~been~loaded~repeatedly. }
369 \cs_set_eq:NN \eb@usepackage@save \usepackage
370 \RenewDocumentCommand{\usepackage}{O{}mO{}}
371 {
372 \PassOptionsToPackage{#1}{#2}
373 \clist_map_inline:nn {#2}
374 {
375 \eb_if_package_loaded:nnF {##1} {#1}
376 { \eb@usepackage@save{##1}[#3] }
377 }
378 }
379 \cs_new_protected:Npn \eb_match_load_package:n #1
380 {
381 \regex_match:nnTF { \[.*\] } {#1}
382 { \eb@case@load@package #1 }
383 { \eb@case@load@package{#1} }
384 }
385 \NewDocumentCommand{\eb@case@load@package}{omO{}}
386 {
387 \IfNoValueTF{#1}
388 {\IfFileExists{#2.sty}{\RequirePackage{#2}[#3]}{}}
389 {\IfFileExists{#2.sty}{\RequirePackage[#1]{#2}[#3]}{}}
390 \IfFileExists{#2.sty}{}
391 {\msg_warning:nnn { easybase } { package-not-found } {#2}}
392 }
393 \msg_new:nnn { easybase } { package-not-found }
394 { The~macro~package~'#1'~can't~be~found. }
395 \cs_new_protected:Npn \ebloadpackage #1
396 {
397 \int_compare:nTF { \clist_count:n {#1} <= 1 }
398 { \RequirePackage{#1} }
399 {
400 \clist_map_inline:nn {#1}
401 { \eb_match_load_package:n {##1} }
402 }
403 }
404 \providecommand{\NewHookWithArguments}[2]{}
405 \ProvideDocumentCommand{\AddToHookWithArguments}{mo+m}{}
406
407 \bool_set_true:N \l__eb_class_mode_book_bool
408 \bool_set_false:N \l__eb_compile_draft_bool
409 \clist_new:N \g__eb_ctex_options_clist
410 \cs_new_protected:Npn \eb_put_geometry:n #1
411 { \PassOptionsToPackage{#1}{geometry} }
412 \providebool{@openright}
413
414 \keys_define:nn { easybase }
415 {
416 draft .code:n =
417 {
418 \bool_set_true:N \l__eb_compile_draft_bool
419 \PassOptionsToPackage{draft}{hyperref}
420 },
421 floatpage .bool_set:N = \l__eb_float_page_bool,
422 floatpage .default:n = true,
423 floatpage .initial:n = false,
424 theorem .choices:nn =
425 { thmtools,keytheorems,false }
426 { \tl_set:Nn \l__eb_theorem_support_tl {#1} },
427 theorem/true .meta:n = { theorem = thmtools },
428 theorem .default:n = thmtools,
429 theorem .initial:n = thmtools,
430 chem .choices:nn =
431 { chemformula,mhchem,false }
432 { \tl_set:Nn \l__eb_chem_support_tl {#1} },
433 chem/true .meta:n = { chem = chemformula },
434 chem .default:n = chemformula,
435 chem .initial:n = chemformula,
436 paper .code:n = \eb_put_geometry:n {#1},
437 paper .initial:n = a4paper,
438 class .choice:,
439 class .value_required:n = true,
440 class/book .code:n =
441 {
442 \bool_set_true:N \l__eb_class_mode_book_bool
443 \eb_put_geometry:n { twoside }
444 \booltrue{@titlepage}
445 \booltrue{@openright}
446 },
447 class/article .code:n =
448 {
449 \bool_set_false:N \l__eb_class_mode_book_bool
450 \eb_put_geometry:n { twoside = false }
451 \boolfalse{@titlepage}
452 },
453 class .initial:x = \cs_if_exist:NTF \chapter { book } { article },
454 book .meta:n = { class = book },
455 article .meta:n = { class = article },
456 twoside .code:n = \eb_put_geometry:n { twoside },
457 oneside .code:n = \eb_put_geometry:n { twoside = false },
458 titlepage .code:n = \booltrue{@titlepage},
459 notitlepage .code:n = \boolfalse{@titlepage},
460 openright .code:n = \booltrue{@openright},
461 openany .code:n = \boolfalse{@openright},
462 unknown .code:n = \clist_gput_right:NV \g__eb_ctex_options_clist \CurrentOption
463 }
464
465 \PassOptionsToPackage{list = off}{bicaption}
466 \PassOptionsToPackage{svgnames}{xcolor}
467 \PassOptionsToPackage{many}{tcolorbox}
468 \cs_if_exist:NTF \ProcessKeyOptions
469 { \ProcessKeyOptions[easybase] }
470 {
471 \RequirePackage{l3keys2e}
472 \ProcessKeysOptions{easybase}
473 }
474 \PassOptionsToPackage{\g__eb_ctex_options_clist}{ctex}
475 \IfClassLoadedTF{ctexbook}{}
476 {
477 \IfClassLoadedTF{ctexart}{}
478 {
479 \IfClassLoadedTF{ctexrep}{}
480 {\RequirePackage[heading]{ctex}}
481 }
482 }
483 \ctex_disable_package:n { nccfoots }
484 \ctex_disable_package:n { tocloft }
485 \ctex_disable_package:n { titlesec }
486
487 \seq_set_from_clist:Nn \l__eb_module_paths_seq
488 {
489 tools,font,space,bib,
490 thmt,toc,hdr,float,
491 ref,geo,cap
492 }
493 \seq_map_inline:Nn \l__eb_module_paths_seq
494 {
495 \ctex_define:n { #1 .meta:nn = { ctex/#1 } {##1} }
496 \cs_new_protected:cpn { eb#1set } ##1 { \ctex_set:nn {#1} {##1} }
497 }
498 \RenewDocumentCommand{\ctexset}{o+m}
499 {
500 \IfValueTF{#1}
501 {\ctex_set:nn {#1} {#2}}
502 {\ctex_set:n {#2}}
503 }
504 \bool_until_do:nn
505 { \int_compare_p:nNn { \seq_count:N \l__eb_module_paths_seq } < { 9 } }
506 { \seq_pop_right:NN \l__eb_module_paths_seq \l_tmpa_tl }
507 \seq_map_inline:Nn \l__eb_module_paths_seq
508 {
509 \msg_new:nnn { easybase } { deprecated-#1 }
510 {
511 The~option~'##1'~of~module~'#1'~is~deprecated~or~non-existent. \\
512 Please~browse~the~user~manual~for~the~new~options.
513 }
514 }
515 \cs_new_protected:Npn \eb_msg_deprecated_option:n #1
516 { \msg_warning:nnV { easybase } { deprecated-#1 } \l_keys_key_str }
517 \cs_if_exist:NF \chapter
518 {
519 \newcounter{chapter}
520 \providebool{@mainmatter}
521 \bool_set_false:N \l__eb_class_mode_book_bool
522 \ctex_define:n { chapter .meta:nn = { ctex/chapter } {#1} }
523 \ctex_define:n { chapter/tocline .code:n = { } }
524 }
525 \bool_if:NF \l__eb_class_mode_book_bool
526 {
527 \cs_undefine:N \chapter
528 \ctex_after_end_preamble:n
529 {
530 \NewDocumentCommand{\chapter}{som}
531 {
532 \msg_error:nn { easybase } { no-chapter }
533 \msg_redirect_name:nnn { easybase } { no-chapter } { none }
534 }
535 }
536 }
537 \msg_new:nnn { easybase } { no-chapter }
538 {
539 Your~document~class~is~in~'article'~mode. \\
540 The~'\string\chapter'\ command~will~not~be~used.
541 }
542
543 \ebloadpackage
544 {
545 [text]{spbmark},
546 [{shortlabels,inline}]{enumitem},
547 siunitx,pifont,
548 geometry,marginnote,multicol,
549 fancyhdr,titletoc,caption,
550 tabularray,graphicx,xcolor,
551 listings
552 }
553 \cs_new_protected:Npn \eb_package_date_check:nn #1#2
554 {
555 \IfPackageAtLeastTF{#1}{#2}{}
556 {\msg_warning:nnn { easybase } { package-old } {#1}}
557 }
558 \msg_new:nnn { easybase } { package-old }
559 {
560 Package~'#1'~has~been~out~of~date. \\
561 Some~problems~or~errors~may~occur \\
562 if~you~continue~compiling. \\\\
563 Please~update~your~macro~package~from~CTAN.
564 }
565
566 \ctex_at_end_package:nn { pdfpages }
567 { \includepdfset{fitpaper = true} }
568 \geometry
569 {
570 vmargin = 2.54cm,
571 hmargin = 3.17cm,
572 columnsep = 2em,
573 headheight = 2.14cm,
574 headsep = 0.4cm,
575 footnotesep = 0.4cm,
576 footskip = 0.79cm,
577 marginparsep = 8pt,
578 marginparwidth = 2.54cm
579 }
580 \cs_new:Npn \eb_unknown_kv_handle:
581 {
582 \str_use:N \l_keys_key_str
583 \tl_if_novalue:VF \l_keys_value_tl
584 { = {\exp_not:V \l_keys_value_tl} }
585 }
586 \ctex_define:nn { geo }
587 {
588 headruleskip .tl_set:N = \headruleskip,
589 headruleskip .initial:n = 0pt,
590 footruleskip .tl_set:N = \footruleskip,
591 footruleskip .initial:n = 3.5pt,
592 unknown .code:n = \exp_args:Nx \geometry { \eb_unknown_kv_handle: },
593 unknown .default:V = \c_novalue_tl
594 }
595
596 \cs_new_protected:Npn \blankpagestyle #1
597 { \tl_set:Nn \l__eb_blank_pagestyle_tl {#1} }
598 \blankpagestyle{empty}
599 \RenewDocumentCommand{\cleardoublepage}{O{\l__eb_blank_pagestyle_tl}}
600 {
601 \clearpage
602 \ifbool{@twoside}
603 {
604 \int_if_odd:nF { \c@page }
605 { \hbox:n { }\thispagestyle{#1}\clearpage }
606 }{}
607 }
608 \DeclareDocumentCommand{\frontmatter}{sO{Roman}}
609 {
610 \IfBooleanTF{#1}{\clearpage}{\cleardoublepage}
611 \boolfalse{@mainmatter}
612 \pagenumbering{#2}
613 }
614 \DeclareDocumentCommand{\mainmatter}{s}
615 {
616 \IfBooleanTF{#1}{\clearpage}{\cleardoublepage}
617 \booltrue{@mainmatter}
618 \pagenumbering{arabic}
619 }
620 \NewDocumentCommand{\markrule}
621 {O{\textwidth}D(){ctex@frame}mO{0pt}}
622 {
623 \group_begin:
624 \color{#2}
625 \exp_last_unbraced:Nx \hrule
626 {
627 \@width \dim_eval:n {#1}
628 \@height \dim_eval:n {#3}
629 \@depth \dim_eval:n {#4}
630 }
631 \group_end:
632 }
633 \cs_new:Npn \eb_mark_uppercase_case_init:n
634 {
635 \str_case:Vn \l__eb_mark_uppercase_value_tl
636 {
637 { all } { \text_uppercase:n }
638 { first } { \text_titlecase_first:n }
639 { none* } { \text_lowercase:n }
640 }
641 }
642 \cs_new_protected:Npn \eb@register@hdr@mark #1
643 {
644 \exp_args:Nc \DeclareDocumentCommand { eb@mark@#1@label@layout }
645 {O{\use:c { CTEXthe#1 }}m}
646 {\tl_set:cn { eb@mark@#1@label } {##1##2}}
647 \cs_set_protected:cpn { eb_mark_#1_name_parse:n } ##1
648 {
649 \regex_match:nnTF { ^\[.*\] } {##1}
650 { \use:c { eb@mark@#1@label@layout }##1 }
651 { \use:c { eb@mark@#1@label@layout }{##1} }
652 }
653 \ctex_define:nn { hdr }
654 {
655 #1-mark .cs_set:cp = { eb@mark@#1@whole } ##1,
656 #1-mark .initial:n =
657 {
658 \CTEXifname{\use:c { eb@mark@#1@label }}{}
659 \eb_mark_uppercase_case_init:n {##1}
660 },
661 #1-label .code:n = \use:c { eb_mark_#1_name_parse:n } {##1},
662 #1-label .initial:n = \hspace{0.5em}
663 }
664 }
665 \cs_new_protected:Npn \RegisterHdrMark #1
666 {
667 \clist_map_function:nN {#1}
668 \eb@register@hdr@mark
669 }
670 \RegisterHdrMark{chapter,section,subsection}
671 \ctex_set:nn { hdr } { chapter-label = \hspace{1em} }
672 \ctex_define:nn { hdr }
673 {
674 chap-mark .meta:n = { chapter-mark = {#1} },
675 sec-mark .meta:n = { section-mark = {#1} },
676 subsec-mark .meta:n = { subsection-mark = {#1} },
677 chap-label .meta:n = { chapter-label = {#1} },
678 sec-label .meta:n = { section-label = {#1} },
679 subsec-label .meta:n = { subsection-label = {#1} },
680 headrulewd .dim_set:N = \eb@head@rule@wd,
681 headrulewd .initial:n = 0.5pt,
682 footnoterulewd .dim_set:N = \eb@footnote@rule@wd,
683 footnoterulewd .initial:n = 0.5pt,
684 headrule .tl_gset:N = \headrule,
685 headrule .initial:n = \markrule{\eb@head@rule@wd},
686 footrule .tl_gset:N = \footrule,
687 footrule .initial:n = { },
688 footnoterule .tl_gset:N = \footnoterule,
689 footnoterule .initial:n =
690 {
691 \markrule[0.35\textwidth]{\eb@footnote@rule@wd}
692 \vspace*{3pt}
693 }
694 }
695
696 \cs_set:Npn \markdouble #1 { \markboth{#1}{\ifbool{@twoside}{#1}{}} }
697 \cs_new_protected:Npn \eb@level@markdouble #1#2
698 { \markdouble{\use:c { eb@mark@#1@whole }{#2}} }
699 \cs_new_protected:Npn \eb@level@markright #1#2
700 { \markright{\use:c { eb@mark@#1@whole }{#2}} }
701 \cs_gset:Npn \chaptermark #1 { \eb@level@markdouble{chapter}{#1} }
702 \cs_gset:Npx \sectionmark #1
703 {
704 \bool_if:NTF \l__eb_class_mode_book_bool
705 { \eb@level@markright{section}{#1} }
706 { \eb@level@markdouble{section}{#1} }
707 }
708 \cs_gset:Npx \subsectionmark #1
709 {
710 \bool_if:NF \l__eb_class_mode_book_bool
711 { \eb@level@markright{subsection}{#1} }
712 }
713 \fancyhf{}
714 \ifbool{@twoside}
715 {
716 \fancyhead[EC]{\color{ctex@frame}\kaishu\leftmark}
717 \fancyhead[OC]{\color{ctex@frame}\kaishu\rightmark}
718 \fancyhead[EL,OR]{\color{ctex@frame}\thepage}
719 }{
720 \fancyhead[L]{\color{ctex@frame}\kaishu\leftmark}
721 \fancyhead[R]{\color{ctex@frame}\thepage}
722 }
723 \bool_if:NT \l__eb_compile_draft_bool
724 {
725 \fancyfoot[C]{\color{SlateGray}\sffamily\today}
726 \geometry{showframe}
727 }
728 \bool_new:N \l__eb_ps_used_bool
729 \NewHook{ps@end}
730 \AddToHook{ps@end}{\bool_set_true:N \l__eb_ps_used_bool}
731 \apptocmd{\pagestyle}{\UseOneTimeHook{ps@end}}{}{}
732 \ctex_at_end_preamble:n
733 {
734 \bool_if:NF \l__eb_ps_used_bool { \pagestyle{fancy} }
735 \providecommand{\kaishu}{\itshape}
736 }
737
738 \ctex_define:nn { tools }
739 {
740 fntnumwith .choices:nn =
741 { part,page,chapter }
742 { \tl_set:Nn \l__eb_fnt_parent_counter_tl {#1} },
743 fntnumwith .value_required:n = true,
744 fntnumwith .initial:n = chapter
745 }
746 \NewDocumentCommand{\eb_assign_fntext_code:n}
747 {>{\SplitArgument{1}{,}}m}
748 {\eb_assign_fnmark_code_pos:nn #1}
749 \cs_new_protected:Npn \eb_assign_fnmark_code_pos:nn #1#2
750 {
751 \tl_set:Nn \l__eb_fntext_before_tl {#1}
752 \tl_if_novalue:nTF {#2}
753 { \tl_clear:N \l__eb_fntext_after_tl }
754 { \tl_set:Nn \l__eb_fntext_after_tl {#2} }
755 }
756 \cs_new_protected:Npn \eb_fnnormal_counter_pifont:N #1
757 { \ding{\int_eval:n { 171 + #1 }} }
758 \cs_new_protected:Npn \eb_fnnormal_counter_pifont_neg:N #1
759 { \ding{\int_eval:n { 181 + #1 }} }
760 \cs_new_protected:Npn \eb_fnnormal_counter_pisans:N #1
761 { \ding{\int_eval:n { 191 + #1 }} }
762 \cs_new_protected:Npn \eb_fnnormal_counter_pisans_neg:N #1
763 { \ding{\int_eval:n { 201 + #1 }} }
764 \cs_new:Npn \eb_fnt_map_symbols_list:n #1
765 {
766 \eb_fnt_map_symbols_list:nn #1
767 \q_recursion_tail \q_recursion_tail
768 \q_recursion_stop
769 }
770 \cs_new:Npn \eb_fnt_map_symbols_list:nn #1#2
771 {
772 \quark_if_recursion_tail_stop:n {#1}
773 \quark_if_recursion_tail_stop:n {#2}
774 { #1 + \int_use:N \c@footnote } { \exp_not:n {#2} }
775 \eb_fnt_map_symbols_list:nn
776 }
777 \cs_new_protected:Npn \SetFntSymbsList #1#2#3
778 {
779 \cs_set_protected:cpn { eb@use@fnt@symbol@#1 }
780 {
781 \cs_set:Npx \eb_int_to_symbols:n ####1
782 {
783 \exp_not:N \int_to_symbols:nnn {####1}
784 { #2 + \int_use:N \c@footnote }
785 { \eb_fnt_map_symbols_list:n {#3} }
786 }
787 }
788 }
789 \cs_new_protected:Npn \UseFntSymbsList #1
790 {
791 \cs_if_exist_use:cF { eb@use@fnt@symbol@#1 }
792 { \msg_warning:nnn { easybase } { undefined-fntsymbol } {#1} }
793 }
794 \msg_new:nnn { easybase } { undefined-fntsymbol }
795 { The~list~of~footnote~symbols~'#1'~isn't~defined. }
796 \SetFntSymbsList{empty}{1}{}
797 \SetFntSymbsList{fnsymbol}{10}
798 {
799 { 1 } { $*$ }
800 { 2 } { $\dagger$ }
801 { 3 } { $\ddagger$ }
802 { 4 } { $\mathsection$ }
803 { 5 } { $\mathparagraph$ }
804 { 6 } { $\|$ }
805 { 7 } { $**$ }
806 { 8 } { $\dagger\dagger$ }
807 { 9 } { $\ddagger\ddagger$ }
808 { 10 } { \@ctrerr }
809 }
810 \UseFntSymbsList{empty}
811 \cs_set_eq:NN \DefineFntSymbols \SetFntSymbsList
812 \cs_set_eq:NN \setfntsymbol \UseFntSymbsList
813 \tl_new:N \l__eb_fnnormal_tmpa_tl
814 \tl_new:N \l__eb_fnnormal_tmpb_tl
815 \cs_new_protected:Npn \eb_fnnormal_normal_label_set:Nn #1#2
816 {
817 \tl_set:Nn \l__eb_fnnormal_tmpa_tl {#2}
818 \cs_set:Npx #1
819 {
820 \str_case:VnT \l__eb_fnnormal_tmpa_tl
821 {
822 { plain }
823 { \exp_not:N \int_use:N }
824 { pifont }
825 { \eb_fnnormal_counter_pifont:N }
826 { pifont* }
827 { \eb_fnnormal_counter_pifont_neg:N }
828 { pisans }
829 { \eb_fnnormal_counter_pisans:N }
830 { pisans* }
831 { \eb_fnnormal_counter_pisans_neg:N }
832 }
833 { \exp_not:N \c@footnote }
834 }
835 \cs_set_eq:NN \thedownfootnote \thefootnote
836 }
837 \cs_generate_variant:Nn \msg_warning:nnnn { nnnV }
838 \cs_new:Npn \eb_footnote_int_trans:n #1
839 {
840 \prop_item:Nn \l__eb_int_trans_cmds_prop {#1}
841 \exp_not:N \c@footnote
842 }
843 \prop_set_from_keyval:Nn \l__eb_int_trans_cmds_prop
844 {
845 A = \int_to_Alph:n,
846 a = \int_to_alph:n,
847 1 = \int_to_arabic:n,
848 I = \int_to_Roman:n,
849 i = \int_to_roman:n,
850 c = \exp_args:NV \zhnumber,
851 s = \eb_int_to_symbols:n
852 }
853 \cs_new_protected:Npn \eb_fnnormal_short_label_set:Nn #1#2
854 {
855 \tl_set:Nn \l__eb_fnnormal_tmpb_tl {#2}
856 \clist_map_inline:nn
857 { A,a,1,I,i,c,s }
858 {
859 \regex_match:nnTF {##1} {#2}
860 {
861 \regex_replace_once:nnN {##1}
862 { \c{eb_footnote_int_trans:n}\0 }
863 \l__eb_fnnormal_tmpb_tl
864 \cs_set:Npx #1 { \l__eb_fnnormal_tmpb_tl }
865 \clist_map_break:
866 }
867 {
868 \str_if_eq:nnT {##1} { s }
869 {
870 \str_if_eq:nnTF {#1} { \thefootnote }
871 { \str_set:Nn \l_tmpa_str { \thedownfootnote } }
872 { \str_set:Nn \l_tmpa_str { \theupfootnote } }
873 \msg_warning:nnnV { easybase } { unknown-fnt-type } {#2} \l_tmpa_str
874 }
875 }
876 }
877 \cs_set_eq:NN \thedownfootnote \thefootnote
878 }
879 \msg_new:nnn { easybase } { unknown-fnt-type }
880 {
881 The~'#1'~includes~unknown~footnote~numbering~type \\
882 in~#2.
883 }
884 \cs_new_protected:Npn \eb_footnote_value_handle:n #1
885 {
886 \str_case:nnF {#1}
887 {
888 { bottom }
889 { \PushFntBottom }
890 { flush }
891 {
892 \tl_set:Nn \l__eb_footnote_value_tl { plain }
893 \clist_push:Nn \l__eb_footnote_value_clist {#1}
894 }
895 }
896 {
897 \bool_lazy_or:nnT
898 { \str_if_eq_p:nn {#1} { hang } }
899 { \str_if_eq_p:nn {#1} { plain } }
900 { \tl_set:Nn \l__eb_footnote_value_tl {#1} }
901 }
902 }
903 \cs_new_protected:Npn \eb_fnnormal_move_set:nnn #1#2#3
904 {
905 \str_if_eq:nnTF {#1} { match }
906 {
907 \tl_set:cv { l__eb_fn#2_#3move_tl }
908 { l__spb_super_#3move_tl }
909 }
910 { \tl_set:cn { l__eb_fn#2_#3move_tl } {#1} }
911 }
912 \cs_new_protected:Npn \eb_fnboth_format_set:nn #1#2
913 {
914 \str_if_eq:nnTF {#1} { match }
915 { \bool_set_true:c { l__eb_fn#2_format_match_bool } }
916 {
917 \bool_set_false:c { l__eb_fn#2_format_match_bool }
918 \tl_set:cn { l__eb_fn#2_format_tl } {#1}
919 }
920 }
921
922 \tl_new:N \l__eb_fnnormal_format_tl
923 \tl_new:N \l__eb_fncustom_format_tl
924 \clist_new:N \l__eb_footnote_value_clist
925 \ctex_define:nn { hdr }
926 {
927 fnfirstindent .tl_set:N = \fnfirstindent,
928 fnfirstindent .initial:n = 1em,
929 fnafterindent .tl_set:N = \fnafterindent,
930 fnafterindent .initial:n = 2em,
931 fnparskip .tl_set:N = \fnparskip,
932 fnparskip .initial:n = 0ex plus .1ex,
933 footnotesep .dim_set:N = \footnotesep,
934 fnpara-format .tl_set:N = \l__eb_fnpara_format_tl,
935 fntext-pos .tl_set:N = \l__eb_fntext_position_tl,
936 fntext-pos .initial:n = super,
937 fntext-code .code:n = \eb_assign_fntext_code:n {#1},
938 fntext-code .initial:n = { ,\tl_if_eq:NnF \l__eb_fntext_position_tl { super } { ~ } },
939 fnnormal-format .code:n = \eb_fnboth_format_set:nn {#1} { normal },
940 fncustom-format .code:n = \eb_fnboth_format_set:nn {#1} { custom },
941 fnmarktext-format .meta:n = { fnnormal-format = {#1} },
942 fnboth-format .meta:n = { fnnormal-format = {#1},fncustom-format = {#1} },
943 footnotetype .multichoices:nn =
944 { plain,hang,bottom,para,flush }
945 { \eb_footnote_value_handle:n {#1} },
946 footnotetype .value_required:n = true,
947 footnotetype/default .meta:n = { footnotetype = plain },
948 footnotetype .initial:n = hang,
949 fnmark-vmove .code:n = \eb_fnnormal_move_set:nnn {#1} { mark } { v },
950 fnmark-hmove .code:n = \eb_fnnormal_move_set:nnn {#1} { mark } { h },
951 fntext-vmove .code:n = \eb_fnnormal_move_set:nnn {#1} { text } { v },
952 fnmark-vmove .initial:n = 0pt,
953 fnmark-hmove .initial:n = 0pt,
954 fntext-vmove .initial:n = 0pt,
955 fnmark-num .choices:nn =
956 { plain,pifont,pifont*,pifont-sans,pifont-sans* }
957 { \eb_fnnormal_normal_label_set:Nn \theupfootnote {#1} },
958 fnmark-num .value_required:n = true,
959 fnmark-num/unknown .code:n = \eb_fnnormal_short_label_set:Nn \theupfootnote {#1},
960 fntext-num .choices:nn =
961 { plain,pifont,pifont*,pifont-sans,pifont-sans* }
962 { \eb_fnnormal_normal_label_set:Nn \thefootnote {#1} },
963 fntext-num .value_required:n = true,
964 fntext-num/unknown .code:n = \eb_fnnormal_short_label_set:Nn \thefootnote {#1},
965 fnnormal-num .meta:n = { fntext-num = {#1},fnmark-num = {#1} },
966 fnnormal-num .initial:n = plain,
967 fnmarktext-num .meta:n = { fnnormal-num = {#1} },
968 unknown .code:n = \eb_msg_deprecated_option:n { hdr }
969 }
970
971 \ctex_before_end_preamble:n
972 {
973 \bool_if:NT \l__eb_chap_counter_withpart_bool
974 { \counterwithin*{chapter}{part} }
975 \str_case:VnT \l__eb_fnt_parent_counter_tl
976 {
977 { part } { \counterwithin*{footnote}{part} }
978 { page }
979 {
980 \RequirePackage{zref-perpage}
981 \zmakeperpage{footnote}
982 }
983 }
984 { \counterwithout*{footnote}{chapter} }
985 }
986 \IfFormatAtLeastTF{2025/06/01}
987 {
988 \cs_new_protected:Npn \PushFntBottom
989 {
990 \AssignSocketPlug{build/column/outputbox}
991 {floats-space-footnotes}
992 }
993 }
994 {
995 \cs_new_protected:Npn \PushFntBottom
996 { \msg_warning:nn { easybase } { fnt-bottom-old } }
997 }
998 \msg_new:nnn { easybase } { fnt-bottom-old }
999 {
1000 The~\string\PushFntBottom\ command~is~outdated. \\
1001 Please~update~the~LaTeX2e~format~to~after~2025/06/01.
1002 }
1003 \cs_new_protected:Npn \eb_footnote_direct_hang:
1004 {
1005 \hbox_set:Nn \l_tmpa_box
1006 {
1007 \dim_compare:nNnTF { \fnfirstindent } > { 0pt }
1008 { \hbox_to_wd:nn { \fnfirstindent } { \eb@makefnmark\hss } }
1009 { \eb@makefnmark }
1010 }
1011 \dim_set:Nn \leftmargin { \box_wd:N \l_tmpa_box }
1012 \dim_zero:N \rightmargin
1013 \dim_set_eq:NN \linewidth \columnwidth
1014 \dim_sub:Nn \linewidth { \leftmargin }
1015 \parshape\@ne\leftmargin\linewidth
1016 \@setpar{{\@@par}}
1017 \mode_leave_vertical:
1018 \hbox_overlap_left:n { \box_use:N \l_tmpa_box }
1019 }
1020 \cs_new_protected:Npn \eb_footnote_direct_plain:
1021 {
1022 \noindent
1023 \clist_if_in:NnT \l__eb_footnote_value_clist { flush }
1024 { \tl_set:Nn \fnfirstindent { 0pt } }
1025 \int_case:nn { \dim_sign:V \fnfirstindent }
1026 {
1027 { 1 } { \use_i:nnn }
1028 { 0 } { \use_ii:nnn }
1029 { -1 } { \use_iii:nnn }
1030 }
1031 { \hbox_to_wd:nn { \fnfirstindent } { \hss\eb@makefnmark } }
1032 { \hbox_overlap_left:n { \eb@makefnmark } }
1033 {
1034 \hbox_overlap_left:n
1035 {
1036 \hbox_to_wd:nn { -\fnfirstindent }
1037 { \eb@makefnmark\hss }
1038 }
1039 }
1040 }
1041 \cs_new_protected:Npn \deffntpara #1
1042 { \cs_set:Npn \@makefntext ##1 {#1} }
1043 \deffntpara
1044 {
1045 \str_case:Vn \l__eb_footnote_value_tl
1046 {
1047 { hang } { \use_i:nn }
1048 { plain } { \use_ii:nn }
1049 }
1050 { \eb_footnote_direct_hang: }
1051 { \eb_footnote_direct_plain: }
1052 \skip_set:NV \parskip \fnparskip
1053 \dim_set:NV \parindent \fnafterindent
1054 \l__eb_fnpara_format_tl{#1}
1055 \tl_if_eq:NnT \l__eb_footnote_value_tl { hang } { \par }
1056 }
1057 \clist_map_inline:nn { \@footnotetext,\@mpfootnotetext }
1058 {
1059 \eb_patch_cmd:Nnn #1
1060 { \reset@font }
1061 {
1062 \usestretch{\eb@spread@footnote}
1063 \eb@font@footnote
1064 }
1065 }
1066 \cs_set_eq:NN \eb@@makefntext \@makefntext
1067 \cs_set_eq:NN \eb@@footnotetext \@footnotetext
1068 \cs_set_eq:NN \eb@@mpfootnotetext \@mpfootnotetext
1069 \ctex_at_end_package:nn { footmisc }
1070 {
1071 \eb_package_date_check:nn { footmisc } { 2022/02/10 }
1072 \ifboolexpr{not (bool {FN@para} or bool {FN@sidefn})}
1073 {
1074 \boolfalse{FN@setspace}
1075 \cs_set_eq:NN \@makefntext \eb@@makefntext
1076 \cs_set_eq:NN \@footnotetext \eb@@footnotetext
1077 }{}
1078 \ifboolexpr
1079 {
1080 bool {FN@hangfoot} or
1081 bool {FN@perpage} or
1082 bool {FN@robust}
1083 }
1084 {\msg_warning:nn { easybase } { footmisc }}{}
1085 }
1086 \msg_new:nnn { easybase } { footmisc }
1087 {
1088 It~is~not~recommended~that~you~use~the \\
1089 hang,~symbol,~perpage,~marginal~or~flushmargin \\
1090 options~of~'footmisc'~package.
1091 }
1092 \ctex_at_end_package:nn { setspace }
1093 {
1094 \cs_set_eq:NN \@footnotetext \eb@@footnotetext
1095 \cs_set_eq:NN \@mpfootnotetext \eb@@mpfootnotetext
1096 }
1097 \cs_set_protected:Npn \footref #1
1098 {
1099 \group_begin:
1100 \unrestored@protected@xdef\@thefnmark{\ref{#1}}
1101 \unrestored@protected@xdef\@the@up@fnmark{\ref{#1}}
1102 \group_end:
1103 \H@@footnotemark
1104 }
1105 \cs_set:Npn \@xfootnote [#1]
1106 {
1107 \group_begin:
1108 \int_set:cn { c@\@mpfn } {#1}
1109 \unrestored@protected@xdef\@thefnmark{\thempfn}
1110 \unrestored@protected@xdef\@the@up@fnmark{\theupfootnote}
1111 \group_end:
1112 \@footnotemark
1113 \@footnotetext
1114 }
1115 \cs_new_protected:Npn \eb_set_current_label:n #1
1116 {
1117 \protected@edef\@currentlabel
1118 {
1119 \exp_args:Nnv
1120 \use:c { p@#1 } { the#1 }
1121 }
1122 }
1123 \cs_set_protected:Npn \footnote
1124 {
1125 \peek_meaning:NTF [
1126 { \@xfootnote }
1127 {
1128 \exp_args:NV \stepcounter \@mpfn
1129 \eb_set_current_label:n { upfootnote }
1130 \protected@xdef\@thefnmark{\thempfn}
1131 \protected@xdef\@the@up@fnmark{\theupfootnote}
1132 \@footnotemark
1133 \@footnotetext
1134 }
1135 }
1136 \cs_set:Npn \footnotemark
1137 {
1138 \peek_meaning:NTF [
1139 { \@xfootnotemark }
1140 {
1141 \stepcounter{footnote}
1142 \protected@xdef\@thefnmark{\thefootnote}
1143 \protected@xdef\@the@up@fnmark{\theupfootnote}
1144 \@footnotemark
1145 }
1146 }
1147 \ctex_at_end_package:nn { hyperref }
1148 {
1149 \cs_set:Npn \@xfootnotemark [#1]
1150 {
1151 \group_begin:
1152 \int_set:Nn \c@footnote {#1}
1153 \protected@xdef\@thefnmark{\thefootnote}
1154 \unrestored@protected@xdef\@the@up@fnmark{\theupfootnote}
1155 \group_end:
1156 \H@@footnotemark
1157 }
1158 }
1159
1160 \ProvideDocumentCommand{\super}{mo}{\textsuperscript{#1}}
1161 \providecommand{\spbset}{\use_none:n}
1162 \NewDocumentCommand{\eb@fnnormal@super}{sm}
1163 {
1164 \IfBooleanTF{#1}
1165 {\super{#2}[vmove = \l__eb_fntext_vmove_tl,nohmove]}
1166 {
1167 \super{\l__eb_fnnormal_format_tl{#2}}[
1168 vmove = \l__eb_fnmark_vmove_tl,
1169 hmove = \l__eb_fnmark_hmove_tl
1170 ]
1171 }
1172 }
1173 \bool_set_true:N \l__eb_normal_footnote_bool
1174 \bool_new:N \l__eb_fnnormal_format_match_bool
1175 \bool_new:N \l__eb_fncustom_format_match_bool
1176 \cs_new_protected:Npn \ifnormalfnt #1#2
1177 { \bool_if:NTF \l__eb_normal_footnote_bool {#1} {#2} }
1178 \cs_new:Npn \eb_fnnormal_format_clear:n #1
1179 {
1180 \bool_if:cTF { l__eb_fn#1_format_match_bool }
1181 { \tl_clear:N \l__eb_fnnormal_format_tl }
1182 { \spbset{spcmd = { }} }
1183 }
1184 \cs_new_protected:Npn \eb_fnnormal_format_initial:
1185 {
1186 \bool_if:NTF \l__eb_normal_footnote_bool
1187 { \eb_fnnormal_format_clear:n { normal } }
1188 { \eb_fnnormal_format_clear:n { custom } }
1189 \eb@font@footnote
1190 }
1191 \cs_new_protected:Npn \defupfntmark #1
1192 { \cs_set:Npn \@makefnmark { \hbox:n {#1} } }
1193 \cs_new_protected:Npn \defdownfntmark #1
1194 { \cs_set:Npn \eb@makefnmark { \hbox:n {#1} } }
1195 \cs_new_protected:Npn \notminipage
1196 { \tl_if_eq:NnTF \@mpfn { footnote } }
1197 \defupfntmark
1198 {
1199 \eb_fnnormal_format_initial:
1200 \eb@fnnormal@super{\notminipage{\@the@up@fnmark}{\@thefnmark}}
1201 }
1202 \defdownfntmark
1203 {
1204 \eb_fnnormal_format_initial:
1205 \tl_if_eq:NnTF \l__eb_fntext_position_tl { super }
1206 { \eb@fnnormal@super* }
1207 { \use:n }
1208 {
1209 \tl_use:N \l__eb_fntext_before_tl
1210 { \l__eb_fnnormal_format_tl{\@thefnmark} }
1211 }
1212 \tl_use:N \l__eb_fntext_after_tl
1213 }
1214
1215 \tl_clear_new:N \@thefnmark
1216 \tl_new:N \@the@up@fnmark
1217 \cs_new:Npn \eb@@makefnmark #1#2
1218 {
1219 \tl_if_empty:oF {#2}
1220 {
1221 \group_begin:
1222 \unrestored@protected@xdef\@thefnmark{#2}
1223 \unrestored@protected@xdef\@the@up@fnmark{#1}
1224 \group_end:
1225 }
1226 }
1227 \cs_new_protected:Npn \eb_fncustom_format_initial:
1228 {
1229 \bool_set_false:N \l__eb_normal_footnote_bool
1230 \bool_if:NF \l__eb_fncustom_format_match_bool
1231 {
1232 \tl_set_eq:NN
1233 \l__eb_fnnormal_format_tl \l__eb_fncustom_format_tl
1234 }
1235 }
1236 \NewDocumentCommand{\Footnote}{O{#2}m+m}
1237 {
1238 \group_begin:
1239 \eb_fncustom_format_initial:
1240 \eb@@makefnmark{#2}{#1}
1241 \@footnotemark
1242 \@footnotetext{#3}
1243 \group_end:
1244 }
1245 \cs_new_protected:Npn \Footnotemark #1
1246 {
1247 \group_begin:
1248 \eb_fncustom_format_initial:
1249 \eb@@makefnmark{#1}{#1}\@footnotemark
1250 \group_end:
1251 }
1252 \cs_new_protected:Npn \Footnotetext #1#2
1253 {
1254 \group_begin:
1255 \eb_fncustom_format_initial:
1256 \eb@@makefnmark{#1}{#1}\@footnotetext{#2}
1257 \group_end:
1258 }
1259
1260 \newcounter{bichapter}
1261 \newcounter{bisection}[bichapter]
1262 \newcounter{bisubsection}[bisection]
1263 \NewDocumentCommand{\counteruse}{sO{}D(){}mo}
1264 {
1265 \use:c { the#4 }
1266 \msg_warning:nnn { easybase } { counteruse } {#4}
1267 }
1268 \msg_new:nnn { easybase } { counteruse }
1269 {
1270 The~command~\string\counteruse{#1}\ is~deprecated. \\
1271 Please~use~the~\string\the#1\ command.
1272 }
1273 \RenewDocumentCommand{\counterwithin}{sO{\arabic}mO{.}m}
1274 {
1275 \@ifbothcounters{#3}{#5}
1276 {
1277 \@addtoreset{#3}{#5}
1278 \IfBooleanF{#1}
1279 {
1280 \cs_gset:cpn { the#3 }
1281 { \use:c { the#5 }#4#2{#3} }
1282 }
1283 }
1284 }
1285 \cs_new_protected:Npn \undefinecounter #1
1286 {
1287 \cs_undefine:c { c@#1 }
1288 \cs_undefine:c { the#1 }
1289 \group_begin:
1290 \exp_args:Nc \providecommand { c@@ckpt }{}
1291 \@removefromreset{#1}{@ckpt}
1292 \group_end:
1293 }
1294 \ProvideDocumentCommand{\declarecounter}{mo}
1295 {
1296 \undefinecounter{#1}
1297 \IfValueTF{#2}{\newcounter{#1}[#2]}{\newcounter{#1}}
1298 }
1299 \ProvideDocumentCommand{\renewcounter}{mo}
1300 {
1301 \cs_if_exist:cTF { c@#1 }
1302 { \IfValueTF{#2}{\declarecounter{#1}[#2]}{\declarecounter{#1}} }
1303 { \exp_args:Nc \renewcommand { c@#1 }{} }
1304 }
1305 \ProvideDocumentCommand{\providecounter}{mo}
1306 {
1307 \cs_if_exist:cF { c@#1 }
1308 { \IfValueTF{#2}{\newcounter{#1}[#2]}{\newcounter{#1}} }
1309 }
1310 \cs_new:Npn \eb_section_counter_prefix:n #1
1311 {
1312 \int_compare:nNnT { \c@chapter } > { 0 } { \use:c { the#1chapter }. }
1313 \int_to_arabic:v { c@#1section }
1314 }
1315 \cs_set:Npn \thebichapter { \@arabic\c@bichapter }
1316 \cs_set:Npn \thebisection { \eb_section_counter_prefix:n { bi } }
1317 \cs_set:Npn \thebisubsection { \thebisection.\@arabic\c@bisubsection }
1318 \cs_set:Npn \thesection { \eb_section_counter_prefix:n { } }
1319 \NewHook{eb/addbitocline/begin}
1320 \DeclareHookRule{eb/addbitocline/begin}{chapter}{<}{code}
1321 \NewDocumentCommand{\BeforeAddtoBitoc}{sm}
1322 {
1323 \IfBooleanT{#1}{\RemoveFromHook{eb/addbitocline/begin}[code]}
1324 \AddToHook{eb/addbitocline/begin}[code]{#2}
1325 }
1326 \cs_set_eq:NN \BeforeAddBitoc \BeforeAddtoBitoc
1327 \cs_new_protected:Npn \CTEX@addbitocline #1#2
1328 {
1329 \group_begin:
1330 \def\CTEX@prechapter{\CTEX@prebichapter}
1331 \def\CTEX@thechapter{\CTEX@bichapter@number}
1332 \def\CTEX@postchapter{\CTEX@postbichapter}
1333 \UseHook{eb/addbitocline/begin}
1334 \tl_if_eq:NnTF \g__eb_bilist_permute_value_tl { mix }
1335 { \addcontentsline{toc}{#1} }
1336 { \addcontentsline{tec}{#1} }
1337 { \use:c { CTEX@#1@tocline }{#1}{#2} }
1338 \group_end:
1339 }
1340 \cs_new_protected:Npn \eb@register@bititle #1
1341 {
1342 \providecounter{bi#1}
1343 \exp_args:Nc \DeclareDocumentCommand { bi#1 }{sO{##3}mm}
1344 {
1345 \IfBooleanTF{##1}
1346 {
1347 \use:c {#1}*{##3}
1348 \CTEX@addtocline{#1}{##2}
1349 \tl_if_empty:oF {##4} { \CTEX@addbitocline{#1}{##4} }
1350 \use:c { #1mark }{##2}
1351 }{
1352 \stepcounter{bi#1}
1353 \use:c {#1}[##2]{##3}
1354 \tl_if_empty:oF {##4} { \CTEX@addbitocline{#1}{##4} }
1355 }
1356 }
1357 }
1358 \cs_new_protected:Npn \RegisterBititle #1
1359 {
1360 \clist_map_function:nN {#1}
1361 \eb@register@bititle
1362 }
1363 \RegisterBititle{chapter,section,subsection}
1364 \eb_preto_cmd:nn { @chapter }
1365 {
1366 \skip_if_eq:nnF { \eb@toc@lol@skip } { \c_zero_skip }
1367 { \addtocontents{lol}{\protect\addvspace{\skip_use:N \eb@toc@lol@skip}} }
1368 }
1369 \cs_new_protected:Npn \CopyTitleFormat #1#2
1370 {
1371 \tl_set_eq:cc { CTEX@#1@beforeskip } { CTEX@#2@beforeskip }
1372 \tl_set_eq:cc { CTEX@#1@afterskip } { CTEX@#2@afterskip }
1373 \bool_set_eq:cc { CTEX@#1@numbering } { CTEX@#2@numbering }
1374 \bool_set_eq:cc { CTEX@#1@fixskip } { CTEX@#2@fixskip }
1375 \bool_set_eq:cc { CTEX@#1@hang } { CTEX@#2@hang }
1376 \bool_set_eq:cc { CTEX@#1@runin } { CTEX@#2@runin }
1377 \cs_set_eq:cc { CTEX@#1@tocline } { CTEX@#2@tocline }
1378 \tl_set_eq:cc { CTEX@#1@break } { CTEX@#2@break }
1379 \tl_set_eq:cc { CTEX@#1@format } { CTEX@#2@format }
1380 \tl_set_eq:cc { CTEX@#1@nameformat } { CTEX@#2@nameformat }
1381 \tl_set_eq:cc { CTEX@#1@numberformat } { CTEX@#2@numberformat }
1382 \tl_set_eq:cc { CTEX@#1@titleformat } { CTEX@#2@titleformat }
1383 \tl_set_eq:cc { CTEX@#1@aftername } { CTEX@#2@aftername }
1384 \tl_set_eq:cc { CTEX@#1@aftertitle } { CTEX@#2@aftertitle }
1385 }
1386 \NewDocumentCommand{\NewTitleCommand}{omm}
1387 {
1388 \newcounter{#2}
1389 \cs_set_eq:cN { #2mark } \use_none:n
1390 \tl_clear:N \l__ctex_tmp_tl
1391 \__ctex_initial_heading:n {#2}
1392 \__ctex_def_heading_keys:n {#2}
1393 \exp_args:No \ctex_define:n { \l__ctex_tmp_tl }
1394 \cs_gset_protected:cpx {#2}
1395 {
1396 \exp_not:N \@startsection{#2}{#3}
1397 {\exp_not:c { CTEX@#2@indent }}
1398 {\exp_not:c { CTEX@#2@beforeskip }}
1399 {\exp_not:c { CTEX@#2@afterskip }}
1400 {\exp_not:N \normalfont\exp_not:c { CTEX@#2@format }}
1401 }
1402 \cs_new:cpn { CTEX@#2@tocline } ##1##2
1403 { \CTEXnumberline{##1}##2 }
1404 \exp_args:Nc \providecommand { ttll@#2 }{#3}
1405 \exp_args:Nc \providecommand { toclevel@#2 }{#3}
1406 \IfValueT{#1}{\CopyTitleFormat{#2}{#1}}
1407 }
1408 \NewDocumentCommand{\NewTitleEntryCommand}{O{toc}m}
1409 {
1410 \cs_new_protected:cpn { #2entry } ##1
1411 {
1412 \bool_if:cTF { CTEX@#2@numbering }
1413 { \CTEX@ifnametrue }
1414 { \CTEX@ifnamefalse }
1415 \CTEX@makeanchor{#2*}
1416 \addcontentsline{#1}{#2}{\use:c { CTEX@#2@tocline }{#2}{##1}}
1417 }
1418 }
1419
1420 \ctex_define:nn { tools }
1421 {
1422 hyphen-figure .tl_set:N = \l__eb_hyphen_figure_tl,
1423 hyphen-table .tl_set:N = \l__eb_hyphen_table_tl,
1424 hyphen-lstlisting .tl_set:N = \l__eb_hyphen_lstlisting_tl,
1425 hyphen-equation .tl_set:N = \l__eb_hyphen_equation_tl,
1426 hyphen-every .meta:n =
1427 {
1428 hyphen-figure = {#1},hyphen-table = {#1},
1429 hyphen-lstlisting = {#1},hyphen-equation = {#1}
1430 },
1431 hyphen-every .initial:n = .,
1432 unknown .code:n = \eb_msg_deprecated_option:n { tools }
1433 }
1434 \AtBeginDocument
1435 {
1436 \clist_map_inline:nn
1437 { figure,table,lstlisting,equation }
1438 {
1439 \cs_set:cpn { the#1 }
1440 {
1441 \int_compare:nNnT { \c@chapter } > { 0 }
1442 {
1443 \thechapter
1444 \tl_use:c { l__eb_hyphen_#1_tl }
1445 }
1446 \int_to_arabic:v { c@#1 }
1447 }
1448 }
1449 }
1450
1451 \NewDocumentCommand{\SetTocOuter}{om}
1452 {
1453 \IfNoValueTF{#1}
1454 {\keys_set:nn { eb/tocouter } {#2}}
1455 {
1456 \clist_if_exist:cF { l__eb_toc_outer_kv_#1_clist }
1457 { \clist_clear_new:c { l__eb_toc_outer_kv_#1_clist } }
1458 \clist_put_right:cn { l__eb_toc_outer_kv_#1_clist } {#2}
1459 }
1460 }
1461 \tl_new:N \eb@bitoc@title
1462 \bool_new:N \l__eb_toc_notitle_bool
1463 \newbool{@bitoc}
1464 \cs_new:Npn \ebifbitoc { \ifbool{@bitoc} }
1465 \seq_new:N \l__eb_level_tmpa_seq
1466 \tl_new:N \l__eb_level_tmpa_tl
1467 \tl_gset:Nn \g__eb_bilist_permute_value_tl { new }
1468 \cs_generate_variant:Nn \regex_extract_all:nnN { no }
1469 \cs_generate_variant:Nn \keys_define:nn { nx }
1470 \cs_generate_variant:Nn \ctex_set:nn { ox }
1471 \cs_new_protected:Npn \eb_toc_extract_level:
1472 {
1473 \regex_extract_all:noN { \cC. } { \eb@toc@title@level }
1474 \l__eb_level_tmpa_seq
1475 \seq_get_right:NN \l__eb_level_tmpa_seq \l__eb_level_tmpa_tl
1476 \tl_set:Nx \l__eb_level_tmpa_tl
1477 {
1478 \exp_last_unbraced:No
1479 \cs_to_str:N { \l__eb_level_tmpa_tl }
1480 }
1481 \regex_replace_case_once:nN
1482 {
1483 { ^bi(.*) } { \1 }
1484 { .* } { \0 }
1485 }
1486 \l__eb_level_tmpa_tl
1487 }
1488 \keys_define:nn { eb/tocouter }
1489 {
1490 level .code:n =
1491 {
1492 \tl_set:Nn \eb@toc@title@level {#1}
1493 \eb_toc_extract_level:
1494 },
1495 level .initial:x =
1496 {
1497 \bool_if:NTF \l__eb_class_mode_book_bool
1498 { \exp_not:N \bichapter* }
1499 { \exp_not:N \bisection* }
1500 },
1501 section .meta:n = { level = \bisection* },
1502 chapter .meta:n = { level = \bichapter* },
1503 none .code:n =
1504 {
1505 \tl_set:Nn \eb@toc@title@level
1506 { \par\use_none:nn }
1507 \bool_set_true:N \l__eb_toc_notitle_bool
1508 },
1509 multoc .int_set:N = \l__eb_toc_columns_int,
1510 multoc .default:n = 2,
1511 multoc .initial:n = 1,
1512 columns .meta:n = { multoc = {#1} },
1513 plan .choice:,
1514 plan .value_required:n = true,
1515 plan/cn .code:n =
1516 {
1517 \bool_set_true:N \l__eb_toc_plan_cn_bool
1518 \bool_set_false:N \l__eb_toc_plan_bi_bool
1519 },
1520 plan/bi .code:n =
1521 {
1522 \bool_set_false:N \l__eb_toc_plan_cn_bool
1523 \bool_set_true:N \l__eb_toc_plan_bi_bool
1524 },
1525 plan/both .code:n =
1526 {
1527 \bool_set_true:N \l__eb_toc_plan_cn_bool
1528 \bool_set_true:N \l__eb_toc_plan_bi_bool
1529 },
1530 plan .initial:n = cn,
1531 title .code:n = \eb_assign_toc_title:n {#1},
1532 bilist .code:n =
1533 {
1534 \str_if_eq:nnTF {#1} { mix }
1535 {
1536 \tl_if_eq:NnF \g__eb_bilist_permute_value_tl { mix }
1537 {
1538 \tl_gset:Nn \g__eb_bilist_permute_value_tl {#1}
1539 \AddToHook{cmd/CTEX@addtocline/before}[bitoc]
1540 {\addtocontents{toc}{\boolfalse{@bitoc}}}
1541 \AddToHook{cmd/CTEX@addbitocline/before}[bitoc]
1542 {\addtocontents{toc}{\booltrue{@bitoc}}}
1543 }
1544 }
1545 {
1546 \tl_if_eq:NnT \g__eb_bilist_permute_value_tl { mix }
1547 {
1548 \RemoveFromHook{cmd/CTEX@addtocline/before}[bitoc]
1549 \RemoveFromHook{cmd/CTEX@addbitocline/before}[bitoc]
1550 }
1551 \tl_gset:Nn \g__eb_bilist_permute_value_tl {#1}
1552 }
1553 },
1554 name .tl_set:N = \eb@index@name,
1555 name .initial:n = \indtl@jobname,
1556 unknown .code:n =
1557 {
1558 \ctex_set:ox { \l__eb_level_tmpa_tl }
1559 { \eb_unknown_kv_handle: }
1560 },
1561 unknown .default:V = \c_novalue_tl
1562 }
1563
1564 \NewDocumentCommand{\eb_assign_toc_title:n}
1565 {>{\SplitArgument{1}{,}}m}
1566 {\eb_toc_assign_title_judge:nn #1}
1567 \cs_new_protected:Npn \eb_toc_assign_title_judge:nn #1#2
1568 {
1569 \tl_set:Nn \eb@toc@title {#1}
1570 \tl_if_novalue:nF {#2} { \tl_set:Nn \eb@bitoc@title {#2} }
1571 }
1572 \cs_new_protected:Npn \eb_toc_start_multi_column_ext:n #1
1573 {
1574 \int_compare:nNnTF { \l__eb_toc_columns_int } > { 1 }
1575 {
1576 \begin{multicols}{\int_use:N \l__eb_toc_columns_int}
1577 \@starttoc{#1}
1578 \end{multicols}
1579 }
1580 { \@starttoc{#1} }
1581 }
1582 \cs_new_protected:Npn \eb_toc_if_title_between_hook:nn #1#2
1583 {
1584 \IfBooleanF{#1}
1585 {
1586 \tl_if_exist:NT \eb@toc@title
1587 {
1588 \bool_if:NF \l__eb_toc_notitle_bool
1589 { \tl_use:c { l__eb_toc_#2_between_hook_tl } }
1590 }
1591 }
1592 }
1593 \cs_new_protected:Npn \eb_toc_title_level_cmd:n #1
1594 {
1595 \IfBooleanTF{#1}
1596 {\par}
1597 {
1598 \tl_if_exist:NTF \eb@toc@title
1599 { \eb@toc@title@level{\eb@toc@title}{\eb@bitoc@title} }
1600 { \par }
1601 }
1602 }
1603 \cs_generate_variant:Nn \keys_set:nn { nv }
1604 \cs_new_protected:Npn \eb_toc_outer_kv_initial:n #1
1605 {
1606 \clist_if_exist:cT { l__eb_toc_outer_kv_#1_clist }
1607 { \keys_set:nv { eb/tocouter } { l__eb_toc_outer_kv_#1_clist } }
1608 }
1609 \cs_new_protected:Npn \eb_toc_kv_set:nn #1#2
1610 {
1611 \eb_toc_outer_kv_initial:n {#1}
1612 \IfValueT{#2}{\keys_set:nn { eb/tocouter } {#2}}
1613 }
1614 \cs_new_protected:Npn \eb_toc_list_struct_parse:nnnnn #1#2#3#4#5
1615 {
1616 \group_begin:
1617 \tl_set_eq:Nc \eb@toc@title { list#4name }
1618 \eb_toc_kv_set:nn {#5} {#3}
1619 \eb_toc_title_level_cmd:n {#1}
1620 \eb_toc_if_title_between_hook:nn {#1} {#4}
1621 \eb_toc_start_multi_column_ext:n {#5}
1622 \group_end:
1623 }
1624 \cs_new:Npn \listnumberline #1
1625 {
1626 \capifname
1627 {
1628 \protect\numberline
1629 {
1630 \exp_args:Nnv
1631 \use:c { p@#1 } { the#1 }
1632 }
1633 }{}
1634 }
1635 \cs_generate_variant:Nn \tl_if_blank:nTF { f }
1636 \cs_new:Npn \capifname #1#2
1637 { \tl_if_blank:fTF { \caption@labelformat{p1}{p2} } {#2} {#1} }
1638 \cs_new_protected:Npn \DeclareFloatList #1#2
1639 {
1640 \exp_args:Nc \DeclareDocumentCommand { listof#1s }{st++o}
1641 {\eb_toc_list_struct_parse:nnnnn {##1} {##2} {##3} {#1} {#2}}
1642 \ctex_define:n
1643 {
1644 #1 .meta:nn = { ctex/#1 } {##1},
1645 #1/between .tl_set:c = l__eb_toc_#1_between_hook_tl,
1646 #1/between .initial:n = \bool_if:NT \l__eb_class_mode_book_bool { \vspace*{-10pt} },
1647 #1/tocline .cs_set:cp = { eb@tocline@#1 } ##1##2,
1648 #1/tocline .initial:n = \listnumberline{##1}##2
1649 }
1650 }
1651 \DeclareFloatList{table}{lot}
1652 \DeclareFloatList{figure}{lof}
1653 \DeclareFloatList{lstlisting}{lol}
1654 \cs_gset:Npn \caption@@@addcontentsline #1#2#3#4
1655 {
1656 \addcontentsline{#1}{#2}
1657 {
1658 \cs_if_exist_use:cTF { eb@tocline@#2 }
1659 { {#2}{#4} }
1660 { \protect\numberline{#3}{#4} }
1661 }
1662 }
1663 \cs_new_protected:Npn \AssignCaptionExt #1#2
1664 {
1665 \clist_map_inline:nn {#1}
1666 { \eb@assign@caption@ext{##1}{#2} }
1667 }
1668 \cs_new_protected:Npn \eb@assign@caption@ext #1#2
1669 { \tl_set:cn { ext@#1 } {#2} }
1670 \cs_set_eq:NN \AllotCaptionExt \AssignCaptionExt
1671 \ctex_define:n
1672 {
1673 bicontentsname .tl_set:N = \bicontentsname,
1674 bicontentsname .initial:n = Contents
1675 }
1676 \RenewDocumentCommand{\tableofcontents}{st++o+D(){}}
1677 {
1678 \group_begin:
1679 \tl_set_eq:NN \eb@toc@title \contentsname
1680 \tl_set_eq:NN \eb@bitoc@title \bicontentsname
1681 \bool_if:NF \l__eb_toc_notitle_bool
1682 {
1683 \tl_set:Nn \eb@toc@title@level
1684 {
1685 \bool_if:NTF \l__eb_class_mode_book_bool
1686 { \chapter* }
1687 { \section* }
1688 }
1689 }
1690 \bool_if:NT \l__eb_toc_plan_cn_bool
1691 {
1692 \eb_toc_kv_set:nn { toc } {#3}
1693 \IfBooleanF{#1}{\eb@toc@title@level{\eb@toc@title}{}}
1694 \eb_toc_if_title_between_hook:nn {#1} { title }
1695 \eb_toc_start_multi_column_ext:n { toc }
1696 }
1697 \bool_if:NT \l__eb_toc_plan_bi_bool
1698 {
1699 \tl_if_eq:NnF \g__eb_bilist_permute_value_tl { mix }
1700 {
1701 \eb_toc_kv_set:nn { tec } {#3}#4
1702 \IfBooleanF{#1}{\eb@toc@title@level{\eb@bitoc@title}{}}
1703 \eb_toc_if_title_between_hook:nn {#1} { bititle }
1704 \eb_toc_start_multi_column_ext:n { tec }
1705 }
1706 }
1707 \group_end:
1708 }
1709
1710 \RenewDocumentCommand{\contentsuse}{O{-1000}mm}
1711 {
1712 \clist_map_inline:nn {#2}
1713 { \eb@contents@use{#1}{##1}{#3} }
1714 }
1715 \cs_new_protected:Npn \eb@contents@use #1#2#3
1716 {
1717 \tl_set:cn { ttlx@#2 } {#3}
1718 \tl_set:cn { ttll@#2 } {#1}
1719 \tl_if_exist:cF { l__eb_contents_use_#2_#3_tl }
1720 {
1721 \tl_put_right:Nn \ttl@finishall
1722 { \@writefile{#3}{\contentsfinish} }
1723 }
1724 \tl_set:cn { l__eb_contents_use_#2_#3_tl } { used }
1725 }
1726 \contentsuse{lstlisting}{lol}
1727 \ctex_at_end_package:nn { hyperref }
1728 {
1729 \cs_if_exist:NTF \Hy@toclinkstart
1730 { \cs_set:Npn \hytoclink #1 { \Hy@toclinkstart #1\Hy@toclinkend } }
1731 { \cs_set_eq:NN \hytoclink \use:n }
1732 }
1733 \seq_put_left:Nn \c__ctex_headings_seq { chapter }
1734 \seq_put_right:Nn \c__ctex_headings_seq { table }
1735 \seq_put_right:Nn \c__ctex_headings_seq { figure }
1736 \seq_put_right:Nn \c__ctex_headings_seq { lstlisting }
1737 \seq_remove_duplicates:N \c__ctex_headings_seq
1738 \cs_new_protected:Npn \eb_toc_format_define:n #1
1739 {
1740 \ctex_define:n
1741 {
1742 #1 .meta:nn = { ctex/#1 } {##1},
1743 #1/tocformat .tl_set:c = l__eb_toc_#1_format_tl,
1744 #1/tocformat+ .code:n = \tl_put_right:cn { l__eb_toc_#1_format_tl } {##1},
1745 #1/tocformat~+ .code:n = \tl_put_right:cn { l__eb_toc_#1_format_tl } {##1},
1746 #1/tocformat* .tl_set:c = l__eb_toc_#1_entry_nolabel_tl,
1747 #1/tocindent .tl_set:c = l__eb_toc_#1_indent_tl,
1748 #1/toclabel .cs_set:cp = { eb_toc_entry_#1:nnn } ##1##2##3,
1749 #1/tocrule .cs_set:cp = { eb_toc_rule_#1:n } ##1,
1750 #1/tocafter .tl_set:c = l__eb_toc_#1_after_tl,
1751 #1/tocbelow .tl_set:c = l__eb_toc_#1_below_tl,
1752 #1/tocbegin .meta:n = { #1/tocbelow = {##1} },
1753 #1/tocsep .tl_set:c = l__eb_toc_#1_sep_tl,
1754 #1/tocend .tl_set:c = l__eb_toc_#1_end_tl
1755 }
1756 }
1757 \tl_new:N \l__eb_toc_tmpa_tl
1758 \tl_new:N \l__eb_toc_tmpb_tl
1759 \cs_new_protected:Npn \eb_toc_format_initial:nn #1#2
1760 {
1761 \exp_last_unbraced:Nx \titlecontents
1762 {
1763 \tl_use:N \l__eb_toc_tmpa_tl
1764 \exp_not:n
1765 {
1766 {#2}
1767 [\tl_use:c { l__eb_toc_#2_indent_tl }]
1768 {\tl_use:c { l__eb_toc_#2_format_tl }}
1769 {\use:c { eb_toc_entry_#2:nnn } { \thecontentslabel } {#2} {#1}}
1770 {\tl_use:c { l__eb_toc_#2_entry_nolabel_tl }}
1771 {\use:c { eb_toc_rule_#2:n } { \thecontentspage }}
1772 [\tl_use:c { l__eb_toc_#2_below_tl }]
1773 }
1774 \exp_not:o { \l__eb_toc_tmpb_tl }
1775 }
1776 \ctex_set:nn {#2}
1777 {
1778 tocformat = \IfBooleanT{#1}{\contentsmargin{0pt}},
1779 tocindent = 0pt,
1780 tocrule = \IfBooleanTF{#1}{,~##1}{\cdottocrule},
1781 toclabel =
1782 {
1783 \bool_if:NTF \l__eb_toc_entry_hang_bool
1784 { \IfBooleanTF{##3}{\use:n}{\contentspush} }
1785 { \use:n }
1786 {
1787 \bool_lazy_or:nnTF
1788 { \str_if_eq_p:Vn \Hy@linktoc { 1 } }
1789 { \str_if_eq_p:Vn \Hy@linktoc { 3 } }
1790 { \hytoclink{##1} }
1791 {##1}
1792 \tl_use:c { l__eb_toc_##2_after_tl }
1793 }
1794 },
1795 tocafter = \hspace{1em},
1796 tocsep = .—,
1797 tocend = .
1798 }
1799 }
1800 \seq_new:N \l__eb_toc_every_include_name_seq
1801 \cs_new_protected:Npn \ExcludeEveryTocName #1
1802 {
1803 \clist_map_inline:nn {#1}
1804 { \seq_remove_all:Nn \l__eb_toc_every_include_name_seq {##1} }
1805 }
1806 \cs_new_protected:Npn \IncludeEveryTocName #1
1807 {
1808 \clist_map_inline:nn {#1}
1809 {
1810 \seq_put_right:Nn \l__eb_toc_every_include_name_seq {##1}
1811 \seq_remove_duplicates:N \l__eb_toc_every_include_name_seq
1812 }
1813 }
1814 \cs_new_protected:Npn \eb@register@toc@name #1#2
1815 {
1816 \IfBooleanT{#1}
1817 {
1818 \ctex_set:nn { toc } { between = { },bibetween = { } }
1819 \tl_set:Nn \l__eb_toc_tmpa_tl {*}
1820 \tl_set:Nn \l__eb_toc_tmpb_tl
1821 {
1822 [\tl_use:c { l__eb_toc_#2_sep_tl }]
1823 [\tl_use:c { l__eb_toc_#2_end_tl }]
1824 }
1825 }
1826 \IncludeEveryTocName{#2}
1827 \eb_toc_format_define:n {#2}
1828 \eb_toc_format_initial:nn {#1} {#2}
1829 \tl_clear:N \l__eb_toc_tmpa_tl
1830 \tl_clear:N \l__eb_toc_tmpb_tl
1831 }
1832 \NewDocumentCommand{\RegisterTocName}{sm}
1833 {
1834 \clist_map_inline:nn {#2}
1835 { \eb@register@toc@name{#1}{##1} }
1836 }
1837 \clist_set_from_seq:NN
1838 \c__ctex_headings_clist \c__ctex_headings_seq
1839 \exp_args:NV \RegisterTocName \c__ctex_headings_clist
1840 \ctex_define:n { float/unknown .code:n = \eb_msg_deprecated_option:n { float } }
1841 \cs_new_protected:Npn \eb@register@every@toc@option #1
1842 {
1843 \ctex_define:nn { toc }
1844 {
1845 #1-every .code:n =
1846 {
1847 \seq_map_inline:Nn \l__eb_toc_every_include_name_seq
1848 { \ctex_set:n { ####1/#1 = {##1} } }
1849 }
1850 }
1851 }
1852 \cs_new_protected:Npn \RegisterEveryTocOption #1
1853 {
1854 \clist_map_function:nN {#1}
1855 \eb@register@every@toc@option
1856 }
1857 \RegisterEveryTocOption{tocafter,tocindent,tocrule}
1858 \NewDocumentCommand{\tocrule}{st-O{0.6pc}d()mO{}}
1859 {
1860 \normalsize\normalfont
1861 \ttl@row@i[#3]{\IfValueTF{#4}{\scalebox{#4}{#5}}{#5}}#6
1862 {
1863 \IfBooleanF{#2}
1864 {
1865 \IfBooleanTF{#1}
1866 {\thecontentspage}
1867 {
1868 \bool_if:NTF \l__eb_toc_dot_align_bool
1869 { \contentspage }
1870 { \thecontentspage }
1871 }
1872 }
1873 }
1874 }
1875 \cs_set:Npn \cdottocrule { \tocrule{\textperiodcentered} }
1876 \bool_new:N \l__eb_toc_dot_align_bool
1877 \ctex_define:nn { toc }
1878 {
1879 lolskip .skip_set:N = \eb@toc@lol@skip,
1880 lolskip .initial:n = 10pt,
1881 between .tl_set:N = \l__eb_toc_title_between_hook_tl,
1882 between .initial:n = \bool_if:NT \l__eb_class_mode_book_bool { \vspace*{-1pc} },
1883 bibetween .tl_set:N = \l__eb_toc_bititle_between_hook_tl,
1884 bibetween .initial:n = \bool_if:NT \l__eb_class_mode_book_bool { \vspace*{-1pc} },
1885 dotalign .choice:,
1886 dotalign/true .code:n =
1887 {
1888 \bool_set_true:N \l__eb_toc_dot_align_bool
1889 \contentsmargin{1.55em}
1890 },
1891 dotalign/false .code:n =
1892 {
1893 \bool_set_false:N \l__eb_toc_dot_align_bool
1894 \contentsmargin{0pt}
1895 },
1896 dotalign .default:n = true,
1897 dotalign .initial:n = true,
1898 hang .bool_set:N = \l__eb_toc_entry_hang_bool,
1899 hang .default:n = true,
1900 hang .initial:n = true,
1901 pagenumwd .code:n = \contentsmargin{#1},
1902 pagenumwd .initial:n = 1.55em,
1903 unknown .code:n = \eb_msg_deprecated_option:n { toc }
1904 }
1905
1906 \NewHookWithArguments{eb/starttoc/end}{1}
1907 \AddToHookWithArguments{eb/starttoc/end}[aux]
1908 {
1909 \AddToHook{enddocument/afterlastpage}
1910 {
1911 \ifbool{@filesw}
1912 {
1913 \tl_if_exist:cF { tf@#1 }
1914 { \iow_new:c { tf@#1 }\iow_open:cn { tf@#1 } { \jobname.#1 } }
1915 }{}
1916 }
1917 }
1918 \cs_set_eq:NN \eb@starttoc \@starttoc
1919 \cs_set:Npn \@starttoc #1
1920 {
1921 \IfFormatAtLeastTF{2023/06/01}
1922 {
1923 \group_begin:
1924 \makeatletter
1925 \file_if_exist_input:nF { \jobname.#1 }
1926 { \typeout{No~file~\jobname.#1.} }
1927 \UseHookWithArguments{eb/starttoc/end}{1}{#1}
1928 \boolfalse{@nobreak}
1929 \group_end:
1930 }
1931 { \eb@starttoc{#1} }
1932 }
1933 \cs_set_protected:Npn \AssignPartialExt #1#2
1934 {
1935 \tl_if_exist:cTF { ttl@partial#1 }
1936 { \msg_warning:nnnn { easybase } { repeated-ptoc } {#1} {#2} }
1937 {
1938 \tl_set:cn { ttl@partial#1 } {#2}
1939 \AddToHookWithArguments{cmd/ttl@writepartial/before}[ttl/#1]
1940 {\ttl@topartial{#1}{##1}{##2}}
1941 }
1942 }
1943 \cs_set_eq:NN \AllotPartialExt \AssignPartialExt
1944 \msg_new:nnn { easybase } { repeated-ptoc }
1945 {
1946 Local~directory~file~'#2'~of~directory~type~'#1'~is \\
1947 repeatedly~allocated.
1948 }
1949 \AssignPartialExt{lol}{pll}
1950
1951 \cs_generate_variant:Nn \str_if_eq:nnT { x }
1952 \NewDocumentCommand{\RegisterTitleIfname}{sO{\jobname}mm}
1953 {
1954 \clist_map_inline:nn {#3}
1955 { \eb@register@title@ifname{#1}{#2}{##1}{#4} }
1956 }
1957 \cs_new_protected:Npn \eb_save_file_name:nnn #1#2#3
1958 { \str_set:Nn \@real@jobname {#2} }
1959 \cs_new_protected:Npn \eb@register@title@ifname #1#2#3#4
1960 {
1961 \IfBooleanT{#1}
1962 {
1963 \RemoveFromHook{cmd/addcontentsline/before}[title/ifname/#3]
1964 \RemoveFromHook{file/\@real@jobname.#3/before}[title/ifname/#3]
1965 \RemoveFromHook{file/\@real@jobname.#3/after}[title/ifname/#3]
1966 }
1967 \AddToHookWithArguments{cmd/addcontentsline/before}[title/ifname/#3]
1968 {
1969 \str_if_eq:xnT {##1} {#3}
1970 {
1971 \addtocontents{##1}
1972 {#4{\CTEX@ifnametrue}{\CTEX@ifnamefalse}}
1973 }
1974 }
1975 \file_parse_full_name_apply:nN {#2} \eb_save_file_name:nnn
1976 \AddToHook{file/\@real@jobname.#3/before}[title/ifname/#3]
1977 {\cs_gset_eq:NN \eb@title@ifname@resume \CTEXifname}
1978 \AddToHook{file/\@real@jobname.#3/after}[title/ifname/#3]
1979 {\cs_gset_eq:NN \CTEXifname \eb@title@ifname@resume}
1980 }
1981 \NewDocumentCommand{\RegisterCapIfname}{sO{\jobname}m}
1982 {
1983 \IfBooleanTF{#1}
1984 {\RegisterTitleIfname*[#2]{#3}{\capifname}}
1985 {\RegisterTitleIfname[#2]{#3}{\capifname}}
1986 }
1987 \RegisterTitleIfname{toc,tec}{\CTEXifname}
1988 \RegisterCapIfname{lot,lof,lol}
1989 \RegisterTitleIfname{loe}{\thmtifname}
1990
1991 \cs_new_protected:Npn \SetTocStyle #1#2#3
1992 {
1993 \clist_map_inline:nn {#1}
1994 { \eb@set@toc@style{##1}{#2}{#3} }
1995 }
1996 \cs_new_protected:Npn \eb@set@toc@style #1#2#3
1997 {
1998 \cs_set_protected:cpn { eb@toc@style@set@#1@#2 }
1999 { \ctex_set:nn {#1} {#3} }
2000 }
2001 \cs_new_protected:Npn \UseTocStyle #1#2#3
2002 {
2003 \clist_map_inline:nn {#1}
2004 { \eb@use@toc@style{##1}{#2}{#3} }
2005 }
2006 \cs_new_protected:Npn \eb@use@toc@style #1#2#3
2007 {
2008 \cs_if_exist:cTF { eb@toc@style@set@#1@#2 }
2009 { \addtocontents{#3}{\string\csuse{eb@toc@style@set@#1@#2}} }
2010 { \msg_warning:nnnn { easybase } { undefined-toc-style } {#2} {#1} }
2011 }
2012 \msg_new:nnn { easybase } { undefined-toc-style }
2013 { The~contents~style~'#1'~of~'#2'~is~not~defined. }
2014
2015 \cs_new:Npn \eb_toc_insert_vspace:
2016 {
2017 \tl_if_eq:NnTF \g__eb_bilist_permute_value_tl { mix }
2018 { \ebifbitoc{}{\addvspace{1pc}} }
2019 { \addvspace{1pc} }
2020 }
2021 \ctex_set:n
2022 {
2023 part =
2024 {
2025 tocformat =
2026 {
2027 \bool_if:NT \l__eb_class_mode_book_bool
2028 { \eb_toc_insert_vspace: }
2029 \sffamily\large
2030 },
2031 tocindent = 0pt,
2032 tocrule = \tocrule{}[\bfseries],
2033 tocline = \CTEXnumberline{#1}#2
2034 },
2035 chapter =
2036 {
2037 tocformat = \eb_toc_insert_vspace:\sffamily,
2038 tocindent = 0pt,
2039 tocrule = \cdottocrule[\bfseries],
2040 tocline = \CTEXnumberline{#1}#2
2041 },
2042 section =
2043 {
2044 tocformat = \bool_if:NF \l__eb_class_mode_book_bool { \sffamily },
2045 tocindent = \bool_if:NTF \l__eb_class_mode_book_bool { 1.5em } { 0pt },
2046 tocrule =
2047 {
2048 \bool_if:NTF \l__eb_class_mode_book_bool
2049 { \cdottocrule }
2050 { \cdottocrule[\bfseries] }
2051 }
2052 },
2053 subsection =
2054 { tocindent = \bool_if:NTF \l__eb_class_mode_book_bool { 3.8em } { 1.5em } }
2055 }
2056
2057 \ctex_at_end_package:nn { indextools }
2058 {
2059 \booltrue{indtl@fancyhdr}
2060 \RenewDocumentCommand{\printindex}{st++o}
2061 {
2062 \group_begin:
2063 \tl_set_eq:NN \eb@toc@title \indexname
2064 \eb_toc_kv_set:nn { idx } {#3}
2065 \cs_set_protected:Npn \indtl@indexlevel ##1
2066 { \eb_toc_title_level_cmd:n {#1} }
2067 \@ifundefined{\csuse{eb@index@name}@idxfile}
2068 {\indtl@error{\eb@index@name}}
2069 {\indtl@putindex{\eb@index@name}}
2070 \group_end:
2071 }
2072 }
2073 \ctex_define:nn { chapter }
2074 {
2075 biname .code:n = \ctex_assign_heading_name:nn { bichapter } {#1},
2076 biname .initial:n = Chapter\space,
2077 binumber .tl_set:N = \CTEX@bichapter@number,
2078 binumber .initial:n = \arabic{chapter}
2079 }
2080 \cs_new_protected:Npn \eb_counter_zero:n #1
2081 { \clist_map_inline:nn {#1} { \setcounter{##1}{0} } }
2082 \RenewDocumentCommand{\appendix}
2083 {O{Appendix\space}D(){\Alph{chapter}}}
2084 {
2085 \ctex_assign_heading_name:nn { biappendix } {#1}
2086 \bool_if:NTF \l__eb_class_mode_book_bool
2087 {
2088 \AddToHook{eb/addbitocline/begin}[chapter]
2089 {
2090 \def\CTEX@prechapter{\CTEX@prebiappendix}
2091 \def\CTEX@thechapter{#2}
2092 \def\CTEX@postchapter{\CTEX@postbiappendix}
2093 }
2094 \gdef\thechapter{\@Alph\c@chapter}
2095 \gdef\thebichapter{\@Alph\c@bichapter}
2096 \gdef\CTEX@prechapter{\CTEX@preappendix}
2097 \gdef\CTEX@thechapter{\CTEX@appendix@number}
2098 \gdef\CTEX@postchapter{\CTEX@postappendix}
2099 \gdef\CTEX@chapter@numbering{\CTEX@appendix@numbering}
2100 \eb_counter_zero:n { chapter,section,bichapter,bisection }
2101 }
2102 {
2103 \gdef\thesection{\@Alph\c@section}
2104 \gdef\thebisection{\@Alph\c@bisection}
2105 \gdef\CTEX@presection{\CTEX@preappendix}
2106 \gdef\CTEX@thesection{\CTEX@appendix@number}
2107 \gdef\CTEX@postsection{\CTEX@postappendix}
2108 \gdef\CTEX@section@numbering{\CTEX@appendix@numbering}
2109 \ctex_set:nn { appendix } { number = \@Alph\c@section,name = { } }
2110 \eb_counter_zero:n { section,subsection,bisection,bisubsection }
2111 }
2112 }
2113
2114 \ctex_define:nn { font }
2115 {
2116 caption-table .tl_set:N = \l__eb_font_caption_table_tl,
2117 caption-figure .tl_set:N = \l__eb_font_caption_figure_tl,
2118 caption-lstlisting .tl_set:N = \l__eb_font_caption_lstlisting_tl,
2119 caption-every .meta:n =
2120 {
2121 caption-table = {#1},caption-figure = {#1},
2122 caption-lstlisting = {#1}
2123 },
2124 caption-every .initial:n = \sffamily\small,
2125 footnote .tl_set:N = \eb@font@footnote,
2126 marginpar .tl_set:N = \marginfont,
2127 marginpar .initial:n = \footnotesize,
2128 unknown .code:n = \eb_msg_deprecated_option:n { font }
2129 }
2130 \cs_new_protected:Npn \ebaddtofont #1#2
2131 {
2132 \str_case:nn {#1}
2133 {
2134 { table }
2135 { \tl_put_right:Nn \l__eb_font_caption_table_tl {#2} }
2136 { figure }
2137 { \tl_put_right:Nn \l__eb_font_caption_figure_tl {#2} }
2138 { lstlisting }
2139 { \tl_put_right:Nn \l__eb_font_caption_lstlisting_tl {#2} }
2140 { every }
2141 {
2142 \tl_put_right:Nn \l__eb_font_caption_table_tl {#2}
2143 \tl_put_right:Nn \l__eb_font_caption_figure_tl {#2}
2144 \tl_put_right:Nn \l__eb_font_caption_lstlisting_tl {#2}
2145 }
2146 { footnote }
2147 { \tl_put_right:Nn \eb@font@footnote {#2} }
2148 { marginpar }
2149 { \tl_put_right:Nn \marginfont {#2} }
2150 }
2151 }
2152 \cs_set_eq:NN \addtosubfont \ebaddtofont
2153
2154 \cs_new_protected:Npn \usestretch #1
2155 {
2156 \edef\baselinestretch{#1}
2157 \@currsize
2158 }
2159 \cs_set_eq:NN \setspread \usestretch
2160 \cs_new_protected:Npn \restore@usespace
2161 {
2162 \par
2163 \vskip\parskip
2164 \vskip\baselineskip
2165 \endgroup
2166 \vskip -\parskip
2167 \vskip -\baselineskip
2168 }
2169 \NewDocumentEnvironment{usespace}{m+b}
2170 {
2171 \par
2172 \begingroup
2173 \usestretch{#1}#2
2174 \restore@usespace
2175 }{}
2176 \msg_new:nnn { easybase } { invalid-spread }
2177 {
2178 The~line~spacing~factor~option~'#1'~is~invalid. \\
2179 Please~use~the~'usespace'~environment~to~set~the~line~spacing.
2180 }
2181 \cs_new_protected:Npn \eb_invalid_spread_warning:
2182 { \msg_warning:nnV { easybase } { invalid-spread } \l_keys_key_str }
2183 \ctex_define:nn { space }
2184 {
2185 linespread .code:n = \usestretch{#1},
2186 tabspread .code:n = \eb_invalid_spread_warning:,
2187 mathspread .code:n = \eb_invalid_spread_warning:,
2188 fntspread .code:n =
2189 {
2190 \tl_set:Nn \eb@spread@footnote {#1}
2191 \group_begin:
2192 \footnotesize
2193 \usestretch{\eb@spread@footnote}
2194 \exp_args:NNNo \group_end:
2195 \dim_set:Nn \footnotesep { \dim_use:N \box_ht:N \strutbox }
2196 },
2197 fntspread .initial:n = 1.2,
2198 captab-spread .fp_set:N = \l__eb_spread_caption_table_fp,
2199 capfig-spread .fp_set:N = \l__eb_spread_caption_figure_fp,
2200 caplst-spread .fp_set:N = \l__eb_spread_caption_lstlisting_fp,
2201 caption-spread .meta:n =
2202 {
2203 captab-spread = {#1},capfig-spread = {#1},
2204 caplst-spread = {#1}
2205 },
2206 caption-spread .initial:n = 1.2,
2207 everyspread .meta:n =
2208 {
2209 linespread = {#1},caption-spread = {#1},
2210 fntspread = {#1}
2211 },
2212 abovedisplayskip .code:n =
2213 { \AfterPreamble{\skip_set:Nn \abovedisplayskip {#1}} },
2214 abovedisplayskip .initial:n = 0.5ex plus .1ex minus .1ex,
2215 belowdisplayskip .code:n =
2216 {
2217 \AfterPreamble
2218 {
2219 \skip_set:Nn \belowdisplayskip {#1}
2220 \skip_set:Nn \belowdisplayshortskip {#1}
2221 }
2222 },
2223 belowdisplayskip .initial:n = 0.5ex plus .1ex minus .1ex,
2224 unknown .code:n = \eb_msg_deprecated_option:n { space }
2225 }
2226 \tl_if_eq:NnT \l__ctex_scheme_tl { chinese }
2227 {
2228 \fp_compare:nNnTF { \l__ctex_line_spread_fp } = { 1.3 }
2229 { \usestretch{1.354} }
2230 { \usestretch{\fp_use:N \l__ctex_line_spread_fp} }
2231 }
2232 \AfterPreamble{\skip_set:Nn \abovedisplayshortskip { 0ex plus .1ex }}
2233
2234 \cs_new_protected:Npn \eb@register@cap@options #1
2235 {
2236 \ctex_define:nn { cap }
2237 {
2238 #1/unknown .code:n =
2239 {
2240 \use:x
2241 {
2242 \exp_not:N \captionsetup[#1]
2243 { \eb_unknown_kv_handle: }
2244 }
2245 },
2246 #1/unknown .default:V = \c_novalue_tl,
2247 #1 .meta:nn = { ctex/cap/#1 } {##1}
2248 }
2249 }
2250 \cs_new_protected:Npn \RegisterCapOptions #1
2251 {
2252 \clist_map_function:nN {#1}
2253 \eb@register@cap@options
2254 }
2255 \RegisterCapOptions{table,figure,lstlisting}
2256 \clist_map_inline:nn
2257 { table,figure,lstlisting }
2258 {
2259 \DeclareCaptionFont{eb@#1@font}
2260 {
2261 \usestretch{\fp_use:c { l__eb_spread_caption_#1_fp }}
2262 \tl_use:c { l__eb_font_caption_#1_tl }
2263 }
2264 }
2265 \captionsetup
2266 {
2267 format = hang,
2268 labelfont = {color = ctex@frame},
2269 labelsep = quad,
2270 hypcap = false,
2271 singlelinecheck = true
2272 }
2273 \captionsetup[table]{font = eb@table@font}
2274 \captionsetup[figure]{font = eb@figure@font}
2275 \captionsetup[lstlisting]{font = eb@lstlisting@font}
2276 \ctex_at_end_package:nn { bicaption }
2277 {
2278 \captionsetup[figure][bi-second]{name = Figure}
2279 \captionsetup[table][bi-second]{name = Table}
2280 }
2281 \UseTblrLibrary{booktabs}
2282 \bool_if:NF \l__eb_float_page_bool
2283 {
2284 \tl_gset:Nn \textfraction { 0.1 }
2285 \tl_gset:Nn \topfraction { 0.9 }
2286 \tl_gset:Nn \bottomfraction { 0.9 }
2287 \tl_gset:Nn \floatpagefraction { 0.9 }
2288 \tl_gset:Nn \dbltopfraction { 0.9 }
2289 \tl_gset:Nn \dblfloatpagefraction { 0.9 }
2290 }
2291 \skip_set:Nn \textfloatsep { 12pt plus 4pt minus 3pt }
2292 \skip_set:Nn \dbltextfloatsep { 12pt plus 4pt minus 3pt }
2293 \skip_set:Nn \multicolsep { 12pt plus 4pt minus 3pt }
2294 \setcounter{topnumber}{4}
2295 \setcounter{bottomnumber}{4}
2296 \setcounter{totalnumber}{8}
2297
2298 \dim_new:N \hangwd
2299 \cs_set_protected:Npn \hangpara #1#2
2300 {
2301 \dim_gset:Nn \hangindent {#1}
2302 \int_gset:Nn \hangafter {#2}
2303 \noindent\ignorespaces
2304 }
2305 \NewDocumentCommand{\hangfrom}{sO{\hangwd}mO{1}}
2306 {
2307 \hbox_set:Nn \l_tmpa_box {#3}
2308 \dim_set:Nn \hangwd { \box_wd:N \l_tmpa_box }
2309 \hangpara{#2}{#4}
2310 \IfBooleanTF{#1}
2311 {\hbox_to_wd:nn {#2} { }}
2312 {\box_use_drop:N \l_tmpa_box}
2313 \ignorespaces
2314 }
2315 \DeclareDocumentEnvironment{hangparas}{mm+b}
2316 {
2317 \dim_zero:N \parindent
2318 \everypar{\hangpara{#1}{#2}}#3\par
2319 }{}
2320 \cs_new_protected:Npn \eb_enumitem_label_set:nn #1#2
2321 { \SetEnumitemValue{label}{#1}{\color{ctex@emph}#2} }
2322 \clist_map_inline:nn
2323 {
2324 { bullet } { \textbullet },
2325 { endash } { \normalfont\bfseries\textendash },
2326 { asterisk } { \textasteriskcentered },
2327 { arabic } { \arabic*. },
2328 { alph } { (\alph*) },
2329 { roman } { \roman*. }
2330 }
2331 { \eb_enumitem_label_set:nn #1 }
2332 \SetEnumitemValue{font}{sf}{\color{ctex@emph}\normalfont\sffamily}
2333 \SetEnumitemValue{ref}{enumii}{\arabic{enumi}.\alph*}
2334 \SetEnumitemValue{ref}{enumiii}{\arabic{enumi}.\alph{enumii}.\roman*}
2335 \setlist{nosep,labelsep = 0.5em,listparindent = \parindent}
2336 \setlist[1]{leftmargin = *,align = left}
2337 \setlist[itemize,1]{label = bullet}
2338 \setlist[itemize,2]{label = endash}
2339 \setlist[itemize,3]{label = asterisk}
2340 \setlist[enumerate,1]{label = arabic,ref = \arabic*}
2341 \setlist[enumerate,2]{label = alph,ref = enumii}
2342 \setlist[enumerate,3]{label = roman,ref = enumiii}
2343 \setlist[description]{font = sf,style = standard}
2344 \newlist{eb@eqcomp@list}{description}{1}
2345 \setlist[eb@eqcomp@list]{nosep,labelsep = 0pt}
2346 \cs_new:Npn \seteqcomplist #1 { \setlist*[eb@eqcomp@list]{#1} }
2347
2348 \keys_define:nn { eb/eqcomp }
2349 {
2350 width .dim_set:N = \l__eb_eqsymb_width_dim,
2351 width .initial:n = 10pt,
2352 delim .tl_set:N = \l__eb_eqsymb_delim_tl,
2353 delim .initial:n = \tl_if_eq:NnTF \l__ctex_scheme_tl { chinese } { —— } { --- },
2354 space .dim_set:N = \l__eb_eqsymb_space_dim,
2355 space .initial:n = 0.25em,
2356 item-align .tl_set:N = \l__eb_eqsymb_item_align_tl,
2357 item-align .initial:n = r,
2358 delim-align .tl_set:N = \l__eb_eqsymb_delim_align_tl,
2359 delim-align .initial:n = c,
2360 enumitem .code:n = \seteqcomplist{#1},
2361 intro .tl_set:N = \l__eb_eqsymb_intro_tl,
2362 font .tl_set:N = \l__eb_eqsymb_font_tl,
2363 mode .tl_set:N = \l__eb_eqsymb_mode_tl,
2364 mode .initial:n = math
2365 }
2366 \cs_new_protected:Npn \seteqcomp #1
2367 { \keys_set:nn { eb/eqcomp } {#1} }
2368
2369 \cs_new_protected:Npn \eb_eqsymb_left_margin_calc:
2370 {
2371 \hbox_set:Nn \l_tmpa_box { \l__eb_eqsymb_delim_tl }
2372 \hbox_set:Nn \l_tmpb_box { \l__eb_eqsymb_intro_tl }
2373 \dim_set:Nn \l_tmpa_dim
2374 {
2375 \box_wd:N \l_tmpb_box +
2376 \l__eb_eqsymb_width_dim +
2377 \box_wd:N \l_tmpa_box +
2378 2\l__eb_eqsymb_space_dim
2379 }
2380 }
2381 \NewDocumentEnvironment{eqcomp}{oD(){}+b}
2382 {
2383 \IfValueT{#1}{\keys_set:nn { eb/eqcomp } {#1}}
2384 \eb_eqsymb_left_margin_calc:
2385 \begin{eb@eqcomp@list}[#2]
2386 #3
2387 \end{eb@eqcomp@list}
2388 }{}
2389 \cs_new_protected:Npn \eb_eqsymb_format_mark:n #1
2390 {
2391 \tl_use:N \l__eb_eqsymb_font_tl
2392 {
2393 \tl_if_eq:NnT \l__eb_eqsymb_mode_tl { math }
2394 { \ensuremath }{#1}
2395 }
2396 }
2397 \cs_new_protected:Npn \eb_eqsymb_space_delim:nn #1#2
2398 {
2399 \hspace{\l__eb_eqsymb_space_dim}
2400 \IfBooleanTF{#1}
2401 {\makebox{#2}}
2402 {\makebox[\box_wd:N \l_tmpa_box][\l__eb_eqsymb_delim_align_tl]{#2}}
2403 \hspace{\l__eb_eqsymb_space_dim}
2404 }
2405 \cs_new_protected:Npn \eb@itembox { \item[]\makebox }
2406 \NewDocumentCommand{\symb}{smO{\l__eb_eqsymb_delim_tl}}
2407 {
2408 \IfBooleanTF{#1}
2409 {
2410 \eb_eqsymb_format_mark:n {#2}
2411 \eb_eqsymb_space_delim:nn {#1} {#3}
2412 }
2413 {
2414 \eb@itembox[\l_tmpa_dim]
2415 {
2416 \makebox[\box_wd:N \l_tmpb_box]{\l__eb_eqsymb_intro_tl}
2417 \makebox[\l__eb_eqsymb_width_dim][\l__eb_eqsymb_item_align_tl]
2418 {\eb_eqsymb_format_mark:n {#2}}
2419 \eb_eqsymb_space_delim:nn {#1} {#3}
2420 }
2421 }
2422 \tl_clear:N \l__eb_eqsymb_intro_tl
2423 \ignorespaces
2424 }
2425
2426 \cs_new:Npn \eb_tl_exist_noempty:cT #1#2
2427 { \tl_if_exist:cT {#1} { \tl_if_empty:cF {#1} {#2} } }
2428 \cs_new_protected:Npn \eb_theorem_load_thmtools:
2429 {
2430 \RequirePackage{amsthm,thmtools}
2431 \cs_set_eq:NN \eb@declaretheoremstyle@save \declaretheoremstyle
2432 \cs_set_eq:NN \eb@declaretheorem@save \declaretheorem
2433 \RenewDocumentCommand{\declaretheoremstyle}{+O{}m+O{}}
2434 {\eb@declaretheoremstyle@save[##1,##3]{##2}}
2435 \RenewDocumentCommand{\declaretheorem}{+O{}m+O{}}
2436 {
2437 \cs_undefine:c {##2}
2438 \undefinecounter{##2}
2439 \eb_tl_exist_noempty:cT { g__eb_thmt_##2_parent_tl }
2440 {
2441 \exp_args:Nnv \@removefromreset {##2}
2442 { g__eb_thmt_##2_parent_tl }
2443 }
2444 \eb@declaretheorem@save[style = default,##1,##3]{##2}
2445 \tl_gset:cV { g__eb_thmt_##2_parent_tl } \thmt@parent
2446 \providebool{thmt@isstarred@##2}
2447 \ifbool{thmt@isstarred}
2448 {\booltrue{thmt@isstarred@##2}}
2449 {\boolfalse{thmt@isstarred@##2}}
2450 \settheoremtocline{##2}
2451 {
2452 \thmtifname{\listnumberline{##2}}{}
2453 \thmtname\thmtifnote{~(\thmtnote)}{}
2454 }
2455 \cs_gset:cpn { thmt@contentsline@##2 }
2456 { \thmt@contentslineIfNamed }
2457 \exp_args:Nc \providecommand { p@##2 }[1]{####1}
2458 }
2459 \ctex_define:nn { thmt }
2460 {
2461 loeskip .skip_set:N = \eb@thmt@loe@skip,
2462 loeskip .initial:n = 10pt,
2463 unknown .code:n = \eb_msg_deprecated_option:n { thmt }
2464 }
2465 \declaretheoremstyle{default}[
2466 spaceabove = 0ex plus .1ex,
2467 spacebelow = 0ex plus .1ex,
2468 headindent = 0pt,
2469 within = \bool_if:NT \l__eb_class_mode_book_bool { chapter },
2470 headpunct = { },
2471 headfont = \color{ctex@emph}\sffamily,
2472 bodyfont = \normalfont,
2473 postheadspace = 1em
2474 ]
2475 \DeclareFloatList{theorem}{loe}
2476 \AssignPartialExt{loe}{ple}
2477 \eb_preto_cmd:nn { listoftheorems }
2478 {
2479 \group_begin:
2480 \let\thmt@contentsline\contentsline
2481 \def\contentsline ##1 {\use:c { thmt@contentsline@##1 }{##1}}
2482 }
2483 \eb_appto_cmd:nn { listoftheorems } { \group_end: }
2484 \eb_preto_cmd:nn { @chapter }
2485 {
2486 \skip_if_eq:nnF { \eb@thmt@loe@skip } { \c_zero_skip }
2487 { \addtocontents{loe}{\protect\addvspace{\skip_use:N \eb@thmt@loe@skip}} }
2488 }
2489 \def\thmtlo@chaptervspacehack{}
2490 \def\thmt@mklistcmd{\thmtlo@newentry}
2491 \def\thmtname{\thmt@thmname}
2492 \def\thmtenvname{\thmt@envname}
2493 \def\thmtnote{\thmt@shortoptarg}
2494 \def\thmtformatoptarg ##1 {##1}
2495 \def\thmtifname ##1##2 {\ifbool{thmt@isstarred@\thmt@envname}{##2}{##1}}
2496 \def\thmtifnote ##1##2
2497 {
2498 \tl_if_empty:NTF \thmt@shortoptarg
2499 {##2}
2500 { \protect\thmtformatoptarg{##1} }
2501 }
2502 \cs_new_protected:Npn \eb@settheoremtocline ##1##2##3
2503 {
2504 \IfBooleanT{##1}{\def\thmt@contentslineIgnore{\thmt@contentsline}}
2505 \cs_set:cpn { ll@##2 } { \@bsphack ##3\@esphack }
2506 }
2507 \NewDocumentCommand{\settheoremtocline}{smm}
2508 {
2509 \clist_map_inline:nn {##2}
2510 { \eb@settheoremtocline{##1}{####1}{##3} }
2511 }
2512 }
2513 \cs_new_protected:Npn \eb_theorem_load_keytheorems:
2514 {
2515 \RequirePackage{keytheorems}
2516 \DeclareFloatList{theorem}{thlist}
2517 \AssignPartialExt{thlist}{ple}
2518 }
2519 \str_case:VnT \l__eb_theorem_support_tl
2520 {
2521 { thmtools }
2522 { \eb_theorem_load_thmtools: }
2523 { keytheorems }
2524 { \eb_theorem_load_keytheorems: }
2525 }
2526 { \cs_undefine:N \proof }
2527 \cs_new_protected:Npn \eb_chem_load_chemformula:
2528 {
2529 \RequirePackage{chemformula}
2530 \setchemformula
2531 {
2532 charge-hshift = 0pt,
2533 subscript-vshift = -0.2ex
2534 }
2535 }
2536 \cs_new_protected:Npn \eb_chem_load_mhchem:
2537 {
2538 \RequirePackage[version = 4]{mhchem}
2539 \mhchemoptions{layout = stacked}
2540 }
2541 \str_case:VnF \l__eb_chem_support_tl
2542 {
2543 { chemformula }
2544 { \eb_chem_load_chemformula: }
2545 { mhchem }
2546 { \eb_chem_load_mhchem: }
2547 }
2548 { \RequirePackage{amsmath} }
2549 \tl_set:Nn \fontsubfuzz { 0.5pt }
2550 \everymath{\displaystyle}
2551 \dim_zero_new:N \mathindent
2552 \allowdisplaybreaks[4]
2553 \DeclareGraphicsExtensions{.pdf,.png,.jpg,.eps,.tif}
2554 \sisetup
2555 {
2556 number-mode = match,
2557 range-phrase = \ensuremath{\sim},
2558 range-units = single,
2559 print-unity-mantissa = false,
2560 table-alignment-mode = none,
2561 group-digits = none
2562 }
2563 \ctex_at_end_package:nn { unicode-math }
2564 { \msg_redirect_module:nnn { unicode-math } { warning } { info } }
2565 \ctex_at_end_package:nn { tcolorbox }
2566 { \file_if_exist_input:n { eb-tcolorbox.cfg } }
2567
2568 \NewDocumentCommand{\eb_assign_tagform:n}
2569 {>{\SplitArgument{1}{,}}m}
2570 {
2571 \eb_assign_tagform_pos:nn #1
2572 \cs_gset:Npn \tagform@ ##1
2573 {
2574 \maketag@@@
2575 {
2576 \color{ctex@emph}
2577 \ignorespaces
2578 \eb@tag@brackets@left{##1}
2579 \unskip\@@italiccorr
2580 \eb@tag@brackets@right
2581 }
2582 }
2583 }
2584 \cs_new_protected:Npn \eb_assign_tagform_pos:nn #1#2
2585 {
2586 \tl_set:Nn \eb@tag@brackets@left {#1}
2587 \tl_set:Nn \eb@tag@brackets@right {#2}
2588 }
2589 \ctex_define:nn { tools }
2590 {
2591 multoc .int_set:N = \l__eb_toc_columns_int,
2592 multoc .default:n = 2,
2593 withpart .bool_set:N = \l__eb_chap_counter_withpart_bool,
2594 withpart .default:n = true,
2595 withpart .initial:n = false,
2596 uppercase .tl_set:N = \l__eb_mark_uppercase_value_tl,
2597 uppercase .default:n = all,
2598 uppercase .initial:n = all,
2599 tagform .code:n = \eb_assign_tagform:n {#1},
2600 tagform .initial:n = { (,) },
2601 brackets .meta:n = { tagform = {#1} },
2602 figurepath .code:n =
2603 {
2604 \tl_if_blank:nF {#1}
2605 {
2606 \regex_match:nnTF { \cB. } {#1}
2607 { \graphicspath{#1} }
2608 { \graphicspath{{#1}} }
2609 }
2610 }
2611 }
2612
2613 \bool_new:N \l__eb_backend_bibtex_bool
2614 \ctex_define:nn { bib }
2615 {
2616 backend .choice:,
2617 backend .value_required:n = true,
2618 backend/bibtex .code:n = \bool_set_true:N \l__eb_backend_bibtex_bool,
2619 backend/biblatex .code:n = \bool_set_false:N \l__eb_backend_bibtex_bool,
2620 bibstyle .tl_set:N = \l__eb_bib_both_style_tl,
2621 bibstyle .initial:n = numerical,
2622 citestyle .tl_set:N = \l__eb_bib_cite_style_tl,
2623 datafile .clist_set:N = \l__eb_bib_datafile_clist,
2624 bititle .tl_set:N = \bibibname,
2625 bititle .initial:n = Bibliography,
2626 unknown .code:n = \eb_msg_deprecated_option:n { bib }
2627 }
2628 \cs_new_protected:Npn \eb_bibtex_natbib_set:
2629 {
2630 \RequirePackage[sort&compress]{natbib}
2631 \str_case:VnTF \l__eb_bib_both_style_tl
2632 {
2633 { numerical }
2634 {
2635 \bibliographystyle{gbt7714-numerical}
2636 \setcitestyle{comma,square,super}
2637 }
2638 { authoryear }
2639 { \bibliographystyle{gbt7714-author-year} }
2640 }
2641 { \cs_set_eq:NN \cite \citep }
2642 { \exp_args:NV \bibliographystyle \l__eb_bib_both_style_tl }
2643 \tl_if_blank:VF \l__eb_bib_cite_style_tl
2644 { \exp_args:NV \setcitestyle \l__eb_bib_cite_style_tl }
2645 \NewDocumentCommand{\printbibliography}{st++o}
2646 {
2647 \group_begin:
2648 \tl_set_eq:NN \eb@toc@title \bibname
2649 \eb_toc_kv_set:nn { bbl } {##3}
2650 \cs_set_protected:Npn \bibsection
2651 {
2652 \eb_toc_title_level_cmd:n {##1}
2653 \int_compare:nNnT { \l__eb_toc_columns_int } > { 1 }
2654 { \begin{multicols}{\int_use:N \l__eb_toc_columns_int} }
2655 }
2656 \exp_args:NV \bibliography \l__eb_bib_datafile_clist
2657 \group_end:
2658 }
2659 \AtEndEnvironment{thebibliography}
2660 {\int_compare:nNnT { \l__eb_toc_columns_int } > { 1 } { \end{multicols} }}
2661 \skip_zero:N \bibsep
2662 }
2663 \cs_new_protected:Npn \eb_put_biblatex:n #1
2664 { \PassOptionsToPackage{#1}{biblatex} }
2665 \cs_new_protected:Npn \eb_biber_toc_title:n #1
2666 {
2667 \bool_if:NTF \l__eb_class_mode_book_bool
2668 { \bichapter*{#1}{\bibibname} }
2669 { \bisection*{#1}{\bibibname} }
2670 }
2671 \cs_new_protected:Npn \eb_biber_biblatex_set:
2672 {
2673 \str_case:VnF \l__eb_bib_both_style_tl
2674 {
2675 { numerical } { \use_i:nnn }
2676 { authoryear } { \use_ii:nnn }
2677 }
2678 { \use_iii:nnn }
2679 { \eb_put_biblatex:n { style = gb7714-2015 } }
2680 { \eb_put_biblatex:n { style = gb7714-2015ay } }
2681 { \eb_put_biblatex:n { style = \l__eb_bib_both_style_tl } }
2682 \tl_if_blank:VF \l__eb_bib_cite_style_tl
2683 { \eb_put_biblatex:n { citestyle = \l__eb_bib_cite_style_tl } }
2684 \RequirePackage[backend = biber]{biblatex}
2685 \clist_map_function:NN \l__eb_bib_datafile_clist \addbibresource
2686 \tl_gset:Nn \blx@default@theheading { bibintoc }
2687 \defbibheading{bibintoc}[\bibname]{\eb_biber_toc_title:n {##1}}
2688 \skip_zero:N \bibitemsep
2689 \setcounter{biburlucpenalty}{1}
2690 \setcounter{biburllcpenalty}{1}
2691 \setcounter{biburlnumpenalty}{1}
2692 }
2693 \ctex_before_end_preamble:n
2694 {
2695 \providecommand{\bibname}{\refname}
2696 \clist_if_empty:NF \l__eb_bib_datafile_clist
2697 {
2698 \bool_if:NTF \l__eb_backend_bibtex_bool
2699 { \eb_bibtex_natbib_set: }
2700 { \eb_biber_biblatex_set: }
2701 }
2702 }
2703
2704 \cs_new:Npn \lstifdisplay #1#2
2705 { \lst@ifdisplaystyle #1\else #2\fi }
2706 \lstdefinestyle{lst-base}
2707 {
2708 breaklines = true,
2709 resetmargins = true,
2710 numberstyle = \footnotesize,
2711 basewidth = 0.5em,
2712 columns = flexible,
2713 aboveskip = 0.5\baselineskip,
2714 belowskip = 0.5\baselineskip,
2715 abovecaptionskip = -1ex,
2716 belowcaptionskip = 2ex,
2717 keepspaces = true,
2718 escapeinside = {(*}{*)},
2719 frame = single,
2720 framerule = 0.5pt,
2721 framesep = 4.5pt,
2722 xleftmargin = 5pt,
2723 xrightmargin = 5pt,
2724 rulecolor = \color{ctex@frame},
2725 commentstyle = \color{SlateGray},
2726 emphstyle = \color{ctex@emph}
2727 }
2728 \lstdefinestyle{lst-latex}
2729 {
2730 style = lst-base,
2731 language = [LaTeX]TeX,
2732 texcsstyle = *\color{ctex@verb}\lstifdisplay{\bfseries}{},
2733 basicstyle = \ttfamily\lstifdisplay{\small}{\color{ctex@verb}},
2734 keywordstyle = \color{ctex@verb}\lstifdisplay{\bfseries}{}
2735 }
2736 \lstset{style = lst-latex}
2737 \lstloadlanguages{C,C++,Java,Python,Matlab}
2738
2739 \clist_new:N \l__eb_hyperref_options_clist
2740 \providecommand{\hypersetup}[1]
2741 {\clist_put_right:Nn \l__eb_hyperref_options_clist {#1}}
2742 \cs_new_protected:Npn \eb_define_link_color:nnn #1#2#3
2743 { \definecolorset{HTML}{ctex@}{}{link,#1;url,#2;cite,#3} }
2744 \cs_new_protected:Npn \eb_define_theme_color:nnn #1#2#3
2745 { \definecolorset{HTML}{ctex@}{}{frame,#1;emph,#2;verb,#3} }
2746 \cs_new_protected:Npn \eb_define_link_color:n #1
2747 { \definecolorset{HTML}{ctex@}{}{link,#1;url,#1;cite,#1} }
2748 \cs_new_protected:Npn \eb_define_theme_color:n #1
2749 { \definecolorset{HTML}{ctex@}{}{frame,#1;emph,#1;verb,#1} }
2750 \cs_new_protected:Npn \DeclareLinkColor #1#2
2751 { \ctex_define:nx { ref } { \eb_link_color_set:nn {#1} {#2} } }
2752 \cs_new_protected:Npn \DeclareThemeColor #1#2
2753 { \ctex_define:nx { tools } { \eb_theme_color_set:nn {#1} {#2} } }
2754 \cs_new_protected:Npn \eb_color_assign_cmd_set:nn #1#2
2755 {
2756 \cs_new:cpn { eb_#2_color_set:nn } ##1##2
2757 {
2758 #1/##1 .code:n =
2759 {
2760 \use:c { eb_define_#2_color:nnn }
2761 { \clist_item:nn {##2} { 1 } }
2762 { \clist_item:nn {##2} { 2 } }
2763 { \clist_item:nn {##2} { 3 } }
2764 }
2765 }
2766 }
2767 \clist_map_inline:nn
2768 {
2769 { linkcolor } { link },
2770 { color } { theme }
2771 }
2772 { \eb_color_assign_cmd_set:nn #1 }
2773 \clist_map_inline:nn
2774 {
2775 { fresh } { 62d71f,0000b2,005752 },
2776 { cutepink } { ea4492,ad3ccc,57b5e5 },
2777 { navyblue } { 000080,4ec9ea,eb6877 },
2778 { crimson } { dc143c,00c1c9,afcd20 }
2779 }
2780 { \DeclareLinkColor #1 }
2781 \ctex_define:nn { ref }
2782 {
2783 linkcolor .choice:,
2784 linkcolor .value_required:n = true,
2785 linkcolor .initial:n = navyblue,
2786 linkcolor-every .code:n = \eb_define_link_color:n {#1}
2787 }
2788 \clist_map_inline:nn
2789 {
2790 { none } { 000000,000000,000000 },
2791 { seaside } { 333fb2,9932cc,09cc00 },
2792 { energy } { f39800,00a0e9,893895 },
2793 { cyberpunk } { 601986,eb6877,a4005b }
2794 }
2795 { \DeclareThemeColor #1 }
2796 \ctex_define:nn { tools }
2797 {
2798 color .choice:,
2799 color .value_required:n = true,
2800 color .initial:n = none,
2801 color-every .code:n = \eb_define_theme_color:n {#1}
2802 }
2803
2804 \cs_new_protected:Npn \eb_link_border_set:n #1
2805 {
2806 \hypersetup{colorlinks = false}
2807 \def\@pdfborder{#1}
2808 }
2809 \cs_new_protected:Npn \eb_link_colors_set:
2810 { \hypersetup{colorlinks} }
2811 \cs_new_protected:Npn \eb_link_toc_set:n #1
2812 { \hypersetup{linktoc = #1} }
2813 \ctex_define:nn { ref }
2814 {
2815 linktype .choice:,
2816 linktype .value_required:n = true,
2817 linktype/edge .code:n = \eb_link_border_set:n { 0~0~1 },
2818 linktype/none .code:n = \eb_link_border_set:n { 0~0~0 },
2819 linktype/colors .code:n = \eb_link_colors_set:,
2820 linktype/various .meta:n = linktype/colors,
2821 linktype .initial:n = edge,
2822 linktoc .choice:,
2823 linktoc .value_required:n = true,
2824 linktoc/unknown .code:n = \eb_link_toc_set:n {#1},
2825 linktoc .initial:n = all,
2826 unknown .code:n = \exp_args:Nx \hypersetup { \eb_unknown_kv_handle: },
2827 unknown .default:V = \c_novalue_tl
2828 }
2829
2830 \cs_new_protected:Npn \eb_allow_url_break:
2831 {
2832 \eb_appto_cmd:nn { UrlBreaks }
2833 {
2834 \UrlOrds
2835 \tl_map_function:NN \c__eb_url_break_points_tl \do
2836 }
2837 }
2838 \tl_const:Nn \c__eb_url_break_points_tl
2839 {
2840 ABCDEFGHIJKLMNOPQRSTUVWXYZ
2841 abcdefghijklmnopqrstuvwxyz
2842 0123456789
2843 }
2844 \ctex_at_end_preamble:n
2845 {
2846 \RequirePackage{hyperref}
2847 \urlstyle{same}
2848 \eb_allow_url_break:
2849 \hypersetup
2850 {
2851 linkcolor = ctex@link,linkbordercolor = ctex@link,
2852 urlcolor = ctex@url,urlbordercolor = ctex@url,
2853 citecolor = ctex@cite,citebordercolor = ctex@cite,
2854 bookmarksnumbered = true
2855 }
2856 \exp_args:NV \hypersetup \l__eb_hyperref_options_clist
2857 }
2858
2859 \cs_set_eq:NN \eb@labelformat@save \labelformat
2860 \cs_set_protected:Npn \labelformat #1#2
2861 { \AfterPreamble{\eb@labelformat@save{#1}{#2}} }
2862 \AtBeginDocument
2863 {
2864 \IfPackageLoadedTF{cleveref}{}
2865 {
2866 \labelformat{part}{\CTEXthepart}
2867 \labelformat{chapter}{\CTEXthechapter}
2868 \labelformat{figure}{\figurename~#1}
2869 \labelformat{table}{\tablename~#1}
2870 \labelformat{lstlisting}{\lstlistingname~#1}
2871 \tl_if_eq:NnTF \l__ctex_scheme_tl { chinese }
2872 {
2873 \labelformat{section}{节#1}
2874 \labelformat{subsection}{小节#1}
2875 }
2876 {
2877 \labelformat{section}{Section~#1}
2878 \labelformat{subsection}{Subsection~#1}
2879 }
2880 }
2881 }
2882 \ctex_define:n
2883 {
2884 listlstlistingname .tl_set:N = \listlstlistingname,
2885 lstlistingname .tl_set:N = \lstlistingname,
2886 listtheoremname .tl_set:N = \listtheoremname
2887 }
2888 \tl_if_eq:NnTF \l__ctex_scheme_tl { chinese }
2889 {
2890 \keys_set_known:nn { ctex }
2891 {
2892 contentsname = 目\hspace{1em}录,
2893 listfigurename = 插图清单,
2894 listtablename = 附表清单,
2895 listlstlistingname = 代码清单,
2896 lstlistingname = 代码,
2897 listtheoremname = 定理清单
2898 }
2899 \ctex_at_end_package:nn { keytheorems }
2900 { \keytheoremlistset{title = 定理清单} }
2901 }
2902 {
2903 \keys_set_known:nn { ctex }
2904 {
2905 listlstlistingname = List~of~Codes,
2906 lstlistingname = Code
2907 }
2908 }
2909
2910 \cs_if_exist:NF \DeclareObjectType
2911 { \RequirePackage{xtemplate} }
2912 \DeclareObjectType{easybook}{0}
2913 \DeclareTemplateInterface{easybook}{cover}{0}
2914 {
2915 content : tokenlist = \c_empty_tl,
2916 beforecode : tokenlist = \c_empty_tl,
2917 aftercode : tokenlist = \c_empty_tl,
2918 align : choice {l,r,c,n} = c
2919 }
2920 \DeclareTemplateCode{easybook}{cover}{0}
2921 {
2922 content = \l__eb_cover_content_tl,
2923 beforecode = \l__eb_cover_before_code_tl,
2924 aftercode = \l__eb_cover_after_code_tl,
2925 align =
2926 {
2927 l = \cs_set_eq:NN \eb_cover_align: \raggedright,
2928 r = \cs_set_eq:NN \eb_cover_align: \raggedleft,
2929 c = \cs_set_eq:NN \eb_cover_align: \centering,
2930 n = \cs_set:Npn \eb_cover_align: { }
2931 }
2932 }
2933 {
2934 \AssignTemplateKeys
2935 \tl_use:N \l__eb_cover_before_code_tl
2936 \group_begin:
2937 \eb_cover_align:
2938 \tl_use:N \l__eb_cover_content_tl
2939 \tex_par:D
2940 \group_end:
2941 \tl_use:N \l__eb_cover_after_code_tl
2942 }
2943 \DeclareInstance{easybook}{top}{cover}{}
2944 \DeclareInstance{easybook}{bottom}{cover}{}
2945 \DeclareInstance{easybook}{middle}{cover}
2946 {
2947 content =
2948 {
2949 \notbool{@titlepage}
2950 {
2951 \renewcommand{\theupfootnote}{\@fnsymbol\c@footnote}
2952 \renewcommand{\thefootnote}{\@fnsymbol\c@footnote}
2953 \let\footnote\thanks
2954 }
2955 {}
2956 \bgroup\sffamily\LARGE\@title\par\egroup
2957 \notbool{@titlepage}{\vskip 1.5em}{\vskip 3em}
2958 \bgroup\large
2959 \begin{tabular}[t]{c}
2960 \@author
2961 \end{tabular}\par\egroup
2962 \notbool{@titlepage}{\vskip 0.75em}{\vskip 1.5em}
2963 \bgroup\large\@date\par\egroup
2964 \notbool{@titlepage}{\vskip 1.5em}{}
2965 \@thanks
2966 },
2967 beforecode =
2968 {
2969 \ifbool{@titlepage}
2970 {
2971 \begin{titlepage}
2972 \let\footnotesize\small
2973 \let\footnoterule\relax
2974 \let\footnote\thanks
2975 \null\vfil\vskip 60\p@
2976 }
2977 {\null\vskip 20\p@}
2978 },
2979 aftercode =
2980 {
2981 \ifbool{@titlepage}
2982 {
2983 \vfil\null
2984 \end{titlepage}
2985 }
2986 {\thispagestyle{plain}}
2987 \setcounter{footnote}{0}
2988 }
2989 }
2990 \keys_define:nn { eb/cover }
2991 {
2992 title .tl_set:N = \@title,
2993 author .tl_set:N = \@author,
2994 date .tl_set:N = \@date
2995 }
2996 \RenewDocumentCommand{\maketitle}{+O{}}
2997 {
2998 \keys_set:nn { eb/cover } {#1}
2999 \UseInstance{easybook}{top}
3000 \UseInstance{easybook}{middle}
3001 \UseInstance{easybook}{bottom}
3002 }
3003 %</package>
3004 %<*tcolorbox>
3005 \ProvidesExplFile{eb-tcolorbox.cfg}{2025/08/01}{2025ae}
3006 {Customization of tcolorbox for easybook}
3007
3008 \cs_set_protected:Npn \addtotcbstyle #1#2
3009 { \tcbset{#1/.append~style = {#2}} }
3010 \cs_set_protected:Npn \deftcbstyle #1#2
3011 { \tcbset{#1/.style = {#2}} }
3012
3013 \deftcbstyle{tc-easyboxi}
3014 {
3015 enhanced~jigsaw,
3016 center~title,
3017 left = 8pt,right = 8pt,
3018 coltitle = black,colframe = black,
3019 top = 0.5\baselineskip,bottom = 0.5\baselineskip,
3020 middle = 0.5\baselineskip,
3021 toptitle = 0.5\baselineskip,
3022 titlerule = 0pt,
3023 beforeafter~skip = 0.5\baselineskip
3024 }
3025 \deftcbstyle{tc-easyboxii}
3026 {
3027 enhanced~jigsaw,
3028 frame~hidden,boxrule = 0pt,
3029 left = 10pt,
3030 middle = 0.5\baselineskip,bottomtitle = 0.5\baselineskip,
3031 beforeafter~skip = 0.5\baselineskip
3032 }
3033 \deftcbstyle{tc-eboxi}{on~line,blank}
3034 \deftcbstyle{tc-eboxii}
3035 {
3036 standard~jigsaw,on~line,
3037 top = 3pt,bottom = 3pt,left = 3pt,right = 3pt,
3038 boxrule = 0.4pt,opacityback = 0.2
3039 }
3040 \tcbset
3041 {
3042 breakable,
3043 pad~at~break* = 0.5\baselineskip,
3044 sharpish~corners,
3045 fonttitle = \sffamily,
3046 colframe = black,
3047 boxsep = 0pt,
3048 boxrule = 0.5pt
3049 }
3050
3051 \DeclareTColorBox{easyboxi}{sO{LemonChiffon}d()O{}}
3052 {
3053 IfBooleanF = {#1}{frame~hidden,boxrule = 0pt},
3054 IfValueT = {#3}{title = #3},
3055 colback = #2,colbacktitle = #2,
3056 tc-easyboxi,#4
3057 }
3058 \DeclareTColorBox{easyboxii}{sO{RoyalBlue}D(){}O{}}
3059 {
3060 borderline~west = {3pt}{0pt}{#2},
3061 IfBooleanTF = {#1}
3062 {
3063 colback = white,
3064 top = 0pt,bottom = 0pt,right = 0pt,
3065 pad~at~break* = 0pt
3066 }{
3067 colback = #2,colbacktitle = #2,
3068 opacityback = 0.2,opacitybacktitle = 0.2,
3069 top = \tl_if_blank:nTF {#3} { 0.5\baselineskip } { 0pt },
3070 bottom = 0.5\baselineskip,
3071 toptitle = 0.5\baselineskip,
3072 right = 8pt
3073 },
3074 title = #3,coltitle = #2,
3075 tc-easyboxii,#4
3076 }
3077 \DeclareTotalTCBox{\eboxi}{O{Yellow}mO{}}
3078 {
3079 fuzzy~halo = 2pt~with~#1,
3080 tc-eboxi,#3
3081 }{#2}
3082 \DeclareTotalTCBox{\eboxii}{O{Green}mO{}}
3083 {
3084 colback = #1,colframe = black,
3085 tc-eboxii,#3
3086 }{#2}
3087 %</tcolorbox>