Debian Codegraph @

texmf-dist/source/latex/hustvisual/hustvisual.dtx

raw
1 % \iffalse meta-comment
2 % !TEX program = XeLaTeX
3 %
4 % DO NOT REMOVE THE MARK MANUALLY (used in l3build) -> %
5 %
6 %<package|doc-sty>\NeedsTeXFormat{LaTeX2e}
7 %<package>\ProvidesExplPackage{hustvisual}
8 %<doc-sty>\ProvidesExplPackage{hustvisual-doc}
9 %<package|doc-sty> {2025-05-07}{1.0.0} %
10 %<package> {Visual Identity of Huazhong University of Science and Technology}
11 %<doc-sty> {Docmentation Style for hustvisual}
12 %<*driver>
13 \documentclass{ctexart}
14 \usepackage{useclass}
15 \useclass*[full]{l3doc}
16 \usepackage{hustvisual}
17 \usepackage{hustvisual-doc}
18 \usepackage{mdframed}
19 \usepackage{marginnote}
20 \usepackage{siunitx}
21
22 \providecommand{\name}{\jobname}
23 \providecommand{\pkgname}{\pkg{\name}}
24 \begin{document}
25 \DisableImplementation
26
27 \DocInput{\jobname.dtx}
28 \DocInput{\jobname-vi.dtx}
29
30 \EnableImplementation
31 \DisableDocumentation
32 \DocInputAgain
33 \PrintChanges
34 \PrintIndex
35 \end{document}
36 %</driver>
37 % \fi
38 %
39 % \begin{documentation}
40 % \title{\pkgname.sty: 华中科技大学视觉标识汇编}
41 % \author
42 % {
43 % 黄宇希 Huang Yuxi^^A
44 % \thanks{
45 % \textit{Huang} is his surname.
46 % }
47 % <^^A
48 % \href
49 % {mailto:[email protected]}
50 % {[email protected]}^^A
51 % >
52 % }
53 % \date{2025-05-07 \quad Version 1.0.0}
54 %
55 % \maketitle
56 %
57 % \tableofcontents
58 %
59 % \changes{v1.0}{2025-05-06}{Initial release.}
60 %
61 % \section{宏包介绍}
62 %
63 % 本宏包提供了华中科技大学视觉标识(visual identity)定义的接口,
64 % 预设了部分常用的视觉标识,
65 % 使得用户可以便捷地在文档中使用。
66 %
67 % \subsection{\pkgname{} 发行版本号\label{sec:version}}
68 %
69 % 更新版本往往会带来新功能和修复问题,
70 % 但有时也会不可避免地带来不向后兼容的修改。
71 % 为了清晰地传达版本之间的变化,
72 % 本宏包发行的版本号使用类似但不完全同于语义化版本控制(Semantic Versioning)规范
73 % \footnote{\url{https://semver.org/}}用以标识。
74 % 在本宏包中,对于版本号 |MAJOR.MINOR.PATCH|,递增相应的部分所表示的含义如下:
75 % \begin{itemize}
76 % \item |MAJOR|:递增大版本号,
77 % 表示已在正文文档化的公开接口上存在不向后兼容(backward compatibility)的修改,
78 % 一般对文档代码不修改无法正常编译;
79 % \item |MINOR|:递增小版本号,
80 % 表示已在正文文档化的非实验性公开接口上\emph{不}存在不向后兼容编译的修改,
81 % 但在实验性公开接口上存在不向后兼容的修改。
82 % 一般对文档代码不作修改或者只需小幅修改就可以正常编译;
83 % \item |PATCH|:递增补丁版本号,
84 % 表示新版本含有向后兼容的 bug 修复,新功能,或新的视觉标识,
85 % 其中未文档化的私有接口可能会发生变化。
86 % \end{itemize}
87 % 以上内容所指的“公开接口”仅包括第 \ref{sec:usage} 节中介绍的供终端用户直接使用的接口。
88 % 用户在更新宏包时,可以根据版本号的变化以及更新日志来判断是否需要修改自己的文档。
89 %
90 % \section{开发说明\label{sec:dev}}
91 %
92 % 本节介绍了宏包的开发和维护相关信息,
93 % 包括如何添加新的色彩和图案。
94 % 本节内容的指令仅可在本宏包或者子模块中使用,
95 % 在正文文档中使用会导致编译错误。
96 %
97 % \subsection{添加新的色彩}
98 %
99 % \begin{function}{\@@_set_color:nnn}
100 % \begin{syntax}
101 % \cs{@@_set_color:nnn} \marg{色彩名称} \marg{色彩模型} \marg{色彩值}
102 % \end{syntax}
103 % \cs{@@_set_color:nnn} 是一个用于同时定义 \pkg{l3color} 和 \pkg{xcolor} 中的色彩的函数。例如:
104 % \begin{verbatim}
105 % \@@_set_color:nnn { hustblue } { CMYK } { 100, 74, 27, 0 }
106 % \end{verbatim}
107 % 它包括三个必选参数:色彩名称、色彩模型和色彩值:
108 % \begin{arguments}
109 % \item[\marg{色彩名称}] 色彩名称,必须是一个合法的 \pkg{xcolor} 色彩名称。
110 % \item[\marg{色彩模型}] 色彩模型,支持的色彩模型包括 \opt{CMYK}、\opt{cmyk}、\opt{RGB}、\opt{rgb} 等。其中 \opt{CMYK} 是本宏包新增的色彩模型,支持 0--100 范围的 \opt{cmyk} 色彩。
111 % \item[\marg{色彩值}] 色彩值,支持由逗号分隔的色彩值,格式包括 \opt{CMYK}、\opt{cmyk}、\opt{RGB}、\opt{rgb} 等。
112 % \end{arguments}
113 % \end{function}
114 %
115 % \subsection{添加新的图案}
116 %
117 % 推荐使用 Inkscape 打开图案矢量图形文件,
118 % 并使用 svg2tikz (\url{https://github.com/xyz2tex/svg2tikz})插件将其转换为 TikZ 代码。
119 % 在导出时,选择 \TeX template 为 Tikzpicture,启用裁切 Crop,关闭自动换行 Wrap paths 和缩进选项 Indent group ,数字精度 Number of decimal 设置为 3;使用 cm 为单位,关闭 Inkscape origin 选项,缩放比例 Scale 设置为 1.0。
120 %
121 % 导出后请使用 |scripts/tikz-format.pl| 脚本进行格式化,
122 % 脚本会对 \TikZ 代码进行格式化,包括缩进、换行、删除多余的空格等操作。
123 %
124 % 之后请手动将颜色按照一定顺序替换为如 \cs{l_@@_color_arg_i_tl} 形式的变量,
125 % 以便于后续的色彩参数传递。
126 % 在完全替换后,
127 % 删除开头的 |\definecolor| 语句,
128 % 将其 \TikZ 代码放入 guard (|%<*xxx>| 至 |%</xxx>|)中,
129 % 并更新相应文档,实现和 |hustvisual.ins| 文件。
130 %
131 % \begin{function}{\@@_set_vi:n}
132 % \begin{syntax}
133 % \cs{@@_set_vi:n} \marg{图案参数}
134 % \end{syntax}
135 % \cs{@@_set_vi:n} 是一个用于设置图案的函数。
136 % \marg{图案参数} 是一个由逗号分隔的键值对无序列表,
137 % 其中每个键值对的格式为 \opt{key=value}。
138 % 有些键值对是可选的,如果没有设置,则使用默认值;而有些是必选的,不设置则会导致编译错误。
139 % 其中键值对的定义如下:
140 % \begin{arguments}
141 % \item[\opt{dept}] 视觉标识的所属学院,默认值为 \opt{vi},即华中科技大学校级的视觉标识。学院的缩写使用官方网站域名四级子域名(域名 |.hust.edu.cn| 左边的部分)作为缩写。
142 % \item[\opt{vi}] 视觉标识的标识符,必选参数,是一个由逗号分隔的无序列表,宏包内部会自动将其排序后存储为唯一的视觉标识名称,与和 \opt{dept} 一起作为查找图案的默认文件名。
143 % \item[\opt{ncolors}] 视觉标识的色彩数量,默认值为 \opt{0},即图案中没有可配置的色彩。
144 % \item[\opt{temps}] 视觉标识的色彩预设模板,如果 \opt{ncolors} 的值大于 \opt{0},则该参数为必选参数。色彩预设模板的格式为有序列表 \opt{\{temp1=\{color1, color2, ...\}, temp2=\{color3, color1, ...\}, ...\}}。其中 \opt{temp1}、\opt{temp2} 等为色彩预设模板的名称,\opt{color1}、\opt{color2} 等为色彩名称,色彩名称需要由 \pkg{xcolor} 宏包定义的色彩名称,且列表中的色彩数量需要等同于 \opt{ncolors} 的值。其中第一个色彩预设模板会被用作默认的色彩预设模板。
145 % \item[\opt{filename}] 视觉标识的文件名,默认缺省,使用由 \opt{dept} 和 \opt{vi} 生成的文件名。如果 \opt{filename} 的值不为空,则该图案会被使用由 \opt{filename} 设置的文件名。
146 % \item[\opt{aliases}] 视觉标识的别名,默认为空,即没有别名。别名的格式为有序列表 \opt{\{\{vi1,vi2\},\{vi2,vi3,vi4\},...\}},其中 \opt{vi1,vi2}、\opt{vi2,vi3,vi4} 等为别名,使用方式同 \opt{vi},用于方便用户调用,不需要每次都输入完整的视觉标识名称。
147 % \end{arguments}
148 % \end{function}
149 %
150 % \section{使用说明\label{sec:usage}}
151 %
152 % \begin{function}{\hustvi}
153 % \begin{syntax}
154 % \cs{hustvi}\oarg{通用选项}\marg{视觉标识}
155 % \end{syntax}
156 % \cs{hustvi} 是本宏包提供给终端用户使用最重要的一个接口,
157 % 一切的视觉标识都是通过这个通用接口来使用。
158 % 例如:
159 % \marginnote{\hustvi[height=1cm,temp=red]{emblem}}
160 % \begin{verbatim}
161 % \hustvi[height=1cm,temp=red]{emblem}
162 % \end{verbatim}
163 % 可以在文档中使用如左页边所示,以通用选项:高 \qty{1}{cm}、色彩预设为\opt{blue}的华中科技大学校徽。
164 % 其中,\marg{视觉标识}是一个由逗号分隔的无序列表,
165 % 列表中的每一项都是一个视觉标识中的基础元素,
166 % 这些元素的组合可以形成一个完整的视觉标识。
167 % 如果视觉标识中只有一个基础元素,
168 % 则可以省略逗号分隔符。
169 % 而\oarg{通用选项}是由一系列逗号分隔的键值对无序列表组成的可选参数,
170 % 所有的视觉标识都实现了如下的通用选项:
171 % \begin{arguments}
172 % \item[\opt{filename}] 视觉标识的文件名,默认缺省,通常情况下不需要设置,仅在需要覆盖原有文件时使用。
173 % \item[\opt{dept}] 视觉标识的所属学院,默认值为 \opt{vi},即华中科技大学校级的视觉标识。学院的缩写使用官方网站域名四级子域名(域名 |.hust.edu.cn| 左边的部分)作为缩写。
174 % \item[\opt{width}] 视觉标识的宽度,默认值为 \opt{0pt},即使用默认的宽度。如果仅设置了宽度而没有设置高度,则高度会自动按比例缩放;如果同时设置了宽度和高度,则宽高比会被强制为 \opt{width}:\opt{height}。
175 % \item[\opt{height}] 视觉标识的高度,默认值为 \opt{0pt},效果同上。
176 % \item[\opt{temp}] 视觉标识的色彩预设模板,不同视觉标识的色彩预设模板不同,具体的色彩预设模板请参考对应视觉标识的文档。
177 % \item[\opt{colors}] 手动按照顺序覆写色彩预设模板,同时设置了 \opt{temp} 和 \opt{colors} 时,\opt{colors} 会覆盖 \opt{temp} 的设置。 \opt{colors} 的格式为有序列表 \opt{\{color1, color2, ...\}},其中 \opt{color1}、\opt{color2} 等为色彩名称,色彩名称需要由 \pkg{xcolor} 宏包定义的色彩名称,且列表中的色彩数量不能超过预设模板中的色彩数量。\marginnote{\hustvi[colors={hustblue,black},temp=red,height=1cm]{emblem}} 例如:\cs{hustvi}\opt{\[colors=\{hustblue,black\},temp=red\]\{emblem\}} (如左页边所示)就是基于 \opt{red} 模板的校徽,对前两种颜色依序覆写了华科蓝 \opt{hustblue} 和黑色 \opt{black} 两种色彩\footnote{本错误配色示例仅用于说明,实际使用时请遵循视觉标识的色彩规范。}。
178 % \item[\opt{opacity}] (实验性功能)视觉标识的透明度,默认值为 \opt{1},即不透明。透明度的范围为 \opt{0} 到 \opt{1},其中 \opt{0} 表示完全透明,\opt{1} 表示完全不透明。
179 % \end{arguments}
180 % \end{function}
181 %
182 % \end{documentation}
183 %
184 % \begin{implementation}
185 %
186 %
187 % \section{\pkgname{} 实现细节}
188 % \begin{macrocode}
189 %<@@=hustvisual>
190 %<*package>
191 % \end{macrocode}
192 %
193 % \subsection{常量声明}
194 %
195 % \begin{macro}{\c_@@_univ_tl}
196 % 定义校级视觉标识的“学院” \opt{dept} 名称。
197 % \begin{macrocode}
198 \tl_const:Nn \c_@@_univ_tl { vi }
199 % \end{macrocode}
200 % \end{macro}
201 %
202 % \begin{macro}{\c_@@_depts_clist}
203 % 定义了各个学院的缩写,使用官方网站域名四级子域名(域名 |.hust.edu.cn| 左边的部分)作为缩写。
204 % 如遇类似同济医学院下设药学院(|pharm.tjmu.edu.cn|)或第一临床学院(|whuh.com|)的以非华科域名结尾的学院,另行商议。
205 % \begin{macrocode}
206 \clist_const:Ne \c_@@_depts_clist
207 {
208 \c_@@_univ_tl,
209 }
210 % \end{macrocode}
211 % \end{macro}
212 %
213 % \begin{macro}{\c_@@_nargs_int, \c_@@_args_clist}
214 % 参数索引。如有需要在这里修改参数索引数量。
215 % \begin{macrocode}
216 \int_const:Nn \c_@@_nargs_int { 5 }
217 \clist_new:N \c_@@_args_clist
218 \int_step_inline:nn { \c_@@_nargs_int }
219 {
220 \exp_args:NNe \clist_put_right:Nn \c_@@_args_clist
221 {
222 \int_to_roman:n { #1 }
223 }
224 }
225 % \end{macrocode}
226 % \end{macro}
227 %
228 % \subsection{变量声明}
229 % \begin{macro}{
230 % \l_@@_color_arg_i_tl,
231 % \l_@@_color_arg_ii_tl,
232 % \l_@@_color_arg_iii_tl,
233 % \l_@@_color_arg_iv_tl,
234 % \l_@@_color_arg_v_tl,
235 % }
236 % 传入 \TikZ 中的色彩参数,默认为黑色。
237 % \begin{macrocode}
238 \clist_map_inline:Nn \c_@@_args_clist
239 {
240 \tl_new:c { l_@@_color_arg_ #1 _tl }
241 \tl_set:cn { l_@@_color_arg_ #1 _tl } { black }
242 }
243 % \end{macrocode}
244 % \end{macro}
245 %
246 % \begin{macro}{\l_@@_color_args_clist}
247 % 色彩参数列表。
248 % \begin{macrocode}
249 \clist_new:N \l_@@_color_args_clist
250 % \end{macrocode}
251 % \end{macro}
252 %
253 % \begin{macro}{
254 % \l_@@_dept_tl,
255 % \l_@@_vi_clist,
256 % \l_@@_ncolors_int,
257 % \l_@@_temps_prop,
258 % \l_@@_temp_tl,
259 % \l_@@_filename_tl,
260 % \l_@@_aliases_clist,
261 % \l_@@_colors_clist,
262 % \l_@@_vi_tl,
263 % \l_@@_width_dim,
264 % \l_@@_height_dim,
265 % \l_@@_opacity_fp,
266 % }
267 % 视觉标识临时变量。
268 % \begin{macrocode}
269 \tl_new:N \l_@@_dept_tl
270 \clist_new:N \l_@@_vi_clist
271 \int_new:N \l_@@_ncolors_int
272 \prop_new:N \l_@@_temps_prop
273 \tl_new:N \l_@@_temp_tl
274 \tl_new:N \l_@@_filename_tl
275 \clist_new:N \l_@@_aliases_clist
276 \clist_new:N \l_@@_colors_clist
277 \tl_new:N \l_@@_vi_tl
278 \dim_new:N \l_@@_width_dim
279 \dim_new:N \l_@@_height_dim
280 \fp_new:N \l_@@_opacity_fp
281 % \end{macrocode}
282 % \end{macro}
283 %
284 % \begin{macro}{\g_@@_vi_prop}
285 % 视觉标识属性列表。
286 % \begin{macrocode}
287 \prop_new:N \g_@@_vi_prop
288 % \end{macrocode}
289 % \end{macro}
290 %
291 %
292 % \subsection{辅助函数}
293 %
294 % \begin{macro}{
295 % \@@_msg_new:nn,
296 % \@@_warning:n,
297 % \@@_warning:ne,
298 % \@@_warning:nee,
299 % \@@_warning:neee,
300 % \@@_error:n,
301 % \@@_error:ne,
302 % \@@_error:nee,
303 % \@@_error:neee,
304 %}
305 % 各种信息函数的缩略形式。
306 % \begin{macrocode}
307 \cs_new:Npn \@@_msg_new:nn { \msg_new:nnn { hustvisual } }
308 \cs_new:Npn \@@_warning:n { \msg_warning:nn { hustvisual } }
309 \cs_new:Npn \@@_warning:ne { \msg_warning:nne { hustvisual } }
310 \cs_new:Npn \@@_warning:nee { \msg_warning:nnee { hustvisual } }
311 \cs_new:Npn \@@_warning:neee { \msg_warning:nneee { hustvisual } }
312 \cs_new:Npn \@@_error:n { \msg_error:nn { hustvisual } }
313 \cs_new:Npn \@@_error:ne { \msg_error:nne { hustvisual } }
314 \cs_new:Npn \@@_error:nee { \msg_error:nnee { hustvisual } }
315 \cs_new:Npn \@@_error:neee { \msg_error:nneee { hustvisual } }
316 % \end{macrocode}
317 % \end{macro}
318 %
319 % \subsection{宏包载入}
320 %
321 % \begin{macrocode}
322 \RequirePackage{tikz}
323 \RequirePackage{xcolor}
324 % \end{macrocode}
325 %
326 % \subsection{内部函数}
327 %
328 % \begin{macro}{\@@_deploy_colors:}
329 % 将 \cs{l_@@_color_args_clist} 展开到对应的变量方便在视觉标识文件(|hustvisual-*.def|)中调用。
330 % \begin{macrocode}
331 \@@_msg_new:nn { color-args-exceed }
332 {
333 The~ `colors'~ arguments(#1)~ exceed~ the~ number~ of~ defined~ colors(#2).
334 Please~ check~ the~ number~ of~ colors~ in~ the~ documentation~ of~ the~ package.
335 }
336 \int_new:N \l_@@_color_nargs_int
337 \cs_new:Npn \@@_deploy_colors:
338 {
339 \int_set:Nn \l_@@_color_nargs_int
340 { \clist_count:N \l_@@_color_args_clist }
341 \int_compare:nNnTF
342 { \l_@@_color_nargs_int } > { \c_@@_nargs_int }
343 {
344 \@@_warning:nee { color-args-exceed }
345 { \int_use:N \l_@@_color_nargs_int }
346 { \int_use:N \c_@@_nargs_int }
347 \@@_deploy_colors:N \c_@@_nargs_int
348 }
349 {
350 \@@_deploy_colors:N \l_@@_color_nargs_int
351 }
352 }
353 \tl_new:N \l_@@_color_arg_tl
354 \cs_new:Npn \@@_deploy_colors:N #1
355 {
356 \int_step_inline:nn { #1 }
357 {
358 \tl_set:Nx \l_@@_color_arg_tl
359 {
360 l_@@_color_arg_
361 \clist_item:Nn \c_@@_args_clist { ##1 }
362 _tl
363 }
364 \tl_set:cx
365 {
366 \l_@@_color_arg_tl
367 }
368 {
369 \clist_item:Nn \l_@@_color_args_clist { ##1 }
370 }
371 }
372 }
373 % \end{macrocode}
374 % \end{macro}
375 %
376 % \begin{macro}{\@@_sort_vi_name:, \@@_sort_vi_name:N}
377 % 对 \cs{l_@@_vi_clist} 进行排序。
378 % \begin{macrocode}
379 \cs_new:Npn \@@_sort_vi_name:
380 {
381 \@@_sort_vi_name:N \l_@@_vi_clist
382 }
383 \cs_new:Npn \@@_sort_vi_name:N #1
384 {
385 \clist_sort:Nn #1
386 {
387 \str_compare:nNnTF { ##1 } > { ##2 }
388 { \sort_return_swapped: }
389 { \sort_return_same: }
390 }
391 }
392 % \end{macrocode}
393 % \end{macro}
394 %
395 % \begin{macro}{\@@_vi_name:, \@@_vi_name:N, \@@_vi_name:NN}
396 % 从 \cs{l_@@_dept_tl},和 \cs{l_@@_vi_clist} 中生成唯一的视觉标识名称。
397 % \begin{macrocode}
398 \tl_const:Nn \c_@@_dept_sep_tl { - }
399 \tl_const:Nn \c_@@_vi_sep_tl { - }
400 \cs_new:Npn \@@_vi_name:
401 {
402 \@@_vi_name:N \l_@@_vi_clist
403 }
404 \cs_new:Npn \@@_vi_name:N #1
405 {
406 \@@_vi_name:NN \l_@@_dept_tl #1
407 }
408 \cs_new:Npn \@@_vi_name:NN #1#2
409 {
410 \tl_use:N #1
411 \tl_use:N \c_@@_dept_sep_tl
412 \exp_args:NNV \clist_use:Nn #2 \c_@@_vi_sep_tl
413 }
414 % \end{macrocode}
415 % \end{macro}
416 %
417 % \begin{macro}{\@@_vi_filename:}
418 % 生成视觉标识文件名。
419 % \begin{macrocode}
420 \tl_const:Nn \c_@@_vi_filename_prefix_tl { hustvisual- }
421 \tl_const:Nn \c_@@_vi_filename_suffix_tl { .def }
422 \cs_new:Npn \@@_vi_filename:
423 {
424 \tl_use:N \c_@@_vi_filename_prefix_tl
425 \@@_vi_name:
426 \tl_use:N \c_@@_vi_filename_suffix_tl
427 }
428 % \end{macrocode}
429 % \end{macro}
430 %
431 % \begin{macro}{\@@_prop_default_value:N}
432 % 定义属性的默认值为第一个插入的值。
433 % \begin{macrocode}
434 %\bool_new:N \l_@@_prop_set_bool
435 \tl_new:N \l_@@_prop_set_tl
436 \cs_new:Npn \@@_prop_default_value:N #1
437 {
438 \bool_set_false:N \l_@@_prop_set_bool
439 % \end{macrocode}
440 % \cs{prop_map_break:} 因未知原因无法使用。
441 % \begin{macrocode}
442 \prop_map_inline:Nn #1
443 {
444 \bool_if:NF \l_@@_prop_set_bool
445 {
446 \bool_set_true:N \l_@@_prop_set_bool
447 \tl_set:Nn \l_@@_prop_set_tl { ##2 }
448 }
449 }
450 \tl_use:N \l_@@_prop_set_tl
451 }
452 % \end{macrocode}
453 % \end{macro}
454 %
455 % \begin{macrocode}
456 \keys_define:nn { hustvisual }
457 {
458 dev .meta:nn = { hustvisual / dev } { #1 },
459 user .meta:nn = { hustvisual / user } { #1 },
460 }
461 % \end{macrocode}
462 %
463 % \subsection{子模块接口}
464 %
465 % \subsubsection{色彩定义}
466 %
467 % \begin{macro}{\@@_set_color:nnn}
468 % 定义色彩的函数。同时定义了 \pkg{l3color} 和 \pkg{xcolor} 中的色彩。
469 % 此外,新增了 \opt{CMYK} 色彩模型的支持,用于添加 0--100 范围的 \opt{cmyk} 色彩。
470 % \begin{arguments}
471 % \item 色彩名称
472 % \item 色彩模型,如 \opt{CMYK}(0--100)、\opt{cmyk}(0--1)、\opt{RGB}(0--255)、\opt{rgb}(0--1) 等
473 % \item 色彩值,用逗号分隔的数值
474 % \end{arguments}
475 % \begin{macrocode}
476 \seq_new:N \l_@@_color_models_seq
477 \seq_new:N \l_@@_color_values_seq
478 \int_new:N \l_@@_set_colors_int
479 \tl_new:N \l_@@_color_model_tl
480 \tl_new:N \l_@@_color_models_tl
481 \tl_new:N \l_@@_color_values_tl
482 \clist_new:N \l_@@_set_colors_clist
483 \cs_new:Npn \@@_set_color:nnn #1#2#3
484 {
485 \seq_set_split:Nnn \l_@@_color_models_seq { / } { #2 }
486 \seq_set_split:Nnn \l_@@_color_values_seq { / } { #3 }
487 \int_compare:nNnF
488 { \seq_count:N \l_@@_color_models_seq }
489 =
490 { \seq_count:N \l_@@_color_values_seq }
491 {
492 \@@_error:nee { color-models-unpair }
493 { \seq_count:N \l_@@_color_models_seq }
494 { \seq_count:N \l_@@_color_values_seq }
495 }
496 \exp_args:NNe \int_set:Nn \l_@@_set_colors_int
497 { \seq_count:N \l_@@_color_models_seq }
498 \int_step_inline:nn { \l_@@_set_colors_int } % ##1
499 {
500 \tl_set:Ne \l_@@_color_model_tl
501 { \seq_item:Nn \l_@@_color_models_seq { ##1 } }
502 \exp_args:Nne \str_if_eq:nnT { CMYK }
503 { \seq_item:Nn \l_@@_color_models_seq { ##1 } }
504 {
505 \clist_clear:N \l_@@_set_colors_clist
506 \seq_set_item:Nnn \l_@@_color_models_seq { ##1 } { cmyk }
507 \exp_args:Ne \clist_map_inline:nn % ####1
508 { \seq_item:Nn \l_@@_color_values_seq { ##1 } }
509 {
510 \clist_put_right:Ne \l_@@_set_colors_clist
511 { \fp_to_decimal:n { \fp_eval:n { ####1 / 100 } } }
512 }
513 \exp_args:NNnV \seq_set_item:Nnn
514 \l_@@_color_values_seq { ##1 } \l_@@_set_colors_clist
515 }
516 }
517 \tl_set:Ne \l_@@_color_models_tl
518 { \seq_use:Nn \l_@@_color_models_seq { / } }
519 \tl_set:Ne \l_@@_color_values_tl
520 { \seq_use:Nn \l_@@_color_values_seq { / } }
521 \exp_args:Nnee \color_set:nnn { #1 }
522 { \l_@@_color_models_tl }
523 { \l_@@_color_values_tl }
524 \definecolor { #1 }
525 { \l_@@_color_models_tl }
526 { \l_@@_color_values_tl }
527 }
528 \@@_msg_new:nn { color-models-unpair }
529 {
530 The~ number(#1)~ of~ color~ models~ in~ the~ `colors'~
531 arguments~ is~ not~ equal~ to~ the~ number(#2)~ of~ color values.
532 }
533 % \end{macrocode}
534 % \end{macro}
535 %
536 % \subsubsection{图案定义}
537 %
538 % \begin{macro}{\@@_set_vi:n}
539 % 定义视觉标识图案的函数。
540 % \begin{macrocode}
541 \cs_new:Npn \@@_set_vi:n #1
542 {
543 \group_begin:
544 \keys_set:nn { hustvisual / dev } { #1 }
545 \@@_process_set_vi:
546 \group_end:
547 }
548 %\prop_new:N \l_@@_colors_clist
549 \keys_define:nn { hustvisual / dev }
550 {
551 dept .choices:Vn = \c_@@_depts_clist
552 {
553 \tl_set_eq:NN \l_@@_dept_tl \l_keys_choice_tl
554 },
555 dept .initial:V = \c_@@_univ_tl,
556 vi .clist_set:N = \l_@@_vi_clist,
557 vi .value_required:n = true,
558 ncolors .int_set:N = \l_@@_ncolors_int,
559 ncolors .initial:V = \c_zero_int,
560 temps .meta:nn = { hustvisual / dev / temps } { #1 },
561 temps / unknown .code:n =
562 {
563 \clist_set:Nn \l_@@_colors_clist { #1 }
564 \prop_put:NVV \l_@@_temps_prop \l_keys_key_str \l_@@_colors_clist
565 },
566 filename .tl_set:N = \l_@@_filename_tl,
567 filename .initial:V = \c_empty_tl,
568 aliases .clist_set:N = \l_@@_aliases_clist,
569 aliases .initial:V = \c_empty_clist,
570 }
571 % \end{macrocode}
572 % \end{macro}
573 %
574 % \begin{macro}{\@@_process_set_vi:}
575 % 处理在定义视觉标识图案时传入的参数。
576 % \begin{macrocode}
577 \prop_new:N \l_@@_vi_prop
578 \int_new:N \l_@@_ncolors_tmp_int
579 \clist_new:N \l_@@_alias_name_clist
580 \tl_new:N \l_@@_alias_name_tl
581 \cs_new:Npn \@@_process_set_vi:
582 {
583 \prop_clear:N \l_@@_vi_prop
584 \int_compare:nNnT
585 { \l_@@_ncolors_int } > { \c_@@_nargs_int }
586 {
587 \@@_error:nee { colors-exceed-max }
588 { \int_use:N \l_@@_ncolors_int }
589 { \int_use:N \c_@@_nargs_int }
590 }
591 \prop_put:NnV \l_@@_vi_prop { ncolors } \l_@@_ncolors_int
592 \prop_map_inline:Nn \l_@@_temps_prop
593 {
594 \int_set:Nn \l_@@_ncolors_tmp_int
595 { \clist_count:n { ##2 } }
596 \int_compare:nNnF
597 { \l_@@_ncolors_int } = { \l_@@_ncolors_tmp_int }
598 {
599 \@@_error:neee { colors-not-match }
600 { ##1 }
601 { \int_use:N \l_@@_ncolors_tmp_int }
602 { \int_use:N \l_@@_ncolors_int }
603 }
604 }
605 \int_compare:nNnF
606 { \l_@@_ncolors_int } = { \c_zero_int }
607 {
608 \int_compare:nNnT
609 { \prop_count:N \l_@@_temps_prop } = { \c_zero_int }
610 {
611 \@@_error:n { no-temp }
612 }
613 }
614 \prop_put:NnV \l_@@_vi_prop { temps } \l_@@_temps_prop
615 \@@_sort_vi_name:
616 \tl_if_empty:NT \l_@@_filename_tl
617 {
618 \tl_set:Ne \l_@@_filename_tl
619 { \@@_vi_filename: }
620 }
621 \file_if_exist:VF \l_@@_filename_tl
622 {
623 \@@_warning:nee { filename-error }
624 { \tl_use:N \l_@@_filename_tl }
625 { \@@_vi_name: }
626 }
627 \prop_put:NnV \l_@@_vi_prop { filename } \l_@@_filename_tl
628 \prop_if_in:NeT \g_@@_vi_prop { \@@_vi_name: }
629 {
630 \@@_warning:ne { vi-skip }
631 { \@@_vi_name: }
632 }
633 \prop_gput_if_not_in:NeV \g_@@_vi_prop \@@_vi_name: \l_@@_vi_prop
634 \clist_map_variable:NNn \l_@@_aliases_clist \l_@@_alias_name_clist
635 {
636 \prop_clear:N \l_@@_vi_prop
637 \prop_put:Nne \l_@@_vi_prop { source } { \@@_vi_name: }
638 \tl_set:Ne \l_@@_alias_name_tl
639 { \@@_vi_name:N \l_@@_alias_name_clist }
640 \prop_if_in:NVT \g_@@_vi_prop \l_@@_alias_name_tl
641 {
642 \@@_warning:nee { vi-skip }
643 { \l_@@_alias_name_tl }
644 }
645 \prop_gput_if_not_in:NVV \g_@@_vi_prop
646 \l_@@_alias_name_tl
647 \l_@@_vi_prop
648 }
649 }
650 \@@_msg_new:nn { colors-exceed-max }
651 {
652 The~ number(#1)~ of~ colors~ in~ the~ `ncolors'~ property~
653 exceeds~ the~ maximum~ number(#2)~ of~ colors.~
654 Please~ increase~ the~ number~ of~ colors~ in~ the~ \c_@@_nargs_int.
655 }
656 \@@_msg_new:nn { no-temp }
657 {
658 The~ `temps'~ property~ should~ be~ set~ to~ a~ list~ of~ colors,~
659 when~ the~ `ncolors'~ property~ is~ not~ zero.
660 }
661 \@@_msg_new:nn { colors-not-match }
662 {
663 The~ number(#2)~ of~ colors~ in~ the~ `temps'~ property(#1)~
664 does~ not~ match~ the~ number(#3)~ asserted~ in~ the~
665 `ncolors'~ property.
666 }
667 \@@_msg_new:nn { filename-error }
668 {
669 The~ filename~(#1)~ of~ the~ vi(#2)~
670 is~ not~ found~ in~ the~ TeX~ search~ path.~
671 Please~ check~ the~ filename.
672 }
673 \@@_msg_new:nn { vi-skip }
674 {
675 The~ vi~(#1)~ is~ already~ defined.~
676 The~ new~ definition~ has~ been~ skipped.
677 }
678 % \end{macrocode}
679 % \end{macro}
680 %
681 %
682 % \subsection{用户接口}
683 %
684 % \begin{macro}{\hustvi}
685 % 插入视觉标识图案的主函数。
686 % \begin{macrocode}
687 \NewDocumentCommand \hustvi { O{} m }
688 {
689 \group_begin:
690 \keys_set:nn { hustvisual / user }
691 {
692 #1,
693 vi = { #2 },
694 }
695 \@@_process_vi_name:
696 \@@_process_temp:
697 \@@_process_colors:
698 \@@_process_file:
699 \@@_process_vi:
700 \group_end:
701 }
702 \keys_define:nn { hustvisual / user }
703 {
704 dept .choices:Vn = \c_@@_depts_clist
705 {
706 \tl_set_eq:NN \l_@@_dept_tl \l_keys_choice_tl
707 },
708 vi .clist_set:N = \l_@@_vi_clist,
709 vi .value_required:n = true,
710 filename .tl_set:N = \l_@@_filename_tl,
711 filename .initial:V = \c_empty_tl,
712 width .dim_set:N = \l_@@_width_dim,
713 width .initial:V = \c_zero_dim,
714 height .dim_set:N = \l_@@_height_dim,
715 height .initial:V = \c_zero_dim,
716 temp .tl_set:N = \l_@@_temp_tl,
717 temp .initial:V = \c_empty_tl,
718 colors .clist_set:N = \l_@@_colors_clist,
719 colors .initial:V = \c_empty_clist,
720 opacity .fp_set:N = \l_@@_opacity_fp,
721 opacity .initial:V = \c_one_fp,
722 }
723 % \end{macrocode}
724 % \end{macro}
725 %
726 % \begin{macro}{\@@_process_vi_name:}
727 % 处理视觉标识唯一名称以及别名的函数。
728 % \begin{macrocode}
729 \tl_new:N \l_@@_source_name_tl
730 \cs_new:Npn \@@_process_vi_name:
731 {
732 \@@_sort_vi_name:
733 \prop_get:NeNF \g_@@_vi_prop \@@_vi_name: \l_@@_vi_prop
734 {
735 \@@_error:nee { invalid-vi-name }
736 { \l_@@_dept_tl }
737 { \l_@@_vi_clist }
738 }
739 \prop_get:NnNT \l_@@_vi_prop { source } \l_@@_source_name_tl
740 {
741 \prop_get:NVN \g_@@_vi_prop
742 \l_@@_source_name_tl
743 \l_@@_vi_prop
744 }
745 }
746 \@@_msg_new:nn { invalid-vi-name }
747 {
748 The~ combination~ of~ `dept'(#1)~ and~ `vi'(#2)~
749 is~ not~ valid.~
750 Please~ check~ the~ documentation~ of~ the~ package.
751 }
752 % \end{macrocode}
753 % \end{macro}
754 %
755 % \begin{macro}{\@@_process_temp:}
756 % 处理视觉标识色彩预设模板的函数。
757 % \begin{macrocode}
758 \bool_new:N \l_@@_prop_set_bool
759 \cs_new:Npn \@@_process_temp:
760 {
761 \prop_get:NnN \l_@@_vi_prop { temps } \l_@@_temps_prop
762 \prop_get:NVNF \l_@@_temps_prop
763 \l_@@_temp_tl \l_@@_color_args_clist
764 {
765 \tl_if_empty:NF \l_@@_temp_tl
766 {
767 \@@_warning:ne { invalid-temp }
768 { \l_@@_temp_tl }
769 }
770 \bool_set_false:N \l_@@_prop_set_bool
771 \prop_map_inline:Nn \l_@@_temps_prop
772 {
773 \bool_if:NF \l_@@_prop_set_bool
774 {
775 \bool_set_true:N \l_@@_prop_set_bool
776 \clist_set:Nn \l_@@_color_args_clist { ##2 }
777 }
778 }
779 }
780 \@@_deploy_colors:
781 }
782 \@@_msg_new:nn { invalid-temp }
783 {
784 The~ `temp'~ property~(#1)~ is~ not~ valid.~
785 The~ default~ template~ will~ be~ used.~
786 Please~ check~ the~ documentation~ of~ the~ package.
787 }
788 % \end{macrocode}
789 % \end{macro}
790 %
791 % \begin{macro}{\@@_process_colors:}
792 % 处理视觉标识图案覆写色彩的函数。
793 % \begin{macrocode}
794 \tl_new:N \l_@@_color_tl
795 \cs_new:Npn \@@_process_colors:
796 {
797 \clist_if_empty:NF \l_@@_colors_clist
798 {
799 \clist_set_eq:NN \l_@@_color_args_clist \l_@@_colors_clist
800 \@@_deploy_colors:
801 }
802 }
803 % \end{macrocode}
804 % \end{macro}
805 %
806 % \begin{macro}{\@@_process_file:}
807 % 读取视觉标识文件(|hustvisual-*.def|),并将其内容前后添加 \TikZ 环境。
808 % \begin{macrocode}
809 \cs_new:Npn \@@_process_file:
810 {
811 \tl_if_empty:NT \l_@@_filename_tl
812 {
813 \prop_get:NnN \l_@@_vi_prop { filename } \l_@@_filename_tl
814 }
815 \file_get:VnNF \l_@@_filename_tl { \ExplSyntaxOn } \l_@@_vi_tl
816 {
817 \@@_error:ne { file-not-found }
818 { \tl_use:N \l_@@_filename_tl }
819 }
820 \tl_gput_left:Nn \l_@@_vi_tl
821 {
822 \begin{tikzpicture}[
823 inner~sep=0pt,
824 outer~sep=0pt,
825 opacity=\fp_use:N \l_@@_opacity_fp
826 ]
827 }
828 \tl_gput_right:Nn \l_@@_vi_tl
829 {
830 \end{tikzpicture}
831 \color_fill:n {red}
832 }
833 }
834 % \end{macrocode}
835 % \end{macro}
836 %
837 % \begin{macro}{\@@_process_vi:}
838 % 处理视觉标识图案尺寸的函数。
839 % \begin{macrocode}
840 \box_new:N \l_@@_vi_box
841 \cs_new:Npn \@@_process_vi:
842 {
843 \exp_args:NNV \hbox_set:Nn \l_@@_vi_box \l_@@_vi_tl
844 \dim_compare:nNnTF
845 { \l_@@_width_dim } > { \c_zero_dim }
846 {
847 \dim_compare:nNnTF
848 { \l_@@_height_dim } > { \c_zero_dim }
849 {
850 \exp_args:NNVV \box_resize_to_wd_and_ht:Nnn \l_@@_vi_box
851 \l_@@_width_dim \l_@@_height_dim
852 }
853 {
854 \exp_args:NNV \box_resize_to_wd:Nn \l_@@_vi_box \l_@@_width_dim
855 }
856 }
857 {
858 \dim_compare:nNnT
859 { \l_@@_height_dim } > { \c_zero_dim }
860 {
861 \exp_args:NNV \box_resize_to_ht:Nn \l_@@_vi_box \l_@@_height_dim
862 }
863 }
864 \box_use:N \l_@@_vi_box
865 }
866 \@@_msg_new:nn { file-not-found }
867 {
868 The~ file~(#1)~ is~ not~ found.~
869 Please~ check~ the~ file~ name.
870 }
871 % \end{macrocode}
872 % \end{macro}
873 %
874 % \begin{macrocode}
875 %</package>
876 % \end{macrocode}
877 % \subsection{文档样式}
878 % \begin{macrocode}
879 %<*doc-sty>
880 % \end{macrocode}
881 %
882 % 解决 |Package multicol Error: Error saving partial page.|
883 % 方法来自于 \url{https://tex.stackexchange.com/a/95893}。
884 % \begin{macrocode}
885 \setlength\IndexMin{100pt}
886 % \end{macrocode}
887 %
888 % \begin{macro}[no-user-doc]{\TikZ}
889 % \begin{macrocode}
890 \newcommand\TikZ{Ti\emph{k}Z}
891 % \end{macrocode}
892 % \end{macro}
893 %
894 % \begin{macro}[no-user-doc]{\key}
895 % 用于在文档中输出自定义索引的命令,主要用于键值对的键的索引。仅当索引项的父分类为 |hustvi| 时,即用于文档类选项时,隐藏父分类。
896 % \begin{arguments}
897 % \item 在索引中显示项的父分类,默认为 \opt{hustvi}。
898 % \item 命令本体。
899 % \end{arguments}
900 % \begin{macrocode}
901 \DeclareDocumentCommand \key { O{hustvi} m }
902 {
903 \tl_if_eq:nnTF { #1 } { hustvi }
904 { \cmd[module=#1/]{#2} }
905 { \cmd[module=#1/]{#1/#2} }
906 }
907 % \end{macrocode}
908 % \end{macro}
909 %
910 % \begin{macro}[no-user-doc]{\opt}
911 % 输出键值对的值。
912 % \begin{macrocode}
913 \DeclareDocumentCommand \opt { s m }
914 { \IfBooleanTF {#1} { \texttt{\bfseries \upshape #2} } { \texttt{\upshape #2} } }
915 % \end{macrocode}
916 % \end{macro}
917 %
918 % \begin{macro}{\g_@@_show_vi_bool}
919 % 定义是否显示视觉标识实现的全局变量,默认为不显示。
920 % \begin{macrocode}
921 \bool_new:N \g_@@_show_vi_bool
922 \bool_gset_false:N \g_@@_show_vi_bool
923 % \end{macrocode}
924 % \end{macro}
925 %
926 % \begin{environment}{viimplementation}
927 % 定义实现视觉标识所需要的文档环境。
928 % \begin{macrocode}
929 \NewDocumentEnvironment { viimplementation } { }
930 {
931 \bool_if:NF \g_@@_show_vi_bool { \comment }
932 }
933 {
934 \bool_if:NF \g_@@_show_vi_bool { \endcomment }
935 }
936 % \end{macrocode}
937 % \end{environment}
938 %
939 % \begin{macrocode}
940 %</doc-sty>
941 % \end{macrocode}
942 %
943 % \section{子模块实现细节}
944 %
945 % \end{implementation}