Debian Codegraph @

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

raw
1 %%
2 %% File ctxdoc.cls
3 %%
4 %% Copyright (C) 2016--2022
5 %% CTEX.ORG and any individual authors listed in the documentation.
6 %%---------------------------------------------------------------------
7 %%
8 %% This work may be distributed and/or modified under the
9 %% conditions of the LaTeX Project Public License, either
10 %% version 1.3c of this license or (at your option) any later
11 %% version. This version of this license is in
12 %% http://www.latex-project.org/lppl/lppl-1-3c.txt
13 %% and the latest version of this license is in
14 %% http://www.latex-project.org/lppl.txt
15 %% and version 1.3 or later is part of all distributions of
16 %% LaTeX version 2005/12/01 or later.
17 %%
18 %% This work has the LPPL maintenance status "maintained".
19 %%
20 %%---------------------------------------------------------------------
21 %%
22 \NeedsTeXFormat{LaTeX2e}
23 \RequirePackage{expl3}
24 \GetIdInfo$Id: ctxdoc.cls c3e8eb5 2022-06-07 19:08:17 +0800 Qing Lee <[email protected]> $
25 {ctex documentation (CTEX)}
26 \ProvidesExplClass{ctxdoc}{\ExplFileDate}{}{\ExplFileDescription}
27 \ExplSyntaxOff
28 \DeclareOption*{\PassOptionsToClass{\CurrentOption}{l3doc}}
29 \PassOptionsToClass{a4paper,full}{l3doc}
30 \ProcessOptions
31 \LoadClass{l3doc}
32 \RequirePackage[UTF8, punct=kaiming, heading, linespread=1.2, sub3section]{ctex}
33 \ctexset{
34 abstractname = 简介,
35 indexname = 代码索引,
36 section/format = \Large\bfseries\raggedright,
37 section/name = {第,节},
38 }
39 \RequirePackage[toc]{multitoc}
40 \RequirePackage{geometry}
41 \RequirePackage{tabularx}
42 \RequirePackage{makecell}
43 \RequirePackage{threeparttable}
44 \RequirePackage{siunitx}
45 \RequirePackage{unicode-math}
46 \RequirePackage{xcolor}
47 \RequirePackage{caption}
48 \RequirePackage{fancyvrb-ex}
49 \RequirePackage{zref-base}
50 \geometry{includemp, hmargin={0mm,15mm}, vmargin={25mm,15mm}, footskip=7mm}
51 \hypersetup{pdfstartview=FitH, bookmarksdepth=subparagraph}
52 \setcounter{secnumdepth}{4}
53 \setcounter{tocdepth}{2}
54 \newcommand*\email{\nolinkurl}
55 \setmainfont{texgyrepagella}[
56 Extension = .otf,
57 UprightFont = *-regular,
58 BoldFont = *-bold,
59 ItalicFont = *-italic,
60 BoldItalicFont = *-bolditalic]
61 \setsansfont{texgyreheros}[
62 Extension = .otf,
63 UprightFont = *-regular,
64 BoldFont = *-bold,
65 ItalicFont = *-italic,
66 BoldItalicFont = *-bolditalic]
67 \setmonofont{cmun}[
68 Extension = .otf,
69 UprightFont = *btl,
70 BoldFont = *tb,
71 ItalicFont = *bto,
72 BoldItalicFont = *tx,
73 HyphenChar = None]
74 \setmathfont{texgyrepagella-math.otf}
75 \captionsetup{%
76 strut=off, labelsep=quad, labelfont+=bf,
77 figureposition = bottom, tableposition = top}
78 %% <--- http://tex.stackexchange.com/a/40896
79 \patchcmd{\@addtocurcol}%
80 {\vskip \intextsep}%
81 {\edef\save@first@penalty{\the\lastpenalty}\unpenalty
82 \ifnum \lastpenalty = \@M % hopefully the OR penalty
83 \unpenalty
84 \else
85 \penalty \save@first@penalty \relax % put it back
86 \fi
87 \ifnum\outputpenalty <-\@Mii
88 \addvspace\intextsep
89 \vskip\parskip
90 \else
91 \addvspace\intextsep
92 \fi}%
93 {\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
94 \patchcmd{\@addtocurcol}%
95 {\vskip\intextsep \ifnum\outputpenalty <-\@Mii \vskip -\parskip\fi}%
96 {\ifnum\outputpenalty <-\@Mii
97 \aftergroup\vskip\aftergroup\intextsep
98 \aftergroup\nointerlineskip
99 \else
100 \vskip\intextsep
101 \fi}%
102 {\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
103 \patchcmd{\@getpen}{\@M}{\@Mi}
104 {\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
105 %% --->
106 %% 不对代码实现的 \section 以下标题编目录。
107 \AtBeginEnvironment{implementation}{%
108 \ifnum\value{tocdepth}>\@ne
109 \addtocontents{toc}{\protect\value{tocdepth}=1\relax}%
110 \fi}
111 \ifxetex
112 \let\ctexdocverbaddon\xeCJKVerbAddon
113 \def\ctexdisableecglue{\xeCJKsetup{CJKecglue}}
114 \def\ctexplainps{\xeCJKsetup{PunctStyle=plain}}
115 \appto\meta@font@select{\ifinner\ctexdisableecglue\fi}
116 \else
117 \let\ctexdocverbaddon\relax
118 \let\ctexplainps\relax
119 \def\ctexdisableecglue{\ltjsetparameter{autoxspacing=false}}
120 \appto\meta@font@select{\ctexdisableecglue}
121 \fi
122 \setlist{noitemsep,topsep=\smallskipamount}
123 \setlist[1]{labelindent=\parindent}
124 \setlist[enumerate]{leftmargin=*}
125 \setlist[itemize]{leftmargin=*}
126 \setlist[trivlist]{topsep=\medskipamount}
127 \renewlist{arguments}{enumerate}{1}
128 \setlist[arguments]{nolistsep,
129 leftmargin=\parindent, labelindent=0pt, labelsep=*,
130 label=\texttt{\#\arabic*}\,:}
131 \newlist{optdesc}{description}{3}
132 %% 设置间距为 \marginparsep,与 l3doc 一致
133 \setlist[optdesc]{%
134 font=\mdseries\small\ttfamily,align=right,listparindent=\parindent,
135 labelsep=\marginparsep,labelindent=-\marginparsep,leftmargin=0pt}
136 %% 重新定义 threeparttable 包的 tablenotes 环境
137 \renewlist{tablenotes}{description}{1}
138 \setlist[tablenotes]{%
139 format=\normalfont\tnote@item,align=right,listparindent=\parindent,
140 labelindent=\tabcolsep,leftmargin=*,rightmargin=\tabcolsep,
141 after=\@noparlisttrue}
142 \AtBeginEnvironment{tablenotes}{%
143 \setlength\parindent{2\ccwd}%
144 \normalfont\footnotesize}
145 \AtBeginEnvironment{threeparttable}{%
146 \stepcounter{tpt@id}%
147 \edef\curr@tpt@id{tpt@\arabic{tpt@id}}}
148 \newcounter{tpt@id}
149 \def\tnote@item#1{%
150 \Hy@raisedlink{\hyper@anchor{\curr@tpt@id-#1}}#1}
151 \def\TPTtagStyle#1{\hyperlink{\curr@tpt@id-#1}{#1}}
152 \fvset{
153 fontsize=\small,baselinestretch=1,numbersep=5pt,
154 formatcom=\ctexdocverbaddon,
155 listparameters=\setlength\topsep{\MacrocodeTopsep}}
156 \DefineVerbatimEnvironment{frameverb}{Verbatim}{%
157 gobble=4,
158 frame=single,framesep=8pt,
159 listparameters=
160 \setlength\topsep{\medskipamount}%
161 \appto\FV@EndList{\nointerlineskip}}
162 \DefineVerbatimEnvironment{ctexexam}{Verbatim}{%
163 gobble=4,
164 frame=single,framesep=10pt,
165 label=\rule{0pt}{12pt}\textnormal{\bfseries 例 \arabic{ctexexam}},
166 listparameters=
167 \setlength\topsep{\bigskipamount}%
168 \refstepcounter{ctexexam}\ctexexamlabelref
169 \appto\FV@EndList{\nointerlineskip}}
170 \define@key{FV}{labelref}{\def\ctexexamlabelref{\label{#1}}}
171 \let\ctexexamlabelref\empty
172 \newcounter{ctexexam}
173 \AtEndEnvironment{function}{\ctexsetverticalspacing}
174 \AfterEndEnvironment{function}{\ctexfixverticalspacing}
175 \AtBeginEnvironment{syntax}{\linespread{1}\ctexplainps\ctexdisableecglue}
176 \newrobustcmd\exptarget{%
177 \AddLineBeginMainAux{\csgdef{Codedoc@expstar}{}}%
178 \Hy@raisedlink{\hypertarget{expstar}{}}}
179 \newrobustcmd\rexptarget{%
180 \AddLineBeginMainAux{\csgdef{Codedoc@rexpstar}{}}%
181 \Hy@raisedlink{\hypertarget{rexpstar}{}}}
182 \newrobustcmd\expstar{\hyperlink{expstar}{$\star$}}
183 \newrobustcmd\rexpstar{\hyperlink{rexpstar}{\ding{73}}}
184 \ExplSyntaxOn
185 \cs_new_protected:Npn \ctexsetverticalspacing
186 {
187 \par
188 \tl_gset:Nx \ctexfixverticalspacing
189 { \dim_set:Nn \prevdepth { \dim_use:N \prevdepth } }
190 \int_compare:nNnT \lastnodetype = { 11 }
191 {
192 \tl_gput_right:Nx \ctexfixverticalspacing
193 { \exp_not:N \skip_vertical:n { \skip_use:N \lastskip } }
194 \unskip
195 }
196 }
197 \tl_new:N \ctexfixverticalspacing
198 \NewDocumentCommand \SideBySideExampleSet { }
199 { \prop_put_from_keyval:Nn \l__ctxdoc_side_example_prop }
200 \prop_new:N \l__ctxdoc_side_example_prop
201 \prop_set_from_keyval:Nn \l__ctxdoc_side_example_prop
202 { frame=single, numbers=left, gobble=5, xrightmargin=.5\linewidth }
203 \tl_put_left:Nn \SideBySideExample
204 {
205 \trivlist \item \relax
206 \exp_args:Ne \fvset
207 { \prop_to_keyval:N \l__ctxdoc_side_example_prop }
208 }
209 \tl_put_right:Nn \endSideBySideExample
210 { \endtrivlist }
211 \ctex_patch_cmd:Nnn \__codedoc_function_typeset_start:
212 { \bigskip }
213 { \nointerlineskip \addvspace { \bigskipamount } }
214 %% l3doc 会设置列表环境中 \listparindent=\z@,我们在这里恢复它。
215 \cs_set_eq:NN \list \__codedoc_oldlist:nn
216 \cs_new_nopar:Npn \zihaopt #1
217 {
218 \exp_last_unbraced:Nf \tl_head:w
219 { \prop_item:Nn \c__ctex_font_size_prop {#1} } { } \q_stop
220 }
221 %% 抑制首段的 \parskip
222 \ctex_patch_cmd_once:NnnnTF \__codedoc_function_descr_start:w
223 { }
224 { \noindent }
225 { \skip_vertical:n { -\parskip } \noindent }
226 { \iow_term:n { *** ~ SUCCESS ~ *** } }
227 { \iow_term:n { *** ~ FAIL ~ *** } }
228 %% l3doc 会在 function 环境的 syntax 和 descr 盒子中间加上 \medskipamount 的距离。
229 %% 但是若 syntax 盒子为空(未使用 syntax 环境),就会显得不好看。
230 %% 此时我们通过将 \medskipamount 设置为零来修正。若盒子非空,则将 \parskip 还回去。
231 \ctex_preto_cmd:NnnTF \__codedoc_function_assemble:
232 { }
233 { \ctex_doc_fix_yoffset: }
234 { \iow_term:n { *** ~ SUCCESS ~ *** } }
235 { \iow_term:n { *** ~ FAIL ~ *** } }
236 \cs_new_protected_nopar:Npn \ctex_doc_fix_yoffset:
237 {
238 \box_if_empty:NTF \g__codedoc_syntax_box
239 { \skip_zero:N \medskipamount }
240 { \skip_add:Nn \medskipamount { \parskip } }
241 }
242 %% 左侧边注的函数列表采用单倍行距
243 \ctex_preto_cmd:NnnTF \__codedoc_typeset_functions:
244 { }
245 { \MacroFont }
246 { \iow_term:n { *** ~ SUCCESS ~ *** } }
247 { \iow_term:n { *** ~ FAIL ~ *** } }
248 \ctex_patch_cmd_once:NnnnTF \__codedoc_macro_init:
249 { }
250 { \hbox:n }
251 { \MacroFont \hbox:n }
252 { \iow_term:n { *** ~ SUCCESS ~ *** } }
253 { \iow_term:n { *** ~ FAIL ~ *** } }
254 \ctex_patch_cmd_once:NnnnTF \__codedoc_macro_dump:
255 { }
256 { \hbox_unpack_drop:N }
257 { \MacroFont \hbox_unpack_drop:N }
258 { \iow_term:n { *** ~ SUCCESS ~ *** } }
259 { \iow_term:n { *** ~ FAIL ~ *** } }
260 \cs_set_eq:NN \__codedoc_macro_end_style:n \use_none:n
261 \cs_set_protected:Npn \__codedoc_macro_typeset_one:nN #1#2
262 {
263 \vbox_set:Nn \l__codedoc_macro_box
264 {
265 \MacroFont
266 \vbox_unpack_drop:N \l__codedoc_macro_box
267 \hbox_set:Nn \l_tmpa_box
268 { \__codedoc_print_macroname:nN {#1} #2 }
269 \dim_set:Nn \l_tmpa_dim { \marginparwidth - \labelsep }
270 \dim_compare:nNnT { \box_wd:N \l_tmpa_box } > \l_tmpa_dim
271 {
272 \box_resize_to_wd_and_ht:Nnn \l_tmpa_box
273 { \l_tmpa_dim }
274 { \box_ht:N \l_tmpa_box }
275 }
276 \hbox_overlap_left:n
277 {
278 \box_use:N \l_tmpa_box
279 \skip_horizontal:n { \marginparsep - \labelsep }
280 }
281 }
282 \int_incr:N \l__codedoc_macro_int
283 }
284 \cs_set_protected:Npn \__codedoc_print_macroname:nN #1#2
285 {
286 \strut
287 \__codedoc_get_hyper_target:xN
288 {
289 \exp_not:n {#1}
290 \bool_if:NT #2 { \tl_to_str:n {TF} }
291 }
292 \l__codedoc_tmpa_tl
293 \cs_if_exist:cTF { r@ \l__codedoc_tmpa_tl }
294 { \exp_args:NNo \label@hyperref [ \l__codedoc_tmpa_tl ] }
295 { \use:n }
296 {
297 \tl_set:Nn \l__codedoc_tmpa_tl {#1}
298 \tl_replace_all:Non \l__codedoc_tmpa_tl
299 { \c_catcode_other_space_tl }
300 { \fontspec_visible_space: }
301 \__codedoc_macroname_prefix:o \l__codedoc_tmpa_tl
302 \__codedoc_macroname_suffix:N #2
303 }
304 }
305 \AtBeginEnvironment { syntax }
306 {
307 \char_set_catcode_active:N \|
308 \char_set_active_eq:NN \| \orbar
309 \char_set_catcode_active:N \(
310 \char_set_active_eq:NN \( \defaultvalaux
311 }
312 %% 不对目录中出现的 \cs 和 \tn 等编索引
313 \DeclareDocumentCommand \StopSpecialIndexModule { }
314 { \cs_set_eq:NN \__codedoc_special_index_module:nnnnN \use_none:nnnnn }
315 \tl_map_inline:nn { \actualchar \encapchar \levelchar }
316 { \exp_args:Nx \DoNotIndex { \bslash \tl_to_str:N #1 } }
317 \DeclareDocumentCommand \package { o m }
318 {
319 \exp_args:Nx \href
320 {
321 http \c_colon_str //www.ctan.org/pkg/
322 \IfNoValueTF {#1} { \str_lowercase:n {#2} } {#1}
323 }
324 { \pkg {#2} }
325 }
326 \DeclareDocumentCommand \GetFileId { m }
327 {
328 \GetFileInfo {#1}
329 \file_get:nnNTF { \c_sys_jobname_str .id }
330 { \int_set:Nn \tex_endlinechar:D { -1 } } \l__ctxdoc_tmp_tl
331 { \tl_if_empty:NTF \l__ctxdoc_tmp_tl }
332 { \use_i:nn }
333 { \GetIdInfo $Id$ }
334 { \exp_after:wN \GetIdInfo \l__ctxdoc_tmp_tl }
335 { \fileinfo }
336 }
337 \cs_new_eq:NN \__ctxdoc_ltx_changes:nnn \changes@
338 \cs_set_protected:Npn \changes@ #1#2
339 {
340 \__ctxdoc_save_version_date:nn {#1} {#2}
341 \tl_if_empty:nTF {#1}
342 { \__ctxdoc_ltx_changes:nnn }
343 { \__ctxdoc_version_zfill:wnnn #1 \q_stop }
344 {#1} {#2}
345 }
346 \cs_new_protected:Npn \__ctxdoc_version_zfill:wnnn #1#2 \q_stop
347 {
348 \str_if_eq:nnTF {#1} { v }
349 { \__ctxdoc_version_zfill:nnnn {#2} }
350 { \__ctxdoc_ltx_changes:nnn }
351 }
352 \cs_new_protected:Npn \__ctxdoc_version_zfill:nnnn #1#2
353 {
354 \tl_clear:N \l__ctxdoc_tmp_tl
355 \int_zero:N \l_tmpa_int
356 \seq_set_split:Nnn \l_tmpa_seq { . } {#1}
357 \seq_map_function:NN \l_tmpa_seq \__ctxdoc_version_zfill:n
358 \int_compare:nNnF \l_tmpa_int > 2
359 {
360 \tl_put_right:Nx \l__ctxdoc_tmp_tl
361 { \prg_replicate:nn { 3 - \l_tmpa_int } { 00000 } }
362 }
363 \__ctxdoc_ltx_changes:nnn { \l__ctxdoc_tmp_tl \actualchar #2 }
364 }
365 \tl_new:N \l__ctxdoc_tmp_tl
366 \cs_new_protected:Npn \__ctxdoc_version_zfill:n #1
367 {
368 \int_incr:N \l_tmpa_int
369 \tl_put_right:Nx \l__ctxdoc_tmp_tl
370 {
371 \prg_replicate:nn
372 { \int_max:nn { 0 } { 5 - \tl_count:n {#1} } } { 0 }
373 \exp_not:n {#1}
374 }
375 }
376 \cs_new_protected:Npn \__ctxdoc_save_version_date:nn #1#2
377 {
378 \prop_get:NnNTF \g__ctxdoc_version_date_prop {#1} \l__ctxdoc_tmp_tl
379 { \exp_after:wN \__ctxdoc_save_version_date:nnnn \l__ctxdoc_tmp_tl {#2} {#1} }
380 { \__ctxdoc_save_version_date:nnn {#1} {#2} {#2} }
381 }
382 \cs_new_protected:Npn \__ctxdoc_save_version_date:nnnn #1#2#3#4
383 {
384 \__ctxdoc_if_date_later:nnTF {#1} {#3}
385 { \__ctxdoc_save_version_date:nnn {#4} {#3} {#2} }
386 {
387 \__ctxdoc_if_date_later:nnT {#3} {#2}
388 { \__ctxdoc_save_version_date:nnn {#4} {#1} {#3} }
389 }
390 }
391 \prg_new_conditional:Npnn \__ctxdoc_if_date_later:nn #1#2 { TF , T }
392 {
393 \if_int_compare:w \__ctxdoc_parse_date:w #1 / / / 0 \q_stop >
394 \__ctxdoc_parse_date:w #2 / / / 0 \q_stop \exp_stop_f:
395 \prg_return_true: \else: \prg_return_false: \fi:
396 }
397 \cs_new:Npn \__ctxdoc_parse_date:w #1/#2/#3/ #4 \q_stop
398 { #1#2#3 }
399 \cs_new_protected:Npn \__ctxdoc_save_version_date:nnn #1#2#3
400 { \prop_gput:Nnn \g__ctxdoc_version_date_prop {#1} { {#2} {#3} } }
401 \cs_new_protected:Npn \CTEX@versionitem #1 \efill
402 {
403 \@idxitem
404 \prop_get:NnNTF \g__ctxdoc_version_date_prop {#1} \l__ctxdoc_tmp_tl
405 { \exp_after:wN \__ctxdoc_version_item:nnn \l__ctxdoc_tmp_tl {#1} }
406 { \BOOM }
407 }
408 \cs_new_protected:Npn \__ctxdoc_version_item:nnn #1#2#3
409 {
410 \noindent
411 \Hy@raisedlink { \belowpdfbookmark {#3} { HD.#3 } }
412 \textbf {#3} \hfill
413 \hbox:n
414 {
415 \footnotesize
416 \str_if_eq:nnTF {#1} {#2}
417 { ( #1 ) }
418 { ( #1 ~ -- ~ #2 ) }
419 }
420 \par \nopagebreak
421 }
422 \prop_new:N \g__ctxdoc_version_date_prop
423 \ctex_patch_cmd:Nnn \HDorg@theglossary
424 { \let \item \@idxitem }
425 { \let \item \CTEX@versionitem }
426 \ctex_patch_cmd:Nnn \l@section { 2.5em } { 1.5em }
427 \ctex_patch_cmd:Nnn \l@subsection { 2.5em } { 1.5em }
428 \ctex_patch_cmd:Nnn \@wrglossary
429 { hdpindex }
430 {
431 \ifnum \c@HD@hypercount = \z@
432 hdpindex
433 \else
434 hdclindex { \the \c@HD@hypercount }
435 \fi
436 }
437 %% 重定义 macrocode 环境的实现,逐行处理
438 \cs_set_protected_nopar:Npn \xmacro@code
439 { \__ctxdoc_marco_code:w }
440 \cs_set_protected_nopar:Npn \sxmacro@code
441 {
442 \fontspec_print_visible_spaces:
443 \xmacro@code
444 }
445 \cs_new_protected_nopar:Npn \__ctxdoc_marco_code:w
446 {
447 \ifcodeline@index
448 \__ctxdoc_marco_every_par:n { \__ctxdoc_code_line_no: }
449 \else:
450 \__ctxdoc_marco_every_par:n { }
451 \fi:
452 \exp_args:Nx \__ctxdoc_make_finish_tag:n { \@currenvir }
453 \__ctxdoc_verbatim_start:w
454 }
455 \cs_new_protected:Npn \__ctxdoc_marco_every_par:n #1
456 {
457 \everypar
458 {
459 \everypar {#1}
460 \if@inlabel
461 \global \@inlabelfalse
462 \@noparlistfalse
463 \unless \ifvoid \CTEX@labelbox
464 \llap { \box \CTEX@labelbox \hskip \leftskip }
465 \fi
466 \fi
467 #1
468 }
469 }
470 \ctex_patch_cmd:Nnn \macro@code
471 { \if@inlabel \leavevmode \fi }
472 {
473 \partopsep \z@skip
474 \if@inlabel \setbox \CTEX@labelbox \copy \@labels \fi
475 }
476 \newbox \CTEX@labelbox
477 \group_begin:
478 \int_set:Nn \tex_endlinechar:D { -1 }
479 \use:n
480 {
481 \char_set_catcode_active:n { 32 }
482 \tl_const:Nn \c__ctxdoc_active_space_tl
483 }
484 { }
485 \group_end:
486 \group_begin:
487 \char_set_catcode_active:n { 13 }
488 \cs_new_protected:Npx \__ctxdoc_make_finish_tag:n #1
489 {
490 \tl_set:Nn \exp_not:N \l__ctxdoc_verbatim_finish_tl
491 {
492 \c_percent_str
493 \prg_replicate:nn { 4 }
494 { \exp_not:o { \c__ctxdoc_active_space_tl } }
495 \exp_not:o { \active@escape@char } end
496 \c_left_brace_str #1 \c_right_brace_str
497 \exp_not:N ^^M
498 }
499 }
500 \cs_new_protected:Npn \__ctxdoc_verbatim_start:w #1
501 {
502 \str_if_eq:nnTF {#1} { ^^M }
503 { \__ctxdoc_verbatim_read_line:w }
504 { \__ctxdoc_verbatim_read_line:w #1 }
505 }
506 \cs_new_protected:Npn \__ctxdoc_verbatim_read_line:w #1 ^^M
507 {
508 \tl_set:Nn \l__ctxdoc_verbatim_line_tl { #1 ^^M }
509 \tl_if_eq:NNTF \l__ctxdoc_verbatim_line_tl \l__ctxdoc_verbatim_finish_tl
510 { \exp_args:Nx \end { \@currenvir } }
511 {
512 \__ctxdoc_verbatim_process_line:
513 \__ctxdoc_verbatim_read_line:w
514 }
515 }
516 \cs_new_protected:Npn \__ctxdoc_swap_cr:
517 { \exp_after:wN \__ctxdoc_swap_cr:w \l__ctxdoc_verbatim_line_tl }
518 \cs_new_protected:Npn \__ctxdoc_swap_cr:w #1 ^^M
519 {
520 \group_insert_after:N ^^M
521 \tl_set:Nn \l__ctxdoc_verbatim_line_tl {#1}
522 }
523 \tl_const:Nn \c__ctxdoc_active_cr_tl { ^^M }
524 \group_end:
525 \tl_new:N \l__ctxdoc_verbatim_line_tl
526 \tl_new:N \l__ctxdoc_verbatim_finish_tl
527 \tl_new:N \g__ctxdoc_verbatim_verb_stop_tl
528 \cs_new_protected_nopar:Npn \__ctxdoc_process_normal_line:
529 {
530 \str_if_eq:eeTF
531 { \str_head:N \l__ctxdoc_verbatim_line_tl } { \c_percent_str }
532 { \__ctxdoc_check_angle:x { \tl_tail:N \l__ctxdoc_verbatim_line_tl } }
533 { \__ctxdoc_output_line: }
534 }
535 \cs_new_protected_nopar:Npn \__ctxdoc_process_verb_line:
536 {
537 \tl_if_eq:NNTF \l__ctxdoc_verbatim_line_tl \g__ctxdoc_verbatim_verb_stop_tl
538 {
539 \tl_gclear:N \g__ctxdoc_verbatim_verb_stop_tl
540 \cs_gset_eq:NN \__ctxdoc_verbatim_process_line: \__ctxdoc_process_normal_line:
541 \__ctxdoc_output_module:nn
542 { \color { verb@guard } }
543 {
544 \__ctxdoc_swap_cr:
545 \__ctxdoc_module_pop:n { \l__ctxdoc_verbatim_line_tl }
546 }
547 }
548 { \tl_use:N \l__ctxdoc_verbatim_line_tl }
549 }
550 \cs_new_eq:NN \__ctxdoc_verbatim_process_line: \__ctxdoc_process_normal_line:
551 \DeclareDocumentCommand \CheckModules { }
552 { \cs_set_eq:NN \__ctxdoc_verbatim_process_line: \__ctxdoc_process_normal_line: }
553 \DeclareDocumentCommand \DontCheckModules { }
554 { \cs_set_eq:NN \__ctxdoc_verbatim_process_line: \__ctxdoc_output_line: }
555 \cs_new_protected:Npn \__ctxdoc_check_angle:n #1
556 {
557 \str_if_eq:eeTF { \str_head:n {#1} } { < }
558 { \__ctxdoc_check_module:x { \tl_tail:n {#1} } }
559 { \__ctxdoc_output_percent_line: }
560 }
561 \cs_generate_variant:Nn \__ctxdoc_check_angle:n { x }
562 \cs_new_protected:Npn \__ctxdoc_check_module:n #1
563 {
564 \exp_args:Nx \str_case:nnF { \str_head:n {#1} }
565 {
566 { * } { \__ctxdoc_module_star:w }
567 { / } { \__ctxdoc_module_slash:w }
568 { @ } { \__ctxdoc_module_at:w }
569 { < } { \__ctxdoc_module_verb:w }
570 }
571 { \__ctxdoc_module_pm:w }
572 #1 \q_stop
573 }
574 \cs_generate_variant:Nn \__ctxdoc_check_module:n { x }
575 \group_begin:
576 \char_set_catcode_active:N \>
577 \cs_new_protected:Npn \__ctxdoc_module_star:w #1 > #2 \q_stop
578 {
579 \__ctxdoc_output_module:nn
580 { \__ctxdoc_star_color: }
581 { \__ctxdoc_module_push:n { \__ctxdoc_module_angle:n {#1} } }
582 \__ctxdoc_output_line:n {#2}
583 \__ctxdoc_star_format:
584 }
585 \cs_new_protected:Npn \__ctxdoc_module_slash:w #1 > #2 \q_stop
586 {
587 \__ctxdoc_output_module:nn
588 { \__ctxdoc_slash_color: }
589 { \__ctxdoc_module_pop:n { \__ctxdoc_module_angle:n {#1} } }
590 \__ctxdoc_output_line:n {#2}
591 \__ctxdoc_slash_format:
592 }
593 \cs_new_protected:Npn \__ctxdoc_module_at:w @ @ = #1 > #2 \q_stop
594 {
595 \__ctxdoc_output_module:nn
596 { \color { at@guard } }
597 { \__ctxdoc_module_angle:n { @ @ = #1 } }
598 \tl_gset:Nn \g__codedoc_module_name_tl {#1}
599 \__ctxdoc_output_line:n {#2}
600 }
601 \cs_new_protected:Npn \__ctxdoc_module_pm:w #1 > #2 \q_stop
602 {
603 \tex_noindent:D
604 \hbox_overlap_left:n
605 {
606 \__ctxdoc_output_module:nn
607 { \__ctxdoc_pm_color: }
608 { \__ctxdoc_module_angle:n {#1} }
609 \skip_horizontal:n { \leftskip + \smallskipamount }
610 }
611 \group_begin:
612 \__ctxdoc_pm_format:
613 \__ctxdoc_output_line:n {#2}
614 \group_end:
615 }
616 \cs_new_protected:Npn \__ctxdoc_module_verb:w #1 \q_stop
617 {
618 \cs_gset_eq:NN \__ctxdoc_verbatim_process_line: \__ctxdoc_process_verb_line:
619 \tl_gset:Nx \g__ctxdoc_verbatim_verb_stop_tl
620 { \c_percent_str \tl_tail:n {#1} }
621 \__ctxdoc_output_module:nn
622 { \color { verb@guard } }
623 {
624 \__ctxdoc_swap_cr:
625 \__ctxdoc_module_push:n { \l__ctxdoc_verbatim_line_tl }
626 }
627 }
628 \group_end:
629 \cs_new_protected_nopar:Npn \__ctxdoc_output_line:
630 {
631 \tex_noindent:D
632 \__ctxdoc_replace_at_at:N \l__ctxdoc_verbatim_line_tl
633 \tl_use:N \l__ctxdoc_verbatim_line_tl
634 }
635 \cs_new_protected:Npn \__ctxdoc_replace_at_at:N #1
636 {
637 \tl_if_empty:NF \g__codedoc_module_name_tl
638 {
639 \exp_args:NNo \__ctxdoc_replace_at_at_aux:Nn
640 #1 \g__codedoc_module_name_tl
641 }
642 }
643 \cs_new_protected:Npx \__ctxdoc_replace_at_at_aux:Nn #1#2
644 {
645 \tl_replace_all:Nnn #1 { \token_to_str:N @ } { @ }
646 \tl_replace_all:Nnn #1 { \token_to_str:N _ } { _ }
647 \tl_replace_all:Nnn #1 { @ @ @ @ } { \token_to_str:N a a }
648 \tl_replace_all:Nnn #1 { _ _ @ @ } { _ _ #2 }
649 \tl_replace_all:Nnn #1 { _ @ @ } { _ _ #2 }
650 \tl_replace_all:Nnn #1 { @ @ } { _ _ #2 }
651 \tl_replace_all:Nnn #1 { \token_to_str:N a a } { @ @ }
652 }
653 \cs_new_protected:Npn \__ctxdoc_output_line:n #1
654 {
655 \tl_set:Nn \l__ctxdoc_verbatim_line_tl {#1}
656 \tl_if_eq:NNTF \l__ctxdoc_verbatim_line_tl \c__ctxdoc_active_cr_tl
657 { \tl_use:N \l__ctxdoc_verbatim_line_tl }
658 {
659 \str_if_eq:eeTF
660 { \str_head:N \l__ctxdoc_verbatim_line_tl }
661 { \c_percent_str }
662 { \__ctxdoc_output_percent_line: }
663 { \__ctxdoc_output_line: }
664 }
665 }
666 \cs_new_protected:Npn \__ctxdoc_output_percent_line:
667 {
668 \tex_noindent:D
669 \group_begin:
670 \color { code@gray }
671 \__ctxdoc_swap_cr:
672 \str_if_eq:eeTF { \f@shape } { \updefault }
673 { \slshape }
674 { \upshape }
675 \__ctxdoc_output_line:
676 \group_end:
677 }
678 \cs_new_protected_nopar:Npn \__ctxdoc_module_push:n
679 { \exp_args:No \__ctxdoc_module_push_aux:nn { \int_use:N \c@HD@hypercount } }
680 \cs_new_protected:Npn \__ctxdoc_module_push_aux:nn #1
681 {
682 \seq_gpush:Nn \g__ctxdoc_module_dest_seq {#1}
683 \hypersetup { hidelinks }
684 \exp_args:Nx \hdclindex
685 { \zref@extractdefault { HD.#1 } { guard@end } { 1 } } { }
686 }
687 \cs_new_protected_nopar:Npn \__ctxdoc_module_pop:n
688 {
689 \seq_gpop:NNTF \g__ctxdoc_module_dest_seq \l__ctxdoc_tmp_tl
690 { \exp_args:No \__ctxdoc_module_pop_aux:nn { \l__ctxdoc_tmp_tl } }
691 { \BOOM \use:n }
692 }
693 \cs_new_protected:Npn \__ctxdoc_module_pop_aux:nn #1
694 {
695 \zref@labelbylist { HD.#1 } { ctxdoc }
696 \hypersetup { hidelinks }
697 \hdclindex {#1} { }
698 }
699 \seq_new:N \g__ctxdoc_module_dest_seq
700 \zref@newlist { ctxdoc }
701 \zref@newprop { guard@end } [ 1 ]
702 { \int_eval:n { \c@HD@hypercount - 1 } }
703 \zref@addprop { ctxdoc } { guard@end }
704 \cs_new_protected_nopar:Npn \__ctxdoc_star_format:
705 {
706 \seq_gpush:No \g__ctxdoc_slash_format_seq { \macro@font }
707 \seq_gpop:NNF \g__ctxdoc_star_format_seq \l__ctxdoc_format_tl
708 { \__ctxdoc_pop_format: }
709 \__ctxdoc_select_format:
710 }
711 \cs_new_protected_nopar:Npn \__ctxdoc_slash_format:
712 {
713 \seq_gpop:NNTF \g__ctxdoc_slash_format_seq \l__ctxdoc_format_tl
714 {
715 \seq_gpush:No \g__ctxdoc_star_format_seq { \macro@font }
716 \__ctxdoc_select_format:
717 }
718 { \BOOM }
719 }
720 \cs_new_protected_nopar:Npn \__ctxdoc_pm_format:
721 {
722 \seq_get:NNF \g__ctxdoc_star_format_seq \l__ctxdoc_format_tl
723 {
724 \__ctxdoc_pop_format:
725 \seq_gpush:No \g__ctxdoc_star_format_seq { \l__ctxdoc_format_tl }
726 }
727 \cs_if_eq:NNF \macro@font \l__ctxdoc_format_tl
728 { \l__ctxdoc_format_tl }
729 }
730 \cs_new_protected_nopar:Npn \__ctxdoc_pop_format:
731 {
732 \seq_gpop_left:NN \g__ctxdoc_format_seq \l__ctxdoc_format_tl
733 \seq_gput_right:No \g__ctxdoc_format_seq { \l__ctxdoc_format_tl }
734 }
735 \cs_new_protected_nopar:Npn \__ctxdoc_select_format:
736 {
737 \cs_if_eq:NNF \macro@font \l__ctxdoc_format_tl
738 {
739 \cs_gset_eq:NN \macro@font \l__ctxdoc_format_tl
740 \macro@font
741 }
742 }
743 \tl_new:N \l__ctxdoc_format_tl
744 \seq_new:N \g__ctxdoc_format_seq
745 \seq_new:N \g__ctxdoc_star_format_seq
746 \seq_new:N \g__ctxdoc_slash_format_seq
747 \seq_gput_right:Nn \g__ctxdoc_format_seq { \MacroFont }
748 \seq_gput_right:Nn \g__ctxdoc_format_seq { \AltMacroFont }
749 \cs_set_protected:Npn \MacroFont
750 {
751 \linespread { 1 }
752 \small
753 \fontseries { \mddefault }
754 \fontshape { \updefault }
755 \ttfamily
756 \ctexdocverbaddon
757 }
758 \cs_set_protected:Npn \AltMacroFont
759 {
760 \linespread { 1 }
761 \small
762 \fontseries { \mddefault }
763 \fontshape { \sldefault }
764 \ttfamily
765 \ctexdocverbaddon
766 }
767 \AtBeginDocument
768 {
769 \tl_gset:Nx \macro@font
770 { \seq_item:Nn \g__ctxdoc_format_seq { 1 } }
771 }
772 \cs_new_protected:Npn \__ctxdoc_output_module:nn #1#2
773 {
774 \tex_noindent:D
775 \group_begin:
776 #1
777 \footnotesize \normalfont \sffamily #2
778 \group_end:
779 }
780 \cs_new_protected_nopar:Npn \__ctxdoc_star_color:
781 {
782 \seq_gpop:NNTF \g__ctxdoc_star_color_seq \current@color
783 { \set@color }
784 { \__ctxdoc_select_color: }
785 \seq_gpush:No \g__ctxdoc_slash_color_seq { \current@color }
786 }
787 \cs_new_protected_nopar:Npn \__ctxdoc_slash_color:
788 {
789 \seq_gpop:NNTF \g__ctxdoc_slash_color_seq \current@color
790 {
791 \set@color
792 \seq_gpush:No \g__ctxdoc_star_color_seq { \current@color }
793 }
794 { \BOOM }
795 }
796 \cs_new_protected_nopar:Npn \__ctxdoc_pm_color:
797 {
798 \seq_get:NNTF \g__ctxdoc_star_color_seq \current@color
799 { \set@color }
800 {
801 \__ctxdoc_select_color:
802 \seq_gpush:No \g__ctxdoc_star_color_seq { \current@color }
803 }
804 }
805 \seq_new:N \g__ctxdoc_star_color_seq
806 \seq_new:N \g__ctxdoc_slash_color_seq
807 \cs_new_protected_nopar:Npn \__ctxdoc_select_color:
808 { \color { guard@series!!+ } }
809 \definecolorseries { guard@series }
810 { cmyk } { last } { blue } { purple }
811 \resetcolorseries [ 3 ] { guard@series }
812 \definecolor { verb@guard } { rgb } { 0.5 , 0.5 , 0 }
813 \definecolor { at@guard } { rgb } { 0.5 , 0 , 0.5 }
814 \definecolor { code@gray } { gray } { 0.5 }
815 \cs_new_protected:Npn \__ctxdoc_module_angle:n #1
816 { \textlangle #1 \textrangle }
817 \cs_new_protected_nopar:Npn \__ctxdoc_code_line_no:
818 {
819 \int_gincr:N \c@CodelineNo
820 \hbox_overlap_left:n
821 {
822 \hbox_to_wd:nn
823 { \MacroIndent }
824 {
825 \HD@target
826 \tex_hss:D
827 \__ctxdoc_code_line_no_style:
828 \theCodelineNo \enspace
829 }
830 \tex_kern:D \@totalleftmargin
831 }
832 }
833 \tl_set:Nn \theCodelineNo
834 { \arabic { CodelineNo } }
835 \cs_new_protected_nopar:Npn \__ctxdoc_code_line_no_style:
836 { \color { code@gray } \normalfont \sffamily \tiny }
837 \cs_set_protected:Npn \HD@SetMacroIndent #1
838 {
839 \group_begin:
840 \settowidth \MacroIndent
841 {
842 \__ctxdoc_code_line_no_style:
843 \prg_replicate:nn { \tl_count:n {#1} } { 0 }
844 \enspace
845 }
846 \dim_gset_eq:NN \MacroIndent \MacroIndent
847 \group_end:
848 }
849 \ExplSyntaxOff
850 \AtBeginDocument{\addtocontents{toc}{\StopSpecialIndexModule}}
851 \pdfstringdefDisableCommands{%
852 \let\path\meta
853 \let\opt\@firstofone}
854 \preto\@thehead{\cslet{MakeUppercase\space}{\@iden}}
855 \def\orbar{\textup{\textbar}}
856 \def\defaultval#1{\textbf{\textup{#1}}}
857 \def\defaultvalaux#1){\defaultval{#1}}
858 \def\TF{true\orbar false}
859 \def\TTF{\defaultval{true}\orbar false}
860 \def\TFF{true\orbar\defaultval{false}}
861 \protected\def\opt{\texttt}
862 \def\TeX{\hologo{TeX}}
863 \def\pdfTeX{\hologo{pdfTeX}}
864 \def\XeTeX{\hologo{XeTeX}}
865 \def\XeLaTeX{\hologo{XeLaTeX}}
866 \def\LuaLaTeX{\hologo{LuaLaTeX}}
867 \def\pdfLaTeX{\hologo{pdfLaTeX}}
868 \def\LaTeX{\hologo{LaTeX}}
869 \def\LaTeXe{\hologo{LaTeX2e}}
870 \def\LaTeXiii{\hologo{LaTeX3}}
871 \def\dvipdfmx{\hologo{DVIPDFMx}}
872 \def\TeXLive{\hologo{TeXLive}}
873 \def\MiKTeX{\hologo{MiKTeX}}
874 \def\pTeX{\hologo{pTeX}}
875 \def\ApTeX{\hologo{ApTeX}}
876 \def\upTeX{\hologo{upTeX}}
877 \def\ApLaTeX{\hologo{ApLaTeX}}
878 \def\upLaTeX{\hologo{upLaTeX}}
879 \def\HoLogo@pTeX#1{p\kern -.15em \hologo{TeX}}
880 \def\HoLogo@pLaTeX#1{p\kern -.05em \hologo{LaTeX}}
881 \def\HoLogo@ApTeX#1{A\kern -.05em \hologo{pTeX}}
882 \def\HoLogo@upTeX#1{u\kern -.05em \hologo{pTeX}}
883 \def\HoLogo@ApLaTeX#1{A\kern -.05em \hologo{pLaTeX}}
884 \def\HoLogo@upLaTeX#1{u\kern -.05em \hologo{pLaTeX}}
885 \def\HoLogoBkm@pTeX#1{p\hologo{TeX}}
886 \def\HoLogoBkm@pLaTeX#1{p\hologo{LaTeX}}
887 \def\HoLogoBkm@ApTeX#1{A\hologo{pTeX}}
888 \def\HoLogoBkm@upTeX#1{u\hologo{pTeX}}
889 \def\HoLogoBkm@ApLaTeX#1{A\hologo{pLaTeX}}
890 \def\HoLogoBkm@upLaTeX#1{u\hologo{pLaTeX}}
891 \def\HoLogo@TeXLive#1{\TeX\ Live}
892 \def\HoLogo@DVIPDFMx#1{DVIPDFM\ensuremath{x}}
893 \def\bashcmd{\texttt}
894 \def\BSTACK{\begin{tabular}[t]{@{}l@{}}}
895 \def\ESTACK{\end{tabular}}
896 \newenvironment{defaultcapconfig}{%
897 \MakePercentComment
898 \input{ctex-name-utf8.cfg}%
899 \ExplSyntaxOff
900 \MakePercentIgnore}{}
901 \def\ctexkit{\href{https://github.com/CTeX-org/ctex-kit/}{\texttt{ctex-kit}}}
902 \def\ctexkitrev#1{%
903 \href{https://github.com/CTeX-org/ctex-kit/commit/#1}{\texttt{ctex-kit} rev. #1}}
904 \appto\GlossaryParms{%
905 \raggedcolumns
906 \let\Hy@writebookmark\HDorg@writebookmark
907 \def\@idxitem{\par\hangindent 2em }%
908 \def\subitem{\@idxitem\hspace*{1em}}%
909 \def\subsubitem{\@idxitem\hspace*{2em}}}
910 \def\glossaryname{版本历史}
911 \GlossaryPrologue{\section{\glossaryname}}
912 \IndexPrologue{%
913 \section{\indexname}
914 \textit{意大利体的数字表示描述对应索引项的页码;
915 带下划线的数字表示定义对应索引项的代码行号;
916 罗马字体的数字表示使用对应索引项的代码行号。}}
917 \def\IndexLayout{%
918 \newgeometry{hmargin=15mm,vmargin={25mm,15mm},footskip=7mm}%
919 \setlength\IndexMin{.5\textheight}%
920 \ctexset{section/numbering=false}%
921 \StopSpecialIndexModule}
922 \EnableCrossrefs
923 \CodelineIndex
924 \RecordChanges
925 %%
926 %%
927 %% End of file ctxdoc.cls.