summaryrefslogtreecommitdiff
path: root/pdf/template.tex
blob: a5e1b2a3688d5814f153b69486d074a995e7c047 (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
\documentclass[a5paper, UTF8, openright]{book}
\usepackage[absolute,overlay,showboxes]{textpos}
% \usepackage[lining]{ebgaramond}
\usepackage[CJKspace]{xeCJK}
\usepackage{tocbibind} % for toc show inside pdf

% section break, and related titlesec and hyperref loading order
% https://tex.stackexchange.com/questions/9497/start-new-page-with-each-section
% https://tex.stackexchange.com/questions/219174/issue-with-page-breaks-before-section-and-toc-hyperlinks
\usepackage{titlesec} % texlive-latex-extra package
\newcommand{\sectionbreak}{\clearpage}
\usepackage[
	%urlbordercolor = {1 1 1},
	%linkbordercolor = {1 1 1},
	%citebordercolor = {1 1 1},
	bookmarksnumbered, % add bookmark number in pdf output
	urlcolor = blue,
	colorlinks = true,
	citecolor = black,
	linkcolor = black]{hyperref}
\usepackage{graphicx}
\usepackage{xltxtra}
\usepackage{fancyhdr}
\usepackage{booktabs}
\usepackage{indentfirst}
\usepackage{framed,color}
\usepackage{footnpag}
\usepackage{listings}
\usepackage{array}
\usepackage[font=small,format=plain,labelfont=bf,up,textfont=it,up]{caption}

\usepackage[titletoc]{appendix} % this is used for \appendices
\usepackage{xltxtra} 
\usepackage{upquote}
\usepackage{changepage}

\usepackage{pdfpages}
\usepackage[bindingoffset=0.5cm, margin=1.5cm, includeheadfoot]{geometry}

% To support tables so required tabulary package
\usepackage{longtable,tabulary}

\definecolor{colorchapter}{RGB}{0,0,0}     % All black 
\definecolor{colorsection}{RGB}{0,0,0}     
\definecolor{colorsubsection}{RGB}{0,0,0} 
\definecolor{colorheader}{RGB}{0,0,0,} 

\definecolor{lightgray}{rgb}{.9,.9,.9}
\definecolor{darkgray}{rgb}{.3,.3,.3}
\definecolor{purple}{rgb}{0.65, 0.12, 0.82}

\definecolor{editorGray}{rgb}{0.95, 0.95, 0.95}
\definecolor{editorOcher}{rgb}{1, 0.5, 0} % #FF7F00 -> rgb(239, 169, 0)
\definecolor{editorGreen}{rgb}{0, 0.4, 0.1} % #007C00 -> rgb(0, 150, 25)

% for pandoc
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}

\lstset{
%language=C++,
basicstyle=\small\ttfamily,
numbers=left,
numbersep=5pt,
xleftmargin=20pt,
frame=tb,
framexleftmargin=20pt
}



\titleformat{\section}
{\color{colorsection}\normalfont\Large\bfseries}
{\color{colorsection}\thesection}{1em}{}
\titleformat{\subsection}
{\color{colorsubsection}\normalfont\large\bfseries}
{\color{colorsubsection}\thesubsection}{1em}{}

\definecolor{shadecolor}{gray}{0.90}

% 修改字体,粗体为 Noto Sans CJK,普通文字 FandolSong 宋体(GPLv3) 
%    字体选择: AR PL UMing 文鼎PL细上海宋 - 会出现问号在中间的错误
%               AR PL SungtiL GB 文鼎PL简报宋 - 英文字体不好看
%               Adobe Song Std L Adobe宋体 - item的·号无法显示 
%               Hiragino Sans - 字体很完美,但item的·不能显示!
%               WenQuanYi Micro Hei 文泉驿微米黑 - 没有对应的粗体字体
%               Source Sans Han S (Noto Sans CJK)  思源黑体 - 不能用有错误
%                jjgod 给 xdvipdfmx 写了补丁,会被包含在 TeX Live 2015。
%                 讨论:http://tug.org/pipermail/xetex/2014-July/025385.html 起
%                 补丁:https://gist.github.com/jjgod/c1194a9b371848aaa746
%                       https://gist.github.com/jjgod/cf39032b839bb3542107

% 设置英文字体
\setmainfont
    [ Numbers        = {Proportional,Lining},
      UprightFont    = *-Regular,
      ItalicFont     = *-Italic,
      BoldFont       = *-Bold,
      BoldItalicFont = *-Italic,
    ]
    {Liberation Serif}

% 设置中文字体
\setCJKmainfont
    [
      %BoldFont   = FandolSong-Bold,
      BoldFont = Noto Sans CJK SC, % uncomment for release build
      ItalicFont = FandolKai,
      %ItalicFont = AR PL KaitiM GB,
    ]
    %{AR PL SungtiL GB}
    {FandolSong}

\setCJKsansfont{Noto Sans CJK SC} 
%\setCJKsansfont{WenQuanYi Micro Hei}
%\setCJKmonofont{WenQuanYi Micro Hei Mono} 
\setCJKmonofont{Noto Sans Mono CJK SC} % uncomment for release build

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 使用 DejaVu Sans 显示 ⚠ ☢ ☠ ✔ 这四个 dingbats 字符
% http://tex.stackexchange.com/questions/23049/font-substitution-with-xelatex

\newcommand\la[1]{{#1}}
\newfontfamily{\DingbatSubstFont}{DejaVu Sans}
\newfontfamily{\ar}[Script=Arabic]{Noto Naskh Arabic}
%\newfontfamily{\ar}{DejaVu Sans}
\newfontfamily{\bg}{Noto Sans CJK SC}
\newfontfamily{\bn}{Noto Sans Bengali}
%\newfontfamily{\fa}{Noto Kufi Arabic}
\newfontfamily{\fa}{DejaVu Sans}
\newfontfamily{\he}{Noto Sans Hebrew}
\newfontfamily{\hi}{Noto Sans Devanagari}
\newfontfamily{\hy}{Noto Sans Armenian}
\newCJKfontfamily{\ja}{Noto Sans CJK JP}
\newfontfamily{\ka}{Noto Sans Georgian}
\newCJKfontfamily{\ko}{Noto Sans CJK KR}
%\newcommand\ko[0]{}
\newfontfamily{\ml}{Noto Sans Malayalam}
\newfontfamily{\si}{Noto Sans Sinhala}
\newfontfamily{\ta}{Noto Sans Tamil}
\newfontfamily{\th}{Noto Sans Thai}
\newfontfamily{\ur}[Script=Arabic,Language=Urdu]{Noto Nastaliq Urdu}
\newCJKfontfamily{\zhtw}{Noto Sans CJK TC}

\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\DingbatSubst
\XeTeXcharclass"26A0=\DingbatSubst	% ⚠
\XeTeXcharclass"2622=\DingbatSubst	% ☢
\XeTeXcharclass"2620=\DingbatSubst	% ☠
\XeTeXcharclass"2714=\DingbatSubst	% ✔
\XeTeXinterchartoks 0 \DingbatSubst = {\begingroup\DingbatSubstFont}
\XeTeXinterchartoks 255 \DingbatSubst = {\begingroup\DingbatSubstFont}
\XeTeXinterchartoks \DingbatSubst 0 = {\endgroup}
\XeTeXinterchartoks \DingbatSubst 255 = {\endgroup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\XeTeXlinebreaklocale{zh}
\XeTeXlinebreakskip=0em plus 0.1em minus 0.01em
\XeTeXlinebreakpenalty=0

\settowidth{\parindent}{文字}
\setcounter{footnote}{1}

\title{\huge{\textbf{自由软件,自由社会}}\\
\large{理查德·斯托曼选集(第三版)}}

\makeatletter
\let\savedauthor=\@author
\let\savedtitle=\@title
\def\imgwidth{.6\linewidth}
\def\maxwidth{\ifdim\Gin@nat@width>\imgwidth\imgwidth
\else\Gin@nat@width\fi}
\makeatother

\title{{\savedtitle}}

\author{\textbf{[美] Richard M. Stallman 著}\\
       \textbf{北京 GNU/Linux 用户组\ 译}\thanks{本书基于 GNU 自由文档协议 1.3 版(GNU Free Documentation License 1.3)授权发布,可自由复制和分发,和/或基于 GNU 自由文档协议 1.3 版或自由软件基金会发布的更高版本,做出修改。本书使用 Markdown 书写,源码地址:\url{https://github.com/beijinglug/fsfs-zh/}。}}

\def\w3cdtfymd{\the\year 年 \ifnum\month<10 0\fi\the\month 月}
\date{\w3cdtfymd}

\newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}
\let\PBS=\PreserveBackslash

\fancypagestyle{plain}{\fancyhf{}\fancyfoot{}} % make sure no page number in page of first chapter

\pagestyle{plain}


\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\newcounter{img}[chapter]
\renewcommand{\theimg}{\thechapter.\arabic{img}}
\newcommand{\img}[1]{\begin{figure}[h!]
	\refstepcounter{img}
	\label{img:\theimg}
	\centering\includegraphics[width=\maxwidth]{figures/\theimg.png}
	\caption{#1}
\end{figure}}

% below for code syntax highlight
\usepackage{fancyvrb}
\usepackage{bigfoot}
%\DefineShortVerb[commandchars=\\\{\}]{\|}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\},frame=leftline,fontsize=\small}
% Add ',fontsize=\small' for more characters per line
\newenvironment{Shaded}{}{}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}}
\newcommand{\ImportTok}[1]{{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}}
\newcommand{\BuiltInTok}[1]{{#1}}
\newcommand{\ExtensionTok}[1]{{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}}
\newcommand{\RegionMarkerTok}[1]{{#1}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\NormalTok}[1]{{#1}}
% end of code syntax highlight

\newcounter{tab}[chapter]
\renewcommand{\thetab}{\thechapter.\arabic{tab}}

\newcommand{\prechap}{第}
\newcommand{\postchap}{部分}
\newcommand{\presect}{}
\newcommand{\postsect}{}
\renewcommand{\chaptermark}[1]{\markboth{\textbf{\prechap \thechapter \postchap}\hspace*{1ex}#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\textbf{\presect \thesection \postsect}\hspace*{1ex}#1}}
\newcommand{\chap}[1]{\newpage\thispagestyle{empty}\chapter{#1}\label{chap:\thechapter}}
\newcommand{\chapref}[1]{\hyperref[chap:#1]{\prechap #1\postchap}}
\newcommand{\imgref}[1]{\hyperref[img:#1]{图 #1}}
\newcommand{\tabref}[1]{\hyperref[tab:#1]{表 #1}}
\newcommand{\e}[1]{$ \times 10^{#1}$}
\renewcommand{\contentsname}{目录}
\renewcommand{\figurename}{图 }
\renewcommand{\tablename}{表 }
\renewcommand{\appendixname}{附录 }

% chapter 
\makeatletter
\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \color{colorchapter}\normalfont\huge\bfseries\prechap{ }\thechapter{ }\postchap
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \color{colorchapter}\normalfont\Huge\bfseries #1\par\nobreak
    \vskip 40\p@
  }}  
 
% this is for non-normal chapter like Acknownledgement, Preface, Contents  
\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \color{colorchapter}\normalfont\huge\bfseries \thechapter{ }
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \color{colorchapter}\normalfont\Huge\bfseries #1\par\nobreak
    \vskip 40\p@
  }}  
\makeatother

\linespread{1.3}

\begin{document}
%\includepdf[noautoscale]{img/cover}
\maketitle

\begin{quote}
\noindent
Copyright \copyright{} 2016 Beijing GNU/Linux User Group <https://beijinglug.club>.

\noindent
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.

\noindent
A copy of the license is included in the section entitled ``GNU Free Documentation License''.
\end{quote}

\thispagestyle{empty}
\setcounter{tocdepth}{1}

\frontmatter
% preface
\input{preface}
\tableofcontents\newpage\thispagestyle{empty}

% customize header & footer

\fancyhf{}
\fancyhead[LE]{\color{colorheader}\quad\small\textbf\thepage\quad\quad\small\leftmark}
\fancyhead[RO]{\color{colorheader}\small\rightmark\quad\quad\small\textbf\thepage\quad}
\fancyfoot[LE,RO]{\small\textbf\thepage} % page number

\renewcommand{\headrulewidth}{0.4pt}  % add one line
\pagestyle{fancy}

\mainmatter
%chapters
\input{chapters}
\appendices
\renewcommand{\prechap}{\appendixname}
\renewcommand{\postchap}{}
%appendix
\input{appendix}
\end{document}