\ProvidesPackage{pvcstyle}
%
% Options for Mathematics
%
% Turn on/off arrows above vectors:
\newif\if@arrow\@arrowfalse\DeclareOption{arrow}{\@arrowtrue}
\ExecuteOptions{arrow}
% Turn on/off boldness of vectors:
\newif\if@bold\@boldfalse\DeclareOption{bold}{\@boldtrue}
% \ExecuteOptions{bold}
%
% Options for Fonts
%
\newif\if@xits\@xitsfalse\DeclareOption{xits}{\@xitstrue}
\newif\if@stix\@stixfalse\DeclareOption{stix}{\@stixtrue}
\newif\if@newcm\@newcmfalse\DeclareOption{newcm}{\@newcmtrue}
\ExecuteOptions{newcm}
%
% Options for Code Highlighting
%
\newif\if@code\@codefalse\DeclareOption{code}{\@codetrue}
%
% Terminates Option Processing
%
\ProcessOptions\relax
%
% Packages for Package Writing
%
\RequirePackage{ifthen}  % mimic logical expressions
%
% Packages for Code Highlighting
%
\if@code
\RequirePackage[chapter]{minted}
\setminted{
  style=xcode,
  frame=leftline,
  baselinestretch={1.0},
  breaklines=true,
  fontsize={\small}
}
\fi
%
% Packages for Mathematics
%
\RequirePackage{amsmath}
\RequirePackage{amsopn}
\RequirePackage{mathtools}
% \RequirePackage{esint}  % more integrals
\RequirePackage{physics}
\RequirePackage{accents}  % more accents, must follow `amsmath`.
\RequirePackage[a]{esvect}
\RequirePackage{siunitx}
\RequirePackage{tensor}
%
% Fonts for Mathematics and Western Languages
%
\RequirePackage{unicode-math}
\ifthenelse{\boolean{@xits}}{  % `then`-branch of `xits'
  % font for english text
  \setmainfont{XITS}
  % font for mathematical symbols
  \setmathfont{XITS Math}
}{  % `else`-branch of `xits`
\ifthenelse{\boolean{@stix}}{  % `then`-branch of `stix`
  % font for english text
  \setmainfont{STIX Two Text}
  % font for mathematical symbols
  \setmathfont{NewCMMath-Book}[
    math-style = ISO,
    bold-style = ISO,
  ]
  \setmathfont{STIX Two Math}
  [
    math-style = ISO,
    bold-style = ISO,
    StylisticSet = {3}, % see stixfonts/docs/charts/StixTwoMath.pdf
    range = {\mathalpha, \vysmblkcircle, \infty}
  ]
  % mathematical symbols
  \if@bold
    \renewcommand{\vdot}{\vysmblkcircle}
  \fi
}{  % `else`-branch of `stix`
\ifthenelse{\boolean{@newcm}}{  % `then`-branch of `newcm`
  \setmainfont[
    ItalicFont=NewCM10-BookItalic,
    BoldFont=NewCM10-Bold,
    BoldItalicFont=NewCM10-BoldItalic,
    SmallCapsFeatures={Numbers=OldStyle}
  ]{NewCM10-Book}
  \setsansfont[
    ItalicFont=NewCMSans10-BookOblique,
    BoldFont=NewCMSans10-Bold,
    BoldItalicFont=NewCMSans10-BoldOblique,
    SmallCapsFeatures={Numbers=OldStyle}
  ]{NewCMSans10-Book}
  \setmonofont[
    ItalicFont=NewCMMono10-BookItalic,
    BoldFont=NewCMMono10-Bold,
    BoldItalicFont=NewCMMono10-BoldOblique,
    SmallCapsFeatures={Numbers=OldStyle}
  ]{NewCMMono10-Book}
  \setmathfont{NewCMMath-Book}[
    math-style = ISO,
    bold-style = ISO,
  ]
  \setmathfont{STIX Two Math}
  [
    math-style = ISO,
    bold-style = ISO,
    StylisticSet = {3}, % see stixfonts/docs/charts/StixTwoMath.pdf
    range = {up/{greek}, \hslash}
  ]
  \if@bold
    \renewcommand{\vdot}{\mathbin{\mdsmblkcircle}}
  \fi
}{  % `else`-branch of `newcm`
}  % end of `newcm`
}  % end of `stix`
}  % end of `xits`
\AtBeginDocument{
  \if@bold
    \renewcommand{\cross}{\vectimes}
  \fi
  \renewcommand{\emptyset}{\diameter}
  \renewcommand{\varnothing}{\diameter}
  %% italic versions of the capital Greek letters
  \let\oldGamma\Gamma
  \let\oldGamma\Gamma
  \let\oldDelta\Delta
  \let\oldTheta\Theta
  \let\oldLambda\Lambda
  \let\oldXi\Xi
  \let\oldPi\Pi
  \let\oldSigma\Sigma
  \let\oldUpsilon\Upsilon
  \let\oldPhi\Phi
  \let\oldPsi\Psi
  \let\oldOmega\Omega
  \renewcommand{\Gamma}{\symup{\oldGamma}}
  \renewcommand{\Delta}{\symup{\oldDelta}}
  \renewcommand{\Theta}{\symup{\oldTheta}}
  \renewcommand{\Lambda}{\symup{\oldLambda}}
  \renewcommand{\Xi}{\symup{\oldXi}}
  \renewcommand{\Pi}{\symup{\oldPi}}
  \renewcommand{\Sigma}{\symup{\oldSigma}}
  \renewcommand{\Upsilon}{\symup{\oldUpsilon}}
  \renewcommand{\Phi}{\symup{\oldPhi}}
  \renewcommand{\Psi}{\symup{\oldPsi}}
  \renewcommand{\Omega}{\symup{\oldOmega}}
  \renewcommand{\varGamma}{\mitGamma}
  \renewcommand{\varDelta}{\mitDelta}
  \renewcommand{\varTheta}{\mitTheta}
  \renewcommand{\varLambda}{\mitLambda}
  \renewcommand{\varXi}{\mitXi}
  \renewcommand{\varPi}{\mitPi}
  \renewcommand{\varSigma}{\mitSigma}
  \renewcommand{\varUpsilon}{\mitUpsilon}
  \renewcommand{\varPhi}{\mitPhi}
  \renewcommand{\varPsi}{\mitPsi}
  \renewcommand{\varOmega}{\mitOmega}
  \renewcommand{\mathrm}[1]{\symup{#1}}
}
%
% Commands for Boldness
%
\if@bold
  \renewcommand{\mathbf}[1]{\symbf{#1}}
  \renewcommand{\boldsymbol}[1]{\symbf{#1}}
\else  % turn off bold commands
  \renewcommand{\symbf}[1]{#1}
  \renewcommand{\symbfit}[1]{#1}
  \renewcommand{\symbfsf}[1]{\symsf{#1}}
  \renewcommand{\symbfsfup}[1]{\symsfup{#1}}
  \renewcommand{\mathbf}[1]{#1}
  \renewcommand{\boldsymbol}[1]{#1}
\fi
%
% Commands for Constants
%
\newcommand{\ii}{\mathrm{i}}
\newcommand{\ee}{\mathrm{e}}
%
% Commands for Algebra
%
\newcommand{\Matrix}[1]{\mathinner{\underline{#1}}}
\let\Mat\Matrix
\let\oldvec\vec
\if@arrow
\else
\renewcommand{\oldvec}[1]{#1}
\fi
\renewcommand{\vec}[1]{\oldvec{\symbf{#1}}}
\newcommand{\DotDot}{\mathbin{\vdot\vdot}}
\newcommand{\Tensor}[1]{\undertilde{\symbf{#1}}}
%
% Commands for Calculus
%
% mimic integral signs in `esint` are not defined in `unicode-math`:
\ifx\dotsint\undefined
\newcommand{\dotsint}{\int\!\!\!\mathord{\cdot}\mathord{\cdot}\mathord{\cdot}\!\!\!\int}\fi
\ifx\ointclockwise\undefined
\newcommand{\ointclockwise}{\varointclockwise}
\fi
\ifx\varointctrclockwise\undefined
\newcommand{\varointctrclockwise}{\ointctrclockwise}
\fi
\ifx\varoiint\undefined
\newcommand{\varoiint}{\oiint}
\fi
% `physics` and `unicode-math` treat `\div` differently:
\let\divg\divergence  % define another abbr for `\divergence`.
% material derivatives:
\DeclareDocumentCommand\diffD{}{\mathrm{D}}
\DeclareDocumentCommand\Dt{ o g d() }{  % D_{t}
	% o: optional n for nth differential
	% g: optional argument for readability and to control spacing
	% d: long-form as in d(cos x)
	\IfNoValueTF{#2}{
		\IfNoValueTF{#3}
			{\diffD_{t}\IfNoValueTF{#1}{}{^{#1}}}
			{\mathinner{\diffD_{t}\IfNoValueTF{#1}{}{^{#1}}\argopen(#3\argclose)}}
		}
		{\mathinner{\diffD_{t}\IfNoValueTF{#1}{}{^{#1}}#2} \IfNoValueTF{#3}{}{(#3)}}
  }
\newcommand{\DDt}[1]{\frac{\diffD #1}{\diffD t}}
%
% Commands for Named Functions
%
\DeclareMathOperator{\Diag}{diag}
\DeclareMathOperator{\Sign}{sign}
\DeclareMathOperator{\Span}{span}
\DeclareMathOperator{\Card}{card}  % cardinality of a set
\DeclareMathOperator{\TV}{TV}  % total variation of a function
\newcommand\ConHypGeo{\sideset{_{1}^{}}{_{1}^{}}{\mathop{\operatorname{F}}}}
\newcommand\HypGeo{\sideset{_{2}^{}}{_{1}^{}}{\mathop{\operatorname{F}}}}
%
% Settings for Chinese
%
\RequirePackage[heading]{ctex}
\ctexset{
  punct = quanjiao,
  part/format += \sffamily,
  chapter/format += \sffamily,
  section/format += \sffamily,
  subsection/format += \sffamily,
  subsubsection/format += \sffamily,
  paragraph/format += \sffamily,
  subparagraph/format += \sffamily,
  contentsname = 章节目录,
  listtablename = 表格目录,
  listfigurename = 插图目录,
}
\AtBeginDocument{
  \ifx\listingscaption\undefined
  \else
  \renewcommand{\listingscaption}{代码}
  \renewcommand{\listoflistingscaption}{代码目录}
  \fi
  \makeatletter
    \def\th@definition{%
      \fangsong % body font
    }
  \makeatother
}
%
% Settings for Graphics
%
\RequirePackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{angles}
\usetikzlibrary{calc}
\usetikzlibrary{quotes}

\endinput
