\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{tikz}
\usepackage[dvipsnames]{xcolor}
\usepackage{ctex}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tabularx} 
\usepackage{hyperref}
\usepackage{tocloft}
\usepackage{longtable} 
\usepackage{array}
\usepackage{enumitem}   
\usepackage{amsthm}     
\usepackage{etoolbox}   
\usepackage{tcolorbox}
\usepackage{ulem}
\usepackage{listings}
\tcbuselibrary{breakable}



\lstset{
    basicstyle=\ttfamily, % 设置字体族
    breaklines=true, % 自动换行
    keywordstyle=\bfseries\color{NavyBlue}, % 设置关键字为粗体，颜色为 NavyBlue
    emph=[1]{}, % 指定强调词，如果有多个，用逗号隔开
    emph=[2]{as},
    emphstyle=[1]\bfseries\color{Rhodamine}, % 强调词样式设置
    emphstyle=[2]\bfseries\color{NavyBlue},
    commentstyle=\itshape\color{black!50!white}, % 设置注释样式，斜体，浅灰色
    stringstyle=\bfseries\color{PineGreen!90!black}, % 设置字符串样式
    columns=flexible,
    numbers=left, % 显示行号在左边
    numbersep=1em, % 设置行号的具体位置
    numberstyle=\footnotesize, % 缩小行号
    frame=single, % 边框
    framesep=0em % 设置代码与边框的距离
}

\raggedbottom

\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}

\hypersetup{colorlinks=true, linkcolor=black}

\newCJKfontfamily\boldsongti{FZCuSong-B09S}[BoldFont=FZCuSong-B09S]

\definecolor{warmbeige}{RGB}{255, 250, 240} 
\definecolor{lightcyan}{RGB}{224,255,255} 
\definecolor{indigo}{RGB}{75,0,130}
\definecolor{royalblue}{RGB}{65,105,225}
\definecolor{rosepurple}{RGB}{154,128,189}
\definecolor{aibeigreen}{RGB}{223,237,214}
\definecolor{canggreen}{RGB}{34,80,54}
\definecolor{farskyblue}{RGB}{207,223,238}
\definecolor{qianniupurple}{RGB}{208,194,211}
\definecolor{dingpurple}{RGB}{232, 215, 223}
\definecolor{grasswhite}{RGB}{220,220,210}
\definecolor{teabrown}{RGB}{93, 61, 33}
\definecolor{honeyyellow}{RGB}{251, 185, 88}
\definecolor{deepblue}{RGB}{0,0,139}

\geometry{
  paper=a4paper,
  margin=2.5cm 
}

\newcommand*{\circled}[1]{\lower.7ex\hbox{\tikz\draw (0pt, 0pt)%
    circle (.5em) node {\makebox[1em][c]{\small #1}};}}
\newcommand\fillin[1][1cm]{\uline{\hspace{#1}}}

\everymath{\displaystyle}

% 设置封面图片路径
\newcommand{\coverimagepath}{fengmian.png} 

% 封面背景元素
\newcommand{\coverbackground}{
  \fill[color=lightcyan] 
    (current page.north east) rectangle ++(-9cm,-11cm); 

  \fill[color=white] 
    ([xshift=-9cm,yshift=-11cm]current page.north east) 
    rectangle ++(6cm,6cm); 
}

% 封面元素
\newcommand{\coverlabelfront}[3]{
  \begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north east, opacity=1] at (current page.north east) {
      \includegraphics[width=\paperwidth,height=\paperheight,trim=50cm 0cm 0cm 0cm,clip]{\coverimagepath} 
    };

    \coverbackground
    
    \node[anchor=south,font=\songti,text=black,align=center] at 
         ([xshift=-4.5cm,yshift=-1.5cm]current page.north east) {
      \fontsize{14}{14}\selectfont \songti{#3}
    };

    \node[align=center, text width=5cm] at ([xshift=-6cm,yshift=-8cm]current page.north east) {
      \fontsize{60}{60}\selectfont \boldsongti{数学}\\[0.4em]
      \fontsize{20}{20}\selectfont \songti{#1}\\[0.2em]
      \fontsize{16}{16}\selectfont \songti{#2}
    };
  \end{tikzpicture}
}

% 封底元素（保持不变）
\newcommand{\coverlabelback}{
  \begin{tikzpicture}[remember picture,overlay]
    \node[anchor=south west, opacity=1] at (current page.south west) {
      \includegraphics[width=\paperwidth,height=\paperheight,trim=0cm 0cm 50cm 0cm,clip]{\coverimagepath} 
    };
  \end{tikzpicture}
}

\newcommand\lab[1]{#1 \label{#1}\!\!}


% 环境定义
%===== 环境一：例题 (example) =====
\newcounter{example}[section] % 
\renewcommand{\theexample}{\arabic{example}} % 
\newenvironment{example}{%
  \refstepcounter{example}%
  \par\noindent\textbf{例\theexample}\quad% 
  \ignorespaces
}{%
  \par\noindent\ignorespacesafterend
}

%===== 环境二：解与证明 (solution/proof) =====
% 解环境
\newenvironment{solution}{%
  \par\noindent\textbf{解}\quad
  \ignorespaces
}{%
  \par\noindent\ignorespacesafterend
}

% 证明环境
\makeatletter
\renewenvironment{proof}[1][\proofname]{%
  \par\noindent\textbf{#1}\quad
  \ignorespaces
}{%
  $\hfill\square$\par\noindent\ignorespacesafterend
}
\makeatother
\renewcommand{\proofname}{证明} 

%===== 环境三：小练习 (exercise) =====
\newenvironment{exercise}{%
  \par\noindent%
  \begin{tcolorbox}[
    breakable=true,
    colback=farskyblue, 
    colframe=royalblue, 
    arc=0mm, 
    boxrule=0pt, 
    left=0pt, 
    right=0pt, 
    top=0pt, 
    bottom=0pt, 
    before skip=10pt, 
    after skip=10pt, 
    fontupper=\normalfont, 
    width=\textwidth 
  ]
  \noindent\fcolorbox{royalblue}{royalblue}{\makebox[4em][l]{\color{white} \textbf{\large 练习}}}\quad
  \begin{enumerate}[label=\arabic*.,leftmargin=2em] 
}{%
  \end{enumerate}%
  \end{tcolorbox}%
}

%===== 环境四：课后练习 (homework) =====
% homework 环境
\newcounter{homework}[section] 
\renewcommand{\thehomework}{\arabic{homework}.\arabic{section}} 
\newenvironment{homework}{%
  \refstepcounter{homework}%
  \begin{tcolorbox}[
    breakable=true,
    colback=qianniupurple, 
    colframe=indigo, 
    arc=0mm, 
    boxrule=0pt, 
    left=0pt, 
    right=0pt, 
    top=0pt, 
    bottom=0pt, 
    before skip=10pt, 
    after skip=10pt, 
    fontupper=\normalfont, 
    title={\centering\color{white}\Large 习题\thehomework}, 
    coltitle=white, 
    colbacktitle=indigo, 
    %attach boxed title to top center={yshift=-2mm}, 
    %boxed title style={boxrule=0pt, colframe=white}, 
    width=\textwidth 
  ]
}{%
  \end{tcolorbox}%
}


% practice 环境
\newenvironment{practice}{%
  \par\noindent{\boldsongti{\circled{1} 复习巩固}}\par\nobreak%
  \begin{enumerate}[label=\arabic*.,leftmargin=3em,series=problems]
}{%
  \end{enumerate}%
}

% solve 环境
\newenvironment{solve}{%
  \par\noindent{\boldsongti{\circled{2} 综合运用}}\par\nobreak%
  \begin{enumerate}[label=\arabic*.,leftmargin=3em,resume*=problems]
}{%
  \end{enumerate}%
}

% study 环境
\newenvironment{study}{%
  \par\noindent{\boldsongti{\circled{3} 拓广探索}}\par\nobreak%
  \begin{enumerate}[label=\arabic*.,leftmargin=3em,resume*=problems]
}{%
  \end{enumerate}%
}

%===== 环境五：阅读材料 (material) =====
\newenvironment{material}[1][]{%
  \par\noindent%
  \begin{tcolorbox}[
    breakable=true,
    colback=dingpurple, 
    colframe=rosepurple, 
    arc=0mm,
    boxrule=0pt, 
    left=0pt, 
    right=0pt, 
    top=0pt, 
    bottom=0pt, 
    before skip=10pt, 
    after skip=10pt, 
    fontupper=\normalfont, 
    title={\centering\color{white}\Large 阅读与思考}, 
    coltitle=white, 
    colbacktitle=rosepurple, 
    width=\textwidth 
  ]
  \par\noindent{\centering \textbf{\large #1}\par\nobreak}
}{%
  \end{tcolorbox}%
}

%===== 环境六：问题 (question) =====
\newenvironment{question}{%
  \par\noindent%
  \begin{tcolorbox}[
    colback=aibeigreen, 
    colframe=canggreen, 
    arc=0mm, 
    boxrule=0pt, 
    left=0pt, 
    right=0pt, 
    top=0pt, 
    bottom=0pt, 
    before skip=10pt, 
    after skip=10pt, 
    fontupper=\normalfont, 
    width=\textwidth 
  ]
  \noindent\fcolorbox{canggreen}{canggreen}{\makebox[4em][l]{\color{white} \textbf{\large 问题}}}\quad
}{%
  \end{tcolorbox}%
}

%===== 环境七：复习参考题 (review) =====
\newcounter{review}[chapter] 
\renewcommand{\thereview}{\arabic{chapter}} 
\newenvironment{review}{%
  \refstepcounter{review}%
  \begin{tcolorbox}[
    breakable=true, 
    colback=grasswhite, 
    colframe=black, 
    arc=0mm, 
    boxrule=0pt, 
    left=0pt, 
    right=0pt, 
    top=0pt, 
    bottom=0pt, 
    before skip=10pt, 
    after skip=10pt,
    fontupper=\normalfont, 
    title={\centering\color{white}\Large 复习参考题\thereview}, 
    coltitle=white, 
    colbacktitle=black, 
    width=\textwidth 
  ]
}{%
  \end{tcolorbox}%
}

%===== 环境八：整理 (conclusion) =====
\newenvironment{conclusion}{%
  \par\noindent%
  \begin{tcolorbox}[
    colback=honeyyellow, 
    colframe=teabrown, 
    arc=0mm, 
    boxrule=0pt, 
    left=0pt, 
    right=0pt, 
    top=0pt, 
    bottom=0pt, 
    before skip=10pt, 
    after skip=10pt, 
    fontupper=\normalfont, 
    width=\textwidth 
  ]
  \noindent\fcolorbox{teabrown}{teabrown}{\makebox[4em][l]{\color{white} \textbf{\large 整理}}}\quad
}{%
  \end{tcolorbox}%
}

%===== 环境九：信息技术应用 (technology) =====
\newenvironment{technology}[1][]{%
  \par\noindent%
  \begin{tcolorbox}[
    breakable=true, 
    colback=farskyblue, 
    colframe=deepblue, 
    arc=0mm, 
    boxrule=0pt, 
    left=0pt, 
    right=0pt, 
    top=0pt, 
    bottom=0pt, 
    before skip=10pt, 
    after skip=10pt, 
    fontupper=\normalfont, 
    title={\centering\color{white}\Large 信息技术应用}, 
    coltitle=white, 
    colbacktitle=deepblue,
    width=\textwidth 
  ]
  \par\noindent{\centering \textbf{\large #1}\par\nobreak} %
}{%
  \end{tcolorbox}%
}


\begin{document}

\let\cleardoublepage\clearpage
\pagenumbering{gobble} 

% 封面页
\newpage
\thispagestyle{empty}
\pagecolor{warmbeige} 
\begin{titlepage}
  \coverlabelfront{必修一}{代数与函数}{高中数学先进生自读教科书}
\end{titlepage}

% 前言
\newpage
\pagenumbering{roman} 
\thispagestyle{empty}
\chapter*{前言}
本书是针对学有余力的同学编写的。如果你符合如下条件之一，则你可能适合读本书：

\begin{enumerate}
    \item 认为现行高中数学教材以及教学比较简单的同学。
    \item 想要拓展视野、学习更多数学知识的同学。
    \item 有志于今后从事数学研究或者与数学强相关工作的同学。
    \item 准备或者正在学习数学竞赛的同学。
    \item 社会上想要重拾高中数学内容的数学爱好者和数学教育工作者。
\end{enumerate}

如果你符合如下条件之一，则不适合读本书：

\begin{enumerate}
    \item 觉得现行高中数学知识的掌握尚有难度或者基础不够扎实的同学。
    \item 对数学兴趣不足的同学。
    \item 认为学习知识的作用是用于向他人炫耀的同学。
\end{enumerate}

如果你觉得自己确实适合，那就开动脑筋加油吧！

% 符号表
\newpage
\chapter*{本书中出现的数学符号}
\begin{center}
  \begin{longtable}{|>{\raggedright\arraybackslash}p{0.45\textwidth}|>{\raggedright\arraybackslash}p{0.45\textwidth}|}
    \hline
    \textbf{数学符号} & \textbf{释义} \\ \hline
    \endfirsthead

    \hline
    \textbf{数学符号} & \textbf{释义} \\ \hline
    \endhead 

    \hline
    \endfoot 
  
    $a \in A$ & 元素 $a$ 属于集合 $A$ \\ \hline
    $a \notin A$ & 元素 $a$ 不属于集合 $A$ \\ \hline
    $\varnothing$ & 空集 \\ \hline
    $A \subseteq B$ & 集合 $A$ 包含于集合 $B$ \\ \hline
    $A \subsetneqq B$ & 集合 $A$ 真包含于集合 $B$ \\ \hline
    $\mathbb N$ & 自然数集合 \\ \hline
    $\mathbb N^*$ 或 $\mathbb N_+$ & 正整数集合 \\ \hline
    $\mathbb Z$ & 整数集合 \\ \hline
    $\mathbb Q$ & 有理数集合 \\ \hline
    $\mathbb R$ & 实数集合 \\ \hline
    $[a,b]$ & 从 $a$ 到 $b$ 的闭区间 \\ \hline
    $(a,b)$ & 从 $a$ 到 $b$ 的开区间 \\ \hline
    $(a,b]$ & 从 $a$ 到 $b$ 的左开右闭区间 \\ \hline
    $[a,b)$ & 从 $a$ 到 $b$ 的左闭右开区间 \\ \hline
    $\infty,+\infty,-\infty$ & 无穷大，正无穷大，负无穷大 \\ \hline
    $A \cap B$ & 集合 $A$ 与集合 $B$ 的交集 \\ \hline
    $A \cup B$ & 集合 $A$ 与集合 $B$ 的并集 \\ \hline
    $\complement_U A$ & 集合 $A$ 关于全集 $U$ 的补集 \\ \hline
    $A \setminus B$ & 集合 $A$ 关于集合 $B$ 的差集 \\ \hline
    $|A|$ & 集合 $A$ 的元素个数（势） \\ \hline
    $p(x)$ & 关于变量 $x$ 的命题 $p(x)$ \\ \hline
    $p \wedge q$ & 命题 $p$ 与命题 $q$ \\ \hline
    $p \vee q$ & 命题 $p$ 或命题 $q$ \\ \hline
    $\neg p$ & 命题 $p$ 的否定 \\ \hline
    $p \to q$ 或 $p \Rightarrow q$ & 命题 $p$ 蕴含命题 $q$ \\ \hline 
    $p \leftrightarrow q$ 或 $p \Leftrightarrow q$ & 命题 $p$ 等价于命题 $q$ \\ \hline
    $\forall$ & 任意 \\ \hline
    $\exists$ & 存在 \\ \hline  
    $f:A \to B$ & 从集合 $A$ 到集合 $B$ 的映射（函数）$f$ \\ \hline
    $f(x)$ & 映射（函数） $f$ 在自变量 $x$ 处的值 \\ \hline
    $f \circ g$ & 映射（函数） $f,g$ 的复合 \\ \hline
    $A \times B$ & 集合 $A$ 与集合 $B$ 的笛卡尔积 \\ \hline
    \raisebox{-0.45\height}{\begin{tikzpicture}[scale=0.7]
      \node (A) at (0,0) {$A$};
      \node (B) at (2,0) {$B$};
      \node (C) at (0,-2) {$C$};
      \node (D) at (2,-2) {$D$};
      \draw[->] (A) -- (B) node[midway, above] {$f$};
      \draw[->] (A) -- (C) node[midway, left] {$f_1$};
      \draw[->] (B) -- (D) node[midway, right] {$g$};
      \draw[->] (C) -- (D) node[midway, below] {$g_1$};
    \end{tikzpicture}} & 映射的图表或交换图 \\ \hline
    $\aleph_0$ & 自然数集合 $\mathbb N$ 的势，阿列夫零 \\ \hline
    $\sqrt[n]a$ & $a$ 的 $n$ 次方根 \\ \hline
    $a^x$ & $a$ 的 $x$ 次幂 \\ \hline
    $\log_a b$ & $b$ 的以 $a$ 为底的对数 \\ \hline
    $\lg x$ & $x$ 的常用对数 \\ \hline
    $\ln x$ & $x$ 的自然对数 \\ \hline
    $f^{-1}(x)$ & $f(x)$ 的反函数（逆映射） \\ \hline
    $\sin x$ & $x$ 的正弦 \\ \hline
    $\cos x$ & $x$ 的余弦 \\ \hline
    $\tan x$ & $x$ 的正切 \\ \hline
    $\csc x$ & $x$ 的余割 \\ \hline
    $\sec x$ & $x$ 的正割 \\ \hline
    $\cot x$ & $x$ 的余切 \\ \hline
    $\arcsin x$ & $x$ 的反正弦 \\ \hline
    $\arccos x$ & $x$ 的反余弦 \\ \hline
    $\arctan x$ & $x$ 的反正切 \\ \hline
    $\sum_{i=1}^n a_i$ & $a_1+\cdots+a_n$ \\ \hline
    $\prod_{i=1}^n a_i$ & $a_1\cdots a_n$ \\ \hline
    $\square$ & 证明完毕 \\ \hline
  \end{longtable}
\end{center}

% 目录
\newpage
\tableofcontents
\newpage

\pagenumbering{arabic} 

% 章节内容
\include{chapters/chapter1} % 第一章：集合与逻辑
\include{chapters/chapter2} % 第二章：等式与不等式
\include{chapters/chapter3} % 第三章：函数的概念与性质
\include{chapters/chapter4} % 第四章：三角函数
\include{chapters/chapter5} % 第五章：不等式扩充


\appendix
\include{appendices/appendixA} % 附录：如何解决数学问题
\include{appendices/appendixB} % 附录：数学信息技术运用

\chapter*{中英文词汇对照表}
\addcontentsline{toc}{chapter}{中英文词汇对照表}
\begin{center}
  \begin{longtable}{|>{\raggedright\arraybackslash}p{0.409\textwidth}|>{\raggedright\arraybackslash}p{0.409\textwidth}|>{\raggedleft\arraybackslash}p{0.1\textwidth}|}
    \hline
    \textbf{中文词汇} & \textbf{英文词汇} & \textbf{页码} \\ \hline
    \endfirsthead 
  
    \hline
    \textbf{中文词汇} & \textbf{英文词汇} & \textbf{页码} \\ \hline
    \endhead 
  
    \hline
    \endfoot 
  
    集合 & Set & \pageref{set} \\ \hline
    函数 & Function & \pageref{function} \\ \hline
    不等式 & Inequality & \pageref{inequality} \\ \hline
    三角函数 & Trigonometric Function & \pageref{trigonometry} \\ \hline
  \end{longtable}
  \end{center}

% 封底页
\newpage
\pagenumbering{gobble} 
\thispagestyle{empty}
\begin{titlepage}
  \coverlabelback
\end{titlepage}

\end{document}
