%%
%% This is file `xepersian.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xepersian.dtx  (with options: `table,xepersian.sty')
%% 
%%   __________________________________________________
%%   Copyright (c) 2008--2015  Vafa Khalighi <persian-tex@tug.org>
%% 
%%   It may be distributed and/or modified under the LaTeX Project Public License,
%%   version 1.3c or higher (your choice). The latest version of
%%   this license is at: http://www.latex-project.org/lppl.txt
%% 
%%   This work is “author-maintained” (as per LPPL maintenance status)
%%   by Vafa Khalighi.
%% 
%% 
%% \CheckSum{9995}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
\NeedsTeXFormat{LaTeX2e}
\def\xepersianversion{v15.8}
\def\xepersiandate{2015/02/01}
\ProvidesPackage{xepersian}[\xepersiandate\space \xepersianversion\space
Persian typesetting in XeLaTeX]
\RequirePackage{fontspec}
\RequirePackage{xepersian-persiancal}
\RequirePackage{xepersian-mathsdigitspec}
\RequirePackage{bidi}
\edef\@xepersian@info{****************************************************^^J%
* ^^J%
* xepersian package (Persian for LaTeX, using XeTeX engine)^^J%
* ^^J%
* Description: The package supports Persian^^J%
* typesetting, using fonts provided in the^^J%
* distribution.^^J%
* ^^J%
* Copyright (c) 2008--2015 Vafa Khalighi^^J%
* ^^J%
* \xepersianversion, \xepersiandate^^J%
* ^^J%
* License: LaTeX Project Public License, version^^J%
* 1.3c or higher (your choice)^^J%
* ^^J%
* Location on CTAN: /macros/xetex/latex/xepersian^^J%
* ^^J%
* Issue tracker: https://github.com/persian-tex/xepersian/issues^^J%
* ^^J%
* Support: persian-tex@tug.org^^J%
****************************************************}
\typeout{\@xepersian@info}
\edef\xepersian@everyjob{\the\everyjob}
\everyjob{\xepersian@everyjob\typeout{\@xepersian@info}}
\def\prq{«}
\def\plq{»}
\def\xepersian@cmds@temp#1{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname xepersian@#1\endcsname\relax
    \begingroup
      \escapechar=-1 %
      \edef\x{\expandafter\meaning\csname#1\endcsname}%
      \def\y{#1}%
      \def\z##1->{}%
      \edef\y{\expandafter\z\meaning\y}%
    \expandafter\endgroup
    \ifx\x\y
      \expandafter\def\csname xepersian@#1\expandafter\endcsname
      \expandafter{%
        \csname#1\endcsname
      }%
    \fi
  \fi
}%
\xepersian@cmds@temp{shellescape}
\newif\ifwritexviii
\ifnum\xepersian@shellescape=1\relax
  \writexviiitrue
\else
\writexviiifalse
\fi
\newfontscript{Parsi}{arab}
\newfontlanguage{Parsi}{FAR}
\ExplSyntaxOn
\DeclareDocumentCommand \settextfont { O{} m O{} }
 {
  \fontspec_set_family:cnn { g__fontspec_ \cs_to_str:N \persianfont  _family } {Script=Parsi,Language=Parsi,Mapping=parsidigits,#1,#3} {#2}
  \use:x
   {
    \exp_not:N \DeclareRobustCommand \exp_not:N \persianfont
     {
      \exp_not:N \fontencoding {\g_fontspec_encoding_tl}
      \exp_not:N \fontfamily { \use:c {g__fontspec_ \cs_to_str:N \persianfont _family} } \exp_not:N \selectfont
     }
   }
  \cs_set_eq:NN \rmdefault \l_fontspec_family_tl
  \normalfont
 }
\DeclareDocumentCommand \setlatintextfont { O{} m O{} }
 {
  \fontspec_set_family:cnn { g__fontspec_ \cs_to_str:N \latinfont _family } {Mapping=tex-text,#1,#3} {#2}
  \use:x
   {
    \exp_not:N \DeclareRobustCommand \exp_not:N \latinfont
     {
      \exp_not:N \fontencoding {\g_fontspec_encoding_tl}
      \exp_not:N \fontfamily { \use:c {g__fontspec_ \cs_to_str:N \latinfont _family} } \exp_not:N \selectfont
     }
   }
 }
\cs_set_eq:NN \setlatinsansfont \setsansfont
\cs_set_eq:NN \setlatinmonofont \setmonofont
\DeclareDocumentCommand \defpersianfont { m O{} m O{} }
 {
  \fontspec_set_family:cnn { g__fontspec_ \cs_to_str:N #1 _family } {Script=Parsi,Language=Parsi,Mapping=parsidigits,#2,#4} {#3}
  \use:x
   {
    \exp_not:N \DeclareRobustCommand \exp_not:N #1
     {
      \exp_not:N \fontencoding {\g_fontspec_encoding_tl}
      \exp_not:N \fontfamily { \use:c {g__fontspec_ \cs_to_str:N #1 _family} } \exp_not:N \selectfont
     }
   }
 }
\DeclareDocumentCommand \deflatinfont { m O{} m O{} }
 {
  \fontspec_set_family:cnn { g__fontspec_ \cs_to_str:N #1 _family } {Mapping=tex-text,#2,#4} {#3}
  \use:x
   {
    \exp_not:N \DeclareRobustCommand \exp_not:N #1
     {
      \exp_not:N \fontencoding {\g_fontspec_encoding_tl}
      \exp_not:N \fontfamily { \use:c {g__fontspec_ \cs_to_str:N #1 _family} } \exp_not:N \selectfont
     }
   }
 }
\newcommand\persiansfdefault{}
\newcommand\persianttdefault{}
\newcommand\iranicdefault{}
\newcommand\navardefault{}
\newcommand\pookdefault{}
\newcommand\sayehdefault{}
\DeclareRobustCommand\persiansffamily
        {\not@math@alphabet\persiansffamily\mathpersiansf
         \fontfamily\persiansfdefault\selectfont}
\DeclareRobustCommand\persianttfamily
        {\not@math@alphabet\persianttfamily\mathpersiantt
         \fontfamily\persianttdefault\selectfont}
\DeclareRobustCommand\iranicfamily
        {\not@math@alphabet\iranicfamily\mathiranic
         \fontfamily\iranicdefault\selectfont}
\DeclareRobustCommand\navarfamily
        {\not@math@alphabet\navarfamily\mathnavar
         \fontfamily\navardefault\selectfont}
\DeclareRobustCommand\pookfamily
        {\not@math@alphabet\pookfamily\mathpook
         \fontfamily\pookdefault\selectfont}
\DeclareRobustCommand\sayehfamily
        {\not@math@alphabet\sayehfamily\mathsayeh
         \fontfamily\sayehdefault\selectfont}
\DeclareTextFontCommand{\textpersiansf}{\persiansffamily}
\DeclareTextFontCommand{\textpersiantt}{\persianttfamily}
\DeclareTextFontCommand{\textiranic}{\iranicfamily}
\DeclareTextFontCommand{\textnavar}{\navarfamily}
\DeclareTextFontCommand{\textpook}{\pookfamily}
\DeclareTextFontCommand{\textsayeh}{\sayehfamily}
\DeclareDocumentCommand \setpersiansansfont { O{} m O{} }
 {
  \fontspec_set_family:Nnn \persiansfdefault {Script=Parsi,Language=Parsi,Mapping=parsidigits,#1,#3}{#2}
  \normalfont
  \ignorespaces
 }
\DeclareDocumentCommand \setpersianmonofont { O{} m O{} }
 {
  \fontspec_set_family:Nnn \persianttdefault {Script=Parsi,Language=Parsi,Mapping=parsidigits,#1,#3}{#2}
  \normalfont
  \ignorespaces
 }
\DeclareDocumentCommand \setnavarfont { O{} m O{} }
 {
  \fontspec_set_family:Nnn \navardefault {Script=Parsi,Language=Parsi,Mapping=parsidigits,#1,#3}{#2}
  \normalfont
  \ignorespaces
 }
\DeclareDocumentCommand \setpookfont { O{} m O{} }
 {
  \fontspec_set_family:Nnn \pookdefault {Script=Parsi,Language=Parsi,Mapping=parsidigits,#1,#3}{#2}
  \normalfont
  \ignorespaces
 }
\DeclareDocumentCommand \setsayehfont  { O{} m O{} }
 {
  \fontspec_set_family:Nnn \sayehdefault {Script=Parsi,Language=Parsi,Mapping=parsidigits,#1,#3}{#2}
  \normalfont
  \ignorespaces
 }
\DeclareDocumentCommand \setiranicfont { O{} m O{} }
 {
  \fontspec_set_family:Nnn \iranicdefault {Script=Parsi,Language=Parsi,Mapping=parsidigits,#1,#3}{#2}
  \normalfont
  \ignorespaces
 }
\ExplSyntaxOff
\def\resetlatinfont{%
\let\normalfont\latinfont%
\let\reset@font\normalfont%
\latinfont}
\def\setpersianfont{%
\let\normalfont\persianfont%
\let\reset@font\normalfont%
\persianfont}
\bidi@newrobustcmd*{\lr}[1]{\LRE{\@Latintrue\latinfont#1}}
\bidi@newrobustcmd*{\rl}[1]{\RLE{\@Latinfalse\persianfont#1}}
\def\latin{\LTR\LatinAlphs\@Latintrue\@RTL@footnotefalse\resetlatinfont}
\def\endlatin{\endLTR}
\def\persian{\RTL\PersianAlphs\@RTL@footnotetrue\setpersianfont}
\def\endpersian{\endRTL}
\newenvironment{latinitems}{\begin{LTRitems}\LatinAlphs\@Latintrue\@RTL@footnotefalse\resetlatinfont}{\end{LTRitems}}
\newenvironment{parsiitems}{\begin{RTLitems}\PersianAlphs\@RTL@footnotetrue\setpersianfont}{\end{RTLitems}}
\let\originaltoday=\today
\def\latintoday{\lr{\originaltoday}}
\def\today{\rl{\persiantoday}}
\def \@LTRmarginparreset {%
        \reset@font
        \latinfont
        \normalsize
        \@minipagetrue
        \everypar{\@minipagefalse\everypar{}\beginL}%
}
\DeclareRobustCommand\Latincite{%
  \@ifnextchar [{\@tempswatrue\@Latincitex}{\@tempswafalse\@Latincitex[]}}
\def\@Latincitex[#1]#2{\leavevmode
  \let\@citea\@empty
  \@cite{\lr{\@for\@citeb:=#2\do
    {\@citea\def\@citea{,\penalty\@m\ }%
     \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@\@citeb}{\hbox{\reset@font\bfseries ?}%
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\@cite@ofmt{\csname b@\@citeb\endcsname}}}}}{#1}}
\def\@outputpage{%
\begingroup           % the \endgroup is put in by \aftergroup
  \let \protect \noexpand
  \@resetactivechars
  \global\let\@@if@newlist\if@newlist
  \global\@newlistfalse
  \@parboxrestore
  \shipout \vbox{%
    \set@typeset@protect
    \aftergroup \endgroup
    \aftergroup \set@typeset@protect
                                % correct? or just restore by ending
                                % the group?
  \if@specialpage
    \global\@specialpagefalse\@nameuse{ps@\@specialstyle}%
  \fi
  \if@twoside
    \ifodd\count\z@ \let\@thehead\@oddhead \let\@thefoot\@oddfoot
         \let\@themargin\oddsidemargin
    \else \let\@thehead\@evenhead
       \let\@thefoot\@evenfoot \let\@themargin\evensidemargin
    \fi
    \ifx\@thehead\@empty \let\@thehead\hfil \fi
    \ifx\@thefoot\@empty \let\@thefoot\hfil \fi
    \else %% not @twoside
    \ifx\@oddhead\@empty \let\@thehead\hfil \fi
    \ifx\@oddfoot\@empty \let\@thefoot\hfil \fi
  \fi
  \reset@font
  \normalsize
  \if@RTLmain\setpersianfont\else\resetlatinfont\fi
  \normalsfcodes
  \let\label\@gobble
  \let\index\@gobble
  \let\glossary\@gobble
  \baselineskip\z@skip \lineskip\z@skip \lineskiplimit\z@
    \@begindvi
    \vskip \topmargin
    \moveright\@themargin \vbox {%
      \setbox\@tempboxa \vbox to\headheight{%
        \vfil
        \color@hbox
          \normalcolor
          \hb@xt@\textwidth{\if@RTLmain\@RTLtrue\beginR\else\@RTLfalse\beginL\fi\@thehead\if@RTLmain\endR\else\endL\fi}%
        \color@endbox
        }%                        %% 22 Feb 87
      \dp\@tempboxa \z@
      \box\@tempboxa
      \vskip \headsep
      \box\@outputbox
      \baselineskip \footskip
      \color@hbox
        \normalcolor
        \hb@xt@\textwidth{\if@RTLmain\@RTLtrue\beginR\else\@RTLfalse\beginL\fi\@thefoot\if@RTLmain\endR\else\endL\fi}%
      \color@endbox
      }%
    }%
  \global\let\if@newlist\@@if@newlist
  \global \@colht \textheight
  \stepcounter{page}%
  \let\firstmark\botmark
}
\newcommand\twocolumnstableofcontents{%
\@ifpackageloaded{multicol}{%
  \begin{multicols}{2}[\section*{\contentsname}]%
    \small
    \@starttoc{toc}%
  \end{multicols}}
{\PackageError{xepersian}{Oops! you should load multicol package before xepersian package for being able to use this command}{}}}
\def\XePersian{\leavevmode$\smash{\hbox{X\lower.5ex
  \hbox{\kern-.125em\bidi@reflect@box{E}}Persian}}$}
\def\figurename{\if@RTL شکل\else Figure\fi}
\def\tablename{\if@RTL جدول\else Table\fi}
\def\contentsname{\if@RTL فهرست مطالب\else Contents\fi}
\def\listfigurename{\if@RTL فهرست تصاویر\else List of Figures\fi}
\def\listtablename{\if@RTL فهرست جداول\else List of Tables\fi}
\def\appendixname{\if@RTL پیوست\else Appendix\fi}
\def\indexname{\if@RTL نمایه\else Index\fi}
\def\refname{\if@RTL مراجع\else References\fi}
\def\abstractname{\if@RTL چکیده\else Abstract\fi}
\def\partname{\if@RTL بخش\else Part\fi}
\def\datename{\if@RTL تاریخ:\else Date:\fi}
\def\@@and{\if@RTL و\else and\fi}
\def\bibname{\if@RTL کتاب‌نامه\else Bibliography\fi}
\def\chaptername{\if@RTL فصل\else Chapter\fi}
\def\ccname{\if@RTL رونوشت\else cc\fi}
\def\enclname{\if@RTL پیوست\else encl\fi}
\def\pagename{\if@RTL صفحه\else Page\fi}
\def\headtoname{\if@RTL به\else To\fi}
\def\proofname{\if@RTL اثبات\else Proof\fi}
\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\Abjad#1{\expandafter\@Abjad\csname c@#1\endcsname}
\let\Abjadnumeral\@Abjad
\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}
\def\harfi#1{\expandafter\@harfi\csname c@#1\endcsname}
\let\harfinumeral\@harfi
\newcommand{\adadi}[1]{%
\expandafter\@adadi\csname c@#1\endcsname%
}
\newcommand{\@adadi}[1]{%
\xepersian@numberstring{#1}\xepersian@yekanii{صفر}{}%
}
\let\adadinumeral\@adadi%
\def\xepersian@numberoutofrange#1#2{%
\PackageError{xepersian}{The number `#1' is too large %
to be formatted using xepersian}{The largest possible %
number is 999,999,999.}%
}
\def\xepersian@numberstring#1#2#3#4{%
\ifnum\number#1<\@ne%
#3%
\else\ifnum\number#1<1000000000 %
\expandafter\xepersian@adadi\expandafter{\number#1}#2%
\else%
\xepersian@numberoutofrange{#1}{#4}%
\fi\fi%
}
\def\xepersian@adadi#1#2{%
\expandafter\xepersian@@adadi%
\ifcase%
\ifnum#1<10 1%
\else\ifnum#1<100 2%
\else\ifnum#1<\@m 3%
\else\ifnum#1<\@M 4%
\else\ifnum#1<100000 5%
\else\ifnum#1<1000000 6%
\else\ifnum#1<10000000 7%
\else\ifnum#1<100000000 8%
\else9%
\fi\fi\fi\fi\fi\fi\fi\fi %
\or00000000#1% case 1: Add 8 leading zeros
\or0000000#1%  case 2: Add 7 leading zeros
\or000000#1%   case 3: Add 6 leading zeros
\or00000#1%    case 4: Add 5 leading zeros
\or0000#1%     case 5: Add 4 leading zeros
\or000#1%      case 6: Add 3 leading zeros
\or00#1%       case 7: Add 2 leading zeros
\or0#1%        case 8: Add 1 leading zero
\or#1%         case 9: Add no leading zeros
\or%
\@nil#2%
\fi%
}
\def\xepersian@@adadi#1#2#3#4#5#6#7\or#8\@nil#9{%
\ifnum#1#2#3>\z@
\xepersian@milyoongan#1#2#3%
\ifnum#7>\z@\ifnum#4#5#6>\z@\ و \else\ و \fi\else\ifnum#4#5#6>\z@\ و \fi\fi%
\fi%
\ifnum#4#5#6>\z@%
\xepersian@sadgan#4#5#6{#1#2#3}{#4#5}\xepersian@yekani%
\ifnum#4#5#6>\@ne‌\fi%
هزار%
\ifnum#7>\z@\ و \fi%
\fi%
\xepersian@sadgan#7{#4#5#6}1#9%
}
\def\xepersian@milyoongan#1#2#3{%
\ifnum#1#2#3=\@ne%
\xepersian@sadgan#1#2#301\xepersian@yekaniii%
‌%
میلیون%
\else%
\xepersian@sadgan#1#2#301\xepersian@yekanii%
‌%
میلیون%
\fi%
}
\def\xepersian@sadgan#1#2#3#4#5#6{%
\ifnum#1>\z@%
\ifnum#4#1>\@ne\xepersian@yekaniv#1\fi%
صد%
\ifnum#2#3>\z@\ و \fi%
\fi%
\ifnum#2#3<20%
\ifnum#5#2#3>\@ne#6{#2#3}\fi%
\else%
\xepersian@dahgan#2%
\ifnum#3>\z@\ و \xepersian@yekani#3\fi%
#60%
\fi%
}
\def\xepersian@yekani#1{%
\ifcase#1\@empty\or یک\or دو\or سه\or چهار\or پنج\or شش%
\or هفت\or هشت\or نه\or ده\or یازده\or دوازده\or سیزده%
\or چهارده\or پانزده\or شانزده\or هفده%
\or هجده\or نوزده\fi%
}
\def\xepersian@yekanii#1{%
\ifcase#1\@empty\or یک\else\xepersian@yekani{#1}\fi%
}
\def\xepersian@yekaniii#1{%
\ifcase#1\@empty\or یک\else\xepersian@yekani{#1}\fi%
}
\def\xepersian@yekaniv#1{%
\ifcase#1\@empty\or\or دوی\or سی\or چهار\or پان\or شش%
\or هفت\or هشت\or نه\fi%
}
\def\xepersian@dahgan#1{%
\ifcase#1\or\or بیست\or سی\or چهل%
\or پنجاه\or شصت\or هفتاد\or هشتاد%
\or نود\fi%
}
\newcommand{\tartibi}[1]{%
\expandafter\@tartibi\csname c@#1\endcsname%
}
\newcommand{\@tartibi}[1]{%
\xepersian@numberstring@tartibi{#1}\xepersian@tartibi{صفرم}{م}%
}
\let\tartibinumeral\@tartibi%
\def\xepersian@numberstring@tartibi#1#2#3#4{%
\ifnum\number#1<\@ne%
#3%
\else\ifnum\number#1<1000000000 %
\expandafter\xepersian@adadi@tartibi\expandafter{\number#1}#2%
\else%
\xepersian@numberoutofrange{#1}{#4}%
\fi\fi%
}
\def\xepersian@adadi@tartibi#1#2{%
\expandafter\xepersian@@adadi@tartibi%
\ifcase%
\ifnum#1<10 1%
\else\ifnum#1<100 2%
\else\ifnum#1<\@m 3%
\else\ifnum#1<\@M 4%
\else\ifnum#1<100000 5%
\else\ifnum#1<1000000 6%
\else\ifnum#1<10000000 7%
\else\ifnum#1<100000000 8%
\else9%
\fi\fi\fi\fi\fi\fi\fi\fi %
\or00000000#1% case 1: Add 8 leading zeros
\or0000000#1%  case 2: Add 7 leading zeros
\or000000#1%   case 3: Add 6 leading zeros
\or00000#1%    case 4: Add 5 leading zeros
\or0000#1%     case 5: Add 4 leading zeros
\or000#1%      case 6: Add 3 leading zeros
\or00#1%       case 7: Add 2 leading zeros
\or0#1%        case 8: Add 1 leading zero
\or#1%         case 9: Add no leading zeros
\or%
\@nil#2%
\fi%
}
\def\xepersian@@adadi@tartibi#1#2#3#4#5#6#7\or#8\@nil#9{%
\ifnum#1#2#3>\z@
\xepersian@milyoongan@tartibi#1#2#3%
\ifnum#7>\z@\ifnum#4#5#6>\z@\ و \else\ و \fi\else\ifnum#4#5#6>\z@\ و \fi\fi%
\fi%
\ifnum#4#5#6>\z@%
\xepersian@sadgan#4#5#6{#1#2#3}{#4#5}\xepersian@yekani%
\ifnum#4#5#6>\@ne ‌\fi%
هزار%
\ifnum#7>\z@\ و \fi%
\fi%
\xepersian@sadgan@tartibi#7{#4#5#6}1#9%
}
\def\xepersian@milyoongan@tartibi#1#2#3{%
\ifnum#1#2#3=\@ne%
\xepersian@sadgan@tartibi#1#2#301\xepersian@yekaniii%
‌%
میلیون%
\else%
\xepersian@sadgan#1#2#301\xepersian@yekanii%
‌%
میلیون%
\fi%
}
\def\xepersian@sadgan@tartibi#1#2#3#4#5#6{%
\ifnum#1>\z@%
\ifnum#4#1>\@ne\xepersian@yekaniv#1\fi%
صد%
\ifnum#2#3>\z@\ و \fi%
\fi%
\ifnum#2#3<20%
\ifnum#5#2#3>\@ne\ifnum#1#2#3#4#5=10001 اول\else#6{#2#3}\fi\fi%
\else%
\xepersian@dahgan#2%
\ifnum#3>\z@\ و \xepersian@yekanv#3\fi%
#60%
\fi%
}
\def\xepersian@tartibi#1{%
\ifcase#1م\or یکم\or دوم\or سوم\or چهارم%
\or پنجم\or ششم\or هفتم\or هشتم\or نهم%
\or دهم\or یازدهم\or دوازدهم\or سیزدهم%
\or چهاردهم\or پانزدهم\or شانزدهم%
\or هفدهم\or هجدهم\or نوزدهم\fi%
}
\def\xepersian@yekanv#1{%
\ifcase#1\@empty\or یک\or دو\or سو\or چهار\or پنج\or شش%
\or هفت\or هشت\or نه\or ده\or یازده\or دوازده\or سیزده%
\or چهارده\or پانزده\or شانزده\or هفده%
\or هجده\or نوزده\fi%
}
\providecommand*{\xpg@warning}[1]{%
   \PackageWarning{XePersian}%
   {#1}}
\if@bidi@csundef{@abjad}{%
\def\@abjad#1{%
\ifnum#1>1999 \xpg@warning{Illegal value (#1) for abjad numeral} {#1}
\else
  \ifnum#1<\z@\space\xpg@warning{Illegal value (#1) for abjad numeral}%
  \else
    \ifnum#1<10\expandafter\abj@num@i\number#1%
    \else
      \ifnum#1<100\expandafter\abj@num@ii\number#1%
      \else
        \ifnum#1<\@m\expandafter\abj@num@iii\number#1%
        \else
          \ifnum#1<\@M\expandafter\abj@num@iv\number#1%since #1<2000, we must have 1000
          \fi
        \fi
      \fi
    \fi
  \fi
\fi
}
\def\abjad#1{\expandafter\@abjad\csname c@#1\endcsname}
\let\abjadnumeral\@abjad
\def\abjad@zero{}
\def\abj@num@i#1{%
  \ifcase#1\or آ\or ب\or ج\or د%
           \or ه\or و\or ز\or ح\or ط\fi
  \ifnum#1=\z@\abjad@zero\fi}
\def\abj@num@ii#1{%
  \ifcase#1\or ی\or ک\or ل\or م\or ن%
           \or س\or ع\or ف\or ص\fi
  \ifnum#1=\z@\fi\abj@num@i}
\def\abj@num@iii#1{%
  \ifcase#1\or ق\or ر\or ش\or ت\or ث%
            \or خ\or ذ\or ض\or ظ\fi
  \ifnum#1=\z@\fi\abj@num@ii}
\def\abj@num@iv#1{%
  \ifcase#1\or غ\fi
  \ifnum#1=\z@\fi\abj@num@iii}
}{}
\let\@latinalph\@alph%
\let\@latinAlph\@Alph%
\def\LatinAlphs{%
   \let\@alph\@latinalph%
   \let\@Alph\@latinAlph%
}
\bidi@AfterEndPreamble{%
\if@bidi@csundef{persianfont}{%
\PackageError{xepersian}{You have not specified any font\MessageBreak
 for the main Persian text}{Use `\settextfont' to load a font.}%
}{}}
\@ifdefinitionfileloaded{loadingorder-xetex-bidi}{\input{loadingorder-xepersian.def}}{}
\@ifpackageloaded{fontspec-xetex}{\input{fontspec-xetex-xepersian.def}}{}
\@ifpackageloaded{listings}{\input{listings-xepersian.def}}{}
\@ifpackageloaded{algorithmic}{\input{algorithmic-xepersian.def}}{}
\@ifpackageloaded{algorithm}{\input{algorithm-xepersian.def}}{}
\@ifpackageloaded{backref}{\input{backref-xepersian.def}}{}
\@ifpackageloaded{flowfram}{\input{flowfram-xepersian.def}}{}
\@ifpackageloaded{bidi}{\input{footnote-xepersian.def}}{}
\@ifpackageloaded{bidituftesidenote}{\input{bidituftesidenote-xepersian.def}}{}
\@ifpackageloaded{breqn}{\input{breqn-xepersian.def}}{}
\@ifpackageloaded{enumerate}{\input{enumerate-xepersian.def}}{}
\@ifpackageloaded{framed}{\input{framed-xepersian.def}}{}
\@ifpackageloaded{glossaries}{\input{glossaries-xepersian.def}}{}
\@ifpackageloaded{hyperref}{\input{hyperref-xepersian.def}}{}
\@ifpackageloaded{minitoc}{\input{minitoc-xepersian.def}}{}
\@ifpackageloaded{natbib}{\input{natbib-xepersian.def}}{}
\@ifpackageloaded{tkz-linknodes}{\input{tkz-linknodes-xepersian.def}}{}
\@ifpackageloaded{tocloft}{\@ifclassloaded{memoir}{}{\input{tocloft-xepersian.def}}}{}
\@ifclassloaded{article}{\input{article-xepersian.def}}{}
\@ifclassloaded{extarticle}{\input{extarticle-xepersian.def}}{}
\@ifclassloaded{artikel1}{\input{artikel1-xepersian.def}}{}
\@ifclassloaded{artikel2}{\input{artikel2-xepersian.def}}{}
\@ifclassloaded{artikel3}{\input{artikel3-xepersian.def}}{}
\@ifclassloaded{amsart}{\input{amsart-xepersian.def}}{}
\@ifclassloaded{bidimoderncv}{\input{bidimoderncv-xepersian.def}}{}
\@ifclassloaded{report}{\input{report-xepersian.def}}{}
\@ifclassloaded{extreport}{\input{extreport-xepersian.def}}{}
\@ifclassloaded{rapport1}{\input{rapport1-xepersian.def}}{}
\@ifclassloaded{rapport3}{\input{rapport3-xepersian.def}}{}
\@ifclassloaded{scrartcl}{\input{scrartcl-xepersian.def}}{}
\@ifclassloaded{scrbook}{\input{scrbook-xepersian.def}}{}
\@ifclassloaded{scrreprt}{\input{scrreprt-xepersian.def}}{}
\@ifclassloaded{amsbook}{\input{amsbook-xepersian.def}}{}
\@ifclassloaded{boek3}{\input{boek3-xepersian.def}}{}
\@ifclassloaded{boek}{\input{boek-xepersian.def}}{}
\@ifclassloaded{bookest}{\input{bookest-xepersian.def}}{}
\@ifclassloaded{extbook}{\input{extbook-xepersian.def}}{}
\@ifclassloaded{book}{\input{book-xepersian.def}}{}
\@ifclassloaded{refrep}{\input{refrep-xepersian.def}}{}
\@ifclassloaded{memoir}{\input{memoir-xepersian.def}}{}
\@ifclassloaded{imsproc}{\input{imsproc-xepersian.def}}{}
\define@choicekey{xepersian.sty}{mathdigits}[\xepersian@tempa\xepersian@tempb]{automatic,default,persian}{%
  \ifcase\xepersian@tempb\relax
    \AutoMathsDigits
  \or
    \DefaultMathsDigits
  \or
    \PersianMathsDigits
  \fi}
\define@choicekey{xepersian.sty}{RTLdocument}[\xepersian@tempa\xepersian@tempb]{on,off}[on]{%
  \ifcase\xepersian@tempb\relax
    \@RTLtrue
  \or
    \@RTLfalse
  \fi}
\define@choicekey{xepersian.sty}{rldocument}[\xepersian@tempa\xepersian@tempb]{on,off}[on]{%
  \ifcase\xepersian@tempb\relax
    \@RTLtrue
  \or
    \@RTLfalse
  \fi}
\define@choicekey{xepersian.sty}{footnoterule}[\xepersian@tempa\xepersian@tempb]{automatic,left,right,split,textwidth}{%
  \ifcase\xepersian@tempb\relax
    \autofootnoterule
  \or
    \leftfootnoterule
  \or
    \rightfootnoterule
  \or
    \SplitFootnoteRule
  \or
    \textwidthfootnoterule
  \fi}
\define@choicekey{xepersian.sty}{footnotedirection}[\xepersian@tempa\xepersian@tempb]{righttoleft,lefttoright}{%
  \ifcase\xepersian@tempb\relax
    \@RTL@footnotetrue
  \or
    \@RTL@footnotefalse
  \fi}
\define@choicekey{xepersian.sty}{debugfootnotedirection}[\xepersian@tempa\xepersian@tempb]{on,off}[on]{%
  \ifcase\xepersian@tempb\relax
    \footdir@debugtrue
  \or
    \footdir@debugfalse
  \fi}
\define@choicekey{xepersian.sty}{Kashida}[\xepersian@tempa\xepersian@tempb]{on,off}[on]{%
  \ifcase\xepersian@tempb\relax
    \input{kashida-xepersian.def}
  \fi}
\define@choicekey{xepersian.sty}{localise}[\xepersian@tempa\xepersian@tempb]{on,off}[on]{%
  \ifcase\xepersian@tempb\relax
    \input{localise-xepersian.def}
  \fi}
\define@choicekey{xepersian.sty}{extrafootnotefeatures}[\xepersian@tempa\xepersian@tempb]{on,off}[on]{%
  \ifcase\xepersian@tempb\relax
    \@extrafootnotefeaturestrue
  \or
    \@extrafootnotefeaturesfalse
  \fi}
\define@choicekey{xepersian.sty}{quickindex}[\xepersian@tempa\xepersian@tempb]{on,off}[on]{%
  \ifcase\xepersian@tempb\relax
     \PackageWarning{xepersian}{Obsolete option}%
     \ifwritexviii%
      \@ifclassloaded{memoir}{\PackageError{xepersian}{This  feature does not yet work with the memoir class}{}}{%
      \renewcommand\printindex{\newpage%
      \immediate\closeout\@indexfile
      \immediate\write18{xindy -L persian-variant2 -C utf8 -M texindy -M page-ranges \jobname.idx}
      \@input@{\jobname.ind}}}%
      \else
      \PackageError{xepersian}{“shell escape” (or “write18”) is not enabled. You need to run “xelatex --shell-escape” on your TeX document for this feature to work}{}
      \fi
  \fi}
\define@choicekey{xepersian.sty}{quickindex-variant1}[\xepersian@tempa\xepersian@tempb]{on,off}[on]{%
  \ifcase\xepersian@tempb\relax
     \ifwritexviii%
      \@ifclassloaded{memoir}{\PackageError{xepersian}{This  feature does not yet work with the memoir class}{}}{%
       \renewcommand\printindex{\newpage%
        \immediate\closeout\@indexfile
        \immediate\write18{xindy -L persian-variant1 -C utf8 -M texindy -M page-ranges \jobname.idx}
        \@input@{\jobname.ind}}}%
         \else
        \PackageError{xepersian}{“shell escape” (or “write18”) is not enabled. You need to run “xelatex --shell-escape” on your TeX document for this feature to work}{}
         \fi
  \fi}
\define@choicekey{xepersian.sty}{quickindex-variant2}[\xepersian@tempa\xepersian@tempb]{on,off}[on]{%
  \ifcase\xepersian@tempb\relax
     \ifwritexviii%
      \@ifclassloaded{memoir}{\PackageError{xepersian}{This  feature does not yet work with the memoir class}{}}{%
       \renewcommand\printindex{\newpage%
       \immediate\closeout\@indexfile
       \immediate\write18{xindy -L persian-variant2 -C utf8 -M texindy -M page-ranges \jobname.idx}
       \@input@{\jobname.ind}}}%
       \else
       \PackageError{xepersian}{“shell escape” (or “write18”) is not enabled. You need to run “xelatex --shell-escape” on your TeX document for this feature to work}{}
       \fi
  \fi}
\define@choicekey{xepersian.sty}{abjadvariant}[\xepersian@tempa\xepersian@tempb]{one,two}{%
  \ifcase\xepersian@tempb\relax
    \def\PersianAlphs{%
    \let\@alph\@abjad%
    \let\@Alph\@abjad%
    }
  \or
    \def\PersianAlphs{%
    \let\@alph\@Abjad%
    \let\@Alph\@Abjad%
    }
  \fi}
\DeclareOptionX{defaultlatinfontfeatures}{%
\defaultfontfeatures
 [\latinfont]
 {#1}
}

\ExecuteOptionsX{%
    RTLdocument=on,
    footnotedirection=righttoleft,
    footnoterule=automatic,
    abjadvariant=two
}

\ProcessOptionsX

\if@extrafootnotefeatures
  \input{extrafootnotefeatures-xetex-bidi.def}
  \input{extrafootnotefeatures-xepersian.def}
\fi

\setlatintextfont[ExternalLocation,BoldFont={lmroman10-bold},BoldItalicFont={lmroman10-bolditalic},ItalicFont={lmroman10-italic},SmallCapsFont={lmromancaps10-regular},SlantedFont={lmromanslant10-regular},BoldSlantedFont={lmromanslant10-bold}]{lmroman10-regular}%
\PersianAlphs
\endinput
%%
%% End of file `xepersian.sty'.
