%%
%% This is file `xepersian-mathsdigitspec.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xepersian.dtx  (with options: `table,xepersian-mathsdigitspec.sty')
%% 
%%   __________________________________________________
%%   Copyright (c) 2008--2018  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{10452}
%% \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}
\ProvidesPackage{xepersian-mathsdigitspec}
  [2018/01/01 v1.1.5 Unicode Persian maths digits in XeLaTeX]
\def\new@mathgroup{\alloc@8\mathgroup\chardef\@cclvi}
\let\newfam\new@mathgroup
\def\select@group#1#2#3#4{%
 \ifx\math@bgroup\bgroup\else\relax\expandafter\@firstofone\fi
 {%
 \ifmmode
  \ifnum\csname c@mv@\math@version\endcsname<\@cclvi
     \begingroup
       \escapechar\m@ne
       \getanddefine@fonts{\csname c@mv@\math@version\endcsname}#3%
       \globaldefs\@ne  \math@fonts
     \endgroup
     \init@restore@version
     \xdef#1{\noexpand\use@mathgroup\noexpand#2%
             {\number\csname c@mv@\math@version\endcsname}}%
     \global\advance\csname c@mv@\math@version\endcsname\@ne
   \else
     \let#1\relax
     \@latex@error{Too many math alphabets used in
                   version \math@version}%
        \@eha
   \fi
 \else \expandafter\non@alpherr\fi
 #1{#4}%
 }%
}
\def\document@select@group#1#2#3#4{%
 \ifx\math@bgroup\bgroup\else\relax\expandafter\@firstofone\fi
 {%
 \ifmmode
   \ifnum\csname c@mv@\math@version\endcsname<\@cclvi
     \begingroup
       \escapechar\m@ne
       \getanddefine@fonts{\csname c@mv@\math@version\endcsname}#3%
       \globaldefs\@ne  \math@fonts
     \endgroup
     \expandafter\extract@alph@from@version
         \csname mv@\math@version\expandafter\endcsname
         \expandafter{\number\csname
                       c@mv@\math@version\endcsname}%
          #1%
     \global\advance\csname c@mv@\math@version\endcsname\@ne
   \else
     \let#1\relax
     \@latex@error{Too many math alphabets used
                   in version \math@version}%
        \@eha
  \fi
 \else \expandafter\non@alpherr\fi
 #1{#4}%
 }%
}
\ExplSyntaxOn
\bool_set_false:N \g__fontspec_math_bool
\tl_map_inline:nn
 {
  \new@mathgroup\cdp@list\cdp@elt\DeclareMathSizes
  \@DeclareMathSizes\newmathalphabet\newmathalphabet@@\newmathalphabet@@@
  \DeclareMathVersion\define@mathalphabet\define@mathgroup\addtoversion
  \version@list\version@elt\alpha@list\alpha@elt
  \restore@mathversion\init@restore@version\dorestore@version\process@table
  \new@mathversion\DeclareSymbolFont\group@list\group@elt
  \new@symbolfont\SetSymbolFont\SetSymbolFont@\get@cdp
  \DeclareMathAlphabet\new@mathalphabet\SetMathAlphabet\SetMathAlphabet@
  \DeclareMathAccent\set@mathaccent\DeclareMathSymbol\set@mathchar
  \set@mathsymbol\DeclareMathDelimiter\@xxDeclareMathDelimiter
  \@DeclareMathDelimiter\@xDeclareMathDelimiter\set@mathdelimiter
  \set@@mathdelimiter\DeclareMathRadical\mathchar@type
  \DeclareSymbolFontAlphabet\DeclareSymbolFontAlphabet@
 }
 {
  \tl_remove_once:Nn \@preamblecmds {\do#1}
 }
\ExplSyntaxOff
\newcommand\xepersian@PackageInfo[1]{\PackageInfo{xepersian-mathsdigitspec}{#1}}
\newcommand\SetMathCode[4]{%
  \Umathcode#1="\mathchar@type#2 \csname sym#3\endcsname #4\relax}
\newcommand\SetMathCharDef[4]{%
  \Umathchardef#1="\mathchar@type#2 \csname sym#3\endcsname #4\relax}
\ExplSyntaxOn
\cs_new_eq:NN \orig_mathbf:n \mathbf
\cs_new_eq:NN \orig_mathit:n \mathit
\cs_new_eq:NN \orig_mathrm:n \mathrm
\cs_new_eq:NN \orig_mathsf:n \mathsf
\cs_new_eq:NN \orig_mathtt:n \mathtt
\NewDocumentCommand \new@mathbf { m } {
 \orig_mathbf:n {
   \int_step_inline:nnnn { `0 } { \c_one } { `9 } {
     \mathcode ##1 = \numexpr "100 * \symnew@mathbf@font@digits + ##1 \relax
   }
   #1
 }
}
\NewDocumentCommand \new@mathit { m } {
 \orig_mathit:n {
   \int_step_inline:nnnn { `0 } { \c_one } { `9 } {
     \mathcode ##1 = \numexpr "100 * \symnew@mathit@font@digits + ##1 \relax
   }
   #1
 }
}
\NewDocumentCommand \new@mathrm { m } {
 \orig_mathrm:n {
   \int_step_inline:nnnn { `0 } { \c_one } { `9 } {
     \mathcode ##1 = \numexpr "100 * \symnew@mathrm@font@digits + ##1 \relax
   }
   #1
 }
}
\NewDocumentCommand \new@mathsf{ m } {
 \orig_mathsf:n {
   \int_step_inline:nnnn { `0 } { \c_one } { `9 } {
     \mathcode ##1 = \numexpr "100 * \symnew@mathsf@font@digits + ##1 \relax
   }
   #1
 }
}
\NewDocumentCommand \new@mathtt{ m } {
 \orig_mathtt:n {
   \int_step_inline:nnnn { `0 } { \c_one } { `9 } {
     \mathcode ##1 = \numexpr "100 * \symnew@mathtt@font@digits + ##1 \relax
   }
   #1
 }
}

\DeclareDocumentCommand \setmathdigitfont { O{} m O{} }
  {
    \__xepersian_main_setmathdigitfont:nnn {#1} {#2} {#3}
  }
\cs_set:Nn \__xepersian_main_setmathdigitfont:nnn
 {
  \let\glb@currsize\relax
  \fontspec_set_family:Nnn \g__xepersian_mathdigitsfamily_tl {Mapping=parsidigits,#1,#3} {#2}
    \xepersian@PackageInfo{Defining the default Persian maths digits font as '#2'}
  \DeclareSymbolFont{OPERATORS}   {\g_fontspec_encoding_tl}{\g__xepersian_mathdigitsfamily_tl} {m}{n}
  \DeclareSymbolFont{new@mathbf@font@digits}{\g_fontspec_encoding_tl}{\g__xepersian_mathdigitsfamily_tl}{bx}{n}
  \DeclareSymbolFont{new@mathit@font@digits}{\g_fontspec_encoding_tl}{\g__xepersian_mathdigitsfamily_tl}{m}{it}
  \DeclareSymbolFont{new@mathrm@font@digits}{\g_fontspec_encoding_tl}{\g__xepersian_mathdigitsfamily_tl}{m}{n}
  \def\persianmathsdigits{%
  \SetMathCode{`0}{\mathalpha}{OPERATORS}{`0}
  \SetMathCode{`1}{\mathalpha}{OPERATORS}{`1}
  \SetMathCode{`2}{\mathalpha}{OPERATORS}{`2}
  \SetMathCode{`3}{\mathalpha}{OPERATORS}{`3}
  \SetMathCode{`4}{\mathalpha}{OPERATORS}{`4}
  \SetMathCode{`5}{\mathalpha}{OPERATORS}{`5}
  \SetMathCode{`6}{\mathalpha}{OPERATORS}{`6}
  \SetMathCode{`7}{\mathalpha}{OPERATORS}{`7}
  \SetMathCode{`8}{\mathalpha}{OPERATORS}{`8}
  \SetMathCode{`9}{\mathalpha}{OPERATORS}{`9}
  \SetMathCode{`\%}{\mathbin}{OPERATORS}{`٪}
  \SetMathCharDef{\decimalseparator}{\mathord}{OPERATORS}{"066B}
  \tl_set_eq:NN \mathbf \new@mathbf
  \tl_set_eq:NN \mathit \new@mathit
  \tl_set_eq:NN \mathrm \new@mathrm}
 }

\DeclareDocumentCommand \setmathsfdigitfont { O{} m O{} }
  {
    \__xepersian_main_setmathsfdigitfont:nnn {#1} {#2} {#3}
  }
\cs_set:Nn \__xepersian_main_setmathsfdigitfont:nnn
 {
  \fontspec_set_family:Nnn \g__xepersian_mathsfdigitfamily_tl {Mapping=parsidigits,#1,#3} {#2}
      \DeclareSymbolFont{new@mathsf@font@digits}{\g_fontspec_encoding_tl}{\g__xepersian_mathsfdigitfamily_tl}{m}{n}
    \def\persianmathsfdigits{\tl_set_eq:NN \mathsf \new@mathsf}
 }

\DeclareDocumentCommand \setmathttdigitfont { O{} m O{} }
  {
    \__xepersian_main_setmathttdigitfont:nnn {#1} {#2} {#3}
  }
\cs_set:Nn \__xepersian_main_setmathttdigitfont:nnn
 {
  \fontspec_set_family:Nnn \g__xepersian_mathttdigitfamily_tl {Mapping=parsidigits,#1,#3} {#2}
      \DeclareSymbolFont{new@mathtt@font@digits}{\g_fontspec_encoding_tl}{\g__xepersian_mathttdigitfamily_tl}{m}{n}
    \def\persianmathttdigits{\tl_set_eq:NN \mathtt \new@mathtt}
 }

\ExplSyntaxOff
\ifx\newcommand\undefined\else
  \newcommand{\ZifferAn}{}
\fi
\mathchardef\ziffer@DotOri="013A
{\ZifferAn
 \catcode`\.=\active\gdef.{\begingroup\obeyspaces\futurelet\n\ziffer@dcheck}}
\def\ziffer@dcheck{\ziffer@check\ZifferLeer\ziffer@DotOri}
\def\ziffer@check#1#2{%
  \ifx\n1\endgroup#1\else
    \ifx\n2\endgroup#1\else
      \ifx\n3\endgroup#1\else
        \ifx\n4\endgroup#1\else
          \ifx\n5\endgroup#1\else
            \ifx\n6\endgroup#1\else
              \ifx\n7\endgroup#1\else
                \ifx\n8\endgroup#1\else
                  \ifx\n9\endgroup#1\else
                    \ifx\n0\endgroup#1\else
                     \ifx\n\overline\endgroup#1\else
                      \endgroup#2%
                    \fi
                  \fi
                \fi
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
   \fi
 \fi}
\mathcode`.="8000\relax
\def\ZifferLeer{\ifx\decimalseparator\undefined .\else \decimalseparator\fi}
\def\DefaultInlineMathsDigits{\def\SetInlineMathsDigits{}}
\def\DefaultDisplayMathsDigits{\def\SetDisplayMathsDigits{}}
\def\DefaultMathsDigits{%
  \DefaultInlineMathsDigits%
  \DefaultDisplayMathsDigits%
}
\def\PersianInlineMathsDigits{\def\SetInlineMathsDigits{%
\ifx\persianmathsdigits\undefined\else\persianmathsdigits\fi%
\ifx\persianmathsfdigits\undefined\else\persianmathsfdigits\fi%
\ifx\persianmathttdigits\undefined\else\persianmathttdigits\fi}}
\def\PersianDisplayMathsDigits{\def\SetDisplayMathsDigits{%
\ifx\persianmathsdigits\undefined\else\persianmathsdigits\fi%
\ifx\persianmathsfdigits\undefined\else\persianmathsfdigits\fi%
\ifx\persianmathttdigits\undefined\else\persianmathttdigits\fi}}
\def\PersianMathsDigits{%
  \PersianInlineMathsDigits%
  \PersianDisplayMathsDigits%
}
\def\AutoInlineMathsDigits{\def\SetInlineMathsDigits{%
\ifx\persianmathsdigits\undefined\else\if@nonlatin\persianmathsdigits\fi\fi%
\ifx\persianmathsfdigits\undefined\else\if@nonlatin\persianmathsfdigits\fi\fi%
\ifx\persianmathttdigits\undefined\else\if@nonlatin\persianmathttdigits\fi\fi}}
\def\AutoDisplayMathsDigits{\def\SetDisplayMathsDigits{%
\ifx\persianmathsdigits\undefined\else\if@nonlatin\persianmathsdigits\fi\fi%
\ifx\persianmathsfdigits\undefined\else\if@nonlatin\persianmathsfdigits\fi\fi%
\ifx\persianmathttdigits\undefined\else\if@nonlatin\persianmathttdigits\fi\fi}}
\def\AutoMathsDigits{%
  \AutoInlineMathsDigits%
  \AutoDisplayMathsDigits%
}
\AutoMathsDigits
\everymath\expandafter{\the\everymath\SetInlineMathsDigits%
  \let\SetDisplayMathsDigits\relax%
}
\everydisplay\expandafter{%
  \the\everydisplay\SetDisplayMathsDigits%
  \let\SetInlineMathsDigits\relax%
}
\endinput
%%
%% End of file `xepersian-mathsdigitspec.sty'.
