%==============  MyTemplate.sty  ==============%
\NeedsTeXFormat{LaTeX2e}[2020-10-01]
\ProvidesExplPackage{MyTemplate}{2025-09-21}{1.1}{My personal utility macros (fixed)}

%=================  选项处理  =================%
\RequirePackage{kvoptions}
\SetupKeyvalOptions{family = MYTMP, prefix = MYTMP@}

\DeclareBoolOption[false]{twocolumn}
\DeclareBoolOption[false]{minted}
\ProcessKeyvalOptions*

%=================  加载顺序  =================%
\RequirePackage{amsmath,amssymb,mathtools, extarrows, amsthm}
\RequirePackage{xspace}
\RequirePackage{physics}
\RequirePackage[a4paper,scale=0.8]{geometry}
\RequirePackage{lmodern}
\RequirePackage{xcolor}
\RequirePackage{etoolbox}
\RequirePackage{bookmark}
% \RequirePackage{microtype}

\ifMYTMP@twocolumn
  \RequirePackage{multicol}
  \setlength{\columnseprule}{0.4pt}
  \setlength{\columnsep}{2em}
\fi

% 先加载 hyperref，再加载 cleveref
\RequirePackage{hyperref}
\RequirePackage{cleveref}

\definecolor{mylink}{RGB}{0,82,155}
\hypersetup{colorlinks=true,urlcolor=mylink}

% 加载 tcolorbox 及其库
\RequirePackage{tcolorbox}
\tcbuselibrary{skins, breakable}
\RequirePackage{tabularx, booktabs}

\RequirePackage{listings}
\lstset{basicstyle=\ttfamily,columns=flexible} % 全局设置

\ifMYTMP@minted
  \RequirePackage{minted}
\fi

%=================  数学运算符  =================%
\DeclareMathOperator{\lcm}{lcm}
\DeclareMathOperator{\arcsinh}{arcsinh}
\DeclareMathOperator{\arccosh}{arccosh}
\DeclareMathOperator{\arctanh}{arctanh}
\DeclareMathOperator{\arccoth}{arccoth}
\DeclareMathOperator{\arcsech}{arcsech}
\DeclareMathOperator{\arccsch}{arccsch}


%=================  黑板粗体（仅数学模式）  =================%
\NewDocumentCommand{\N}{}{\ensuremath{\mathbb{N}}}
\NewDocumentCommand{\Z}{}{\ensuremath{\mathbb{Z}}}
\NewDocumentCommand{\Q}{}{\ensuremath{\mathbb{Q}}}
\NewDocumentCommand{\R}{}{\ensuremath{\mathbb{R}}}
\NewDocumentCommand{\C}{}{\ensuremath{\mathbb{C}}}
\NewDocumentCommand{\st}{}{\ensuremath{\mathrm{s.t.}\xspace\>}}
\NewDocumentCommand{\eg}{}{\ensuremath{\mathrm{e.g.}\xspace\>}}
\NewDocumentCommand{\ie}{}{\ensuremath{\mathrm{i.e.}\xspace\>}}
\NewDocumentCommand{\wlg}{}{\ensuremath{\mathrm{w.l.o.g.}\xspace\>}}
\NewDocumentCommand{\etal}{}{\ensuremath{\mathrm{et al.}\xspace\>}}
\NewDocumentCommand{\resp}{}{\ensuremath{\mathrm{resp.}\xspace\>}}
\NewDocumentCommand{\viz}{}{\ensuremath{\mathrm{viz.}\xspace\>}}

%=================  实用符号（仅数学模式）  =================%
\NewDocumentCommand{\diff}{m}{\mathop{}\!\mathrm{d}#1}
\NewDocumentCommand{\perm}{m m}{\mathrm{A}_{#1}^{#2}} % 这样写显示效果会有问题
\NewDocumentCommand{\comb}{m m}{\mathrm{C}_{#1}^{#2}} % 这样写显示效果会有问题
\NewDocumentCommand{\ii}{}{\mathrm{i}}
\NewDocumentCommand{\e}{}{\mathrm{e}}
\NewDocumentCommand{\dne}{}{\mathrm{DNE}}
\NewDocumentCommand{\sgn}{m}{\mathop{}\!\mathrm{sgn}\qty(#1)}

%=================  伪章节  =================%
\NewDocumentCommand{\additionalSection}{m}{%
  \par\nopagebreak[3]%
  \subsection*{#1}%
  \nopagebreak[3]\par
}
%================= 伪小节 =================%
\NewDocumentCommand{\additionalSubsection}{m}{%
  \par\nopagebreak[3]%
  \subsubsection*{#1}%
  \nopagebreak[3]\par
}

%—— 仅依赖 xcolor 与 tcolorbox ——%
% \RequirePackage{xcolor}
% \RequirePackage{tcolorbox}

%—— 定义新盒子 ——%
\newtcbox{\inline}{
  on~line, % .sty文件中`on line`的写法会被看作`online`
  % 行内模式
  boxsep=2pt,
  left=1pt,right=1pt,top=0pt,bottom=0pt,
  colback=gray!12,  % 背景色
  colframe=gray!50, % 边框色
  boxrule=0.4pt,
  arc=2pt,
  fontupper=\ttfamily
}
% \newtcbox{\inline}{on line,colback=gray!15,boxrule=0.4pt,arc=2pt}
%—— 兼容旧命令 ——%
\let\code=\inline   % 两种写法等价

%=================  shell-escape 检测  =================%
\ifMYTMP@minted
  \RequirePackage{pdftexcmds}
  \makeatletter
  \ifnum\pdf@shellescape=\@ne\else
    \PackageError{MyTemplate}
      {--shell-escape required for minted}
      {Please compile with:  lualatex -shell-escape  or  xelatex -shell-escape}
  \fi
  \makeatother
\fi

\endinput