Debian Codegraph @

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

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