% ctex-cjk-engine.def: for LaTeX engine with CJK
% vim:ft=tex

\ifCTEX@GBK
  \RequirePackage{CJK}[2003/03/28]
\else
  \RequirePackage{CJKutf8}[2003/03/28]
\fi

\ifCTEX@punct
  \RequirePackage{CJKpunct}[2009/05/06]
\fi

\AtEndOfPackage{\CJK@makeActive}

\ifCTEX@space
  \ifCTEX@GBK
    \def\CTEX@beginCJK{\begin{CJK}{GBK}{rm}}
  \else
    \def\CTEX@beginCJK{\begin{CJK}{UTF8}{rm}}
  \fi
  \def\CTEX@endCJK{\clearpage\end{CJK}}
\else
  \ifCTEX@GBK
    \def\CTEX@beginCJK{\begin{CJK*}{GBK}{rm}\CJKtilde}
  \else
    \def\CTEX@beginCJK{\begin{CJK*}{UTF8}{rm}\CJKtilde}
  \fi
  \def\CTEX@endCJK{\clearpage\end{CJK*}}
\fi

\let\CTEX@begindocumenthook\@begindocumenthook
\let\CTEX@enddocumenthook\@enddocumenthook
\def\AtBeginDocument{\g@addto@macro\CTEX@begindocumenthook}
\def\AtEndDocument{\g@addto@macro\CTEX@enddocumenthook}
\def\@begindocumenthook{\CTEX@begindocumenthook\CTEX@beginCJK}
\def\@enddocumenthook{\CTEX@endCJK\CTEX@enddocumenthook}

\input{ctex-cjk-common.def}

\providecommand*\CTEX@rm@family{}
\providecommand*\CTEX@sf@family{}
\providecommand*\CTEX@tt@family{}

\ifCTEX@nofonts
  \renewcommand*\CTEX@rm@family{gbsn}
  \renewcommand*\CTEX@sf@family{gbsn}
  \renewcommand*\CTEX@tt@family{gbsn}
\else
  \ifCTEX@winfonts
    \input{ctex-cjk-winfonts.def}
  \else\ifCTEX@adobefonts
    \input{ctex-cjk-adobefonts.def}
  \fi\fi
\fi

\let\CTEX@save@rmfamily\rmfamily
\renewcommand*\rmfamily{\CTEX@save@rmfamily\CJKfamily{\CTEX@rm@family}}
\let\CTEX@save@sffamily\sffamily
\renewcommand*\sffamily{\CTEX@save@sffamily\CJKfamily{\CTEX@sf@family}}
\let\CTEX@save@ttfamily\ttfamily
\renewcommand*\ttfamily{\CTEX@save@ttfamily\CJKfamily{\CTEX@tt@family}}
\let\CTEX@save@normalfont\normalfont
\renewcommand*\normalfont{\CTEX@save@normalfont\CJKfamily{\CTEX@rm@family}}

\endinput
