\usepackage[vmargin=3.5cm,left=3cm,right=4cm]{geometry}  
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage[marginal,stable,bottom]{footmisc}     % for footnotes: marginal --> the same margins as text, 
                                                                                  %                       stable--> ?
                                                                                  %                       bottom --> starting the footnotes at a fixed place at the bottom of the page.
 
    
\usepackage{multirow}                                       
\usepackage{subfigure}
  
\usepackage{cite}                                                     % for collecting citations: [1,2,3,4] --> [1-4]
\usepackage{setspace}                                            % for switching between double/single space in document
\allowdisplaybreaks                                                    % breaking the lines&pages when needed for the style.
\usepackage{parskip}                                               % ? 

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot[OC,EC]{\thepage}
\fancyhead[OL,EL]{}
\fancyhead[OR,ER]{\small\nouppercase\leftmark}
%\relpenalty=9999                                            % show the neccessity of breaks for lines, changing the number to 10000 cause no break in lines.
%\binoppenalty=9999

\usepackage{xecolor}
\usepackage{amsmath}
\usepackage{makeidx}
\usepackage{verbatim}
\usepackage[colorlinks,linkcolor=blue,citecolor=blue]{hyperref}
\usepackage{graphicx}
\usepackage{ifthen}
\allowdisplaybreaks 

\usepackage{supertabular}

\usepackage{amsmath,hhline}

\usepackage{lscape}

\usepackage{pbox}

 \setlength{\parindent}{5pt}


\setcounter{secnumdepth}{3}

\setcounter{tocdepth}{3}

\makeatletter
\pdfstringdefDisableCommands{%
\let\lr\@firstofone
}
\makeatother
% ----------------------------------------------------------------------------
\theoremstyle{plain}
\newtheorem{thm}{قضیه}%[chapter]
\numberwithin{thm}{chapter}
\renewcommand{\thethm}{\arabic{thm}.\arabic{section}.\arabic{chapter}}
\renewcommand{\theequation}{\arabic{equation}.\arabic{section}.\arabic{chapter}}
\newtheorem{lem}[thm]{لم}
\newtheorem{prop}[thm]{گزاره}
\newtheorem{cor}[thm]{نتیجه}
\theoremstyle{definition}
\newtheorem{dfn}[thm]{تعریف}
\newtheorem{subdfn}[thm]{زیرتعریف}
\newtheorem{exam}[thm]{مثال}
\newtheorem{rem}[thm]{تذکر}
\newtheorem{note}[thm]{توجه}
\newtheorem{notee}[thm]{نکته}
\newtheorem{tab}[thm]{تبصره}
\newcommand{\borhan}{\textbf{برهان. }}
\def\d{\displaystyle}
\def\Star{\mathrm{star}}
\def\Co{\mathrm{Co\,}}
\def\resp{\mathrm{resp}}
\def\Sign{\mathrm{sign}}
\def\dist{\mathrm{dist}}
\def\norm{\mathrm{norm}}
\def\DMU{\mathrm{DMU}}
% ----------------------------------------------------------------------------
\usepackage{xepersian}

\usepackage[Lenny]{fncychap}

\settextfont[Scale=1.05]{XB Niloofar}
\setlatintextfont[Scale=1.05]{Times New Roman} 
\setdigitfont[Scale=1.05]{Parsi Digits} 
% قلم برای اعداد به صورت فارسی با صفر توخالی، در صورتی که بخواهیم اعداد انگلیسی نوشته شوند این خط را غیر فعال می‌کنیم.

\defpersianfont\nastaliq[Scale=2.0]{IranNastaliq}
% قلم برای نوشتن تقدیم
\defpersianfont\nastaliqone[Scale=1.0]{IranNastaliq}
\defpersianfont\nastaliqonee[Scale=1.3]{IranNastaliq}
% قلم نستعلیق با سایز متناسب با متن در صورت نیاز
\defpersianfont\anotherfont[Scale=1.2]{IranNastaliq}
% قلم برای نوشتن تشکر (قلم فانتزی)
\newenvironment{fantezi}
{\anotherfont }




\makeindex


\def\beginto{
\newpage
\begin{RTL}
\begin{Large}
\nastaliqone

اَلْحَمدُ لِلّهِ الََّذِي لَا يَبْلُغُ مِدْحَتَهُ الْقَائِلُونَ، وَ لَا يُحْصِي نَعْمَاءَهُ الْعَادُّونَ، وَ لَا يُؤَدّي حَقَّهُ الْمُجْتَهِِدُونَ، الَّذِي لَا يُدْرِکُهُ بُعْدُ الْهِِمَمِ، وَ لَا يَنَالُهُ غَوْصُ الْفِطَنِ... .\\ 
\nastaliqone
سپاس خدای را که حق ستايشش بالاتر از حدّ ستايشگران است و نعمت‌هايش فوق انديشه شمارشگران، حق جويان کوشا از ادای حقّش ناتوانند، و همّت‌های دور پرواز آدميان از درک و احاطه به مقام شامخش نارسا، و حوزه اعلای ربوبی‌اش از نفوذ هشياری هشياران به دور است... . 

 \;\                   \hfill                      نهج البلاغه، خطبه ۱\\[5mm]
\begin{center}
%\vspace*{0.15cm}
\nastaliqonee
 \hspace*{-12.5cm}
تقدیم به 
}

\def\endto{
~
\end{center}
\end{Large}
\end{RTL}
}

\def\beginthanks{
\newpage

{\centering\huge{\nastaliqone{
تشکر و قدردانی ~\\
~}}}
}
\def\endthanks{
~
}

\def\thanks{
\beginthanks
\input{thanks}
\endthanks
}

\def\startpage{
\newpage
\vspace*{3cm}
\begin{center}
\includegraphics[width=12cm]{besm}
\end{center}
}
\makeatletter
\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \centering\normalfont\nastaliq
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \LARGE\bfseries \@chapapp\space \tartibi{chapter} 
        \par\nobreak
        \vskip 30\p@
      \fi
    \fi
    \interlinepenalty\@M
    \LARGE \bfseries #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



\renewcommand\bibname{مراجع}
%\def\contentsname{فهرست}

% some extra diffinitions %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\d{\displaystyle}

\def\bea{\begin{eqnarray}}
\def\eea{\end{eqnarray}}

\def\ba{\begin{array}}
\def\ea{\end{array}}

\def\ni{\noindent}
\def\nn{\nonumber}

\def\bc{\begin{center}}
\def\ec{\end{center}}