%%
%% This is file `easybook.cls',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% easybook.dtx  (with options: `class')
%% 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}
\ProvidesExplClass{easybook}{2021/04/18}{1.24n}{beta}

\cs_generate_variant:Nn \__ctex_define:nn {nx}
\cs_generate_variant:Nn \int_to_arabic:n {v}
\cs_generate_variant:Nn \dim_add:Nn {NV}
\cs_generate_variant:Nn \__eb_put_hyperref:n {x}
\cs_new_protected:Npn \__ctex_define:nn #1
  {\keys_define:nn {ctex/#1}}
\cs_new_protected:Npn \__eb_put_ctexbook:n #1
  {\PassOptionsToClass{#1}{ctexbook}}
\cs_new_protected:Npn \__eb_patch_cmd:Nnn #1#2#3
  {\ctex_patch_cmd_once:NnnnTF #1{}{#2}{#3}{}{\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_end_preamble:n
  {\ctex_gadd_ltxhook:nn {env/document/before}}

\bool_set_false:N \l__eb_draft_bool
\bool_set_false:N \l__eb_newline_bool
\bool_set_false:N \l__eb_font_noto_bool
\bool_set_true:N  \l__eb_zhtitle_bool
\bool_set_true:N  \l__eb_page_twoside_bool
\bool_set_true:N  \l__eb_class_book_bool
\clist_new:N      \g__eb_options_clist

\keys_define:nn {easybook}
  {
    draft         .code:n = \bool_set_true:N  \l__eb_draft_bool,
    newline       .code:n = \bool_set_true:N  \l__eb_newline_bool,
    entitle       .code:n = \bool_set_false:N \l__eb_zhtitle_bool,
    scheme        .code:n = \__eb_put_ctexbook:n {scheme = #1},
    enstyle       .meta:n = {newline,entitle,scheme = plain},

    font          .choices:nn =
      {adobe,founder,mac,windows,none}
      {\__eb_put_ctexbook:n {fontset = \l_keys_choice_tl}},
    font/noto     .code:n =
      {
        \bool_set_true:N \l__eb_font_noto_bool
        \__eb_put_ctexbook:n {fontset = none}
      },
    font/overleaf .code:n = {},
    font/linux    .code:n = \__eb_put_ctexbook:n {fontset = ubuntu},
    font          .value_required:n = true,
    font          .initial:n = overleaf,

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

    oneside       .value_forbidden:n = true,
    twoside       .value_forbidden:n = true,
    oneside       .code:n =
      {
        \bool_set_false:N \l__eb_page_twoside_bool
        \__eb_put_ctexbook:n {oneside}
      },
    twoside       .code:n =
      {
        \bool_set_true:N \l__eb_page_twoside_bool
        \__eb_put_ctexbook:n {twoside}
      },

    class         .choice:,
    class         .value_required:n = true,
    class/book    .code:n = {},
    class/article .code:n =
      {
        \bool_set_false:N \l__eb_class_book_bool
        \keys_set:nn {easybook}{oneside}
      },
    class         .initial:n = book,

    unknown       .code:n =
      {\clist_gput_right:No \g__eb_options_clist{\CurrentOption}}
  }

\ProcessKeysOptions{easybook}

\clist_map_inline:nn
  {
    {svgnames}{xcolor},
    {hang,stable}{footmisc},
    {normalem}{ulem},
    {protrusion = false}{microtype},
    {list = off}{bicaption},
    {shortlabels,inline}{enumitem},
    {many}{tcolorbox},
    {xindy}{imakeidx},
    {CJKmath = true}{xeCJK},
    {no-math}{fontspec},
    {noto,upint}{newtxmath}
  }{\PassOptionsToPackage#1}
\__eb_put_ctexbook:n {\g__eb_options_clist}
\LoadClass[UTF8]{ctexbook}

\bool_new:N \l__eb_multoc_bool
\bool_new:N \l__eb_notomath_bool
\bool_new:N \l__eb_uppercase_bool
\bool_new:N \l__eb_chap_withpart_bool
\tl_new:N   \l__eb_foot_numberwith_tl
\tl_new:N   \g__eb_config_tl

\seq_const_from_clist:Nn \c__eb_options_path_seq
  {
    style,link,elsefont,
    spread,bibset,thmset,
    geoset,hdrset,tocset
  }
\seq_map_inline:Nn \c__eb_options_path_seq
  {
    \ctex_define:n {#1  .meta:nn = {ctex/#1}{##1}}
    \cs_new:cpn {#1}##1{\keys_set:nn {ctex/#1}{##1}}
  }
\ctex_define:n
  {
    config              .tl_set:N = \g__eb_config_tl,
    lstlistlistingname  .tl_set:N = \lstlistlistingname,
    lstlistingname      .tl_set:N = \lstlistingname
  }
\__ctex_define:nn {style}
  {
    multoc        .bool_set:N = \l__eb_multoc_bool,
    multoc        .default:n = true,
    withpart      .bool_set:N = \l__eb_chap_withpart_bool,
    withpart      .default:n = true,
    withpart      .initial:n = false,
    notomath      .bool_set:N = \l__eb_notomath_bool,
    notomath      .default:n = true,
    notomath      .initial:n = true,
    rulewidth     .dim_set:N = \l__eb_rule_width_dim,
    rulewidth     .initial:n = 0.75pt,
    uppercase     .bool_set:N = \l__eb_uppercase_bool,
    uppercase     .default:n = true,
    uppercase     .initial:n = true,

    footwith      .choices:nn =
      {part,page,chapter}
      {\tl_set_eq:NN \l__eb_foot_numberwith_tl\l_keys_choice_tl},
    footwith      .value_required:n = true,
    footwith      .initial:n = chapter,

    figure-sep    .tl_set:N = \l__eb_figure_separator_tl,
    table-sep     .tl_set:N = \l__eb_table_separator_tl,
    listing-sep   .tl_set:N = \l__eb_lstlisting_separator_tl,
    equation-sep  .tl_set:N = \l__eb_equation_separator_tl,
    number-sep    .meta:n =
      {
        figure-sep = {#1},table-sep = {#1},
        listing-sep = {#1},equation-sep = {#1}
      },
    number-sep    .initial:n = {.}
  }

\RequirePackage
  {
    xcolor,
    footmisc,setspace,
    amsmath,amsthm,thmtools,cases,
    chemformula,siunitx,ulem,pifont,
    geometry,marginnote,nccfoots,
    pdfpages,graphicx,
    fancyhdr,titletoc,
    caption-light,subcaption,
    tabularx,multirow,booktabs,
    enumitem,
    listings
  }
\ctex_at_end_preamble:n
  {
    \bool_if:NT \l__eb_notomath_bool{\RequirePackage{newtxmath,bm}}
    \tl_if_empty:NF \g__eb_config_tl{\file_input:n {\g__eb_config_tl}}
  }

\cs_new_protected:Npn \__eb_package_later_bool:nn #1#2
  {
    \@ifpackagelater{#1}{#2}
      {}{\msg_warning:nnn {easybook}{package-old}{#1}}
  }
\msg_new:nnn {easybook}{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},
    {ctex}{2020/10/19},
    {thmtools}{2020/08/01},
    {caption-light}{2020/08/24}
  }{\__eb_package_later_bool:nn #1}

\sys_if_engine_xetex:TF
  {
    \cs_new_eq:NN \__eb_set_family:nnn  \xeCJK_set_family:nnn
    \cs_new_eq:NN \__eb_switch_family:n \xeCJK_switch_family:n
  }{
    \cs_new_eq:NN \__eb_set_family:nnn  \ctex_ltj_set_family:nnn
    \cs_new_eq:NN \__eb_switch_family:n \ctex_ltj_switch_family:n
  }

\cs_new_protected:Npn \__eb_setmainfont:nn #1#2
  {\__fontspec_main_setmainfont:nn {#2}{#1}}
\cs_new_protected:Npn \__eb_setsansfont:nn #1#2
  {\__fontspec_main_setsansfont:nn {#2}{#1}}
\cs_new_protected:Npn \__eb_setmonofont:nn #1#2
  {\__fontspec_main_setmonofont:nn {#2}{#1}}
\cs_new_protected:Npn \__eb_setCJKmainfont:nn #1#2
  {\__eb_set_family:nnn {\CJKrmdefault}{#2}{#1}}
\cs_new_protected:Npn \__eb_setCJKsansfont:nn #1#2
  {\__eb_set_family:nnn {\CJKsfdefault}{#2}{#1}}
\cs_new_protected:Npn \__eb_setCJKmonofont:nn #1#2
  {\__eb_set_family:nnn {\CJKttdefault}{#2}{#1}}
\cs_new_protected:Npn \__eb_set_zhfont_songti:nn #1#2
  {\__eb_set_family:nnn {songti}{#2}{#1}}
\cs_new_protected:Npn \__eb_set_zhfont_heiti:nn #1#2
  {\__eb_set_family:nnn {heiti}{#2}{#1}}
\cs_new_protected:Npn \__eb_set_zhfont_kaishu:nn #1#2
  {\__eb_set_family:nnn {kaishu}{#2}{#1}}
\cs_new_protected:Npn \__eb_set_zhfont_fangsong:nn #1#2
  {\__eb_set_family:nnn {fangsong}{#2}{#1}}

\tl_const:Nn \__eb_option_zhfont_tl
  {UprightFont = *,AutoFakeBold = 1.5,ItalicFont = *}
\cs_new_protected:Npx \__eb_setCJKmainfont:n #1
  {\__eb_setCJKmainfont:nn {#1}{\__eb_option_zhfont_tl}}
\cs_new_protected:Npx \__eb_setCJKsansfont:n #1
  {\__eb_setCJKsansfont:nn {#1}{\__eb_option_zhfont_tl}}
\cs_new_protected:Npx \__eb_setCJKmonofont:n #1
  {\__eb_setCJKmonofont:nn {#1}{\__eb_option_zhfont_tl}}
\cs_new_protected:Npx \__eb_set_zhfont_songti:n #1
  {\__eb_set_zhfont_songti:nn {#1}{\__eb_option_zhfont_tl}}
\cs_new_protected:Npx \__eb_set_zhfont_heiti:n #1
  {\__eb_set_zhfont_heiti:nn {#1}{\__eb_option_zhfont_tl}}
\cs_new_protected:Npx \__eb_set_zhfont_kaishu:n #1
  {\__eb_set_zhfont_kaishu:nn {#1}{\__eb_option_zhfont_tl}}
\cs_new_protected:Npx \__eb_set_zhfont_fangsong:n #1
  {\__eb_set_zhfont_fangsong:nn {#1}{\__eb_option_zhfont_tl}}

\bool_if:NT \l__eb_font_noto_bool
  {
    \__eb_setmainfont:nn {NotoSerif}
      {
        Extension = .ttf,
        UprightFont = *-Regular,
        BoldFont = *-Bold,
        ItalicFont = *-Italic
      }
    \__eb_setsansfont:nn {NotoSans}
      {
        Extension = .ttf,
        UprightFont = *-Regular,
        BoldFont = *-Bold,
        ItalicFont = *-Italic
      }
    \__eb_setmonofont:nn {NotoSansMono}
      {
        Extension = .ttf,
        UprightFont = *-Regular,
        BoldFont = *-Bold
      }
    \__eb_setCJKmainfont:nn {FZShuSong-Z01S}
      {
        UprightFont = *,
        BoldFont = FZHei-B01S,
        ItalicFont = FZKai-Z03S
      }
    \__eb_setCJKsansfont:n {FZHei-B01S}
    \__eb_setCJKmonofont:n {FZFangSong-Z02S}
    \__eb_set_zhfont_songti:n {FZShuSong-Z01S}
    \__eb_set_zhfont_heiti:n {FZHei-B01S}
    \__eb_set_zhfont_kaishu:n {FZKai-Z03S}
    \__eb_set_zhfont_fangsong:n {FZFangSong-Z02S}
    \cs_new_protected:Npn \songti{\__eb_switch_family:n {songti}}
    \cs_new_protected:Npn \heiti{\__eb_switch_family:n {heiti}}
    \cs_new_protected:Npn \kaishu{\__eb_switch_family:n {kaishu}}
    \cs_new_protected:Npn \fangsong{\__eb_switch_family:n {fangsong}}
  }
\__eb_at_end_preamble:n
  {\cs_if_exist:NF \kaishu{\cs_gset_eq:NN \kaishu\normalfont}}

\includepdfset{fitpaper = true}
\geometry
  {
    vmargin = 2.54cm,
    hmargin = 3.17cm,
    columnsep = 2\ccwd,
    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}
  {
    footnotemargin  .dim_set:N = \footnotemargin,
    footnotemargin  .initial:n = 0.5\ccwd,
    footparskip     .tl_set:N = \hangfootparskip,
    footparskip     .initial:n = 0ex,
    footparindent   .tl_set:N = \hangfootparindent,
    footparindent   .initial:n = 2\ccwd,
    list-labelsep   .dim_set:N = \eb@list@labelsep,
    list-labelsep   .initial:n = \ccwd,
    unknown         .code:n =
      {
        \clist_gput_right:Nx \g__eb_geometry_clist
          {
            \l_keys_key_str
            \tl_if_empty:NF \l_keys_value_tl{ = {#1}}
          }
      }
  }

\RenewDocumentCommand{\cleardoublepage}{O{empty}}
  {
    \clearpage
    \bool_if:NT \l__eb_page_twoside_bool
      {
        \int_if_odd:nF {\c@page}
          {\hbox:n {}\thispagestyle{#1}\clearpage}
      }
  }
\RenewDocumentCommand{\frontmatter}{sO{Roman}}
  {
    \IfBooleanTF{#1}{\clearpage}{\cleardoublepage}
    \@mainmatterfalse
    \pagenumbering{#2}
  }
\RenewDocumentCommand{\mainmatter}{s}
  {
    \IfBooleanTF{#1}{\clearpage}{\cleardoublepage}
    \@mainmattertrue
    \pagenumbering{arabic}
  }
\cs_gset_eq:NN \easyhead\fancyhead
\cs_gset_eq:NN \easyfoot\fancyfoot
\__ctex_define:nn {hdrset}
  {
    head-foot     .tl_set:N = \l__eb_fancyhf_content_tl,
    head-foot     .initial:n =
      {
        \bool_if:NTF \l__eb_page_twoside_bool
          {
            \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_chap_mark:n #1,
    chap-mark     .initial:n =
      {
        \int_compare:nT {\c@secnumdepth > -1}
          {
            \if@mainmatter
              \ifodd\CTEX@chapter@numbering
                \CTEXthechapter\hspace{\ccwd}
              \fi
            \fi
          }#1
      },
    sec-mark      .cs_set:Np = \__eb_fancyhf_sec_mark:n #1,
    sec-mark      .initial:n =
      {
        \int_compare:nT {\c@secnumdepth > 0}
          {
            \ifodd\CTEX@section@numbering
              \CTEXthesection\hspace{0.5\ccwd}
            \fi
          }#1
      },
    subsec-mark   .cs_set:Np = \__eb_fancyhf_subsec_mark:n #1,
    subsec-mark   .initial:n =
      {
        \int_compare:nT {\c@secnumdepth > 1}
          {
            \ifodd\CTEX@subsection@numbering
              \CTEXthesubsection\hspace{0.5\ccwd}
            \fi
          }#1
      },

    headrule      .tl_gset:N = \headrule,
    headrule      .initial:n =
      {
        \group_begin:
        \color{ctex@frame}\vspace*{1.5pt}
        \hrule width \textwidth height \l__eb_rule_width_dim
        \group_end:
      },
    footrule      .tl_gset:N = \footrule,
    footrule      .initial:n = {},
    footnoterule  .tl_gset:N = \footnoterule,
    footnoterule  .initial:n =
      {
        \group_begin:
        \color{ctex@frame}
        \hrule width 0.35\columnwidth height \l__eb_rule_width_dim
        \vspace*{2.6pt}
        \group_end:
      }
  }
\cs_new:Npn \__eb_upper_chaptermark_bool:n #1
  {
    \bool_if:NTF \l__eb_uppercase_bool
      {\text_uppercase:n {\__eb_fancyhf_chap_mark:n {#1}}}
      {\text_titlecase_first:n {\__eb_fancyhf_chap_mark:n {#1}}}
  }
\cs_new:Npn \__eb_upper_sectionmark_bool:n #1
  {
    \bool_if:NTF \l__eb_uppercase_bool
      {\text_uppercase:n {\__eb_fancyhf_sec_mark:n {#1}}}
      {\text_titlecase_first:n {\__eb_fancyhf_sec_mark:n {#1}}}
  }
\cs_new:Npn \__eb_upper_subsectionmark_bool:n #1
  {
    \bool_if:NTF \l__eb_uppercase_bool
      {\text_uppercase:n {\__eb_fancyhf_subsec_mark:n {#1}}}
      {\text_titlecase_first:n {\__eb_fancyhf_subsec_mark:n {#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}
    \bool_if:NTF \l__eb_class_book_bool
      {
        \bool_if:NTF \l__eb_page_twoside_bool
          {
            \cs_gset:Npn \chaptermark#1
              {
                \markboth
                  {\__eb_upper_chaptermark_bool:n {#1}}
                  {\__eb_upper_chaptermark_bool:n {#1}}
              }
          }{
            \cs_gset:Npn \chaptermark#1
              {\markboth{\__eb_upper_chaptermark_bool:n {#1}}{}}
          }
        \cs_gset:Npn \sectionmark#1
          {\markright{\__eb_upper_sectionmark_bool:n {#1}}}
      }{
        \bool_if:NTF \l__eb_page_twoside_bool
          {
            \cs_gset:Npn \sectionmark#1
              {
                \markboth
                  {\__eb_upper_sectionmark_bool:n {#1}}
                  {\__eb_upper_sectionmark_bool:n {#1}}
              }
          }{
            \cs_gset:Npn \sectionmark#1
              {\markboth{\__eb_upper_sectionmark_bool:n {#1}}{}}
          }
        \cs_gset:Npn \subsectionmark#1
          {\markright{\__eb_upper_subsectionmark_bool:n {#1}}}
      }
    \bool_if:NT \l__eb_draft_bool
      {
        \bool_if:NTF \l__eb_page_twoside_bool
          {\easyfoot[C]{\color{SlateGray}\sffamily\today}}
          {\easyhead[C]{\color{SlateGray}\sffamily\today}}
        \geometry{showframe}
      }
  }

\seq_const_from_clist:Nn \c__eb_toc_headings_level_seq
  {part,chapter,section,subsection,lists}
\seq_map_inline:Nn \c__eb_toc_headings_level_seq
  {
    \ctex_define:n {tocset/#1 .meta:nn = {ctex/tocset/#1}{##1}}
    \__ctex_define:nn {tocset}
      {
        #1/format .tl_set:c = l__toc_#1_format_tl,
        #1/indent .tl_set:c = l__toc_#1_indent_tl,
        #1/rule   .tl_set:c = l__toc_#1_rule_tl
      }
  }
\__ctex_define:nn {tocset}
  {
    lists/lolskip     .skip_set:N = \l__eb_toc_lolskip_skip,
    lists/lolskip     .initial:n = 0.8pc,
    lists/belowoffset .dim_set:N = \l__eb_toc_listsoffset_dim,
    lists/belowoffset .initial:n = 0pc,
    tocline-fig       .cs_set:Np = \eb@labelname@lof#1#2,
    tocline-fig       .initial:n =
      {\figurename\space#1\hspace{\eb@list@labelsep}#2},
    tocline-tab       .cs_set:Np = \eb@labelname@lot#1#2,
    tocline-tab       .initial:n =
      {\tablename\space#1\hspace{\eb@list@labelsep}#2},
    tocline-lst       .tl_set:N = \eb@labelname@lol,
    tocline-lst       .initial:n =
      {
        \lstlistingname\space
        \thelstlisting\hspace{\eb@list@labelsep}
        \lstcaption
      },
    belowoffset       .dim_set:N = \l__eb_toc_offset_dim,
    belowoffset       .initial:n = -1pc,
    line-align        .bool_set:N = \l__eb_toc_line_align_bool,
    line-align        .default:n = true,
    line-align        .initial:n = true
  }
\ctex_set:nn {tocset}
  {
    part/format = \addvspace{1pc}\sffamily\large,
    part/indent = 0\ccwd,
    part/rule = \tocrule{}[\bfseries],

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

    section/format = \addvspace{0.35pc},
    section/indent = 1.5\ccwd,
    section/rule = \tocrule{$\cdot$},

    subsection/format = \addvspace{0.35pc},
    subsection/indent = 3.8\ccwd,
    subsection/rule = \tocrule{$\cdot$},

    lists/format = \addvspace{0.2pc},
    lists/indent = 0\ccwd,
    lists/rule = \tocrule{$\cdot$}
  }

\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}
      }
  }
\cs_new_protected:Npn \__eb_titlecontents_set:nn #1#2
  {
    \titlecontents{#1}
      [\use:c {l__toc_#2_indent_tl}]
      {\use:c {l__toc_#2_format_tl}}{}{}
      {\use:c {l__toc_#2_rule_tl}}
  }
\contentsuse{lstlisting}{lol}
\clist_map_inline:nn
  {
    {part}{part},
    {chapter}{chapter},
    {section}{section},
    {subsection}{subsection},
    {figure}{lists},
    {table}{lists},
    {lstlisting}{lists}
  }{\__eb_titlecontents_set:nn #1}

\prop_new:N \l_label_name_prop
\prop_set_from_keyval:Nn \l_label_name_prop
  {
    figure = \eb@labelname@lof,
    table = \eb@labelname@lot
  }
\cs_gset:Npn \caption@@@addcontentsline#1#2#3#4
  {
    \addcontentsline{#1}{#2}
      {\prop_item:Nn \l_label_name_prop{#2}{#3}{#4}}
  }
\ctex_patch_cmd:Nnn \lst@MakeCaption
  {
    \addcontentsline{lol}{lstlisting}
      {\protect\numberline{\thelstlisting}\lst@@caption}
  }{
    \let\lstcaption\lst@@caption
    \addcontentsline{lol}{lstlisting}{\eb@labelname@lol}
  }
\__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}}
      }
    \bool_if:NF \l__eb_class_book_bool
      {\msg_error:nn {easybook}{no-chapter}}
  }
\__eb_appto_cmd:Nn \@schapter
  {
    \bool_if:NF \l__eb_class_book_bool
      {\msg_error:nn {easybook}{no-chapter}}
  }
\msg_new:nnn {easybook}{no-chapter}
  {
    Your~document~class~is~in~article~mode. \\
    The~\string\chapter\space~command~will~not~be~used.
  }

\cs_new_protected:Npn \__eb_uppercase_bool:n #1
  {
    \bool_if:NTF \l__eb_uppercase_bool
      {\text_uppercase:n {#1}}
      {\text_titlecase_first:n {#1}}
  }
\cs_new_protected:Npn \eb@markdouble#1
  {
    \bool_if:NTF \l__eb_page_twoside_bool
      {
        \markboth
          {\__eb_uppercase_bool:n {#1}}
          {\__eb_uppercase_bool:n {#1}}
      }{\markboth{\__eb_uppercase_bool:n {#1}}{}}
  }

\tl_set:Nn \l__eb_toc_type_tl{book}
\keys_define:nn {listoc}
  {
    article .code:n = \tl_set:Nn \l__eb_toc_type_tl{article},
    book    .code:n = {},
    multoc  .bool_set:N = \l__eb_multoc_bool,
    multoc  .default:n = true,
    multoc  .initial:n = false,
    title   .tl_set:N = \eb@toc@title
  }

\cs_new_protected:Npn \__eb_title_mark_intoc:n #1
  {
    \tl_if_eq:NnTF \l__eb_toc_type_tl{book}
      {
        \chapter*{\phantomsection#1}
        \CTEX@addtocline{chapter}{#1}
      }{
        \section*{\phantomsection#1}
        \CTEX@addtocline{section}{#1}
      }
    \eb@markdouble{#1}
  }
\cs_new_protected:Npn \__eb_title_mark_notoc:n #1
  {
    \tl_if_eq:NnTF \l__eb_toc_type_tl{book}
      {\chapter*{\phantomsection#1}}
      {\section*{\phantomsection#1}}
    \eb@markdouble{#1}
  }
\cs_new_protected:Npn \__eb_class_title_bool:n #1
  {
    \bool_if:NTF \l__eb_class_book_bool
      {
        \chapter*{\phantomsection#1}
        \CTEX@addtocline{chapter}{#1}
      }{
        \section*{\phantomsection#1}
        \CTEX@addtocline{section}{#1}
      }
    \eb@markdouble{#1}
  }
\cs_new_protected:Npn \__eb_multoc_pre_bool:
  {
    \bool_if:NTF \l__eb_class_book_bool
      {
        \if@twocolumn
          \@restonecoltrue
          \bool_if:NTF \l__eb_multoc_bool{\twocolumn}{\onecolumn}
        \else
          \@restonecolfalse
          \bool_if:NT \l__eb_multoc_bool{\twocolumn}
        \fi
      }{\tl_set:Nn \l__eb_toc_type_tl{article}}
  }
\cs_new_protected:Npn \__eb_multoc_post_bool:
  {
    \bool_if:NTF \l__eb_class_book_bool
      {
        \if@restonecol
          \twocolumn
        \else
          \onecolumn
        \fi
      }{\tl_set:Nn \l__eb_toc_type_tl{article}}
  }
\cs_new_protected:Npn \__eb_title_intoc_bool:n #1
  {
    \IfBooleanTF{#1}
      {\__eb_title_mark_notoc:n {\eb@toc@title}}
      {\__eb_title_mark_intoc:n {\eb@toc@title}}
  }
\RenewDocumentCommand{\tableofcontents}{o}
  {
    \group_begin:
    \tl_set_eq:NN \eb@toc@title\contentsname
    \IfValueT{#1}{\keys_set:nn {listoc}{#1}}
    \__eb_multoc_pre_bool:
    \__eb_title_mark_notoc:n {\eb@toc@title}
    \vspace*{\dim_use:N \l__eb_toc_offset_dim}
    \@starttoc{toc}
    \__eb_multoc_post_bool:
    \group_end:
  }
\RenewDocumentCommand{\listoffigures}{so}
  {
    \group_begin:
    \tl_set_eq:NN \eb@toc@title\listfigurename
    \IfValueT{#2}{\keys_set:nn {listoc}{#2}}
    \__eb_multoc_pre_bool:
    \__eb_title_intoc_bool:n {#1}
    \dim_add:NV \l__eb_toc_offset_dim\l__eb_toc_listsoffset_dim
    \vspace*{\dim_use:N \l__eb_toc_offset_dim}
    \@starttoc{lof}
    \__eb_multoc_post_bool:
    \group_end:
  }
\RenewDocumentCommand{\listoftables}{so}
  {
    \group_begin:
    \tl_set_eq:NN \eb@toc@title\listtablename
    \IfValueT{#2}{\keys_set:nn {listoc}{#2}}
    \__eb_multoc_pre_bool:
    \__eb_title_intoc_bool:n {#1}
    \dim_add:NV \l__eb_toc_offset_dim\l__eb_toc_listsoffset_dim
    \vspace*{\dim_use:N \l__eb_toc_offset_dim}
    \@starttoc{lot}
    \__eb_multoc_post_bool:
    \group_end:
  }
\NewDocumentCommand{\listoflistings}{so}
  {
    \group_begin:
    \tl_set_eq:NN \eb@toc@title\lstlistlistingname
    \IfValueT{#2}{\keys_set:nn {listoc}{#2}}
    \__eb_multoc_pre_bool:
    \__eb_title_intoc_bool:n {#1}
    \dim_add:NV \l__eb_toc_offset_dim\l__eb_toc_listsoffset_dim
    \vspace*{\dim_use:N \l__eb_toc_offset_dim}
    \@starttoc{lol}
    \__eb_multoc_post_bool:
    \group_end:
  }

\ctex_at_end_package:nn {imakeidx}
  {
    \makeindex[
      intoc,
      options = -M~texindy~-C~utf8,
      program = truexindy,
      columns = 2,
      columnsep = 2\ccwd
      ]
    \indexsetup
      {
        level = \bool_if:NTF \l__eb_class_book_bool{\chapter*}{\section*},
        toclevel = \bool_if:NTF \l__eb_class_book_bool{chapter}{section},
        firstpagestyle = \bool_if:NTF \l__eb_class_book_bool{plain}{fancy}
      }
    \ctex_patch_cmd:Nnn \imki@indexheaders
      {\@mkboth{\MakeUppercase\indexname}{\MakeUppercase\indexname}}
      {\eb@markdouble{\indexname}}
  }

\tl_new:N \l__eb_font_table_tl
\tl_new:N \l__eb_font_figure_tl
\tl_new:N \l__eb_font_listing_tl
\tl_new:N \l__eb_font_footnote_tl

\__ctex_define:nn {elsefont}
  {
    table-cap   .tl_set:N = \l__eb_font_table_tl,
    table-cap   .initial:n = \sffamily\small,
    figure-cap  .tl_set:N = \l__eb_font_figure_tl,
    figure-cap  .initial:n = \sffamily\small,
    listing-cap .tl_set:N = \l__eb_font_listing_tl,
    listing-cap .initial:n = \sffamily\small,
    footnote    .tl_set:N = \l__eb_font_footnote_tl,
    footnote    .initial:n = \rmfamily,
    marginpar   .tl_set:N = \marginfont,
    marginpar   .initial:n = \rmfamily\footnotesize
  }

\DeclareCaptionLabelSeparator{ccwd}{\hspace{\ccwd}}
\DeclareCaptionLabelFormat{parens}{\bothIfFirst{#1}{~}(#2)}
\DeclareCaptionFont{eb@table@font}{\l__eb_font_table_tl}
\DeclareCaptionFont{eb@figure@font}{\l__eb_font_figure_tl}
\DeclareCaptionFont{eb@listing@font}{\l__eb_font_listing_tl}
\captionsetup
  {
    format = hang,
    % figurewithin = section,
    % tablewithin = section,
    font = {stretch = {\fp_use:N \l__eb_spread_caption_fp}},
    labelfont = {color = ctex@frame},
    labelsep = ccwd,
    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}
  }
\cs_new:Npn \__eb_arabic:n #1{\int_to_arabic:v {c@#1}}
\cs_new_protected:Npn \__eb_separator_set:n #1
  {
    \cs_set:cpn {the#1}
      {
        \int_compare:nT {\c@chapter > 0}
          {
            \thechapter
            \use:c {l__eb_#1_separator_tl}
          }
        \__eb_arabic:n {#1}
      }
  }
\cs_gset:cpn {thesection}
  {
    \int_compare:nT {\c@chapter > 0}{\thechapter.}
    \__eb_arabic:n {section}
  }
\clist_map_inline:nn
  {figure,table,lstlisting,equation}
  {\__eb_separator_set:n {#1}}
\cs_gset_protected:Npn \appendix
  {
    \int_compare:nNnTF {\c@chapter} > {0}
      {
        \setcounter{chapter}{0}
        \setcounter{section}{0}
        \gdef\thechapter{\@Alph\c@chapter}
        \gdef\CTEX@prechapter{\CTEX@preappendix}
        \gdef\CTEX@thechapter{\CTEX@appendix@number}
        \gdef\CTEX@postchapter{\CTEX@postappendix}
        \gdef\CTEX@chapter@numbering{\CTEX@appendix@numbering}
      }{
        \setcounter{section}{0}
        \setcounter{subsection}{0}
        \gdef\thesection{\@Alph\c@section}
        \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 = {}}
      }
  }
\AtBeginEnvironment{tabularx}
  {
    \exp_args:Nx \linespread{\fp_use:N \l__eb_spread_table_fp}
    \selectfont\ignorespaces
  }
\AtBeginEnvironment{tabular}
  {
    \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
  }

\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,
    footnote  .fp_set:N = \l__eb_spread_footnote_fp,
    footnote  .initial:n = 1
  }

\skip_set:Nn \parskip{0pt plus 2pt minus 1pt}
\skip_set:Nn \floatsep{12pt plus 2pt minus 2pt}
\skip_set:Nn \intextsep{14pt plus 2pt minus 2pt}
\skip_set:Nn \textfloatsep{16pt plus 2pt minus 4pt}
\skip_set:Nn \dbltextfloatsep{16pt plus 2pt minus 4pt}
\skip_set:Nn \@fpsep{8pt plus 2.0fil}
\setcounter{topnumber}{4}
\setcounter{bottomnumber}{4}
\setcounter{totalnumber}{8}
\cs_gset:Npn \textfraction{0.18}
\cs_gset:Npn \topfraction{0.85}
\cs_gset:Npn \bottomfraction{0.65}
\cs_gset:Npn \floatpagefraction{0.60}

\newcolumntype{L}{X}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\graphicspath{{figures/}}
\DeclareGraphicsExtensions{.pdf,.png,.jpg,.eps,.tif}

\cs_new_protected:Npn \__eb_enumitem_labelval_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_labelval_set:nn #1}
\SetEnumitemValue{font}{sf}{\color{ctex@emph}\normalfont\sffamily}
\setlist
  {
    labelsep = .75\ccwd,listparindent = 2\ccwd,leftmargin = *,
    itemsep = .75ex plus .1ex,topsep = .75ex plus .1ex,
    partopsep = 0ex,parsep = 0ex
  }
\newlist{outlinelist}{itemize}{1}
\setlist[outlinelist]{label = outline,itemsep = .5ex plus .1ex}
\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 = \arabic{enumi}.\alph*}
\setlist[enumerate,3]{label = roman,ref = \arabic{enumi}.\alph{enumii}.\roman*}
\setlist*[enumerate,3]{labelwidth = *}
\setlist[description]{font = sf,labelwidth = *,leftmargin = 2\ccwd}

\cs_new_protected:Npn \__eb_thmname_set:nnn #1#2#3
  {
    \tl_if_eq:NnTF \l__ctex_scheme_tl{chinese}
      {\tl_const:cn {c__eb_name_#1_tl}{#2}}
      {\tl_const:cn {c__eb_name_#1_tl}{#3}}
  }
\clist_map_inline:nn
  {
    {example}{例}{Example},
    {definition}{定义}{Definition},
    {theorem}{定理}{Theorem},
    {proposition}{性质}{Proposition},
    {lemma}{引理}{Lemma},
    {corollary}{推论}{Corollary},
    {remark}{注}{Remark},
    {exercise}{练习}{Exercise}
  }{\__eb_thmname_set:nnn #1}

\bool_new:N \l__eb_thmbox_bool
\tl_new:N \l__eb_thm_numberwith_tl
\tl_new:N \l__eb_thm_headpunct_tl
\tl_new:N \l__eb_thm_bodyfont_tl
\tl_new:N \l__eb_thm_notefont_tl
\tl_new:N \l__eb_thm_headindent_tl
\tl_new:N \l__eb_thm_spaceabove_tl
\tl_new:N \l__eb_thm_spacebelow_tl

\RenewDocumentCommand{\newtheorem}{O{}m}
  {\AfterPreamble{\declaretheorem[#1]{#2}}}
\__ctex_define:nn {thmset}
  {
    thmbox      .bool_set:N = \l__eb_thmbox_bool,
    thmbox      .default:n = true,
    thmbox      .initial:n = false,
    within      .tl_set:N = \l__eb_thm_numberwith_tl,
    within      .initial:n = \bool_if:NT \l__eb_class_book_bool{chapter},
    bodyfont    .tl_set:N = \l__eb_thm_bodyfont_tl,
    bodyfont    .initial:n = {},
    notefont    .tl_set:N = \l__eb_thm_notefont_tl,
    notefont    .initial:n = {},
    headfont    .tl_set:N = \l__eb_thm_headfont_tl,
    headfont    .initial:n = \color{ctex@emph}\sffamily,
    headpunct   .tl_set:N = \l__eb_thm_headpunct_tl,
    headpunct   .initial:n = {},
    spacepost   .tl_set:N = \l__eb_thm_spacepost_tl,
    spacepost   .initial:n = \ccwd,
    headindent  .tl_set:N = \l__eb_thm_headindent_tl,
    headindent  .initial:n = 0\ccwd,
    spaceabove  .tl_set:N = \l__eb_thm_spaceabove_tl,
    spaceabove  .initial:n = .75ex plus .1ex,
    spacebelow  .tl_set:N = \l__eb_thm_spacebelow_tl,
    spacebelow  .initial:n = .75ex plus .1ex
  }
\tl_const:Nn \c__eb_thmtools_keyval_tl
  {
    [
      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 = {}{},
      bodyfont = \l__eb_thm_bodyfont_tl,
      headpunct = \l__eb_thm_headpunct_tl,
      postheadspace = \l__eb_thm_spacepost_tl,
      within = \l__eb_thm_numberwith_tl,
      headformat = \NAME\space\NUMBER\NOTE
    ]
  }
\ctex_at_end_preamble:n
  {
    \exp_args:NNc \exp_after:wN
    \declaretheoremstyle{c__eb_thmtools_keyval_tl}{easy-thm-sty}
    \clist_map_inline:nn
      {
        example,definition,theorem,
        proposition,lemma,corollary
      }{
        \declaretheorem[
          style = easy-thm-sty,
          name = \use:c {c__eb_name_#1_tl}
          ]{#1}
      }
    \cs_undefine:N \proof
    \declaretheorem[
      style = easy-thm-sty,
      name = \c__eb_name_remark_tl,
      numbered = no
      ]{remark}
    \declaretheorem[
      style = easy-thm-sty,
      name = \proofname,
      numbered = no,
      qed = \qedsymbol
      ]{proof}
  }

\ctex_at_end_package:nn {tasks}
  {
    \settasks
      {
        label = (\Alph*),
        after-item-skip = 0ex plus .1ex,
        column-sep = .5\ccwd,
        item-indent = 2\ccwd,
        label-width = 1.5\ccwd
      }
  }
\setchemformula
  {
    math-scripts = false,
    charge-hshift = 0.25\ccwd,
    subscript-vshift = -0.2ex
  }
\sisetup
  {
    detect-family,
    detect-weight,
    detect-shape,
    detect-inline-family = math,
    detect-inline-weight = math,
    detect-display-math,
    range-phrase = \ensuremath{\sim},
    range-units = single,
    table-parse-only,
    group-digits = false
  }
\allowdisplaybreaks[4]
\cs_gset:Npn \ULthickness{.75pt}
\skip_set:Nn \jot{4pt plus 1pt minus 1pt}
\cs_new_protected:Npn \l__eb_math_restore:n #1
  {
    \AtBeginEnvironment{#1}
      {\linespread{\fp_use:N \l__eb_spread_math_fp}\selectfont\ignorespaces}
  }
\clist_map_inline: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
  }{\l__eb_math_restore:n {#1}}
\__eb_patch_cmd:Nnn \start@gather
  {\collect@body}
  {\linespread{\fp_use:N \l__eb_spread_math_fp}\selectfont\collect@body}
\__eb_patch_cmd:Nnn \start@align
  {\collect@body}
  {\linespread{\fp_use:N \l__eb_spread_math_fp}\selectfont\collect@body}
\__eb_patch_cmd:Nnn \start@multline
  {\collect@body}
  {\linespread{\fp_use:N \l__eb_spread_math_fp}\selectfont\collect@body}
\__eb_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{5pt plus 1pt minus 1pt}
    \skip_set:Nn \belowdisplayskip{5pt plus 1pt minus 1pt}
    \skip_set:Nn \abovedisplayshortskip{0pt}
    \skip_set:Nn \belowdisplayshortskip{5pt plus 1pt minus 1pt}
  }
\cs_gset:Npn \tagform@#1
  {\maketag@@@{\color{ctex@emph}(\ignorespaces#1\unskip\@@italiccorr)}}
\ctex_at_end_package:nn {unicode-math}
  {\msg_redirect_module:nnn {unicode-math}{warning}{none}}

\ctex_at_end_package:nn {tcolorbox}
  {
    \__eb_package_later_bool:nn {tcolorbox}{2020/10/09}
    \tcbset
      {
        tc-theorem/.style =
          {
            enhanced~jigsaw,pad~at~break* = 3pt,
            opacityback = 0,
            colframe = ctex@emph,
            left = 6pt,right = 6pt,top = 8pt,bottom = 8pt,middle= 8pt,
            arc = 0pt
          },
        tc-outline/.style =
          {
            enhanced,nofloat,
            tikznode~boxed~title,
            interior~style = white,colframe = ctex@emph,
            colbacktitle = white,coltitle = ctex@emph,
            fonttitle = \large\sffamily,fontupper = \itshape,
            boxed~title~style = {size = normal,opacityframe = 0,boxrule = 0pt},
            attach~boxed~title~to~top~center = {yshift = -\tcboxedtitleheight/2},
            arc = 3pt,boxsep = 5pt,
            after~skip = 3ex,
            left = 1.5pc,right = 1.5pc,top = 1pc,bottom = 0.5pc
          },
        tc-exercise/.style =
          {
            enhanced,on~line,
            fontupper = \sffamily\Large,
            boxrule = 1pt,arc = 5pt,
            left = 6pt,right = 6pt,top = 3.5pt,bottom = 3.5pt,
            before~skip = 4ex,after~skip = 2.25ex
          },
        breakable,
        boxsep = 0pt,
        boxrule = \l__eb_rule_width_dim
      }
    \NewDocumentEnvironment{outline}{D(){\abstractname}o+b}
      {
        \begin{tcolorbox}[tc-outline,title = #1,IfValueT = {#2}{#2}]
          \begin{outlinelist}
            #3
          \end{outlinelist}
        \end{tcolorbox}
      }{}
    \NewDocumentEnvironment{exercise}
      {sO{LightYellow}O{1.}D(){\c__eb_name_exercise_tl}o+b}
      {
        \begin{center}
          \bool_if:NTF \l__eb_thmbox_bool
            {
              \tcbox[
                tc-exercise,
                colback = #2,colframe = black,
                drop~fuzzy~shadow = #2,
                IfValueT = {#5}{#5},
                phantom =
                  \IfBooleanF{#1}
                    {
                      \CTEX@ifnametrue
                      \refstepcounter{section}
                      \markright{\CTEXthesection\hspace{0.5\ccwd}#4}
                      \CTEX@addtocline{section}{#4}
                    }
                ]{\IfBooleanF{#1}{\CTEXthesection\hspace{0.5\ccwd}}#4}
            }{
              \color{ctex@frame}\sffamily\Large
              \IfBooleanF{#1}
                {
                  \CTEX@ifnametrue
                  \refstepcounter{section}
                  \markright{\CTEXthesection\hspace{0.5\ccwd}#4}
                  \CTEX@addtocline{section}{#4}
                  \CTEXthesection\hspace{0.5\ccwd}
                }#4
            }
        \end{center}
        \begin{enumerate}[#3,labelsep = 0.5\ccwd]
          #6
        \end{enumerate}
      }{}
    \DeclareTColorBox{easybox}{sO{DarkCyan}d()O{}}
      {
        enhanced~jigsaw,pad~at~break* = 3pt,
        IfBooleanTF = {#1}
          {toptitle = 8pt,top = 8pt}
          {frame~hidden,boxrule = 0pt,toptitle = 8pt,top = 0pt},
        IfValueT = {#3}{title = #3},
        colback = #2!8!white,colbacktitle = #2!8!white,
        coltitle = black,colframe = black,
        fonttitle = \sffamily,
        left = 6pt,right = 6pt,bottom = 8pt,middle= 8pt,
        bottomtitle = 8pt,arc = 0pt,
        beforeafter~skip = 2ex,
        halign~upper = left,halign~lower = left,
        center~title,#4
      }
    \DeclareTColorBox{ebparbox}{sO{Purple}d()O{}}
      {
        frame~hidden,
        enhanced~jigsaw,pad~at~break* = 3pt,
        boxrule = 0pt,
        borderline~west = {3pt}{0pt}{#2},
        IfBooleanTF = {#1}
          {
            colback = white,
            IfValueT = {#3}{title = #3},
            top = 0pt,bottom = 0pt,toptitle = 0pt
          }{
            colback = #2!8!white,colbacktitle = #2!8!white,
            IfValueTF = {#3}{title = #3,top = 0pt}{top = 8pt},
            bottom = 8pt,toptitle = 8pt
          },
        left = 8pt,right = 8pt,middle= 8pt,
        bottomtitle = 8pt,arc = 0pt,
        beforeafter~skip = 1.5ex,
        colframe = #2,coltitle = #2,
        fonttitle = \sffamily,#4
      }
    \DeclareTotalTCBox{\fuzzy}{O{DarkSeaGreen}vO{}}
      {
        nobeforeafter,tcbox~raise~base,
        blank,fuzzy~halo = 2pt~with~#1,#3
      }{#2}
    \DeclareTotalTCBox{\concise}{O{Aqua}vO{}}
      {
        nobeforeafter,tcbox~raise~base,
        top = 2pt,bottom = 2.5pt,left = 2pt,right = 2pt,
        boxsep = 0pt,boxrule = 0.75pt,arc = 1pt,
        colback = #1!15!white,#3
      }{#2}
  }
\ctex_at_end_preamble:n
  {
    \bool_if:NT \l__eb_thmbox_bool
      {
        \@ifpackageloaded{tcolorbox}
          {
            \tcolorboxenvironment{theorem}{tc-theorem}
            \tcolorboxenvironment{definition}{tc-theorem}
            \tcolorboxenvironment{lemma}{tc-theorem}
            \tcolorboxenvironment{corollary}{tc-theorem}
            \tcolorboxenvironment{proposition}{tc-theorem}
            \tcolorboxenvironment{example}{tc-theorem}
          }{}
      }
  }

\bool_set_true:N \l__eb_backend_bibtex_bool
\tl_new:N \l__eb_bib_style_tl
\tl_new:N \l__eb_bib_otherstyle_tl
\tl_new:N \l__eb_bib_citestyle_tl
\tl_new:N \l__eb_bib_file_tl

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

    bib-style             .choice:,
    bib-style             .value_required:n = true,
    bib-style/numerical   .code:n =
      {
        \tl_set:Nn  \l__eb_bib_style_tl{#1}
        \tl_clear:N \l__eb_bib_otherstyle_tl
      },
    bib-style/authoryear  .code:n =
      {
        \tl_set:Nn  \l__eb_bib_style_tl{#1}
        \tl_clear:N \l__eb_bib_otherstyle_tl
      },
    bib-style/unknown     .code:n =
      {\tl_set_eq:NN \l__eb_bib_otherstyle_tl\l_keys_value_tl},
    bib-style             .initial:n = numerical,

    cite-style            .code:n =
      {\tl_set:Nn \l__eb_bib_citestyle_tl{#1}},
    bibfile               .tl_set:N = \l__eb_bib_file_tl,
    bibfile               .initial:n = refs.bib,

    bib-loadpkg           .bool_set:N = \l__eb_bib_loadpkg_bool,
    bib-loadpkg           .default:n = true,
    bib-loadpkg           .initial:n = true
  }

\cs_new_protected:Npn \EbBibtexSet
  {
    \tl_if_empty:NTF \l__eb_bib_otherstyle_tl
      {
        \tl_if_eq:NnT \l__eb_bib_style_tl{numerical}
          {
            \bibliographystyle{gbt7714-numerical}
            \setcitestyle{comma,square,super}
          }
        \tl_if_eq:NnT \l__eb_bib_style_tl{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_citestyle_tl
      {\exp_args:NV \setcitestyle\l__eb_bib_citestyle_tl}
    \skip_set:Nn \bibsep{0ex}
    \NewDocumentCommand{\printbibliography}{so}
      {
        \group_begin:
        \tl_set_eq:NN \eb@toc@title\bibname
        \IfValueT{##2}{\keys_set:nn {listoc}{##2}}
        \__eb_multoc_pre_bool:
        \cs_set:Npn \bibsection{\__eb_title_intoc_bool:n {##1}}
        \exp_args:NV \bibliography\l__eb_bib_file_tl
        \__eb_multoc_post_bool:
        \group_end:
      }
  }
\cs_new_protected:Npn \__eb_put_biblatex:n #1
  {\PassOptionsToPackage{#1}{biblatex}}
\cs_new_protected:Npn \EbBiblatexPreset
  {
    \tl_if_empty:NTF \l__eb_bib_otherstyle_tl
      {
        \tl_if_eq:NnT \l__eb_bib_style_tl{numerical}
          {\__eb_put_biblatex:n {style = gb7714-2015}}
        \tl_if_eq:NnT \l__eb_bib_style_tl{authoryear}
          {\__eb_put_biblatex:n {style = gb7714-2015ay}}
      }{\__eb_put_biblatex:n {style = \l__eb_bib_otherstyle_tl}}
    \tl_if_empty:NF \l__eb_bib_citestyle_tl
      {\__eb_put_biblatex:n {citestyle = \l__eb_bib_citestyle_tl}}
    \__eb_put_biblatex:n {backend = biber}
  }
\cs_new_protected:Npn \EbBiblatexPostset
  {
    \exp_args:NV \addbibresource\l__eb_bib_file_tl
    \cs_gset:Npn \blx@default@theheading{bibintoc}
    \cs_gset:Npn \blx@warning@noline##1{}
    \defbibheading{bibintoc}[\bibname]{\__eb_class_title_bool:n {##1}}
    \skip_set:Nn \bibitemsep{0ex}
  }
\__eb_at_end_preamble:n
  {
    \bool_if:NT \l__eb_bib_loadpkg_bool
      {
        \bool_if:NTF \l__eb_backend_bibtex_bool
          {
            \RequirePackage[sort&compress]{natbib}
            \EbBibtexSet
          }{
            \EbBiblatexPreset
            \RequirePackage{biblatex}
            \EbBiblatexPostset
          }
      }
  }

\__eb_at_end_preamble:n
  {
    \group_begin:
    \footnotesize
    \exp_args:Nx
    \linespread{\fp_use:N \l__eb_spread_footnote_fp}\selectfont
    \skip_gset:Nn \footnotesep{\ht\strutbox}
    \group_end:
    \bool_if:NT \l__eb_chap_withpart_bool
      {\counterwithin*{chapter}{part}}
    \tl_if_eq:NnT \l__eb_foot_numberwith_tl{part}
      {
        \counterwithout*{footnote}{chapter}
        \counterwithin*{footnote}{part}
      }
    \tl_if_eq:NnT \l__eb_foot_numberwith_tl{page}
      {
        \counterwithout*{footnote}{chapter}
        \counterwithin*{footnote}{page}
      }
  }
\__eb_patch_cmd:Nnn \@footnotetext
  {\reset@font}
  {
    \def\baselinestretch{\fp_use:N \l__eb_spread_footnote_fp}
    \l__eb_font_footnote_tl
  }
\__eb_patch_cmd:Nnn \@mpfootnotetext
  {\reset@font}
  {
    \def\baselinestretch{\fp_use:N \l__eb_spread_footnote_fp}
    \l__eb_font_footnote_tl
  }
\__eb_patch_cmd:Nnn \@makefnmark
  {\normalfont}{\l__eb_font_footnote_tl}
\cs_gset:Npn \thempfootnote{\int_to_alph:n {\c@mpfootnote}}

\lstdefinestyle{easy-lst-sty}
  {
    language = [LaTeX]TeX,
    texcsstyle =
      {
        *\lst@ifdisplaystyle
          \bfseries\color{ctex@verb}
        \else
          \color{ctex@verb}
        \fi
      },
    basicstyle =
      {
        \ttfamily\lst@ifdisplaystyle
          \small
        \else
          \color{ctex@verb}
        \fi
      },
    keywordstyle =
      {
        \lst@ifdisplaystyle
          \bfseries\color{ctex@verb}
        \else
          \color{ctex@verb}
        \fi
      },
    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},
    emph = {caption,multirow,subcaption,tabularx},
    morekeywords =
      {
        includegraphics,setmainfont,setsansfont,setmonofont,setCJKmainfont,setCJKsansfont,setCJKmonofont,setCJKfamilyfont,RequirePackage
      }
  }
\lstset
  {
    style = easy-lst-sty,
    breaklines = true,
    resetmargins = true,
    % numbers = left,
    numberstyle = \footnotesize,
    abovecaptionskip = -1ex,
    belowcaptionskip = 1.5ex,
    aboveskip = 1.5ex plus .2ex minus .1ex,
    belowskip = 0.55ex plus .2ex minus .1ex,
    keepspaces = true,
    framerule = \l__eb_rule_width_dim,
    columns = flexible
  }
\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_linkcolor:nnn #1#2#3
  {\definecolorset{HTML}{ctex@}{}{link,#1;url,#2;cite,#3}}
\cs_new_protected:Npn \__eb_define_themecolor:nnn #1#2#3
  {\definecolorset{HTML}{ctex@}{}{frame,#1;emph,#2;verb,#3}}
\cs_new_protected:Npn \__eb_define_linkcolor:n #1
  {\definecolorset{HTML}{ctex@}{}{link,#1;url,#1;cite,#1}}
\cs_new_protected:Npn \__eb_define_themecolor:n #1
  {\definecolorset{HTML}{ctex@}{}{frame,#1;emph,#1;verb,#1}}
\cs_new:Npn \__eb_linkcolor_set:n #1
  {
    linkcolor/\clist_item:nn {#1}{1} .code:n =
      {
        \__eb_define_linkcolor:nnn
          {\clist_item:nn {#1}{2}}
          {\clist_item:nn {#1}{3}}
          {\clist_item:nn {#1}{4}}
        \__eb_put_hyperref:n
          {
            linkcolor = ctex@link,linkbordercolor = ctex@link,
            urlcolor = ctex@url,urlbordercolor = ctex@url,
            citecolor = ctex@cite,citebordercolor = ctex@cite
          }
      },
  }
\cs_new:Npn \__eb_themecolor_set:n #1
  {
    color/\clist_item:nn {#1}{1} .code:n =
      {
        \__eb_define_themecolor:nnn
          {\clist_item:nn {#1}{2}}
          {\clist_item:nn {#1}{3}}
          {\clist_item:nn {#1}{4}}
      },
  }

\cs_new:Npn \__eb_allow_urlbreak:
  {
    \cs_new:Npn \__eb_add_urlbreak_points:
      {\tl_map_function:NN \c__eb_urlbreak_points_tl\do}
    \__eb_appto_cmd:Nn
      \UrlBreaks{\UrlOrds\__eb_add_urlbreak_points:}
  }
\tl_const:Nn \c__eb_urlbreak_points_tl
  {
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    abcdefghijklmnopqrstuvwxyz
    0123456789
  }

\__ctex_define:nx {link}
  {
    hyperlink         .choice:,
    hyperlink/edge    .code:n = {},
    hyperlink/various .code:n = \__eb_put_hyperref:n {colorlinks},
    hyperlink/none    .code:n = \__eb_put_hyperref:n {hidelinks},
    hyperlink         .default:n = edge,
    hyperlink         .initial:n = edge,

    linkcolor         .choice:,
    \clist_map_function:nN
      {
        {fresh,     62d71f,0000B2,005752},
        {cutepink,  ff69b4,9d5196,57b5e5},
        {navyblue,  000080,004986,eb6877},
        {crimson,   dc143c,00c1c9,afcd20}
      }
      \__eb_linkcolor_set:n
    linkcolor         .default:n = navyblue,
    linkcolor         .initial:n = navyblue,
    linkcol-all       .code:n = \__eb_define_linkcolor:n {\exp_not:n {#1}},

    linktoc           .choice:,
    linktoc/unknown   .code:n =
      {\__eb_put_hyperref:n {linktoc = \exp_not:n {#1}}},
    linktoc           .default:n = all,
    linktoc           .initial:n = all,
    unknown           .code:n =
      {
        \__eb_put_hyperref:x
          {
            \exp_not:N \l_keys_key_str
            \exp_not:N \tl_if_empty:NF
            \exp_not:N \l_keys_value_tl{ = \exp_not:n {#1}}
          }
      }
  }
\__ctex_define:nx {style}
  {
    color     .choice:,
    color     .value_required:n = true,
    \clist_map_function:nN
      {
        {none,      000000,000000,000000},
        {seaside,   4169e1,708090,9932cc},
        {energy,    f39800,00a0e9,893895},
        {cyberpunk, 601986,eb6877,a4005b}
      }
      \__eb_themecolor_set:n
    color     .initial:n = none,
    color-all .code:n = \__eb_define_themecolor:n {\exp_not:n {#1}}
  }

\ctex_at_end_preamble:n
  {
    \RequirePackage{hyperref}
    \urlstyle{same}
    \__eb_allow_urlbreak:
    \ctex_hypersetup:n {pdfstartview = FitH}
    \exp_args:NV \hypersetup\l__eb_hyperref_clist
    \labelformat{part}{\CTEXthepart}
    \labelformat{chapter}{\CTEXthechapter}
    \tl_if_eq:NnTF \l__ctex_scheme_tl{chinese}
      {
        \keys_set_known:nn {ctex}
          {
            contentsname = 目\hspace{\ccwd}录,
            indexname = 索\hspace{\ccwd}引,
            listfigurename = 图片索引,
            listtablename = 表格索引,
            abstractname = 摘\hspace{\ccwd}要,
            lstlistlistingname = 代码索引,
            lstlistingname = 代码
          }
        \labelformat{equation}{式（#1）}
        \labelformat{align}{式（#1）}
        \labelformat{multline}{式（#1）}
        \labelformat{gather}{式（#1）}
        \labelformat{figure}{图#1}
        \labelformat{table}{表#1}
        \labelformat{section}{节#1}
        \labelformat{subsection}{小节#1}
        \labelformat{theorem}{定理#1}
        \labelformat{definition}{定义#1}
        \labelformat{lemma}{引理#1}
        \labelformat{corollary}{推论#1}
        \labelformat{proposition}{性质#1}
        \labelformat{example}{例#1}
      }{
        \keys_set_known:nn {ctex}
          {
            abstractname = Abstract,
            lstlistlistingname = List~of~Codes,
            lstlistingname = Code
          }
        \labelformat{equation}{Equation~(#1)}
        \labelformat{align}{Equation~(#1)}
        \labelformat{multline}{Equation~(#1)}
        \labelformat{gather}{Equation~(#1)}
        \labelformat{figure}{Figure~#1}
        \labelformat{table}{Table~#1}
        \labelformat{section}{Section~#1}
        \labelformat{subsection}{Subsection~#1}
        \labelformat{theorem}{Theorem~#1}
        \labelformat{definition}{Definition~#1}
        \labelformat{lemma}{Lemma~#1}
        \labelformat{corollary}{Corollary~#1}
        \labelformat{proposition}{Proposition~#1}
        \labelformat{example}{Example~#1}
      }
  }

\ctex_set:n
  {
    secnumdepth = 3,
    tocdepth = 1,
    part =
      {
        pagestyle = empty,
        number =
          {\bool_if:NTF \l__eb_zhtitle_bool{\chinese{part}}{\thepart}},
        format = \color{ctex@frame}\sffamily\Huge,
        aftername =
          {\bool_if:NTF \l__eb_newline_bool{\par\nobreak}{\hspace{\ccwd}}},
        tocline = \CTEXifname{\CTEXthepart\hspace{\ccwd}}{}#2
      },
    chapter =
      {
        % pagestyle = fancy,
        number =
          {\bool_if:NTF \l__eb_zhtitle_bool{\chinese{chapter}}{\thechapter}},
        format =
          {
            \color{ctex@frame}\sffamily\LARGE
            \bool_if:NF \l__eb_newline_bool{\centering}
          },
        aftername =
          {
            \bool_if:NTF \l__eb_newline_bool
              {\par\nobreak\vskip 1.5pc}{\hspace{\ccwd}}
          },
        beforeskip = -1.5ex,
        afterskip = 3ex,
        lotskip = 0.8pc,
        lofskip = 0.8pc,
        tocline = \CTEXifname{\CTEXthechapter\hspace{\ccwd}}{}#2
      },
    section =
      {
        hang = true,
        format = \color{ctex@frame}\sffamily\Large,
        aftername = \hspace{0.5\ccwd},
        beforeskip = 1.5ex plus .2ex minus .1ex,
        afterskip = 1.5ex plus .2ex minus .1ex,
        tocline = \CTEXifname{\CTEXthesection\hspace{\ccwd}}{}#2
      },
    subsection =
      {
        hang = true,
        format = \color{ctex@frame}\sffamily\large,
        aftername = \hspace{0.5\ccwd},
        beforeskip = 1.3ex plus .2ex minus .1ex,
        afterskip = 1.3ex plus .2ex minus .1ex,
        tocline = \CTEXifname{\CTEXthesubsection\hspace{\ccwd}}{}#2
      },
    subsubsection =
      {
        hang = true,
        format = \color{ctex@frame}\sffamily,
        aftername = \hspace{0.5\ccwd},
        beforeskip = \parskip,
        afterskip = \parskip
      }
  }

\bool_if:NF \l__eb_newline_bool
  {
    \ctex_set:n
      {
        part/hang = true,
        chapter/hang = true
      }
  }
\endinput
%%
%% End of file `easybook.cls'.
