summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/xelatex/mynsfc/mynsfc.dtx
blob: 1f48c1e66590ae37b58a70976aea36fc7c8254d9 (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
% \iffalse meta-comment
%<*internal>
\iffalse
%</internal>
%<*readme>
# mynsfc
My XeLaTeX template for writing the main body of NSFC proposals.

----------------------------------------------------------------
mynsfc --- A XeLaTeX template for writing the main body of NSFC proposals.
Author:  Fei Qi
E-mail:  fred.qi@ieee.org
License: Released under the LaTeX Project Public License v1.3c or later
See:     http://www.latex-project.org/lppl.txt
----------------------------------------------------------------

Some text about the class: probably the same as the abstract.
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
----------------------------------------------------------------
mynsfc --- A XeLaTeX template for writing the main body of NSFC proposals.
Author:  Fei Qi
E-mail:  fred.qi@ieee.org
License: Released under the LaTeX Project Public License v1.3c or later
See:     http://www.latex-project.org/lppl.txt
----------------------------------------------------------------

\endpreamble
\postamble

Copyright (C) 2015,2016 by Fei Qi <fred.qi@ieee.org>

This work 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:

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

This work is "maintained" (as per LPPL maintenance status) by
Fei Qi.

This work consists of the file mynsfc.dtx and a Makefile.
Running "make" generates the derived files README, mynsfc.pdf and mynsfc.cls.
Running "make inst" installs the files in the user's TeX tree.
Running "make install" installs the files in the local TeX tree.

\endpostamble

\usedir{tex/xelatex/mynsfc}
\generate{
  \file{\jobname.cls}{\from{\jobname.dtx}{class}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/xelatex/mynsfc}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
% \usedir{doc/xelatex/mynsfc}
% \generate{
%   \file{README.md}{\from{\jobname.dtx}{readme}}
% }
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{mynsfc.dtx}
%</driver>
%<class>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<class>\ProvidesClass{mynsfc}
%<*class>
    [2016/07/11 v1.01 A LaTeX class for writing NSFC proposals.]
%</class>
%<*driver>
\documentclass{ltxdoc}
\usepackage[a4paper,margin=25mm,left=50mm,nohead]{geometry}
\usepackage[numbered]{hypdoc}
\usepackage{xltxtra}
\usepackage{xeCJK}
\defaultfontfeatures{Mapping=tex-text} % after fontspec
\setCJKmainfont{仿宋_GB2312}
\setCJKsansfont{SimHei}
\setCJKmonofont{仿宋_GB2312}
\setmainfont{Times New Roman}
\setmonofont{Courier Std}
\renewcommand{\abstractname}{摘\hspace{2em}要}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{\jobname.dtx}
% \DoNotIndex{\newcommand,\newenvironment}
%
% \title{\textsf{mynsfc} --- 国家自然科学基金申请书正文模板\thanks{此文档描述的
% 模板版本为 \fileversion, 最后修改日期为
% \filedate.} } \author{Fred Qi\thanks{E-mail: fred.qi@ieee.org}} \date{
% \filedate 发布}
%
%\maketitle
%
%\changes{v1.00}{2015/08/18}{First public release}
%\changes{v1.01}{2016/07/11}{Revised command maketitle}
%\changes{v1.01}{2016/07/11}{Added an option arabicpart}
%\changes{v1.01}{2016/07/11}{Author highlight with latest biblatex}
%
% \begin{abstract}
% 用于自然基金申请书正文部分的撰写。
% \end{abstract}
%
% \section{使用说明}
%
% 参见样例文件 \texttt{examples/my-nsfc-proposal.tex}。
%
%\StopEventually{^^A
%  \PrintChanges
%  \PrintIndex
%}
%
% \section{实现}
%
%<*class>
%    \begin{macrocode}
%% Options
\newif\ifmynsfc@subfig\mynsfc@subfigfalse
\newif\ifmynsfc@arabicpart\mynsfc@arabicpartfalse
\DeclareOption{subfig}{\mynsfc@subfigtrue}
\DeclareOption{arabicpart}{\mynsfc@arabicparttrue}
\ExecuteOptions{}
\ProcessOptions
%% Load default class
\LoadClass[a4paper,fleqn]{article}
%    \end{macrocode}
%
%    \begin{macrocode}
%% Load required packages
\RequirePackage{titlesec}
\RequirePackage{marvosym}
\RequirePackage{bm,amsmath,amssymb}
\RequirePackage{paralist}
\RequirePackage{graphicx}
\ifmynsfc@subfig
\RequirePackage[config]{subfig}
\else
\RequirePackage{subcaption}
\fi
\RequirePackage{xcolor}
\RequirePackage{calc}
\RequirePackage{hyperref}
\hypersetup{%
  breaklinks=true,
  colorlinks=true,
  allcolors=black,
  pdfpagelabels}
\urlstyle{same}
%    \end{macrocode}
%    \begin{macrocode}
%% Load and setup package biblatex
\RequirePackage[backend=biber,
                url=true,
                isbn=false,
                defernumbers=true,
                style=ieee]{biblatex}

\appto{\bibfont}{\wuhao}
\defbibheading{reftype}[\bibname]{\subsection*{#1}}
\defbibheading{cvtype}[\bibname]{\paragraph{#1}}
\defbibfilter{conference}{type=inproceedings or type=incollection}

\RequirePackage{xpatch}% or use http://tex.stackexchange.com/a/40705

\@ifpackagelater{biblatex}{2016/03/01}
{
\newcommand*{\list@bold@authors}{}
\newcommand{\initauthors}[1]{
  \renewcommand*{\list@bold@authors}{}
  \forcsvlist{\listadd\list@bold@authors}{#1}}

\newboolean{bold}
\renewcommand*{\mkbibnamefamily}[1]{\ifthenelse{\boolean{bold}}{\textbf{#1}}{#1}}
\renewcommand*{\mkbibnamegiven}[1]{\ifthenelse{\boolean{bold}}{\textbf{#1}}{#1}}

\newbibmacro*{name:bold}{%
  \setboolean{bold}{false}%
  \def\do##1{\iffieldequalstr{hash}{##1}{\setboolean{bold}{true}\listbreak}{}}%
  \dolistloop{\list@bold@authors}%
}

\xpretobibmacro{name:family}{\begingroup\usebibmacro{name:bold}}{}{}{}{}
\xpretobibmacro{name:given-family}{\begingroup\usebibmacro{name:bold}}{}{}{}{}
\xpretobibmacro{name:family-given}{\begingroup\usebibmacro{name:bold}}{}
%\xpretobibmacro{name:delim}{\begingroup\normalfont}{}{}

\xapptobibmacro{name:family}{\endgroup}{}{}{}{}
\xapptobibmacro{name:given-family}{\endgroup}{}{}{}{}
\xapptobibmacro{name:family-given}{\endgroup}{}{}{}{}
%\xapptobibmacro{name:delim}{\endgroup}{}{}
}
{
\newbibmacro*{name:bold}[2]{%
  \def\do##1{\ifstrequal{#1, #2}{##1}{\bfseries\listbreak}{}}%
  \dolistloop{\boldnames}}
\newcommand*{\boldnames}{}

\xpretobibmacro{name:last}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:first-last}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:last-first}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{}
\xpretobibmacro{name:delim}{\begingroup\normalfont}{}{}

\xapptobibmacro{name:last}{\endgroup}{}{}
\xapptobibmacro{name:first-last}{\endgroup}{}{}
\xapptobibmacro{name:last-first}{\endgroup}{}{}
\xapptobibmacro{name:delim}{\endgroup}{}{}
}
%    \end{macrocode}
%
% \begin{macro}{\dummyMacro}
% This is a dummy macro.  If it did anything, we'd describe its
% implementation here.
%    \begin{macrocode}
%    \begin{macrocode}
%
\newcommand{\dummyMacro}{}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%% Setup Chinese fonts with xeCJK
\RequirePackage[AutoFakeBold]{xeCJK}
\def\CJK@null{\kern\CJKnullspace\Unicode{48}{7}\kern\CJKnullspace}
\punctstyle{quanjiao}
\defaultfontfeatures{Mapping=tex-text} % after fontspec
\setCJKmainfont{仿宋_GB2312}
\setCJKsansfont{SimHei}
\setCJKmonofont{仿宋_GB2312}
\setCJKfamilyfont{song}{仿宋_GB2312}
\setCJKfamilyfont{hei}{SimHei}
\setCJKfamilyfont{kai}{KaiTi}
\setmainfont{Times New Roman}
\setmonofont{Courier Std}
%    \end{macrocode}
%
% \begin{macro}{\kai}
% \begin{macro}{\kaiti}
% \begin{macro}{\song}
% \begin{macro}{\songti}
% \begin{macro}{\hei}
% \begin{macro}{\heiti}
% Define commands to select Chinese fonts.
%    \begin{macrocode}
\newcommand{\kai}{\CJKfamily{kai}} % 仿宋体
\newcommand{\song}{\CJKfamily{song}} % 宋体
\newcommand{\hei}{\CJKfamily{hei}} % 黑体
\def\kaiti{\kai}
\def\songti{\song}
\def\heiti{\hei}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
\newlength\mynsfc@linespace
\newcommand{\mynsfc@choosefont}[2]{%
  \setlength{\mynsfc@linespace}{#2*\real{#1}}%
  \fontsize{#2}{\mynsfc@linespace}\selectfont}
\def\mynsfc@define@fontsize#1#2{%
  \expandafter\newcommand\csname #1\endcsname[1][\baselinestretch]{%
    \mynsfc@choosefont{##1}{#2}}}
\mynsfc@define@fontsize{chuhao}{42bp}
\mynsfc@define@fontsize{xiaochu}{36bp}
\mynsfc@define@fontsize{yihao}{26bp}
\mynsfc@define@fontsize{xiaoyi}{24bp}
\mynsfc@define@fontsize{erhao}{22bp}
\mynsfc@define@fontsize{xiaoer}{18bp}
\mynsfc@define@fontsize{sanhao}{16bp}
\mynsfc@define@fontsize{xiaosan}{15bp}
\mynsfc@define@fontsize{sihao}{14bp}
\mynsfc@define@fontsize{banxiaosi}{13bp}
\mynsfc@define@fontsize{xiaosi}{12bp}
\mynsfc@define@fontsize{dawu}{11bp}
\mynsfc@define@fontsize{wuhao}{10.5bp}
\mynsfc@define@fontsize{xiaowu}{9bp}
\mynsfc@define@fontsize{liuhao}{7.5bp}
\mynsfc@define@fontsize{xiaoliu}{6.5bp}
\mynsfc@define@fontsize{qihao}{5.5bp}
\mynsfc@define@fontsize{bahao}{5bp}
%    \end{macrocode}
%
%    \begin{macrocode}
% Define page layout
\setlength{\textwidth}{\paperwidth}
\setlength{\textheight}{\paperheight}
\setlength\marginparwidth{0mm}
\setlength\marginparsep{0mm}
\addtolength{\textwidth}{-50mm}
\setlength{\oddsidemargin}{0mm}
\setlength{\evensidemargin}{\oddsidemargin}
\setlength{\headheight}{20pt}
\setlength{\topskip}{0mm}
\setlength{\skip\footins}{15pt}
\setlength{\topmargin}{-15mm}
\setlength{\footskip}{13mm}
\setlength{\headsep}{6mm}
\addtolength{\textheight}{-50mm}
\setlength{\parskip}{0pt \@plus2pt \@minus0pt}
%    \end{macrocode}
%
% \begin{macro}{\normalsize}
% Redefine command 
%    \begin{macrocode}
\renewcommand\normalsize{%
  \@setfontsize\normalsize{12bp}{20bp}
  \abovedisplayskip=10bp \@plus 2bp \@minus 2bp
  \abovedisplayshortskip=10bp \@plus 2bp \@minus 2bp
  \belowdisplayskip=\abovedisplayskip
  \belowdisplayshortskip=\abovedisplayshortskip}
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
% Define page styles      
\def\ps@mynsfc@empty{%
  \let\@oddhead\@empty%
  \let\@evenhead\@empty%
  \let\@oddfoot\@empty%
  \let\@evenfoot\@empty}
%    \end{macrocode}
%
% \begin{environment}{hcomment}
% Dimmed text used as hint after section titles. 
%    \begin{macrocode}
\newenvironment{hcomment}{\vskip-3pt\color{gray}}{\vskip6pt}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\figurename}
% \begin{macro}{\tablename}
% \begin{macro}{\contentsname}
% Translate English to Chinese.
%    \begin{macrocode}
\renewcommand{\figurename}{图}
\renewcommand{\tablename}{表}
\renewcommand{\contentsname}{内容目录}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
%      
\DeclareCaptionLabelFormat{mynsfc@cap}{{\wuhao#1\rmfamily#2}}
\DeclareCaptionLabelSeparator{mynsfc@sep}{\hspace{1em}}
\DeclareCaptionFont{mynsfc@capfont}{\wuhao}
\captionsetup{labelformat=mynsfc@cap,
              labelsep=mynsfc@sep,
              font=mynsfc@capfont,
              justification=centering}
%    \end{macrocode}
%
% \begin{macro}{CJKindent}
% Indent with two Chinese full spaces.
%    \begin{macrocode}
%      
\newlength\mynsfc@CJK@twochars
\newcommand{\mynsfc@unicode}[2]{\char\numexpr#1*256+#2\relax}
\def\mynsfc@CJK@space{\mynsfc@unicode{48}{7}}
\def\CJKindent{%
  \settowidth\mynsfc@CJK@twochars{\mynsfc@CJK@space\mynsfc@CJK@space}%
  \parindent\mynsfc@CJK@twochars}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\maketitle}
\renewcommand{\maketitle}{%
  \begin{center}%
    \heiti\erhao\@title%
  \end{center}}
% \end{macro}
%
% \begin{macro}{\part}
% \begin{macro}{\section}
% \begin{macro}{\subsection}
% \begin{macro}{\subsubsection}
% \begin{macro}
% Commands to format several levels of titles (part, section, subsection).
%    \begin{macrocode}
\ifmynsfc@arabicpart%
\renewcommand{\thepart}{\arabic{part}.}
\titleformat{\part}{\heiti\sanhao}{\thepart}{1ex}{}
\renewcommand{\thesection}{\arabic{section})}
\renewcommand{\thesubsection}{\Alph{subsection})}
\else%
\def\nsfc@CJKnumber#1{\ifcase#1{零}\or%
  {一}\or{二}\or{三}\or{四}\or{五}\or%
  {六}\or{七}\or{八}\or{九}\or{十}\or%
  {十一}\or{十二}\or{十三}\or{十四}\or{十五}\or%
  {十六}\or{十七}\or{十八}\or{十九}\or{二十}\fi}
\renewcommand{\thepart}{(\nsfc@CJKnumber{\c@part})}
\titleformat{\part}{\heiti\sanhao}{\thepart}{0ex}{}
\renewcommand{\thesection}{\arabic{section}.}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}
\fi

\titlespacing{\part}{0ex}{4ex}{2ex}

\@addtoreset{section}{part}
\titleformat{\section}{\heiti\xiaosan}{\thesection}{0.25em}{}
\titlespacing{\section}{0em}{4ex}{2ex}

\titleformat{\subsection}{\hei\sihao}{\thesubsection}{0.25em}{}
\titlespacing{\subsection}{0em}{2ex}{1ex}

\titleformat{\subsubsection}{\heiti\banxiaosi}{\thesubsubsection}{0.25em}{}
\titlespacing{\subsubsection}{0em}{2ex}{1ex}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%    \begin{macrocode}
\let\mynsfc@begindocumenthook\@begindocumenthook
\let\mynsfc@enddocumenthook\@enddocumenthook
\def\AtBeginDocument{\g@addto@macro\mynsfc@begindocumenthook}
\def\AtEndDocument{\g@addto@macro\mynsfc@enddocumenthook}
\def\@begindocumenthook{\mynsfc@begindocumenthook}
\def\@enddocumenthook{\mynsfc@enddocumenthook}
\AtBeginDocument{\ps@mynsfc@empty\CJKindent}
\endinput
%</class>
%    \end{macrocode}
%\Finale