
%-------------------------------------------------------------------------------------------------------------------

% در ورژن جدید زی‌پرشین برای تایپ متن‌های ریاضی، این سه بسته، حتماً باید فراخوانی شود

\usepackage{amsthm,amssymb}
\usepackage[fleqn]{amsmath}

% بسته‌ای برای تنطیم حاشیه‌های بالا، پایین، چپ و راست صفحه
\usepackage[top=35mm, bottom=35mm, left=30mm, right=35mm]{geometry}
\footskip=2cm% فاصله شماره صفحه از انتهای متن
% بسته‌‌ای برای ظاهر شدن شکل‌ها و تصاویر متن
\usepackage{graphicx}
\usepackage{float}
%\usepackage{sidecap}
%\usepackage{tikz}
% بسته‌ای برای رسم کادر
\usepackage{framed} 
% بسته‌‌ای برای چاپ شدن خودکار تعداد صفحات در صفحه «معرفی پایان‌نامه»
\usepackage{lastpage}
% بسته‌ و دستوراتی برای ایجاد لینک‌های رنگی با امکان جهش
%\usepackage[pagebackref=false,colorlinks,linkcolor=blue,citecolor=blue]{hyperref}
% چنانچه قصد پرینت گرفتن نوشته خود را دارید، خط بالا را غیرفعال و  از دستور زیر استفاده کنید چون در صورت استفاده از دستور زیر‌‌، 
% لینک‌ها به رنگ سیاه ظاهر خواهند شد که برای پرینت گرفتن، مناسب‌تر است
%\usepackage[utf8]{inputenc}
\usepackage[pdfencoding=auto]{hyperref}
% بسته‌ لازم برای تنظیم سربرگ‌ها
\usepackage{fancyhdr}
%
\usepackage{setspace}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage[font=footnotesize]{caption}
\captionsetup{labelfont=bf,textfont=bf}
\usepackage{subfigure}
\usepackage[subfigure]{tocloft}
\makeatletter
\def\@seccntformat#1{\csname the#1\endcsname \hspace{1cm}}
\def\@subseccntformat#1{\csname the#1\endcsname \hspace{1cm}}
\def\@subsubseccntformat#1{\csname the#1\endcsname \hspace{1cm}}
\makeatother
% بسته‌ای برای ظاهر شدن «مراجع» و «نمایه» در فهرست مطالب
\usepackage[nottoc]{tocbibind}
% دستورات مربوط به ایجاد نمایه
\usepackage{makeidx}
\makeindex
\graphicspath{{figs/}}
%%%%%%%%%%%%%%%%%%%%%%%%%%
%دستورات برای ظاهر شدن شماره زیرزیربخش ها  و نشان دادن آنها در فهرست
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
% فراخوانی بسته زی‌پرشین و تعریف قلم فارسی و انگلیسی
\usepackage{titlesec}
\usepackage[titles]{tocloft} 
\usepackage{xepersian}
\usepackage{bidi}
\usepackage[numbers,sort&compress]{natbib}
\usepackage{bm}
\setlength{\intextsep}{0pt}
\setlength{\parindent}{1cm}
\setlength {\parskip} {0pt}
\setlength{\topskip}{0pt}
\usepackage{lipsum}
\titlespacing{\section}{0pt}{30pt}{24pt}
\titlespacing{\subsection}{0pt}{30pt}{24pt}
\titlespacing{\subsubsection}{0pt}{30pt}{24pt}
\setlength{\mathindent}{0cm}
\settextfont[Scale=1.17]{B Lotus}
\setlatintextfont[Scale=1]{Times New Roman}
\usepackage{xfrac,fontspec,unicode-math}
%\usepackage{bm}
\setmathfont[version=cambria]{Cambria Math}
\setmathfont[range=\mathit ]{Cambria Italic}
\setmathfont[range=\mathbf]{Cambria Bold}
\setmathfont[range=\overrightarrow]{Cambria Math}
\setmathfont[range=\overleftarrow]{Cambria Math}
\mathversion{cambria}
\makeatletter
\makeatletter
\g@addto@macro\normalsize{%
  \setlength\abovedisplayskip{4pt}
  \setlength\belowdisplayskip{4pt}
  \setlength\abovedisplayshortskip{4pt}
  \setlength\belowdisplayshortskip{4pt}
}

\allowdisplaybreaks
\makeatother
\SepMark{-}

%%%%%%%%%%%%%%%%%%%%%%%%%%

\defpersianfont\chapfont[Scale=1.5]{B Lotus}% تعریف اندازه فونت عنوان فصل
\defpersianfont\secfont[Scale=1.25]{B Lotus}% تعریف اندازه فونت عنوان بخش

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
\usepackage[bottom]{footmisc}                                                                        %ثابت کردن فاصله زیرنویس از پایین صفحه
%%%%%%%%%%%%%%%%%%%%%%%%%%
% چنانچه می‌خواهید اعداد در فرمول‌ها، انگلیسی باشد، خط زیر را غیرفعال کنید
\setdigitfont[Scale=1.1]{ZB Nazanin}%{Persian Modern}
%%%%%%%%%%%%%%%%%%%%%%%%%%
% تعریف قلم‌های فارسی و انگلیسی اضافی برای استفاده در بعضی از قسمت‌های متن

%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%
% دستوری برای حذف کلمه «چکیده»
\renewcommand{\abstractname}{}
% دستوری برای حذف کلمه «abstract»
%\renewcommand{\latinabstract}{}
% دستوری برای تغییر نام کلمه «اثبات» به «برهان»
\renewcommand\proofname{\textbf{برهان}}
% دستوری برای تغییر نام کلمه «کتاب‌نامه» به «مراجع»
\renewcommand{\bibname}{مراجع}
% دستوری برای تعریف واژه‌نامه انگلیسی به فارسی
\newcommand\persiangloss[2]{#1\dotfill\lr{#2}\\}
% دستوری برای تعریف واژه‌نامه فارسی به انگلیسی 
\newcommand\englishgloss[2]{#2\dotfill\lr{#1}\\}
% تعریف دستور جدید «\پ» برای خلاصه‌نویسی جهت نوشتن عبارت «پروژه/پایان‌نامه/رساله»
\newcommand{\پ}{پروژه/پایان‌نامه/رساله }

%\newcommand\BackSlash{\char`\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%
%\SepMark{-}
%%%%%%%%%%%%%%%


% تعریف و نحوه ظاهر شدن عنوان قضیه‌ها، تعریف‌ها، مثال‌ها و ...
\theoremstyle{definition}
\newtheorem{definition}{تعریف}[section]
\theoremstyle{theorem}
\newtheorem{theorem}[definition]{قضیه}
\newtheorem{lemma}[definition]{لم}
\newtheorem{proposition}[definition]{گزاره}
\newtheorem{corollary}[definition]{نتیجه}
\newtheorem{remark}[definition]{ملاحظه}
\theoremstyle{definition}
\newtheorem{example}[definition]{مثال}

%\renewcommand{\theequation}{\thechapter-\arabic{equation}}
\def\bibname{مراجع}
%\numberwithin{algorithm}{chapter}
%\listalgorithmname{فهرست الگوریتم‌ها}
%%%%%%%%%%%%%%%%%%%%%%%%%
%دستورات برای نشان دادن زیرنویس در عنوان بخش ها و زیر بخش ها
\makeatletter
\@ifpackageloaded{bidiftnxtra}{}{%
\let\FN@sf@@footnote\footnote
\let\FN@sf@@LTRfootnote\LTRfootnote
\let\FN@sf@@RTLfootnote\RTLfootnote
\def\footnote{\ifx\protect\@typeset@protect
    \expandafter\FN@sf@@footnote
  \else
    \expandafter\FN@sf@gobble@opt
  \fi
}
\def\LTRfootnote{\ifx\protect\@typeset@protect
    \expandafter\FN@sf@@LTRfootnote
  \else
    \expandafter\FN@sf@gobble@opt
  \fi
}
\def\RTLfootnote{\ifx\protect\@typeset@protect
    \expandafter\FN@sf@@RTLfootnote
  \else
    \expandafter\FN@sf@gobble@opt
  \fi
}
\edef\FN@sf@gobble@opt{\noexpand\protect
  \expandafter\noexpand\csname FN@sf@gobble@opt \endcsname}
\expandafter\def\csname FN@sf@gobble@opt \endcsname{%
  \@ifnextchar[%]
    \FN@sf@gobble@twobracket
    \@gobble
}
\def\FN@sf@gobble@twobracket[#1]#2{}
\let\FN@sf@@footnotemark\footnotemark
\def\footnotemark{\ifx\protect\@typeset@protect
    \expandafter\FN@sf@@footnotemark
  \else
    \expandafter\FN@sf@gobble@optonly
  \fi
}
\edef\FN@sf@gobble@optonly{\noexpand\protect
  \expandafter\noexpand\csname FN@sf@gobble@optonly \endcsname}
\expandafter\def\csname FN@sf@gobble@optonly \endcsname{%
  \@ifnextchar[%]
    \FN@sf@gobble@bracket
    {}%
}
\def\FN@sf@gobble@bracket[#1]{}
}
\makeatother
\usepackage{zref-perpage}
\zmakeperpage{footnote}
%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\def\@harfi#1{\ifcase#1\or \hspace{0.4em}الفـ\or ب\or پ\or ت\or ث\or
ج\or چ\or ح\or خ\or د\or ذ\or ر\or ز\or س\or ش\or ص\or ض\or ع\or غ\or
ف\or ق\or ک\or گ\or ل\or م\or ن\or ه\or و\or ی\else\@ctrerr\fi}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%
%دستورات تنظیم فهرست و درج کلمه عنوان و صفحه در فهرست مطالب%%%%

\makeatletter
\renewcommand\tableofcontents{%
\thispagestyle{plain}
\vspace*{70\p@}
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \centerline{\huge\bfseries\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \vskip 40\p@
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }
 % \renewcommand{\baselinestretch}{2}
%%%%%%%%
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{ #1}}
\fancyhf{}
%\fancyhead[LO,RE]{\thepage}
\fancyhead[RE]{\small \bfseries   \rightmark}
\fancyhead[LO]{\small \bfseries\leftmark }
\fancypagestyle{plain}{%
\fancyhead{}
}
\renewcommand{\headrulewidth}{0pt}
\rhead{\small \bfseries عنوان}
\lhead{\small \bfseries صفحه}
%%%%%
  \renewcommand{\@starttoc}[1]{%
  \hboxR to \textwidth{\textbf{عنوان \hfill صفحه}}
  \begingroup
    \makeatletter
    \@input{\jobname.#1}%
    \if@filesw
      \expandafter\newwrite\csname tf@#1\endcsname
      \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
    \fi
    \@nobreakfalse
  \endgroup}
\cfoot{\thepage}
\makeatother

\renewcommand*\cftfigpresnum{شکل}
\settowidth{\cftfignumwidth}{\cftfigpresnum \qquad}
\renewcommand{\cftfigaftersnumb}{\quad}
\renewcommand{\cftfigaftersnum}{:\qquad}
\renewcommand{\contentsname}{\centerline{فهرست مطالب}}
\renewcommand{\listfigurename}{فهرست شکل‌ها و نمودارها}
\renewcommand{\listtablename}{فهرست جدول‌ها}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% دستورهایی برای سفارشی کردن سربرگ صفحات
\csname@twosidetrue\endcsname
\pagestyle{fancy}
\fancyhf{} 
\fancyfoot[c]{\thepage}
\renewcommand{\headrulewidth}{0pt}

% \newcommand{\SetHeader}{
% \csname@twosidetrue\endcsname
% \pagestyle{fancy}
% \fancyhf{} 
% \fancyhead[OL,EL]{\thepage}
% \fancyhead[OR]{\small\rightmark}
% \fancyhead[ER]{\small\leftmark}
% \renewcommand{\chaptermark}[1]{%
% \markboth{\thechapter-\ #1}{}}
% }
%%%%%%%%%%%%5
%\def\MATtextbaseline{1.5}
%\renewcommand{\baselinestretch}{\MATtextbaseline}
\doublespacing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% دستوراتی برای اضافه کردن کلمه «فصل» در فهرست مطالب


\newlength\mylenprt
\newlength\mylenchp
\newlength\mylenapp

\renewcommand\cftpartpresnum{\partname~}
\renewcommand\cftchappresnum{\chaptername~}
\renewcommand\cftchapaftersnum{\qquad } 

\settowidth\mylenprt{\cftpartfont\cftpartpresnum\cftpartaftersnum}
\settowidth\mylenchp{\cftchapfont\cftchappresnum\cftchapaftersnum}
\settowidth\mylenapp{\cftchapfont\appendixname~\cftchapaftersnum}
\addtolength\mylenprt{\cftpartnumwidth}
\addtolength\mylenchp{\cftchapnumwidth}
\addtolength\mylenapp{\cftchapnumwidth}

\setlength\cftpartnumwidth{\mylenprt}
\setlength\cftchapnumwidth{\mylenchp}	

\makeatletter
{\def\thebibliography#1{\chapter*{\refname\@mkboth
   {\uppercase{\refname}}{\uppercase{\refname}}}\list
   {[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}
   \rightmargin\labelwidth
   \advance\rightmargin\labelsep
   \advance\rightmargin\bibindent
   \itemindent -\bibindent
   \listparindent \itemindent
   \parsep \z@
   \usecounter{enumi}}
   \def\newblock{}
   \sloppy
   \sfcode`\.=1000\relax}}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%وسط چین کردن عنوان فصل و حروفی کردن شماره فصل ها در اول هر فصل%%%%%%%%%% 
\makeatletter
\renewcommand \thechapter {\@tartibi\c@chapter}
\def\@makechapterhead #1{%
  \vspace*{-40\p@}%
  {\parindent \z@ \centering\normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \Huge\bfseries {\chapterfont \@chapapp}\space \thechapter
        % \Huge\bfseries {\chapterfont \@chapapp\space \thechapter}
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \Huge \bfseries{\chapterfont #1}\par\nobreak
    \vskip 40\p@
  }}
\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \centering
    \normalfont
    \interlinepenalty\@M
    \Huge \bfseries   #1\par\nobreak
    \vskip 40\p@
  }}
\makeatother
%%%%%%%%%%%%%%%%

%%%%%%%%%%%%% عددی کردن شماره فصل در شماره فرمول ها
\makeatletter
\renewcommand \theequation {\@arabic\c@equation -\@arabic\c@chapter}   
\renewcommand \thefigure {\@arabic\c@figure -\@arabic\c@chapter}
\renewcommand \thesection {\@arabic\c@section -\@arabic\c@chapter}
\makeatother




