Debian Codegraph @

texmf-dist/doc/latex/codebox/ctxdoc-en.cls

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