summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/njuvisual/njuvisual.dtx
blob: 8d2831c9c24730757f1ca78e573c63d292a62300 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
% \iffalse meta-comment
%
% Copyright (C) 2021
% by Nanjing University Linux User Group <nju.lug@yaoge123.cn>
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version. The latest version
% of this license is in the file
%
%    https://www.latex-project.org/lppl.txt
%
% -----------------------------------------------------------------------
%
% The development version of the template can be found at
%
%    https://github.com/nju-lug/NJUVisual
%
% for those people who are interested.
%
% -----------------------------------------------------------------------
%
%<*internal>
\iffalse
%</internal>
%
%<*internal>
\fi
\begingroup
  \def\NameOfLaTeXe{LaTeX2e}
\expandafter\endgroup\ifx\NameOfLaTeXe\fmtname\else
\csname fi\endcsname
%</internal>
%
%<*install>
\input l3docstrip.tex
\keepsilent
\askforoverwritefalse

\preamble

Copyright (C) 2021
by Nanjing University Linux User Group <nju.lug@yaoge123.cn>

This file may be distributed and/or modified under the conditions of
the LaTeX Project Public License, either version 1.3 of this license
or (at your option) any later version.  The latest version of this
license is in:

   http://www.latex-project.org/lppl.txt

and version 1.3 or later is part of all distributions of LaTeX version
2005/12/01 or later.

To produce the documentation run the original source files ending with `.dtx'
through XeTeX.

\endpreamble

\generate{
  \usedir{tex/latex/njuvisual}
    \file{\jobname.sty} {\from{\jobname.dtx}{visual}
                        \from{\jobname-curves.dtx}{visual}}
%</install>
%<*internal>
  \usedir{source/latex/njuvisual}
    \file{\jobname.ins} {\from{\jobname.dtx}{install}}
%</internal>
%<*install>
}

\obeyspaces
\Msg{*************************************************************}
\Msg{*                                                           *}
\Msg{* To finish the installation you have to move the following *}
\Msg{* files into a directory searched by TeX:                   *}
\Msg{*                                                           *}
\Msg{* The recommended directory is TDS:tex/latex/njuvisual      *}
\Msg{*                                                           *}
\Msg{*     njuvisual.ins                                         *}
\Msg{*     njuvisual.sty                                         *}
\Msg{*                                                           *}
\Msg{* To produce the documentation, run the file njuvisual.dtx  *}
\Msg{* through XeLaTeX.                                          *}
\Msg{*                                                           *}
\Msg{* Happy TeXing!                                             *}
\Msg{*                                                           *}
\Msg{*************************************************************}

\endbatchfile
%</install>
%
%<*internal>
\fi
%</internal>
%
%<visual>\NeedsTeXFormat{LaTeX2e}
%<visual>\RequirePackage{expl3}
%<!driver>\GetIdInfo  $Id: njuvisual.dtx 0.1.1 2021-11-27 22:30:00 +0800  NJU LUG <nju.lug@yaoge123.cn> $
%<visual>  { LaTeX3 Package for NJU Visual Identity }
%<visual>\ProvidesExplPackage{njuvisual}
%<visual>{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
%
%<*driver>
\documentclass{ctxdoc}
\usepackage{multirow,njuvisual}
\setlist[1]{labelindent=0.5em}
\begin{document}
    \DocInput{njuvisual.dtx}
    \DocInput{njuvisual-curves.dtx}
    \PrintChanges
    \PrintIndex
\end{document}
%</driver>
%
% \fi
%
% \title{\color{njuviolet}{The \pkg{njuvisual} package\\ 南京大学视觉形象规范化标准}}
%
% \author{^^A
% Nanjing University Linux User Group
% \thanks{E-mail: \href{mailto:nju.lug@yaoge123.cn}{nju.lug@yaoge123.cn}}}
%
% \date{v0.1.1 \\ Released 2021-11-21}
%
% \changes{v0.1}{2021/11/21}{将\pkg{njuvisual}分离为单独宏包。}
% \changes{v0.1}{2021/11/27}{完成文档编写并发布至 CTAN。}
%
% \maketitle
%
% \begin{abstract}
% 南京大学视觉形象规范化标准(\pkg{njuvisual})宏包负责实现\href{https://www.nju.edu.cn/3647/list.htm}{南京大学视觉形象规范化标准}以及各院系制定的配色方案和标识。
% \end{abstract}
%
% \def\abstractname{Abstract}
% \begin{abstract}
% The \pkg{njuvisual} package provides an interface to display logos related to Nanjing University.
% \end{abstract}
%
% \clearpage
%
% \tableofcontents
%
% \EnableDocumentation
%
%
% \begin{documentation}
%
% \section{宏包介绍}
%
% \pkg{njuvisual} 用于收录南京大学及其各院系制定的标准色彩及图标,并提供简洁的绘制指令。
%
% 本宏包衍生自 \pkg{njuthesis},依赖 \hologo{LaTeX3} 项目
% 中的 \pkg{expl3}、\pkg{xparse} 和 \pkg{l3keys2e} 宏包。
% 特别感谢 \pkg{fduthesis} 与 \pkg{zhlipsum} 提供的处理思路。
%
% \section{使用方法}
%
% \subsection{标准色彩}
%
% \begin{function}{\color}
%   \begin{syntax}
%     \tn{color}\Arg{颜色}
%   \end{syntax}
% 使用标准色彩。
% \end{function}
%
% 本宏包定义的所有标准色彩见表~\ref{tab:pre-defined-colors}。
% \begingroup
% \def\B#1{\color{#1}$\blacksquare\blacksquare\blacksquare\blacksquare\blacksquare$}
% \def\M#1{\multirow{2}*{#1}}
% \def\MN#1{\multirow{4}*{#1}}
% \begin{table}[htb]
%   \caption{预定义标准色} \label{tab:pre-defined-colors}
%   \centering\small
%   \begin{tabular}{cccc}
%     \toprule
%       名称                   & 颜色名称        & CMYK 数值                & 示例 \\
%     \midrule
%       \MN{南京大学}          & |njuviolet|     & $0.50, 1   , 0   , 0.40$ & \B{njuviolet} \\
%                              & |njumagenta|    & $0.05, 1   , 0.55, 0$    & \B{njumagenta} \\
%                              & |njublue|       & $0.80, 0.50, 0   , 0$    & \B{njublue} \\
%                              & |njuyellow|     & $0   , 0.30, 1   , 0$    & \B{njuyellow} \\
%       \M{人工智能学院}       & |nju-ai-blue|   & $0.75, 0.65, 0   , 0$    & \B{nju-ai-blue} \\
%                              & |nju-ai-orange| & $0   , 0.75, 1   , 0$    & \B{nju-ai-orange} \\
%       \M{计算机科学与技术系} & |nju-cs-blue|   & $0.89, 0.66, 0.13, 0$    & \B{nju-cs-blue} \\
%                              & |nju-cs-green|  & $0.60, 0.23, 1   , 0$    & \B{nju-cs-green} \\
%     \bottomrule
%   \end{tabular}
% \end{table}
% \endgroup
%
% \subsection{标准图标}
%
% \begin{function}[added=2021-09-24,updated=2021-11-27]{\njuemblem}
%   \begin{syntax}
%     \tn{njuemblem}\oarg{选项}\Arg{宽度}\Arg{高度}
%   \end{syntax}
%   生成徽标,默认生成校徽。参数 \meta{选项} 是可选的。注意各
%   参数之间不可以有空格。
% \end{function}
%
% \begin{function}[added=2021-09-24,updated=2021-11-27]{\njuname,\njuname*}
%   \begin{syntax}
%     \tn{njuname}\oarg{选项}\Arg{宽度}\Arg{高度}
%     \tn{njuname*}\oarg{选项}\Arg{宽度}\Arg{高度}
%   \end{syntax}
%   生成名称,带有可选星号的命令会生成英文名称,默认生成校名。要求同上。
% \end{function}
%
% 可选参数 \meta{选项} 可使用两种方式给出:
% \begin{itemize}
%   \item 颜色名称,使用颜色名称即默认生成校徽、校名
%   \item 使用英文半角逗号分隔的键值列表
% \end{itemize}
%
% 其中,键值列表支持的选项见下。
%
% \begin{function}[added=2021-11-27]{color,color*}
%   \begin{syntax}
%     color = \meta{主要颜色}
%     color* = \meta{辅助颜色}
%   \end{syntax}
%   定制图标颜色。
% \end{function}
%
% 对于绝大多数南京大学院系,其图标仅使用两种以内的颜色,因此本宏包仅提供两种颜色选项。
% 其中的 |color*| 选项一般无需修改,原因在于现有的图标可被总结为下列若干种情况:
% \begin{description}
%   \item[纯色、透明底色] 如南大徽标,无辅助颜色,|color*| 选项无效
%   \item[纯色、白色] 如现工徽标,辅助颜色默认为白色,无需进行修改
%   \item[双色] 如计科徽标,主要颜色、辅助颜色已预先进行定义,为美观考虑,修改主要颜色时会将图标颜色统一为一种
% \end{description}
%
% \begin{function}[added=2021-11-27]{department}
%   \begin{syntax}
%     department = \meta{院系名称}
%   \end{syntax}
%   院系名称。
% \end{function}
%
% 为保证无歧义,|department| 选项使用的名称来自于院系官网域名。如化学化工学院域名为\url{https://chem.nju.edu.cn/},其选项名称即为 |chem|。
%
% 目前的支持情况如表~\ref{tab:supported-departments-list}所示。对于不支持的院系,本宏包会抛出异常。
% \begingroup
% \def\B{\bullet}
% \begin{table}[htb]
%   \caption{收录院系列表} \label{tab:supported-departments-list}
%   \centering\small
%   \begin{tabular}{cccccccc}
%     \toprule
%       名称 & 选项名称 & emblem & name & name* \\
%     \midrule
%       匡亚明学院             & |dii| & \B & & \\
%       现代工程与应用科学学院 & |eng| & \B & & \\
%       人工智能学院           & |ai| & \B & & \\
%       计算机科学与技术系     & |cs| & \B & & \\
%     \bottomrule
%   \end{tabular}
% \end{table}
% \endgroup
%
% 举例如下:
% \begin{ctexexam}
%   \njuemblem{!}{3cm}                           % 默认生成指定大小的紫色南大校徽
%   \njuname{4cm}{!}                             % 默认生成指定大小的紫色南大中文校名
%   \njuname*{4cm}{!}                            % 默认生成指定大小的紫色南大英文校名
%   \njuemblem[black]{!}{3cm}                    % 黑色的南大校徽
%   \njuemblem[department=dii]{!}{4cm}           % 紫色匡院徽标
%   \njuemblem[department=cs,color=blue]{!}{3cm} % 纯蓝色计科徽标
% \end{ctexexam}
%
%
% \begin{function}[added=2021-09-24]{\njumotto}
%   \begin{syntax}
%     \tn{njumotto}\oarg{颜色}\Arg{宽度}\Arg{高度}
%   \end{syntax}
% 生成指定颜色和大小的南京大学校训。
% \end{function}
%
%
% \begin{function}[added=2021-09-24]{\njuspirit}
%   \begin{syntax}
%     \tn{njuspirit}\oarg{颜色}\Arg{宽度}\Arg{高度}
%   \end{syntax}
% 生成指定颜色和大小的南京大学校风。
% \end{function}
%
% \end{documentation}
%
% \EnableImplementation
%
% \begin{implementation}
%
% \section{实现细节}
%
%    \begin{macrocode}
%<@@=njuvis>
%<*visual>
%    \end{macrocode}
%
% \subsection{载入宏包}
%
% 导入 \pkg{tikz} 宏包,其中已包含 \pkg{xcolor},无需单独加载。
%    \begin{macrocode}
\RequirePackage { tikz }
%    \end{macrocode}
%
% \subsection{定义变量}
%
% \begin{macro}{\l_@@_color_a_tl,\l_@@_color_b_tl}
% 存储使用的颜色。
%    \begin{macrocode}
\tl_new:N \l_@@_color_a_tl
\tl_new:N \l_@@_color_b_tl
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_department_tl}
% 存储院系
%    \begin{macrocode}
\tl_new:N \l_@@_department_tl
%    \end{macrocode}
% \end{macro}
%
% \changes{v0.1}{2021/11/27}{使用键值对处理院系和颜色。}
%    \begin{macrocode}
\keys_define:nn { njuvisual }
  {
%    \end{macrocode}
% \begin{macro}{color,color*}
% 颜色。设定初始辅助色为白色
%    \begin{macrocode}
    color       .tl_set:N = \l_@@_color_a_tl,
    color      .initial:n = default,
    color*      .tl_set:N = \l_@@_color_b_tl,
    color*     .initial:n = white,
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{department}
% 院系
%    \begin{macrocode}
    department  .tl_set:N = \l_@@_department_tl,
    department .initial:n = nju,
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{variable}{\c_@@_department_all_clist}
% 定义南京大学全体院系名单。
%    \begin{macrocode}
\clist_const:Nn \c_@@_department_all_clist
{ nju, dii, eng, chin, history, philo, jc, law, nubs, sfs, im, sociology, 
  math, physics, astronomy, chem, cs, software, ai, ese, hjxy, sgos,
  as, life, med, sme, hwxy, arch, marxism, art, edu }
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{\c_@@_department_emblem_clist}
% 定义受图标支持的南京大学院系名单。
%    \begin{macrocode}
\clist_const:Nn \c_@@_department_emblem_clist { nju, dii, eng, cs, ai }
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{\c_@@_department_name_clist}
% 定义受名称支持的南京大学院系名单。
%    \begin{macrocode}
\clist_const:Nn \c_@@_department_name_clist   { nju }
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{\c_@@_department_color_clist}
% 定义受色彩支持的南京大学院系名单。
%    \begin{macrocode}
\clist_const:Nn \c_@@_department_color_clist  { cs, ai }
%    \end{macrocode}
% \end{variable}
%
% 定义对不支持的院系的报错信息。
%    \begin{macrocode}
\msg_new:nnn { njuvisual } { unsupported-department }
{ "#1"~ is~ not~ an~ valid~ option~ \\\\
  Please~ refer~ to~ the~ package~ documentation~  for~ supported~ 
  departments~ and~ check~ your~ spelling. \\ }
%    \end{macrocode}
%
% \subsection{内部命令}
%
% \begin{macro}{\@@_set_color:}
% \changes{v0.1}{2021/11/25}{完善设定颜色的方法。}
% 设定颜色。
%    \begin{macrocode}
\cs_new_protected:Nn \@@_set_color:
  {
    \str_if_eq:VnTF \l_@@_color_a_tl { default }
      { 
%    \end{macrocode}
% 如果没有单独设定,则使用默认颜色。
%    \begin{macrocode}
        \clist_if_in:NVTF \c_@@_department_color_clist \l_@@_department_tl
          { \tl_set:Nn \l_@@_color_a_tl 
              { \clist_item:cn { c_@@_color_ \l_@@_department_tl _clist } { 1 } }
            \tl_set:Nn \l_@@_color_b_tl 
              { \clist_item:cn { c_@@_color_ \l_@@_department_tl _clist } { 2 } } }
          { \tl_set:Nn \l_@@_color_a_tl { njuviolet } }
      } 
      { \clist_if_in:NVT \c_@@_department_color_clist \l_@@_department_tl
%    \end{macrocode}
% 将双色图标设定为纯色。
%    \begin{macrocode}
          { \tl_set_eq:NN \l_@@_color_b_tl \l_@@_color_a_tl } }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_tikz_wrapper:nnn}
% 可变大小的 tikz 容器。\footnote{此处手动调整了列表缩进,实际上\env{arguments}环境的缩进问题已在\href{https://github.com/CTeX-org/ctex-kit/commit/838ebab8378b6b0477f5aece81ace28ae2a8bcd9}{838ebab}提交中修复}
% \begin{arguments}
%   \item 路径
%   \item 宽度
%   \item 高度
% \end{arguments}
% 封装 resizebox 和 tikzpicture 环境,减少重复。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_tikz_wrapper:nnn #1#2#3
{
  \resizebox { #2 } { #3 } {
    \begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1,
        xscale=1, inner~sep=0pt, outer~sep=0pt] #1
    \end{tikzpicture} }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_if_key_value_list:nTF}
% 判断是否为键值列表,即是否含有 |=|。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_if_key_value_list:nTF #1
  { \tl_if_in:nnTF {#1} {=} }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_colon}
% 定义类别为 other 的冒号,用于在 Expl3 中表示路径
%    \begin{macrocode}
\def \@@_colon { \char_generate:nn { 58 } { 12 } }
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{用户接口}
%
% \begin{macro}{\njuemblem}
% \changes{v0.1}{2021/11/24}{将学校和院系的徽标和名称命令统一。}
% 定义南京大学标准徽标。
% \begin{arguments}
%   \item 颜色或者键值对
%   \item 宽度
%   \item 高度
% \end{arguments}
%    \begin{macrocode}
\NewDocumentCommand \njuemblem { O { njuviolet } m m }
{
  \group_begin:
%    \end{macrocode}
% 根据参数是否含有 |=| 来判断该参数是段落数还是选项列表。
%    \begin{macrocode}
    \@@_if_key_value_list:nTF { #1 }
    {
      \keys_set:nn { njuvisual } { #1 }
%    \end{macrocode}
% 检查是否受支持。
%    \begin{macrocode}
          \clist_if_in:NVTF \c_@@_department_emblem_clist \l_@@_department_tl
        { \@@_set_color:
          \@@_tikz_wrapper:nnn 
            { \use:c { @@_path_emblem_ \l_@@_department_tl } } { #2 } { #3 } }
        { \msg_error:nnx { njuvisual } 
            { unsupported-department } { \l_@@_department_tl } }
    }
    { \tl_set:Nn \l_@@_color_a_tl { #1 }
      \@@_tikz_wrapper:nnn { \@@_path_emblem_nju } { #2 } { #3 } }
  \group_end:
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\njuname,\njuname*}
% 定义南京大学标准名称。
% \begin{arguments}
%   \item 可选星号
%   \item 颜色或者键值对
%   \item 宽度
%   \item 高度
% \end{arguments}
%    \begin{macrocode}
\NewDocumentCommand \njuname { t* O { njuviolet } m m }
{
  \group_begin:
    \@@_if_key_value_list:nTF { #2 }
    {
      \keys_set:nn { njuvisual } { #2 }
      \clist_if_in:NVTF \c_@@_department_name_clist \l_@@_department_tl
        { 
          \@@_set_color:
          \bool_if:NTF { #1 }
            { \@@_tikz_wrapper:nnn 
                { \use:c { @@_path_name_ #2 _en } } { #3 } { #4 } }
            { \@@_tikz_wrapper:nnn 
                { \use:c { @@_path_name_ #2 _cn } } { #3 } { #4 } }
        }
        { \msg_error:nnx { njuvisual } 
            { unsupported-department } { \l_@@_department_tl } }
    }
    {
      \tl_set:Nn \l_@@_color_a_tl { #2 }
      \bool_if:NTF { #1 }
        { \@@_tikz_wrapper:nnn { \@@_path_name_nju_en } { #3 } { #4 } }
        { \@@_tikz_wrapper:nnn { \@@_path_name_nju_cn } { #3 } { #4 } }
    }
  \group_end:
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\njumotto}
% 定义南京大学校训。
% \begin{arguments}
%   \item 颜色
%   \item 宽度
%   \item 高度
% \end{arguments}
%    \begin{macrocode}
\NewDocumentCommand \njumotto  { o m m }
{ 
  \group_begin:
    \tl_set:Nn \l_@@_color_a_tl { #1 }
    \@@_tikz_wrapper:nnn { \@@_path_motto } { #2 } { #3 }
  \group_end:
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\njuspirit}
% 定义南京大学校风。
% \begin{arguments}
%   \item 颜色
%   \item 宽度
%   \item 高度
% \end{arguments}
%    \begin{macrocode}
\NewDocumentCommand \njuspirit { o m m }
{ 
  \group_begin:
    \tl_set:Nn \l_@@_color_a_tl { #1 }
    \@@_tikz_wrapper:nnn { \@@_path_spirit } { #2 } { #3 } 
  \group_end:
}
%</visual>
%    \end{macrocode}
% \end{macro}
%