%------------------------------------------------------------------------------
%% https://ctan.org/pkg/
%% Geometry
\usepackage{geometry}
% \geometry{a4paper,scale=0.9}
\usepackage{fancyhdr} % Extensive control of page headers and footers

%% Font
\ifx\cn\undefined
    \usepackage[utf8]{inputenc} % Required for inputting international characters, allow utf-8 input
    \usepackage[T1]{fontenc} % Output font encoding for international characters, use 8-bit T1 fonts
    % \usepackage[default]{sourcesanspro} % https://fonts.adobe.com/fonts/source-sans#fonts-section
\else
    \usepackage[UTF8]{ctex}
    \newcommand{\chuhao}{\fontsize{42pt}{1.25\baselineskip}\selectfont}     %初号
    \newcommand{\xiaochuhao}{\fontsize{36pt}{1.25\baselineskip}\selectfont} %小初号
    \newcommand{\yihao}{\fontsize{28pt}{1.25\baselineskip}\selectfont}      %一号
    \newcommand{\erhao}{\fontsize{21pt}{1.25\baselineskip}\selectfont}      %二号
    \newcommand{\xiaoerhao}{\fontsize{18pt}{1.25\baselineskip}\selectfont}  %小二号
    \newcommand{\sanhao}{\fontsize{15.75pt}{1.25\baselineskip}\selectfont}  %三号
    \newcommand{\sihao}{\fontsize{14pt}{1.25\baselineskip}\selectfont}      %四号
    \newcommand{\xiaosihao}{\fontsize{12pt}{1.25\baselineskip}\selectfont}  %小四号
    \newcommand{\wuhao}{\fontsize{10.5pt}{1.25\baselineskip}\selectfont}    %五号
    \newcommand{\xiaowuhao}{\fontsize{9pt}{1.25\baselineskip}\selectfont}   %小五号
    \newcommand{\liuhao}{\fontsize{7.875pt}{1.25\baselineskip}\selectfont}  %六号
    \newcommand{\qihao}{\fontsize{5.25pt}{1.25\baselineskip}\selectfont}    %七号
\fi
\usepackage{microtype} % Subliminal refinements towards typographical perfection
\usepackage{lmodern} % The Latin Modern family is a recent collection of fonts.

%% Algorithm
% https://www.overleaf.com/learn/latex/Algorithms
% https://tex.stackexchange.com/questions/229355/algorithm-algorithmic-algorithmicx-algorithm2e-algpseudocode-confused

%%% I-1
% \usepackage{algorithm}
% \usepackage{algorithmic} % Conflict with algpseudocode

%%% I-2
% \usepackage{algorithm}
% \usepackage{algorithmicx} % http://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/algorithmicx/algorithmicx.pdf
% This package is like algorithmic upgraded. It enables you to define custom commands, which is something algorithmic can't do.

%%% I-3
% \usepackage{algorithm}
% \usepackage[noend]{algpseudocode} % Load algorithmicx automatically.

%%% I-4
\usepackage{algorithm}
\usepackage[noEnd=true]{algpseudocodex} % https://ctan.org/pkg/algpseudocodex

%%% For I-1, I-2, I-3, and I-4
\algrenewcommand{\algorithmicrequire}{\textbf{Input:}}
\algrenewcommand{\algorithmicensure}{\textbf{Output:}}

%%% II-1
% http://tug.ctan.org/macros/latex/contrib/algorithm2e/doc/algorithm2e.pdf
% https://texfaq.org/FAQ-algorithms: The algorithm2e is of very long standing, and is widely used and recommended.
% \usepackage[linesnumbered,boxed,ruled,commentsnumbered, vlined]{algorithm2e}

%% Box
\usepackage{framed} % Create three environments: framed, shaded, and leftbar.
\usepackage{tcolorbox} % Provide an environment for coloured and framed text boxes with a heading line.
\tcbuselibrary{skins, breakable,listings, theorems}
\tcbset{
    breakable=false,
    enhanced,
    % watermark graphics=*.jpg,
    watermark opacity=0.08,
    watermark zoom=0.9,
    colframe=blue!15,
    colback=blue!5,
    coltitle=blue!20!black,
    colbacktitle = blue!15,
    colupper=black,
    collower=black,
    drop fuzzy shadow
}

%% Math
\usepackage{bm} % https://www.ctan.org/pkg/bm
\usepackage{amsmath} % https://www.ctan.org/pkg/amsmath
\usepackage{amsfonts} % https://www.ctan.org/pkg/amsfonts
\usepackage{amssymb} % https://latexstudio.net/hulatex/package/maths-1.htm. Contained in amsfonts.
\usepackage{amsthm} % https://www.ctan.org/pkg/amsthm. Facilitates the kind of theorem setup typically needed in AMS Publications.
\usepackage{mathrsfs}
\usepackage{csquotes} % Provides advanced facilities for inline and display quotations.
\usepackage{siunitx} % Ensure that the combined mathematical meaning of the value plus unit combination is clear.
\usepackage{mathtools} % https://www.ctan.org/pkg/mathtools. Based on amsmath.
\usepackage{nicefrac} % Compact symbols for 1/2, etc.

%% Color
% cyan, magenta, darkgray, lightgray, brown, orange, lime, purple, teal, violet and pink
\usepackage{color}
\usepackage{xcolor} % The package allows rows and columns to be coloured, and even individual cells.
\usepackage{colortbl} % Fill color

%% Figure and Table
\usepackage[small]{caption} % [bf, small]
\usepackage{subcaption}
\usepackage{float} % Improves the interface for defining floating objects such as figures and tables.

%% Figure
\usepackage{graphicx}
\usepackage{graphics}
\graphicspath{{./}
{./figure/}{./figures/}{./image/}{./images/}{./graphics/}{./graphic/}{./pictures/}{./picture/}
{./Figure/}{./Figures/}{./Image/}{./Images/}{./Graphics/}{./Graphic/}{./Pictures/}{./Picture/}
{./fig}{./figs}{./img}{./imgs}
{./Fig}{./Figs}{./Img}{./Imgs}
}
\usepackage{pgf} % PGF is a macro package for creating graphics.
\usepackage{wrapfig}
\usepackage{standalone}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}
\usetikzlibrary{arrows,arrows.meta}
\usetikzlibrary{decorations,decorations.text,decorations.pathreplacing,decorations.footprints,decorations.pathmorphing}
\usetikzlibrary{shapes,shapes.symbols,shapes.callouts,shapes.misc}
\usetikzlibrary{patterns,shadows,shadows.blur,fadings}
\usetikzlibrary{trees,backgrounds,shadings,calc,positioning,fpu,fit,spy,chains}

%% Table
\usepackage{booktabs} % For professional tables
\usepackage{multirow}
\usepackage{multicol}
\usepackage{dcolumn}
\usepackage{makecell}

%% Citation
% https://mirrors.zju.edu.cn/CTAN/macros/latex/contrib/biblatex/doc/biblatex.pdf
% backend=bibtex, bibtex8, biber
% sorting=nty, nyt, nyvt, anyt, anyvt, ynt, ydnt, none, debug,
% citestyle=numeric, numeric-comp, numeric-verb ,
    % alphabetic, alphabetic-verb,
    % authoryear, authoryear-comp, authoryear-ibid, authoryear-icomp,
    % authortitle, authortitle-comp, authortitle-ibid , authortitle-icomp, authortitle-terse, authortitle-tcomp, authortitle-ticomp,
    % verbose, verbose-ibid, verbose-note, verbose-inote, verbose-trad1, verbose-trad2, verbose-trad3,
    % reading, draft, debug
% bibstyle=numeric, alphabetic, authoryear, authortitle, verbose, reading, draft, debug
% refsection=none, part, chapter, chapter+, section, section+, subsection
% maxnames, minnames, maxbibnames, minbibnames, maxcitenames, mincitenames, maxsortnames, minsortnames
\usepackage[backend=biber,
    % For APA
    style=apa, % https://mirrors.cloud.tencent.com/CTAN/macros/latex/contrib/biblatex-contrib/biblatex-apa/biblatex-apa.pdf
    apamaxprtauth=20, % Control the number of author/editor names which are printed in the References. APA style defaults to 20.
    %
    backref=false,
    natbib=true,
    refsection=none,
    sorting=ydnt,
    % Ignored fields in references
    doi=false,
    url=false,
]{biblatex}
% \usepackage[backend=biber,
%   % For ieee
%   style=ieee,
%   %
%   backref=false, % false, ture
%   bibstyle=numeric,
%   citestyle=numeric,
%   defernumbers=false, % false, ture
%   maxnames=2,
%   minnames=1,
%   natbib=true, % false, ture
%   refsection=none, % none, part, chapter, chapter+, section, section+, subsection, subsection+
%   sorting=ydnt,
%   % Ignored fields in references
%   doi=false,
%   url=false,
% ]{biblatex}
\addbibresource{./References/References.bib}
\usepackage{hyperref} % When using the `hyperref` package, it is preferable to load it after `biblatex`.
\hypersetup{
    colorlinks=true,
    linkcolor=red,
    filecolor=cyan,
    urlcolor=blue,
    citecolor=green,
    pdfborder={0 0 0}}
\pdfstringdefDisableCommands{\let\fullcite \@firstofone}
% \usepackage{cleveref} % Intelligent cross-referencing
% [capitalise,nameinlink,noabbrev,compress]. When using the `cleveref` package, it is preferable to load it after `hyperref`
% Confict with algorithmic, algorithmicx, algpseudocode, algpseudocodex

%% Codes
\usepackage{listings} % Typeset source code listings using LATEX
% https://nasa.github.io/nasa-latex-docs/html/examples/listing.html
% https://www.overleaf.com/learn/latex/
% http://users.ece.utexas.edu/~garg/dist/listings.pdf
% https://www.overleaf.com/learn/latex/Code_listing
\lstdefinestyle{lfonts}{
  basicstyle       = \footnotesize\ttfamily,
  backgroundcolor  = \color{olive!5!white},
  stringstyle      = \color{green!60!black},
  keywordstyle     = \color{blue!90!black}\textbf,  % \textbf or \bfseries
  commentstyle     = \color{olive!70!black}\textit,  % \textit or \scshape
}
\lstdefinestyle{lnumbers}{
  numbers     = left,
  numberstyle = \tiny,
  numbersep   = 0.2em,
  firstnumber = 1,
  stepnumber  = 1,
}
\lstdefinestyle{llayout}{
  breaklines = true,
  tabsize    = 2,
  columns    = flexible,
}
\lstdefinestyle{lgeometry}{
  xleftmargin      = 20pt,
  xrightmargin     = 0pt,
  frame            = tb,
  framesep         = \fboxsep,
  framexleftmargin = 20pt,
}
\lstdefinestyle{lgeneral}{
  style = lfonts,
  style = lnumbers,
  style = llayout,
  style = lgeometry,
}
\lstdefinestyle{python}{
  language = {Python},
  style    = lgeneral,
}

%% Footnote
% Add backlinks to footnote references. https://tex.stackexchange.com/questions/302266/make-footnote-clickable-both-ways
\usepackage{footnotebackref}
\setlength{\emergencystretch}{3em} % Prevent overfull lines
\providecommand{\tightlist}{ %
    \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
% \setcounter{secnumdepth}{-\maxdimen} % Remove section numbering

%% Others
\usepackage{ifthen} % Conditional commands in LATEX documents
\usepackage{pdfpages} % Simplifies the inclusion of external multi-page PDF documents in LATEX documents.
\usepackage{verbatim} % (that skips everything between \begin{comment} and \end{comment})
\usepackage{pstricks} % PSTricks offers an extensive collection of macros for generating PostScript
\usepackage[english]{babel} % Manages culturally-determined typographical (and other) rules for a wide range of languages.
\usepackage{makeidx} % Standard package for creating indexes, and Provides two new commands, \see and \printindex.
\usepackage{rotating} % Rotation tools, including rotated full-page floats
\usepackage{bbm} % Provide LaTex support for Blackboard varients of Computer Modern fonts.
\usepackage{soul} % Find hypen automatically
\usepackage{url} % Allow linebreaks at certain characters or combinations of characters. (simple URL typesetting)
\usepackage{enumitem}
