%
% Definitions for typesetting Chinese documents with LaTeX2e using CJK package
%
%
%


\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{mybase}[1999/12/25 Custom definitions for CJK package]
\RequirePackage{CJK}




\RequirePackage{graphicx} \RequirePackage{ifthen}
\RequirePackage{calc}


\begin{CJK}{GBK}{st}
\end{CJK}



% Rewrite theindex environment (removing \MakeUppercase, use `multicol' )
\RequirePackage{multicol}
\renewenvironment{theindex}
                 {\chapter*{\indexname}\addcontentsline{toc}{chapter}{索引}
                  \vskip 15pt \zihao{-5}
                  \begin{multicols}{2}%
                  \let\item\@idxitem}
                {\end{multicols}}

%\renewenvironment{theindex}{\newpage
 %  \let\item\@idxitem
%  \chapter* {\indexname} \addcontentsline{toc}{chapter}{索引}%
%   \vskip 15pt
%   \begin{multicols}{2}
%   \par\bigskip}
%   {\end{multicols}}

% \renewcommand{\subitem}{\par\hspace*{0pt}}




% Change default font size and style in \caption.

% (based on article/book classes).
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
%org \sbox\@tempboxa{#1: #2}%
  \sbox\@tempboxa{\small #1: #2}%          !!!
  \ifdim \wd\@tempboxa >\hsize
%org   #1: #2\par
    {\small #1: #2\par}%                   !!!
  \else
    \global \@minipagefalse
    \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}



%=========== suppress extra inter-line spacing in \list environments
\setlength\partopsep{0pt}
\renewcommand\@listI{\leftmargin\leftmargini
            \parsep 0pt
            \topsep \parsep
            \itemsep \parsep}
\@listI
\renewcommand\@listii {\leftmargin\leftmarginii
              \labelwidth\leftmarginii
              \advance\labelwidth-\labelsep
              \parsep    \z@ \@plus\z@  \@minus\z@
              \topsep    \parsep
              \itemsep   \parsep}
\renewcommand\@listiii{\leftmargin\leftmarginiii
              \labelwidth\leftmarginiii
              \advance\labelwidth-\labelsep
              \parsep    \z@ \@plus\z@  \@minus\z@
              \topsep    \parsep
              \itemsep   \parsep}
\renewcommand\@listiv{\leftmargin\leftmarginiv
              \labelwidth\leftmarginiv
              \advance\labelwidth-\labelsep
              \parsep    \z@ \@plus\z@  \@minus\z@
              \topsep    \parsep
              \itemsep   \parsep}
\renewcommand\@listv{\leftmargin\leftmarginv
              \labelwidth\leftmarginv
              \advance\labelwidth-\labelsep
              \parsep    \z@ \@plus\z@  \@minus\z@
              \topsep    \parsep
              \itemsep   \parsep}
\renewcommand\@listvi{\leftmargin\leftmarginvi
              \labelwidth\leftmarginvi
              \advance\labelwidth-\labelsep
              \parsep    \z@ \@plus\z@  \@minus\z@
              \topsep    \parsep
              \itemsep   \parsep}

%



%

%
% Use \bfseries in the title
\let\oldtitle=\title
\def\title#1{\oldtitle{\bfseries #1}}

\renewcommand{\baselinestretch}{1.3}\normalsize


%
% Match Chinese typefaces to LaTeX typefaces
\newcommand\@matchccfont[3]{%
  \let#2#1\def#1{#2#3}
}



% Use XiHei for \sffamily
 \@matchccfont{\sffamily}{\osffamily}{\CJKfamily{xh}}

% Use SongTi for \rmfamily
\@matchccfont{\rmfamily}{\ormfamily}{\CJKfamily{st}}

% Use KaiTi for \italic shape
% \@matchccfont{\itshape}{\oitshape}{\CJKfamily{kt}}


\newcommand{\songti}{\CJKfamily{st}}
\newcommand{\kaishu}{\CJKfamily{kt}}
\newcommand{\fangsong}{\CJKfamily{fs}}
\newcommand{\heiti}{\CJKfamily{ht}}
\newcommand{\dahei}{\CJKfamily{dh}}
\newcommand{\lishu}{\CJKfamily{li}}
\newcommand{\biaosong}{\CJKfamily{sh}}
\newcommand{\xihei}{\CJKfamily{xh}}
\newcommand{\weibei}{\CJKfamily{wb}}
\newcommand{\xingkai}{\CJKfamily{xk}}
\newcommand{\libian}{\CJKfamily{lb}}
\newcommand{\xiyuan}{\CJKfamily{xy}}
\newcommand{\zhunyuan}{\CJKfamily{zy}}
\newcommand{\songhei}{\CJKfamily{sh}}

% Define \chntoday & \CHNtoday
\newcommand\chntoday{%
       \number\year\,\chnyearname\,\number\month\,\chnmonthname\,\number\day\,\chndayname}
\newcommand\CHNtoday{%
       \CJKdigits{\number\year}\chnyearname\CJKnumber{\number\month}\chnmonthname%
       \CJKnumber{\number\day}\chndayname}



%% Define CJK indentation 横排首行缩格
  \def\CJKhindent{%
  \setbox0=\hbox{\CJKchar{"0A1}{"0A1}\CJKchar{"0A1}{"0A1}}%
  \setlength{\parindent}{\wd0}}


%%% 竖排首行缩格
 \def\CJKvindent{%
  \setbox0=\hbox{\CJKchar{"0A1}{"0A1}\CJKchar{"0A1}{"0A1}}%
  \setlength{\parindent}{\wd0}}






%% Define the command \ziju[factor] to set the distance between
%% the followingChinese characters. The default value is 0
%% This command also change the indentation of following paragraphs

\newlength\CJKonespace
\newlength\CJKtwospaces
\newcommand{\ziju}[1][0]{%
\settowidth\CJKonespace{\CJKchar{"0A1}{"0A1}}%
\settowidth\CJKtwospaces{\CJKchar{"0A1}{"0A1}%
\hspace{#1\CJKonespace}\hspace{#1\CJKonespace}\CJKchar{"0A1}{"0A1}}%
\parindent=\CJKtwospaces%
\renewcommand{\CJKglue}{%
\settowidth\CJKonespace{\CJKchar{"0A1}{"0A1}}%
\hskip #1\CJKonespace plus 0.08\baselineskip}%
                        }

%% Define the command \parziju[factor]{CJK characters}
%% which change the distance between  Chinese characters in some paragraphs
%% This command also change the indentation of these paragraphs
%% The default value of factor is 0

\newcommand{\parziju}[2][0]{{%
\settowidth\CJKonespace{\CJKchar{"0A1}{"0A1}}%
\settowidth\CJKtwospaces{\CJKchar{"0A1}{"0A1}%
\hspace{#1\CJKonespace}\hspace{#1\CJKonespace}\CJKchar{"0A1}{"0A1}}%
\parindent=\CJKtwospaces%
\renewcommand{\CJKglue}{%
\settowidth\CJKonespace{\CJKchar{"0A1}{"0A1}}%
\hskip #1\CJKonespace plus 0.08\baselineskip}#2}}

%% Define the command \lineziju[factor]{CJK characters}
%% which change the distance between Chinese characters in a line
%% The default value of factor is 0

\newcommand{\lineziju}[2][0]{{%
\renewcommand{\CJKglue}{%
\settowidth\CJKonespace{\CJKchar{"0A1}{"0A1}}%
\hskip #1\CJKonespace plus 0.08\baselineskip}#2}}

%% Define the command \CJKline{CJK characters}
%% which stretch the CJK characters to fill the line

\newcommand{\CJKfill}[1]{{%
\renewcommand{\CJKglue}{\hspace{\fill}}\par\noindent #1}}

%% 定义命令 \verticle 将文字逆时针旋转90度

\newcommand{\verticle}{%
   \renewcommand{\CJKsymbol}[1]{%
      \setbox0=\hbox{\symbol{##1}}%
      \newcommand{\POS}{}%
      \ifthenelse{\lengthtest{\ht0<.39\wd0}}{\renewcommand{\POS}{c}}{\renewcommand{\POS}{r}}%
      \makebox[\wd0][\POS]{\rotatebox[origin=lB]{90}{\symbol{##1}}}%
      \ifCJK@bold@%
      \hbox to \CJKboldshift{\hss\makebox[\wd0][\POS]{%
             \rotatebox[origin=lB]{90}{\symbol{##1}}}}%
      \hbox to \CJKboldshift{\hss\makebox[\wd0][\POS]{%
             \rotatebox[origin=lB]{90}{\symbol{##1}}}}%
      \fi}
   \let\CJKpunctsymbol\CJKsymbol
}

%% 定义命令 \shupai 来竖排文字。

\newsavebox{\saverotate}%
\newcommand{\shupai}[2][\textheight]{%
\savebox{\saverotate}{\parbox[t]{#1}{\verticle #2}}%
\rotatebox[origin=lt]{-90}{\usebox{\saverotate}}}

%% 定义中式省略号

\newcommand{\CDOTS}{\mbox{$\cdots$\hbox{}$\cdots$}}

% 字体字号的定义-----------------------------------------------
%\def\CJKfontsize#1#2#3#4{\fontsize{#1}{#2 plus#3 minus #4}\selectfont}
%\newcount\CJKZihaoNo
%\newcommand\zihao[1]{
%\CJKZihaoNo=#1
%     \ifnum \CJKZihaoNo=0     \CJKfontsize{42bp}{50.4pt}{.5pt}{.3pt}
%\else\ifnum \CJKZihaoNo=-0    \CJKfontsize{36bp}{43.2pt}{.5pt}{.3pt}
%\else\ifnum \CJKZihaoNo=1     \CJKfontsize{26bp}{31.2pt}{.5pt}{.3pt}
%\else\ifnum \CJKZihaoNo=-1    \CJKfontsize{24bp}{28.8pt}{.5pt}{.3pt}
%\else\ifnum \CJKZihaoNo=2     \CJKfontsize{22bp}{26.4pt}{.5pt}{.3pt}
%\else\ifnum \CJKZihaoNo=-2    \CJKfontsize{18bp}{21.6pt}{.3pt}{.2pt}
%\else\ifnum \CJKZihaoNo=3     \CJKfontsize{16bp}{19.3pt}{.3pt}{.2pt}
%\else\ifnum \CJKZihaoNo=-3    \CJKfontsize{15bp}{18pt}{.3pt}{.2pt}
%\else\ifnum \CJKZihaoNo=4     \CJKfontsize{14bp}{16.8pt}{.3pt}{.2pt}
%\else\ifnum \CJKZihaoNo=-4    \CJKfontsize{12bp}{14.4pt}{.3pt}{.2pt}
%\else\ifnum \CJKZihaoNo=5     \CJKfontsize{10.5bp}{12.6pt}{.3pt}{.2pt}
%\else\ifnum \CJKZihaoNo=-5    \CJKfontsize{9bp}{10.8pt}{.2pt}{.1pt}
%\else\ifnum \CJKZihaoNo=6     \CJKfontsize{7.5bp}{9pt}{.2pt}{.1pt}
%\else\ifnum \CJKZihaoNo=-6    \CJKfontsize{6.5bp}{7.8pt}{.2pt}{.1pt}
%\else\ifnum \CJKZihaoNo=7     \CJKfontsize{5.5bp}{6.6pt}{.1pt}{.1pt}
%\else\ifnum \CJKZihaoNo=8     \CJKfontsize{5bp}{6pt}{.1pt}{.1pt}
%\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}

\newdimen\bp@  \bp@=1bp % 字体定义中使用 PS 磅值。 1 in = 72 bp = 72.27 pt
\def\@cjk@normaleightbp{5}    \def\@cjk@normaleightskip{6}     %八号字
\def\@cjk@normalsevenbp{5.5}  \def\@cjk@normalsevenskip{6.6}   %七号字
\def\@cjk@smallsixbp{6.5}     \def\@cjk@smallsixskip{7.8}      %小六号
\def\@cjk@normalsixbp{7.5}    \def\@cjk@normalsixskip{9}       %六号字
\def\@cjk@smallfivebp{9}      \def\@cjk@smallfiveskip{10.8}    %小五号
\def\@cjk@normalfivebp{10.5}  \def\@cjk@normalfiveskip{12.6}   %五号字
\def\@cjk@smallfourbp{12}     \def\@cjk@smallfourskip{14.4}    %小四号
\def\@cjk@normalfourbp{14}    \def\@cjk@normalfourskip{16.8}   %四号字
\def\@cjk@smallthreebp{15}    \def\@cjk@smallthreeskip{18}     %小三号
\def\@cjk@normalthreebp{16}   \def\@cjk@normalthreeskip{19.2}  %三号字
\def\@cjk@smalltwobp{18}      \def\@cjk@smalltwoskip{21.6}     %小二号
\def\@cjk@normaltwobp{22}     \def\@cjk@normaltwoskip{26.4}    %二号字
\def\@cjk@smallonebp{24}      \def\@cjk@smalloneskip{28.8}     %小一号
\def\@cjk@normalonebp{26}     \def\@cjk@normaloneskip{31.2}    %一号字
\def\@cjk@smallzerobp{36}     \def\@cjk@smallzeroskip{43.2}    %小初号
\def\@cjk@normalzerobp{42}    \def\@cjk@normalzeroskip{50.4}   %初号字
\newcount\CJK@ZihaoNo
\def\defCJKfontsize#1#2#3#4{%
         \fontsize{#1\bp@}{#2pt plus#3pt minus #4pt}\selectfont}
\def\zihao#1{\CJK@ZihaoNo=#1 %
             \ifnum #11<0
                        \ifnum \CJK@ZihaoNo=-0  \defCJKfontsize\@cjk@smallzerobp\@cjk@smallzeroskip{.5}{.3}
                   \else\ifnum \CJK@ZihaoNo=-1  \defCJKfontsize\@cjk@smallonebp\@cjk@smalloneskip{.5}{.3}
                   \else\ifnum \CJK@ZihaoNo=-2  \defCJKfontsize\@cjk@smalltwobp\@cjk@smalltwoskip{.3}{.2}
                   \else\ifnum \CJK@ZihaoNo=-3  \defCJKfontsize\@cjk@smallthreebp\@cjk@smallthreeskip{.3}{.2}
                   \else\ifnum \CJK@ZihaoNo=-4  \defCJKfontsize\@cjk@smallfourbp\@cjk@smallfourskip{.3}{.2}
                   \else\ifnum \CJK@ZihaoNo=-5  \defCJKfontsize\@cjk@smallfivebp\@cjk@smallfiveskip{.2}{.1}
                   \else\ifnum \CJK@ZihaoNo=-6  \defCJKfontsize\@cjk@smallsixbp\@cjk@smallsixskip{.2}{.1}
                   \fi\fi\fi\fi\fi\fi\fi
             \else
                        \ifnum \CJK@ZihaoNo=0   \defCJKfontsize\@cjk@normalzerobp\@cjk@normalzeroskip{.5}{.3}
                   \else\ifnum \CJK@ZihaoNo=1   \defCJKfontsize\@cjk@normalonebp\@cjk@normaloneskip{.5}{.3}
                   \else\ifnum \CJK@ZihaoNo=2   \defCJKfontsize\@cjk@normaltwobp\@cjk@normaltwoskip{.5}{.3}
                   \else\ifnum \CJK@ZihaoNo=3   \defCJKfontsize\@cjk@normalthreebp\@cjk@normalthreeskip{.3}{.2}
                   \else\ifnum \CJK@ZihaoNo=4   \defCJKfontsize\@cjk@normalfourbp\@cjk@normalfourskip{.3}{.2}
                   \else\ifnum \CJK@ZihaoNo=5   \defCJKfontsize\@cjk@normalfivebp\@cjk@normalfiveskip{.3}{.2}
                   \else\ifnum \CJK@ZihaoNo=6   \defCJKfontsize\@cjk@normalsixbp\@cjk@normalsixskip{.2}{.1}
                   \else\ifnum \CJK@ZihaoNo=7   \defCJKfontsize\@cjk@normalsevenbp\@cjk@normalsevenskip{.1}{.1}
                   \else\ifnum \CJK@ZihaoNo=8   \defCJKfontsize\@cjk@normaleightbp\@cjk@normaleightskip{.1}{.1}
                   \fi\fi\fi\fi\fi\fi\fi\fi\fi
            \fi}





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% 定义反白字命令 %%%%%%%%%%
\newcommand{\fanbai}[1]{\setlength{\fboxsep}{0.2pt}%
                        \colorbox{black}{\textcolor{white}{\bfseries #1}}}

%%%%%%%%%
\def\Lastpage{100}

\AtEndDocument{%    
\clearpage   \addtocounter{page}{-1}%
    \immediate\write\@auxout{\string\gdef\string\Lastpage{\arabic{page}}}%
  }


\def\ccwd{.9em}

\endinput
