| 1 |
% \iffalse meta-comment |
| 2 |
% !TEX program = XeLaTeX |
| 3 |
%<*internal> |
| 4 |
\iffalse |
| 5 |
%</internal> |
| 6 |
%<*readme> |
| 7 |
Create code box and viewer based on tcolorbox and minted/listings |
| 8 |
======= |
| 9 |
|
| 10 |
`codebox` is a LaTeX3 package developed based on tcolorbox and minted/listings, which provides environments `codebox` and `codeview` to typset with environment body, and macros `\codefile` and `\cvfile` to typeset programming source code from a file in a fancy box. |
| 11 |
|
| 12 |
The starred version of all environments and macros are provided at the same time, such as `codebox*`, `codeview*`, `\codefile*` and `\cvfile*` which adds comment at bottom of the fancy box. |
| 13 |
|
| 14 |
You can read the manual (in Chinese/English) for more details and examples. |
| 15 |
|
| 16 |
Contributing |
| 17 |
------------ |
| 18 |
|
| 19 |
1. github repository: |
| 20 |
1. repository: [codebox](https://github.com/registor/codebox) |
| 21 |
2. Issues and pull requests are welcome. [issue](https://github.com/registor/codebox/issues) or [pull request](https://github.com/registor/codebox/pulls). |
| 22 |
|
| 23 |
2. gitee repository: |
| 24 |
1. repository: [codebox](https://gitee.com/nwafu_nan/codebox) |
| 25 |
2. Issues and pull requests are welcome. [issue](https://gitee.com/nwafu_nan/codebox/issues) or [pull request](https://gitee.com/nwafu_nan/codebox/pulls). |
| 26 |
|
| 27 |
基于tcolorbox的终端模拟宏包 |
| 28 |
======= |
| 29 |
|
| 30 |
`codebox`是一个基于tcolorbox的用LaTeX3开发的终端模拟LaTeX宏包,它提供了用于排版程序源代码盒子的环境和命令。 |
| 31 |
|
| 32 |
其中`codebox`和`codeview`环境用于根据环境内容排版代码,`\codefile`和`\cvfile`命令用于根据文件内容排版代码。 |
| 33 |
|
| 34 |
`codebox`同时提供了各环境和命令的星号版本,如`codebox*`和`codeview*`,`\codefile*`和`\cvfile*`,用于为代码盒子添加底线注释。 |
| 35 |
|
| 36 |
可以通过阅读宏包手册(中文/英文)以也解该宏包更多的使用细节和使用样例。 |
| 37 |
|
| 38 |
### 参与贡献 |
| 39 |
--------------------- |
| 40 |
|
| 41 |
1. github仓库: |
| 42 |
(1). 仓库地址: [codebox](https://github.com/registor/codebox) |
| 43 |
(2). Issues和PR: [issue](https://github.com/registor/codebox/issues) or [pull request](https://github.com/registor/codebox/pulls). |
| 44 |
|
| 45 |
2. gitee仓库: |
| 46 |
(1). 仓库地址: [codebox](https://gitee.com/nwafu_nan/codebox) |
| 47 |
(2). Issues and PR: [issue](https://gitee.com/nwafu_nan/codebox/issues) or [pull request](https://gitee.com/nwafu_nan/codebox/pulls). |
| 48 |
|
| 49 |
Copyright and Licence |
| 50 |
--------------------- |
| 51 |
|
| 52 |
Copyright (C) 2020-2022 by Nan Geng <[email protected]> |
| 53 |
---------------------------------------------------------------------- |
| 54 |
|
| 55 |
This work may be distributed and/or modified under the |
| 56 |
conditions of the LaTeX Project Public License, either |
| 57 |
version 1.3c of this license or (at your option) any later |
| 58 |
version. This version of this license is in |
| 59 |
http://www.latex-project.org/lppl/lppl-1-3c.txt |
| 60 |
and the latest version of this license is in |
| 61 |
http://www.latex-project.org/lppl.txt |
| 62 |
and version 1.3 or later is part of all distributions of |
| 63 |
LaTeX version 2005/12/01 or later. |
| 64 |
|
| 65 |
This work has the LPPL maintenance status "maintained". |
| 66 |
|
| 67 |
The Current Maintainer of this work is Nan Geng. |
| 68 |
|
| 69 |
This package consists of the file codebox.dtx, |
| 70 |
and the derived files codebox.sty, |
| 71 |
codebox.pdf, |
| 72 |
codebox.ins, |
| 73 |
README.md (this file). |
| 74 |
|
| 75 |
%</readme> |
| 76 |
%<*internal> |
| 77 |
\fi |
| 78 |
\begingroup |
| 79 |
\def\temp{LaTeX2e} |
| 80 |
\expandafter\endgroup\ifx\temp\fmtname\else |
| 81 |
\csname fi\endcsname |
| 82 |
%</internal> |
| 83 |
%<*install> |
| 84 |
|
| 85 |
\input ctxdocstrip % |
| 86 |
|
| 87 |
\let\MetaPrefix\relax |
| 88 |
|
| 89 |
\preamble |
| 90 |
|
| 91 |
Copyright (C) 2020-2022 by Nan Geng <[email protected]> |
| 92 |
-------------------------------------------------------------------------- |
| 93 |
|
| 94 |
This work may be distributed and/or modified under the |
| 95 |
conditions of the LaTeX Project Public License, either |
| 96 |
version 1.3c of this license or (at your option) any later |
| 97 |
version. This version of this license is in |
| 98 |
http://www.latex-project.org/lppl/lppl-1-3c.txt |
| 99 |
and the latest version of this license is in |
| 100 |
http://www.latex-project.org/lppl.txt |
| 101 |
and version 1.3 or later is part of all distributions of |
| 102 |
LaTeX version 2005/12/01 or later. |
| 103 |
|
| 104 |
This work has the LPPL maintenance status "maintained". |
| 105 |
|
| 106 |
The Current Maintainer of this work is Nan Geng. |
| 107 |
|
| 108 |
-------------------------------------------------------------------------- |
| 109 |
|
| 110 |
\endpreamble |
| 111 |
|
| 112 |
\postamble |
| 113 |
|
| 114 |
This package consists of the file codebox.dtx, |
| 115 |
and the derived files codebox.sty, |
| 116 |
codebox.pdf, |
| 117 |
codebox.ins, |
| 118 |
README.md. |
| 119 |
\endpostamble |
| 120 |
|
| 121 |
\declarepostamble\emptypostamble |
| 122 |
\endpostamble |
| 123 |
|
| 124 |
\def\MetaPrefix{-- } |
| 125 |
|
| 126 |
|
| 127 |
\let\MetaPrefix\DoubleperCent |
| 128 |
|
| 129 |
\generate |
| 130 |
{ |
| 131 |
%</install> |
| 132 |
%<*internal> |
| 133 |
\usedir{source/xelatex/codebox} |
| 134 |
\file{codebox.ins} {\from{\jobname.dtx}{install}} |
| 135 |
%</internal> |
| 136 |
%<*install> |
| 137 |
\usedir{xetex/xelatex/codebox} |
| 138 |
\file{codebox.sty} {\from{\jobname.dtx}{package}} |
| 139 |
\nopreamble\nopostamble |
| 140 |
\usedir{doc/xelatex/codebox} |
| 141 |
\file{README.md} {\from{\jobname.dtx}{readme}} |
| 142 |
} |
| 143 |
|
| 144 |
\endbatchfile |
| 145 |
%</install> |
| 146 |
%<*internal> |
| 147 |
\fi |
| 148 |
%</internal> |
| 149 |
%<package>\NeedsTeXFormat{LaTeX2e}[2020/10/01] |
| 150 |
%<package>\RequirePackage{expl3} |
| 151 |
%<+package>\GetIdInfo$Id: codebox.dtx 1.0.4 2022-01-28 08:00:00 +0800 Nan Geng <[email protected]> $ |
| 152 |
%<package> {Code Box with tcolorbox and minted/listings.} |
| 153 |
%<package>\ProvidesExplPackage{\ExplFileName} |
| 154 |
%<package> {\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} |
| 155 |
%<*driver> |
| 156 |
\documentclass{ctxdoc} |
| 157 |
\usepackage{minted} |
| 158 |
\usepackage{listings} |
| 159 |
\usepackage{xcolor} |
| 160 |
\usepackage{xcolor-material} |
| 161 |
\usepackage{codebox} |
| 162 |
\renewcommand*\marg[1]{\{\meta{#1}\}} |
| 163 |
\renewcommand*\oarg[1]{[\meta{#1}]} |
| 164 |
\renewcommand*\parg[1]{(\meta{#1})} |
| 165 |
\NewDocumentCommand{\init}{+v}{\hspace{\fill}初始值~=~\textcolor{blue}{\bfseries#1}} |
| 166 |
\DeclareDocumentCommand\opt{m}{\texttt{#1}} |
| 167 |
\DeclareDocumentCommand\kvopt{mm} |
| 168 |
{\texttt{#1\breakablethinspace=\breakablethinspace#2}} |
| 169 |
\def\breakablethinspace{\hskip 0.16667em\relax} |
| 170 |
\begin{document} |
| 171 |
%<!--CODEDOC--> \DisableImplementation |
| 172 |
\EnableImplementation |
| 173 |
\DocInput{\jobname.dtx} |
| 174 |
\IndexLayout |
| 175 |
\PrintChanges |
| 176 |
\PrintIndex |
| 177 |
\end{document} |
| 178 |
%</driver> |
| 179 |
% \fi |
| 180 |
% |
| 181 |
% \changes{v1.0.0}{2021/12/25}{开始编写模板} |
| 182 |
% |
| 183 |
% \CheckSum{313} |
| 184 |
% \GetFileId{codebox.sty} |
| 185 |
% |
| 186 |
% \CharacterTable |
| 187 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 188 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 189 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 190 |
% Exclamation \! Double quote \" Hash (number) \# |
| 191 |
% Dollar \$ Percent \% Ampersand \& |
| 192 |
% Acute accent \' Left paren \( Right paren \) |
| 193 |
% Asterisk \* Plus \+ Comma \, |
| 194 |
% Minus \- Point \. Solidus \/ |
| 195 |
% Colon \: Semicolon \; Less than \< |
| 196 |
% Equals \= Greater than \> Question mark \? |
| 197 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 198 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 199 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 200 |
% Right brace \} Tilde \~} |
| 201 |
% |
| 202 |
% |
| 203 |
% \title{\bfseries\pkg{codebox}:代码盒子排版宏包\\ \bfseries\pkg{codebox}:progrmming source code box} |
| 204 |
% \author{耿楠\\ \path{[email protected]}} |
| 205 |
% \date{\filedate\qquad\fileversion\thanks{\url{https://github.com/registor/codebox}}\thanks{\url{https://gitee.com/nwafu_nan/codebox}}} |
| 206 |
% \maketitle |
| 207 |
% |
| 208 |
% \begin{documentation} |
| 209 |
% |
| 210 |
% \begin{abstract} |
| 211 |
% |
| 212 |
% \pkg{codebox} 是一个基于\pkg{tcolorbox}用\LaTeX3 开发的 \LaTeX 宏包,它提供用于 |
| 213 |
% 排版源代码盒子的环境和命令。 |
| 214 |
% 其中,\env{codebox}和\env{codeview}环境用于根据环境内容排版代码, |
| 215 |
% \tn{codefile}和\tn{cvfile}命令用于根据文件内容排版代码。 |
| 216 |
% 同时,\pkg{codebox}还提供了各环境和命令的星号版本, |
| 217 |
% 如\env{codebox*}和\env{codeview*},\tn{codefile*}和\tn{cvfile*}, |
| 218 |
% 用于为代码盒子添加底线注释。 |
| 219 |
% |
| 220 |
% \end{abstract} |
| 221 |
% |
| 222 |
% \tableofcontents |
| 223 |
% |
| 224 |
% \section{简介} |
| 225 |
% |
| 226 |
% \pkg{codebox} 是一个基于\pkg{tcolorbox}用\LaTeX3 开发的 \LaTeX 宏包, |
| 227 |
% 它可以根据用户设置使用\pkg{minted}或\pkg{listings}宏包实现代码盒子排版。 |
| 228 |
% |
| 229 |
% 该宏包提供了\env{codebox}和\env{codeview}两个环境和 |
| 230 |
% \tn{codefile}和\tn{cvfile}两个命令以排版代码盒子。 |
| 231 |
% |
| 232 |
% 同时,\pkg{codebox}宏包还提供环境和命令的星号版本, |
| 233 |
% 用于为代码盒子添加底线注释。 |
| 234 |
% |
| 235 |
% \section{用户接口} |
| 236 |
% |
| 237 |
% \subsection{\env{codebox}和\env{codebox*}环境} |
| 238 |
% |
| 239 |
% \begin{function}[added=2021-12-25,updated=2021-12-25]{codebox,codebox*} |
| 240 |
% \begin{syntax} |
| 241 |
% \tn{begin}\{codebox\}\oarg{外观选项}\Arg{盒子标题} |
| 242 |
% ..... |
| 243 |
% \tn{end}\{codebox\} |
| 244 |
% \tn{begin}\{codebox*\}\oarg{外观选项}\Arg{盒子标题} |
| 245 |
% ..... |
| 246 |
% \tn{end}\{codebox*\} |
| 247 |
% \end{syntax} |
| 248 |
% 使用环境内容排版代码盒子。 |
| 249 |
% 可以通过\Arg{盒子标题}为代码盒子设置标题。 |
| 250 |
% |
| 251 |
% \oarg{外观选项}中通过key-value方式设置代码盒子外观。 |
| 252 |
% |
| 253 |
% 星号环境\texttt{codebox*}用于为代码盒子添加底线注释, |
| 254 |
% 此时,需要在\oarg{外观选项}中用 |
| 255 |
% \kvopt{\meta{comments}}{\meta{底线注释}}选项提供\textbf{底线注释}内容。 |
| 256 |
% |
| 257 |
% 代码盒子的外观也可以通过\tn{codeset}命令的逗号分隔 |
| 258 |
% key-value列表进行设置。 |
| 259 |
% |
| 260 |
% \end{function} |
| 261 |
% \begin{Verbatim}[frame=none,numbers=left,gobble=5] |
| 262 |
% \centering |
| 263 |
% \begin{codebox}{代码标题} |
| 264 |
% #include <stdio.h> |
| 265 |
% #include <stdlib.h> |
| 266 |
% |
| 267 |
% int main(void) |
| 268 |
% { |
| 269 |
% printf("Hello World!\n"); |
| 270 |
% |
| 271 |
% return 0; |
| 272 |
% } |
| 273 |
% \end{codebox} |
| 274 |
% \end{Verbatim} |
| 275 |
% |
| 276 |
% \begin{center} |
| 277 |
% \begin{minipage}{0.85\textwidth} |
| 278 |
% \codefile{代码盒子标题}{test.c} |
| 279 |
% \end{minipage} |
| 280 |
% \end{center} |
| 281 |
% |
| 282 |
% \subsection{\tn{codefile}和\tn{codefile*}命令} |
| 283 |
% |
| 284 |
% \begin{function}[added=2021-12-25,updated=2021-12-25]{\codefile,\codefile*} |
| 285 |
% \begin{syntax} |
| 286 |
% \tn{codefile} \oarg{外观选项} \Arg{盒子标题} \Arg{代码文件} |
| 287 |
% \tn{codefile*} \oarg{外观选项} \Arg{盒子标题} \Arg{代码文件} |
| 288 |
% \end{syntax} |
| 289 |
% |
| 290 |
% 用于排版代码盒子,源代码来自于\Arg{代码文件}, |
| 291 |
% 可以通过\Arg{盒子标题}为代码盒子设置标题。 |
| 292 |
% |
| 293 |
% \oarg{外观选项}中通过key-value方式设置代码盒子外观。 |
| 294 |
% |
| 295 |
% 星号命令\texttt{codefile*}用于为代码盒子添加底线注释, |
| 296 |
% 此时,需要在\oarg{外观选项}中用 |
| 297 |
% \kvopt{\meta{comments}}{\meta{底线注释}}选项提供\textbf{底线注释}内容。 |
| 298 |
% |
| 299 |
% 代码盒子的外观也可以通过\tn{codeset}命令的逗号分隔 |
| 300 |
% key-value列表进行设置。 |
| 301 |
% \end{function} |
| 302 |
% |
| 303 |
% \newpage |
| 304 |
% \begin{Verbatim}[frame=none,numbers=left,gobble=5] |
| 305 |
% \centering |
| 306 |
% \codefile{代码盒子标题}{test.c} |
| 307 |
% \end{Verbatim} |
| 308 |
% |
| 309 |
% \begin{center} |
| 310 |
% \begin{minipage}{0.85\textwidth} |
| 311 |
% \codefile{代码盒子标题}{test.c} |
| 312 |
% \end{minipage} |
| 313 |
% \end{center} |
| 314 |
% |
| 315 |
% \subsection{\env{codeview}和\env{codeview*}环境} |
| 316 |
% |
| 317 |
% \begin{function}[added=2021-12-26,updated=2021-12-26]{codeview,codeview*} |
| 318 |
% \begin{syntax} |
| 319 |
% \tn{begin}\{codeview\}\oarg{外观选项}\Arg{盒子标题} |
| 320 |
% ..... |
| 321 |
% \tn{end}\{codeview\} |
| 322 |
% \tn{begin}\{codeview*\}\oarg{外观选项}\Arg{盒子标题} |
| 323 |
% ..... |
| 324 |
% \tn{end}\{codeview*\} |
| 325 |
% \end{syntax} |
| 326 |
% 使用环境内容排版带编号代码盒子。 |
| 327 |
% 可以通过\Arg{盒子标题}为代码盒子设置标题。 |
| 328 |
% |
| 329 |
% \oarg{外观选项}中通过key-value方式设置代码盒子外观。 |
| 330 |
% |
| 331 |
% 星号环境\texttt{codeview*}用于为代码盒子添加底线注释, |
| 332 |
% 此时,需要在\oarg{外观选项}中用 |
| 333 |
% \kvopt{\meta{comments}}{\meta{底线注释}}选项提供\textbf{底线注释}内容。 |
| 334 |
% |
| 335 |
% 代码盒子的外观也可以通过\tn{codeset}命令的逗号分隔 |
| 336 |
% key-value列表进行设置。 |
| 337 |
% \end{function} |
| 338 |
% |
| 339 |
% \begin{Verbatim}[frame=none,numbers=left,gobble=5] |
| 340 |
% \centering |
| 341 |
% \begin{codeview}{代码标题} |
| 342 |
% #include <stdio.h> |
| 343 |
% #include <stdlib.h> |
| 344 |
% |
| 345 |
% int main(void) |
| 346 |
% { |
| 347 |
% printf("Hello World!\n"); |
| 348 |
% |
| 349 |
% return 0; |
| 350 |
% } |
| 351 |
% \end{codeview} |
| 352 |
% \end{Verbatim} |
| 353 |
% |
| 354 |
% \codeset{pretitle=代码} |
| 355 |
% \begin{center} |
| 356 |
% \begin{minipage}{0.85\textwidth} |
| 357 |
% \cvfile{代码标题}{test.c} |
| 358 |
% \end{minipage} |
| 359 |
% \end{center} |
| 360 |
% |
| 361 |
% \subsection{\tn{cvfile}和\tn{cvfile*}命令} |
| 362 |
% |
| 363 |
% \begin{function}[added=2021-12-26,updated=2021-12-26]{\cvfile,\cvfile*} |
| 364 |
% \begin{syntax} |
| 365 |
% \tn{cvfile} \oarg{外观选项} \Arg{盒子标题} \Arg{代码文件} |
| 366 |
% \tn{cvfile*} \oarg{外观选项} \Arg{盒子标题} \Arg{代码文件} |
| 367 |
% \end{syntax} |
| 368 |
% |
| 369 |
% 用于排版带编号代码盒子,源代码来自于\Arg{代码文件}, |
| 370 |
% 可以通过\Arg{盒子标题}为代码盒子设置标题。 |
| 371 |
% |
| 372 |
% \oarg{外观选项}中通过key-value方式设置代码盒子外观。 |
| 373 |
% |
| 374 |
% 星号命令\texttt{cvfile*}用于为代码盒子添加底线注释, |
| 375 |
% 此时,需要在\oarg{外观选项}中用 |
| 376 |
% \kvopt{\meta{comments}}{\meta{底线注释}}选项提供\textbf{底线注释}内容。 |
| 377 |
% |
| 378 |
% 代码盒子的外观也可以通过\tn{codeset}命令的逗号分隔 |
| 379 |
% key-value列表进行设置。 |
| 380 |
% \end{function} |
| 381 |
% |
| 382 |
% \begin{Verbatim}[frame=none,numbers=left,gobble=5] |
| 383 |
% \centering |
| 384 |
% \cvfile*[comments=这是一个简单的C语言代码]{代码标题}{test.c} |
| 385 |
% \end{Verbatim} |
| 386 |
% |
| 387 |
% \begin{center} |
| 388 |
% \begin{minipage}{0.85\textwidth} |
| 389 |
% \cvfile*[comments=这是一个简单的C语言代码]{代码标题}{test.c} |
| 390 |
% \end{minipage} |
| 391 |
% \end{center} |
| 392 |
% |
| 393 |
% \section{选项说明} |
| 394 |
% |
| 395 |
% \pkg{codebox}宏包提供了一系列选项,以设置代码盒子的外观样式。 |
| 396 |
% 载入\pkg{codebox}宏包后,以下选项均可通过用户接口命令\tn{codeset}进行设置。 |
| 397 |
% 当然,这些选项也可以通过各个环境或命令的\oarg{外观选项}进行设置。 |
| 398 |
% |
| 399 |
% \subsection{代码引擎} |
| 400 |
% |
| 401 |
% \begin{function}[added=2021-12-26,updated=2021-12-26]{minted} |
| 402 |
% \begin{syntax} |
| 403 |
% minted = <\TTF> \init{true} |
| 404 |
% \end{syntax} |
| 405 |
% \opt{minted} 用于设置代码排版引擎,如为\textbf{true}则使用\pkg{minted}宏包 |
| 406 |
% 排版代码盒子中的内容,如为\textbf{false}则使用\pkg{listings}宏包排版 |
| 407 |
% 代码盒子中的内容。默认值为\textbf{true}。 |
| 408 |
% \end{function} |
| 409 |
% |
| 410 |
% \subsection{代码语言} |
| 411 |
% |
| 412 |
% \begin{function}[added=2021-12-26,updated=2021-12-26]{lang} |
| 413 |
% \begin{syntax} |
| 414 |
% lang = \Arg{代码语言} \init{c} |
| 415 |
% \end{syntax} |
| 416 |
% \opt{lang} 用于设置代码语言,默认值为\textbf{c语言}。 |
| 417 |
% \end{function} |
| 418 |
% |
| 419 |
% \subsection{代码名称} |
| 420 |
% |
| 421 |
% \begin{function}[added=2021-12-26,updated=2021-12-26]{pretitle} |
| 422 |
% \begin{syntax} |
| 423 |
% pretitle = \Arg{代码名称} \init{Code} |
| 424 |
% \end{syntax} |
| 425 |
% \opt{pretitle} 用于代码编号前的代码名称前缀,默认值为\textbf{Code}。 |
| 426 |
% \end{function} |
| 427 |
% |
| 428 |
% \subsection{代码样式} |
| 429 |
% |
| 430 |
% \begin{function}[added=2021-12-26,updated=2021-12-26]{codestyle} |
| 431 |
% \begin{syntax} |
| 432 |
% codestyle = \Arg{代码样式} \init{codeblocks} |
| 433 |
% \end{syntax} |
| 434 |
% \opt{codestyle} 用于设置代码盒子中代码的样式,仅对\textbf{minted} |
| 435 |
% 引擎有效,默认值为\textbf{codeblocks}。 |
| 436 |
% \end{function} |
| 437 |
% |
| 438 |
% \subsection{代码字号} |
| 439 |
% |
| 440 |
% \begin{function}[added=2021-12-26,updated=2021-12-26]{codesize} |
| 441 |
% \begin{syntax} |
| 442 |
% codesize = \Arg{字号命令} \init{\small} |
| 443 |
% \end{syntax} |
| 444 |
% \opt{codesize} 用于设置代码盒子中代码的字号,仅对\textbf{minted} |
| 445 |
% 引擎有效,默认值为\textbf{\tn{small}}。 |
| 446 |
% \end{function} |
| 447 |
% |
| 448 |
% \subsection{底线注释内容} |
| 449 |
% |
| 450 |
% \begin{function}[added=2021-12-26,updated=2021-12-26]{comments} |
| 451 |
% \begin{syntax} |
| 452 |
% comments = \Arg{注释内容} \init{无} |
| 453 |
% \end{syntax} |
| 454 |
% \opt{commentf} 用于设置代码盒子底线注释的内容, |
| 455 |
% 默认值为\textbf{无}。 |
| 456 |
% \end{function} |
| 457 |
% |
| 458 |
% \subsection{底线注释格式} |
| 459 |
% |
| 460 |
% \begin{function}[added=2021-12-26,updated=2021-12-26]{commentf} |
| 461 |
% \begin{syntax} |
| 462 |
% commentf = \Arg{格式命令组} \init{\small\sffamily} |
| 463 |
% \end{syntax} |
| 464 |
% \opt{commentf} 用于设置代码盒子底线注释的格式, |
| 465 |
% 默认值为\textbf{\tn{small}\tn{sffamily}}。 |
| 466 |
% \end{function} |
| 467 |
% |
| 468 |
% \subsection{代码行距} |
| 469 |
% |
| 470 |
% \begin{function}[added=2021-12-26,updated=2021-12-26]{codestretch} |
| 471 |
% \begin{syntax} |
| 472 |
% codestretch = \Arg{浮点数} \init{1.0} |
| 473 |
% \end{syntax} |
| 474 |
% \opt{codestretch} 用于设置代码盒子内容(代码)的行距,仅对\textbf{minted} |
| 475 |
% 引擎有效,取浮点数。默认值为\textbf{1.0}。 |
| 476 |
% \end{function} |
| 477 |
% |
| 478 |
% \subsection{行号间距} |
| 479 |
% |
| 480 |
% \begin{function}[added=2021-12-26,updated=2022-1-28]{linenumsep} |
| 481 |
% \begin{syntax} |
| 482 |
% linenumsep = \Arg{浮点数} \init{1.80} |
| 483 |
% \end{syntax} |
| 484 |
% \opt{linenumsep} 用于设置代码盒子行号与代码的间距,仅对\textbf{minted} |
| 485 |
% 引擎有效,取浮点数,单位是mm。默认值为\textbf{3.0}。 |
| 486 |
% \end{function} |
| 487 |
% |
| 488 |
% \changes{v1.0.3}{2022/1/4}{添加label引用标签选项的使用说明} |
| 489 |
% |
| 490 |
% \subsection{引用标签} |
| 491 |
% |
| 492 |
% \begin{function}[added=2022-1-4,updated=2022-1-4]{label} |
| 493 |
% \begin{syntax} |
| 494 |
% label = \Arg{引用标签名称} \init{空} |
| 495 |
% \end{syntax} |
| 496 |
% \opt{label} 用于设置带编号代码盒子的引用标签, |
| 497 |
% 该选项仅对\env{codeview}/\env{codeview*}环境 |
| 498 |
% 或\tn{cvfile}/\tn{cvfile*}命令有效。 |
| 499 |
% 默认值为\textbf{空}。 |
| 500 |
% \end{function} |
| 501 |
% |
| 502 |
% \changes{v1.0.2}{2021/12/28}{添加cvcounter使用说明} |
| 503 |
% |
| 504 |
% \section{计数器} |
| 505 |
% |
| 506 |
% \begin{function}[added=2021-12-28,updated=2021-12-28]{cvcounter} |
| 507 |
% \pkg{codebox}宏包提供了一个计数器\texttt{cvcounter}, |
| 508 |
% 当使用带编号环境\env{codeview}/\env{codeview*}和 |
| 509 |
% 命令\tn{cvfile}/\tn{cvfile*}排版代码时,可以用于对代码盒子进行计数。 |
| 510 |
% 默认情况下,如果存在\texttt{thechapter}计数器,则其父计数器设置为\texttt{chapter} |
| 511 |
% 否则将按全文统一计数。 |
| 512 |
% |
| 513 |
% 可以使用类似\tn{renewcommand\{\tn{thecvcounter}\}\{\tn{thechapter.\tn{arabic\{cvcounter\}}}\}} |
| 514 |
% 的形式更改编号输出内容。 |
| 515 |
% \end{function} |
| 516 |
% |
| 517 |
% \newpage |
| 518 |
% \section{排版样例} |
| 519 |
% |
| 520 |
% \pkg{codebox}宏包可用于需要语法高亮代码排版场合, |
| 521 |
% 以避免使用代码截图。代码盒子可以带/不带底线注释。 |
| 522 |
% |
| 523 |
% \subsection{Java代码} |
| 524 |
% 可以使用\tn{codeset}命令设置代码语言。 |
| 525 |
% |
| 526 |
% \begin{Verbatim}[frame=none,numbers=left,gobble=5] |
| 527 |
% \centering |
| 528 |
% \codeset{lang=java} |
| 529 |
% \codefile{Java代码盒子}{hellojava.java} |
| 530 |
% \end{Verbatim} |
| 531 |
% |
| 532 |
% \begin{center} |
| 533 |
% \begin{minipage}{0.85\textwidth} |
| 534 |
% \codeset{lang=java} |
| 535 |
% \codefile{Java代码盒子}{hellojava.java} |
| 536 |
% \end{minipage} |
| 537 |
% \end{center} |
| 538 |
% |
| 539 |
% \subsection{Python代码} |
| 540 |
% 还可以使用环境或命令的\oarg{外观选项}设置代码语言。 |
| 541 |
% 当然,也可以通过使用\opt{label}选项为编号代码添加引用标签, |
| 542 |
% 并通过\tn{ref}命令引用该标签,如代码\ref{code-test}所示。 |
| 543 |
% |
| 544 |
% \begin{Verbatim}[frame=none,numbers=left,gobble=5] |
| 545 |
% \centering |
| 546 |
% \cvfile[lang=python,label=code-test]{Python代码示例}{hellopy.py} |
| 547 |
% \end{Verbatim} |
| 548 |
% |
| 549 |
% \begin{center} |
| 550 |
% % \begin{minipage}{0.85\textwidth} |
| 551 |
% \cvfile[lang=python,label=code-test]{Python代码示例}{hellopy.py} |
| 552 |
% \end{minipage} |
| 553 |
% \end{center} |
| 554 |
% |
| 555 |
% \subsection{listings引擎} |
| 556 |
% 在选项中使用\kvopt{\meta{minted}}{\meta{false}} |
| 557 |
% 以使用\pkg{listings}宏包排版代码。 |
| 558 |
% |
| 559 |
% \begin{Verbatim}[frame=none,numbers=left,gobble=5] |
| 560 |
% \centering |
| 561 |
% \cvfile[minted=false,lang=c]{C语言代码示例}{test.c} |
| 562 |
% \end{Verbatim} |
| 563 |
% |
| 564 |
% \begin{center} |
| 565 |
% \begin{minipage}{0.85\textwidth} |
| 566 |
% \cvfile[minted=false,lang=c]{C语言代码示例}{test.c} |
| 567 |
% \end{minipage} |
| 568 |
% \end{center} |
| 569 |
% |
| 570 |
% |
| 571 |
% \end{documentation} |
| 572 |
% |
| 573 |
% \StopEventually{} |
| 574 |
% |
| 575 |
% \begin{implementation} |
| 576 |
% |
| 577 |
% \section{代码实现} |
| 578 |
% |
| 579 |
% 该宏包使用 \LaTeX3 语法编写,依赖 \pkg{expl3} 环境, |
| 580 |
% 并需调用 \pkg{l3packages}、\pkg{tcolorbox}、\pkg{minted} |
| 581 |
% \pkg{listings}、\pkg{fontawesome5}等宏包。 |
| 582 |
% |
| 583 |
% 按照 \LaTeX3 语法,代码中的空格、换行、回车与制表符会完全被忽略, |
| 584 |
% 而下划线“|_|”和冒号“|:|”则可作为一般字母使用。 |
| 585 |
% 正常的空格可以使用“|~|”代替;至于 |~| 原来所表示的“带子”, |
| 586 |
% 则要用 \LaTeXe{} 的原始命令 \tn{nobreakspace} 代替。 |
| 587 |
% |
| 588 |
% 以下代码中有一些形如 \textcolor[HTML]{2E3191}{\textsf{<*package>}} |
| 589 |
% 的标记,这是 \pkg{DocStrip} 中的“guard”,用来选择性地提取文件。 |
| 590 |
% “\textsf{*}”和“\textsf{/}”分别表示该部分的开始和结束。不含 |
| 591 |
% “\textsf{*}”和“\textsf{/}”的 guard 出现在行号右侧,它们用来确定 |
| 592 |
% 单独一行代码的归属。这些 guard 的颜色深浅不一,用以明确嵌套关系。 |
| 593 |
% |
| 594 |
% 另有若干形如 \textcolor[HTML]{AD1457}{\textsf{<@@=codebox>}} 的 guard, |
| 595 |
% 它们由 \pkg{l3docstrip} 定义,用来标识名字空间(模块)。 |
| 596 |
% |
| 597 |
% \subsection{环境检测与准备} |
| 598 |
% |
| 599 |
% \begin{macrocode} |
| 600 |
%<*package> |
| 601 |
%<@@=codebox> |
| 602 |
% \end{macrocode} |
| 603 |
% |
| 604 |
% 载入必要的\LaTeX3 宏包 |
| 605 |
% |
| 606 |
% \begin{macrocode} |
| 607 |
\RequirePackage { xtemplate, l3keys2e, xparse } |
| 608 |
% \end{macrocode} |
| 609 |
% |
| 610 |
% \changes{v1.0.1}{2021/12/26}{删除原\LaTeX3 版本检测代码} |
| 611 |
% |
| 612 |
% \subsection{载入其它宏包} |
| 613 |
% |
| 614 |
% 载入\pkg{fontawesome5}、\pkg{tcolorbox}、\pkg{amssymb}、 |
| 615 |
% \pkg{xcolor}宏包 |
| 616 |
% |
| 617 |
% \begin{macrocode} |
| 618 |
\RequirePackage {fontawesome5, tcolorbox, varwidth, xcolor, etoolbox} |
| 619 |
% \end{macrocode} |
| 620 |
% |
| 621 |
% 解决Expl3中\pkg{tcolorbox}和\pkg{tikz}附加库无法加载的 |
| 622 |
% 的补丁(需要\pkg{etoolbox}宏包支持) |
| 623 |
% |
| 624 |
% \url{https://tex.stackexchange.com/questions/57424/using-of-usetikzlibrary-in-an-expl3-package-fails} |
| 625 |
% |
| 626 |
% \begin{macrocode} |
| 627 |
\ExplSyntaxOff |
| 628 |
\patchcmd |
| 629 |
{\tcb@input@library@in} |
| 630 |
{% |
| 631 |
\input\tcbpkgprefix#1\relax% |
| 632 |
} |
| 633 |
{% |
| 634 |
\@pushfilename |
| 635 |
\input\tcbpkgprefix#1\relax% |
| 636 |
\@popfilename |
| 637 |
} |
| 638 |
{}{} |
| 639 |
|
| 640 |
\patchcmd |
| 641 |
{\pgfutil@InputIfFileExists} |
| 642 |
{\input #1} |
| 643 |
{% |
| 644 |
\@pushfilename |
| 645 |
\xdef\@currname{#1}% |
| 646 |
\input #1 % |
| 647 |
\@popfilename |
| 648 |
} |
| 649 |
{}{} |
| 650 |
\ExplSyntaxOn |
| 651 |
% \end{macrocode} |
| 652 |
% |
| 653 |
% \changes{v1.0.1}{2021/12/26}{minted2.6发布,删除原补丁代码} |
| 654 |
% |
| 655 |
% 载入\pkg{tcolorbox}和\pkg{tikz}附加库 |
| 656 |
% |
| 657 |
% \begin{macrocode} |
| 658 |
\tcbuselibrary{skins, xparse, breakable} |
| 659 |
\tcbuselibrary{minted,listings} |
| 660 |
\usetikzlibrary{shapes.geometric} |
| 661 |
% \end{macrocode} |
| 662 |
% |
| 663 |
% \subsection{定义颜色} |
| 664 |
% |
| 665 |
% \begin{macrocode} |
| 666 |
\definecolor{cvgrayc}{RGB}{247,247,247} |
| 667 |
\definecolor{cvgray}{RGB}{220,220,220} |
| 668 |
\definecolor{cvgrayb}{RGB}{153,153,153} |
| 669 |
\definecolor{cvblue}{RGB}{223,238,255} |
| 670 |
\definecolor{chengse}{RGB}{250,140,53} |
| 671 |
% \end{macrocode} |
| 672 |
% |
| 673 |
% \subsection{代码盒子样式设计} |
| 674 |
% |
| 675 |
% 代码盒子lang样式 |
| 676 |
% |
| 677 |
% \begin{macrocode} |
| 678 |
\tcbset{% |
| 679 |
skin=enhanced, |
| 680 |
lang/.style={% |
| 681 |
breakable,% |
| 682 |
drop~shadow,% |
| 683 |
colframe=gray!75!black,% |
| 684 |
left=4.5mm, |
| 685 |
enhanced,% |
| 686 |
colframe=tcbcolback!60!black,% |
| 687 |
colback=white,% |
| 688 |
colbacktitle=tcbcolback!5!gray!10!white,% |
| 689 |
fonttitle=\bfseries,% |
| 690 |
coltitle=black,% |
| 691 |
attach~boxed~title~to~top~center={% |
| 692 |
yshift=-0.25mm-\tcboxedtitleheight/2,% |
| 693 |
yshifttext=2mm-\tcboxedtitleheight/2% |
| 694 |
},% |
| 695 |
attach~boxed~title~to~top~left={% |
| 696 |
xshift=1cm,% |
| 697 |
yshift*=1mm-\tcboxedtitleheight% |
| 698 |
},% |
| 699 |
varwidth~boxed~title*=-3cm,% |
| 700 |
boxed~title~style={% |
| 701 |
frame~code={% |
| 702 |
\path[fill=tcbcolback!30!black]([yshift=-1mm,xshift=-1mm]frame.north~west)% |
| 703 |
arc[start~angle=0,end~angle=180,radius=1mm]([yshift=-1mm,xshift=1mm]frame.north~east)% |
| 704 |
arc[start~angle=180,end~angle=0,radius=1mm];% |
| 705 |
\path[left~color=tcbcolback!60!black,right~color=tcbcolback!60!black, |
| 706 |
middle~color=tcbcolback!80!black]([xshift=-2mm]frame.north~west)% |
| 707 |
--([xshift=2mm]frame.north~east)[rounded~corners=1mm]% |
| 708 |
--([xshift=1mm,yshift=-1mm]frame.north~east)% |
| 709 |
--(frame.south~east)% |
| 710 |
--(frame.south~west)% |
| 711 |
--([xshift=-1mm,yshift=-1mm]frame.north~west)[sharp~corners]% |
| 712 |
--cycle;% |
| 713 |
},% |
| 714 |
interior~engine=empty% |
| 715 |
},% |
| 716 |
overlay={% |
| 717 |
\begin{tcbclipinterior} |
| 718 |
\fill[tcbcolback!80!black] (frame.south~west) rectangle |
| 719 |
([xshift=5mm]frame.north~west); |
| 720 |
\end{tcbclipinterior}% |
| 721 |
}, |
| 722 |
}% |
| 723 |
}% |
| 724 |
% \end{macrocode} |
| 725 |
% |
| 726 |
% \changes{v1.0.4}{2022/1/28}{修订分页代码盒子无行号底色问题} |
| 727 |
% |
| 728 |
% 代码盒子cv样式 |
| 729 |
% |
| 730 |
% \begin{macrocode} |
| 731 |
\tcbset{% |
| 732 |
skin=enhanced, |
| 733 |
cv/.style={ |
| 734 |
boxrule=0.4mm, |
| 735 |
breakable, |
| 736 |
top=0mm, |
| 737 |
boxsep=1mm, |
| 738 |
drop~shadow, |
| 739 |
attach~boxed~title~to~top, |
| 740 |
colframe=blue!75!black, |
| 741 |
left=4.5mm, |
| 742 |
right=0mm, |
| 743 |
enhanced, |
| 744 |
colframe=tcbcolback!60!black, |
| 745 |
colback=white, |
| 746 |
colbacktitle=cvgray, |
| 747 |
fonttitle=\ttfamily, |
| 748 |
coltitle=black, |
| 749 |
underlay~boxed~title = { |
| 750 |
\begin{tcbclipinterior} |
| 751 |
\fill[cvblue] (frame.south~west) rectangle ([xshift=5.0mm,yshift=0mm]frame.north~west); |
| 752 |
\end{tcbclipinterior} |
| 753 |
}, |
| 754 |
underlay~middle = { |
| 755 |
\begin{tcbclipinterior} |
| 756 |
\fill[cvblue] (frame.south~west) rectangle |
| 757 |
([xshift=5.0mm,yshift=0mm]frame.north~west); |
| 758 |
\end{tcbclipinterior} |
| 759 |
}, |
| 760 |
underlay~last = { |
| 761 |
\begin{tcbclipinterior} |
| 762 |
\fill[cvblue] (frame.south~west) rectangle |
| 763 |
([xshift=5.0mm,yshift=0mm]frame.north~west); |
| 764 |
\end{tcbclipinterior} |
| 765 |
}, |
| 766 |
} |
| 767 |
}% |
| 768 |
% \end{macrocode} |
| 769 |
% |
| 770 |
% \subsection{内部变量声明} |
| 771 |
% |
| 772 |
% \begin{variable}{\l_@@_minted_bool, |
| 773 |
% \l_@@_comment_bool, |
| 774 |
% \l_@@_language_tl, |
| 775 |
% \l_@@_code_style_tl, |
| 776 |
% \l_@@_code_fontsize_tl, |
| 777 |
% \l_@@_code_name_tl, |
| 778 |
% \l_@@_comment_contents_tl, |
| 779 |
% \l_@@_comment_format_tl, |
| 780 |
% \l_@@_label_name_tl, |
| 781 |
% \l_@@_baseline_stretch_fp, |
| 782 |
% \l_@@_linenumber_sep_fp |
| 783 |
% } |
| 784 |
% 定义变量。 |
| 785 |
% |
| 786 |
% \changes{v1.0.3}{2022/1/4}{增加\tn{\_@@_label_name_tl}变量} |
| 787 |
% |
| 788 |
% \begin{macrocode} |
| 789 |
\bool_new:N \l_@@_minted_bool |
| 790 |
\bool_new:N \l_@@_comment_bool |
| 791 |
|
| 792 |
\tl_new:N \l_@@_language_tl |
| 793 |
\tl_new:N \l_@@_code_style_tl |
| 794 |
\tl_new:N \l_@@_code_fontsize_tl |
| 795 |
\tl_new:N \l_@@_code_name_tl |
| 796 |
\tl_new:N \l_@@_comment_contents_tl |
| 797 |
\tl_new:N \l_@@_comment_format_tl |
| 798 |
\tl_new:N \l_@@_label_name_tl |
| 799 |
\fp_new:N \l_@@_baseline_stretch_fp |
| 800 |
\fp_new:N \l_@@_linenumber_sep_fp |
| 801 |
% \end{macrocode} |
| 802 |
% \end{variable} |
| 803 |
% |
| 804 |
% \changes{v1.0.4}{2022/1/28}{修正linenumsep为默认值1.80以避免3位行号溢出边界} |
| 805 |
% |
| 806 |
% \subsection{选项处理} |
| 807 |
% |
| 808 |
% 定义 |codebox| 键值类。 |
| 809 |
% \begin{macrocode} |
| 810 |
\keys_define:nn { codebox } |
| 811 |
{ |
| 812 |
% \end{macrocode} |
| 813 |
% |
| 814 |
% \begin{macro}{minted} |
| 815 |
% 是否使用minted宏包排版代码,默认为true。 |
| 816 |
% \begin{macrocode} |
| 817 |
minted .bool_set:N = \l_@@_minted_bool, |
| 818 |
minted .default:n = true, |
| 819 |
minted .initial:n = true, |
| 820 |
% \end{macrocode} |
| 821 |
% \end{macro} |
| 822 |
% |
| 823 |
% \begin{macro}{lang} |
| 824 |
% 设置排版代码语言,默认为c。 |
| 825 |
% \begin{macrocode} |
| 826 |
lang .tl_set:N = \l_@@_language_tl, |
| 827 |
lang .initial:n = c, |
| 828 |
% \end{macrocode} |
| 829 |
% \end{macro} |
| 830 |
% |
| 831 |
% \begin{macro}{pretitle} |
| 832 |
% 代码名称前缀 |
| 833 |
% \begin{macrocode} |
| 834 |
pretitle .tl_set:N = \l_@@_code_name_tl, |
| 835 |
pretitle .initial:n = Code, |
| 836 |
% \end{macrocode} |
| 837 |
% \end{macro} |
| 838 |
% |
| 839 |
% \begin{macro}{codestyle} |
| 840 |
% 代码样式 |
| 841 |
% \begin{macrocode} |
| 842 |
codestyle .tl_set:N = \l_@@_code_style_tl, |
| 843 |
codestyle .initial:n = default, |
| 844 |
% \end{macrocode} |
| 845 |
% \end{macro} |
| 846 |
% |
| 847 |
% \begin{macro}{codesize} |
| 848 |
% 代码字号 |
| 849 |
% \begin{macrocode} |
| 850 |
codesize .tl_set:N = \l_@@_code_fontsize_tl, |
| 851 |
codesize .initial:n = \small, |
| 852 |
% \end{macrocode} |
| 853 |
% \end{macro} |
| 854 |
% |
| 855 |
% \begin{macro}{comments} |
| 856 |
% 注释格式 |
| 857 |
% \begin{macrocode} |
| 858 |
comments .tl_set:N = \l_@@_comment_contents_tl, |
| 859 |
comments .initial:n = {}, |
| 860 |
% \end{macrocode} |
| 861 |
% \end{macro} |
| 862 |
% |
| 863 |
% \begin{macro}{commentf} |
| 864 |
% 注释格式 |
| 865 |
% \begin{macrocode} |
| 866 |
commentf .tl_set:N = \l_@@_comment_format_tl, |
| 867 |
commentf .initial:n = \small\sffamily, |
| 868 |
% \end{macrocode} |
| 869 |
% \end{macro} |
| 870 |
% |
| 871 |
% \begin{macro}{codestretch} |
| 872 |
% 基线伸展系数 |
| 873 |
% \begin{macrocode} |
| 874 |
codestretch .code:n = { \fp_set:Nn \l_@@_baseline_stretch_fp { #1 } |
| 875 |
}, |
| 876 |
codestretch .initial:n = 1.0, |
| 877 |
% \end{macrocode} |
| 878 |
% \end{macro} |
| 879 |
% |
| 880 |
% \begin{macro}{linenumsep} |
| 881 |
% 行号与文本之间的距离(单位:mm) |
| 882 |
% \begin{macrocode} |
| 883 |
linenumsep .fp_set:N = \l_@@_linenumber_sep_fp, |
| 884 |
linenumsep .initial:n = 1.80, |
| 885 |
% \end{macrocode} |
| 886 |
% \end{macro} |
| 887 |
% |
| 888 |
% \changes{v1.0.3}{2022/1/4}{增加引用标签label选项} |
| 889 |
% |
| 890 |
% \begin{macro}{label} |
| 891 |
% 注释格式 |
| 892 |
% \begin{macrocode} |
| 893 |
label .tl_set:N = \l_@@_label_name_tl, |
| 894 |
label .initial:n = {}, |
| 895 |
% \end{macrocode} |
| 896 |
% \end{macro} |
| 897 |
% |
| 898 |
% 处理未知选项。 |
| 899 |
% \begin{macrocode} |
| 900 |
unknown .code:n = { \@@_error:n { unknown-option } } |
| 901 |
} |
| 902 |
\msg_new:nnn { codebox } { unknown-option } |
| 903 |
{ package~ option~ "\l_keys_key_tl"~ is~ unknown. } |
| 904 |
% \end{macrocode} |
| 905 |
% |
| 906 |
% \subsection{选项设置用户接口} |
| 907 |
% |
| 908 |
% \begin{macro}{\codeset} |
| 909 |
% |
| 910 |
% 选项设置用户接口。 |
| 911 |
% |
| 912 |
% \begin{macrocode} |
| 913 |
\NewDocumentCommand \codeset { m } |
| 914 |
{ \keys_set:nn { codebox } {#1} } |
| 915 |
% \end{macrocode} |
| 916 |
% \end{macro} |
| 917 |
% |
| 918 |
% \subsection{内部函数} |
| 919 |
% |
| 920 |
% \changes{v1.0.2}{2022/1/2}{修改按章编号时cvcounter的编号方式} |
| 921 |
% |
| 922 |
% \begin{macro}{\@@_set_counter_parent:} |
| 923 |
% |
| 924 |
% 设置代码编号计数器的父计数器。 |
| 925 |
% |
| 926 |
% \begin{macrocode} |
| 927 |
\cs_new:Npn \@@_set_counter_parent: |
| 928 |
{ |
| 929 |
\ifdef{\thechapter} |
| 930 |
{ |
| 931 |
\newcounter{cvcounter}[chapter]% |
| 932 |
\renewcommand{\thecvcounter}{\thechapter.\arabic{cvcounter}} |
| 933 |
}{ |
| 934 |
\newcounter{cvcounter}%[section]% |
| 935 |
} |
| 936 |
} |
| 937 |
% \end{macrocode} |
| 938 |
% \end{macro} |
| 939 |
% |
| 940 |
% \changes{v1.0.1}{2021/12/26}{调整minted style选项为参数实现} |
| 941 |
% \changes{v1.0.2}{2021/12/28}{将minted/listings的参数设置独立为函数} |
| 942 |
% |
| 943 |
% \begin{macro}{\@@_minted_engine_tcbset:n #1} |
| 944 |
% 设置代码盒子minted宏包参数。 |
| 945 |
% |
| 946 |
% \begin{macrocode} |
| 947 |
\cs_new:Npn \@@_minted_engine_tcbset:n #1 |
| 948 |
{ |
| 949 |
\tcbset{ |
| 950 |
listing~engine=minted,% |
| 951 |
minted~style=#1, |
| 952 |
minted~options={% |
| 953 |
autogobble, |
| 954 |
breaklines,% |
| 955 |
fontsize=\tl_use:N \l_@@_code_fontsize_tl,% |
| 956 |
baselinestretch=\fp_eval:n { \l_@@_baseline_stretch_fp }, |
| 957 |
breaksymbolleft={},% |
| 958 |
linenos,% |
| 959 |
numbersep=\fp_eval:n { \l_@@_linenumber_sep_fp }~mm, |
| 960 |
},% |
| 961 |
minted~language=\tl_use:N \l_@@_language_tl% |
| 962 |
} |
| 963 |
} |
| 964 |
\cs_generate_variant:Nn \@@_minted_engine_tcbset:n {V} |
| 965 |
% \end{macrocode} |
| 966 |
% \end{macro} |
| 967 |
% |
| 968 |
% \begin{macro}{\@@_listings_engine_tcbset:} |
| 969 |
% 设置代码盒子listings宏包参数。 |
| 970 |
% |
| 971 |
% \begin{macrocode} |
| 972 |
\cs_new:Npn \@@_listings_engine_tcbset: |
| 973 |
{ |
| 974 |
\lstset{% general command to set parameter(s) |
| 975 |
basicstyle=\ttfamily\tl_use:N \l_@@_code_fontsize_tl, % print whole listing small |
| 976 |
keywordstyle=\color{chengse}\bfseries,% |
| 977 |
identifierstyle=, % nothing happens |
| 978 |
breaklines=true, |
| 979 |
commentstyle=\itshape\color{gray}, |
| 980 |
stringstyle=\ttfamily, % typewriter type for strings |
| 981 |
numbers=left,% |
| 982 |
numberstyle=\tl_use:N \l_@@_code_fontsize_tl\sffamily\color[rgb]{0.5,0.5,1.0},% |
| 983 |
}% |
| 984 |
\tcbset{ |
| 985 |
overlay={% |
| 986 |
\begin{tcbclipinterior} |
| 987 |
\fill[tcbcolback!80!black] (frame.south~west) rectangle |
| 988 |
([xshift=5mm]frame.north~west); |
| 989 |
\end{tcbclipinterior}% |
| 990 |
},% |
| 991 |
listing~options={ |
| 992 |
language=\tl_use:N \l_@@_language_tl, |
| 993 |
numbersep=\fp_eval:n { \l_@@_linenumber_sep_fp }~mm, |
| 994 |
%linebackgroundcolor={\ifodd\value{lstnumber}\color{cvgray}\fi} |
| 995 |
} |
| 996 |
}% |
| 997 |
} |
| 998 |
% \end{macrocode} |
| 999 |
% \end{macro} |
| 1000 |
% |
| 1001 |
% \begin{macro}{\@@_code_engine_tcbset:} |
| 1002 |
% 设置代码盒子引擎宏包参数。 |
| 1003 |
% |
| 1004 |
% \begin{macrocode} |
| 1005 |
\cs_new:Npn \@@_code_engine_tcbset: |
| 1006 |
{ |
| 1007 |
\bool_if:NTF \l_@@_minted_bool |
| 1008 |
{ |
| 1009 |
\@@_minted_engine_tcbset:V \l_@@_code_style_tl |
| 1010 |
}{ |
| 1011 |
\@@_listings_engine_tcbset: |
| 1012 |
} |
| 1013 |
} |
| 1014 |
% \end{macrocode} |
| 1015 |
% \end{macro} |
| 1016 |
% |
| 1017 |
% \begin{macro}{\@@_comment_tcbset:} |
| 1018 |
% 设置代码盒子底线注释。 |
| 1019 |
% |
| 1020 |
% \begin{macrocode} |
| 1021 |
\cs_new:Npn \@@_comment_tcbset: |
| 1022 |
{ |
| 1023 |
\bool_if:NTF { \l_@@_comment_bool } |
| 1024 |
{ |
| 1025 |
\tcbset{% |
| 1026 |
listing~and~comment,% |
| 1027 |
colbacklower=tcbcolback!5!yellow!10!white,% |
| 1028 |
collower=tcbcolback!60!black,% |
| 1029 |
comment={\tl_use:N \l_@@_comment_format_tl~ |
| 1030 |
\tl_use:N \l_@@_comment_contents_tl},% |
| 1031 |
} |
| 1032 |
}{ |
| 1033 |
\tcbset{ listing~only,} |
| 1034 |
} |
| 1035 |
} |
| 1036 |
% \end{macrocode} |
| 1037 |
% \end{macro} |
| 1038 |
% |
| 1039 |
% \changes{v1.0.1}{2021/12/27}{修订代码盒子前多一个逗号的问题} |
| 1040 |
% \changes{v1.0.4}{2022/1/28}{修改用户接口的{group_begin}到开始位置} |
| 1041 |
% |
| 1042 |
% \subsection{不计数代码盒子用户接口} |
| 1043 |
% |
| 1044 |
% 定义不带底线注释的代码盒子环境\env{codebox} |
| 1045 |
% |
| 1046 |
% \begin{macrocode} |
| 1047 |
\NewDocumentEnvironment{ codebox }{O{} m } |
| 1048 |
{ |
| 1049 |
\group_begin: |
| 1050 |
\bool_set_false:N \l_@@_comment_bool |
| 1051 |
\keys_set:nn { codebox } { #1 } |
| 1052 |
\@@_code_engine_tcbset: |
| 1053 |
\@@_comment_tcbset: |
| 1054 |
\tcbset{lang, title={#2} }% |
| 1055 |
\tcblisting{} |
| 1056 |
}{ |
| 1057 |
\endtcblisting |
| 1058 |
\group_end: |
| 1059 |
} |
| 1060 |
% \end{macrocode} |
| 1061 |
% |
| 1062 |
% 定义带底线注释的代码盒子环境\env{codebox*} |
| 1063 |
% |
| 1064 |
% \begin{macrocode} |
| 1065 |
\NewDocumentEnvironment{ codebox* }{O{} m } |
| 1066 |
{ |
| 1067 |
\group_begin: |
| 1068 |
\bool_set_false:N \l_@@_comment_bool |
| 1069 |
\keys_set:nn { codebox } { #1 } |
| 1070 |
\@@_code_engine_tcbset: |
| 1071 |
\@@_comment_tcbset: |
| 1072 |
\tcbset{lang, title={#2} }% |
| 1073 |
\tcblisting{} |
| 1074 |
}{ |
| 1075 |
\endtcblisting |
| 1076 |
\group_end: |
| 1077 |
} |
| 1078 |
% \end{macrocode} |
| 1079 |
% |
| 1080 |
% 定义带/不带底线注释的从文件读取内容的命令\tn{codefile}/\tn{codefile*} |
| 1081 |
% |
| 1082 |
% \begin{macrocode} |
| 1083 |
\NewDocumentCommand \codefile { s O{} m m } |
| 1084 |
{ |
| 1085 |
\group_begin: |
| 1086 |
\IfBooleanTF{#1} |
| 1087 |
{ |
| 1088 |
\bool_set_true:N \l_@@_comment_bool |
| 1089 |
}{ |
| 1090 |
\bool_set_false:N \l_@@_comment_bool |
| 1091 |
} |
| 1092 |
\keys_set:nn { codebox } { #2 } |
| 1093 |
\@@_code_engine_tcbset: |
| 1094 |
\@@_comment_tcbset: |
| 1095 |
\tcbset{ |
| 1096 |
lang, |
| 1097 |
title={#3}, |
| 1098 |
listing~file={#4}, |
| 1099 |
}% |
| 1100 |
\tcbinputlisting{ } |
| 1101 |
\group_end: |
| 1102 |
} |
| 1103 |
% \end{macrocode} |
| 1104 |
% |
| 1105 |
% \subsection{计数代码盒子用户接口} |
| 1106 |
% |
| 1107 |
% 设置代码盒子计算器 |
| 1108 |
% |
| 1109 |
% \begin{macrocode} |
| 1110 |
\@@_set_counter_parent: |
| 1111 |
% \end{macrocode} |
| 1112 |
% |
| 1113 |
% \changes{v1.0.2}{2021/12/28}{为计数器两端添加\tn{nobreakspace}} |
| 1114 |
% \changes{v1.0.3}{2022/1/4}{为带编号代码盒子添加引用标签选项} |
| 1115 |
% |
| 1116 |
% 定义不带底线注释的代码盒子环境\env{codeview} |
| 1117 |
% |
| 1118 |
% \begin{macrocode} |
| 1119 |
\DeclareTCBListing[use~counter=cvcounter]{codeviewaux}{m} |
| 1120 |
{ |
| 1121 |
title={\tl_use:N \l_@@_code_name_tl\nobreakspace\thecvcounter\nobreakspace~#1}, |
| 1122 |
} |
| 1123 |
\NewDocumentEnvironment{ codeview }{O{} m } |
| 1124 |
{ |
| 1125 |
\group_begin: |
| 1126 |
\bool_set_false:N \l_@@_comment_bool |
| 1127 |
\keys_set:nn { codebox } { #1 } |
| 1128 |
\@@_code_engine_tcbset: |
| 1129 |
\@@_comment_tcbset: |
| 1130 |
\tl_if_empty:NF \l_@@_label_name_tl |
| 1131 |
{ |
| 1132 |
\tcbset{ |
| 1133 |
label=\tl_use:N \l_@@_label_name_tl, |
| 1134 |
} |
| 1135 |
} |
| 1136 |
\tcbset{ |
| 1137 |
cv, |
| 1138 |
overlay~unbroken~and~first ={ |
| 1139 |
\begin{tcbclipinterior} |
| 1140 |
\node[inner~sep=0pt,anchor=north~east,yshift=-3pt,xshift=-5pt,text=cvgrayb] |
| 1141 |
at (frame.north~east){ |
| 1142 |
\ttfamily\faFile*\ \faCode\ \faCodeBranch\ \faCopy\ \faExternalLink*\ |
| 1143 |
\MakeUppercase{\tl_use:N \l_@@_language_tl} |
| 1144 |
}; |
| 1145 |
\end{tcbclipinterior} |
| 1146 |
} |
| 1147 |
}% |
| 1148 |
\codeviewaux{#2} |
| 1149 |
}{ |
| 1150 |
\endcodeviewaux |
| 1151 |
\group_end: |
| 1152 |
} |
| 1153 |
% \end{macrocode} |
| 1154 |
% |
| 1155 |
% |
| 1156 |
% 定义带底线注释的代码盒子环境\env{codeview*} |
| 1157 |
% |
| 1158 |
% \begin{macrocode} |
| 1159 |
\NewDocumentEnvironment{ codeview* }{O{} m } |
| 1160 |
{ |
| 1161 |
\group_begin: |
| 1162 |
\bool_set_true:N \l_@@_comment_bool |
| 1163 |
\keys_set:nn { codebox } { #1 } |
| 1164 |
\@@_code_engine_tcbset: |
| 1165 |
\@@_comment_tcbset: |
| 1166 |
\tl_if_empty:NF \l_@@_label_name_tl |
| 1167 |
{ |
| 1168 |
\tcbset{ |
| 1169 |
label=\tl_use:N \l_@@_label_name_tl, |
| 1170 |
} |
| 1171 |
} |
| 1172 |
\tcbset{ |
| 1173 |
cv, |
| 1174 |
overlay~unbroken~and~first ={ |
| 1175 |
\begin{tcbclipinterior} |
| 1176 |
\node[inner~sep=0pt,anchor=north~east,yshift=-3pt,xshift=-5pt,text=cvgrayb] |
| 1177 |
at (frame.north~east){ |
| 1178 |
\ttfamily\faFile*\ \faCode\ \faCodeBranch\ \faCopy\ \faExternalLink*\ |
| 1179 |
\MakeUppercase{\tl_use:N \l_@@_language_tl} |
| 1180 |
}; |
| 1181 |
\end{tcbclipinterior} |
| 1182 |
} |
| 1183 |
}% |
| 1184 |
\codeviewaux{#2} |
| 1185 |
}{ |
| 1186 |
\endcodeviewaux |
| 1187 |
\group_end: |
| 1188 |
} |
| 1189 |
% \end{macrocode} |
| 1190 |
% |
| 1191 |
% 定义带/不带底线注释的从文件读取内容的命令\tn{cvfile}/\tn{cvfile*} |
| 1192 |
% |
| 1193 |
% \begin{macrocode} |
| 1194 |
\DeclareTCBInputListing[use~counter=cvcounter]{\langfileaux}{m} |
| 1195 |
{ |
| 1196 |
title={\tl_use:N \l_@@_code_name_tl\nobreakspace\thecvcounter\nobreakspace~#1}, |
| 1197 |
} |
| 1198 |
\NewDocumentCommand \cvfile { s O{} m m } |
| 1199 |
{ |
| 1200 |
\group_begin: |
| 1201 |
\IfBooleanTF{#1} |
| 1202 |
{ |
| 1203 |
\bool_set_true:N \l_@@_comment_bool |
| 1204 |
}{ |
| 1205 |
\bool_set_false:N \l_@@_comment_bool |
| 1206 |
} |
| 1207 |
\keys_set:nn { codebox } { #2 } |
| 1208 |
\@@_code_engine_tcbset: |
| 1209 |
\@@_comment_tcbset: |
| 1210 |
\tl_if_empty:NF \l_@@_label_name_tl |
| 1211 |
{ |
| 1212 |
\tcbset{ |
| 1213 |
label=\tl_use:N \l_@@_label_name_tl, |
| 1214 |
} |
| 1215 |
} |
| 1216 |
\tcbset{ |
| 1217 |
cv, |
| 1218 |
listing~file={#4}, |
| 1219 |
overlay~unbroken~and~first ={ |
| 1220 |
\begin{tcbclipinterior} |
| 1221 |
\node[inner~sep=0pt,anchor=north~east,yshift=-3pt,xshift=-5pt,text=cvgrayb] |
| 1222 |
at (frame.north~east){ |
| 1223 |
\ttfamily\faFile*\ \faCode\ \faCodeBranch\ \faCopy\ \faExternalLink*\ |
| 1224 |
\MakeUppercase{\tl_use:N \l_@@_language_tl} |
| 1225 |
}; |
| 1226 |
\end{tcbclipinterior} |
| 1227 |
} |
| 1228 |
}% |
| 1229 |
\langfileaux{#3} |
| 1230 |
\group_end: |
| 1231 |
} |
| 1232 |
% \end{macrocode} |
| 1233 |
% |
| 1234 |
% \begin{macrocode} |
| 1235 |
%</package> |
| 1236 |
% \end{macrocode} |
| 1237 |
% |
| 1238 |
% \end{implementation} |
| 1239 |
% |
| 1240 |
% \Finale |
| 1241 |
% |
| 1242 |
\endinput |