% Configuring Chinese fonts with Noto Serif CJK SC or fallback
\usepackage{xeCJK}
% Try Noto Serif CJK SC; fallback to Source Han Serif SC if Noto is unavailable
% \IfFontExistsTF{Noto Serif CJK SC}{
%   \setCJKmainfont{Noto Serif CJK SC}
%   \setCJKsansfont{Noto Sans CJK SC}
%   \setCJKmonofont{Noto Sans Mono CJK SC}
% }{
%   \IfFontExistsTF{Source Han Serif SC}{
%     \setCJKmainfont{Source Han Serif SC}[BoldFont=Source Han Serif SC Bold, ItalicFont=Source Han Serif SC Light]
%     \setCJKsansfont{Source Han Sans SC}[BoldFont=Source Han Sans SC Bold]
%     \setCJKmonofont{Source Han Sans SC} % 等宽字体通常用黑体
%   }{
%     \setCJKmainfont{SimSun}       % Windows宋体
%     \setCJKsansfont{Microsoft YaHei}  % 微软雅黑
%     \setCJKmonofont{SimHei}       % 黑体
%   }
% }

% Ensuring proper Chinese punctuation and spacing
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt

% Loading essential packages
\usepackage{geometry}
\usepackage{setspace}
\usepackage{hyperref}
\usepackage{tocloft}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{fontspec} % For font existence checking

% Setting hyperlink colors
\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  citecolor=blue,
  urlcolor=blue
}

% Configuring double spacing
\doublespacing

% Customizing table of contents
\renewcommand{\cfttoctitlefont}{\huge\bfseries}
\renewcommand{\cftchapfont}{\large\bfseries}
\renewcommand{\cftsecfont}{\normalsize}
\setlength{\cftbeforetoctitleskip}{-2em}
\setlength{\cftaftertoctitleskip}{1em}

% Defining logo placeholder
\newcommand{\booklogo}[1]{\includegraphics[width=0.3\textwidth]{#1}}

% Ensuring compatibility with Quarto
\providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
