\documentclass[11pt]{book}

%\usepackage{lnote}

\usepackage{CJKutf8,CJKnumb}
%\usepackage{CJKpunct} %a homemade package

\usepackage{fancyhdr}
\usepackage{titlesec}

\usepackage{indentfirst}
\usepackage{paralist}
\usepackage{verbatim}

\usepackage[plain]{fancyref}
\usepackage[bookmarksnumbered,dvipdfmx,unicode, pdfborder=1,breaklinks,colorlinks,linkcolor=RoyalBlue3,urlcolor=blue]{hyperref}
\usepackage{makeidx}

\usepackage{mflogo,texnames}
\usepackage{textcomp}

\usepackage{amsmath,amsfonts,amsthm}

\usepackage[x11names]{xcolor} %must before tikz, x11names defines RoyalBlue3
\usepackage{graphicx}
%\usepackage{ps4pdf} %conflict with tabularx
\usepackage{pstricks,pst-plot,pst-eps}
\usepackage{subfig}
\def\pgfsysdriver{pgfsys-dvipdfmx.def} %put before tikz
\usepackage{tikz}

\usepackage{booktabs,tabularx,multirow,colortbl,longtable}

\usepackage{chapterbib}
\usepackage[sectionbib,super,square,sort&compress]{natbib}


%中文设置
\newcommand{\song}{\CJKfamily{usong}}
\newcommand{\fang}{\CJKfamily{ufang}}
\newcommand{\kai}{\CJKfamily{ukai}}
\newcommand{\hei}{\CJKfamily{uhei}}

%\AtBeginDvi{\special{pdf:tounicode GBK-EUC-UCS2}} %not necessary if use UTF8.

%行距
\renewcommand{\baselinestretch}{1.25}

%页眉页脚
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[RE]{\leftmark}
\fancyhead[LO]{\rightmark}
\fancypagestyle{plain}{%设置plain页格式
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
}

%章节
\renewcommand{\chaptername}{第\CJKnumber{\thechapter}章}
\newcommand{\sectionname}{节}
\renewcommand{\figurename}{图}
\renewcommand{\tablename}{表}
\renewcommand{\bibname}{参考文献}
\renewcommand{\contentsname}{目~录}
\renewcommand{\listfigurename}{图~目~录}
\renewcommand{\listtablename}{表~目~录}
\renewcommand{\indexname}{索~引}
\titleformat{\chapter}[block]{\center\Huge}{\chaptername}{20pt}{}

\makeindex

%空白页
\makeatletter
\def\cleardoublepage{
    \clearpage\if@twoside\ifodd\c@page\else
    \hbox{}
    \vspace*{\fill}
    \begin{center}
        看什么看，没见过空白页？
    \end{center}
    \vspace{\fill}
    \thispagestyle{empty}
    \newpage
    \if@twocolumn\hbox{}\newpage\fi\fi\fi
}
\makeatother

%Code demo
\makeatletter
\newenvironment{mycode}{
    \noindent
    \newsavebox{\mybox}
    \begin{lrbox}{\mybox}
    \begin{minipage}[c]{.945\textwidth}
    \begin{verbatim}
}{
    \end{verbatim}
    \end{minipage}
    \end{lrbox}%
    \setlength{\fboxsep}{8pt}
    \colorbox{demo@bgcolor}{\usebox{\mybox}}
    \setlength{\fboxsep}{\oldfboxsep}
}

\newenvironment{myoutput}{
    \noindent
    \begin{lrbox}{\@tempboxa}
    \begin{minipage}[c]{.945\textwidth}
}{
    \end{minipage}
    \end{lrbox}%
    \setlength{\fboxsep}{8pt}
    \fbox{\usebox{\@tempboxa}}
    \setlength{\fboxsep}{\oldfboxsep}
}
\makeatother


\definecolor{demo@bgcolor}{gray}{.8}
\let\oldfboxsep\fboxsep
\newwrite\file
\newsavebox{\mybox}

\makeatletter
\def\demo@start{
    \begingroup% Lets Keep the Changes Local
    \@bsphack
    \immediate\openout \file \jobname.exa
    \let\do\@makeother\dospecials
    \catcode`\^^M\active
    \def\verbatim@processline{
        \immediate\write\file{\the\verbatim@line}
    }
    \verbatim@start
}

\def\demo@end{\immediate\closeout\file\@esphack\endgroup}

\def\demo@code#1#2{%
    \setlength{\fboxsep}{8pt}%
    \colorbox{#1}{%
    \begin{minipage}[c]{#2}
        \setlength{\fboxsep}{\oldfboxsep}
        \small\verbatiminput{\jobname.exa}
    \end{minipage}%
    }%
}

\def\demo@out#1{%
    \setlength{\fboxsep}{8pt}%
    \fbox{%
    \begin{minipage}[c]{#1}
        \setlength{\fboxsep}{\oldfboxsep}
        \small\input{\jobname.exa}
    \end{minipage}%
    }%
}

\newenvironment{code}{
    \demo@start
}{
    \demo@end
    \list{}{\itemindent-\leftmargin}
    \item
    \demo@code{demo@bgcolor}{.95\textwidth}
    \endlist
}

\newenvironment{halfcode}{
    \demo@start
}{
    \demo@end
    \list{}{\itemindent-\leftmargin}
    \item
    \demo@code{demo@bgcolor}{.52\textwidth}
    \endlist
}

\newenvironment{out}{
    \demo@start
}{
    \demo@end
    \list{}{\itemindent-\leftmargin}
    \item
    \demo@out{.95\textwidth}
    \endlist
}

\newenvironment{demo}{
    \demo@start
}{
    \demo@end
    \list{}{\itemindent-\leftmargin}
    \item
    \makebox[\textwidth][c]{%
        \demo@code{demo@bgcolor}{.52\textwidth}%
        \hspace{10pt}%
        \demo@out{.36\textwidth}%
    }
    \endlist
}

\newenvironment{fdemo}[1]{
    \begin{lrbox}{\mybox}%
    \setlength{\fboxsep}{8pt}%
    \fbox{%
    \begin{minipage}[c]{.36\textwidth}
        \setlength{\fboxsep}{\oldfboxsep}
        \small{#1}
    \end{minipage}%
    }%
    \end{lrbox}
    \demo@start
}{
    \demo@end
    \list{}{\itemindent-\leftmargin}
    \item
    \makebox[\textwidth][c]{%
        \demo@code{demo@bgcolor}{0.52\textwidth}%
        \hspace{10pt}%
        \usebox{\mybox}%
    }
    \endlist
}
\makeatother

\def\reflect#1{{\setbox0=\hbox{#1}\rlap{\kern0.5\wd0
  \special{x:gsave}\special{x:scale -1 1}}\box0 \special{x:grestore}}}
\def\XeTeX{\leavevmode
  \setbox0=\hbox{X\lower.5ex\hbox{\kern-.15em\reflect{E}}\kern-.1667em \TeX}%
  \dp0=0pt\ht0=0pt\box0 }

%图形设置
\DeclareGraphicsExtensions{.eps,.mps,.pdf,.jpg,.png}

\usetikzlibrary{arrows,decorations,positioning}
\pgfsetxvec{\pgfpoint{10pt}{0}}
\pgfsetyvec{\pgfpoint{0}{10pt}}
\tikzset{
    box/.style={rectangle,rounded corners=6pt, 
        minimum width=40pt, minimum height=20pt, inner sep=6pt,
        draw=gray,thick,fill=lightgray},
    arrow/.style={->, shorten >=1pt, >=stealth', semithick},
    larrow/.style={->, shorten >=1pt, >=stealth', semithick},
    bloop/.style={semithick, to path={-- ++(0,-35pt) -| (\tikztotarget)}},
    rloop/.style={semithick, to path={-- ++(10pt,0) |- (\tikztotarget)}}
}

\begin{document}
\begin{CJK*}{UTF8}{usong}
\CJKindent %can only be used in the CJK environment
\CJKtilde

\frontmatter

\title{\Huge\LaTeX~ Notes v~1.20}
\author{Alpha Huang\footnote{\url{http://www.dralpha.com/}}}
\date{2008年7月26日}
\maketitle


%\setcitestyle{numbers,square}

%前言页眉
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\include{preface}
\tableofcontents

\mainmatter
%正文页眉
\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}

\include{introduction}
\include{basics}
\include{math}
\include{graphics}
\include{tables}
\include{misc}
\include{i18n}
\include{fonts}

\backmatter
\include{postcript}

%chapter*{索引}
%\printindex

\newpage

\end{CJK*}

\end{document}