Debian Codegraph @

texmf-dist/tex/latex/ctex/heading/ctex-heading-book.def

raw
1 %%
2 %% This is file `ctex-heading-book.def',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% ctex.dtx (with options: `heading,book')
8 %%
9 %% Copyright (C) 2003--2022
10 %% CTEX.ORG and any individual authors listed in the documentation.
11 %% ---------------------------------------------------------------------
12 %%
13 %% This work may be distributed and/or modified under the
14 %% conditions of the LaTeX Project Public License, either
15 %% version 1.3c of this license or (at your option) any later
16 %% version. This version of this license is in
17 %% http://www.latex-project.org/lppl/lppl-1-3c.txt
18 %% and the latest version of this license is in
19 %% http://www.latex-project.org/lppl.txt
20 %% and version 1.3 or later is part of all distributions of
21 %% LaTeX version 2005/12/01 or later.
22 %%
23 %% This work has the LPPL maintenance status "maintained".
24 %%
25 %% ---------------------------------------------------------------------
26 %%
27 \GetIdInfo$Id: ctex.dtx 13a2256 2022-07-14 18:54:09 +0800 Qing Lee <[email protected]> $
28 {Heading modification for book (CTEX)}
29 \ProvidesExplFile{ctex-book.def}
30 {\ExplFileDate}{2.5.10}{\ExplFileDescription}
31 \seq_const_from_clist:Nn \c__ctex_section_headings_seq
32 { section , subsection , subsubsection , paragraph , subparagraph }
33 \seq_new:N \c__ctex_headings_seq
34 \seq_gset_eq:NN \c__ctex_headings_seq \c__ctex_section_headings_seq
35 \seq_gput_left:Nn \c__ctex_headings_seq { chapter }
36 \seq_gput_left:Nn \c__ctex_headings_seq { part }
37 \cs_new_protected:Npn \__ctex_initial_heading:n #1
38 {
39 \tl_new:c { CTEX@pre#1 }
40 \tl_new:c { CTEX@post#1 }
41 \tl_const:cx { CTEXthe#1 }
42 {
43 \exp_not:c { CTEX@pre#1 }
44 \exp_not:c { CTEX@the#1 }
45 \exp_not:c { CTEX@post#1 }
46 }
47 \tl_const:cx { CTEX@#1name }
48 {
49 \group_begin:
50 \exp_not:c { CTEX@#1@nameformat }
51 {
52 \exp_not:c { CTEX@pre#1 }
53 \exp_not:N \tl_if_empty:NTF
54 \exp_not:c { CTEX@#1@numberformat }
55 { \exp_not:c { CTEX@the#1 } }
56 {
57 \group_begin:
58 \exp_not:c { CTEX@#1@numberformat }
59 \exp_not:c { CTEX@the#1 }
60 \group_end:
61 }
62 \exp_not:c { CTEX@post#1 }
63 }
64 \group_end:
65 }
66 }
67 \cs_new_protected:Npn \__ctex_def_heading_keys:n #1
68 {
69 \exp_args:NNe \tl_put_right:Nn \l__ctex_tmp_tl
70 {
71 #1 .meta:nn = { ctex / #1 } { ##1 } ,
72 #1 / name .code:n =
73 { \ctex_assign_heading_name:nn {#1} { ##1 } } ,
74 #1 / number .tl_set:N = \exp_not:c { CTEX@the#1 } ,
75 #1 / beforeskip .tl_set:N = \exp_not:c { CTEX@#1@beforeskip } ,
76 #1 / afterskip .tl_set:N = \exp_not:c { CTEX@#1@afterskip} ,
77 #1 / indent .tl_set:N = \exp_not:c { CTEX@#1@indent } ,
78 #1 / numbering .bool_set:N = \exp_not:c { CTEX@#1@numbering } ,
79 #1 / numbering .initial:n = true ,
80 #1 / beforeskip .initial:n = \c_zero_skip ,
81 #1 / afterskip .initial:n = \c_zero_skip ,
82 #1 / indent .initial:n = \c_zero_dim ,
83 #1 / beforeskip .value_required:n = true ,
84 #1 / afterskip .value_required:n = true ,
85 #1 / indent .value_required:n = true ,
86 #1 / afterindent .bool_set:N = \exp_not:c { CTEX@#1@afterindent } ,
87 #1 / fixskip .bool_set:N = \exp_not:c { CTEX@#1@fixskip } ,
88 #1 / hang .bool_set:N = \exp_not:c { CTEX@#1@hang } ,
89 #1 / hang .initial:n = true ,
90 #1 / runin .bool_set:N = \exp_not:c { CTEX@#1@runin } ,
91 #1 / tocline .cs_set:Np = \exp_not:c { CTEX@#1@tocline } ##1##2 ,
92 \__ctex_plus_key_aux:nn {#1} { break } ,
93 \__ctex_plus_key_aux:nn {#1} { format } ,
94 \__ctex_plus_key_aux:nn {#1} { nameformat } ,
95 \__ctex_plus_key_aux:nn {#1} { numberformat } ,
96 \__ctex_plus_key_aux:nn {#1} { titleformat } ,
97 \__ctex_plus_key_aux:nn {#1} { aftername } ,
98 \__ctex_plus_key_aux:nn {#1} { aftertitle } ,
99 }
100 }
101 \cs_new:Npn \__ctex_plus_key_aux:nn #1#2
102 {
103 #1 / #2 .tl_set:N = \exp_not:c { CTEX@#1@#2 } ,
104 #1 / #2 + .code:n =
105 { \tl_put_right:Nn \exp_not:c { CTEX@#1@#2 } { ##1 } } ,
106 #1 / #2 ~ + .code:n =
107 { \tl_put_right:Nn \exp_not:c { CTEX@#1@#2 } { ##1 } }
108 }
109 \NewDocumentCommand \ctex_assign_heading_name:nn
110 { m > { \SplitArgument { 1 } { , } } +m }
111 { \__ctex_assign_heading_name:nnn {#1} #2 }
112 \cs_new_protected:Npn \__ctex_assign_heading_name:nnn #1#2#3
113 {
114 \tl_set:cn { CTEX@pre#1 } {#2}
115 \tl_if_novalue:nTF {#3}
116 { \tl_clear:c { CTEX@post#1 } }
117 { \tl_set:cn { CTEX@post#1 } {#3} }
118 }
119 \group_begin:
120 \tl_set:Nn \l__ctex_tmp_tl
121 {
122 part / pagestyle .tl_set:N = \CTEX@part@pagestyle ,
123 chapter / pagestyle .tl_set:N = \CTEX@chapter@pagestyle ,
124 chapter / lofskip .tl_set:N = \CTEX@chapter@lofskip ,
125 chapter / lotskip .tl_set:N = \CTEX@chapter@lotskip ,
126 chapter / lofskip .initial:n = \c_zero_skip ,
127 chapter / lotskip .initial:n = \c_zero_skip ,
128 chapter / lofskip .value_required:n = true ,
129 chapter / lotskip .value_required:n = true ,
130 }
131 \seq_map_inline:Nn \c__ctex_headings_seq
132 {
133 \__ctex_initial_heading:n {#1}
134 \__ctex_def_heading_keys:n {#1}
135 }
136 \exp_args:NNo \group_end: \ctex_define:n { \l__ctex_tmp_tl }
137 \cs_new_protected:Npn \CTEX@heading@format@initial
138 {
139 \normalfont
140 \tl_clear:N \l__ctex_autoindent_tl
141 \int_set:Nn \tex_interlinepenalty:D { 10 000 }
142 \tex_noindent:D
143 }
144 \cs_new_protected:Npn \ctex_indent_box:n #1
145 {
146 \dim_set:Nn \tex_parindent:D {#1}
147 \__ctex_insert_indent:
148 }
149 \cs_new_protected:Npn \__ctex_insert_indent:
150 {
151 \dim_compare:nNnF \tex_parindent:D = \c_zero_dim
152 { \tex_indent:D }
153 }
154 \cs_new_eq:NN \CTEX@indentbox \ctex_indent_box:n
155 \cs_new_protected:Npn \CTEX@fixtopskip
156 {
157 \CTEX@fixheadingskip
158 \dim_compare:nNnF \tex_pagegoal:D < \c_max_dim
159 { \skip_sub:Nn \l__ctex_heading_skip { \tex_topskip:D } }
160 }
161 \cs_new_protected:Npn \CTEX@fixheadingskip
162 {
163 \par
164 \dim_set:Nn \tex_prevdepth:D { -1000pt }
165 \skip_sub:Nn \l__ctex_heading_skip { \tex_parskip:D }
166 }
167 \skip_new:N \l__ctex_heading_skip
168 \cs_new_protected:Npn \CTEX@setheadingskip
169 { \skip_set:Nn \l__ctex_heading_skip }
170 \cs_new_eq:NN \CTEX@headingskip \l__ctex_heading_skip
171 \cs_new_protected:Npn \CTEX@setthispagestyle #1
172 { \exp_args:Ne \thispagestyle { \use:c { CTEX@#1@pagestyle } } }
173 \ProvideDocumentCommand \partmark { m }
174 { \markboth { } { } }
175 \cs_new_eq:NN \CTEXifname \use_ii:nn
176 \cs_new_protected:Npn \CTEX@ifnametrue
177 { \cs_set_eq:NN \CTEXifname \use_i:nn }
178 \cs_new_protected:Npn \CTEX@ifnamefalse
179 { \cs_set_eq:NN \CTEXifname \use_ii:nn }
180 \cs_new_protected:Npn \CTEX@addloflotskip #1
181 {
182 \skip_set:Nn \l__ctex_heading_skip { \use:c { CTEX@#1@lofskip } }
183 \skip_if_eq:nnF { \l__ctex_heading_skip } { \c_zero_skip }
184 {
185 \addtocontents { lof }
186 { \protect \addvspace { \skip_use:N \l__ctex_heading_skip } }
187 }
188 \skip_set:Nn \l__ctex_heading_skip { \use:c { CTEX@#1@lotskip } }
189 \skip_if_eq:nnF { \l__ctex_heading_skip } { \c_zero_skip }
190 {
191 \addtocontents { lot }
192 { \protect \addvspace { \skip_use:N \l__ctex_heading_skip } }
193 }
194 }
195 \cs_new_protected:Npn \CTEX@addtocline #1#2
196 { \addcontentsline { toc } {#1} { \use:c { CTEX@#1@tocline } {#1} {#2} } }
197 \renewcommand\part{%
198 \CTEX@part@break
199 \CTEX@setthispagestyle{part}%
200 \if@twocolumn
201 \onecolumn
202 \@tempswatrue
203 \else
204 \@tempswafalse
205 \fi
206 \CTEX@setheadingskip \CTEX@part@beforeskip
207 \ifodd \CTEX@part@fixskip \CTEX@fixtopskip \fi
208 \vspace*{\CTEX@headingskip}%
209 \secdef\@part\@spart}
210 \def\@part[#1]#2{%
211 \ifnum \c@secnumdepth >-2\relax
212 \ifodd \CTEX@part@numbering
213 \CTEX@ifnametrue
214 \refstepcounter{part}%
215 \else
216 \CTEX@ifnamefalse
217 \CTEX@makeanchor{part*}%
218 \fi
219 \else
220 \CTEX@ifnamefalse
221 \CTEX@makeanchor{part*}%
222 \fi
223 \CTEX@gettitle{#1}%
224 \CTEX@addtocline{part}{#1}%
225 \partmark{#1}%
226 \begingroup
227 \CTEX@heading@format@initial
228 \CTEX@part@format{%
229 \CTEX@headinghang{part}%
230 {\CTEXifname{\CTEX@partname\CTEX@part@aftername}{}}%
231 \CTEX@part@titleformat{#2}%
232 \CTEX@part@aftertitle}\par
233 \endgroup
234 \@endpart}
235 \def\@spart#1{%
236 \CTEX@ifnamefalse
237 \CTEX@makeanchor@spart{part*}%
238 \CTEX@gettitle{#1}%
239 \begingroup
240 \CTEX@heading@format@initial
241 \CTEX@part@format{%
242 \CTEX@headinghang{part}{}%
243 \CTEX@part@titleformat{#1}%
244 \CTEX@part@aftertitle}\par
245 \endgroup
246 \@endpart}
247 \def\@endpart{%
248 \CTEX@setheadingskip \CTEX@part@afterskip
249 \ifodd \CTEX@part@fixskip \CTEX@fixheadingskip \fi
250 \vskip \CTEX@headingskip
251 \newpage
252 \if@twoside
253 \if@openright
254 \null
255 \thispagestyle{empty}%
256 \newpage
257 \fi
258 \fi
259 \if@tempswa
260 \twocolumn
261 \fi}
262 \renewcommand\chapter{%
263 \CTEX@chapter@break
264 \CTEX@setthispagestyle{chapter}%
265 \global\@topnum\z@
266 \ifodd \CTEX@chapter@afterindent
267 \@afterindenttrue
268 \else
269 \@afterindentfalse
270 \fi
271 \secdef\@chapter\@schapter}
272 \def\@chapter[#1]#2{%
273 \ifnum \c@secnumdepth >\m@ne
274 \if@mainmatter
275 \ifodd \CTEX@chapter@numbering
276 \CTEX@ifnametrue
277 \refstepcounter{chapter}%
278 \typeout{\CTEXthechapter}%
279 \else
280 \CTEX@ifnamefalse
281 \CTEX@makeanchor{\Hy@chapapp*}%
282 \fi
283 \else
284 \CTEX@ifnamefalse
285 \CTEX@makeanchor@chapter{\Hy@chapapp*}%
286 \fi
287 \else
288 \CTEX@ifnamefalse
289 \CTEX@makeanchor@chapter{\Hy@chapapp*}%
290 \fi
291 \CTEX@gettitle{#1}%
292 \CTEX@addtocline{chapter}{#1}%
293 \chaptermark{#1}%
294 \CTEX@addloflotskip{chapter}%
295 \if@twocolumn
296 \@topnewpage[\@makechapterhead{#2}]%
297 \else
298 \@makechapterhead{#2}%
299 \@afterheading
300 \fi}
301 \def\@schapter#1{%
302 \CTEX@ifnamefalse
303 \CTEX@makeanchor@schapter{\Hy@chapapp*}%
304 \CTEX@gettitle{#1}%
305 \if@twocolumn
306 \@topnewpage[\@makeschapterhead{#1}]%
307 \else
308 \@makeschapterhead{#1}%
309 \@afterheading
310 \fi}
311 \def\@makechapterhead#1{%
312 \CTEX@setheadingskip \CTEX@chapter@beforeskip
313 \ifodd \CTEX@chapter@fixskip \CTEX@fixtopskip \fi
314 \vspace*{\CTEX@headingskip}%
315 \begingroup
316 \CTEX@heading@format@initial
317 \CTEX@chapter@format{%
318 \CTEX@headinghang{chapter}%
319 {\CTEXifname{\CTEX@chaptername\CTEX@chapter@aftername}{}}%
320 \CTEX@chapter@titleformat{#1}%
321 \CTEX@chapter@aftertitle}\par
322 \endgroup
323 \nobreak
324 \CTEX@setheadingskip \CTEX@chapter@afterskip
325 \ifodd \CTEX@chapter@fixskip \CTEX@fixheadingskip \fi
326 \vskip \CTEX@headingskip}
327 \def\@makeschapterhead#1{%
328 \CTEX@setheadingskip \CTEX@chapter@beforeskip
329 \ifodd \CTEX@chapter@fixskip \CTEX@fixtopskip \fi
330 \vspace*{\CTEX@headingskip}%
331 \begingroup
332 \CTEX@heading@format@initial
333 \CTEX@chapter@format{%
334 \CTEX@headinghang{chapter}{}%
335 \CTEX@chapter@titleformat{#1}%
336 \CTEX@chapter@aftertitle}\par
337 \endgroup
338 \nobreak
339 \CTEX@setheadingskip \CTEX@chapter@afterskip
340 \ifodd \CTEX@chapter@fixskip \CTEX@fixheadingskip \fi
341 \vskip \CTEX@headingskip}
342 \def\@startsection#1#2#3#4#5#6{%
343 \if@noskipsec \leavevmode \fi
344 \par
345 \CTEX@update@sectionformat@n{#1}%
346 \ifodd \CTEX@afterindent
347 \@afterindenttrue
348 \else
349 \@afterindentfalse
350 \fi
351 \if@nobreak
352 \everypar{}%
353 \else
354 \csname CTEX@#1@break\endcsname
355 \CTEX@setheadingskip{#4}%
356 \ifodd \CTEX@fixskip \CTEX@fixheadingskip \fi
357 \addvspace \CTEX@headingskip
358 \fi
359 \@ifstar
360 {\CTEX@makeanchor@ssect{#1*}\@ssect{#3}{#4}{#5}{#6}}%
361 {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
362 \def\@seccntformat#1{%
363 \csname CTEX@#1name\endcsname
364 \csname CTEX@#1@aftername\endcsname}
365 \def\@sect#1#2#3#4#5#6[#7]#8{%
366 \ifnum #2>\c@secnumdepth
367 \CTEX@ifnamefalse
368 \CTEX@makeanchor@sect{#1*}%
369 \let\@svsec\@empty
370 \else
371 \ifodd \csname CTEX@#1@numbering\endcsname
372 \CTEX@ifnametrue
373 \refstepcounter{#1}%
374 \protected@edef\@svsec{\@seccntformat{#1}\relax}%
375 \else
376 \CTEX@ifnamefalse
377 \CTEX@makeanchor{#1*}%
378 \let\@svsec\@empty
379 \fi
380 \fi
381 \CTEX@gettitle{#7}%
382 \unless \ifodd \CTEX@runin
383 \begingroup
384 \CTEX@heading@format@initial
385 #6{%
386 \CTEX@sectionhang{#3}{\@svsec}%
387 \csname CTEX@#1@titleformat\endcsname{#8}%
388 \csname CTEX@#1@aftertitle\endcsname}\par
389 \endgroup
390 \csname #1mark\endcsname{#7}%
391 \CTEX@addtocline{#1}{#7}%
392 \else
393 \def\@svsechd{%
394 #6{%
395 {\CTEX@indentbox{#3}}\@svsec
396 \csname CTEX@#1@titleformat\endcsname{#8}%
397 \csname CTEX@#1@aftertitle\endcsname}%
398 \csname #1mark\endcsname{#7}%
399 \CTEX@addtocline{#1}{#7}}%
400 \fi
401 \@xsect{#5}}
402 \def\@ssect#1#2#3#4#5{%
403 \CTEX@ifnamefalse
404 \CTEX@gettitle{#5}%
405 \unless \ifodd \CTEX@runin
406 \begingroup
407 \CTEX@heading@format@initial
408 #4{%
409 \CTEX@sectionhang{#1}{}%
410 \CTEX@titleformat@n{#5}%
411 \CTEX@aftertitle}\par
412 \endgroup
413 \else
414 \def\@svsechd{#4{{\CTEX@indentbox{#1}}%
415 \CTEX@titleformat@n{#5}\CTEX@aftertitle}}%
416 \fi
417 \@xsect{#3}}
418 \def\@xsect#1{%
419 \unless \ifodd \CTEX@runin
420 \par \nobreak
421 \CTEX@setheadingskip{#1}%
422 \ifodd \CTEX@fixskip \CTEX@fixheadingskip \fi
423 \vskip \CTEX@headingskip
424 \@afterheading
425 \else
426 \@nobreakfalse
427 \global\@noskipsectrue
428 \everypar{%
429 \if@noskipsec
430 \global\@noskipsecfalse
431 {\setbox\z@\lastbox}%
432 \clubpenalty\@M
433 \begingroup \@svsechd \endgroup
434 \unskip
435 \CTEX@heading@glue{#1}%
436 \else
437 \clubpenalty \@clubpenalty
438 \everypar{}%
439 \fi}%
440 \fi
441 \ignorespaces}
442 \cs_new_protected:Npn \CTEX@headinghang #1
443 {
444 \ctex_heading_hang:cnn
445 { CTEX@#1@hang }
446 { \use:c { CTEX@#1@indent } }
447 }
448 \cs_new_protected:Npn \CTEX@sectionhang
449 { \ctex_heading_hang:Nnn \CTEX@hang }
450 \cs_new_protected:Npn \ctex_heading_hang:Nnn #1#2#3
451 {
452 \dim_set:Nn \tex_parindent:D {#2}
453 \bool_if:NTF #1
454 { \ctex_hang_from:n }
455 { \use:n }
456 { \__ctex_insert_indent: #3 }
457 }
458 \cs_new_protected:Npn \ctex_hang_from:n #1
459 {
460 \tex_noindent:D
461 \hbox_set:Nn \l__ctex_tmp_box {#1}
462 \tex_hangindent:D = \box_wd:N \l__ctex_tmp_box
463 \box_use_drop:N \l__ctex_tmp_box
464 }
465 \cs_generate_variant:Nn \ctex_heading_hang:Nnn { c }
466 \cs_new_protected:Npn \ctex_heading_glue:n #1
467 {
468 \group_begin:
469 \skip_set:Nn \l__ctex_heading_skip {#1}
470 \dim_compare:nNnF \l__ctex_heading_skip = \c_zero_dim
471 { \skip_horizontal:N \l__ctex_heading_skip }
472 \group_end:
473 }
474 \cs_new_eq:NN \CTEX@heading@glue \ctex_heading_glue:n
475 \cs_new_protected:Npn \CTEX@update@sectionformat@n #1
476 {
477 \cs_set_eq:Nc \CTEX@titleformat@n { CTEX@#1@titleformat }
478 \cs_set_eq:Nc \CTEX@aftertitle { CTEX@#1@aftertitle }
479 \cs_set_eq:Nc \CTEX@afterindent { CTEX@#1@afterindent }
480 \cs_set_eq:Nc \CTEX@fixskip { CTEX@#1@fixskip }
481 \cs_set_eq:Nc \CTEX@hang { CTEX@#1@hang }
482 \cs_set_eq:Nc \CTEX@runin { CTEX@#1@runin }
483 }
484 \cs_new_eq:NN \CTEX@titleformat@n \use:n
485 \cs_new_eq:NN \CTEX@aftertitle \prg_do_nothing:
486 \cs_new_eq:NN \CTEX@afterindent \c_true_bool
487 \cs_new_eq:NN \CTEX@fixskip \c_false_bool
488 \cs_new_eq:NN \CTEX@hang \c_true_bool
489 \cs_new_eq:NN \CTEX@runin \c_false_bool
490 \cs_new:Npn \CTEX@part@tocline #1#2
491 {
492 \CTEXifname
493 { \CTEXthepart \hspace { 1em } }
494 { }
495 #2
496 }
497 \cs_new:Npn \CTEX@chapter@tocline #1#2
498 {
499 \CTEXifname
500 { \protect \numberline { \CTEXthechapter \hspace { .3em } } }
501 { }
502 #2
503 }
504 \cs_new:Npn \CTEXnumberline #1
505 {
506 \CTEXifname
507 { \protect \numberline { \use:c { CTEXthe #1 } } }
508 { }
509 }
510 \int_zero:N \l__ctex_tmp_int
511 \seq_map_inline:Nn \c__ctex_section_headings_seq
512 {
513 \int_incr:N \l__ctex_tmp_int
514 \cs_gset_protected:cpx {#1}
515 {
516 \exp_not:N \@startsection {#1}
517 { \int_use:N \l__ctex_tmp_int }
518 { \exp_not:c { CTEX@#1@indent } }
519 { \exp_not:c { CTEX@#1@beforeskip } }
520 { \exp_not:c { CTEX@#1@afterskip } }
521 { \exp_not:N \normalfont \exp_not:c { CTEX@#1@format } }
522 }
523 \cs_new:cpn { CTEX@#1@tocline } ##1##2
524 { \CTEXnumberline { ##1 } ##2 }
525 }
526 \ctex_define:n
527 {
528 appendix .meta:nn = { ctex / appendix } {#1} ,
529 appendix / name .code:n =
530 { \ctex_assign_heading_name:nn { appendix } {#1} } ,
531 appendix / number .tl_set:N = \CTEX@appendix@number ,
532 appendix / numbering .bool_set:N = \CTEX@appendix@numbering ,
533 appendix / numbering .initial:n = true
534 }
535 \tl_new:N \CTEX@preappendix
536 \tl_new:N \CTEX@postappendix
537 \cs_new_eq:NN \CTEX@save@appendix \appendix
538 \cs_gset_protected:Npn \appendix
539 {
540 \CTEX@save@appendix
541 \gdef \CTEX@prechapter { \CTEX@preappendix }
542 \gdef \CTEX@thechapter { \CTEX@appendix@number }
543 \gdef \CTEX@postchapter { \CTEX@postappendix }
544 \gdef \CTEX@chapter@numbering { \CTEX@appendix@numbering }
545 }
546 \cs_new_protected:Npn \CTEX@makeanchor #1
547 { }
548 \seq_const_from_clist:Nn \c__ctex_headings_cs_seq
549 { part , spart , chapter , schapter , sect , ssect }
550 \seq_map_inline:Nn \c__ctex_headings_cs_seq
551 {
552 \cs_new_eq:cc { CTEX@ #1 } { @ #1 }
553 \cs_new_eq:cN { CTEX@makeanchor@ #1 } \CTEX@makeanchor
554 }
555 \cs_new_protected:Npn \CTEX@hyperheadinghook
556 {
557 \group_begin:
558 \legacy_if:nTF { Hy@implicit }
559 {
560 \cs_set_eq:NN \H@old@chapter \Hy@org@chapter
561 \seq_map_inline:Nn \c__ctex_headings_cs_seq
562 {
563 \cs_if_eq:ccT { H@old@ ##1 } { CTEX@ ##1 }
564 {
565 \cs_gset_eq:cc { @ ##1 } { CTEX@ ##1 }
566 \cs_gset_eq:cN { CTEX@makeanchor@ ##1 } \CTEX@makeanchor
567 }
568 }
569 }
570 {
571 \seq_map_inline:Nn \c__ctex_headings_cs_seq
572 { \cs_gset_eq:cN { CTEX@makeanchor@ ##1 } \CTEX@makeanchor }
573 }
574 \group_end:
575 }
576 \ctex_at_end_package:nn { hyperref }
577 {
578 \cs_gset_protected:Npn \CTEX@makeanchor #1
579 {
580 \Hy@MakeCurrentHrefAuto {#1}
581 \Hy@raisedlink
582 {
583 \hyper@anchorstart { \@currentHref }
584 \hyper@anchorend
585 }
586 }
587 \CTEX@hyperheadinghook
588 }
589 \cs_new_protected:Npn \CTEX@gettitle #1
590 { }
591 \ctex_at_end_package:nn { nameref }
592 {
593 \cs_gset_protected:Npn \CTEX@gettitle { \NR@gettitle }
594 \seq_map_inline:Nn \c__ctex_headings_cs_seq
595 {
596 \cs_if_eq:ccT { NR@ #1 } { CTEX@ #1 }
597 { \cs_gset_eq:cc { @ #1 } { CTEX@ #1 } }
598 }
599 }
600 \cs_new_protected:Npn \ctex_titlesec_hook:
601 {
602 \@ifpackagewith { titlesec } { explicit }
603 {
604 \cs_set_eq:NN \__ctex_titlesec_format:Nn
605 \__ctex_titlesec_format_explicit:Nn
606 }
607 { }
608 \clist_map_inline:nn
609 { indentafter , noindentafter , indentfirst , nonindentfirst }
610 {
611 \@ifpackagewith { titlesec } { ##1 }
612 {
613 \clist_map_break:n
614 { \cs_set_eq:NN \__ctex_titlesec_hook:n \__ctex_titlesec_format:n }
615 }
616 { }
617 }
618 \seq_map_function:NN \c__ctex_section_headings_seq \__ctex_titlesec_hook:n
619 }
620 \cs_new_protected:Npn \__ctex_titlesec_hook:n #1
621 {
622 \__ctex_titlesec_format:n {#1}
623 \exp_args:Nc \__ctex_titlesec_spacing:Nn { ttls@#1 } {#1}
624 }
625 \cs_new_protected:Npn \__ctex_titlesec_format:n #1
626 {
627 \cs_if_free:cF { ttlf@#1 }
628 { \exp_args:Nc \__ctex_titlesec_format:Nn { ttlf@#1 } {#1} }
629 }
630 \cs_new_protected:Npn \__ctex_titlesec_format:Nn #1#2
631 {
632 \tl_set:Nx #1
633 {
634 \bool_if:cTF { CTEX@#2@runin }
635 { \exp_not:N \ttlh@runin }
636 { \exp_not:N \ttlh@hang }
637 \tl_tail:N #1
638 }
639 }
640 \cs_new_protected:Npn \__ctex_titlesec_format_explicit:Nn #1#2
641 {
642 \cs_set_nopar:Npx #1 ##1
643 {
644 \bool_if:cTF { CTEX@#2@runin }
645 { \exp_not:N \ttlh@runin }
646 { \exp_not:N \ttlh@hang }
647 \exp_args:No \tl_tail:n { #1 { } }
648 }
649 }
650 \cs_new_protected:Npn \__ctex_titlesec_spacing:Nn #1#2
651 { \tl_set:Nx #1 { \exp_after:wN \__ctex_titlesec_spacing:nnnnnn #1 {#2} } }
652 \cs_new:Npn \__ctex_titlesec_spacing:nnnnnn #1#2#3#4#5#6
653 {
654 \exp_not:n { {#1} {#2} {#3} {#4} }
655 { \bool_if:cTF { CTEX@#6@afterindent } { \@ne } { \z@ } }
656 }
657 \@ifpackageloaded { titlesec }
658 { }
659 {
660 \ctex_at_end_package:nn { titlesec }
661 {
662 \@ifpackagewith { titlesec } { loadonly }
663 { }
664 { \ctex_titlesec_hook: }
665 }
666 }
667 \ctex_at_end_package:nn { titlesec }
668 {
669 \tl_set:Nn \ttl@chapterout { \typeout { \CTEXthechapter } }
670 \cs_if_free:NF \ttl@tocpart
671 {
672 \cs_set_protected:Npn \ttl@tocpart
673 { \tl_set:Nn \ttl@a { \CTEXthepart \hspace { 1em } } }
674 }
675 \seq_map_inline:Nn \c__ctex_headings_seq
676 {
677 \cs_if_exist:cF { ttl@toc #1 }
678 {
679 \cs_new_protected:cpx { ttl@toc #1 }
680 {
681 \tl_set:Nn \exp_not:N \ttl@a
682 {
683 \exp_not:N \protect
684 \exp_not:N \numberline { \exp_not:c { CTEXthe #1 } }
685 }
686 }
687 }
688 }
689 }
690 \ctex_at_end_package:nn { titlesec }
691 {
692 \ctex_patch_cmd:Nnn \ttl@labelling
693 { \let \ifttl@toclabel \ifttl@label }
694 {
695 \let \ifttl@toclabel \ifttl@label
696 \CTEX@updatettlifname
697 }
698 \cs_new_protected:Npn \CTEX@updatettlifname
699 { \legacy_if:nTF { ttl@label } { \CTEX@ifnametrue } { \CTEX@ifnamefalse } }
700 }
701 \group_begin:
702 \char_set_catcode_other:N \#
703 \cs_new_protected:Npn \ctex_titleps_hook:
704 {
705 \ctex_patch_cmd:Nnn \ttl@settopmark
706 { \protect \@namedef { the#1 } { \@nameuse { the#1 } } }
707 {
708 \protect \@namedef { the#1 } { \@nameuse { the#1 } }
709 \CTEX@titlepslabel@set {#1}
710 }
711 \ctex_patch_cmd:Nnn \ttl@setsubmark
712 { \protect \@namedef { the#1 } { } }
713 {
714 \protect \@namedef { the#1 } { }
715 \CTEX@titlepslabel@clear {#1}
716 }
717 \ctex_patch_cmd:Nnn \ttl@setsubmark
718 { \protect \@namedef { the#2 } { \@nameuse { the#2 } } }
719 {
720 \protect \@namedef { the#2 } { \@nameuse { the#2 } }
721 \CTEX@titlepslabel@set {#2}
722 }
723 }
724 \group_end:
725 \cs_new:Npn \CTEX@titlepslabel@set #1
726 {
727 \cs_if_free:cF { CTEXthe#1 }
728 { \protect \@namedef { CTEXthe#1 } { \@nameuse { CTEXthe#1 } } }
729 }
730 \cs_new:Npn \CTEX@titlepslabel@clear #1
731 {
732 \cs_if_free:cF { CTEXthe#1 }
733 { \protect \@namedef { CTEXthe#1 } { } }
734 }
735 \ctex_at_end_package:nn { titlesec }
736 { \cs_if_free:NF \ttl@settopmark { \ctex_titleps_hook: } }
737 \ctex_at_end_package:nn { titleps } { \ctex_titleps_hook: }
738 \ctex_at_end_package:nn { titleps }
739 {
740 \cs_set_protected:Npn \ttl@setifthe #1
741 {
742 \exp_args:Nco \cs_set:Npn { ifthe #1 }
743 {
744 \CTEXifname
745 { \protect \@firstoftwo }
746 { \protect \@secondoftwo }
747 }
748 }
749 \seq_map_function:NN \c__ctex_headings_seq \ttl@setifthe
750 }
751 \cs_new_protected:Npn \CTEX@toc@width@n #1
752 {
753 \hbox_set:Nn \l__ctex_tmp_box {#1}
754 \dim_set:Nn \@tempdima
755 {
756 \dim_max:nn { \@tempdima }
757 { \box_wd:N \l__ctex_tmp_box + \f@size \p@ / 2 }
758 }
759 }
760 \group_begin:
761 \char_set_catcode_other:N \#
762 \use:n
763 {
764 \group_end:
765 \ctex_preto_cmd:NnnTF \numberline { \ExplSyntaxOff }
766 { \CTEX@toc@width@n {#1} }
767 { }
768 { \ctex_patch_failure:N \numberline }
769 \cs_new_protected:Npn \__ctex_patch_toc_width:n \c_parameter_token 1
770 {
771 \@ifpackageloaded { \c_parameter_token 1 }
772 { }
773 {
774 \ctex_at_end_package:nn { \c_parameter_token 1 }
775 {
776 \ctex_preto_cmd:NnnTF \numberline
777 { \char_set_catcode_letter:n { 64 } }
778 { \CTEX@toc@width@n {#1} }
779 { }
780 { \ctex_patch_failure:N \numberline }
781 }
782 }
783 }
784 }
785 \__ctex_patch_toc_width:n { tocloft }
786 \__ctex_patch_toc_width:n { titletoc }
787 \ctex_patch_cmd:Nnn \ps@headings
788 {
789 \ifnum \c@secnumdepth > \m@ne \if@mainmatter
790 \@chapapp \ \thechapter . ~ \ %
791 \fi \fi
792 }
793 { \CTEXifname { \CTEXthechapter \quad } { } }
794 \legacy_if:nT { @twoside }
795 {
796 \ctex_patch_cmd:Nnn \ps@headings
797 { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
798 { \CTEXifname { \CTEXthesection \quad } { } }
799 }
800 \ctex_at_end_package:nn { fancyhdr }
801 {
802 \ctex_patch_cmd:Nnn \f@nch@initialise
803 { \ifnum \c@secnumdepth > \z@ \thesection \hskip 1em \relax \fi }
804 { \CTEXifname { \CTEXthesection \quad } { } }
805 \ctex_patch_cmd:Nnn \f@nch@initialise
806 { \ifnum \c@secnumdepth > \@ne \thesubsection \hskip 1em \relax \fi }
807 { \CTEXifname { \CTEXthesubsection \quad } { } }
808 \ctex_patch_cmd:Nnn \f@nch@initialise
809 { \ifnum \c@secnumdepth > \m@ne \@chapapp\ \thechapter . ~ \ \fi }
810 { \CTEXifname { \CTEXthechapter \quad } { } }
811 \ctex_patch_cmd:Nnn \f@nch@initialise
812 { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
813 { \CTEXifname { \CTEXthesection \quad } { } }
814 \f@nch@initialise
815 \@ifpackagewith { fancyhdr } { headings }
816 {
817 \ctex_patch_cmd:Nnn \ps@headings
818 {
819 \ifnum \c@secnumdepth > \m@ne \if@mainmatter
820 \@chapapp \ \thechapter . ~ \ %
821 \fi \fi
822 }
823 { \CTEXifname { \CTEXthechapter \quad } { } }
824 \legacy_if:nT { @twoside }
825 {
826 \ctex_patch_cmd:Nnn \ps@headings
827 { \ifnum \c@secnumdepth > \z@ \thesection . ~ \ \fi }
828 { \CTEXifname { \CTEXthesection \quad } { } }
829 }
830 }
831 { }
832 }
833 \ctex_define:n
834 {
835 secnumdepth .code:n = \ctex_heading_depth:ne { secnumdepth } {#1} ,
836 secnumdepth .value_required:n = true ,
837 tocdepth .code:n = \ctex_heading_depth:ne { tocdepth } {#1} ,
838 tocdepth .value_required:n = true
839 }
840 \cs_new_protected:Npn \ctex_heading_depth:nn #1#2
841 {
842 \prop_get:NnNTF \c__ctex_heading_level_prop {#2} \l__ctex_tmp_tl
843 { \setcounter {#1} { \l__ctex_tmp_tl } }
844 { \setcounter {#1} { \int_eval:n {#2} } }
845 }
846 \cs_generate_variant:Nn \ctex_heading_depth:nn { ne }
847 \prop_const_from_keyval:Nn \c__ctex_heading_level_prop
848 {
849 part = -1 ,
850 chapter = 0 ,
851 section = 1 ,
852 subsection = 2 ,
853 subsubsection = 3 ,
854 paragraph = 4 ,
855 subparagraph = 5
856 }
857 \cs_new_protected:Npn \CTEX@setcurrentlabel@n #1
858 {
859 \protected@edef \@currentlabel
860 {
861 \cs_if_exist:cTF { CTEX@the#1 }
862 { \exp_args:cc { p@#1 } { CTEX@the#1 } }
863 { \exp_not:o { \@currentlabel } }
864 }
865 }
866 \cs_new_protected:Npn \ctex_varioref_hook:
867 {
868 \seq_map_inline:Nn \c__ctex_headings_seq
869 { \ctex_fix_varioref_label:n { ##1 } }
870 \ctex_at_end_package:nn { cleveref } { \ctex_cleveref_hook: }
871 }
872 \cs_new_protected:Npn \ctex_fix_varioref_label:n #1
873 {
874 \tl_if_empty:cT { p@#1 }
875 { \exp_args:Nnx \labelformat {#1} { \exp_not:c { CTEX@the#1 } } }
876 }
877 \cs_new_protected:Npn \ctex_cleveref_hook:
878 {
879 \@ifpackageloaded { hyperref }
880 {
881 \@ifpackagewith { hyperref } { implicit = false }
882 { }
883 { \__ctex_cleveref_hook_aux:N \H@refstepcounter }
884 }
885 {
886 \__ctex_cleveref_hook_aux:N \refstepcounter@noarg
887 \__ctex_cleveref_hook_aux:N \refstepcounter@optarg
888 }
889 \__ctex_cleveref_hook_aux:N \appendix
890 }
891 \cs_new_protected:Npn \__ctex_cleveref_hook_aux:N #1
892 {
893 \ctex_patch_cmd_all:NnnnTF #1
894 {
895 \ExplSyntaxOff
896 \char_set_catcode_letter:n { 64 }
897 }
898 { \endcsname \csname the }
899 { \expandafter \endcsname \csname the }
900 { }
901 { \ctex_patch_failure:N #1 }
902 }
903 \cs_if_exist:NTF \labelformat
904 { \ctex_varioref_hook: }
905 {
906 \cs_new_eq:NN \CTEX@save@refstepcounter \refstepcounter
907 \RenewDocumentCommand \refstepcounter { m }
908 {
909 \CTEX@save@refstepcounter {#1}
910 \CTEX@setcurrentlabel@n {#1}
911 }
912 \ctex_at_end_package:nn { varioref } { \ctex_varioref_hook: }
913 }
914 \ctex_scheme_input:o { \l__ctex_scheme_tl }
915 %%
916 %%
917 %% End of file `ctex-heading-book.def'.