summaryrefslogtreecommitdiff
path: root/info/lshort/chinese/src/lshort-zh-cn-style.sty
blob: 3aca98d561afabebeb601c568bfe59dbb8c1f58f (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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{lshort-zh-cn-style}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% lshort 调用的宏包
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 基本工具宏包
%
\RequirePackage{amsmath,amsthm}
\RequirePackage{hologo,verbatim,fancyvrb,layout,multicol}
\RequirePackage[normalem]{ulem}
\RequirePackage{colortbl,tabularx,multirow,makecell,booktabs}
\RequirePackage{graphicx,xcolor,float,subfig}
\RequirePackage{makeidx}
\RequirePackage[inner=1in,outer=1.5in,vmargin=1in,marginparwidth=1in]{geometry}
\RequirePackage{tikz}

%
% ctex 宏包 2.2(2015/06/24) 或以上版本
% ctex 宏包的字号设定会让许多固定字号的字体宏包报太多 warning,应当抑制
% 中文正文字体使用 Fandol
%
\PassOptionsToPackage{no-math}{fontspec}
\RequirePackage[zihao=false,scheme=chinese,heading=true,fontset=fandol]{ctex}[2015/06/24]

%
% 字体和符号宏包
%
\setmainfont{cmun}[
  Extension       = .otf,
  UprightFont     = *rm,
  ItalicFont      = *ti,
  SlantedFont     = *sl,
  BoldFont        = *bx,
  BoldItalicFont  = *bi,
  BoldSlantedFont = *bl,
]
\setsansfont{cmun}[
  Extension      = .otf,
  UprightFont    = *ss,
  ItalicFont     = *si,
  BoldFont       = *sx,
  BoldItalicFont = *so,
]
\setmonofont{cmun}[
  Extension      = .otf,
  UprightFont    = *btl,% light version
  ItalicFont     = *bto,%  light version
  BoldFont       = *tb,
  BoldItalicFont = *tx,
]
\RequirePackage{amssymb,latexsym,textcomp,mathrsfs,euscript,yhmath} % 与默认字体不冲突的一些符号包
% 消除 \t 命令的字体 warning
\AtBeginDocument{%}
  \renewcommand*\t[1]{{\edef\restore@font{\the\font}\usefont{OML}{cmm}{m}{it}\accent"7F\restore@font#1}}
}

% 调整 layout 宏包的命令使之能够放入浮动体,手动指定奇偶页的 layout
\input lshort-zh-cn-layout
\oddsidelayouttrue
% layout 文字汉化
\def\Headertext{页眉}
\def\Bodytext{版心}
\def\Footertext{页脚}
\def\MarginNotestext{边注}
\def\oneinchtext{1in}
\def\notshown{未显示}

% hyperref 基本设定
\RequirePackage{hyperref}
\hypersetup{colorlinks,%
  bookmarksnumbered=true,%
  pdfstartview=FitH}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% lshort 的版式设置
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\raggedbottom

%
% 不依赖 fancyhdr 的页眉页脚设定
%
\addtolength{\headheight}{1.6pt}
\newdimen\headwidth \headwidth\textwidth
\newdimen\headrulewidth \headrulewidth=0.4pt
\def\ps@fancy{%
  \let\@oddfoot\@empty\let\@evenfoot\@empty
  \def\@evenhead{\vbox to \headheight{%
    \hb@xt@\headwidth{\bfseries\thepage\hfil\leftmark}%
    \vss\hrule\@height\headrulewidth}}%
  \def\@oddhead{\vbox to \headheight{%
    \hb@xt@\headwidth{\bfseries\rightmark\hfil\thepage}%
    \vss\hrule\@height\headrulewidth}}%
  \let\@mkboth\markboth
  \def\chaptermark##1{\markboth{\if@mainmatter\CTEXthechapter\fi\quad ##1}{}}
  \def\sectionmark##1{\markright{\S\thesection\quad ##1}}
}
%\let\ps@plain\ps@fancyplain
\pagestyle{fancy}

%
% 不依赖 tocbibind 的参考文献/索引修改
% 索引依赖 multicols 环境排版
%
\renewenvironment{thebibliography}[1]
  {\chapter{\bibname}%
  \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}%
  \list{\@biblabel{\@arabic\c@enumiv}}%
   {\settowidth\labelwidth{\@biblabel{#1}}%
    \leftmargin\labelwidth
    \advance\leftmargin\labelsep
    \@openbib@code
    \usecounter{enumiv}%
    \let\p@enumiv\@empty
    \renewcommand\theenumiv{\@arabic\c@enumiv}}%
    \sloppy
    \clubpenalty4000
    \@clubpenalty \clubpenalty
    \widowpenalty4000%
    \sfcode`\.\@m}
   {\def\@noitemerr
     {\@latex@warning{Empty `thebibliography' environment}}%
  \endlist}
\renewenvironment{theindex}%
  {\chapter{\indexname}%
   \@mkboth{\MakeUppercase\indexname}{\MakeUppercase\indexname}%
   \parskip\z@ \@plus .3\p@\relax
   \let\item\@idxitem
   \small
   \begin{multicols}{2}}
   {\end{multicols}}

%
% 将主目录和源代码目录合并排版
% 不依赖 float 宏包的 \listof,因此要补充定义 \l@sourcecode
%
\renewcommand\tableofcontents%
  {\chapter{\contentsname}%
  \@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}%
  \begin{multicols}{2}
    \@starttoc{toc}%
  \end{multicols}
  \@makeschapterhead{\sourcecodename}%
  \@starttoc{los}%
}

%
% 令 \cleardoublepage 的偶数页页眉页脚为空
%
\renewcommand{\cleardoublepage}
    {\clearpage\if@twoside \ifodd\c@page\else
    \hbox{}\thispagestyle{empty}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}

% 允许 hologo 断词
\hologoSetup{discretionarybreak=true}
% 新定义 hologo
\def\HoLogo@TeXLive#1{%
  \hologo{TeX}\HOLOGO@space\HOLOGO@mbox{Live}%
}
\def\HoLogo@MacTeX#1{%
  \HOLOGO@mbox{Mac}\hologo{TeX}%
}
\def\HoLogo@CTeX#1{%
  \HOLOGO@mbox{C}\hologo{TeX}%
}
\def\HoLogo@TikZ#1{%
  \HOLOGO@mbox{Ti\textit{k\/}Z}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% lshort 用到的自定义命令
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 源自 TeX FAQ 的超链接命令
% CTAN 镜像暂用清华源
%
\newcommand{\Email}{\begingroup \def\UrlLeft{<}\def\UrlRight{>} \urlstyle{tt}\Url}     % email address
\def\mailto|#1|{\href{mailto:#1}{\Email|#1|}}        % url to mail somewhere
\def\CTANref{\begingroup \urlstyle{tt}\Url}
\def\CTAN|#1|{\href{http://mirrors.tuna.tsinghua.edu.cn/CTAN/#1}{\CTANref|CTAN://#1|}}
\newcommand{\contrib}[3]{#1\quad\mailto|#2|{\small\\\quad\textit{#3}}\\[1ex]}

%
% 示意长度
%
\def\demowidth#1{\rule{0.4pt}{1ex}\rule{#1}{1.2pt}\rule{0.4pt}{1ex}}

%
% 命令和环境的写法
%
\DeclareRobustCommand*\cmd[1]{\texttt{\char`\\#1}}
\DeclareRobustCommand\cs[1]{\texttt{\char`\\#1}}
\def\crcmd{\cmd{\char`\\}}
\DeclareRobustCommand*\env[1]{\texttt{#1}}
\DeclareRobustCommand*\pkg[1]{\textsf{#1}}
\DeclareRobustCommand*\cls[1]{\textsf{#1}}
\DeclareRobustCommand*\marg{\@ifstar\@marg\@margmeta}
\DeclareRobustCommand*\oarg{\@ifstar\@oarg\@oargmeta}
\DeclareRobustCommand*\Arg[1]{\@meta{#1}}
\def\@oarg#1{\textcolor{gray}{\texttt{[#1]}}}
\def\@oargmeta#1{\@oarg{\@meta{#1}}}
\def\@marg#1{\texttt{\{#1\}}}
\def\@margmeta#1{\@marg{\@meta{#1}}}
\def\@meta#1{$\m@th\langle$\textnormal{\textit{#1}}$\m@th\rangle$}

%
% 命令和环境的索引
%
\def\pkgindex#1{\@for\pkgname:=#1\do{\index{\pkgname @\pkg{\pkgname} 宏包}}}
\def\clsindex#1{\@for\clsname:=#1\do{\index{\clsname @\cls{\clsname} 文档类}}}
\def\cmdindex{\@ifnextchar[{\pkgcmdindex}{\ltxcmdindex}}
\def\envindex{\@ifnextchar[{\pkgenvindex}{\ltxenvindex}}
\def\ltxcmdindex#1{\@for\@ltxcmd:=#1\do{\index{\@ltxcmd @\cmd{\@ltxcmd}}}}
\def\ltxenvindex#1{\@for\@ltxenv:=#1\do{\index{\@ltxenv @\env{\@ltxenv} 环境}}}
\def\pkgcmdindex[#1]#2{\@for\@pkgcmd:=#2\do{\index{\@pkgcmd @\cmd{\@pkgcmd} (\pkg{#1})}}}
\def\pkgenvindex[#1]#2{\@for\@pkgenv:=#2\do{\index{\@pkgenv @\env{\@pkgenv} 环境 (\pkg{#1})}}}

%
% 文本和数学符号索引
%
\def\symindex#1{\@for\t@xtsym:=#1\do{\index{\t@xtsym @\cmd{\t@xtsym} (\textit{符号} \expandafter\protect\csname \t@xtsym\endcsname)}}}
\def\mathindex#1{\@for\m@thcmd:=#1\do{\index{\m@thcmd @\cmd{\m@thcmd} (\textit{数学命令})}}}
\def\msymindex#1{\@for\m@thsym:=#1\do{\index{\m@thsym @\cmd{\m@thsym} (\textit{数学符号}$\expandafter\protect\csname \m@thsym\endcsname$)}}}
\def\maccindex#1{\@for\m@thacc:=#1\do{\index{\m@thacc @\cmd{\m@thacc} (\textit{数学重音}$\expandafter\protect\csname \m@thacc\endcsname{a}$)}}}
\def\waccindex#1{\@for\wideacc:=#1\do{\index{\wideacc @\cmd{\wideacc} (\textit{数学重音}$\expandafter\protect\csname \wideacc\endcsname{AB}$)}}}

%
% 拼音索引
%
\def\pinyinindex#1#2{\index{#1@#2}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% lshort 用到的自定义环境
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% 每章最前的介绍内容环境 intro
%
\newenvironment{intro}
  {\advance\leftskip\parindent\advance\rightskip\parindent\sffamily}%
  {\par\vspace*{2ex minus 1.5ex}}

%
% 展示命令
%
\newenvironment{command}%
  {\trivlist\item\relax%
  \def\arraystretch{1.2}%
  \hskip\parindent%
  \begin{tabular}{>{\columncolor{blue!5}}l}
  }{\end{tabular}\endtrivlist}

%
% 示例环境 example
% 环境中的代码写入临时文件 lshort-zh-cn-example.aux
% 再从临时文件中读取,分别生成代码盒子和示例盒子
%
\newwrite\example@out
\newlength\savefboxrule
\newlength\savefboxsep
\edef\example@name{\jobname-example.aux}
\newenvironment{example}%
{\begingroup\@bsphack
  \immediate\openout\example@out=\example@name
  \let\do\@makeother\dospecials\catcode`\^^M\active
  \def\verbatim@processline{\immediate\write\example@out{\the\verbatim@line}}%
  \verbatim@start}%
{\immediate\closeout\example@out\@esphack\endgroup%
  \trivlist\item\relax
  \setlength{\savefboxrule}{\fboxrule}%
  \setlength{\savefboxsep}{\fboxsep}%
  \setlength{\fboxsep}{0.015\textwidth}%
  \setlength{\fboxrule}{0.4pt}%
  \fcolorbox[gray]{0}{0.95}{%
    \begin{minipage}[c]{0.45\textwidth}%
      \setlength{\fboxrule}{\savefboxrule}%
      \setlength{\fboxsep}{\savefboxsep}%
      \small\verbatiminput{\example@name}%
    \end{minipage}%
  }%
  \hfill%
  \fbox{%
    \begin{minipage}[c]{0.45\textwidth}%
      \setlength{\fboxrule}{\savefboxrule}%
      \setlength{\fboxsep}{\savefboxsep}%
      \setlength{\parskip}{1ex plus 0.4ex minus 0.2ex}%
      \normalsize\input{\example@name}%
    \end{minipage}%
  }%
  \endtrivlist
}

%
% sourcecode 浮动体
%
\belowcaptionskip\abovecaptionskip
\fvset{fontsize=\small,frame=lines}
\newfloat{sourcecode}{tbp}{los}[chapter]
\floatname{sourcecode}{源代码}
\def\sourcecodename{源代码示例列表}
\def\l@sourcecode{\@dottedtocline{1}{1.5em}{2.3em}}

\endinput