%%
%% This is file `easybase.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% easybook.dtx  (with options: `package')
%% Copyright (C) 2021 by Qu Yi <quee123@foxmail.com>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the CC-BY 4.0 License.
%% The latest version of this license is in
%%   https://creativecommons.org/licenses/by/4.0/legalcode
\NeedsTeXFormat{LaTeX2e}[2020/10/01]
\RequirePackage{l3keys2e,etoolbox}
\ProvidesExplPackage{easybase}{2021/08/11}{1.28L}
  {Typeset Chinese theses or books}

\cs_generate_variant:Nn \dim_add:Nn { NV,Nv }
\cs_generate_variant:Nn \dim_set:Nn { NV }
\cs_generate_variant:Nn \dim_sign:n { V }
\cs_generate_variant:Nn \int_to_arabic:n { v }
\cs_generate_variant:Nn \prop_set_from_keyval:Nn { NV }
\cs_generate_variant:Nn \skip_set:Nn { NV }
\cs_generate_variant:Nn \seq_set_from_clist:Nn { No }
\cs_generate_variant:Nn \ctex_define:nn { nx }
\cs_generate_variant:Nn \eb_put_hyperref:n { x }
\cs_generate_variant:Nn \eb_at_begin_environment:nn { on }

\cs_new_protected:Npn \ctex_define:nn #1
  { \keys_define:nn { ctex/#1 } }
\cs_new_protected:Npn \eb_clist_map_inline:nn #1#2
  {
    \seq_set_from_clist:Nn \l_tmpa_seq {#1}
    \seq_map_inline:Nn \l_tmpa_seq {#2}
  }
\cs_new_protected:Npn \eb_clist_map_function:nN #1#2
  {
    \seq_set_from_clist:Nn \l_tmpb_seq {#1}
    \seq_map_function:NN \l_tmpb_seq #2
  }
\cs_new_protected:Npn \eb_char_patch_cmd:nnn #1#2#3
  {
    \ExplSyntaxOn\makeatletter
    \eb_clist_map_inline:nn {#1}
      {
        \ctex_patch_cmd_once:NnnnTF ##1 { } {#2} {#3}
          { } { \ctex_patch_failure:N ##1 }
      }
    \ExplSyntaxOff\makeatother
  }
\cs_new_protected:Npn \eb_at_end_patch_cmd:nnn #1#2#3
  {
    \eb_at_end_preamble:n
      { \eb_char_patch_cmd:nnn {#1} {#2} {#3} }
  }
\cs_new_protected:Npn \eb_preto_cmd:Nn #1#2
  {
    \ctex_preto_cmd:NnnTF #1 { } {#2}
      { } { \ctex_patch_failure:N #1 }
  }
\cs_new_protected:Npn \eb_appto_cmd:Nn #1#2
  {
    \ctex_appto_cmd:NnnTF #1 { } {#2}
      { } { \ctex_patch_failure:N #1 }
  }
\cs_new_protected:Npn \eb_at_begin_environment:nn #1#2
  {
    \eb_clist_map_inline:nn {#1}
      { \AtBeginEnvironment{##1}{#2} }
  }
\cs_new_protected:Npn \eb_match_load_package:n #1
  {
    \tl_if_in:nnTF {#1} { [ }
      {
        \seq_set_split:Nnn \l_tmpa_seq { [ } {#1}
        \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl
        \seq_pop_right:NN \l_tmpa_seq \l_tmpb_tl
        \IfFileExists{\l_tmpa_tl.sty}
          {
            \exp_last_unbraced:Nx \RequirePackage
              { [\l_tmpb_tl }{\l_tmpa_tl}
          }{}
      }
      { \IfFileExists{#1.sty}{\RequirePackage{#1}}{} }
  }
\cs_new_protected:Npn \eb_if_package_reload:nF #1#2
  {
    \@ifpackageloaded{#1}
      {\msg_warning:nnn { easybase } { package-reload } {#1}}
      {#2\disable@package@load{#1}{}}
  }
\msg_new:nnn { easybase } { package-reload }
  {
    The~macro~package~#1~has~been~reloaded. \\
    Please~pass~the~arguments~by \\
    the~\string\PassOptionsToPackage{\#1}{#1}\space~command.
  }
\cs_set_eq:NN \eb@usepackage@save \usepackage
\RenewDocumentCommand{\usepackage}{O{}m}
  {
    \PassOptionsToPackage{#1}{#2}
    \eb_clist_map_inline:nn {#2}
      {
        \eb_if_package_reload:nF {##1}
          { \eb@usepackage@save{##1} }
      }
  }
\NewDocumentCommand{\LoadPackage}{O{}m}
  {
    \seq_set_split:Nnn \l_tmpb_seq { + } {#2}
    \int_compare:nNnT { \seq_count:N \l_tmpb_seq } = { 1 }
      { \PassOptionsToPackage{#1}{#2} }
    \seq_map_function:NN
    \l_tmpb_seq \eb_match_load_package:n
  }
\cs_new_protected:Npn \eb_at_end_preamble:n
  { \BeforeBeginEnvironment{document} }
\cs_gset_eq:NN \PackageWarning \PackageInfo

\bool_if_exist:NF \l__eb_class_book_bool
  { \bool_set_true:N \l__eb_class_book_bool }
\bool_if_exist:NF \l__eb_compile_draft_bool
  { \bool_set_false:N \l__eb_compile_draft_bool }
\clist_new:N \g__eb_ctex_options_clist

\keys_define:nn { easybase }
  {
    draft .code:n         = \bool_set_true:N \l__eb_compile_draft_bool,
    floatpage .bool_set:N = \l__eb_float_page_bool,
    floatpage .default:n  = true,
    floatpage .initial:n  = false,

    paper .choice:,
    paper .value_required:n = true,
    paper/unknown .code:n   = \PassOptionsToPackage{#1}{geometry},
    paper .initial:n        = a4paper,

    class .choice:,
    class .value_required:n = true,
    class/book .code:n      = { },
    class/article .code:n   =
      {
        \bool_set_false:N \l__eb_class_book_bool
        \boolfalse{@twoside}
        \boolfalse{@mparswitch}
      },
    class .initial:n        = book,
    book .meta:n            = { class = book },
    article .meta:n         = { class = article },

    unknown .code:n         =
      { \clist_gput_right:NV \g__eb_ctex_options_clist \CurrentOption }
  }

\clist_map_inline:nn
  {
    { protrusion = false } { microtype },
    { list = off } { bicaption },
    { many } { tcolorbox },
    { upint } { newtxmath },
    { svgnames } { xcolor }
  }
  { \PassOptionsToPackage #1 }
\ProcessKeysOptions{easybase}
\PassOptionsToPackage{\g__eb_ctex_options_clist}{ctex}
\@ifclassloaded{ctexbook}{}
  {
    \@ifclassloaded{ctexart}{}
      {
        \@ifclassloaded{ctexrep}{}
          {\RequirePackage[heading]{ctex}}
      }
  }

\bool_new:N \l__eb_toc_multi_column_bool
\bool_new:N \l__eb_mark_uppercase_bool
\bool_new:N \l__eb_chap_counter_withpart_bool
\tl_new:N   \l__eb_foot_counter_parent_choice_tl

\eb_clist_map_inline:nn
  {
    style,subfont,spread,
    refset,bibset,thmset,
    geoset,hdrset,tocset
  }
  {
    \ctex_define:n { #1 .meta:nn = { ctex/#1 } {##1} }
    \cs_new:cpn {#1} ##1 { \ctex_set:nn {#1} {##1} }
  }
\keys_define:nn { } { ctex/link .inherit:n = ctex/refset }
\ctex_define:n { link .meta:nn = { ctex/link } {#1} }
\cs_set_eq:NN \link \refset
\eb_clist_map_inline:nn
  { style,subfont,spread,bibset,thmset,hdrset,tocset }
  {
    \msg_new:nnn { easybase } { ignore-#1 }
      {
        ##1~is~an~unknown~option~of~#1. \\
        Please~check~the~user~manual~for~the~supported~options.
      }
  }
\cs_new:Npn \eb_msg_unknown_option:n #1
  {
    \msg_warning:nnx
      { easybase } { ignore-#1 } { \l_keys_key_str }
  }
\cs_if_exist:NF \chapter
  {
    \newcounter{chapter}
    \bool_set_false:N \l__eb_class_book_bool
    \ctex_define:n { chapter/tocline .code:n = { } }
  }
\bool_if:NF \l__eb_class_book_bool
  {
    \cs_undefine:N \chapter
    \ctex_after_end_preamble:n
      {
        \NewDocumentCommand{\chapter}{som}
          {\msg_error:nn { easybase } { no-chapter }}
      }
  }
\msg_new:nnn { easybase } { no-chapter }
  {
    Your~document~class~is~in~article~mode. \\
    The~\string\chapter\space~command~will~not~be~used.
  }
\ctex_define:nn { style }
  {
    multoc .bool_set:N    = \l__eb_toc_multi_column_bool,
    multoc .default:n     = true,
    withpart .bool_set:N  = \l__eb_chap_counter_withpart_bool,
    withpart .default:n   = true,
    withpart .initial:n   = false,
    rulewidth .dim_set:N  = \l__eb_rule_width_dim,
    rulewidth .initial:n  = 0.75pt,
    uppercase .bool_set:N = \l__eb_mark_uppercase_bool,
    uppercase .default:n  = true,
    uppercase .initial:n  = true,
    figurepath .tl_set:N  = \l_eb_graphics_path_tl
  }

\LoadPackage
  {
    spbmark[ctex]+
    ulem[normalem]+
    enumitem[shortlabels,inline]+
    chemformula+siunitx+pifont+
    amsthm+thmtools+
    geometry+marginnote+
    pdfpages+multicol+
    fancyhdr+titletoc+caption+
    tabularray+
    setspace+
    listings
  }
\cs_new_protected:Npn \eb_package_date_check:nn #1#2
  {
    \IfPackageAtLeastTF{#1}{#2}
      {}{\msg_warning:nnn { easybase } { package-old } {#1}}
  }
\msg_new:nnn { easybase } { package-old }
  {
    Package~#1~has~been~out~of~date. \\
    Some~problems~or~errors~may~occur \\
    if~you~continue~compiling. \\\\
    Please~update~your~macro~package~from~CTAN.
  }
\clist_map_inline:nn
  {
    { expl3 } { 2020/10/27 },
    { xparse } { 2020/10/27 },
    { l3keys2e } { 2020/10/27 },
    { thmtools } { 2020/08/01 },
    { caption } { 2020/08/24 },
    { fancyhdr } { 2021/01/28 },
    { siunitx } { 2021/06/22 },
    { tabularray } { 2021/07/01 },
    { spbmark } { 2021/06/30 }
  }
  { \eb_package_date_check:nn #1 }

\includepdfset{fitpaper = true}
\geometry
  {
    vmargin         = 2.54cm,
    hmargin         = 3.17cm,
    columnsep       = 2em,
    headheight      = 2.04cm,
    headsep         = 0.5cm,
    footskip        = 0.79cm,
    footnotesep     = 0.5cm,
    marginparsep    = 8pt,
    marginparwidth  = 2.54cm
  }
\clist_new:N \g__eb_geometry_clist
\ctex_define:nn { geoset }
  {
    headruleskip .tl_set:N  = \headruleskip,
    headruleskip .initial:n = 1.5pt,
    footruleskip .tl_set:N  = \footruleskip,
    unknown .code:n         =
      {
        \clist_gput_right:Nx \g__eb_geometry_clist
          {
            \l_keys_key_str
            \tl_if_empty:NF \l_keys_value_tl { = {#1} }
          }
      }
  }

\cs_new_protected:Npn \blankpagestyle #1
  { \tl_set:Nn \l__eb_blank_pagestyle_tl {#1} }
\blankpagestyle{empty}
\RenewDocumentCommand{\cleardoublepage}
  {O{\l__eb_blank_pagestyle_tl}}
  {
    \clearpage
    \ifbool{@twoside}
      {
        \int_if_odd:nF { \c@page }
          { \hbox:n { }\thispagestyle{#1}\clearpage }
      }{}
  }
\DeclareDocumentCommand{\frontmatter}{sO{Roman}}
  {
    \IfBooleanTF{#1}{\clearpage}{\cleardoublepage}
    \boolfalse{@mainmatter}
    \pagenumbering{#2}
  }
\DeclareDocumentCommand{\mainmatter}{s}
  {
    \IfBooleanTF{#1}{\clearpage}{\cleardoublepage}
    \booltrue{@mainmatter}
    \pagenumbering{arabic}
  }
\eb_clist_map_inline:nn
  { chapter,section,subsection }
  {
    \exp_args:Nc \NewDocumentCommand { eb@mark@#1@label@layout }
      {O{\use:c { CTEXthe#1 }}m}
      {\tl_set:cn { eb@mark@#1@label } {##1##2}}
    \cs_new:cpn { eb_mark_#1_name_parse:n } ##1
      {
        \tl_if_in:nnTF {##1} { [ }
          { \use:c { eb@mark@#1@label@layout }##1 }
          { \use:c { eb@mark@#1@label@layout }{##1} }
      }
  }
\cs_gset_eq:NN \easyhead \fancyhead
\cs_gset_eq:NN \easyfoot \fancyfoot
\NewDocumentCommand{\markrule}
  {O{\textwidth}D(){ctex@frame}m>{\SplitArgument{1}{!}}O{}}
  {\eb_draw_markrule:nnnnn {#1} {#2} {#3} #4}
\cs_new_protected:Npn \eb_draw_markrule:nnnnn #1#2#3#4#5
  {
    \group_begin:
    \tl_if_empty:nF {#4} { \vspace*{#4} }
    \color{#2}\hrule\@width #1\@height #3
    \tl_if_novalue:nF {#5} { \vspace*{#5} }
    \group_end:
  }
\ctex_define:nn { hdrset }
  {
    head-foot .tl_set:N   = \l__eb_fancyhf_content_tl,
    head-foot .initial:n  =
      {
        \ifbool{@twoside}
          {
            \easyhead[EC]{\color{ctex@frame}\kaishu\leftmark}
            \easyhead[OC]{\color{ctex@frame}\kaishu\rightmark}
            \easyhead[EL,OR]{\color{ctex@frame}\thepage}
          }{
            \easyhead[L]{\color{ctex@frame}\kaishu\leftmark}
            \easyhead[R]{\color{ctex@frame}\thepage}
          }
      },

    chap-mark .cs_set:Np    = \eb_fancyhf_chapter_mark:n #1,
    chap-mark .initial:n    =
      { \CTEXifname{\eb@mark@chapter@label}{}#1 },
    sec-mark .cs_set:Np     = \eb_fancyhf_section_mark:n #1,
    sec-mark .initial:n     =
      { \CTEXifname{\eb@mark@section@label}{}#1 },
    subsec-mark .cs_set:Np  = \eb_fancyhf_subsection_mark:n #1,
    subsec-mark .initial:n  =
      { \CTEXifname{\eb@mark@subsection@label}{}#1 },
    chap-label .code:n      = \eb_mark_chapter_name_parse:n {#1},
    chap-label .initial:n   = \hspace{1em},
    sec-label .code:n       = \eb_mark_section_name_parse:n {#1},
    sec-label .initial:n    = \hspace{0.5em},
    subsec-label .code:n    = \eb_mark_subsection_name_parse:n {#1},
    subsec-label .initial:n = \hspace{0.5em},

    headrule .tl_gset:N     = \headrule,
    headrule .initial:n     = \markrule{\l__eb_rule_width_dim},
    footrule .tl_gset:N     = \footrule,
    footrule .initial:n     = { },
    footnoterule .tl_gset:N = \footnoterule,
    footnoterule .initial:n =
      { \markrule[0.35\textwidth]{\l__eb_rule_width_dim}[!2.6pt] }
  }

\cs_set_eq:NN \eb_mark_uppercase:n \text_uppercase:n
\cs_set_eq:NN \eb_mark_nouppercase:n \text_titlecase_first:n
\cs_new:Npn \eb_mark_if_uppercase:nn #1#2
  {
    \bool_if:NTF \l__eb_mark_uppercase_bool
      { \eb_mark_uppercase:n }
      { \eb_mark_nouppercase:n }
      { \use:c { eb_fancyhf_#1_mark:n } {#2} }
  }
\cs_new:Npn \eb@level@markdouble #1#2
  {
    \markboth
      {\eb_mark_if_uppercase:nn {#1} {#2}}
      {\ifbool{@twoside}{\eb_mark_if_uppercase:nn {#1} {#2}}{}}
  }
\cs_new:Npn \eb@level@markright #1#2
  { \markright{\eb_mark_if_uppercase:nn {#1} {#2}} }
\cs_new:Npn \eb@level@section@mark #1
  {
    \bool_if:NTF \l__eb_class_book_bool
      { \eb@level@markright{section}{#1} }
      { \eb@level@markdouble{section}{#1} }
  }
\cs_new:Npn \eb@level@subsection@mark #1
  {
    \bool_if:NF \l__eb_class_book_bool
      { \eb@level@markright{subsection}{#1} }
  }
\ctex_at_end_preamble:n
  {
    \exp_args:NV \geometry \g__eb_geometry_clist
    \fancyhf{}
    \tl_use:N \l__eb_fancyhf_content_tl
    \cs_gset_eq:NN \ps@plain \ps@empty
    \pagestyle{fancy}
    \cs_gset:Npn \chaptermark #1 { \eb@level@markdouble{chapter}{#1} }
    \cs_gset_eq:NN \sectionmark \eb@level@section@mark
    \cs_gset_eq:NN \subsectionmark \eb@level@subsection@mark
    \bool_if:NT \l__eb_compile_draft_bool
      {
        \easyfoot[C]{\color{SlateGray}\sffamily\today}
        \geometry{showframe}
      }
    \tl_if_empty:NF \l_eb_graphics_path_tl
      { \exp_args:NV \graphicspath \l_eb_graphics_path_tl }
    \cs_if_exist:NF \kaishu { \cs_gset_eq:NN \kaishu \itshape }
  }

\ctex_define:nn { style }
  {
    footwith .choices:nn        =
      { part,page,chapter }
      { \tl_set:Nn \l__eb_foot_counter_parent_choice_tl {#1} },
    footwith .value_required:n  = true,
    footwith .initial:n         = chapter
  }
\NewDocumentCommand{\eb_assign_fnmark_code:n}
  {>{\SplitArgument{1}{,}}m}
  {\eb_assign_fnmark_code_pos:nn #1}
\cs_new_protected:Npn \eb_assign_fnmark_code_pos:nn #1#2
  {
    \tl_set:Nn \l__eb_fnmark_before_tl {#1}
    \tl_if_novalue:nTF {#2}
      { \tl_clear:N \l__eb_fnmark_after_tl }
      { \tl_set:Nn \l__eb_fnmark_after_tl {#2} }
  }
\cs_new:Npn \eb_fnmark_counter_pifont:N #1
  { \ding{\int_eval:n { 171 + #1 }} }
\cs_new:Npn \eb_fnmark_counter_pifont_neg:N #1
  { \ding{\int_eval:n { 181 + #1 }} }
\cs_new:Npn \eb_fnmark_counter_pifont_sans:N #1
  { \ding{\int_eval:n { 191 + #1 }} }
\cs_new:Npn \eb_fnmark_counter_pifont_sans_neg:N #1
  { \ding{\int_eval:n { 201 + #1 }} }
\cs_new:Npn \eb_int_format_trans:NN #1
  {
    \str_case:nn {#1}
      {
        { A } { \int_to_Alph:n }
        { a } { \int_to_alph:n }
        { 1 } { \int_to_arabic:n }
        { I } { \int_to_Roman:n }
        { i } { \int_to_roman:n }
        { c } { \exp_args:NV \zhnumber }
      }
  }
\cs_new_protected:Npn \eb_fnmark_normal_label_set:nn #1#2
  {
    \tl_set:Nn \l__eb_fnmark_number_type_tl {#1}
    \cs_set:cpx {#2}
      {
        \str_case:VnT \l__eb_fnmark_number_type_tl
          {
            { plain }
            { \exp_not:N \int_use:N }
            { pifont }
            { \exp_not:N \eb_fnmark_counter_pifont:N }
            { pifont* }
            { \exp_not:N \eb_fnmark_counter_pifont_neg:N }
            { pifont-sans }
            { \exp_not:N \eb_fnmark_counter_pifont_sans:N }
            { pifont-sans* }
            { \exp_not:N \eb_fnmark_counter_pifont_sans_neg:N }
          }
          { \exp_not:N \c@footnote }
      }
  }
\cs_new_protected:Npn \eb_fnmark_short_label_set:nn #1#2
  {
    \tl_set:Nn \l__eb_fnmark_short_tokens_tl {#1}
    \eb_clist_map_inline:nn
      { A,a,1,I,i,c }
      {
        \tl_if_in:nnT {#1} {##1}
          {
            \tl_replace_once:Nnn \l__eb_fnmark_short_tokens_tl {##1}
              { \eb_int_format_trans:NN ##1 \c@footnote }
            \seq_map_break:
          }
      }
    \cs_set_eq:cN {#2} \l__eb_fnmark_short_tokens_tl
  }
\bool_new:N \l__eb_fntext_bottom_bool
\ctex_define:nn { hdrset }
  {
    fnmargin .dim_set:N             = \footnoteindent,
    fnmargin .initial:n             = 0.75em,
    fnparskip .skip_set:N           = \footparskip,
    fnparskip .initial:n            = 0ex,
    fnparindent .dim_set:N          = \footparindent,
    fnparindent .initial:n          = 2em,
    fntext-form .tl_set:N           = \l__eb_fntext_format_tl,

    fnmark-pos .tl_set:N            = \l__eb_fnmark_position_tl,
    fnmark-pos .initial:n           = super,
    fnmark-code .code:n             = \eb_assign_fnmark_code:n {#1},
    fnmark-code .initial:n          =
      { ,\tl_if_eq:NnF \l__eb_fnmark_position_tl { super } { \space } },
    fnmark-form .tl_set:N           = \l__eb_fnmark_format_tl,
    fncust-form .tl_set:N           = \l__eb_fncust_format_tl,
    fnboth-form .meta:n = { fnmark-form = #1,fncust-form = #1 },

    footnotetype .multichoices:nn   =
      { default,hang,bottom,para }
      {
        \tl_if_eq:nnTF { bottom } {#1}
          { \bool_set_true:N \l__eb_fntext_bottom_bool }
          { \tl_set:Nn \l__eb_footnotetype_choice_tl {#1} }
      },
    footnotetype .value_required:n  = true,
    footnotetype .initial:n         = hang,

    fnmark-num .choices:nn          =
      { plain,pifont,pifont*,pifont-sans,pifont-sans* }
      { \eb_fnmark_normal_label_set:nn {#1} { the@footnote } },
    fnmark-num .value_required:n    = true,
    fnmark-num/unknown .code:n      =
      { \eb_fnmark_short_label_set:nn {#1} { the@footnote } },
    fntext-num .choices:nn          =
      { plain,pifont,pifont*,pifont-sans,pifont-sans* }
      { \eb_fnmark_normal_label_set:nn {#1} { thefootnote } },
    fntext-num .value_required:n    = true,
    fntext-num/unknown .code:n      =
      { \eb_fnmark_short_label_set:nn {#1} { thefootnote } },
    fnboth-num .meta:n = { fntext-num = #1,fnmark-num = #1 },
    fnboth-num .initial:n           = plain,

    unknown .code:n = \eb_msg_unknown_option:n { hdrset }
  }

\eb_at_end_preamble:n
  {
    \group_begin:
    \footnotesize
    \exp_args:Nx
    \linespread{\fp_use:N \l__eb_spread_footnote_fp}\selectfont
    \exp_args:NNNo \group_end:
    \dim_set:Nn \footnotesep { \dim_use:N \box_ht:N \strutbox }
    \bool_if:NT \l__eb_chap_counter_withpart_bool
      { \counterwithin*{chapter}{part} }
    \str_case:Vn \l__eb_foot_counter_parent_choice_tl
      {
        { part } { \counterwithin*{footnote}{part} }
        { page } { \counterwithin*{footnote}{page} }
      }
    \bool_if:NT \l__eb_fntext_bottom_bool
      {
        \cs_set:Npn \@makecol
          {
            \setbox\@outputbox\box\@cclv
            \xdef\@freelist{\@freelist\@midlist}
            \global\let\@midlist\@empty
            \@combinefloats
            \eb@footmisc@ifvoid\footins{}
              {
                \setbox\@outputbox\vbox
                \bgroup
                \boxmaxdepth\@maxdepth
                \unvbox\@outputbox
                \vfill\relax
                \vskip\skip\footins
                \color@begingroup
                \normalcolor\footnoterule
                \unvbox\footins
                \color@endgroup
                \egroup
              }
            \eb@footmisc@ifvoid\@kludgeins
              {\@makespecialcolbox}
              {
                \setbox\@outputbox\vbox to\@colht
                  {
                    \@texttop\dimen@\dp\@outputbox
                    \unvbox\@outputbox
                    \vskip -\dimen@\@textbottom
                  }
              }
            \global\maxdepth\@maxdepth
          }
      }
  }
\cs_set:Npn \@makefntext #1
  {
    \group_begin:
    \str_case:Vn \l__eb_footnotetype_choice_tl
      {
        { hang } { \use_i:nn }
        { default } { \use_ii:nn }
      }
      {
        \hbox_set:Nn \l_tmpa_box
          {
            \dim_compare:nNnTF { \footnoteindent } > { 0pt }
              { \hbox_to_wd:nn { \footnoteindent } { \eb@makefnmark\hss } }
              { \eb@makefnmark }
          }
        \dim_set:Nn \leftmargin { \box_wd:N \l_tmpa_box }
        \dim_zero:N \rightmargin
        \dim_set_eq:NN \linewidth \columnwidth
        \dim_sub:Nn \linewidth { \leftmargin }
        \parshape\@ne\leftmargin\linewidth
        \@setpar{{\@@par}}
        \mode_leave_vertical:
        \hbox_overlap_left:n { \box_use:N \l_tmpa_box }
      }
      {
        \noindent
        \int_case:nn { \dim_sign:V \footnoteindent }
          {
            { 1 } { \use_i:nnn }
            { 0 } { \use_ii:nnn }
            { -1 } { \use_iii:nnn }
          }
          { \hbox_to_wd:nn { \footnoteindent } { \hss\eb@makefnmark } }
          { \hbox_overlap_left:n { \eb@makefnmark } }
          {
            \hbox_overlap_left:n
              {
                \hbox_to_wd:nn { -\footnoteindent }
                  { \eb@makefnmark\hss }
              }
          }
      }
    \skip_set:NV \parskip \footparskip
    \dim_set:NV \parindent \footparindent
    \l__eb_fntext_format_tl{#1}
    \tl_if_eq:NnT \l__eb_footnotetype_choice_tl { hang } { \par }
    \group_end:
  }
\cs_set_eq:NN \eb@makefntext \@makefntext
\ctex_at_end_package:nn { footmisc }
  { \cs_set_eq:NN \@makefntext \eb@makefntext }
\eb_at_end_patch_cmd:nnn { \@footnotetext,\@mpfootnotetext }
  { \reset@font }
  {
    \linespread{\fp_use:N \l__eb_spread_footnote_fp}
    \selectfont\ignorespaces
    \l__eb_subfont_footnote_tl
  }
\ProvideDocumentCommand{\super}{d()mo}{\textsuperscript{#2}}
\providecommand{\spbset}{\use_none:n}
\cs_set_protected:Npn \footref #1
  {
    \group_begin:
    \unrestored@protected@xdef\eb@thefnmark{\ref{#1}}
    \group_end:
    \H@@footnotemark
  }
\cs_set_protected:Npn \footnote
  {
    \@ifnextchar [
      {\@xfootnote}
      {
        \exp_args:NV \stepcounter \@mpfn
        \eb_current_label:n { @footnote }
        \protected@xdef\@thefnmark{\thempfn}
        \protected@xdef\eb@thefnmark{\the@footnote}
        \@footnotemark
        \@footnotetext
      }
  }
\cs_set:Npn \footnotemark
  {
    \@ifnextchar [
      {\@xfootnotemark}
      {
        \stepcounter{footnote}
        \protected@xdef\eb@thefnmark{\the@footnote}
        \@footnotemark
      }
  }
\ctex_at_end_package:nn { hyperref }
  {
    \cs_set:Npn \@xfootnotemark [#1]
      {
        \group_begin:
        \setcounter{footnote}{#1}
        \unrestored@protected@xdef\eb@thefnmark{\the@footnote}
        \group_end:
        \H@@footnotemark
      }
  }
\NewDocumentCommand{\eb@fnmark@super}{sm}
  {
    \IfBooleanTF{#1}
      {\super{#2}[0pt]}
      {\super(\l__eb_fnmark_format_tl){#2}[0pt]}
  }
\cs_new_protected:Npn \eb_fnmark_format_initial:
  {
    \spbset{super-format = { },nohshift}
    \tl_use:N \l__eb_subfont_footnote_tl
  }
\cs_set:Npn \@makefnmark
  {
    \hbox:n
      {
        \eb_fnmark_format_initial:
        \tl_if_eq:NnTF \@mpfn { footnote }
          { \eb@fnmark@super{\eb@thefnmark} }
          { \eb@fnmark@super{\@thefnmark} }
      }
  }
\cs_new:Npn \eb@makefnmark
  {
    \hbox:n
      {
        \eb_fnmark_format_initial:
        \tl_if_eq:NnT \l__eb_fnmark_position_tl { super }
          { \eb@fnmark@super* }
          {
            \tl_use:N \l__eb_fnmark_before_tl
            \l__eb_fnmark_format_tl{\@thefnmark}
            \tl_use:N \l__eb_fnmark_after_tl
          }
      }
  }
\tl_clear:N \@thefnmark
\tl_new:N \eb@thefnmark
\cs_new:Npn \eb@@makefnmark #1#2
  {
    \tl_if_empty:oF {#2}
      {
        \group_begin:
        \unrestored@protected@xdef\eb@thefnmark{#1}
        \unrestored@protected@xdef\@thefnmark{#2}
        \group_end:
      }
  }
\cs_new_protected:Npn \eb_fncust_format_initial:
  {
    \hdrset{fnmark-code = { }}
    \tl_set_eq:NN
    \l__eb_fnmark_format_tl \l__eb_fncust_format_tl
  }
\NewDocumentCommand{\Footnote}{O{#2}mm}
  {
    \group_begin:
    \eb_fncust_format_initial:
    \eb@@makefnmark{#2}{#1}
    \@footnotemark
    \@footnotetext{#3}
    \group_end:
  }
\cs_new_protected:Npn \Footnotemark #1
  {
    \group_begin:
    \eb_fncust_format_initial:
    \eb@@makefnmark{#1}{#1}\@footnotemark
    \group_end:
  }
\cs_new_protected:Npn \Footnotetext #1#2
  {
    \group_begin:
    \eb_fncust_format_initial:
    \eb@@makefnmark{#1}{#1}\@footnotetext{#2}
    \group_end:
  }
\cs_new:Npn \eb@footmisc@ifvoid #1#2#3 { \ifvoid #1#2\else #3\fi }
\cs_set:Npn \thempfootnote { \int_to_alph:n { \c@mpfootnote } }

\contentsuse{lstlisting}{lol}
\seq_put_left:Nn  \c__ctex_headings_seq { chapter }
\seq_put_right:Nn \c__ctex_headings_seq { figure }
\seq_put_right:Nn \c__ctex_headings_seq { table }
\seq_put_right:Nn \c__ctex_headings_seq { lstlisting }
\seq_remove_duplicates:N \c__ctex_headings_seq
\cs_new_protected:Npn \eb_toc_assign_keys:n #1
  {
    \ctex_define:n { tocset/#1 .meta:nn = { ctex/tocset/#1 } {##1} }
    \ctex_define:nn { tocset }
      {
        #1/format .tl_set:c   = l__eb_toc_#1_format_tl,
        #1/format+ .code:n    =
          { \tl_put_right:cn { l__eb_toc_#1_format_tl } {##1} },
        #1/format~+ .code:n   =
          { \tl_put_right:cn { l__eb_toc_#1_format_tl } {##1} },
        #1/indent .dim_set:c  = l__eb_toc_#1_indent_dim,
        #1/rule .tl_set:c     = l__eb_toc_#1_rule_tl,
        #1/numsep .dim_set:c  = eb@toc@#1@numsep,
        #1/unknown .code:n    = \eb_msg_unknown_option:n { tocset }
      }
    \seq_if_in:NnF \c__ctex_headings_seq { subparagraph }
      {
        \ctex_define:nn { tocset }
          { #1/belowoffset .dim_set:c = l__eb_toc_#1_offset_dim }
      }
    \seq_pop:NN \c__ctex_headings_seq \l_tmpa_tl
    \titlecontents{#1}
      [\dim_use:c { l__eb_toc_#1_indent_dim }]
      {\tl_use:c { l__eb_toc_#1_format_tl }}
      {
        \ifbool{eb@titletoc@hang@fix}
          {
            \contentspush
              {
                \bool_if:NT \l__eb_toc_number_color_bool
                  { \color{ctex@toc@number} }
                \thecontentslabel
                \hspace{\use:c { eb@toc@#1@numsep }}
              }
          }{}
      }{}
      {\tl_use:c { l__eb_toc_#1_rule_tl }}
  }
\seq_map_function:NN
\c__ctex_headings_seq \eb_toc_assign_keys:n
\ctex_define:n { tocset/list .meta:nn = { ctex/tocset/list } {#1} }
\eb_clist_map_inline:nn
  { format,format+,format~+,indent,rule,numsep,belowoffset }
  {
    \ctex_define:nn { tocset }
      {
        list/#1 .meta:n   =
          {
            figure/#1     = ##1,
            table/#1      = ##1,
            lstlisting/#1 = ##1
          }
      }
  }

\cs_set_eq:NN \ctexnumberline \CTEXnumberline
\cs_set:Npn \CTEXnumberline #1
  {
    \CTEXifname
      {
        \ifbool{eb@titletoc@hang@fix}
          {\eb@numberline{\use:c { CTEXthe#1 }}}
          {
            \use:c { CTEXthe#1 }
            \hspace{\use:c { eb@toc@#1@numsep }}
          }
      }{}
  }
\cs_new:Npn \eb@numberline { \protect\numberline }
\cs_set_eq:NN \EBNumberLine \CTEXnumberline
\newbool{eb@titletoc@hang@fix}
\ctex_define:nn { tocset }
  {
    lolskip .skip_set:N     = \l__eb_toc_lolskip_skip,
    lolskip .initial:n      = 0.8pc,
    belowoffset .dim_set:N  = \l__eb_toc_offset_dim,
    belowoffset .initial:n  =
      { \bool_if:NTF \l__eb_class_book_bool { -1pc } { -0.35pc } },
    line-align .bool_set:N  = \l__eb_toc_line_align_bool,
    line-align .default:n   = true,
    line-align .initial:n   = true,

    tocline-fig .cs_set:Np  = \eb@labelname@lof #1,
    tocline-fig .initial:n  =
      {
        \figurename\space #1
        \notbool{eb@titletoc@hang@fix}
          {\hspace{\eb@toc@figure@numsep}}{}
      },
    tocline-tab .cs_set:Np  = \eb@labelname@lot #1,
    tocline-tab .initial:n  =
      {
        \tablename\space #1
        \notbool{eb@titletoc@hang@fix}
          {\hspace{\eb@toc@table@numsep}}{}
      },
    tocline-lst .tl_set:N   = \eb@labelname@lol,
    tocline-lst .initial:n  =
      {
        \lstlistingname\space\thelstlisting
        \notbool{eb@titletoc@hang@fix}
          {\hspace{\eb@toc@lstlisting@numsep}}{}
      },

    hang .choice:,
    hang/true .code:n     = \booltrue{eb@titletoc@hang@fix},
    hang/false .code:n    = { },
    hang .default:n       = true,
    hang .initial:n       = false,

    numsep-all .meta:n    =
      {
        part/numsep       = #1,
        chapter/numsep    = #1,
        section/numsep    = #1,
        subsection/numsep = #1,
        list/numsep       = #1
      },
    numsep-all .initial:n = 1em,
    indent-all .meta:n    =
      {
        part/indent       = #1,
        chapter/indent    = #1,
        section/indent    = #1,
        subsection/indent = #1,
        list/indent       = #1
      },
    rule-all .meta:n      =
      {
        part/rule         = #1,
        chapter/rule      = #1,
        section/rule      = #1,
        subsection/rule   = #1,
        list/rule         = #1
      }
  }
\ctex_set:n
  {
    part/tocline        = \CTEXnumberline{#1}#2,
    chapter/tocline     = \CTEXnumberline{#1}#2,
    section/tocline     = \CTEXnumberline{#1}#2,
    subsection/tocline  = \CTEXnumberline{#1}#2
  }

\NewDocumentCommand{\tocrule}{sO{0.7pc}D(){1.2}mO{}}
  {
    \normalsize\normalfont
    \titlerule*[#2]{\scalebox{#3}{#4}}#5
      {
        \IfBooleanTF{#1}
          {\thecontentspage}
          {
            \bool_if:NTF \l__eb_toc_line_align_bool
              { \contentspage }
              { \thecontentspage }
          }
      }
  }
\ctex_set:nn { tocset }
  {
    part/format       = \addvspace{1pc}\sffamily\large,
    part/indent       = 0em,
    part/rule         = \tocrule{}[\bfseries],

    chapter/format    = \addvspace{1pc}\sffamily\large,
    chapter/indent    = 0em,
    chapter/rule      = \tocrule{$\cdot$}[\bfseries],

    section/format    =
      {
        \addvspace{0.35pc}
        \bool_if:NF \l__eb_class_book_bool { \sffamily }
      },
    section/indent    =
      { \bool_if:NTF \l__eb_class_book_bool { 1.5em } { 0em } },
    section/rule      =
      {
        \bool_if:NTF \l__eb_class_book_bool
          { \tocrule{$\cdot$} }
          { \tocrule{$\cdot$}[\bfseries] }
      },

    subsection/format = \addvspace{0.35pc},
    subsection/indent =
      { \bool_if:NTF \l__eb_class_book_bool { 3.8em } { 1.4em } },
    subsection/rule   = \tocrule{$\cdot$},

    list/format       = \addvspace{0.2pc},
    list/indent       = 0em,
    list/rule         = \tocrule{$\cdot$},
    list/belowoffset  =
      { \bool_if:NTF \l__eb_class_book_bool { 0pc } { 0.15pc } }
  }

\prop_new:N \l__eb_label_name_prop
\prop_set_from_keyval:Nn \l__eb_label_name_prop
  {
    figure  = \eb@labelname@lof,
    table   = \eb@labelname@lot
  }
\cs_gset:Npn \caption@@@addcontentsline #1#2#3#4
  {
    \addcontentsline{#1}{#2}
      {
        \ifbool{eb@titletoc@hang@fix}{\eb@numberline}{}
          {\prop_item:Nn \l__eb_label_name_prop {#2}{#3}}#4
      }
  }
\ctex_patch_cmd:Nnn \lst@MakeCaption
  {
    \addcontentsline{lol}{lstlisting}
      {\protect\numberline{\thelstlisting}\lst@@caption}
  }
  {
    \addcontentsline{lol}{lstlisting}
      {
        \ifbool{eb@titletoc@hang@fix}{\eb@numberline}{}
          {\eb@labelname@lol}\lst@@caption
      }
  }

\newcounter{bichapter}
\newcounter{bisection}[bichapter]
\newcounter{bisubsection}[bisection]
\cs_set_protected:Npn \eb_current_label:n #1
  {
    \tl_set:Nx \@currentlabel
      {
        \use:c { p@#1 }
        \tl_use:c { the#1 }
      }
  }
\NewDocumentCommand{\UseCounter}{soD(){arabic}mmO{.}d()}
  {
    \IfBooleanF{#1}{\stepcounter{#4}}
    \IfValueT{#7}{\setcounter{#4}{#7}}
    \tl_set:cn { theeb@#4 }
      {
        \IfValueT{#2}{\use:c { the#2 }#6}
        \use:c {#3}{#4}\space #5
      }
    \tl_use:c { theeb@#4 }
    \tl_remove_once:cn { theeb@#4 } {#5}
    \eb_current_label:n { eb@#4 }
  }
\cs_new:Npn \eb_section_counter_prefix:n #1
  {
    \int_compare:nNnT { \c@chapter } > { 0 } { \use:c { the#1chapter }. }
    \int_to_arabic:v { c@#1section }
  }
\cs_set:Npn \thebichapter { \eb_arabic:n { bichapter } }
\cs_set:Npn \thebisection { \eb_section_counter_prefix:n { bi } }
\cs_set:Npn \thebisubsection { \thebisection.\eb_arabic:n { bisubsection } }
\cs_set:Npn \thesection { \eb_section_counter_prefix:n { } }

\contentsuse{}{tec}
\tl_new:N \eb@before@addbitoc@hook
\NewDocumentCommand{\BeforeAddBitoc}{sm}
  {
    \IfBooleanTF{#1}
      {\tl_gset:Nn \eb@before@addbitoc@hook {#2}}
      {\tl_gput_right:Nn \eb@before@addbitoc@hook {#2}}
  }
\cs_set_protected:Npn \CTEX@addbitocline #1#2
  {
    \group_begin:
    \def\CTEX@prechapter{\CTEX@prebichapter}
    \def\CTEX@thechapter{\CTEX@bichapter@number}
    \def\CTEX@postchapter{\CTEX@postbichapter}
    \eb@before@addbitoc@hook
    \addcontentsline{tec}{#1}{\use:c { CTEX@#1@tocline }{#1}{#2}}
    \group_end:
  }
\eb_clist_map_inline:nn
  { chapter,section,subsection }
  {
    \exp_args:Nc \NewDocumentCommand { bi#1 }{sO{##3}mm}
      {
        \IfBooleanTF{##1}
          {
            \use:c {#1}*{\phantomsection ##3}
            \CTEX@addtocline{#1}{##2}
            \tl_if_empty:oF {##4} { \CTEX@addbitocline{#1}{##4} }
            \tl_set:Nn \l__eb__bitoc_mark_title_level_tl {#1}
            \str_case:nn {#1}
              {
                { chapter } { \eb@level@markdouble{chapter}{##2} }
                { section } { \eb@level@section@mark{##2} }
                { subsection } { \eb@level@subsection@mark{##2} }
              }
          }{
            \stepcounter{bi#1}
            \use:c {#1}[##2]{##3}
            \tl_if_empty:oF {##4} { \CTEX@addbitocline{#1}{##4} }
          }
      }
  }
\cs_if_exist:NT \chapter
  {
    \eb_appto_cmd:Nn \@chapter
      {
        \skip_if_eq:nnF { \l__eb_toc_lolskip_skip } { \c_zero_skip }
          {
            \addtocontents{lol}
              {\protect\addvspace{\skip_use:N \l__eb_toc_lolskip_skip}}
          }
      }
  }

\ctex_define:nn { style }
  {
    figure-con .tl_set:N    = \l__eb_figure_connector_tl,
    table-con .tl_set:N     = \l__eb_table_connector_tl,
    listing-con .tl_set:N   = \l__eb_lstlisting_connector_tl,
    equation-con .tl_set:N  = \l__eb_equation_connector_tl,
    number-con .meta:n      =
      {
        figure-con    = #1,
        table-con     = #1,
        listing-con   = #1,
        equation-con  = #1
      },
    number-con .initial:n   = { . },
    unknown .code:n = \eb_msg_unknown_option:n { style }
  }
\eb_clist_map_inline:nn
  { figure,table,lstlisting,equation }
  {
    \cs_set:cpn { the#1 }
      {
        \int_compare:nNnT { \c@chapter } > { 0 }
          {
            \thechapter
            \tl_use:c { l__eb_#1_connector_tl }
          }
        \int_to_arabic:v { c@#1 }
      }
  }

\tl_set:Nx \l__eb_toc_type_tl
  { \bool_if:NTF \l__eb_class_book_bool { chapter } { section } }
\tl_new:N \eb@bitoc@title
\keys_define:nn { eb/listoc }
  {
    section .code:n     = \tl_set:Nn \l__eb_toc_type_tl { section },
    chapter .code:n     = { },
    article .meta:n     = section,
    book .meta:n        = chapter,
    multoc .bool_set:N  = \l__eb_toc_multi_column_bool,
    multoc .default:n   = true,
    multoc .initial:n   = false,
    title .code:n       = \eb_assign_toc_title:n {#1},
    columns .int_set:N  = \l__eb_toc_columns_int,
    columns .initial:n  = 2
  }
\bool_if:NTF \l__eb_class_book_bool
  { \keys_define:nn { } { eb/listoc .inherit:n = ctex/chapter } }
  { \keys_define:nn { } { eb/listoc .inherit:n = ctex/section } }
\NewDocumentCommand{\eb_assign_toc_title:n}
  {>{\SplitArgument{1}{,}}m}
  {\eb_assign_toc_title_judge:nn #1}
\cs_new_protected:Npn \eb_assign_toc_title_judge:nn #1#2
  {
    \tl_set:Nn \eb@toc@title {#1}
    \tl_if_novalue:nTF {#2}
      { \tl_clear:N \eb@bitoc@title }
      { \tl_set:Nn \eb@bitoc@title {#2} }
  }

\cs_new_protected:Npn \eb_title_mark_intoc:n #1
  {
    \tl_if_eq:NnTF \l__eb_toc_type_tl { chapter }
      {
        \bichapter*{#1}{\eb@bitoc@title}
        \eb@level@markdouble{chapter}{#1}
      }
      {
        \bisection*{#1}{\eb@bitoc@title}
        \eb@level@section@mark{#1}
      }
  }
\cs_new_protected:Npn \eb_title_mark_notoc:n #1
  {
    \tl_if_eq:NnTF \l__eb_toc_type_tl { chapter }
      {
        \chapter*{\phantomsection #1}
        \eb@level@markdouble{chapter}{#1}
      }
      {
        \section*{\phantomsection #1}
        \eb@level@section@mark{#1}
      }
  }
\cs_new_protected:Npn \eb_title_number_intoc_spec:nn #1#2
  {
    \IfBooleanTF{#1}
      {
        \tl_if_eq:NnTF \l__eb_toc_type_tl { chapter }
          { \bichapter{\eb@toc@title}{\eb@bitoc@title} }
          { \bisection{\eb@toc@title}{\eb@bitoc@title} }
      }{
        \IfBooleanTF{#2}
          {\eb_title_mark_notoc:n { \eb@toc@title }}
          {\eb_title_mark_intoc:n { \eb@toc@title }}
      }
  }
\cs_new_protected:Npn \eb_biber_title_level_spec:n #1
  {
    \bool_if:NTF \l__eb_class_book_bool
      { \bichapter*{#1}{\l__eb_bib_en_bitoc_title_tl} }
      { \bisection*{#1}{\l__eb_bib_en_bitoc_title_tl} }
    \eb@level@section@mark{#1}
  }
\cs_new_protected:Npn \eb_toc_start_multi_column_ext:n #1
  {
    \bool_if:NTF \l__eb_toc_multi_column_bool
      {
        \begin{multicols}{\int_use:N \l__eb_toc_columns_int}
          \@starttoc{#1}
        \end{multicols}
      }
      { \@starttoc{#1} }
  }
\cs_new_protected:Npn \eb_toc_list_parse:nnnnn #1#2#3#4#5
  {
    \group_begin:
    \tl_set_eq:Nc \eb@toc@title { list#4name }
    \IfValueT{#3}{\keys_set:nn { eb/listoc } {#3}}
    \eb_title_number_intoc_spec:nn {#2} {#1}
    \dim_add:Nv
    \l__eb_toc_offset_dim { l__eb_toc_#4_offset_dim }
    \vspace*{\dim_use:N \l__eb_toc_offset_dim}
    \eb_toc_start_multi_column_ext:n {#5}
    \group_end:
  }
\clist_map_inline:nn
  {
    { figure,lof },
    { table,lot },
    { lstlisting,lol }
  }
  {
    \exp_args:Nc \DeclareDocumentCommand
      { listof\clist_item:nn {#1} { 1 }s }{st+o}
      {
        \eb_toc_list_parse:nnnnn {##1} {##2} {##3}
          { \clist_item:nn {#1} { 1 } }
          { \clist_item:nn {#1} { 2 } }
      }
  }
\cs_set_eq:NN \listoflistings \listoflstlistings
\RenewDocumentCommand{\tableofcontents}{t+oD(){}}
  {
    \group_begin:
    \tl_set_eq:NN \eb@toc@title \contentsname
    \tl_set:Nn \eb@bitoc@title { Contents }
    \IfValueT{#2}{\keys_set:nn { eb/listoc } {#2}}
    \eb_title_mark_notoc:n { \eb@toc@title }
    \vspace*{\dim_use:N \l__eb_toc_offset_dim}
    \eb_toc_start_multi_column_ext:n { toc }#3
    \IfBooleanT{#1}
      {
        \eb_title_mark_notoc:n { \eb@bitoc@title }
        \vspace*{\dim_use:N \l__eb_toc_offset_dim}
        \eb_toc_start_multi_column_ext:n { tec }
      }
    \group_end:
  }

\ctex_at_end_package:nn { imakeidx }
  {
    \makeindex
    \RenewDocumentCommand{\printindex}{st+oD(){\imki@jobname}}
      {
        \group_begin:
        \tl_set_eq:NN \eb@toc@title \indexname
        \cs_set_eq:NN \imki@indexlevel \use_none:n
        \setkeys{imkiindex}{noclearpage}
        \IfValueT{#3}{\keys_set:nn { eb/listoc } {#3}}
        \tl_set:Nn \imki@indexheaders
          {
            \eb_title_number_intoc_spec:nn {#2} {#1}
            \cs_set_eq:NN \thispagestyle \use_none:n
            \cs_undefine:N \imki@firstpagestyle
          }
        \imki@putindex{#4}
        \group_end:
      }
  }
\ctex_define:nn { chapter }
  {
    biname .code:n      =
      { \ctex_assign_heading_name:nn { bichapter } {#1} },
    biname .initial:n   = Chapter\space,
    binmuber .tl_set:N  = \CTEX@bichapter@number,
    binmuber .initial:n = \arabic{chapter}
  }
\cs_new_protected:Npn \eb_counter_zero:n #1
  { \eb_clist_map_inline:nn {#1} { \setcounter{##1}{0} } }
\RenewDocumentCommand{\appendix}
  {O{Appendix\space}D(){\Alph{chapter}}}
  {
    \ctex_assign_heading_name:nn { biappendix } {#1}
    \int_compare:nNnTF { \c@chapter } > { 0 }
      {
        \eb_char_patch_cmd:nnn \CTEX@addbitocline
          {
            \def\CTEX@prechapter{\CTEX@prebichapter}
            \def\CTEX@thechapter{\CTEX@bichapter@number}
            \def\CTEX@postchapter{\CTEX@postbichapter}
          }
          {
            \def\CTEX@prechapter{\CTEX@prebiappendix}
            \def\CTEX@thechapter{#2}
            \def\CTEX@postchapter{\CTEX@postbiappendix}
          }
        \gdef\thechapter{\@Alph\c@chapter}
        \gdef\thebichapter{\@Alph\c@bichapter}
        \gdef\CTEX@prechapter{\CTEX@preappendix}
        \gdef\CTEX@thechapter{\CTEX@appendix@number}
        \gdef\CTEX@postchapter{\CTEX@postappendix}
        \gdef\CTEX@chapter@numbering{\CTEX@appendix@numbering}
        \eb_counter_zero:n { chapter,section,bichapter,bisection }
      }
      {
        \gdef\thesection{\@Alph\c@section}
        \gdef\thebisection{\@Alph\c@bisection}
        \gdef\CTEX@presection{\CTEX@preappendix}
        \gdef\CTEX@thesection{\CTEX@appendix@number}
        \gdef\CTEX@postsection{\CTEX@postappendix}
        \gdef\CTEX@section@numbering{\CTEX@appendix@numbering}
        \ctex_set:nn { appendix } { number = \@Alph\c@section,name = { } }
        \eb_counter_zero:n { section,subsection,bisection,bisubsection }
      }
  }

\tl_new:N \l__eb_subfont_table_tl
\tl_new:N \l__eb_subfont_figure_tl
\tl_new:N \l__eb_subfont_listing_tl
\tl_new:N \l__eb_subfont_footnote_tl

\ctex_define:nn { subfont }
  {
    table-cap .tl_set:N     = \l__eb_subfont_table_tl,
    table-cap .initial:n    = \sffamily\small,
    figure-cap .tl_set:N    = \l__eb_subfont_figure_tl,
    figure-cap .initial:n   = \sffamily\small,
    listing-cap .tl_set:N   = \l__eb_subfont_listing_tl,
    listing-cap .initial:n  = \sffamily\small,
    footnote .tl_set:N      = \l__eb_subfont_footnote_tl,
    footnote .initial:n     = \rmfamily,
    marginpar .tl_set:N     = \marginfont,
    marginpar .initial:n    = \rmfamily\footnotesize,

    math .choices:nn        =
      {
        noto,notosans,times,libertine,
        charter,garamond,none,nc,stix
      }
      { \tl_set:Nn \l__eb_subfont_math_choice_tl {#1} },
    math .value_required:n  = true,
    math .initial:n         = times,
    unknown .code:n = \eb_msg_unknown_option:n { subfont }
  }

\cs_new_protected:Npn \eb_put_newtxmath:n #1
  { \PassOptionsToPackage{#1}{newtxmath} }
\eb_at_end_preamble:n
  {
    \str_case:VnT \l__eb_subfont_math_choice_tl
      {
        { noto } { \eb_put_newtxmath:n { noto } }
        { notosans } { \eb_put_newtxmath:n { notosans } }
        { garamond } { \eb_put_newtxmath:n { ebgaramond } }
        { times } { \eb_put_newtxmath:n { noOT1 } }
        { libertine } { \eb_put_newtxmath:n { libertine,noOT1 } }
        { stix } { \eb_put_newtxmath:n { stix2,noOT1 } }
        { nc } { \eb_put_newtxmath:n { nc,noOT1 } }
        { charter } { \eb_put_newtxmath:n { charter,noOT1 } }
      }
      { \LoadPackage{newtxmath+bm} }
  }

\fp_new:N \l__eb_spread_line_fp
\fp_new:N \l__eb_spread_table_fp
\fp_new:N \l__eb_spread_math_fp
\fp_new:N \l__eb_spread_caption_fp
\fp_new:N \l__eb_spread_footnote_fp

\ctex_define:nn { spread }
  {
    line .fp_set:N      = \l__eb_spread_line_fp,
    line .initial:n     = 1.3,
    table .fp_set:N     = \l__eb_spread_table_fp,
    table .initial:n    = 1.05,
    math .fp_set:N      = \l__eb_spread_math_fp,
    math .initial:n     = 1.05,
    caption .fp_set:N   = \l__eb_spread_caption_fp,
    caption .initial:n  = 1.1,
    footnote .fp_set:N  = \l__eb_spread_footnote_fp,
    footnote .initial:n = 1.1,
    spread-all .meta:n  =
      {
        line      = #1,
        table     = #1,
        math      = #1,
        caption   = #1,
        footnote  = #1
      },
    unknown .code:n = \eb_msg_unknown_option:n { spread }
  }

\DeclareCaptionLabelFormat{parens}{\bothIfFirst{#1}{~}(#2)}
\DeclareCaptionFont{eb@table@font}{\l__eb_subfont_table_tl}
\DeclareCaptionFont{eb@figure@font}{\l__eb_subfont_figure_tl}
\DeclareCaptionFont{eb@listing@font}{\l__eb_subfont_listing_tl}
\captionsetup
  {
    format          = hang,
    font = {stretch = \fp_use:N \l__eb_spread_caption_fp},
    labelfont       = {color = ctex@frame},
    labelsep        = quad,
    singlelinecheck = true,
    belowskip       = 0pt,
    aboveskip       = 10pt
  }
\captionsetup[table]{font += eb@table@font}
\captionsetup[figure]{font += eb@figure@font}
\captionsetup[lstlisting]{font += eb@listing@font}
\captionsetup[subfigure]
  {
    labelformat = parens,
    font+       = eb@figure@font,
    belowskip   = 2pt,
    aboveskip   = 6pt
  }
\ctex_at_end_package:nn { bicaption }
  {
    \captionsetup[figure][bi-second]{name = Figure}
    \captionsetup[table][bi-second]{name = Table}
  }
\IfPackageAtLeastTF{tabularray}{2021/07/01}
  {
    \SetTblrInner
      {
        rows    = {abovesep = 4pt,belowsep = 2pt},
        stretch = \fp_use:N \l__eb_spread_table_fp
      }
    \NewTableCommand{\toprule}[1][1pt]{\hline[#1]}
    \NewTableCommand{\midrule}[1][0.5pt]{\hline[#1]}
    \NewTableCommand{\bottomrule}[1][1pt]{\hline[#1]}
  }{}
\eb_at_begin_environment:nn { tabular,tabularx }
  {
    \exp_args:Nx \linespread { \fp_use:N \l__eb_spread_table_fp }
    \selectfont\ignorespaces
  }
\ctex_after_end_preamble:n
  {
    \exp_args:Nx \linespread { \fp_use:N \l__eb_spread_line_fp }
    \selectfont\ignorespaces
  }

\cs_new_protected:Npn \eb_float_proportion_set:nn #1#2
  { \tl_gset:cn { #1fraction } {#2} }
\bool_if:NF \l__eb_float_page_bool
  {
    \clist_map_inline:nn
      {
        { text } { 0.1 },
        { top } { 0.9 },
        { bottom } { 0.9 },
        { floatpage } {0.9 },
        { dbltop } { 0.9 },
        { dblfloatpage } { 0.9 }
      }
      { \eb_float_proportion_set:nn #1 }
  }
\skip_set:Nn \parskip { 0pt plus 2pt minus 1pt }
\skip_set:Nn \intextsep { 14pt plus 2pt minus 2pt }
\skip_set:Nn \textfloatsep { 16pt plus 2pt minus 4pt }
\skip_set:Nn \multicolsep { 12pt plus 4pt minus 3pt }
\skip_set:Nn \dbltextfloatsep { 16pt plus 2pt minus 4pt }
\int_gset:Nn \vbadness { 10000 }
\int_gset:Nn \hbadness { 10000 }
\setcounter{topnumber}{4}
\setcounter{bottomnumber}{4}
\setcounter{totalnumber}{8}
\allowdisplaybreaks[4]
\everymath{\displaystyle}
\tl_gset:Nn \ULthickness { \l__eb_rule_width_dim }
\DeclareGraphicsExtensions{.pdf,.png,.jpg,.eps,.tif}

\cs_new_protected:Npn \hangpara #1#2
  { \hangindent #1\hangafter #2\noindent\ignorespaces }
\NewDocumentEnvironment{hangparas}{mm+b}
  {
    \dim_zero:N \parindent
    \everypar{\hangpara{#1}{#2}}#3\par
  }{}
\cs_new_protected:Npn \eb_enumitem_label_set:nn #1#2
  { \SetEnumitemValue{label}{#1}{\color{ctex@emph}#2} }
\clist_map_inline:nn
  {
    { bullet } { \textbullet },
    { endash } { \normalfont\bfseries\textendash },
    { asterisk } { \textasteriskcentered },
    { arabic } { \arabic*. },
    { alph } { (\alph*) },
    { roman } { \roman*. },
    { outline } { \upshape\ding{111} }
  }
  { \eb_enumitem_label_set:nn #1 }
\SetEnumitemValue{font}{sf}{\color{ctex@emph}\normalfont\sffamily}
\SetEnumitemValue{ref}{enumii}{\arabic{enumi}.\alph*}
\SetEnumitemValue{ref}{enumiii}{\arabic{enumi}.\alph{enumii}.\roman*}
\setlist
  {
    labelsep = 0.75em,listparindent = 2em,leftmargin = *,
    itemsep = 0.75ex plus .1ex,topsep = 0.75ex plus .1ex,
    partopsep = 0ex,parsep = 0ex
  }
\newlist{eb@outline@list}{itemize}{1}
\newlist{eb@exercise@list}{enumerate}{2}
\newlist{eb@eqcomp@list}{description}{1}
\setlist[eb@outline@list]{label = outline,itemsep = 0.5ex plus .1ex}
\setlist[eb@exercise@list]{labelsep = 0.5em,nosep}
\setlist[eb@eqcomp@list]{labelsep = 0em,nosep}
\setlist[itemize,1]{label = bullet}
\setlist[itemize,2]{label = endash}
\setlist[itemize,3]{label = asterisk}
\setlist[enumerate,1]{label = arabic,ref = \arabic*}
\setlist[enumerate,2]{label = alph,ref = enumii,labelwidth = *}
\setlist[enumerate,3]{label = roman,ref = enumiii,labelwidth = *}
\setlist[description]{font = sf,labelwidth = *,leftmargin = 2em}
\cs_new:Npn \setexerlist #1 { \setlist*[eb@exercise@list]{#1} }
\cs_new:Npn \seteqcomplist #1 { \setlist*[eb@eqcomp@list]{#1} }
\cs_new:Npn \setoutlinelist #1 { \setlist*[eb@outline@list]{#1} }

\keys_define:nn { eb/eqcomp }
  {
    width .dim_set:N        = \l__eb_eqsymb_width_dim,
    width .initial:n        = 2em,
    delim .tl_set:N         = \l__eb_eqsymb_delim_tl,
    delim .initial:n        = { —— },
    space .dim_set:N        = \l__eb_eqsymb_space_dim,
    space .initial:n        = 0.25em,
    item-align .tl_set:N    = \l__eb_eqsymb_item_align_tl,
    item-align .initial:n   = r,
    delim-align .tl_set:N   = \l__eb_eqsymb_delim_align_tl,
    delim-align .initial:n  = c,
    enumitem .code:n        = \seteqcomplist{#1},
    intro .tl_set:N         = \l__eb_eqsymb_intro_tl,
    font .tl_set:N          = \l__eb_eqsymb_font_tl,
    mode .tl_set:N          = \l__eb_eqsymb_mode_tl,
    mode .initial:n         = math
  }
\cs_new_protected:Npn \seteqcomp #1
  { \keys_set:nn { eb/eqcomp} {#1} }

\cs_new:Npn \eb@itembox { \item\makebox }
\cs_new:Npn \eb_eqsymb_left_margin_calc:
  {
    \hbox_set:Nn \l_tmpa_box { \l__eb_eqsymb_delim_tl }
    \hbox_set:Nn \l_tmpb_box { \l__eb_eqsymb_intro_tl }
    \dim_set:Nn \l_tmpa_dim
      {
        \box_wd:N \l_tmpb_box +
        \l__eb_eqsymb_width_dim +
        \l__eb_eqsymb_space_dim +
        \box_wd:N \l_tmpa_box +
        \l__eb_eqsymb_space_dim
      }
  }
\NewDocumentEnvironment{eqcomp}{oD(){}+b}
  {
    \IfValueT{#1}{\keys_set:nn { eb/eqcomp } {#1}}
    \eb_eqsymb_left_margin_calc:
    \begin{eb@eqcomp@list}[#2]
      #3
    \end{eb@eqcomp@list}
  }{}
\NewDocumentCommand{\symb}{smO{\l__eb_eqsymb_delim_tl}}
  {
    \IfBooleanTF{#1}
      {
        \eb_eqsymb_left_margin_calc:
        \makebox
      }
      {\eb@itembox}[\l_tmpa_dim]
      {
        \makebox[\box_wd:N \l_tmpb_box]{\l__eb_eqsymb_intro_tl}
        \makebox[\l__eb_eqsymb_width_dim][\l__eb_eqsymb_item_align_tl]
          {
            \tl_use:N \l__eb_eqsymb_font_tl
              {
                \tl_if_eq:NnT \l__eb_eqsymb_mode_tl { math }
                  { \ensuremath }{#2}
              }
          }
        \hspace{\l__eb_eqsymb_space_dim}
        \makebox[\box_wd:N \l_tmpa_box][\l__eb_eqsymb_delim_align_tl]{#3}
        \hspace{\l__eb_eqsymb_space_dim}
      }
    \tl_clear:N \l__eb_eqsymb_intro_tl
    \ignorespaces
  }

\cs_new_protected:Npn \eb_thm_name_set:nnn #1#2#3
  {
    \tl_if_eq:NnTF \l__ctex_scheme_tl { chinese }
      { \tl_const:cn { c__eb_name_#1_tl } {#3} }
      { \tl_const:cn { c__eb_name_#1_tl } {#2} }
  }
\cs_set_eq:NN \eb@declaretheorem@save \declaretheorem
\cs_set_eq:NN \eb@declaretheoremsyle@save \declaretheoremstyle
\RenewDocumentCommand{\declaretheorem}{O{}mO{}}
  {\AfterPreamble{\eb@declaretheorem@save[#1,#3]{#2}}}
\RenewDocumentCommand{\declaretheoremstyle}{O{}mO{}}
  {\eb@declaretheoremsyle@save[#1,#3]{#2}}
\cs_set_eq:NN \newtheorem \declaretheorem
\NewDocumentCommand{\DeclareTheorem}
  {mO{\text_titlecase_first:n {#1}}mD(){tc-theorem}O{}}
  {
    \eb_thm_name_set:nnn {#1} {#2} {#3}
    \declaretheorem{#1}[
      name  = \tl_use:c { c__eb_name_#1_tl },
      style = easy-theorem,#5
      ]
    \bool_if:NT \l__eb_thmbox_bool
      {
        \@ifpackageloaded{tcolorbox}
          {\tcolorboxenvironment{#1}{#4}}{}
      }
    \labelformat{#1}{\tl_use:c { c__eb_name_#1_tl }~##1}
  }
\cs_set_eq:NN \EBNewTheorem \DeclareTheorem
\prop_new:N \l__eb_thmtools_entry_prop
\clist_const:Nn \c__eb_thmtools_entry_clist
  {
    spaceabove    = \l__eb_thm_spaceabove_tl,
    spacebelow    = \l__eb_thm_spacebelow_tl,
    headindent    = \l__eb_thm_headindent_tl,
    headfont      = \l__eb_thm_headfont_tl,
    notefont      = \l__eb_thm_notefont_tl,
    notebraces    = \l__eb_thm_notebraces_tl,
    bodyfont      = \l__eb_thm_bodyfont_tl,
    headpunct     = \l__eb_thm_headpunct_tl,
    postheadspace = \l__eb_thm_postheadspace_tl,
    within        = \l__eb_thm_within_tl,
    headformat    = \l__eb_thm_headformat_tl
  }
\prop_set_from_keyval:NV
\l__eb_thmtools_entry_prop \c__eb_thmtools_entry_clist
\prop_map_inline:Nn \l__eb_thmtools_entry_prop
  { \ctex_define:nn { thmset } { #1 .tl_set:N = #2 } }
\NewDocumentCommand{\eb_assign_tag_brackets:n}
  {>{\SplitArgument{1}{,}}m}
  {\eb_assign_tag_brackets_pos:nn #1}
\cs_new_protected:Npn \eb_assign_tag_brackets_pos:nn #1#2
  {
    \tl_set:Nn \eb@tag@brackets@left {#1}
    \tl_set:Nn \eb@tag@brackets@right {#2}
  }
\cs_gset:Npn \tagform@ #1
  {
    \maketag@@@
      {
        \color{ctex@emph}
        \eb@tag@brackets@left
        \ignorespaces #1\unskip\@@italiccorr
        \eb@tag@brackets@right
      }
  }
\ctex_define:nn { thmset }
  {
    thmbox .bool_set:N  = \l__eb_thmbox_bool,
    thmbox .default:n   = true,
    thmbox .initial:n   = false,
    brackets .code:n    = \eb_assign_tag_brackets:n {#1},
    brackets .initial:n = { (,) },
    unknown .code:n     = \eb_msg_unknown_option:n { thmset }
  }
\ctex_set:nn { thmset }
  {
    spaceabove    = 0.75ex plus .1ex,
    spacebelow    = 0.75ex plus .1ex,
    headindent    = 0em,
    headfont      = \color{ctex@emph}\sffamily,
    postheadspace = 1em,
    within        = \bool_if:NT \l__eb_class_book_bool { chapter },
    headformat    = \NAME\space\NUMBER\NOTE
  }
\eb_at_end_preamble:n
  {
    \exp_last_unbraced:NNV
    \declaretheoremstyle[\c__eb_thmtools_entry_clist]{easy-theorem}
    \eb_thm_name_set:nnn { exercise } { Exercise } { 练习 }
    \cs_undefine:N \proof
    \clist_map_inline:nn
      {
        { lemma } { 引理 },
        { example } { 例 },
        { theorem } { 定理 },
        { corollary } { 推论 },
        { definition } { 定义 },
        { proposition } { 性质 },
        { remark } { 注 } [ numbered = no ],
        { { proof } { 证明 } [ numbered = no,qed = \qedsymbol ] }
      }
      { \DeclareTheorem #1 }
  }

\setchemformula
  {
    math-scripts      = false,
    charge-hshift     = 0.25em,
    subscript-vshift  = -0.2ex
  }
\IfPackageAtLeastTF{siunitx}{2021/06/22}
  {
    \sisetup
      {
        mode = match,
        table-parse-only,
        text-family-to-math,
        text-series-to-math,
        reset-text-family   = false,
        reset-text-series   = false,
        reset-text-shape    = false,
        range-phrase  = \ensuremath{\sim},
        range-units   = single,
        group-digits  = none
      }
  }{}
\eb_at_begin_environment:nn
  {
    array,matrix,pmatrix,bmatrix,Bmatrix,vmatrix,Vmatrix,
    matrix*,pmatrix*,bmatrix*,Bmatrix*,vmatrix*,Vmatrix*,
    cases,cases*,dcases,dcases*,rcases,rcases*,drcases,drcases*,
    aligned,alignedat,gathered,multlined,lgathered,rgathered
  }
  {
    \linespread{\fp_use:N \l__eb_spread_math_fp}
    \selectfont\ignorespaces
  }
\eb_at_end_patch_cmd:nnn
  { \start@gather,\start@align,\start@multline }
  { \collect@body }
  {
    \linespread{\fp_use:N \l__eb_spread_math_fp}
    \selectfont\collect@body
  }
\eb_at_end_patch_cmd:nnn \gather@split
  { \spread@equation }
  {
    \linespread{\fp_use:N \l__eb_spread_math_fp}
    \selectfont\spread@equation
  }
\ctex_after_end_preamble:n
  {
    \skip_set:Nn \abovedisplayskip { 6pt plus 1pt minus 1pt }
    \skip_set:Nn \belowdisplayskip { 6pt plus 1pt minus 1pt }
    \skip_set:Nn \abovedisplayshortskip { 0pt plus 1pt minus 1pt }
    \skip_set:Nn \belowdisplayshortskip { 6pt plus 1pt minus 1pt }
  }
\ctex_at_end_package:nn { unicode-math }
  { \msg_redirect_module:nnn { unicode-math } { warning } { info } }

\keys_define:nn { eb/exercise }
  {
    color .tl_set:N   = \eb@tc@background@color,
    color .initial:n  = DeepSkyBlue,
    number .tl_set:N  = \eb@tc@list@number,
    number .initial:n = { 1. },
    title .tl_set:N   = \eb@tc@exercise@title,
    title .initial:n  = \c__eb_name_exercise_tl,
    numsep .dim_set:N = \eb@toc@exercise@numsep,
    numsep .initial:n = 0.5em,
    label .tl_set:N   = \eb@tc@exercise@label,
    enumitem .code:n  = \setexerlist{#1},
    tcolorbox .code:n = \tcbappstyle{exercise}{#1}
  }
\cs_new_protected:Npn \setexercise #1
  { \keys_set:nn { eb/exercise } {#1} }
\NewDocumentCommand{\tcbappstyle}{smm}
  {
    \IfBooleanTF{#1}
      {\tcbset{tc-#2/.style = {#3}}}
      {\tcbset{tc-#2/.append~style = {#3}}}
  }
\ctex_at_end_package:nn { tcolorbox }
  {
    \eb_package_date_check:nn { tcolorbox } { 2020/10/09 }
    \file_if_exist_input:n { eb-tcolorbox.cfg }
  }

\bool_set_true:N \l__eb_backend_bibtex_bool
\tl_new:N \l__eb_bib_all_style_tl
\tl_new:N \l__eb_bib_cite_style_tl
\clist_new:N \l__eb_bib_datafile_clist

\ctex_define:nn { bibset }
  {
    backend .choice:,
    backend .value_required:n   = true,
    backend/bibtex .code:n      = { },
    backend/biblatex .code:n    =
      { \bool_set_false:N \l__eb_backend_bibtex_bool },

    bib-style .code:n           =
      { \tl_set:Nn \l__eb_bib_all_style_tl {#1} },
    bib-style .value_required:n = true,
    bib-style .initial:n        = numerical,

    cite-style .code:n      =
      { \tl_set:Nn \l__eb_bib_cite_style_tl {#1} },
    datafile .clist_set:N   = \l__eb_bib_datafile_clist,
    bitoc-title .tl_set:N   = \l__eb_bib_en_bitoc_title_tl,
    bitoc-title .initial:n  = Reference,
    unknown .code:n = \eb_msg_unknown_option:n { bibset }
  }

\cs_new_protected:Npn \eb_natbib_bibtex_set:
  {
    \LoadPackage[sort&compress]{natbib}
    \str_case:VnTF \l__eb_bib_all_style_tl
      {
        { numerical }
        {
          \bibliographystyle{gbt7714-numerical}
          \setcitestyle{comma,square,super}
        }
        { authoryear }
        { \bibliographystyle{gbt7714-author-year} }
      }
      { \cs_set_eq:NN \cite \citep }
      { \exp_args:NV \bibliographystyle \l__eb_bib_otherstyle_tl }
    \tl_if_empty:NF \l__eb_bib_cite_style_tl
      { \exp_args:NV \setcitestyle \l__eb_bib_cite_style_tl }
    \skip_zero:N \bibsep
    \AtEndEnvironment{thebibliography}
      {\bool_if:NT \l__eb_toc_multi_column_bool { \end{multicols} }}
    \NewDocumentCommand{\printbibliography}{st+o}
      {
        \group_begin:
        \tl_set_eq:NN \eb@toc@title \bibname
        \IfValueT{##3}{ \keys_set:nn { eb/listoc } {##3} }
        \tl_set:Nn \bibsection
          {
            \eb_title_number_intoc_spec:nn {##2} {##1}
            \bool_if:NT \l__eb_toc_multi_column_bool
              { \begin{multicols}{\int_use:N \l__eb_toc_columns_int} }
          }
        \exp_args:NV \bibliography \l__eb_bib_datafile_clist
        \group_end:
      }
  }
\cs_new_protected:Npn \eb_put_biblatex:n #1
  { \PassOptionsToPackage{#1}{biblatex} }
\cs_new_protected:Npn \eb_biblatex_biber_set:
  {
    \str_case:VnF \l__eb_bib_all_style_tl
      {
        { numerical } { \use_i:nnn }
        { authoryear } { \use_ii:nnn }
      }
      { \use_iii:nnn }
      { \eb_put_biblatex:n { style = gb7714-2015 } }
      { \eb_put_biblatex:n { style = gb7714-2015ay } }
      { \eb_put_biblatex:n { style = \l__eb_bib_all_style_tl } }
    \tl_if_empty:NF \l__eb_bib_cite_style_tl
      { \eb_put_biblatex:n { citestyle = \l__eb_bib_cite_style_tl } }
    \LoadPackage[backend = biber]{biblatex}
    \clist_map_function:NN \l__eb_bib_datafile_clist \addbibresource
    \tl_gset:Nn \blx@default@theheading { bibintoc }
    \defbibheading{bibintoc}[\bibname]
      {\eb_biber_title_level_spec:n {##1}}
    \skip_zero:N \bibitemsep
  }
\eb_at_end_preamble:n
  {
    \clist_if_empty:NF \l__eb_bib_datafile_clist
      {
        \bool_if:NTF \l__eb_backend_bibtex_bool
          { \eb_natbib_bibtex_set: }
          { \eb_biblatex_biber_set: }
      }
  }

\cs_new:Npn \eb@lst@if@display #1#2
  { \lst@ifdisplaystyle #1\else #2\fi }
\lstdefinestyle{easy-listings}
  {
    language      = [LaTeX]TeX,
    texcsstyle    = *\color{ctex@verb}\bfseries,
    basicstyle    =
      {
        \ttfamily
        \eb@lst@if@display{\small}{\color{ctex@verb}}
      },
    keywordstyle  =
      {
        \color{ctex@verb}
        \eb@lst@if@display{\bfseries}{}
      },
    framexleftmargin  = 0pt,
    framexrightmargin = 0pt,
    xleftmargin       = 3pt,
    xrightmargin      = 3pt,
    numbersep         = 10pt,
    framesep          = 3pt,
    frame             = single,
    rulecolor         = \color{ctex@frame},
    commentstyle      = \color{SlateGray},
    emphstyle         = \color{ctex@emph}
  }
\lstset
  {
    style         = easy-listings,
    breaklines    = true,
    resetmargins  = true,
    % numbers       = left,
    numberstyle   = \footnotesize,
    aboveskip     = 1.5ex plus .2ex minus .1ex,
    belowskip     = 1.5ex plus .2ex minus .1ex,
    keepspaces    = true,
    framerule     = \l__eb_rule_width_dim,
    columns       = flexible,
    abovecaptionskip  = -1ex,
    belowcaptionskip  = 1.5ex
  }
\lstloadlanguages{C,C++,Java,Python,Matlab}

\clist_new:N \l__eb_hyperref_clist
\cs_new_protected:Npn \eb_put_hyperref:n #1
  { \clist_put_right:Nn \l__eb_hyperref_clist {#1} }
\cs_new_protected:Npn \eb_define_link_color:nnn #1#2#3
  { \definecolorset{HTML}{ctex@}{}{link,#1;url,#2;cite,#3} }
\cs_new_protected:Npn \eb_define_theme_color:nnn #1#2#3
  { \definecolorset{HTML}{ctex@}{}{frame,#1;emph,#2;verb,#3} }
\cs_new_protected:Npn \eb_define_link_color:n #1
  { \definecolorset{HTML}{ctex@}{}{link,#1;url,#1;cite,#1} }
\cs_new_protected:Npn \eb_define_theme_color:n #1
  { \definecolorset{HTML}{ctex@}{}{frame,#1;emph,#1;verb,#1} }
\cs_new_protected:Npn \DeclareLinkColor #1
  { \ctex_define:nx { refset } { \eb_link_color_set:n {#1} } }
\cs_new_protected:Npn \DeclareThemeColor #1
  { \ctex_define:nx { style } { \eb_theme_color_set:n {#1} } }
\clist_map_inline:nn
  {
    { linkcolor,link },
    { color,theme }
  }
  {
    \cs_new:cpn { eb_\clist_item:nn {#1} { 2 }_color_set:n } ##1
      {
        \clist_item:nn {#1} { 1 }/\clist_item:nn {##1} { 1 } .code:n =
          {
            \use:c { eb_define_\clist_item:nn {#1} { 2 }_color:nnn }
              { \clist_item:nn {##1} { 2 } }
              { \clist_item:nn {##1} { 3 } }
              { \clist_item:nn {##1} { 4 } }
          },
      }
  }

\bool_set_false:N \l__eb_toc_number_color_bool
\ctex_define:nn { refset }
  {
    linktype .choice:,
    linktype .value_required:n  = true,
    linktype/edge .code:n       =
      { \AtBeginDocument[hyperref]{\tl_set:Nn \@pdfborder { 0~0~1 }} },
    linktype/none .code:n       =
      { \AtBeginDocument[hyperref]{\tl_set:Nn \@pdfborder { 0~0~0 }} },
    linktype/colors .code:n     =
      {
        \bool_set_true:N \l__eb_toc_number_color_bool
        \eb_put_hyperref:n { colorlinks }
      },
    linktype/various .meta:n    = linktype/colors,
    linktype .initial:n         = edge,

    linktoc .choice:,
    linktoc/unknown .code:n =
      {
        \eb_put_hyperref:n { linktoc = #1 }
        \clist_map_inline:nn { page,none }
          {
            \tl_if_eq:NnT \l_keys_value_tl {##1}
              {
                \colorlet{ctex@toc@number}{black}
                \clist_map_break:
              }
          }
      },
    linktoc .default:n      = all,
    linktoc .initial:n      = all,
    unknown .code:n         =
      {
        \eb_put_hyperref:x
          {
            \l_keys_key_str
            \tl_if_empty:NF \l_keys_value_tl { = {#1} }
          }
      }
  }
\ctex_define:nx { refset }
  {
    linkcolor .choice:,
    \clist_map_function:nN
      {
        { fresh,     62d71f,0000B2,005752 },
        { cutepink,  ff69b4,9d5196,57b5e5 },
        { navyblue,  000080,004986,eb6877 },
        { crimson,   dc143c,00c1c9,afcd20 }
      }
      \eb_link_color_set:n
    linkcolor .default:n  = navyblue,
    linkcolor .initial:n  = navyblue,
    linkcol-all .code:n   =
      { \eb_define_link_color:n { \exp_not:n {#1} } }
  }
\colorlet{ctex@toc@number}{ctex@link}
\ctex_define:nx { style }
  {
    color .choice:,
    color .value_required:n = true,
    \clist_map_function:nN
      {
        { none,      000000,000000,000000 },
        { seaside,   4169e1,9932cc,eb6100 },
        { energy,    f39800,00a0e9,893895 },
        { cyberpunk, 601986,eb6877,a4005b }
      }
      \eb_theme_color_set:n
    color .initial:n  = none,
    color-all .code:n =
      { \eb_define_theme_color:n { \exp_not:n {#1} } }
  }

\cs_new:Npn \eb_allow_url_break:
  {
    \eb_appto_cmd:Nn \UrlBreaks
      {
        \UrlOrds
        \tl_map_function:NN \c__eb_url_break_points_tl \do
      }
  }
\tl_const:Nn \c__eb_url_break_points_tl
  {
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    abcdefghijklmnopqrstuvwxyz
    0123456789
  }
\ctex_at_end_preamble:n
  {
    \LoadPackage{hyperref}
    \urlstyle{same}
    \eb_allow_url_break:
    \eb_put_hyperref:n
      {
        linkcolor = ctex@link,linkbordercolor = ctex@link,
        urlcolor  = ctex@url,urlbordercolor   = ctex@url,
        citecolor = ctex@cite,citebordercolor = ctex@cite
      }
    \exp_args:NV \hypersetup \l__eb_hyperref_clist
  }

\labelformat{part}{\CTEXthepart}
\labelformat{chapter}{\CTEXthechapter}
\labelformat{figure}{\figurename~#1}
\labelformat{table}{\tablename~#1}
\cs_if_free:NT \bibname { \cs_set_eq:NN \bibname \refname }
\ctex_define:n
  {
    lstlistlistingname .tl_set:N  = \listlstlistingname,
    lstlistingname .tl_set:N      = \lstlistingname
  }
\tl_if_eq:NnTF \l__ctex_scheme_tl { chinese }
  {
    \keys_set_known:nn { ctex }
      {
        contentsname        = 目\hspace{1em}录,
        indexname           = 索\hspace{1em}引,
        abstractname        = 摘\hspace{1em}要,
        listfigurename      = 图片索引,
        listtablename       = 表格索引,
        lstlistlistingname  = 代码索引,
        lstlistingname      = 代码
      }
    \labelformat{equation}{式（#1）}
    \labelformat{section}{节 #1}
    \labelformat{subsection}{小节 #1}
  }
  {
    \keys_set_known:nn { ctex }
      {
        abstractname        = Abstract,
        lstlistlistingname  = List~of~Codes,
        lstlistingname      = Code
      }
    \labelformat{equation}{Equation~(#1)}
    \labelformat{section}{Section~#1}
    \labelformat{subsection}{Subsection~#1}
  }
\endinput
%%
%% End of file `easybase.sty'.
