
\documentclass[11pt,fleqn]{book} % Default font size and left-justified equations
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry} % Page margins
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
\usepackage{avant} % Use the Avantgarde font for headings
\usepackage{mathptmx} % Use the Adobe Times Roman as the default text font together with math symbols from the Sym­bol, Chancery and Com­puter Modern fonts
\usepackage{microtype} % Slightly tweak font spacing for aesthetics
\usepackage[style=alphabetic,sorting=nyt,sortcites=true,autopunct=true,babel=hyphen,hyperref=true,abbreviate=false,backref=true,backend=biber]{biblatex}

\usepackage{calc} % For simpler calculation - used for spacing the index letter headings correctly
\usepackage{makeidx} % Required to make an index
\makeindex % Tells LaTeX to create the files required for indexing

\usepackage{amsmath,amsfonts,amssymb,amsthm}
\RequirePackage[framemethod=default]{mdframed}
\usepackage{fancyhdr} % 
\usepackage{titlesec} % Allows customization of titles
\usepackage{titletoc}
\usepackage{graphicx} % Required for including pictures
\graphicspath{{./Pictures/}} % Specifies the directory where pictures are stored

\usepackage{lipsum} % Inserts dummy text

\usepackage{tikz} 

\usepackage{enumitem} % Customize lists
\setlist{nolistsep} % Reduce spacing between bullet points and numbered lists

\usepackage{booktabs} % Required for nicer horizontal rules in tables

\usepackage{eso-pic} 
\usepackage{xepersian}



% Removes the header from odd empty pages at the end of chapters
\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}


\newcommand{\intoo}[2]{\mathopen{]}#1\,;#2\mathclose{[}}
\newcommand{\ud}{\mathop{\mathrm{{}d}}\mathopen{}}
\newcommand{\intff}[2]{\mathopen{[}#1\,;#2\mathclose{]}}
\newtheorem{tho}{قضیه}[chapter]

\newtheoremstyle{ocrenum} % Theorem style name
{7pt} % Space above
{7pt} % Space below
{\normalfont} % Body font
{} % Indent amount
{\small\bf\color{ocre}} % Theorem head font
{\;\;} % Punctuation after theorem head
{0.25em} % Space after theorem head
{\small\color{ocre}\thmname{#1}\thmnumber{\@ifnotempty{#1}{ }\@upn{#2}} % Theorem text (e.g. Theorem 2.1)
\thmnote{\ {\the\thm@notefont\bfseries\color{black}--- #3.}}} % Optional theorem note
\renewcommand{\qedsymbol}{$\blacksquare$} % Optional qed square

\newtheoremstyle{blacknumex} % Theorem style name
{7pt} % Space above
{7pt} % Space below
{\normalfont} % Body font
{} % Indent amount
{\small\bf} % Theorem head font
{\;\;} % Punctuation after theorem head
{0.25em} % Space after theorem head
{\small{\tiny\ensuremath{\blacksquare}}\ \thmname{#1}\thmnumber{\@ifnotempty{#1}{ }\@upn{#2}} % Theorem text (e.g. Theorem 2.1)
\thmnote{\ {\the\thm@notefont\bfseries--- #3.}}} % Optional theorem note

\newtheoremstyle{blacknum} % Theorem style name
{7pt} % Space above
{7pt} % Space below
{\normalfont} % Body font
{} % Indent amount
{\small\bf} % Theorem head font
{\;\;} % Punctuation after theorem head
{0.25em} % Space after theorem head
{\small\thmname{#1}\thmnumber{\@ifnotempty{#1}{ }\@upn{#2}} % Theorem text (e.g. Theorem 2.1)
\thmnote{\ {\the\thm@notefont--- #3.}}} % Optional theorem note
\makeatother

% Defines the theorem text style for each type of theorem to one of the three styles above
\theoremstyle{ocrenum}
\newtheorem{dfi}{تعریف}[chapter]
\newtheorem{prp}{اثبات}[chapter]
\newtheorem{sol}{حل}[chapter]
\newtheorem{exx}{تمرین}[chapter]
\theoremstyle{blacknumex}
\newtheorem{exa}{مثال}[chapter]
\theoremstyle{blacknum}
\newtheorem{voc}{لغات}[chapter]
\newtheorem{rema}{تبصره}[chapter]
\newtheorem{cen}{نتیجه}[chapter]







 % Required for creating the theorem, definition, exercise and corollary boxes

% Theorem box
\newmdenv[skipabove=7pt,
skipbelow=7pt,
backgroundcolor=black!5,
linecolor=ocre,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=5pt,
leftmargin=0cm,
rightmargin=0cm,
innerbottommargin=5pt]{tBox}

% Exercise box	  
\newmdenv[skipabove=7pt,
skipbelow=7pt,
rightline=false,
leftline=true,
topline=false,
bottomline=false,
backgroundcolor=ocre!10,
linecolor=ocre,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=5pt,
innerbottommargin=5pt,
leftmargin=0cm,
rightmargin=0cm,
linewidth=4pt]{eBox}	

% Definition box
\newmdenv[skipabove=10pt,
skipbelow=10pt,
rightline=false,
leftline=true,
topline=false,
bottomline=false,
linecolor=ocre,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=0pt,
leftmargin=0cm,
rightmargin=0cm,
linewidth=4pt,
innerbottommargin=0pt]{dBox}	

% Corollary box
\newmdenv[skipabove=7pt,
skipbelow=7pt,
rightline=false,
leftline=true,
topline=false,
bottomline=false,
linecolor=gray,
backgroundcolor=black!5,
innerleftmargin=5pt,
innerrightmargin=5pt,
innertopmargin=5pt,
leftmargin=0cm,
rightmargin=0cm,
linewidth=4pt,
innerbottommargin=5pt]{cBox}				  
		  

% Creates an environment for each type of theorem and assigns it a theorem text style from the "Theorem Styles" section above and a colored box from above
\newenvironment{thot}{\begin{tBox}\begin{tho}}{\end{tho}\end{tBox}}
% Creates an environment for each type of theorem and assigns it a theorem text style from the "Theorem Styles" section above and a colored box from above
%\newenvironment{theorem}{\begin{tBox}\begin{theoremeT}}{\end{theoremeT}\end{tBox}}
\newenvironment{exxt}{\begin{eBox}\begin{exx}}{\hfill{\color{ocre}\tiny\ensuremath{\blacksquare}}\end{exx}\end{eBox}}				  
\newenvironment{dfit}{\begin{dBox}\begin{dfi}}{\end{dfi}\end{dBox}}	
\newenvironment{exat}{\begin{exa}}{\hfill{\tiny\ensuremath{\blacksquare}}\end{exa}}		
\newenvironment{cent}{\begin{cBox}\begin{cen}}{\end{cen}\end{cBox}}	


\newenvironment{rem}{\par\vskip10pt\small % Vertical white space above the remark and smaller font size
\begin{list}{}{
\leftmargin=35pt % Indentation on the left
\rightmargin=25pt}\item\ignorespaces % Indentation on the right
\makebox[-2pt]{\begin{tikzpicture}[overlay]
\node[draw=ocre!60,line width=1pt,circle,fill=ocre!25,font=\bfseries,inner sep=2pt,outer sep=0pt] at (5pt,2.5pt){\textcolor{ocre}{R}};\end{tikzpicture}} % Orange R in a circle
\advance\baselineskip -1pt}{\end{list}\vskip5pt} % Tighter line spacing and white space after remark











\contentsmargin{0cm} % Removes the default margin
% Chapter text styling
\titlecontents{chapter}[1.25cm] % Indentation
{\addvspace{15pt}\large\bfseries} % Spacing and font options for chapters
{\color{ocre!60}\contentslabel[\Large\thecontentslabel]{1.25cm}\color{ocre}} % Chapter number
{}  
{\color{ocre!60}\normalsize\bfseries\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number
% Section text styling
\titlecontents{section}[1.25cm] % Indentation
{\addvspace{5pt}\bfseries} % Spacing and font options for sections
{\contentslabel[\thecontentslabel]{1.25cm}} % Section number
{}
{\hfill\color{black}\thecontentspage} % Page number
[]
% Subsection text styling
\titlecontents{subsection}[1.25cm] % Indentation
{\addvspace{1pt}\small} % Spacing and font options for subsections
{\contentslabel[\thecontentslabel]{1.25cm}} % Subsection number
{}
{\;\titlerule*[.5pc]{.}\;\thecontentspage} % Page number
[] 

%----------------------------------------------------------------------------------------
%	MINI TABLE OF CONTENTS IN CHAPTER HEADS
%----------------------------------------------------------------------------------------

% Section text styling
\titlecontents{lsection}[0em] % Indendating
{\footnotesize} % Font settings
{}
{}
{}

% Subsection text styling
\titlecontents{lsubsection}[.5em] % Indentation
{\normalfont\footnotesize} % Font settings
{}
{}
{}







\addbibresource{bibliography.bib} % BibTeX bibliography file
\defbibheading{bibempty}{}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\normalsize\bfseries #1}{}} % Chapter text font settings
\renewcommand{\sectionmark}[1]{\markright{\normalsize\thesection\hspace{5pt}#1}{}} % Section text font settings
\fancyhf{} \fancyhead[LE,RO]{\normalsize\thepage} % Font setting for the page number in the header
\fancyhead[LO]{\rightmark} % Print the nearest section name on the left side of odd pages
\fancyhead[RE]{\leftmark} % Print the current chapter name on the right side of even pages
\renewcommand{\headrulewidth}{0.5pt} % Width of the rule under the header
\addtolength{\headheight}{2.5pt} % Increase the spacing around the header slightly
\renewcommand{\footrulewidth}{0pt} % Removes the rule in the footer
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} % Style for when a plain pagestyle is specified









\makeatletter
\renewcommand{\@seccntformat}[1]{\llap{\textcolor{ocre}{\csname the#1\endcsname}\hspace{1em}}}                    
\renewcommand{\section}{\@startsection{section}{1}{\z@}
{-4ex \@plus -1ex \@minus -.4ex}
{1ex \@plus.2ex }
{\normalfont\large\bfseries}}
\renewcommand{\subsection}{\@startsection {subsection}{2}{\z@}
{-3ex \@plus -0.1ex \@minus -.4ex}
{0.5ex \@plus.2ex }
{\normalfont\bfseries}}
\renewcommand{\subsubsection}{\@startsection {subsubsection}{3}{\z@}
{-2ex \@plus -0.1ex \@minus -.2ex}
{0.2ex \@plus.2ex }
{\normalfont\small\bfseries}}                        
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}
{-2ex \@plus-.2ex \@minus .2ex}
{0.1ex}
{\normalfont\small\bfseries}}

%----------------------------------------------------------------------------------------
%	CHAPTER HEADINGS
%----------------------------------------------------------------------------------------
\makeatother

\makeatletter
\newcommand{\thechapterimage}{}
\newcommand{\chapterimage}[1]{\renewcommand{\thechapterimage}{#1}}
\def\thechapter{\arabic{chapter}}
\def\@makechapterhead#1{
\thispagestyle{empty}
{\centering \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\startcontents
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]

\node[anchor=north west,inner sep=0pt] at (0,0) {\includegraphics[width=\paperwidth]{\thechapterimage}};

%Commenting the 3 lines below removes the small contents box in the chapter heading
\draw[fill=white,opacity=.4] (10cm,0) rectangle (18cm,-7cm);
\node[anchor=north east] at (18cm,.25cm) {\parbox[t][8cm][t]{7.5cm}{\rl{\bfseries\flushright \printcontents{r}{1}{\setcounter{tocdepth}{2}}}}};

\draw[anchor=east] (18cm,-9cm) node [rounded corners=25pt,fill=white,fill opacity=.5,text opacity=1,draw=ocre,draw opacity=1,line width=2pt,inner sep=15pt]{\rl{\huge\bfseries\textcolor{black}{\thechapter\ ---\ #1\vphantom{plPQq}\makebox[22cm]{}}}};
\end{tikzpicture}};
\end{tikzpicture}}\par\vspace*{230\p@}
\fi
\fi
}
\def\@makeschapterhead#1{
\thispagestyle{empty}
{\centering \normalfont  
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\startcontents
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west] at (-4pt,4pt) {\includegraphics[width=\paperwidth]{\thechapterimage}};
\draw[anchor=east] (18cm,-9cm) node [rounded corners=25pt,fill=white,opacity=.7,inner sep=26pt]{\rl{\huge\bfseries\textcolor{black}{\vphantom{plPQq}\makebox[22cm]{}}}};
\draw[anchor=east] (18cm,-9cm) node [rounded corners=25pt,draw=ocre,line width=2pt,inner sep=15pt]{\rl{\huge\bfseries\textcolor{black}{#1\vphantom{plPQq}\makebox[22cm]{}}}};
\end{tikzpicture}};
\end{tikzpicture}}\par\vspace*{230\p@}
\fi
\fi
}
\makeatother




\makeatletter
\@ifundefined{Umathcode}{\let\Umathcode\XeTeXmathcode}{}
\@ifundefined{Umathchardef}{\let\Umathchardef\XeTeXmathchardef}{}
\def\@makefnmark{\hbox{\normalfont\@thefnmark\space}}
\def\@makefnmark{\hbox{\normalfont\@thefnmark\@SepMark  }}
\makeatother



\begin{document}

\begingroup
\thispagestyle{empty}
\AddToShipoutPicture*{\put(-175,5){\includegraphics[scale=1]{background}}} % Image background
\centering
\vspace*{9cm}
\par\normalfont\fontsize{35}{35}\selectfont
نظریه گـــــــــراف\par % Book title
\vspace*{1cm}
{\Huge دکتر فلانی}\par % Author name
\endgroup

\chapterimage{chapter_head_1.pdf} % Table of contents heading image

\pagestyle{empty} % No headers

\tableofcontents % Print the table of contents itself

\cleardoublepage % Forces the first chapter to start on an odd page so it's on the right

\pagestyle{fancy} % Print headers again


\chapterimage{chapter_head_1.pdf} 
\chapter{گراف‌های ساده}
\section{تعاریف مقدماتی}
\section{متن}
\section{متن بعد}
مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن 
\newpage
مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن 
\newpage
مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن 
\newpage  
\begin{dfi}

مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری
\end{dfi}

\begin{prp}

مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری
\end{prp}

\begin{sol}

مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری
\end{sol}




\begin{exx}

مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری
\end{exx}

\begin{exa}

مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری
\end{exa}

\begin{rem}
مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری
\end{rem}
\begin{cen}

مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری
\end{cen}
\begin{rema}

مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری
\end{rema}





\begin{cent}

مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری متن مقداری
\end{cent}

\begin{exxt}
قضیه ی توتندی
\end{exxt}

\begin{exat}
قضیه ی توتندی
\end{exat}



\begin{dfit}
مثال
\end{dfit}




%----------------------------------------------------------------------------------------
%	CHAPTER 1
%----------------------------------------------------------------------------------------

\chapterimage{chapter_head_2.pdf} % Chapter heading image

\chapter{زیرگراف}


\end{document}