<filename>template.tex
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}

\usepackage{geometry}       %设定边界
\geometry{
    top=1in,
    inner=1in,
    outer=1in,
    bottom=1in,
    headheight=3ex,
    headsep=2ex
}

$if(fontfamily)$
\usepackage{$fontfamily$}
$else$
\usepackage{lmodern}
$endif$
$if(linestretch)$
\usepackage{setspace}
\setstretch{$linestretch$}
$endif$

\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
$if(euro)$
  \usepackage{eurosym}
$endif$
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
    \usepackage{xltxtra,xunicode}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
  \newcommand{\euro}{€}

% \usepackage[fntef]{ctexcap}
% \CTEXsetup[number={\chinese{section}},format={\Large\bfseries}]{section}
% \CTEXsetup[number={\chinese{subsection}},format={\Large\bfseries}]{subsection}

% SUPPORT for Chinese
\usepackage[boldfont,slantfont,CJKsetspaces,CJKchecksingle]{xeCJK}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\setmainfont{Consolas}             % other fonts: {Consolas} {Monaco} {Courier New}
\punctstyle{quanjiao}
\setCJKmainfont{Microsoft JhengHei}
\setmonofont{Monaco}
\setCJKmonofont{Microsoft JhengHei}
\XeTeXlinebreaklocale "zh"         % 针对中文自动换行
\XeTeXlinebreakskip = 0pt plus 1pt % 字与字之间加入0pt至1pt的间距，确保左右对齐
\linespread{1.1}\selectfont        % 行距

\newfontfamily{\zhfont}{Microsoft JhengHei}
\DeclareTextFontCommand{\textzh}{\zhfont}

\setmathfont{XITS Math}
\setmathfont[version=bold,FakeBold=3.5]{XITS Math}

% INDENT
\parindent 2em
\newenvironment{subs}
  {\adjustwidth{2em}{1pt}}
  {\endadjustwidth}
\makeatother

\setlength{\parskip}{5pt}        % 段落之间的距离
\setlength{\parindent}{2em}
% \setlength{\parindent}{0pt}
% \setlength{\parskip}{6pt plus 2pt minus 1pt}

%% CHINESE NUMBERING

\makeatletter
\def\zhdigits#1{\expandafter\@zhdigits\csname c@#1\endcsname}
\def\@zhdigits#1{\expandafter\textzh\expandafter{\expandafter\@slowzhdigits\number#1@}}
\def\zhnumber#1{\textzh{\@slowzhdigits#1@}}
\def\@slowzhdigits#1{%
  \ifx @#1% terminate
  \else
    \if0#1〇\else\if1#1一\else\if2#1二\else\if3#1三\else\if4#1四%
    \else\if5#1五\else\if6#1六\else\if7#1七\else\if8#1八\else\if9#1九%
    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\@slowzhdigits
  \fi}
\makeatother

\makeatletter
% we use \prefix@<level> only if it is defined
\renewcommand{\@seccntformat}[1]{%
  \ifcsname prefix@#1\endcsname
    \csname prefix@#1\endcsname
  \else
    \csname the#1\endcsname\quad
  \fi}
% define \prefix@section
% \newcommand\prefix@section{\zhdigits{section}、\quad }
\renewcommand{\thesection}{\zhdigits{section}、}
\renewcommand{\thesubsection}{\arabic{subsection}}
\makeatother

% for multiple authors.
\usepackage{authblk}

$if(mainfont)$
    \setmainfont{$mainfont$}
$endif$
$if(sansfont)$
    \setsansfont{$sansfont$}
$endif$
$if(monofont)$
    \setmonofont[Mapping=tex-ansi]{$monofont$}
$endif$
$if(mathfont)$
    \setmathfont(Digits,Latin,Greek){$mathfont$}
$endif$
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
$if(geometry)$
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
$endif$
$if(natbib)$
\usepackage{natbib}
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$}
$endif$
$if(biblatex)$
\usepackage{biblatex}
$if(biblio-files)$
\bibliography{$biblio-files$}
$endif$
$endif$
$if(listings)$
\usepackage{listings}
$endif$
$if(lhs)$
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
$endif$
$if(highlighting-macros)$
$highlighting-macros$
$endif$
% $if(verbatim-in-note)$
% \usepackage{fancyvrb}
% $endif$

\usepackage{fancyvrb}

%% self defined \provideenvironment
\makeatletter
\def\provideenvironment{\@star@or@long\provide@environment}
\def\provide@environment#1{%
        \@ifundefined{#1}%
                {\def\reserved@a{\newenvironment{#1}}}%
                {\def\reserved@a{\renewenvironment{dummy@environ}}}%
        \reserved@a
}
\def\dummy@environ{}
\makeatother

% for frame around code blocks.
\usepackage{framed}
\provideenvironment{Shaded}{}{}
\renewenvironment{Shaded} {\begin{framed}\normalsize} {\end{framed}}
\DefineVerbatimEnvironment{verbatim}{Verbatim}{frame=single,framerule=\FrameRule,framesep=\FrameSep,samepage=true,fontsize=\normalsize}

$if(tables)$
\usepackage{longtable,booktabs}
$endif$
$if(graphics)$
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
$endif$
\ifxetex
  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
              xetex,linktoc=all,CJKbookmarks=true]{hyperref}
\else
  \usepackage[unicode=true,linktoc=all,CJKbookmarks=true]{hyperref}
\fi
\usepackage{makeidx}
\usepackage{titlesec}
\hypersetup{breaklinks=true,
            bookmarks=true,
            pdfauthor={$author-meta$},
            pdftitle={$title-meta$},
            colorlinks=true,
            linktoc=all,
            citecolor=$if(citecolor)$$citecolor$$else$blue$endif$,
            urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,
            linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,
            pdfborder={0 0 0}}
\urlstyle{same}  % don't use monospace font for urls
$if(links-as-notes)$
% Make links footnotes instead of hotlinks:
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(strikeout)$
\usepackage[normalem]{ulem}
% avoid problems with \sout in headers with hyperref:
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
$endif$
\setlength{\emergencystretch}{3em}  % prevent overfull lines
$if(numbersections)$
\setcounter{secnumdepth}{5}
$else$
\setcounter{secnumdepth}{0}
$endif$
$if(verbatim-in-note)$
\VerbatimFootnotes % allows verbatim text in footnotes
$endif$
$if(lang)$
\ifxetex
  \usepackage{polyglossia}
  \setmainlanguage{$mainlang$}
\else
  \usepackage[$lang$]{babel}
\fi
$endif$

$if(title)$
\title{\huge $title$$if(subtitle)$\\\vspace{0.5em}{\large $subtitle$}$endif$}
$endif$

$if(author)$
\author{$for(author)$$author$$sep$ \and $endfor$}
$endif$

$if(date)$
\date{$date$}
$else$
\date{\today}
$endif$

$for(header-includes)$
$header-includes$
$endfor$

\begin{document}
$if(title)$
% {\let\newpage\relax\maketitle}
\maketitle
$endif$

\thispagestyle{empty}
\mbox{}\vfill
\begin{center}
Copyright <NAME> 2015-2016.

This work is licensed under a \href{Creative Commons Attribution-Noncommercial-No Derivative Works 3.0
Unported License}{http://creativecommons.org/licenses/by-nc-nd/3.0/}. The license text is available at:
\end{center}

\begin{center}
\url{http://creativecommons.org/licenses/by-nc-nd/3.0/}
\end{center}

\renewcommand{\contentsname}{目\qquad 录}
\phantomsection
\tableofcontents
\thispagestyle{empty}
\newpage

$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$

$for(include-before)$
$include-before$
$endfor$

$if(toc)$
{
\hypersetup{colorlinks=true,linktoc=all,linkcolor=black}
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
}
$endif$

$if(lot)$
\listoftables
$endif$
$if(lof)$
\listoffigures
$endif$

$body$

$if(natbib)$
$if(biblio-files)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$biblio-files$}

$endif$
$endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$

$endif$
$for(include-after)$
$include-after$
$endfor$

\end{document}
