%%
%% 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 <texeasybook@foxmail.com>
%% This work may be distributed and/or modified under the
%% conditions of the CC-BY-NC 4.0 License.
%% Gitee: https://gitee.com/TeX-doc/easybook
%% Github: https://github.com/TeX-doc/easybook
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{l3keys2e}
\ProvidesExplClass{easybook}{2021/01/03}{v1.0}{}

\cs_generate_variant:Nn \keys_define:nn {nx}
\cs_generate_variant:Nn \int_to_arabic:n {v}
\cs_new_protected:Npn \__appto_cmd:Nn #1#2
  {\ctex_appto_cmd:NnnTF #1{}{#2}{}{\ctex_patch_failure:N #1}}

\bool_set_false:N \l__draft_bool
\bool_set_false:N \l__newline_bool
\bool_set_false:N \l__enstyle_bool
\bool_set_true:N  \l__zhtitle_bool
\bool_set_true:N  \l__myfont_bool
\bool_set_true:N  \l__lang_chinese_bool
\bool_set_false:N \l__paper_bfive_bool
\bool_set_true:N  \l__paper_afour_bool
\bool_set_true:N  \l__page_twoside_bool
\bool_new:N       \l__thmbox_bool
\bool_new:N       \l__capdash_bool
\bool_new:N       \l__multoc_bool
\bool_new:N       \l__chap_withpart_bool
\bool_new:N       \l__foot_perpart_bool
\clist_new:N      \g__hyperref_clist
\clist_new:N      \g__options_clist

\keys_define:nn {easybook}
  {
    draft         .code:n = {\bool_set_true:N  \l__draft_bool},
    newline       .code:n = {\bool_set_true:N  \l__newline_bool},
    enstyle       .code:n = {\bool_set_true:N  \l__enstyle_bool},
    entitle       .code:n = {\bool_set_false:N \l__zhtitle_bool},
    english       .code:n = {\bool_set_false:N \l__lang_chinese_bool},

    font          .choice:,
    font/adobe    .code:n =
      {
        \PassOptionsToClass{fontset = #1}{ctexbook}
        \bool_set_false:N \l__myfont_bool
      },
    font/founder  .code:n =
      {
        \PassOptionsToClass{fontset = #1}{ctexbook}
        \bool_set_false:N \l__myfont_bool
      },
    font/mac      .code:n =
      {
        \PassOptionsToClass{fontset = #1}{ctexbook}
        \bool_set_false:N \l__myfont_bool
      },
    font/windows  .code:n =
      {
        \PassOptionsToClass{fontset = #1}{ctexbook}
        \bool_set_false:N \l__myfont_bool
      },
    font/linux    .code:n =
      {
        \PassOptionsToClass{fontset = ubuntu}{ctexbook}
        \bool_set_false:N \l__myfont_bool
      },
    font/overleaf .code:n =
      {\bool_set_false:N \l__myfont_bool},
    font/none     .code:n =
      {
        \PassOptionsToClass{fontset = #1}{ctexbook}
        \bool_set_false:N \l__myfont_bool
      }, 
    font          .default:n = windows,

    paper         .choice:,
    paper/a4      .code:n = {},
    paper/b5      .code:n = {\bool_set_true:N \l__paper_bfive_bool},
    paper         .initial:n = a4,

    oneside       .value_forbidden:n = true,
    twoside       .value_forbidden:n = true,
    oneside       .code:n =
      {\bool_set_false:N \l__page_twoside_bool},

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

\ProcessKeysOptions{easybook}

\bool_if:NT \l__myfont_bool{\PassOptionsToClass{fontset = none}{ctexbook}}
\bool_if:NT \l__enstyle_bool
  {
    \bool_set_false:N \l__lang_chinese_bool
    \bool_set_false:N \l__zhtitle_bool
    \bool_set_true:N  \l__newline_bool
  }
\bool_if:NTF \l__lang_chinese_bool
  {\PassOptionsToClass{scheme = chinese}{ctexbook}}
  {\PassOptionsToClass{scheme = plain}{ctexbook}}

\PassOptionsToClass{\g__options_clist}{ctexbook}
\PassOptionsToPackage{CJKmath = true}{xeCJK}
\LoadClass[UTF8]{ctexbook}

\tl_new:N \g__keys_color_tl
\tl_new:N \g__keys_cite_tl
\fp_new:N \g__line_spread_fp
\fp_new:N \g__tab_spread_fp
\tl_new:N \g__math_spread_tl
\tl_new:N \g__cap_spread_tl
\tl_new:N \g__foot_spread_tl

\ctex_define:n
  {
    style               .meta:nn = {ctex/style}{#1},
    link                .meta:nn = {ctex/link}{#1},
    spread              .meta:nn = {ctex/spread}{#1},
    style/color         .choices:nn =
      {black,navygreen,navyblue}
      {\tl_set_eq:NN \g__keys_color_tl\l_keys_choice_tl},
    style/color         .initial:n = black,
    style/cite          .choices:nn =
      {number,authoryear}
      {\tl_set_eq:NN \g__keys_cite_tl\l_keys_choice_tl},
    style/cite          .initial:n = number,

    style/thmbox        .bool_set:N = \l__thmbox_bool,
    style/thmbox        .default:n = true,
    style/thmbox        .initial:n = false,
    style/capdash       .bool_set:N = \l__capdash_bool,
    style/capdash       .default:n = true,
    style/capdash       .initial:n = false,
    style/multoc        .bool_set:N = \l__multoc_bool,
    style/multoc        .default:n = true,
    style/multoc        .initial:n = false,
    style/withpart      .bool_set:N = \l__chap_withpart_bool,
    style/withpart      .default:n = true,
    style/withpart      .initial:n = false,
    style/perpart       .bool_set:N = \l__foot_perpart_bool,
    style/perpart       .default:n = true,
    style/perpart       .initial:n = false,
    style/perpage       .bool_set:N = \l__foot_perpage_bool,
    style/perpage       .default:n = true,
    style/perpage       .initial:n = false,

    spread/linespread   .fp_set:N = \g__line_spread_fp,
    spread/linespread   .initial:n = 1.3,
    spread/tabspread    .fp_set:N = \g__tab_spread_fp,
    spread/tabspread    .initial:n = 1,
    spread/mathspread   .tl_set:N = \g__math_spread_tl,
    spread/mathspread   .initial:n = 1,
    spread/capspread    .tl_set:N = \g__cap_spread_tl,
    spread/capspread    .initial:n = 1,
    spread/fnspread     .tl_set:N = \g__foot_spread_tl,
    spread/fnspread     .initial:n = 1,

    lstlistlistingname  .tl_set:N = \lstlistlistingname,
    lstlistingname      .tl_set:N = \lstlistingname
  }

\RequirePackage[svgnames]{xcolor}
\cs_new_protected:Nn \__load_color_black:
  {\definecolorset{HTML}{ctex@}{}{frame,000000;emph,000000;verb,000000}}
\cs_new_protected:Nn \__load_color_navygreen:
  {\definecolorset{HTML}{ctex@}{}{frame,005752;emph,004986;verb,a40000}}
\cs_new_protected:Nn \__load_color_navyblue:
  {\definecolorset{HTML}{ctex@}{}{frame,005982;emph,eb6877;verb,a4005b}}
\cs_new_protected:Nn \__load_color:
  {\use:c {__load_color_ \g__keys_color_tl :}}
\ctex_at_end_preamble:n {\__load_color:}

\RequirePackage{pdfpages,subfiles}
\includepdfset{fitpaper = true}
\RequirePackage[hang,stable]{footmisc}
\RequirePackage{setspace,zhlineskip}
\RequirePackage{amsthm,thmtools,cases}
\RequirePackage[noto,upint]{newtxmath}
\RequirePackage{chemformula}
\RequirePackage{chemfig}
\RequirePackage{siunitx,physics,bm}
\RequirePackage[normalem]{ulem}
\RequirePackage[protrusion = false]{microtype}
\RequirePackage{hologo}
\hologoSetup{discretionarybreak = true}
\RequirePackage{rotfloat}
\RequirePackage{geometry,marginnote,nccfoots,tablefootnote}
\RequirePackage{fancyhdr,titletoc}
\RequirePackage{caption,bicaption,subcaption}
\RequirePackage{graphicx,wrapfig}
\RequirePackage{zhlipsum,fontawesome,pifont}
\RequirePackage{tabularx,multirow,makecell,tabu,booktabs}
\RequirePackage{paralist,tasks}
\RequirePackage[shortlabels,inline]{enumitem}
\RequirePackage[most]{tcolorbox}
\RequirePackage[sort&compress]{gbt7714}
\RequirePackage[xindy]{imakeidx}

\sys_if_engine_xetex:TF
  {
    \cs_new_eq:NN \__set_family:nnn  \xeCJK_set_family:nnn
    \cs_new_eq:NN \__switch_family:n \xeCJK_switch_family:n
  }{
    \cs_new_eq:NN \__set_family:nnn  \ctex_ltj_set_family:nnn
    \cs_new_eq:NN \__switch_family:n \ctex_ltj_switch_family:n
  }

\cs_new_protected:Npn \__setmainfont:nn #1#2
  {\__fontspec_main_setmainfont:nn {#2}{#1}}
\cs_new_protected:Npn \__setsansfont:nn #1#2
  {\__fontspec_main_setsansfont:nn {#2}{#1}}
\cs_new_protected:Npn \__setmonofont:nn #1#2
  {\__fontspec_main_setmonofont:nn {#2}{#1}}
\cs_new_protected:Npn \__setCJKmainfont:nn #1#2
  {\__set_family:nnn {\CJKrmdefault}{#2}{#1}}
\cs_new_protected:Npn \__setCJKsansfont:nn #1#2
  {\__set_family:nnn {\CJKsfdefault}{#2}{#1}}
\cs_new_protected:Npn \__setCJKmonofont:nn #1#2
  {\__set_family:nnn {\CJKttdefault}{#2}{#1}}
\cs_new_protected:Npn \__set_zhfont_songti:nn #1#2
  {\__set_family:nnn {songti}{#2}{#1}}
\cs_new_protected:Npn \__set_zhfont_heiti:nn #1#2
  {\__set_family:nnn {heiti}{#2}{#1}}
\cs_new_protected:Npn \__set_zhfont_kaishu:nn #1#2
  {\__set_family:nnn {kaishu}{#2}{#1}}
\cs_new_protected:Npn \__set_zhfont_fangsong:nn #1#2
  {\__set_family:nnn {fangsong}{#2}{#1}}

\tl_const:Nn \__option_zhfont:
  {UprightFont = *,AutoFakeBold = 1.5,ItalicFont = *}
\cs_new_protected:Npx \__setCJKmainfont:n #1
  {\__setCJKmainfont:nn {#1}{\__option_zhfont:}}
\cs_new_protected:Npx \__setCJKsansfont:n #1
  {\__setCJKsansfont:nn {#1}{\__option_zhfont:}}
\cs_new_protected:Npx \__setCJKmonofont:n #1
  {\__setCJKmonofont:nn {#1}{\__option_zhfont:}}
\cs_new_protected:Npx \__set_zhfont_songti:n #1
  {\__set_zhfont_songti:nn {#1}{\__option_zhfont:}}
\cs_new_protected:Npx \__set_zhfont_heiti:n #1
  {\__set_zhfont_heiti:nn {#1}{\__option_zhfont:}}
\cs_new_protected:Npx \__set_zhfont_kaishu:n #1
  {\__set_zhfont_kaishu:nn {#1}{\__option_zhfont:}}
\cs_new_protected:Npx \__set_zhfont_fangsong:n #1
  {\__set_zhfont_fangsong:nn {#1}{\__option_zhfont:}}
  
\bool_if:NT \l__myfont_bool
  {
    \__setmainfont:nn {NotoSerif}
      {
        Extension = .ttf,
        UprightFont = *-Regular,
        BoldFont = *-Bold,
        ItalicFont = *-Italic
      }
    \__setsansfont:nn {NotoSans}
      {
        Extension = .ttf,
        UprightFont = *-Regular,
        BoldFont = *-Bold,
        ItalicFont = *-Italic
      }
    \__setmonofont:nn {NotoSansMono}
      {
        Extension = .ttf,
        UprightFont = *-Regular,
        BoldFont = *-Bold
      }
    \__setCJKmainfont:nn {FZShuSong-Z01S}
      {
        UprightFont = *,
        BoldFont = FZHei-B01S,
        ItalicFont = FZKai-Z03S
      }
    \__setCJKsansfont:n {FZHei-B01S}
    \__setCJKmonofont:n {FZFangSong-Z02S}
    \__set_zhfont_songti:n {FZShuSong-Z01S}
    \__set_zhfont_heiti:n {FZHei-B01S}
    \__set_zhfont_kaishu:n {FZKai-Z03S}
    \__set_zhfont_fangsong:n {FZFangSong-Z02S}
    \cs_new_protected:Npn \songti{\__switch_family:n {songti}}
    \cs_new_protected:Npn \heiti{\__switch_family:n {heiti}}
    \cs_new_protected:Npn \kaishu{\__switch_family:n {kaishu}}
    \cs_new_protected:Npn \fangsong{\__switch_family:n {fangsong}}
  }
\cs_if_exist:NF \kaishu{\cs_gset_eq:NN \kaishu\normalfont}

\bool_if:NT \l__paper_afour_bool
  {
    \geometry
      {
        a4paper,
        columnsep = 2\ccwd,
        vmargin = 2.54cm,
        hmargin = 3.17cm,
        headheight = 2.04cm,
        headsep = 0.5cm,
        footskip = 0.79cm,
        footnotesep = 0.5cm,
        marginparsep = 8pt,
        marginparwidth = 2.54cm
      }
  }
\bool_if:NT \l__paper_bfive_bool
  {
    \geometry
      {
        b5paper,
        columnsep = 2\ccwd,
        margin = 2.54cm,
        headheight = 2.09cm,
        headsep = 0.45cm,
        footskip = 0.7cm,
        footnotesep = 0.45cm,
        marginparsep = 0.25cm,
        marginparwidth = 2.25cm
      }
  }

\cs_gset:Npn \cleardoublepage
  {
    \clearpage
    \bool_if:NT \l__page_twoside_bool
      {
        \int_if_odd:nF \c@page
          {\hbox:n {}\thispagestyle{empty}\clearpage}
      }
  }
\cs_gset:Npn \frontmatter
  {
    \cleardoublepage
    \@mainmatterfalse
    \pagenumbering{Roman}
  }
\pagestyle{fancy}
\fancyhf{}
\bool_if:NTF \l__page_twoside_bool
  {
    \cs_gset:Npn \chaptermark#1
      {
        \markboth
          {
            \MakeUppercase
              {
                \ifnum\c@secnumdepth>\m@ne
                  \if@mainmatter
                    \ifodd\CTEX@chapter@numbering
                      \CTEXthechapter\hspace{\ccwd}
                    \fi
                  \fi
                \fi#1
              }
          }{
            \MakeUppercase
              {
                \ifnum\c@secnumdepth>\m@ne
                  \if@mainmatter
                    \ifodd\CTEX@chapter@numbering
                      \CTEXthechapter\hspace{\ccwd}
                    \fi
                  \fi
                \fi#1
              }
          }
      }
    \fancyhead[EC]{\color{ctex@frame}\kaishu\leftmark}
    \fancyhead[OC]{\color{ctex@frame}\kaishu\rightmark}
    \fancyhead[EL,OR]{\color{ctex@frame}\thepage}
    \cs_gset_eq:NN \ps@plain\ps@empty
  }{
    \cs_gset:Npn \chaptermark#1
      {
        \markboth
          {
            \MakeUppercase
              {
                \ifnum\c@secnumdepth>\m@ne
                  \if@mainmatter
                    \ifodd\CTEX@chapter@numbering
                      \CTEXthechapter\hspace{\ccwd}
                    \fi
                  \fi
                \fi#1
              }
          }{}
      }
    \fancyhead[L]{\color{ctex@frame}\kaishu\leftmark}
    \fancyhead[R]{\color{ctex@frame}\kaishu\rightmark}
    \fancyfoot[C]{\color{ctex@frame}\thepage}
    \fancypagestyle{plain}
      {
        \fancyhf{}\cs_gset:Npn\headrule{}
        \fancyfoot[C]{\color{ctex@frame}\thepage}
      }
  }
\cs_gset:Npn \sectionmark#1
  {
    \markright
      {
        \ifnum\c@secnumdepth>\z@
          \ifodd\CTEX@section@numbering
            \CTEXthesection\hspace{0.5\ccwd}
          \fi
        \fi#1
      }
  }
\cs_gset:Npn \headrule
  {
    \color{ctex@frame}\vspace{2.5pt}
    \hrule width\textwidth height 0.75pt
  }
\bool_if:NT \l__draft_bool
  {
    \bool_if:NTF \l__page_twoside_bool
      {\fancyfoot[C]{\color{gray!60}\sffamily\today}}
      {\fancyhead[C]{\color{gray!60}\sffamily\today}}
    \geometry{showframe}
  }

\titlecontents{part}
  [0\ccwd]
  {\addvspace{1pc}\sffamily\large}
  {}
  {}
  {\normalsize\titlerule*{}\bf\contentspage}
\titlecontents{chapter}
  [0\ccwd]
  {\addvspace{1pc}\sffamily\large}
  {\thecontentslabel\hspace{\ccwd}}
  {}
  {\normalsize\titlerule*[0.55pc]{\scalebox{1.2}{$\cdot$}}\bf\contentspage}
\titlecontents{section}
  [1.5\ccwd]
  {\addvspace{0.35pc}}
  {\thecontentslabel\hspace{\ccwd}}
  {}
  {\titlerule*[0.55pc]{\scalebox{1.2}{$\cdot$}}\contentspage}
\titlecontents{subsection}
  [3.8\ccwd]
  {\addvspace{0.35pc}}
  {\thecontentslabel\hspace{\ccwd}}
  {}
  {\titlerule*[0.55pc]{\scalebox{1.2}{$\cdot$}}\contentspage}
\titlecontents{figure}
  [0\ccwd]
  {\addvspace{0.2pc}}
  {\thecontentslabel\hspace{\ccwd}}
  {}
  {\titlerule*[0.55pc]{\scalebox{1.2}{$\cdot$}}\contentspage}
\titlecontents{table}
  [0\ccwd]
  {\addvspace{0.2pc}}
  {\thecontentslabel\hspace{\ccwd}}
  {}
  {\titlerule*[0.55pc]{\scalebox{1.2}{$\cdot$}}\contentspage}
\contentsuse{lstlisting}{lol}
\titlecontents{lstlisting}
  [0\ccwd]
  {\addvspace{0.2pc}}
  {\thecontentslabel\hspace{\ccwd}}
  {}
  {\titlerule*[0.55pc]{\scalebox{1.2}{$\cdot$}}\contentspage}

\cs_gset:Npn \tableofcontents
  {
    \if@twocolumn
      \@restonecoltrue\onecolumn
      \bool_if:NT \l__multoc_bool{\twocolumn}
    \else
      \@restonecolfalse
      \bool_if:NT \l__multoc_bool{\twocolumn}
    \fi
    \chapter*{\contentsname}
    \bool_if:NTF \l__page_twoside_bool
      {\markboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
      {\markboth{\MakeUppercase\contentsname}{}}
    \vspace*{-1pc}
    \@starttoc{toc}
    \if@restonecol
      \twocolumn
    \else
      \onecolumn
    \fi
  }
\cs_gset:Npn \listoffigures
  {
    \if@twocolumn
      \@restonecoltrue\onecolumn
      \bool_if:NT \l__multoc_bool{\twocolumn}
    \else
      \@restonecolfalse
      \bool_if:NT \l__multoc_bool{\twocolumn}
    \fi
    \chapter*{\phantomsection\listfigurename}
    \addcontentsline{toc}{chapter}{\listfigurename}
    \bool_if:NTF \l__page_twoside_bool
      {\markboth{\MakeUppercase\listfigurename}{\MakeUppercase\listfigurename}}
      {\markboth{\MakeUppercase\listfigurename}{}}
    \vspace*{-1pc}
    \@starttoc{lof}
    \if@restonecol
      \twocolumn
    \else
      \onecolumn
    \fi
  }
\cs_gset:Npn \listoftables
  {
    \if@twocolumn
      \@restonecoltrue\onecolumn
      \bool_if:NT \l__multoc_bool{\twocolumn}
    \else
      \@restonecolfalse
      \bool_if:NT \l__multoc_bool{\twocolumn}
    \fi
    \chapter*{\phantomsection\listtablename}
    \addcontentsline{toc}{chapter}{\listtablename}
    \bool_if:NTF \l__page_twoside_bool
      {\markboth{\MakeUppercase\listtablename}{\MakeUppercase\listtablename}}
      {\markboth{\MakeUppercase\listtablename}{}}
    \vspace*{-1pc}
    \@starttoc{lot}
    \if@restonecol
      \twocolumn
    \else
      \onecolumn
    \fi
  }
\cs_new:Npn \listoflistings
  {
    \begingroup
    \@ifundefined{@restonecoltrue}{}
      {
        \if@twocolumn
          \@restonecoltrue\onecolumn
          \bool_if:NT \l__multoc_bool{\twocolumn}
        \else
          \@restonecolfalse
          \bool_if:NT \l__multoc_bool{\twocolumn}
        \fi
      }
    \chapter*{\phantomsection\lstlistlistingname}
    \addcontentsline{toc}{chapter}{\lstlistlistingname}
    \bool_if:NTF \l__page_twoside_bool
      {\markboth{\MakeUppercase\lstlistlistingname}{\MakeUppercase\lstlistlistingname}}
      {\markboth{\MakeUppercase\lstlistlistingname}{}}
    \vspace*{-0.2pc}
    \@starttoc{lol}
    \@ifundefined{@restonecoltrue}{}
      {
        \if@restonecol
          \twocolumn
        \else
          \onecolumn
        \fi
      }
    \endgroup
  }

\cs_gset:Npn \bibsection{\chapter{\bibname}}
\skip_set:Nn \bibsep{0ex}
\cs_new_protected:Npn \__load_cite_number:
  {
    \setcitestyle{square,comma,super}
    \bibliographystyle{gbt7714-numerical}
  }
\cs_new_protected:Nn \__load_cite_authoryear:
  {\bibliographystyle{gbt7714-author-year}}
\cs_new_protected:Nn \__load_cite:
  {\use:c {__load_cite_ \g__keys_cite_tl :}}
\ctex_at_end_preamble:n {\__load_cite:}
\makeindex[
  intoc,
  options = -M~texindy~-C~utf8,
  program = truexindy,
  columns = 2,
  columnsep = 2\ccwd
  ]
\indexsetup
  {
    level = \chapter*,
    toclevel = chapter,
    firstpagestyle = plain
  }
\patchcmd\imki@indexheaders
  {\@mkboth{\MakeUppercase\indexname}{\MakeUppercase\indexname}}
  {
    \bool_if:NTF \l__page_twoside_bool
      {\markboth{\MakeUppercase\indexname}{\MakeUppercase\indexname}}
      {\markboth{\MakeUppercase\indexname}{}}
  }
  {}{}

\DeclareCaptionLabelSeparator{ccwd}{\hspace{\ccwd}}
\DeclareCaptionLabelFormat{parens}{\bothIfFirst{#1}{~}(#2)}
\captionsetup
  {
    format = hang,
    % figurewithin = section,
    % tablewithin = section,
    labelfont = {sf,small,color = ctex@frame},
    labelsep = ccwd,
    textfont = {sf,small,stretch = \g__cap_spread_tl},
    belowskip = 0pt,aboveskip = 10pt
  }
\captionsetup[subfigure]
  {
    labelfont = {sf,small,color = ctex@frame},
    labelformat = parens,
    belowskip = 2pt,aboveskip = 6pt
  }
\captionsetup[lstlisting]{singlelinecheck = false}
\captionsetup[figure][bi-second]{name = Figure}
\captionsetup[table][bi-second]{name = Table}
\cs_new:Npn \__arabic:n #1{\int_to_arabic:v {c@#1}}
\AtBeginDocument
  {
    \bool_if:NT \l__capdash_bool
      {
        \cs_gset:Npn \thefigure{\thechapter\textendash\__arabic:n {figure}}
        \cs_gset:Npn \thetable{\thechapter\textendash\__arabic:n {table}}
        \cs_gset:Npn \thelstlisting{\thechapter\textendash\__arabic:n {lstlisting}}
      }
  }
\AtBeginEnvironment{tabularx}
  {\exp_args:Nx \linespread{\fp_use:N \g__tab_spread_fp}\selectfont\ignorespaces}
\AtBeginEnvironment{tabular}
  {\exp_args:Nx \linespread{\fp_use:N \g__tab_spread_fp}\selectfont\ignorespaces}

\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}
\ctex_after_end_preamble:n
  {\exp_args:Nx \linespread{\fp_use:N \g__line_spread_fp}\selectfont}

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

\setlist
  {
    labelsep = .75\ccwd,listparindent = 2\ccwd,
    itemsep = .75ex plus .1ex,parsep = 0ex,topsep = .75ex plus .1ex,partopsep = 0ex
  }
\setlist[itemize,1]
  {label = \color{ctex@emph}\ensuremath{\bullet},leftmargin = *}
\setlist[itemize,2]
  {label = \color{ctex@emph}\ensuremath{\circ},leftmargin = *}
\setlist[enumerate,1]
  {label = \color{ctex@emph}\arabic*.,ref = \arabic*,leftmargin = *}
\setlist[enumerate,2]
  {label = \color{ctex@emph}(\alph*),ref = \theenumi(\alph*),leftmargin = *}
\setlist[description]
  {font = \color{ctex@emph}\sf,labelwidth = *,leftmargin = 2\ccwd}
\newlist{outlinelist}{itemize}{1}
\setlist[outlinelist]
  {label = \color{ctex@emph}\upshape\ding{112},itemsep = .5ex plus .1ex,leftmargin = *}
\skip_set:Nn \pltopsep{.75ex plus .1ex}
\skip_set:Nn \plpartopsep{0ex}
\skip_set:Nn \plitemsep{.75ex plus .1ex}
\skip_set:Nn \plparsep{0ex}
\cs_new:Npn \circled#1
  {
    \lower .7ex
    \hbox{\tikz\draw(0pt,0pt)circle(.5\ccwd)node{\makebox[\ccwd][c]{\small#1}};}
  }

\tl_new:N \theoremname
\tl_new:N \definitioname
\tl_new:N \lemmaname
\tl_new:N \corollaryname
\tl_new:N \propositioname
\tl_new:N \examplename
\tl_new:N \remarkname
\tl_new:N \exercisename

\bool_if:NTF \l__lang_chinese_bool
  {
    \tl_set:Nn \theoremname{定理}
    \tl_set:Nn \definitioname{定义}
    \tl_set:Nn \lemmaname{引理}
    \tl_set:Nn \corollaryname{推论}
    \tl_set:Nn \propositioname{性质}
    \tl_set:Nn \examplename{例}
    \tl_set:Nn \remarkname{注}
    \tl_set:Nn \exercisename{练习}
  }{        
    \tl_set:Nn \theoremname{Theorem}
    \tl_set:Nn \definitioname{Definition}
    \tl_set:Nn \lemmaname{Lemma}
    \tl_set:Nn \corollaryname{Corollary}
    \tl_set:Nn \propositioname{Proposition}
    \tl_set:Nn \examplename{Example}
    \tl_set:Nn \remarkname{Remark}
    \tl_set:Nn \exercisename{Exercise}
  }

\declaretheoremstyle[
  spaceabove = .75ex plus .1ex,
  spacebelow = .75ex plus .1ex,
  headindent = 0\ccwd,
  headfont = \color{ctex@emph}\sffamily,
  notefont = {},
  notebraces = {}{},
  bodyfont = \normalfont,
  headpunct = {.},
  postheadspace = \ccwd,
  numberwithin = chapter,
  headformat = \NAME\space\NUMBER\NOTE
  ]{mythm}
\declaretheorem[style = mythm,name = \theoremname]{theorem}
\declaretheorem[style = mythm,name = \definitioname]{definition}
\declaretheorem[style = mythm,name = \lemmaname]{lemma}
\declaretheorem[style = mythm,name = \corollaryname]{corollary}
\declaretheorem[style = mythm,name = \propositioname]{proposition}
\declaretheorem[style = mythm,name = \examplename]{example}
\cs_gset_eq:NN \proof\relax
\declaretheorem{remark}[
  style = mythm,
  name = \faCommentingO\space\remarkname,
  numbered = no
  ]
\declaretheorem{proof}[
  style = mythm,
  name = \faPencilSquareO\space\proofname,
  numbered = no,
  qed = \qedsymbol
  ]

\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,
    unit-math-rm = \mathrm,
    number-math-rm = \mathrm,
    table-parse-only,
    group-digits = false
  }
\allowdisplaybreaks[4]
\cs_gset:Npn \ULthickness{.75pt}
\SetMathEnvironmentSinglespace{\g__math_spread_tl}
\skip_set:Nn \jot{4pt plus 1pt minus 1pt}
\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)}}

\tcbset
  {
    thmsty/.style =
      {
        enhanced~jigsaw,pad~at~break* = 3pt,
        opacityback = 0,
        colframe = ctex@emph,
        left = .2pc,right = .2pc,top = .5pc,bottom = .5pc,middle= .5pc,
        arc = 0pt
      },
    outlinesty/.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,
        after~skip = 3ex,
        left = 1.5pc,right = 1.5pc,top = 1pc,bottom = 0.5pc,
        boxsep = 5pt
      },
    exsty/.style =
      {
        enhanced,on~line,
        arc = 5pt,
        fontupper = \sffamily\Large,
        boxrule = 1pt,boxsep = 0pt,
        left = 6pt,right = 6pt,top = 3.5pt,bottom = 3.5pt,
        before~skip = 4ex,after~skip = 2.25ex
      },
    breakable,
    boxrule = .75pt
  }
\ctex_at_end_preamble:n
  {
    \bool_if:NT \l__thmbox_bool
      {
        \tcolorboxenvironment{theorem}{thmsty}
        \tcolorboxenvironment{definition}{thmsty}
        \tcolorboxenvironment{lemma}{thmsty}
        \tcolorboxenvironment{corollary}{thmsty}
        \tcolorboxenvironment{proposition}{thmsty}
        \tcolorboxenvironment{example}{thmsty}
      }
  }
\NewDocumentEnvironment{outline}{O{\abstractname}}
  {
    \begin{tcolorbox}[outlinesty,title = #1]
      \begin{outlinelist}
  }{
      \end{outlinelist}
    \end{tcolorbox}
  }
\NewDocumentEnvironment{exercise}{sO{black}O{1.}O{\exercisename}}
  {
    \IfBooleanF{#1}
      {
        \refstepcounter{section}
        \addcontentsline{toc}{section}{\CTEXthesection\hspace{\ccwd}#4}
        \markright
          {
            \ifnum\c@secnumdepth>\z@
              \CTEXthesection\hspace{0.5\ccwd}
            \fi#4
          }
      }
    \begin{center}
      \bool_if:NTF \l__thmbox_bool
        {
          \tcbox[
            exsty,
            colback = #2!8!white,colframe = #2!50!black,
            drop~fuzzy~shadow = #2!50!white,
            ]{\IfBooleanF{#1}{\CTEXthesection\hspace{0.5\ccwd}}#4}
        }{
          \sffamily\Large\IfBooleanF{#1}{\CTEXthesection\hspace{0.5\ccwd}}#4
        }
    \end{center}
    \begin{compactenum}[#3]
  }{
    \end{compactenum}
  }
\DeclareTColorBox{mybox}{so}
  {
    enhanced~jigsaw,pad~at~break* = 3pt,
    IfBooleanF = {#1}{opacityback = 0,colframe = ctex@emph},
    coltitle = black,opacitybacktitle = 0,
    fonttitle = \sffamily,
    left = .2pc,right = .2pc,top = .5pc,bottom = .5pc,middle= .5pc,
    arc = 0pt,
    toptitle = 2pt,bottomtitle = 2pt,
    beforeafter~skip=2ex,
    halign~upper = left,halign~lower = left,
    center~title,
    IfValueT = {#2}{title = #2}
  }
\NewTCBox{\fuzzy}{O{yellow}O{}}
  {nobeforeafter,tcbox~raise~base,blank,fuzzy~halo = 2pt~with~#1,#2}
\DeclareTotalTCBox{\concise}{O{Aqua}O{}v}
  {
    nobeforeafter,tcbox~raise~base,
    top = 2pt,bottom = 2.5pt,left = 2pt,right = 2pt,
    boxsep = 0pt,arc = 1pt,
    colback = #1!15!white,#2
  }{#3}

\skip_set:Nn \footnotemargin{0.5\ccwd}
\skip_set:Nn \footnotesep{0ex}
\cs_gset:Npn \hangfootparskip{0ex}
\cs_gset:Npn \footnoterule
  {
    \color{ctex@frame}\hrule width 0.35\columnwidth height 0.75pt
    \vspace*{2.6pt}\color{black}
  }
\bool_if:NT \l__lang_chinese_bool
  {\cs_gset:Npn \hangfootparindent{2\ccwd}}
\ctex_at_end_preamble:n
  {
    \bool_if:NT \l__chap_withpart_bool
      {\counterwithin*{chapter}{part}}
    \bool_if:NT \l__foot_perpart_bool
      {
        \counterwithout*{footnote}{chapter}
        \counterwithin*{footnote}{part}
      }
    \bool_if:NT \l__foot_perpage_bool
      {
        \counterwithout*{footnote}{chapter}
        \counterwithin*{footnote}{page}
      }
  }
\patchcmd\@footnotetext
  {\def\baselinestretch{\ZhLS@footlinespread}}
  {\def\baselinestretch{\g__foot_spread_tl}}
  {}{}
\patchcmd\@mpfootnotetext
  {\def\baselinestretch{\ZhLS@footlinespread}}
  {\def\baselinestretch{\g__foot_spread_tl}}
  {}{}
\patchcmd\@makefnmark
  {\normalfont}
  {\normalfont\rmfamily}
  {}{}
\cs_gset:Npn \marginfont{\sffamily\footnotesize}

\lstdefinestyle{mystyle}
  {
    language = [LaTeX]TeX,
    texcsstyle = *\lst@ifdisplaystyle\bfseries\color{ctex@emph}\else\color{ctex@verb}\fi,
    basicstyle = \ttfamily\lst@ifdisplaystyle\small\else\color{ctex@verb}\fi,
    framexleftmargin = 0pt,
    framexrightmargin = 0pt,
    xleftmargin = 0pt,
    xrightmargin = 0pt,
    framesep = 3pt,
    frame = lines,
    rulecolor = \color{ctex@frame},
    commentstyle = \color{gray},
    emphstyle = \color{ctex@emph},
    emph =
      {
        amsmath,align,aligned,chemfig,cleveref,cases,caption,chemformula,compactenum,description,enumitem,enumerate,exercise,easybook,footmisc,hang,itemize,imakeidx,listings,LaTeX,multline,mybox,paralist,Python,siunitx,split,subnumcases,subcaption,tabularx,thmtools,xcolor
      },
    keywordstyle = \lst@ifdisplaystyle\bfseries\color{ctex@emph}\else\color{ctex@verb}\fi,
    morekeywords =
      {
        includegraphics,setmainfont,setsansfont,setmonofont,setCJKmainfont,setCJKsansfont,setCJKmonofont,setCJKfamilyfont,RequirePackage
      }
  }
\lstset
  {
    style = mystyle,
    breaklines = true,
    resetmargins = true,
    numbers = left,
    numberstyle = \small,
    abovecaptionskip = -1ex,
    belowcaptionskip = 1ex,
    aboveskip = 1.5ex plus .2ex minus .1ex,
    belowskip = 0.55ex plus .2ex minus .1ex,
    keepspaces = true,
    framerule = 0.75pt,
    columns = flexible
  }
\lstloadlanguages{C,C++,Java,Python,Matlab}
\AtBeginEnvironment{verbatim}{\microtypesetup{activate=false}}

\cs_new_protected:Npn \__clist_put_hyperref:n #1
  {\clist_gput_right:Nn \g__hyperref_clist{#1}}
\cs_new_protected:Npn \__define_linkcolor:nnn #1#2#3
  {\definecolorset{HTML}{ctex@}{}{link,#1;url,#2;cite,#3}}
\cs_new:Npn \__set_linkcolor:n #1
  {
    linkcolor/\clist_item:nn {#1}{1} .code:n =
      {
        \__define_linkcolor:nnn
          {\clist_item:nn {#1}{2}}
          {\clist_item:nn {#1}{3}}
          {\clist_item:nn {#1}{4}}
        \__clist_put_hyperref:n
          {
            linkcolor = ctex@link,linkbordercolor = ctex@link,
            urlcolor = ctex@url,urlbordercolor = ctex@url,
            citecolor = ctex@cite,citebordercolor = ctex@cite
          }
      },
  }
\cs_new:Npn \__allow_urlbreak:
  {
    \cs_new:Npn \__add_urlbreak_points:
      {\tl_map_function:NN \c__urlbreak_points_tl\do}
    \__appto_cmd:Nn
      \UrlBreaks{\UrlOrds\__add_urlbreak_points:}
  }
\tl_const:Nn \c__urlbreak_points_tl
  {ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789}

\keys_define:nx {ctex/link}
  {
    hyperlink         .choice:,
    hyperlink         .value_required:n = true,
    hyperlink/edge    .code:n = {},
    hyperlink/various .code:n = {\__clist_put_hyperref:n {colorlinks}},
    hyperlink/none    .code:n = {\__clist_put_hyperref:n {hidelinks}},
    hyperlink         .default:n = edge,
    hyperlink         .initial:n = edge,

    linkcolor         .choice:,
    linkcolor         .value_required:n = true,
    \clist_map_function:nN
      {
        {darkgray,  626262,0000B2,005752},
        {lightblue, 0000ff,004986,eb6877},
        {crimson,   dc143c,00c1c9,afcd20},
        {hotpink,   ff69b4,9d5196,57b5e5}
      }
      \__set_linkcolor:n,
    linkcolor         .default:n = darkgray,
    linkcolor         .initial:n = darkgray,

    linktopage        .choice:,
    linktopage        .value_required:n = true,
    linktopage/true   .code:n = {\__clist_put_hyperref:n {linktocpage}},
    linktopage/false  .code:n = {\__clist_put_hyperref:n {linktocpage = false}},
    linktopage        .default:n = true,
    linktopage        .initial:n = false
  }

\RequirePackage[
  lang = {chinese-utf8},
  type = {CC},
  modifier = {by-nc},
  version = {4.0}
  ]{doclicense}

\ctex_at_end_preamble:n
  {
    \RequirePackage[pdfstartview = FitH,bookmarksnumbered]{hyperref}
    \RequirePackage{cleveref}
    \urlstyle{same}
    \exp_args:NV \hypersetup\g__hyperref_clist
    \__allow_urlbreak:

    \bool_if:NTF \l__lang_chinese_bool
      {
        \keys_set_known:nn {ctex}
          {
            contentsname = {目\hspace{\ccwd}录},
            indexname = {索\hspace{\ccwd}引},
            listfigurename = {图片索引},
            listtablename = {表格索引},
            abstractname = {摘\hspace{\ccwd}要},
            lstlistlistingname = {代码索引},
            lstlistingname = {\faCode 代码}
          }
        \crefformat{equation}{#2式（#1）#3}
        \crefformat{align}{#2式（#1）#3}
        \crefformat{multline}{#2式（#1）#3}
        \crefformat{gather}{#2式（#1）#3}
        \crefformat{figure}{#2图#1#3}
        \crefformat{table}{#2表#1#3}
        \crefformat{chapter}{#2第#1章#3}
        \crefformat{section}{#2节#1#3}
        \crefformat{subsection}{#2小节#1#3}
        \crefformat{theorem}{#2定理#1#3}
        \crefformat{definition}{#2定义#1#3}
        \crefformat{lemma}{#2引理#1#3}
        \crefformat{corollary}{#2推论#1#3}
        \crefformat{proposition}{#2性质#1#3}
        \crefformat{example}{#2例#1#3}
      }{
        \keys_set_known:nn {ctex}
          {
            abstractname = {Abstract},
            lstlistlistingname = {List~of~Listings},
            lstlistingname = {\faCode\space Code}
          }
        \crefformat{equation}{#2Equation~(#1)#3}
        \crefformat{align}{#2Equation~(#1)#3}
        \crefformat{multline}{#2Equation~(#1)#3}
        \crefformat{gather}{#2Equation~(#1)#3}
        \crefformat{figure}{#2Figure~#1#3}
        \crefformat{table}{#2Table~#1#3}
        \crefformat{chapter}{#2Chapter~#1#3}
        \crefformat{section}{#2Section~#1#3}
        \crefformat{subsection}{#2Subsection~#1#3}
        \crefformat{theorem}{#2Theorem~#1#3}
        \crefformat{definition}{#2Definition~#1#3}
        \crefformat{lemma}{#2Lemma~#1#3}
        \crefformat{corollary}{#2Corollary~#1#3}
        \crefformat{proposition}{#2Proposition~#1#3}
        \crefformat{example}{#2Example~#1#3}
      }
  }

\ctex_set:n
  {
    secnumdepth = 3,
    tocdepth = 1,
    part =
      {
        pagestyle = empty,
        number =
          {\bool_if:NTF \l__zhtitle_bool{\chinese{part}}{\thepart}},
        format = {\color{ctex@frame}\sffamily\Huge},
        aftername =
          {\bool_if:NTF \l__newline_bool{\par\nobreak}{\hspace{\ccwd}}},
        tocline = {\CTEXifname{\CTEXthepart\hspace{\ccwd}}{}#2}
      },
    chapter =
      {
        % pagestyle = fancy,
        number =
          {\bool_if:NTF \l__zhtitle_bool{\chinese{chapter}}{\thechapter}},
        format =
          {
            \color{ctex@frame}\sffamily\LARGE
            \bool_if:NF \l__newline_bool{\centering}
          },
        aftername =
          {\bool_if:NTF \l__newline_bool{\par\nobreak\vskip 1.5pc}{\hspace{\ccwd}}},
        beforeskip = -1.5ex,
        afterskip = 3ex,
        lotskip = 0.8pc,
        lofskip = 0.8pc,
        tocline = {\CTEXifname{\protect\numberline{\CTEXthechapter}}{}#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{\protect\numberline{\CTEXthesection}}{}#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{\protect\numberline{\CTEXthesubsection}}{}#2}
      },
    subsubsection =
      {
        hang = true,
        format = {\color{ctex@frame}\sffamily},
        aftername = {\hspace{0.5\ccwd}},
        beforeskip = \parskip,
        afterskip = \parskip
      }
  }

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