%%
%% This is file `xepersian.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xepersian.dtx  (with options: `table,xepersian.sty')
%% 
%%   __________________________________________________
%%   Vafa Khalighi
%% 
%%   Copyright (c) 2008--2025  Vafa Khalighi
%%   Copyright (c) 2018--2020 bidi-tex GitHub Organization
%% 
%%   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{10792}
%% \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\xepersian@version{25.2.2}
\def\xepersiandate{2025/02/02}
\def\xepersian@releasename{Persian Gate}
\def\xepersian@persian@@releasename{دربند پارس}
\newcommand*{\xepersianreleasename}{\if@RTL\xepersian@persian@@releasename\else\xepersian@releasename\fi}
\ProvidesPackage{xepersian}[\xepersiandate\space v\xepersian@version\space (Release \xepersian@releasename)\space
Persian typesetting in XeLaTeX]
\newif\if@xepersian@banner
\newif\if@xepersian@@computeautoilg
\DeclareUnknownKeyHandler{%
  \PassOptionsToPackage{\CurrentOption}{bidi}%
}
\ExplSyntaxOn
\msg_new:nnn {xepersian} {cannot-use-engine}
  {
    Oops!~can~not~use~\c_sys_engine_str.\\\\
    The~xepersian~package~requires~XeTeX.
  }
 \sys_if_engine_xetex:F
  {
    \msg_fatal:nn {xepersian} {cannot-use-engine}
  }

\keys_define:nn { xepersian }
  {
    banner .choice: ,
    banner / on .code:n =
      \@xepersian@bannertrue
      \PassOptionsToPackage{banner=on}{bidi} ,
    banner / off .code:n =
      \@xepersian@bannerfalse
      \PassOptionsToPackage{banner=off}{bidi} ,
    banner .default:n = on
  }
\keys_define:nn { xepersian }
  {
    mathdigits .choice: ,
    mathdigits / automatic .code:n = \AtEndOfPackage{\AutoMathDigits} ,
    mathdigits / default .code:n = \AtEndOfPackage{\DefaultMathDigits} ,
    mathdigits / persian .code:n = \AtEndOfPackage{\PersianMathDigits}
  }
\keys_define:nn { xepersian }
  {
    inlinemathdigits .choice: ,
    inlinemathdigits / automatic .code:n = \AtEndOfPackage{\AutoInlineMathDigits} ,
    inlinemathdigits / default .code:n = \AtEndOfPackage{\DefaultInlineMathDigits} ,
    inlinemathdigits / persian .code:n = \AtEndOfPackage{\PersianInlineMathDigits}
  }
\keys_define:nn { xepersian }
  {
    displaymathdigits .choice: ,
    displaymathdigits / automatic .code:n = \AtEndOfPackage{\AutoDisplayMathDigits} ,
    displaymathdigits / default .code:n = \AtEndOfPackage{\DefaultDisplayMathDigits} ,
    displaymathdigits / persian .code:n = \AtEndOfPackage{\PersianDisplayMathDigits}
  }
\keys_define:nn { xepersian }
  {
    Kashida .choice: ,
    Kashida / on .code:n = \AtEndOfPackage{\input{kashida-xetex-xepersian.def}} ,
    Kashida / off .code:n = \relax ,
    Kashida .default:n = on
  }
\keys_define:nn { xepersian }
  {
    localize .choice: ,
    localize / on .code:n = \AtEndOfPackage{\input{localize-xetex-xepersian.def}} ,
    localize / off .code:n = \relax ,
    localize .default:n = on
  }
\cs_new_protected:Npn \__xepersian_quickindex_variant:n #1
{
  \AtEndOfPackage{%
      \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-variant#1~-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
    }
}
\keys_define:nn { xepersian }
  {
    quickindex-variant .choice: ,
    quickindex-variant / one .code:n = \__xepersian_quickindex_variant:n { 1 } ,
    quickindex-variant / two .code:n = \__xepersian_quickindex_variant:n { 2 } ,
    quickindex-variant / three .code:n = \__xepersian_quickindex_variant:n { 3 }
  }
\keys_define:nn { xepersian }
  {
    abjad-variant .choice: ,
    abjad-variant / one .code:n =
      \def\PersianAlphs{%
        \let\@alph\@abjad
        \let\@Alph\@abjad
      } ,
    abjad-variant / two .code:n =
     \def\PersianAlphs{%
       \let\@alph\@Abjad
       \let\@Alph\@Abjad
     }
  }
\keys_define:nn { xepersian }
  {
    defaultlatinfontfeatures .code:n = \AtEndOfPackage{\defaultfontfeatures[\latinfont]{#1}}
  }
\keys_define:nn { xepersian }
  {
    mathfontsizescale .code:n = \def\xepersian@@math@fontsize@scale{#1}
  }
\keys_define:nn { xepersian }
  {
    fontsizescale .code:n = \def\xepersian@@fontsize@scale{#1}
  }
\keys_define:nn { xepersian }
  {
    fontsize .code:n = \AtEndOfPackage{\xepersian@@fontsize@branch{#1}}
  }
\keys_define:nn { xepersian }
  {
    latinfontsizescale .code:n = \def\xepersian@@latin@fontsize@scale{#1}
  }
 \keys_define:nn { xepersian }
  {
    baselineskipscale .code:n = \def\xepersian@@baselineskip@scale{#1}
  }
 \keys_define:nn { xepersian }
  {
    latinbaselineskipscale .code:n = \def\xepersian@@latin@baselineskip@scale{#1}
  }
\keys_define:nn { xepersian }
  {
    computeautoilg .choice: ,
    computeautoilg / on .code:n = \@xepersian@@computeautoilgtrue ,
    computeautoilg / off .code:n = \@xepersian@@computeautoilgfalse ,
    computeautoilg .default:n = on
  }
\keys_define:nn { xepersian }
  {
    debugtextdigitfont .choice: ,
    debugtextdigitfont / on .code:n = \AtEndOfPackage{%
      \bidi@AtEndPreamble{%
        \bidi@patchcmd\xepersian@@start@switch@textdigitfont\xepersian@textdigitfont{%
          \addfontfeature{Color=C71585}
        }{}{}
      }
    } ,
    debugtextdigitfont / off .code:n = \relax ,
    debugtextdigitfont .default:n = on
  }
\keys_set:nn { xepersian }
  {
    banner = on ,
    abjad-variant = two ,
    fontsizescale = \@ne ,
    latinfontsizescale = \@ne ,
    mathfontsizescale = \@ne ,
    baselineskipscale = \@ne ,
    latinbaselineskipscale = \@ne
  }
\ExplSyntaxOff
\ProcessKeyOptions
\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--2025 Vafa Khalighi^^J%
* Copyright (c) 2018--2020 bidi-tex GitHub Organization^^J%
* ^^J%
* v\xepersian@version\space (Release \xepersian@releasename), \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/xepersian/xepersian/issues^^J%
* ^^J%
* Discussions: https://github.com/xepersian/xepersian/discussions^^J%
* ^^J%
* Primary author of xepersian package: Vafa Khalighi.^^J%
* ^^J%
****************************************************}
\edef\xepersian@everyjob{\the\everyjob}
\if@xepersian@banner
  \typeout{\@xepersian@info}
  \everyjob{\xepersian@everyjob\typeout{\@xepersian@info}}
\fi
\RequirePackage{fontspec}
\RequirePackage{xepersian-persiancal}
\RequirePackage{unicode-persianmath}
\RequirePackage[%
  documentdirection=righttoleft,%
  tabledirection=righttoleft,%
  script=nonlatin,%
  footnotedirection=righttoleft,%
  footnoterule=automatic%
]{bidi}
\newcommand*{\xepersianversion}
  {\ensuremath\xepersian@version}
\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{Persian}{arab}
\newfontlanguage{Persian}{FAR}
\ExplSyntaxOn

\keys_define:nn {fontspec-opentype}
  {
    Ligatures / PersianTeX .code:n = { \tl_set:Nn \l__fontspec_mapping_tl {persian-tex-text} },
    Ligatures / PersianTeXOff .code:n = { \tl_clear:N \l__fontspec_mapping_tl },
    Ligatures / PersianTeXReset .code:n = { \tl_clear:N \l__fontspec_mapping_tl },
  }

\keys_define:nn {fontspec-aat}
 {
  Ligatures / PersianTeX .code:n =
   {
     \tl_set:Nn \l__fontspec_mapping_tl { persian-tex-text }
   }
 }

\keys_define:nn {fontspec-opentype}
  {
    Ligatures / PersianTeXNoNumbers .code:n = { \tl_set:Nn \l__fontspec_mapping_tl {persian-tex-text-nonumbers} },
    Ligatures / PersianTeXNoNumbersOff .code:n = { \tl_clear:N \l__fontspec_mapping_tl },
    Ligatures / PersianTeXNoNumbersReset .code:n = { \tl_clear:N \l__fontspec_mapping_tl },
  }

\keys_define:nn {fontspec-aat}
 {
  Ligatures / PersianTeXNoNumbers .code:n =
   {
     \tl_set:Nn \l__fontspec_mapping_tl { persian-tex-text-nonumbers }
   }
 }

\DeclareDocumentCommand \settextfont { O{} m O{} }
  {
    \__xepersian_main_settextfont:nn {#1,#3} {#2}
    \ignorespaces
  }
\cs_new:Nn \__xepersian_main_settextfont:nn
 {
  \fontspec_set_family:Nnn \l__fontspec_persianfont_family_tl {RawFeature={script=arab},Ligatures=PersianTeX,#1} {#2}
  \tl_set_eq:NN \rmdefault \l__fontspec_persianfont_family_tl
  \use:x { \exp_not:n { \DeclareRobustCommand \persianfont }
   {
    \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
    \exp_not:N \fontfamily { \l__fontspec_persianfont_family_tl }
    \exp_not:N \selectfont
   }
  }
  \str_if_eq:eeT {\familydefault} {\rmdefault}
    { \tl_set_eq:NN \encodingdefault \g__fontspec_nfss_enc_tl }
  \__xepersian_settextfont_hook:nn {#1} {#2}
  \normalfont
 }

\cs_set_eq:NN \__xepersian_settextfont_hook:nn   \use_none:nn

\DeclareDocumentCommand \settextdigitfont { O{} m O{} }
  {
    \__xepersian_main_settextdigitfont:nn {#1,#3} {#2}
    \ignorespaces
  }
\cs_new:Nn \__xepersian_main_settextdigitfont:nn
 {
  \fontspec_set_family:Nnn \l__fontspec_textdigitfont_family_tl {Ligatures=PersianTeX,#1} {#2}
  \use:x
   {
    \exp_not:n { \DeclareRobustCommand \xepersian@textdigitfont }
     {
      \exp_not:N \fontfamily { \l__fontspec_textdigitfont_family_tl }
      \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
      \exp_not:N \selectfont
     }
   }
   \__xepersian_settextdigitfont_hook:nn {#1} {#2}
   \XeTeXinterchartoks \e@alloc@intercharclass@top \bidi@digits@charclass = {\xepersian@@start@switch@textdigitfont}
   \XeTeXinterchartoks \bidi@digits@charclass \e@alloc@intercharclass@top = {\xepersian@@stop@switch@textdigitfont}
   \XeTeXinterchartoks \z@ \bidi@digits@charclass = {\xepersian@@start@switch@textdigitfont}
   \XeTeXinterchartoks \bidi@digits@charclass \z@ = {\xepersian@@stop@switch@textdigitfont}
   \XeTeXinterchartoks \bidi@digits@charclass  \bidi@sepmark@charclass = {\xepersian@@stop@switch@textdigitfont}
   \XeTeXinterchartoks \bidi@sepmark@charclass  \bidi@digits@charclass = {\DigitsDotDashInterCharToks\xepersian@@start@switch@textdigitfont}
   \if@bidi@csundef{xepersian@dualjoiner}{}{%
     \XeTeXinterchartoks \xepersian@dualjoiner  \bidi@digits@charclass = {\xepersian@@start@switch@textdigitfont}
     \XeTeXinterchartoks \bidi@digits@charclass  \xepersian@dualjoiner = {\xepersian@@stop@switch@textdigitfont}
     \XeTeXinterchartoks \xepersian@lam  \bidi@digits@charclass = {\xepersian@@start@switch@textdigitfont}
     \XeTeXinterchartoks \bidi@digits@charclass  \xepersian@lam = {\xepersian@@stop@switch@textdigitfont}
     \XeTeXinterchartoks \xepersian@alef  \bidi@digits@charclass = {\xepersian@@start@switch@textdigitfont}
     \XeTeXinterchartoks \bidi@digits@charclass  \xepersian@alef = {\xepersian@@stop@switch@textdigitfont}
     \XeTeXinterchartoks \xepersian@rightjoiner  \bidi@digits@charclass = {\xepersian@@start@switch@textdigitfont}
     \XeTeXinterchartoks \bidi@digits@charclass  \xepersian@rightjoiner = {\xepersian@@stop@switch@textdigitfont}
   }
 }

\newcommand*{\xepersian@@start@switch@textdigitfont}{\ifx\f@family\ttdefault\else\if@nonlatin\if@@textdigitfont@on\let\xepersian@save@@f@family\f@family\xepersian@textdigitfont\else\fi\fi\fi}
\newcommand*{\xepersian@@stop@switch@textdigitfont}{\ifx\f@family\ttdefault\else\if@nonlatin\if@@textdigitfont@on\let\f@family\xepersian@save@@f@family\selectfont\else\fi\fi\fi}

\cs_set_eq:NN \__xepersian_settextdigitfont_hook:nn   \use_none:nn

\DeclareDocumentCommand \setdigitfont { O{} m O{} }
  {
    \__xepersian_main_settextdigitfont:nn {#1,#3} {#2}
    \__xepersian_main_setmathdigitfont:nn {#1,#3} {#2}
    \ignorespaces
  }

\DeclareDocumentCommand \setlatintextfont { O{} m O{} }
  {
    \__xepersian_main_setlatintextfont:nn {#1,#3} {#2}
    \ignorespaces
  }
\cs_new:Nn \__xepersian_main_setlatintextfont:nn
 {
  \fontspec_set_family:Nnn \l__fontspec_latinfont_family_tl {Ligatures=TeX,#1} {#2}
  \use:x { \exp_not:n { \DeclareRobustCommand \latinfont }
   {
    \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
    \exp_not:N \fontfamily { \l__fontspec_latinfont_family_tl }
    \exp_not:N \selectfont
   }
  }
  \str_if_eq:eeT {\familydefault} {\rmdefault}
    { \tl_set_eq:NN \encodingdefault \g__fontspec_nfss_enc_tl }
  \__xepersian_setlatintextfont_hook:nn {#1} {#2}
  \normalfont
 }

\cs_set_eq:NN \__xepersian_setlatintextfont_hook:nn   \use_none:nn

\tl_set_eq:NN \setlatinsansfont \setsansfont
\tl_set_eq:NN \setlatinmonofont \setmonofont

\DeclareDocumentCommand \defpersianfont { m O{} m O{} }
  {
    \__xepersian_main_defpersianfont:NnnN #1 {#2,#4} {#3}
    \NewDocumentCommand
  }
\DeclareDocumentCommand \redefpersianfont { m O{} m O{} }
  {
    \__xepersian_main_defpersianfont:NnnN #1 {#2,#4} {#3}
    \RenewDocumentCommand
  }
\cs_new:Nn \__xepersian_main_defpersianfont:NnnN
 {
  \fontspec_set_family:cnn { l__fontspec_ \cs_to_str:N #1 _family_tl } {RawFeature={script=arab},Ligatures=PersianTeX,#2} {#3}
  \use:x
   {
    \exp_not:N #4 \exp_not:N #1 {}
     {
      \exp_not:N \fontfamily { \use:c {l__fontspec_ \cs_to_str:N #1 _family_tl } }
      \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
      \exp_not:N \selectfont
     }
   }
 }

\DeclareDocumentCommand \deflatinfont { m O{} m O{} }
  {
    \__xepersian_main_deflatinfont:NnnN #1 {#2,#4} {#3}
    \NewDocumentCommand
  }
\DeclareDocumentCommand \redeflatinfont { m O{} m O{} }
  {
    \__xepersian_main_deflatinfont:NnnN #1 {#2,#4} {#3}
    \RenewDocumentCommand
  }
\cs_new:Nn \__xepersian_main_deflatinfont:NnnN
 {
  \fontspec_set_family:cnn { l__fontspec_ \cs_to_str:N #1 _family_tl } {Ligatures=TeX,#2} {#3}
  \use:x
   {
    \exp_not:N #4 \exp_not:N #1 {}
     {
      \exp_not:N \fontfamily { \use:c {l__fontspec_ \cs_to_str:N #1 _family_tl } }
      \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
      \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{} }
  {
    \__xepersian_main_setpersiansansfont:nn {#1,#3} {#2}
    \ignorespaces
  }
\cs_new:Nn \__xepersian_main_setpersiansansfont:nn
 {
  \fontspec_set_family:Nnn \l__fontspec_persiansffamily_family_tl {RawFeature={script=arab},Ligatures=PersianTeX,#1} {#2}
  \tl_set_eq:NN \persiansfdefault \l__fontspec_persiansffamily_family_tl
  \use:x { \exp_not:n { \DeclareRobustCommand \persiansffamily }
   {
    \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
    \exp_not:N \fontfamily { \l__fontspec_persiansffamily_family_tl }
    \exp_not:N \selectfont
   }
  }
  \str_if_eq:eeT {\familydefault} {\persiansfdefault}
    { \tl_set_eq:NN \encodingdefault \g__fontspec_nfss_enc_tl }
  \__xepersian_setpersiansansfont_hook:nn {#1} {#2}
  \normalfont
 }

\cs_set_eq:NN \__xepersian_setpersiansansfont_hook:nn   \use_none:nn

\DeclareDocumentCommand \setpersianmonofont { O{} m O{} }
  {
    \__xepersian_main_setpersianmonofont:nn {#1,#3} {#2}
    \ignorespaces
  }
\cs_new:Nn \__xepersian_main_setpersianmonofont:nn
 {
  \fontspec_set_family:Nnn \l__fontspec_persianttfamily_family_tl {RawFeature={script=arab},Ligatures=PersianTeX,#1} {#2}
  \tl_set_eq:NN \persianttdefault \l__fontspec_persianttfamily_family_tl
  \use:x { \exp_not:n { \DeclareRobustCommand \persianttfamily }
   {
    \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
    \exp_not:N \fontfamily { \l__fontspec_persianttfamily_family_tl }
    \exp_not:N \selectfont
   }
  }
  \str_if_eq:eeT {\familydefault} {\persianttdefault}
    { \tl_set_eq:NN \encodingdefault \g__fontspec_nfss_enc_tl }
  \__xepersian_setpersianmonofont_hook:nn {#1} {#2}
  \normalfont
 }

\cs_set_eq:NN \__xepersian_setpersianmonofont_hook:nn   \use_none:nn

\DeclareDocumentCommand \setnavarfont { O{} m O{} }
  {
    \__xepersian_main_setnavarfont:nn {#1,#3} {#2}
    \ignorespaces
  }
\cs_new:Nn \__xepersian_main_setnavarfont:nn
 {
  \fontspec_set_family:Nnn \l__fontspec_navarfamily_family_tl {RawFeature={script=arab},Ligatures=PersianTeX,#1} {#2}
  \tl_set_eq:NN \navardefault \l__fontspec_navarfamily_family_tl
  \use:x { \exp_not:n { \DeclareRobustCommand \navarfamily }
   {
    \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
    \exp_not:N \fontfamily { \l__fontspec_navarfamily_family_tl }
    \exp_not:N \selectfont
   }
  }
  \str_if_eq:eeT {\familydefault} {\navardefault}
    { \tl_set_eq:NN \encodingdefault \g__fontspec_nfss_enc_tl }
  \__xepersian_setnavarfont_hook:nn {#1} {#2}
  \normalfont
 }

\cs_set_eq:NN \__xepersian_setnavarfont_hook:nn   \use_none:nn

\DeclareDocumentCommand \setpookfont { O{} m O{} }
  {
    \__xepersian_main_setpookfont:nn {#1,#3} {#2}
    \ignorespaces
  }
\cs_new:Nn \__xepersian_main_setpookfont:nn
 {
  \fontspec_set_family:Nnn \l__fontspec_pookfamily_family_tl {RawFeature={script=arab},Ligatures=PersianTeX,#1} {#2}
  \tl_set_eq:NN \pookdefault \l__fontspec_pookfamily_family_tl
  \use:x { \exp_not:n { \DeclareRobustCommand \pookfamily }
   {
    \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
    \exp_not:N \fontfamily { \l__fontspec_pookfamily_family_tl }
    \exp_not:N \selectfont
   }
  }
  \str_if_eq:eeT {\familydefault} {\pookdefault}
    { \tl_set_eq:NN \encodingdefault \g__fontspec_nfss_enc_tl }
  \__xepersian_setpookfont_hook:nn {#1} {#2}
  \normalfont
 }

\cs_set_eq:NN \__xepersian_setpookfont_hook:nn   \use_none:nn

\DeclareDocumentCommand \setsayehfont { O{} m O{} }
  {
    \__xepersian_main_setsayehfont:nn {#1,#3} {#2}
    \ignorespaces
  }
\cs_new:Nn \__xepersian_main_setsayehfont:nn
 {
  \fontspec_set_family:Nnn \l__fontspec_sayehfamily_family_tl {RawFeature={script=arab},Ligatures=PersianTeX,#1} {#2}
  \tl_set_eq:NN \sayehdefault \l__fontspec_sayehfamily_family_tl
  \use:x { \exp_not:n { \DeclareRobustCommand \sayehfamily }
   {
    \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
    \exp_not:N \fontfamily { \l__fontspec_sayehfamily_family_tl }
    \exp_not:N \selectfont
   }
  }
  \str_if_eq:eeT {\familydefault} {\sayehdefault}
    { \tl_set_eq:NN \encodingdefault \g__fontspec_nfss_enc_tl }
  \__xepersian_setsayehfont_hook:nn {#1} {#2}
  \normalfont
 }

\cs_set_eq:NN \__xepersian_setsayehfont_hook:nn   \use_none:nn

\DeclareDocumentCommand \setiranicfont { O{} m O{} }
  {
    \__xepersian_main_setiranicfont:nn {#1,#3} {#2}
    \ignorespaces
  }
\cs_new:Nn \__xepersian_main_setiranicfont:nn
 {
  \fontspec_set_family:Nnn \l__fontspec_iranicfamily_family_tl {RawFeature={script=arab},Ligatures=PersianTeX,#1} {#2}
  \tl_set_eq:NN \iranicdefault \l__fontspec_iranicfamily_family_tl
  \use:x { \exp_not:n { \DeclareRobustCommand \iranicfamily }
   {
    \exp_not:N \fontencoding { \g__fontspec_nfss_enc_tl }
    \exp_not:N \fontfamily { \l__fontspec_iranicfamily_family_tl }
    \exp_not:N \selectfont
   }
  }
  \str_if_eq:eeT {\familydefault} {\iranicdefault}
    { \tl_set_eq:NN \encodingdefault \g__fontspec_nfss_enc_tl }
  \__xepersian_setiranicfont_hook:nn {#1} {#2}
  \normalfont
 }

\cs_set_eq:NN \__xepersian_setiranicfont_hook:nn   \use_none:nn

\ExplSyntaxOff
\def\resetlatinfont{%
\let\@xepersian@@fontsize@scale\xepersian@@fontsize@scale%
\let\@xepersian@@baselineskip@scale\xepersian@@baselineskip@scale%
\def\xepersian@@fontsize@scale{%
  \strip@pt\dimexpr 1pt * \dimexpr
  \xepersian@@latin@fontsize@scale pt\relax
  /  \dimexpr \@xepersian@@fontsize@scale pt\relax\relax
}%
\def\xepersian@@baselineskip@scale{%
  \strip@pt\dimexpr 1pt * \dimexpr
  \xepersian@@latin@baselineskip@scale pt\relax
  /  \dimexpr \@xepersian@@baselineskip@scale pt\relax\relax
}%
\@nonlatinfalse%
\let\normalfont\latinfont%
\let\reset@font\normalfont%
\latinfont%
\fontsize\f@size\f@baselineskip%
\selectfont%
\let\xepersian@@fontsize@scale\xepersian@@latin@fontsize@scale%
\let\xepersian@@baselineskip@scale\xepersian@@latin@baselineskip@scale%
}
\def\setpersianfont{%
\let\@xepersian@@fontsize@scale\xepersian@@fontsize@scale%
\let\@xepersian@@baselineskip@scale\xepersian@@baselineskip@scale%
\let\xepersian@@fontsize@scale\@ne%
\let\xepersian@@baselineskip@scale\@ne%
\@nonlatintrue%
\let\normalfont\persianfont%
\let\reset@font\normalfont%
\persianfont%
\fontsize\f@size\f@baselineskip%
\selectfont%
\let\xepersian@@fontsize@scale\@xepersian@@fontsize@scale%
\let\xepersian@@baselineskip@scale\@xepersian@@baselineskip@scale%
}
\bidi@newrobustcmd*{\lr}[1]{\LRE{\resetlatinfont#1}}
\bidi@newrobustcmd*{\rl}[1]{\RLE{\setpersianfont#1}}
\def\latin{\LTR\LatinAlphs\@RTL@footnotefalse\resetlatinfont}
\def\endlatin{\endLTR}
\newenvironment{latin*}{\latin
  \everypar{%
    {\setbox\z@\lastbox
      \ifvoid\z@
        \kern-\parindent
    \fi}%
  }%
}{\endlatin\@endpetrue}
\def\persian{\RTL\PersianAlphs\@RTL@footnotetrue\setpersianfont}
\def\endpersian{\endRTL}
\newenvironment{persian*}{\persian
  \everypar{%
    {\setbox\z@\lastbox
      \ifvoid\z@
        \kern-\parindent
    \fi}%
  }%
}{\endpersian\@endpetrue}
\newenvironment{latinitems}{\begin{LTRitems}\LatinAlphs\@RTL@footnotefalse\resetlatinfont}{\end{LTRitems}}
\newenvironment{persianitems}{\begin{RTLitems}\PersianAlphs\@RTL@footnotetrue\setpersianfont}{\end{RTLitems}}
\let\originaltoday=\today
\def\latintoday{\lr{\originaltoday}}
\def\today{\rl{\persiantoday}}
\def \@LTRmarginparreset {%
        \reset@font
        \resetlatinfont
        \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}}

\renewcommand*{\bidi@font@@outputpage}{\if@RTLmain\setpersianfont\else\resetlatinfont\fi}

\newcount\xepersian@tcl
\newdimen\xepersian@ilg
\newdimen\xepersian@strutilg
\chardef\f@ur=4
\newcommand*{\xepersian@computeautoilg}{% compute the interline glue
 \xepersian@tcl=1536\xepersian@ilg\z@\xepersian@strutilg\z@
 \loop
 \iffontchar\font\xepersian@tcl
 \ifdim\XeTeXglyphbounds\tw@ \the\XeTeXcharglyph\xepersian@tcl>\z@
 \ifdim\XeTeXglyphbounds\tw@ \the\XeTeXcharglyph\xepersian@tcl>\xepersian@ilg
   \xepersian@ilg=\XeTeXglyphbounds\tw@ \the\XeTeXcharglyph\xepersian@tcl
 \fi
 \else
 \ifdim\XeTeXglyphbounds\tw@ \the\XeTeXcharglyph\xepersian@tcl<\z@
  \ifdim-\XeTeXglyphbounds\tw@ \the\XeTeXcharglyph\xepersian@tcl>\xepersian@ilg
   \xepersian@ilg=-\XeTeXglyphbounds\tw@ \the\XeTeXcharglyph\xepersian@tcl
 \fi
 \fi
 \fi
 \ifdim\XeTeXglyphbounds\f@ur \the\XeTeXcharglyph\xepersian@tcl>\z@
 \ifdim\XeTeXglyphbounds\f@ur \the\XeTeXcharglyph\xepersian@tcl>\xepersian@strutilg
   \xepersian@strutilg=\XeTeXglyphbounds\f@ur \the\XeTeXcharglyph\xepersian@tcl
 \fi
 \else
 \ifdim\XeTeXglyphbounds\f@ur \the\XeTeXcharglyph\xepersian@tcl<\z@
  \ifdim-\XeTeXglyphbounds\f@ur \the\XeTeXcharglyph\xepersian@tcl>\xepersian@strutilg
   \xepersian@strutilg=-\XeTeXglyphbounds\f@ur \the\XeTeXcharglyph\xepersian@tcl
 \fi
 \fi
 \fi
 \fi
 \advance\xepersian@tcl\@ne
 \ifnum\xepersian@tcl<1792\repeat
 \advance\xepersian@strutilg\xepersian@ilg
}

\newif\if@@textdigitfont@on

\newcommand{\TextDigitFontOn}{\@@textdigitfont@ontrue}
\newcommand{\TextDigitFontOff}{\@@textdigitfont@onfalse}

\TextDigitFontOn

\newcommand*\xepersian@setlength[4]{%
    \ifdim #2<\ifdim #2=\z@ \z@ \else \p@\fi
      \ifdim #3<\ifdim #3=\z@ \z@ \else \p@\fi
        \ifdim #4<\ifdim #4=\z@ \z@ \else \p@\fi
          \setlength{#1}{\p@ \@plus\p@ \@minus\p@}%
        \else
          \setlength{#1}{\p@ \@plus\p@ \@minus#4}%
        \fi
      \else
        \ifdim #4<\ifdim #4=\z@ \z@ \else \p@\fi
          \setlength{#1}{\p@ \@plus#3 \@minus\p@}%
        \else
          \setlength{#1}{\p@ \@plus#3 \@minus#4}%
        \fi
      \fi
    \else
      \ifdim #3<\ifdim #3=\z@ \z@ \else \p@\fi
        \ifdim #4<\ifdim #4=\z@ \z@ \else \p@\fi
          \setlength{#1}{#2 \@plus\p@ \@minus\p@}%
        \else
          \setlength{#1}{#2 \@plus\p@ \@minus#4}%
        \fi
      \else
        \ifdim #4<\ifdim #4=\z@ \z@ \else \p@\fi
          \setlength{#1}{#2 \@plus#3 \@minus\p@}%
        \else
          \setlength{#1}{#2 \@plus#3 \@minus#4}%
        \fi
      \fi
    \fi
}

\newcommand*{\setfontsize}[2][1.2\@tempdima]{%
  \@defaultunits\@tempdima#2pt\relax\@nnil
  \setlength{\@tempdimc}{\@tempdima}%
  \addtolength{\@tempdimc}{-10\p@}%
  \edef\@ptsize{\strip@pt\@tempdimc}%
  \@defaultunits\@tempdimb#1pt\relax\@nnil
  \setlength{\@tempdimc}{\dimexpr (100\@tempdimb / \@tempdima * \p@)}%
  \edef\@tempb{\the\@tempdimc}%
  \setlength{\@tempdimc}{\@tempdima}%
  \def\@tempa##1##2##3##4##5\@nnil{\def##1{##2.##3##4}}%
  \expandafter\@tempa\expandafter\@tempb\@tempb\@nnil%
    \xepersian@setlength{\abovedisplayskip}%
                  {.8333\@tempdimb}{.1667\@tempdimb}{.5\@tempdimb}%
    \xepersian@setlength{\abovedisplayshortskip}{\z@}{.25\@tempdimb}{\z@}%
    \xepersian@setlength{\belowdisplayshortskip}%
                  {.5\@tempdimb}{.25\@tempdimb}{.25\@tempdimb}%
  \setlength{\belowdisplayskip}{\abovedisplayskip}%
  \edef\normalsize{%
    \noexpand\@setfontsize\noexpand\normalsize
    {\the\@tempdima}{\the\@tempdimb}%
    \abovedisplayskip \the\abovedisplayskip
    \abovedisplayshortskip \the\abovedisplayshortskip
    \belowdisplayskip \the\belowdisplayskip
    \belowdisplayshortskip \the\belowdisplayshortskip
    \let\noexpand\@listi\noexpand\@listI
  }%
  \setlength{\@tempdima}{0.9125\@tempdimc}%
  \setlength{\@tempdimb}{\@tempb\@tempdima}%
    \xepersian@setlength{\abovedisplayskip}%
                  {.8333\@tempdimb}{.1667\@tempdimb}{.5\@tempdimb}%
    \xepersian@setlength{\abovedisplayshortskip}{\z@}{.25\@tempdimb}{\z@}%
    \xepersian@setlength{\belowdisplayshortskip}%
                  {.5\@tempdimb}{.25\@tempdimb}{.25\@tempdimb}%
  \setlength{\belowdisplayskip}{\abovedisplayskip}%
  \edef\small{%
    \noexpand\@setfontsize\noexpand\small
    {\the\@tempdima}{\the\@tempdimb}%
    \abovedisplayskip \the\abovedisplayskip
    \abovedisplayshortskip \the\abovedisplayshortskip
    \belowdisplayskip \the\belowdisplayskip
    \belowdisplayshortskip \the\belowdisplayshortskip
    \let\noexpand\@listi\noexpand\@listi@small
  }%
  \setlength{\@tempdima}{.83334\@tempdimc}%
  \setlength{\@tempdimb}{\@tempb\@tempdima}%
    \xepersian@setlength{\abovedisplayskip}%
                  {.8333\@tempdimb}{.1667\@tempdimb}{.5\@tempdimb}%
    \xepersian@setlength{\abovedisplayshortskip}{\z@}{.25\@tempdimb}{\z@}%
    \xepersian@setlength{\belowdisplayshortskip}%
                  {.5\@tempdimb}{.25\@tempdimb}{.25\@tempdimb}%
  \setlength{\belowdisplayskip}{\abovedisplayskip}%
  \edef\footnotesize{%
    \noexpand\@setfontsize\noexpand\footnotesize
    {\the\@tempdima}{\the\@tempdimb}%
    \abovedisplayskip \the\abovedisplayskip
    \abovedisplayshortskip \the\abovedisplayshortskip
    \belowdisplayskip \the\belowdisplayskip
    \belowdisplayshortskip \the\belowdisplayshortskip
    \let\noexpand\@listi\noexpand\@listi@footnotesize
  }%
  \setlength{\@tempdima}{.66667\@tempdimc}%
  \setlength{\@tempdimb}{\@tempb\@tempdima}%
  \edef\scriptsize{%
    \noexpand\@setfontsize\noexpand\scriptsize
    {\the\@tempdima}{\the\@tempdimb}%
  }%
  \setlength{\@tempdima}{.5\@tempdimc}%
  \setlength{\@tempdimb}{\@tempb\@tempdima}%
  \edef\tiny{%
    \noexpand\@setfontsize\noexpand\tiny
    {\the\@tempdima}{\the\@tempdimb}%
  }%
  \setlength{\@tempdima}{1.2\@tempdimc}%
  \setlength{\@tempdimb}{\@tempb\@tempdima}%
  \edef\large{%
    \noexpand\@setfontsize\noexpand\large
    {\the\@tempdima}{\the\@tempdimb}%
  }%
  \setlength{\@tempdima}{1.44\@tempdimc}%
  \setlength{\@tempdimb}{\@tempb\@tempdima}%
  \edef\Large{%
    \noexpand\@setfontsize\noexpand\Large
    {\the\@tempdima}{\the\@tempdimb}%
  }%
  \setlength{\@tempdima}{1.728\@tempdimc}%
  \setlength{\@tempdimb}{\@tempb\@tempdima}%
  \edef\LARGE{%
    \noexpand\@setfontsize\noexpand\LARGE
    {\the\@tempdima}{\the\@tempdimb}%
  }%
  \setlength{\@tempdima}{2.074\@tempdimc}%
  \setlength{\@tempdimb}{\@tempb\@tempdima}%
  \edef\huge{%
    \noexpand\@setfontsize\noexpand\huge
    {\the\@tempdima}{\the\@tempdimb}%
  }%
  \setlength{\@tempdima}{2.488\@tempdimc}%
  \setlength{\@tempdimb}{\@tempb\@tempdima}%
  \edef\Huge{%
    \noexpand\@setfontsize\noexpand\Huge
    {\the\@tempdima}{\the\@tempdimb}%
  }%
  \normalsize
    \setlength{\@tempdimb}{\f@baselineskip}%
    \xepersian@setlength{\parsep}%
                  {.3333\@tempdimb}{.1667\@tempdimb}{.0833\@tempdimb}%
    \xepersian@setlength{\topsep}%
                  {.6667\@tempdimb}{.1667\@tempdimb}{.3333\@tempdimb}%
  \@tempswafalse
  \begingroup
    \def\@list@extra{\aftergroup\@tempswatrue}%
    \csname @listi\endcsname
  \endgroup
  \edef\@listi{\leftmargin\leftmargini
    \topsep \the\topsep
    \parsep \the\parsep
    \itemsep \parsep
    \if@tempswa\noexpand\@list@extra\fi
  }%
  \let\@listI\@listi
    \xepersian@setlength{\parsep}%
                  {.1667\@tempdimb}{.0833\@tempdimb}{.0833\@tempdimb}%
    \xepersian@setlength{\topsep}%
                  {.3333\@tempdimb}{.1667\@tempdimb}{.1667\@tempdimb}%
  \@tempswafalse
  \begingroup
    \def\@list@extra{\aftergroup\@tempswatrue}%
    \csname @listi\endcsname
  \endgroup
  \edef\@listi@small{\leftmargin\leftmargini
    \topsep \the\topsep
    \parsep \the\parsep
    \itemsep \parsep
    \if@tempswa\noexpand\@list@extra\fi
  }%
    \xepersian@setlength{\parsep}%
                  {.125\@tempdimb}{.0625\@tempdimb}{.0625\@tempdimb}%
    \xepersian@setlength{\topsep}%
                  {.25\@tempdimb}{.125\@tempdimb}{.125\@tempdimb}
  \@tempswafalse
  \begingroup
    \def\@list@extra{\aftergroup\@tempswatrue}%
    \csname @listi\endcsname
  \endgroup
  \edef\@listi@footnotesize{\leftmargin\leftmargini
    \topsep \the\topsep
    \parsep \the\parsep
    \itemsep \parsep
    \if@tempswa\noexpand\@list@extra\fi
  }%
    \xepersian@setlength{\parsep}%
                  {.1667\@tempdimb}{.0833\@tempdimb}{.0833\@tempdimb}%
    \xepersian@setlength{\topsep}%
                  {.3333\@tempdimb}{.1667\@tempdimb}{.0833\@tempdimb}%
  \@tempswafalse
  \begingroup
    \def\@list@extra{\aftergroup\@tempswatrue}%
    \csname @listii\endcsname
  \endgroup
  \edef\@listii{\leftmargin\leftmarginii
    \labelwidth=\dimexpr \leftmargin-\labelsep
    \topsep \the\topsep
    \parsep \the\parsep
    \itemsep \parsep
    \if@tempswa\noexpand\@list@extra\fi
  }%
    \xepersian@setlength{\topsep}%
                  {.1667\@tempdimb}{.0833\@tempdimb}{.0833\@tempdimb}%
  \setlength{\partopsep}{\z@ \@plus\z@ \@minus\p@}%
  \@tempswafalse
  \begingroup
    \def\@list@extra{\aftergroup\@tempswatrue}%
    \csname @listiii\endcsname
  \endgroup
  \edef\@listiii{\leftmargin\leftmarginiii
    \labelwidth=\dimexpr \leftmargin-\labelsep
    \topsep \the\topsep
    \parsep \z@
    \partopsep \the\partopsep
    \itemsep \topsep
    \if@tempswa\noexpand\@list@extra\fi
  }%
  \@tempswafalse
  \begingroup
    \def\@list@extra{\aftergroup\@tempswatrue}%
    \csname @listiv\endcsname
  \endgroup
  \edef\@listiv{\leftmargin\leftmarginiv
    \labelwidth=\dimexpr \leftmargin-\labelsep\relax
    \if@tempswa\noexpand\@list@extra\fi
  }%
  \@tempswafalse
  \begingroup
    \def\@list@extra{\aftergroup\@tempswatrue}%
    \csname @listv\endcsname
  \endgroup
  \edef\@listv{\leftmargin\leftmarginv
    \labelwidth=\dimexpr \leftmargin-\labelsep\relax
    \if@tempswa\noexpand\@list@extra\fi
  }%
  \@tempswafalse
  \begingroup
    \def\@list@extra{\aftergroup\@tempswatrue}%
    \csname @listvi\endcsname
  \endgroup
  \edef\@listvi{\leftmargin\leftmarginvi
    \labelwidth=\dimexpr \leftmargin-\labelsep\relax
    \if@tempswa\noexpand\@list@extra\fi
  }%
  \@listi
    \setlength{\@tempdimb}{\f@baselineskip}%
    \setlength{\footnotesep}{.555\@tempdimb}%
    \xepersian@setlength{\skip\footins}%
                  {.75\@tempdimb}{.3333\@tempdimb}{.1667\@tempdimb}%
    \xepersian@setlength{\floatsep}%
                  {\@tempdimb}{.1667\@tempdimb}{.1667\@tempdimb}%
    \xepersian@setlength{\textfloatsep}%
                  {1.6667\@tempdimb}{.1667\@tempdimb}{.3333\@tempdimb}%
    \setlength{\intextsep}{\floatsep}%
    \setlength{\dblfloatsep}{\floatsep}%
    \setlength{\dbltextfloatsep}{\textfloatsep}%
    \setlength{\@fptop}{\z@ \@plus 1fil}%
    \setlength{\@fpsep}{.6667\@tempdimb \@plus 2fil}%
    \setlength{\@fpbot}{\@fptop}%
    \setlength{\@dblfptop}{\@fptop}%
    \setlength{\@dblfpsep}{\@fpsep}%
    \setlength{\@dblfpbot}{\@fptop}%
    \xepersian@setlength{\partopsep}{.2\@tempdimb}{.1\@tempdimb}{.1\@tempdimb}%
}

\renewcommand*{\@bidi@logo@}{%
  \@bidi@logo@hb@xt@columnwidth
  {\hss\bfseries
حروف‌چینی شده {\today} در {\TypesetTime} با
  \textsf{\XePersian}\quad\@bidi@logo{xepersian-logo.pdf}}}

\renewcommand*{\@bidi@pdfcreator}{%
  The xepersian package, v\xepersian@version\space (Release \xepersian@releasename), \xepersiandate
}

\newcommand*{\@xepersian@pdfcustomproperties}{%
  This is the xepersian package, Version \xepersian@version\space (Release \xepersian@releasename),
  Released February 2, 2025.
}

\newcommand\twocolumnstableofcontents{%
\if@bidi@csundef{multi@column@out}{%
\PackageError{xepersian}{Oops! you should load multicol package before xepersian package for being able to use this command}{}}{%
  \begin{multicols}{2}[\section*{\contentsname}]%
    \small
    \@starttoc{toc}%
  \end{multicols}}}
\bidi@newrobustcmd*{\XePersian}{\leavevmode$\smash{\hbox{X\lower.5ex
  \hbox{\kern-.125em\bidi@reflect@box{E}}Persian}}$}
\AtBeginDocument{%
  \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%
\ifnum#2#3=30%
\xepersian@dahgan@tartibi#2%
\else%
\xepersian@dahgan#2%
\fi%
\ifnum#3>\z@\ و \xepersian@yekanv#3\fi%
#60%
\fi%
}
\def\xepersian@dahgan@tartibi#1{%
\ifcase#1\or\or بیست\or سی‌ا\or چهل%
\or پنجاه\or شصت\or هفتاد\or هشتاد%
\or نود\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%
}
\def\thempfootnote{{\itshape\@latinalph\c@mpfootnote}}
\renewcommand*{\bidi@@thebibliography@font@hook}{%
\if@LTRbibitems
  \resetlatinfont
\fi}
\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.}%
}{}}

\ApplyPatchToFiles{%
  footnote-xetex-bidi, %
  extrafootnotefeatures-xetex-bidi %
}[def][xepersian]

\ApplyPatchToClasses{%
  article, %
  amsart, %
  amsbook, %
  artikel1, %
  artikel2, %
  artikel3, %
  beamer, %
  bidimoderncv, %
  boek, %
  boek3, %
  book, %
  bookest, %
  extbook, %
  extarticle, %
  extreport, %
  imsproc, %
  memoir, %
  rapport1, %
  rapport3, %
  refrep, %
  report, %
  scrartcl, %
  scrbook, %
  scrreprt %
}[xepersian]

\ApplyPatchToPackages{%
  algorithm, %
  algorithmic, %
  appendix, %
  backref, %
  beamerbasetranslator, %
  bidituftesidenote, %
  breqn, %
  enumerate, %
  enumitem, %
  fancyref, %
  framed, %
  glossaries, %
  hyperref, %
  listings, %
  minitoc, %
  natbib, %
  soul, %
  tkz-linknodes, %
  tocloft, %
  url, %
  varioref %
}[xepersian]

\newtoks\xepersian@toks
\def\xepersian@tempa#1{%
\long\def\xepersian@@sp@def##1##2{%
  \futurelet\xepersian@resa\xepersian@@sp@d##2\@nil\@nil#1\@nil\relax##1}%
\long\def\xepersian@@sp@d{%
  \ifx\xepersian@resa\@sptoken
    \expandafter\xepersian@@sp@b
  \else
    \expandafter\xepersian@@sp@b\expandafter#1%
  \fi}%
\long\def\xepersian@@sp@b#1##1 \@nil{\xepersian@@sp@c##1}%
  }
\xepersian@tempa{ }
\long\def\xepersian@@sp@c#1\@nil#2\relax#3{\xepersian@toks{#1}\edef#3{\the\xepersian@toks}}
\def\xepersian@@fontsize@branch#1{%
  \@tempcnta\z@
  \@for\xepersian@tmp:=#1\do{%
    \xepersian@@sp@def\xepersian@frag{\xepersian@tmp}%
    \ifcase\@tempcnta\relax% cnta == 0
      \edef\xepersian@value{\xepersian@frag}%
      \setfontsize{\xepersian@frag}%
    \or% cnta == 1
      \setfontsize[\xepersian@frag]{\xepersian@value}%
    \else\fi
    \advance\@tempcnta\@ne}%
}

\bidi@patchcmd{\set@fontsize}{\@tempdimb#2pt}{%
  \@tempdimb\xepersian@@fontsize@scale\dimexpr#2pt\relax
}{}{}

\bidi@patchcmd{\set@fontsize}{\@tempskipa#3pt}{%
  \@tempskipa\xepersian@@baselineskip@scale\dimexpr#3pt\relax
}{}{}

\newcommand*{\xepersian@@update@math@fontsize}[1]{%
  \strip@pt\dimexpr\xepersian@@math@fontsize@scale
  \dimexpr 1pt * \dimexpr #1 pt\relax /
  \dimexpr \xepersian@@fontsize@scale pt\relax
  \relax\relax
}

\bidi@patchcmd{\getanddefine@fonts}{%
  \xdef\font@name{\csname \string#2/\tf@size\endcsname}%
}{%
  \xdef\font@name{\csname \string#2/\xepersian@@update@math@fontsize\tf@size\endcsname}%
}{}{}

\bidi@patchcmd{\getanddefine@fonts}{%
  \xdef\font@name{\csname \string#2/\sf@size\endcsname}%
}{%
  \xdef\font@name{\csname \string#2/\xepersian@@update@math@fontsize\sf@size\endcsname}%
}{}{}

\bidi@patchcmd{\getanddefine@fonts}{%
  \xdef\font@name{\csname \string#2/\ssf@size\endcsname}%
}{%
  \xdef\font@name{\csname \string#2/\xepersian@@update@math@fontsize\ssf@size\endcsname}%
}{}{}

\if@xepersian@@computeautoilg
\bidi@patchcmd{\set@fontsize}{%
\baselineskip\f@baselineskip\relax
}{%
\baselineskip\f@baselineskip\relax
\xepersian@computeautoilg
 \ifdim\xepersian@strutilg>\baselineskip
  \PackageInfo{xepersian}{character with height+depth greater than current baselineskip found in font}%
  \PackageInfo{xepersian}{baselineskip changed to that height+depth!}%
  \baselineskip\xepersian@strutilg
  \ifdim\footnotesep=.7\baselineskip
  \else
    \footnotesep.7\baselineskip
  \fi
 \fi
}{}{}
\fi

\AtEndOfPackage{%
  \setlatintextfont[%
    Path,%
    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'.
