% \iffalse meta-comment
%
% File: ctex-scheme.dtx
% -----------------------------------------------------------------------
%   Copyright (C) 2003--2026
%   CTEX.ORG and any individual authors listed elsewhere in this file.
% -----------------------------------------------------------------------
%   This work may be distributed and/or modified under the conditions   *
%   of the LaTeX Project Public License (LPPL), either version 1.3c of  *
%   this license or (at your option) any later version.                 *
%   The latest version of this license is in                            *
%                                                                       *
%       http://www.latex-project.org/lppl.txt                           *
%                                                                       *
%   and version 1.3c or later is part of all distributions of LaTeX     *
%   version 2008 or later.                                              *
%                                                                       *
%   This work has the LPPL maintenance status `maintained'.             *
% -----------------------------------------------------------------------
%   This work consists of the files ctex.dtx,                           *
%                                   ctex-kernel.dtx,                    *
%                                   ctex-engine.dtx,                    *
%                                   ctex-scheme.dtx,                    *
%                                   ctex-auxpkg.dtx,                    *
%                                   ctex-fontset.dtx,                   *
%                                   ctexpunct.spa,                      *
%                                   ctxdoc.cls,                         *
%                                   ctxdocstrip.tex,                    *
%                                   ctex-zhconv.lua,                    *
%                                   ctex-zhconv-index.lua,              *
%                                   ctex-zhconv-make.lua,               *
%                 the derived files ctex.ins,                           *
%                                   ctex.sty,                           *
%                                   ctexsize.sty,                       *
%                                   ctexheading.sty,                    *
%                                   ctexart.cls,                        *
%                                   ctexbook.cls,                       *
%                                   ctexrep.cls,                        *
%                                   ctexbeamer.cls,                     *
%                                   ctexcap.sty,                        *
%                                   ctexhook.sty,                       *
%                                   ctexpatch.sty,                      *
%                                   ctex-c5size.clo,                    *
%                                   ctex-cs4size.clo,                   *
%                                   ctex-heading-article.def,           *
%                                   ctex-heading-book.def,              *
%                                   ctex-heading-report.def,            *
%                                   ctex-heading-beamer.def,            *
%                                   ctexbackend.cfg,                    *
%                                   ctex-engine-pdftex.def,             *
%                                   ctex-engine-xetex.def,              *
%                                   ctex-engine-luatex.def,             *
%                                   ctex-engine-aptex.def,              *
%                                   ctex-engine-uptex.def,              *
%                                   ctex-name-utf8.cfg,                 *
%                                   ctex-name-gbk.cfg,                  *
%                                   ctex.cfg,                           *
%                                   ctexopts.cfg,                       *
%                                   ctex-scheme-plain.def,              *
%                                   ctex-scheme-plain-article.def,      *
%                                   ctex-scheme-plain-book.def,         *
%                                   ctex-scheme-plain-report.def,       *
%                                   ctex-scheme-plain-beamer.def,       *
%                                   ctex-scheme-chinese.def,            *
%                                   ctex-scheme-chinese-article.def,    *
%                                   ctex-scheme-chinese-book.def,       *
%                                   ctex-scheme-chinese-report.def,     *
%                                   ctex-scheme-chinese-beamer.def,     *
%                                   ctex-fontset-adobe.def,             *
%                                   ctex-fontset-fandol.def,            *
%                                   ctex-fontset-founder.def,           *
%                                   ctex-fontset-hanyi.def,             *
%                                   ctex-fontset-mac.def,               *
%                                   ctex-fontset-macnew.def,            *
%                                   ctex-fontset-macold.def,            *
%                                   ctex-fontset-ubuntu.def,            *
%                                   ctex-fontset-windows.def,           *
%                                   c19rm.fd,                           *
%                                   c19sf.fd,                           *
%                                   c19tt.fd,                           *
%                                   c70rm.fd,                           *
%                                   c70sf.fd,                           *
%                                   c70tt.fd,                           *
%                                   jy2zhrm.fd,                         *
%                                   jy2zhsf.fd,                         *
%                                   jy2zhtt.fd,                         *
%                                   jt2zhrm.fd,                         *
%                                   jt2zhsf.fd,                         *
%                                   jt2zhtt.fd,                         *
%                                   ctexspa.def,                        *
%                     translator-theorem-dictionary-ChineseUTF8.dict,   *
%                     translator-theorem-dictionary-ChineseGBK.dict,    *
%                                   ctex-spa-make.tex,                  *
%                                   ctex-spa-macro.tex,                 *
%                                   ctex-zhmap-adobe.tex,               *
%                                   ctex-zhmap-fandol.tex,              *
%                                   ctex-zhmap-founder.tex,             *
%                                   ctex-zhmap-hanyi.tex,               *
%                                   ctex-zhmap-mac.tex,                 *
%                                   ctex-zhmap-ubuntu.tex,              *
%                                   ctex-zhmap-windows.tex,             *
%           the documentation files ctex.pdf,                           *
%                               and README.md.                          *
% -----------------------------------------------------------------------
%                                                                       *
%   Any modification of this file should ensure that the copyright and  *
%   license information is placed in the derived files.                 *
%                                                                       *
% -----------------------------------------------------------------------
%
%<*!driver>
%<+!driver>\GetIdInfo $Id: ctex-scheme.dtx 2.6.2 2026-07-04 20:30:27 +0800 6357331c Liam <liamhuang0205@gmail.com>$
%<name&GBK>  {Caption with encoding GBK (CTEX)}
%<name&GBK>\ProvidesExplFile{ctex-name-gbk.cfg}
%<name&UTF8>  {Caption with encoding UTF-8 (CTEX)}
%<name&UTF8>\ProvidesExplFile{ctex-name-utf8.cfg}
%<config>  {Configuration file (CTEX)}
%<config>\ProvidesExplFile{\ExplFileName.cfg}
%<ctexopts>  {Option configuration file (CTEX)}
%<ctexopts>\ProvidesExplFile{ctexopts.cfg}
%<scheme&plain&generic>  {Plain scheme for generic (CTEX)}
%<scheme&plain&generic>\ProvidesExplFile{ctex-scheme-plain.def}
%<scheme&plain&article>  {Plain scheme for article (CTEX)}
%<scheme&plain&article>\ProvidesExplFile{ctex-scheme-plain-article.def}
%<scheme&plain&book>  {Plain scheme for book (CTEX)}
%<scheme&plain&book>\ProvidesExplFile{ctex-scheme-plain-book.def}
%<scheme&plain&report>  {Plain scheme for report (CTEX)}
%<scheme&plain&report>\ProvidesExplFile{ctex-scheme-plain-report.def}
%<scheme&plain&beamer>  {Plain scheme for beamer (CTEX)}
%<scheme&plain&beamer>\ProvidesExplFile{ctex-scheme-plain-beamer.def}
%<scheme&chinese&generic>  {Chinese scheme for generic (CTEX)}
%<scheme&chinese&generic>\ProvidesExplFile{ctex-scheme-chinese.def}
%<scheme&chinese&article>  {Chinese scheme for article (CTEX)}
%<scheme&chinese&article>\ProvidesExplFile{ctex-scheme-chinese-article.def}
%<scheme&chinese&book>  {Chinese scheme for book (CTEX)}
%<scheme&chinese&book>\ProvidesExplFile{ctex-scheme-chinese-book.def}
%<scheme&chinese&report>  {Chinese scheme for report (CTEX)}
%<scheme&chinese&report>\ProvidesExplFile{ctex-scheme-chinese-report.def}
%<scheme&chinese&beamer>  {Chinese scheme for beamer (CTEX)}
%<scheme&chinese&beamer>\ProvidesExplFile{ctex-scheme-chinese-beamer.def}
%<!driver>  {\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
%</!driver>
%
% \fi
%
% \begin{implementation}
%
% \paragraph*{\fbox{\file{\jobname-scheme.dtx}}}
%
%    \begin{macrocode}
%<@@=ctex>
%    \end{macrocode}
%
% \subsubsection{标题配置文件}
%
%    \begin{macrocode}
%<*name>
%    \end{macrocode}
%
%    \begin{macrocode}
\keys_set_known:nn { ctex }
  {
    contentsname   = 目录 ,
    listfigurename = 插图 ,
    listtablename  = 表格 ,
    figurename     = 图 ,
    tablename      = 表 ,
    abstractname   = 摘要 ,
    indexname      = 索引 ,
    bibname        = 参考文献 ,
    appendixname   = 附录 ,
    proofname      = 证明 ,
    algorithmname  = 算法 ,
    refname        = 参考文献 ,
    continuation   = （续） ,
    part    / name = { 第 , 部分 } ,
    chapter / name = { 第 , 章 }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
%</name>
%    \end{macrocode}
%
% \subsubsection{\texttt{ctexopts.cfg}}
%
% 这里仅为配置文件示例：使用 Windows 下的字体设置。
%    \begin{macrocode}
%<*ctexopts>
%%
%% \ctex_set:nn { option } { fontset = windows }
%</ctexopts>
%    \end{macrocode}
%
% \subsubsection{标题格式的 \opt{scheme} 定义}
%
% 下面使用 \CTeX 文档类的设置方式，\opt{plain} 模拟标准文档类直接定义或以
% \tn{@startsection} 设定的章节标题格式，\opt{chinese} 汉化的标题格式。
%
%    \begin{macrocode}
%<*scheme&(article|book|report|beamer)>
%    \end{macrocode}
%
% \changes{v2.1}{2015/05/30}{修复 \cls{ctexbook} 和 \cls{ctexrep} 类的中文
% \opt{part/number} 选项初值为空的错误。}
% \changes{v2.2}{2015/06/30}{将中文版式下的 \texttt{part} 和 \texttt{chapter}
% 标题的 \opt{nameformat} 和 \opt{titleformat} 选项的初值合并到 \opt{format} 中。}
%
%    \begin{macrocode}
\ctex_set:nn { part }
  {
    aftertitle  = \par ,
%<*article|book|report>
    hang        = false ,
%</article|book|report>
%<*plain>
    name        = \partname \space ,
%<*article|book|report>
    number      = \thepart ,
%</article|book|report>
%<*beamer>
    number      = \insertromanpartnumber ,
%</beamer>
%</plain>
%<*chinese>
    number      = \chinese { part } ,
%</chinese>
%<*article>
    beforeskip  = 4ex ,
    afterskip   = 3ex ,
%<*plain>
    format      = \raggedright ,
    nameformat  = \Large \bfseries ,
    aftername   = \par \nobreak ,
    titleformat = \huge \bfseries ,
    afterindent = false
%</plain>
%<*chinese>
    format      = \Large \bfseries \centering ,
    aftername   = \quad ,
    afterindent = true
%</chinese>
%</article>
%<*book|report>
    aftername   = \par \vskip 20 \p@ ,
    beforeskip  = 0pt \@plus 1fil ,
    afterskip   = 0pt \@plus 1fil ,
    pagestyle   = plain ,
    break       = \if@openright \cleardoublepage \else \clearpage \fi ,
%<*plain>
    format      = \centering ,
    nameformat  = \huge \bfseries ,
    titleformat = \Huge \bfseries
%</plain>
%<*chinese>
    format      = \huge \bfseries \centering
%</chinese>
%</book|report>
%<*beamer>
    format      = \centering ,
    nameformat  = \usebeamerfont { part ~ name }
                  \usebeamercolor [fg] { part ~ name } ,
    aftername   = \vskip 1em \par ,
    titleformat = \usebeamerfont { part ~ title }
%</beamer>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
%<*book|report>
\ctex_set:nn { chapter }
  {
    pagestyle   = plain ,
    aftertitle  = \par ,
    hang        = false ,
    beforeskip  = 50 \p@ ,
    afterskip   = 40 \p@ ,
    lofskip     = 10 \p@ ,
    lotskip     = 10 \p@ ,
    break       = \if@openright \cleardoublepage \else \clearpage \fi ,
%<*plain>
    name        = \chaptername \space ,
    number      = \thechapter ,
    format      = \raggedright ,
    nameformat  = \huge \bfseries ,
    aftername   = \par \nobreak \vskip 20 \p@ ,
    titleformat = \Huge \bfseries ,
    afterindent = false ,
    tocline     = \CTEXnumberline {#1} #2
%</plain>
%<*chinese>
    number      = \chinese { chapter } ,
    format      = \huge \bfseries \centering ,
    aftername   = \quad ,
    afterindent = true
%</chinese>
  }
%</book|report>
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex_set:nn { section }
  {
%<*article|book|report>
    number      = \thesection ,
    aftername   = \quad ,
    aftertitle  = \@@@@par ,
    beforeskip  = 3.5ex \@plus 1ex \@minus .2ex ,
    afterskip   = 2.3ex \@plus .2ex ,
    runin       = false ,
    break       = \addpenalty \@secpenalty ,
%<*plain>
    format      = \Large \bfseries ,
    afterindent = false
%</plain>
%<*chinese>
    format      = \Large \bfseries \centering ,
    afterindent = true
%</chinese>
%</article|book|report>
%<*beamer>
%<*plain>
    name        = \sectionname \space ,
%</plain>
    format      = \centering ,
    number      = \insertsectionnumber ,
    nameformat  = \usebeamerfont { section ~ name }
                  \usebeamercolor [fg] { section ~ name } ,
    aftername   = \vskip 1em \par ,
    titleformat = \usebeamerfont { section ~ title } ,
    aftertitle  = \par
%</beamer>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex_set:nn { subsection }
  {
%<*article|book|report>
    number      = \thesubsection ,
    format      = \large \bfseries ,
    aftername   = \quad ,
    aftertitle  = \@@@@par ,
    beforeskip  = 3.25ex \@plus 1ex \@minus .2ex ,
    afterskip   = 1.5ex  \@plus .2ex ,
    runin       = false ,
    break       = \addpenalty \@secpenalty ,
%<*plain>
    afterindent = false
%</plain>
%<*chinese>
    afterindent = true
%</chinese>
%</article|book|report>
%<*beamer>
%<*plain>
    name        = \subsectionname \space ,
    number      = \insertsubsectionnumber ,
%</plain>
%<*chinese>
    number      = \arabic { section } . \arabic { subsection } ,
%</chinese>
    format      = \centering ,
    nameformat  = \usebeamerfont { subsection ~ name }
                  \usebeamercolor [fg] { subsection ~ name } ,
    aftername   = \vskip 1em \par ,
    titleformat = \usebeamerfont { subsection ~ title } ,
    aftertitle  = \par
%</beamer>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
%<*article|book|report>
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex_set:nn { subsubsection }
  {
    number      = \thesubsubsection ,
    format      = \normalsize \bfseries ,
    aftername   = \quad ,
    aftertitle  = \@@@@par ,
    beforeskip  = 3.25ex \@plus 1ex \@minus .2ex ,
    afterskip   = 1.5ex \@plus .2ex ,
    runin       = false ,
    break       = \addpenalty \@secpenalty ,
%<*plain>
    afterindent = false
%</plain>
%<*chinese>
    afterindent = true
%</chinese>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex_set:nn { paragraph }
  {
    number      = \theparagraph ,
    format      = \normalsize \bfseries ,
    aftername   = \quad ,
    beforeskip  = 3.25ex \@plus 1ex \@minus .2ex ,
    break       = \addpenalty \@secpenalty ,
%<*plain>
    afterindent = false
%</plain>
%<*chinese>
    afterindent = true
%</chinese>
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\ctex_set:nn { subparagraph }
  {
    number      = \thesubparagraph ,
    format      = \normalsize \bfseries ,
    aftername   = \quad ,
    beforeskip  = 3.25ex \@plus 1ex \@minus .2ex ,
    break       = \addpenalty \@secpenalty ,
%<*plain>
    afterindent = false
%</plain>
%<*chinese>
    afterindent = true
%</chinese>
  }
%    \end{macrocode}
%
% 处理 \opt{sub3section} 与 \opt{sub4section} 的格式。
%    \begin{macrocode}
\int_compare:nNnTF \g_@@_section_depth_int > 2
  {
    \ctex_set:nn { paragraph }
      {
        aftertitle  = \@@@@par ,
        afterskip   = 1ex \@plus .2ex ,
        runin       = false
      }
  }
  {
    \ctex_set:nn { paragraph }
      {
        afterskip   = 1em ,
        runin       = true
      }
  }
\int_compare:nNnTF \g_@@_section_depth_int > 3
  {
    \ctex_set:nn { subparagraph }
      {
        aftertitle  = \@@@@par ,
        afterskip   = 1ex \@plus .2ex ,
        runin       = false
      }
  }
  {
    \ctex_set:nn { subparagraph }
      {
        afterskip   = 1em ,
        runin       = true
      }
  }
\int_compare:nNnTF \g_@@_section_depth_int > 2
  { \ctex_set:nn { subparagraph } { indent = \c_zero_dim } }
  { \ctex_set:nn { subparagraph } { indent = \parindent } }
%    \end{macrocode}
%
% 处理附录的格式。
%    \begin{macrocode}
\ctex_set:nn { appendix }
%<*article>
  { number      = \@Alph \c@section }
%</article>
%<*book|report>
  {
    name        = \appendixname \space ,
    number      = \@Alph \c@chapter
  }
%</book|report>
%    \end{macrocode}
%
%    \begin{macrocode}
%</article|book|report>
%    \end{macrocode}
%
%    \begin{macrocode}
%</scheme&(article|book|report|beamer)>
%    \end{macrocode}
%
% \subsection{\opt{chinese} 方案的其他设置}
%
%    \begin{macrocode}
%<*scheme&chinese>
%    \end{macrocode}
%
% \opt{chinese} 在标准文档类下的页面格式总采用 \texttt{headings}。
%    \begin{macrocode}
%<article|book|report>\pagestyle { headings }
%    \end{macrocode}
%
% 日期格式。
%    \begin{macrocode}
\ctex_set:n { today = small }
%    \end{macrocode}
%
% 若用户未设置宏包选项 \opt{autoindent}，则自动调整首行缩进。
%    \begin{macrocode}
\ctex_if_autoindent_touched:F
  { \ctex_set:n { autoindent = true } }
%    \end{macrocode}
%
% 使用标题定义时的设置。首先是命题名字汉化。\cls{beamer} 需要汉化定理名称。
%    \begin{macrocode}
%<*!generic>
\str_if_eq:onTF { \g_@@_encoding_tl } { GBK }
%<*beamer>
  {
    \uselanguage { ChineseGBK }
    \languagealias { chinese } { ChineseGBK }
    \ctex_file_input:n { ctex-name-gbk.cfg }
  }
  {
    \uselanguage { ChineseUTF8 }
    \languagealias { chinese } { ChineseUTF8 }
    \ctex_file_input:n { ctex-name-utf8.cfg }
  }
%    \end{macrocode}
% 让 \pkg{translator} 包优先查找中文翻译。
%    \begin{macrocode}
\clist_put_left:Nn \trans@languagepath { chinese }
%</beamer>
%<*!beamer>
  { \ctex_file_input:n { ctex-name-gbk.cfg } }
  { \ctex_file_input:n { ctex-name-utf8.cfg } }
%    \end{macrocode}
%
% \changes{v2.4.1}{2016/05/09}{\cls{beamer} 不调整默认字体大小。}
% 对 \cls{beamer} 以外的文档类，若用户未设置宏包选项 \opt{zihao}，则设置 \tn{normalsize}
% 为五号字。\cls{beamer} 不调整默认字体大小。
%    \begin{macrocode}
\int_compare:nNnF \g_@@_font_size_int > { -1 }
  { \int_gset:Nn \g_@@_font_size_int { 0 } }
%    \end{macrocode}
%
% \changes{v2.4.1}{2016/05/09}{\cls{beamer} 不调整默认行距。}
% 对 \cls{beamer} 以外的文档类，若用户未设置宏包选项 \opt{linespread}，则设置行
% 距初始值为 $1.3\times 1.2=1.56$ 倍字体大小。\cls{beamer} 不调整行距。
%    \begin{macrocode}
\fp_if_nan:nT { \l_@@_line_spread_fp }
  { \fp_set:Nn \l_@@_line_spread_fp { 1.3 } }
%</!beamer>
%</!generic>
%    \end{macrocode}
%
% 不使用标题定义时的通用设置，注意此处 \cs{c_@@_std_class_tl} 可能没有定义。
%    \begin{macrocode}
%<*generic>
\tl_if_eq:NnTF \c_@@_std_class_tl { beamer }
  {
    \str_if_eq:onTF { \g_@@_encoding_tl } { GBK }
      {
        \uselanguage { ChineseGBK }
        \languagealias { chinese } { ChineseGBK }
        \ctex_file_input:n { ctex-name-gbk.cfg }
      }
      {
        \uselanguage { ChineseUTF8 }
        \languagealias { chinese } { ChineseUTF8 }
        \ctex_file_input:n { ctex-name-utf8.cfg }
      }
    \clist_put_left:Nn \trans@languagepath { chinese }
  }
  {
    \str_if_eq:onTF { \g_@@_encoding_tl } { GBK }
      { \ctex_file_input:n { ctex-name-gbk.cfg } }
      { \ctex_file_input:n { ctex-name-utf8.cfg } }
    \int_compare:nNnF \g_@@_font_size_int > { -1 }
      { \int_gset:Nn \g_@@_font_size_int { 0 } }
    \fp_if_nan:nT { \l_@@_line_spread_fp }
      { \fp_set:Nn \l_@@_line_spread_fp { 1.3 } }
%    \end{macrocode}
% \changes{v2.0.2}{2015/05/16}{修复加载 \pkg{ctex} 宏包后章节标题后第一段
% 无段首缩进的问题。}
% 若 \pkg{ctex} 宏包与标准文档类及其衍生文档类联用，则将载入 \pkg{indentfirst} 宏包，
% 实现章节标题后首个段落的段首缩进。
%    \begin{macrocode}
    \tl_if_exist:NT \c_@@_std_class_tl
      { \RequirePackage { indentfirst } }
  }
%</generic>
%    \end{macrocode}
%
%    \begin{macrocode}
%</scheme&chinese>
%    \end{macrocode}
%
% \subsubsection{列表环境的缩进}
%
% \begin{macro}[int]{\verse,\quotation}
% 只在使用文档类的时候修改诗歌和引用环境的缩进。
%    \begin{macrocode}
%<*scheme&chinese&(article|book|report)>
\ctex_patch_cmd:Nnn \verse { -1.5em } { -2 \ccwd }
\ctex_patch_cmd:Nnn \verse {  1.5em } {  2 \ccwd }
\ctex_patch_cmd:Nnn \quotation { 1.5em } { 2 \ccwd }
%</scheme&chinese&(article|book|report)>
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%<@@=>
%    \end{macrocode}
%
% \end{implementation}
