% ctex-caption.def: definitions only ctexcap.sty and ctex document classes used
% vim:ft=tex

% Load caption file

\ifCTEX@caption
  \AtEndOfPackage{%
    \makeatletter
    \InputIfFileExists{ctexcap.cfg}{}{%
      \PackageError{ctex}{%
        Can't find ctexcap.cfg}{%
        The english captions are used if you continue.}}
    \makeatother}
\fi

% section format

\def\CTEX@defsecformat#1{%
  \expandafter\def\csname CTEX@pre#1\endcsname{}%
  \expandafter\def\csname CTEX@post#1\endcsname{}%
  \expandafter\def\csname CTEX@the#1\endcsname{%
    \csname the#1\endcsname}%
  \expandafter\def\csname CTEXthe#1\endcsname{%
    \csname CTEX@pre#1\endcsname%
    \csname CTEX@the#1\endcsname%
    \csname CTEX@post#1\endcsname}%
  \expandafter\def\csname CTEX@#1@format\endcsname{}%
  \expandafter\def\csname CTEX@#1@nameformat\endcsname{}%
  \expandafter\def\csname CTEX@#1@numberformat\endcsname{}%
  \expandafter\def\csname CTEX@#1@aftername\endcsname{}%
  \expandafter\def\csname CTEX@#1@titleformat\endcsname{}
  \expandafter\def\csname CTEX@#1name\endcsname{%
    \csname CTEX@#1@nameformat\endcsname%
    \csname CTEX@pre#1\endcsname%
    \begingroup%
    \csname CTEX@#1@numberformat\endcsname%
    \csname CTEX@the#1\endcsname%
    \endgroup%
    \csname CTEX@post#1\endcsname%
    \csname CTEX@#1@aftername\endcsname}%
  \expandafter\def\csname CTEX@#1@beforeskip\endcsname{}%
  \expandafter\def\csname CTEX@#1@afterskip\endcsname{}%
  \expandafter\def\csname CTEX@#1@indent\endcsname{}%
}
\CTEX@defsecformat{part}
\CTEX@defsecformat{chapter}
\CTEX@defsecformat{section}
\CTEX@defsecformat{subsection}
\CTEX@defsecformat{subsubsection}
\CTEX@defsecformat{paragraph}
\CTEX@defsecformat{subparagraph}

% Default caption names

\def\CTEX@contentsname{Contents}
\def\CTEX@listfigurename{List of Figures}
\def\CTEX@listtablename{List of Tables}
\def\CTEX@figurename{Figure}
\def\CTEX@tablename{Table}
\def\CTEX@abstractname{Abstract}
\def\CTEX@indexname{Index}
\def\CTEX@bibname{Bibliography}

\renewcommand*\contentsname{\CTEX@contentsname}
\renewcommand*\listfigurename{\CTEX@listfigurename}
\renewcommand*\listtablename{\CTEX@listtablename}
\renewcommand*\figurename{\CTEX@figurename}
\renewcommand*\tablename{\CTEX@tablename}
\@ifundefined{abstractname}{}{
  \renewcommand*\abstractname{\CTEX@abstractname}}
\renewcommand*\partname{\CTEX@thepart}
\@ifundefined{chaptername}{}{
  \renewcommand*\chaptername{\CTEX@thechapter}}
\renewcommand*\appendixname{\CTEX@appendixname}
\renewcommand*\indexname{\CTEX@indexname}

\ifCTEX@cls{article}{
  \renewcommand*\refname{\CTEX@bibname}
  }{
  \renewcommand*\bibname{\CTEX@bibname}
  }

\def\CTEX@setsecname#1[#2,#3]{%
  \expandafter\def\csname CTEX@pre#1\endcsname{#2}%
  \expandafter\def\csname CTEX@post#1\endcsname{\ignorespaces#3}}
\def\CTEX@setsecnumber#1[#2]{%
  \expandafter\def\csname CTEX@the#1\endcsname{#2}}
\def\CTEX@setsecformat#1#2[#3]{%
  \expandafter\def\csname CTEX@#1@#2\endcsname{#3}}
\def\CTEX@addsecformat#1#2[#3]{%
  \expandafter\let\expandafter\reserved@a\csname CTEX@#1@#2\endcsname%
  \expandafter\expandafter\expandafter\def\expandafter\expandafter%
    \csname CTEX@#1@#2\endcsname\expandafter{\reserved@a#3}}
\def\CTEX@defseckey#1{%
  \CTEX@subkey{#1}{name}{\CTEX@setsecname{#1}[##1]}%
  \CTEX@subkey{#1}{number}{\CTEX@setsecnumber{#1}[##1]}%
  \CTEX@subkey{#1}{format}{\CTEX@setsecformat{#1}{format}[##1]}%
  \CTEX@subkey{#1}{format+}{\CTEX@addsecformat{#1}{format}[##1]}%
  \CTEX@subkey{#1}{nameformat}{\CTEX@setsecformat{#1}{nameformat}[##1]}%
  \CTEX@subkey{#1}{nameformat+}{\CTEX@addsecformat{#1}{nameformat}[##1]}%
  \CTEX@subkey{#1}{numberformat}{\CTEX@setsecformat{#1}{numberformat}[##1]}%
  \CTEX@subkey{#1}{numberformat+}{\CTEX@addsecformat{#1}{numberformat}[##1]}%
  \CTEX@subkey{#1}{aftername}{\CTEX@setsecformat{#1}{aftername}[##1]}%
  \CTEX@subkey{#1}{aftername+}{\CTEX@addsecformat{#1}{aftername}[##1]}%
  \CTEX@subkey{#1}{titleformat}{\CTEX@setsecformat{#1}{titleformat}[##1]}%
  \CTEX@subkey{#1}{titleformat+}{\CTEX@addsecformat{#1}{titleformat}[##1]}%
  \CTEX@subkey{#1}{beforeskip}{\CTEX@setsecformat{#1}{beforeskip}[##1]}%
  \CTEX@subkey{#1}{afterskip}{\CTEX@setsecformat{#1}{afterskip}[##1]}%
  \CTEX@subkey{#1}{indent}{\CTEX@setsecformat{#1}{indent}[##1]}%
}
\CTEX@defseckey{part}
\CTEX@defseckey{chapter}
\CTEX@defseckey{section}
\CTEX@defseckey{subsection}
\CTEX@defseckey{subsubsection}
\CTEX@defseckey{paragraph}
\CTEX@defseckey{subparagraph}
\CTEX@subkey{appendix}{name}{\def\CTEX@appendixname{#1}}
\CTEX@subkey{appendix}{number}{\def\CTEX@appendixnumber{#1}}
\CTEX@key{contentsname}{\def\CTEX@contentsname{#1}}
\CTEX@key{listfigurename}{\def\CTEX@listfigurename{#1}}
\CTEX@key{listtablename}{\def\CTEX@listtablename{#1}}
\CTEX@key{figurename}{\def\CTEX@figurename{#1}}
\CTEX@key{tablename}{\def\CTEX@tablename{#1}}
\CTEX@key{abstractname}{\def\CTEX@abstractname{#1}}
\CTEX@key{indexname}{\def\CTEX@indexname{#1}}
\CTEX@key{bibname}{\def\CTEX@bibname{#1}}

% caption delimiter

\def\CTEX@caption@delimiter{: }
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1\CTEX@caption@delimiter #2}%
  \ifdim \wd\@tempboxa >\hsize
    #1\CTEX@caption@delimiter #2\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}
\CTEX@key{captiondelimiter}{\CTEX@setcaptiondelimiter{#1}}
\newcommand*\CTEX@setcaptiondelimiter[1]{%
  \def\CTEX@caption@delimiter{#1}}

% Change the parindent of verse and quotation to two Chinese characters
\renewenvironment{verse}
               {\let\\\@centercr
                \list{}{\itemsep      \z@
                        \itemindent   -2\ccwd%
                        \listparindent\itemindent
                        \rightmargin  \leftmargin
                        \advance\leftmargin 2\ccwd}%
                \item\relax}
               {\endlist}
\renewenvironment{quotation}
               {\list{}{\listparindent 2\ccwd%
                        \itemindent    \listparindent
                        \rightmargin   \leftmargin
                        \parsep        \z@ \@plus\p@}%
                \item\relax}
               {\endlist}

\endinput

