% !TEX TS-program = XeLaTeX
% !TeX root=main.tex
% در این فایل، دستورها و تنظیمات مورد نیاز، آورده شده است.
%-------------------------------------------------------------------------------------------------------------------

% در ورژن جدید زی‌پرشین برای تایپ متن های ریاضی، این سه بسته، حتماً باید فراخوانی شود
\usepackage{amsthm,amssymb,amsmath}
% بسته‌ای برای تنطیم حاشیه‌های بالا، پایین، چپ و راست صفحه
\usepackage[top=30mm, bottom=25mm, left=25mm, right=35mm]{geometry}
% بسته  ای برای ظاهر شدن شکل ها و تصاویر متن
\usepackage{graphicx}
\usepackage{pdfpages}
% بسته‌ای برای رسم کادر
%\usepackage{framed} 
% بسته  ای برای چاپ شدن خودکار تعداد صفحات در صفحه «معرفی پایان‌نامه»
%\usepackage{lastpage}


\usepackage[obeyDraft]{todonotes}
\setlength{\marginparwidth}{2cm}

% بسته  لازم برای تنظیم سربرگ ها
\usepackage{fancyhdr}
%
\usepackage{setspace}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{subfigure}
\usepackage[subfigure]{tocloft}



% بسته موردنیاز برای رسم نمودارهای زیبا
\usepackage{tikz}
\usetikzlibrary{arrows,automata, shapes,positioning,matrix,calc}
\usepackage[object=vectorian]{pgfornament}
% بسته‌ای برای ظاهر شدن «مراجع» و «نمایه» در فهرست مطالب
\usepackage[nottoc]{tocbibind}
% دستورات مربوط به‌ایجاد نمایه
\usepackage{makeidx}
\makeindex
% رنگهای موردنیاز در کدنویسی
\usepackage{xcolor}
% بسته مورد نیاز برای نوشتن کدهای برنامه نویسی در نوشتار 
\usepackage[final]{listings}

\usepackage{tabularx}
\usepackage{hhline}
\usepackage{pbox}
\usepackage{caption}
\usepackage{rotating}

% hyperref: بسته  و دستوراتی برای ایجاد لینک های رنگی با امکان جهش
% بررسی حالت پیش نویس
\usepackage{ifdraft}
\ifdraft
{%
    \usepackage[pagebackref=true,colorlinks,linkcolor=blue,citecolor=blue,final]{hyperref}
    \usepackage[firstpage]{draftwatermark}
\SetWatermarkText{\ \ \ پیش‌نویس}
\SetWatermarkScale{1.2}
}
{
 % اگر مایلید در نسخه چاپی هم لینکها رنگی باشند، رنگهای دستور زیر را مطابق دستور شش خط بالاتر تنظیم نمایید.
   \usepackage[pagebackref=false,colorlinks,linkcolor=black,citecolor=black,urlcolor=black]{hyperref}
}

\usepackage[xindy,acronym,nonumberlist=true]{glossaries}

%\usepackage[thinlines]{easytable}
\usepackage[extrafootnotefeatures]{xepersian}
\usepackage{amsmath}
%\usepackage{xspace}
%%%%%%%%%%%%%%%%%%%%%%%%%%
% فراخوانی بسته زی‌پرشین و تعریف قلم فارسی و انگلیسی
\usepackage[extrafootnotefeatures]{xepersian}
\settextfont[BoldFont={NazaninBold.ttf}, BoldItalicFont={NazaninBold.ttf}, ItalicFont={bnazanin.ttf},Scale=1.07]{bnazanin.ttf}%{IRZar.ttf}

\setlatintextfont[Scale=0.94]{Times New Roman}

%%%%%%%%%%%%%%%%%%%%%%%%%%
%\setdigitfont[Scale=1.2]{times.ttf}
%%%%%%%%%%%%%%%%%%%%%%%%%%
% تعریف قلم های فارسی و انگلیسی اضافی برای استفاده در بعضی از قسمت‌های متن
\defpersianfont\titlefont[Scale=1]{IRTitr.ttf}
\setiranicfont[Scale=1.3]{bnazanin.ttf}				% ایرانیک، خوابیده به چپ
% \defpersianfont\nastaliq[Contextuals=Swash,Scale=1.2]{IranNastaliq}
\setmathsfdigitfont{IRTitr.ttf}


% راستچین شدن todonotes
\presetkeys{todonotes}{align=right,textdirection=righttoleft}{}
\makeatletter
\providecommand\@dotsep{5}
\def\listtodoname{فهرست کارهای باقیمانده}
\def\listoftodos{\newpage\noindent{\Large\vspace{10mm}\textbf{\listtodoname}}\@starttoc{tdo}}
\renewcommand{\@todonotes@MissingFigureText}{شکل}
\renewcommand{\@todonotes@MissingFigureUp}{شکل}
\renewcommand{\@todonotes@MissingFigureDown}{جاافتاده}
\makeatother


\paragraphfootnotes   % برای افقی بودن زیرنویسها
%%%%%%%%%%%%%%%%%%%%%%%%%%
% دستوری برای حذف کلمه «چکیده»
\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]{مثال}
% از یک شروع شدن شماره‌ها در هر بخش
%\makeatletter
%\@addtoreset{definition}{section}
%\makeatother


%\renewcommand{\theequation}{\thechapter-\arabic{equation}}
%\def\bibname{مراجع}
\numberwithin{algorithm}{chapter}
\def\listalgorithmname{فهرست الگوریتم ها}
\def\listfigurename{فهرست تصاویر}
\def\listtablename{فهرست جداول}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% دستورهایی برای سفارشی کردن سربرگ صفحات
% \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{:}

\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}}
   
% اگر مایلید در شماره گذاری حرفی و ابجد به جای آ از الف استفاده شود دستورات زیر را فعال کنید.   
%\def\@Abjad#1{%
%  \ifcase#1\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}
%
% \def\abj@num@i#1{%
%   \ifcase#1\or الف\or ب\or ج\or د%
%            \or هـ‍\or و\or ز\or ح\or ط\fi
%   \ifnum#1=\z@\abjad@zero\fi}   
%  
%   \def\@harfi#1{\ifcase#1\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 م\or ن\or و\or ه\or ی\else\@ctrerr\fi}
%
\makeatother

%%%%%%%%%%%%%%% امکان درج کد در سند
%  در این قسمت تمام ابزارهای مورد نیاز در نوشتن برنامه‌ها اورده شده 
%  است. با استفاده از این ابزارهای می توان برنامه‌های مورد نیاز را در مستند جای داد.
\ifdraft
{%
\lstset{% general command to set parameter(s) 
basicstyle=\setLTR\footnotesize\ttfamily,
captiondirection=RTL,
keywordstyle=\color{blue}\bfseries,
identifierstyle=, % nothing happens
stringstyle=\color{red},
commentstyle=\color{LimeGreen}, % white comments
stringstyle=\color{red}, % typewriter type for strings
showstringspaces=false} % no special string spaces
}
{
\lstset{
basicstyle=\setLTR\footnotesize\ttfamily,
captiondirection=RTL,
keywordstyle=\bfseries,
showstringspaces=false} % no special string spaces
}
%\threecolumnfootnotes
%\RTLcolumnfootnotes

\def\lstlistingname{برنامه }

% for numbering subsubsections
\setcounter{secnumdepth}{3}
%to include subsubsections in the table of contents
\setcounter{tocdepth}{3}

% اگر مایلید شماره پاورقی‌های لاتین به لاتین و فارسی به فارسی باشد:
%\makeatletter
%\def\@makeLTRfnmark{\hbox{\@textsuperscript{\latinfont\@thefnmark}}}
%\renewcommand\@makefntext[1]{%
%    \parindent 1em%
%    \noindent
%    \hb@xt@1.8em{\hss\if@RTL\@makefnmark\else\@makeLTRfnmark\fi}#1}
%\makeatother

\newcommand{\argmin}{\arg\!\min}
\newcommand{\argmax}{\arg\!\max}
\newcommand\norm[1]{\left\lVert#1\right\rVert}