-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommons.sty
executable file
·365 lines (365 loc) · 14.4 KB
/
commons.sty
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
%%%%% --------------------------------------------------------------------------------
%%
%%%%***************************** version information ********************************
%%
%% this is the "commons.sty" package used for configure document styles
%% Copyright (C) 2014-2018 Huangrui Mo <huangrui.mo@gmail.com>
%% This is free software: you can redistribute it and/or modify it
%% under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{commons}
[2014/10/01 v0.1 commons
macros package]
%%%%% --------------------------------------------------------------------------------
%%
%%%%********************************Declare Options***********************************
%%
\newif\ifCOMMONS@myhdr \COMMONS@myhdrfalse
\DeclareOption{myhdr}{% user defined header and footer style
\COMMONS@myhdrtrue%
}
\newif\ifCOMMONS@lscape \COMMONS@lscapefalse
\DeclareOption{lscape}{% landscape layout
\COMMONS@lscapetrue%
}
\newif\ifCOMMONS@geometry \COMMONS@geometryfalse
\DeclareOption{geometry}{% enable geometry for redefining page layout
\COMMONS@geometrytrue%
}
\newif\ifCOMMONS@numbered \COMMONS@numberedtrue
\newif\ifCOMMONS@authoryear \COMMONS@authoryearfalse
\newif\ifCOMMONS@alpha \COMMONS@alphafalse
\DeclareOption{numbered}{% enable numbered citation style
\COMMONS@numberedtrue%
\COMMONS@authoryearfalse
\COMMONS@alphafalse
}
\DeclareOption{authoryear}{% enable author year citation style
\COMMONS@numberedfalse%
\COMMONS@authoryeartrue
\COMMONS@alphafalse
}
\DeclareOption{alpha}{% enable alpha citation style
\COMMONS@numberedfalse%
\COMMONS@authoryearfalse
\COMMONS@alphatrue
}
\newif\ifCOMMONS@list \COMMONS@listfalse
\DeclareOption{list}{% enable enhanced list structures
\COMMONS@listtrue%
}
\newif\ifCOMMONS@color \COMMONS@colorfalse
\DeclareOption{color}{% enable color package to use color
\COMMONS@colortrue%
}
\newif\ifCOMMONS@background \COMMONS@backgroundfalse
\DeclareOption{background}{% enable page background
\COMMONS@colortrue% need a color package
\COMMONS@backgroundtrue%
}
\newif\ifCOMMONS@tikz \COMMONS@tikzfalse
\DeclareOption{tikz}{% enable tikz package for complex diagrams
\COMMONS@colortrue% need xcolor package
\COMMONS@tikztrue%
}
\newif\ifCOMMONS@table \COMMONS@tablefalse
\DeclareOption{table}{% enable a table package for complex tables
\COMMONS@tabletrue%
}
%% end-user parameters, each option is declared by one declare option command
\DeclareOption*{% handle non-implemented options
\PackageWarning{commons}{Unknown option '\CurrentOption'}%
}
%% terminates all options processing
\ProcessOptions\relax
%%%%% --------------------------------------------------------------------------------
%%
%%%%********************************Required Packages*********************************
%%
%% Language Setting
\RequirePackage{ifpdf,ifxetex}
%% packages and settings depend on PDF mode
\ifxetex % running xelatex in PDF mode
%%%%% --------------------------------------------------------------------------------
%%
%%%%***********************************xelatex****************************************
%%
%%% >>> System Font Environment
%%
%% If compile by "xelatex", then it support system fonts.
%% Fonts and tweaks for xelatex:
\RequirePackage{fontspec}% fontspec package.
\defaultfontfeatures{Ligatures=TeX}% use tex style to support LaTeX quoting style.
%% -- Set English fonts.
%% Roman, or Serif - typefaces are named for the features at the ends of their strokes
%% determine \rmfamily, usually for main contents
%% because of \renewcommand*{\familydefault}{\rmdefault}, it's also determine \normalfont.
%% examples: Times New Roman, Garamond, Adobe Garamond Pro
%\setmainfont[BoldFont=Garamond-Bold,ItalicFont=Garamond-Italic]{Garamond}%
%% Sans serif - typefaces without strokes (without serif) to get high readability
%% determine \sffamily, usually for signage, headings that demanding high readability
%% examples: Helvetica, Gill Sans, Futura
%\setsansfont{Gill Sans MT}%
%% Monospaced - typefaces that every glyph is the same width (opposed to variable-width fonts).
%% determine \ttfamily, usually for programming, tabulated data, etc.
%% examples: Rockwell, Andale Mono, Courier, Monaco
%\setmonofont{Rockwell}%
\else
\ifpdf % running pdfTeX in PDF mode
%%%%% --------------------------------------------------------------------------------
%%
%%%%*********************************pdflatex*****************************************
%%
%%% >>> Input encoding and the font encoding
%%
%% Specify language.
%% Set Language you want to use: \RequirePackage[language]{babel}
%% You should place it soon after the \documentclass command, so that all the other
%% packages you load afterwards will know the language you are using.
%\RequirePackage[english]{babel}% language.
%% Specify input encoding.
\RequirePackage[utf8]{inputenc}% make sure your document is saved using the UTF-8 encoding.
%\RequirePackage[latin1]{inputenc}% latin encoding
%% Font encoding.
\RequirePackage[T1]{fontenc}
%% Font package.
\RequirePackage{mathptmx}
%% Options:
%% Need \RequirePackage[T1]{fontenc}:
%% - \RequirePackage{lmodern}, modern font.
%% - \RequirePackage{concrete}, text: Concrete, math: Concrete italic + Euler VM symbols.
%% - \RequirePackage{concmath}, text: Concrete, math: Concrete italic + Concmath symbols.
%% No need \RequirePackage[T1]{fontenc}:
%% Text: Helvetica, Math: Helvetica italic + Euler VM symbols:
%% - \RequirePackage{eulervm} + \RequirePackage[scaled]{helvet}
%% Text: Palatino, Math: Palatino italic + Euler VM symbols:
%% - \RequirePackage{palatino} or {mathpazo} + \RequirePackage{eulervm}
%% Text + Math: Times, not a good font for screen presentation:
%% - \RequirePackage{mathptmx}
%% Text: Bradhley Hand writing, Math: mathpazo symbols:
%% - \RequirePackage{mathpazo} % Mathpazo symbols + \renewcommand{\rmdefault}{ibh} % Bradhley Hand.
\fi
\fi
%%
%% >>> graphic packages
%%
\RequirePackage{graphicx}% graphics packages for including graphics
%\RequirePackage{caption}% caption options like:[margin=10pt,font=small,labelfont=bf]
\RequirePackage{subcaption}% subcaption package for subfigures
\RequirePackage[section]{placeins}% to prevent floats from being moved over section
%%
%% >>> Page Layout and Line Spacing
%%
\ifCOMMONS@myhdr% header and footer style
\RequirePackage{fancyhdr}% fancy headers and footers
\fi
\ifCOMMONS@lscape% landscape layout
\RequirePackage{fancyhdr}% fancy headers and footers
%% Usage: \begin{landscape} [\thispagestyle{lscape}] text... \end{landscape}
\RequirePackage{pdflscape}% landscape environment
\RequirePackage[absolute]{textpos}% rotated page number
\fi
\ifCOMMONS@geometry% enable geometry to redefine page layout
\RequirePackage{geometry}% page layout
%\RequirePackage{setspace}% line spacing
\fi
%%
%%% >>> Natural Sciences Citations and References
%%
%% if use bibtex citation, not need to use any packages!
%% if use natbib package, then:
\ifCOMMONS@numbered% enable numbered citation style
\RequirePackage[square,comma,numbers,sort&compress]{natbib}% square bracket
%\RequirePackage[square,comma,super,sort&compress]{natbib}% superscripted square bracket
\bibliographystyle{elsarticle-num-names}% numbered scheme
\fi
\ifCOMMONS@authoryear% enable author year citation style
\RequirePackage{natbib}% author year citation mode is the default
\bibliographystyle{elsarticle-harv}% author year scheme
\fi
\ifCOMMONS@alpha% enable alpha citation style
\RequirePackage[square,comma,numbers]{natbib}% square bracket
\bibliographystyle{alpha}% alpha scheme
\fi
%%
%% >>> List Structures
%%
\ifCOMMONS@list% enable enhanced list and verbatim structures
\RequirePackage{enumitem}% configure the enumerate environment
\RequirePackage{listings}% useful for Algorithm and Coding
%% Improves the verbatim environment, fixing some bugs. Moreover
%% it provides the comment environment, that lets you add multiple-line
%% comments or easily comment out big parts of the code.
\RequirePackage{verbatim}
\fi
%%
%%% >>> Color
%%
\ifCOMMONS@color% enable color package to use color
%\RequirePackage{color}%
\RequirePackage[dvipsnames]{xcolor}%
\fi
%%
%%% >>> Tables
%%
\ifCOMMONS@table% enable a table for complex tables
%% ctable package imports the array, tabularx and booktabs packages
%% all commands from those packages are available as well.
\RequirePackage{ctable}%
\fi
%%
%% >>> Math packages
%%
\RequirePackage{mathtools,amstext,amsfonts}
%%
%% >>> Tkiz
%%
%% Draw graphics directly with TeX commands
%% LaTeX/PGF/TikZ to draw procedural graphics directly with TeX commands.
%% Using TikZ in a LaTeX document requires loading the tikz package:
\ifCOMMONS@tikz% enable tikz for complex diagrams
\RequirePackage{tikz}%
%% This will automatically load the pgf package. To load further libraries use:
\usetikzlibrary{
positioning,
arrows,
calc,
trees
}%
\fi
%% Examples for libraries are "arrows", "automata", "backgrounds", "calendar",
%% "chains", "matrix", "mindmap", "patterns", "petri", "shadows", "shapes.geometric",
%% "shapes.misc", "spy", "trees".
%%
%% >>> hyperref packages
%%
%% packages and settings depend on PDF mode
\ifxetex % running xelatex in PDF mode
\RequirePackage[xetex]{hyperref}
\else
\ifpdf % running pdfTeX in PDF mode
\RequirePackage[pdftex]{hyperref}
\fi
\fi
%% Setting Hyperlinks
\hypersetup{% set hyperlinks.
%pdftitle={},% title
%pdfauthor={},% author
%pdfsubject={},% subject
%pdfkeywords={keyword1}{key2} {key3},% list of keywords, and uncomment this line if desired
%pdftoolbar=true,% show Acrobat's toolbar?
%pdfmenubar=true,% show Acrobat's menu?
pdffitwindow=false,% window fit to page when opened
pdfstartview={FitH},% fits the width of the page to the window
%pdfnewwindow=true,% links in new window
%colorlinks=true,% false: boxed links; true: colored links
%linkcolor=blue,% color of internal links
%citecolor=green,% color of links to bibliography
%filecolor=magenta,% color of file links
%urlcolor=cyan% color of external links
hidelinks% remove link color and border.
}
%% it gives LaTeX the possibility to manage links
%% within the document or to any URL when you compile in PDF.
%% Just load the package in the preamble, at the end of all the
%% other packages but prior to other settings.
%%%%% --------------------------------------------------------------------------------
%%
%%%%*****************************Configuration Command********************************
%%
%% >>> Extensions and Directories for graphics
%%
\ifxetex % running xelatex in PDF mode
\DeclareGraphicsExtensions{.pdf,.png,.jpg,.gif,.bmp,.eps}% available graphic extensions
\else
\ifpdf % running pdfTeX in PDF mode
\DeclareGraphicsExtensions{.pdf,.png,.jpg,.jpeg,.PNG,.JPG,.JPEG}%
\fi
\fi
%\graphicspath{{./Img/}}% search path for figures, no need if use scripts to compile
%%
%%% >>> Page background:
%%
\ifCOMMONS@background% enable page background
\definecolor{backgroundcolor}{RGB}{224,224,224}
\pagecolor{backgroundcolor} % page background color, require a color package.
\fi
%%
%%% >>> Layout and Margin
%%
\ifCOMMONS@geometry% enable geometry to redefine page layout
\geometry{left=1.125in,right=1.125in}% reduced margins at each side.
\fi
%%
%%% >>> Page header and footer Style
%%
%% Page styles in Latex terms refers not to page dimensions, but to the running headers
%% and footers of a document. These headers typically contain document titles, chapter
%% or section numbers/names, and page numbers.
%% configure fancy style
\ifCOMMONS@myhdr% user defined header and footer style
\pagestyle{fancy}
%% reset style of chapter and section mark to actual name without converting it to uppercase
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}
%% define different kinds of header and footer for defferent parts
\fancypagestyle{frontmatterstyle}{% header and footer style for frontmatter
\fancyhf{}% Clear header/footer
\fancyfoot[C]{\thepage}%
\renewcommand{\headrulewidth}{0pt}% No header rule
\renewcommand{\footrulewidth}{0pt}% No footer rule
}
\fancypagestyle{mainmatterstyle}{% header and footer style for mainmatter
\fancyhf{}% clear all header and footer fields
%% header configure:
\fancyhead[RE]{\small \@title}% title name in header, \@title is the default value
\fancyhead[LO]{\small \leftmark}% chapter name in header
\fancyhead[LE,RO]{\small \thepage}% page number in header
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
%% redefine \frontmatter to include the change
\let\myfrontmatter\frontmatter
\renewcommand{\frontmatter}{%
\myfrontmatter
\pagestyle{frontmatterstyle}
}
%% redefine \mainmatter to include the change
\let\mymainmatter\mainmatter
\renewcommand{\mainmatter}{%
\mymainmatter
\pagestyle{mainmatterstyle}
}
%% Some LATEX commands, like \chapter, use the \thispagestyle command to automatically switch
%% to the plain page style, thus ignoring the page style currently in effect.
%% To customize even such pages you must redefine the plain pagestyle.
%% redefine plain style:
%\fancypagestyle{plain}{%
%\fancyhf{}% remove everything
%\renewcommand{\headrulewidth}{0pt}% remove lines as well
%\renewcommand{\footrulewidth}{0pt}% remove lines as well
%}
\fi
\ifCOMMONS@lscape% configure landscape environment
\fancypagestyle{lscape}{% landscape layout style
\fancyhf{}% clear all header and footer fields
\fancyfoot[CE,CO]{% footer
%% textpos: \begin{textblock}{<blockwidth>}[0.5,0.5](<hpos>,<vpos>) text... \end{textblock}
%% origin of the absolute coordinate is the top-left corner of the page
%% [0.5,0.5] means reference point of the block is the middle
\begin{textblock}{0.1}[0.5,0.5](0.85,0.5){\rotatebox{90}{\thepage}}\end{textblock}% position the page number
}
%% set units of <blockwidth>, <hpos>, and <vpos> arguments by corresponding modules
\setlength{\TPHorizModule}{8.5in}% set to the width of page
\setlength{\TPVertModule}{11in} % set to the height of page
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
\fi
%%%%% --------------------------------------------------------------------------------
\endinput
%% End of commons.sty
%%%%% --------------------------------------------------------------------------------