\NeedsTeXFormat{LaTeX2e} \ProvidesPackage{xepersian}[2008/09/27 v0.162 Persian typesetting in XeLaTeX] \begingroup \def\notXeLaTeXformat{% \@latex@error{*** this package currently works only with XeLaTeX ***^^J You are not using XeLaTeX, so we are exiting cleanly!^^J Continuing may lead to 'unavailable font metrics' errors!^^J}\@ehc \endgroup\endinput} \expandafter\ifx\csname XeTeXpicfile\endcsname\relax\expandafter\notXeLaTeXformat\fi \endgroup \RequirePackage{graphicx} \RequirePackage{amssymb} \RequirePackage{amsmath} \RequirePackage{amsthm} \RequirePackage[quiet]{fontspec} \RequirePackage{bidi} \RequirePackage{xltxtra} \RequirePackage{xunicode} \RequirePackage{etoolbox} \RequirePackage{xepersian-mathsdigitspec} \def\ps@plain{\ps@empty \def\@oddfoot{\hfil\farsifont\thepage\hfil}% \let\@evenfoot\@oddfoot \let\@oddhead\@empty\let\@evenhead\@empty } \AtBeginDocument{\setRL\farsifont\addfontfeature{Mapping=parsidigits}} %To convert the MILADI date to SHAMSI date, taken from farsitex \newif\ifFT@leap \newif\ifFT@kabiseh \newcount\FT@i \newcount\FT@y \newcount\FT@m \newcount\FT@d \newcount\FT@latini \newcount\FT@farsii \newcount\FT@latinii \newcount\FT@farsiii \newcount\FT@latiniii \newcount\FT@farsiiii \newcount\FT@latiniv \newcount\FT@farsiiv \newcount\FT@latinv \newcount\FT@farsiv \newcount\FT@latinvi \newcount\FT@farsivi \newcount\FT@latinvii \newcount\FT@farsivii \newcount\FT@latinviii \newcount\FT@farsiviii \newcount\FT@latinix \newcount\FT@farsiix \newcount\FT@latinx \newcount\FT@farsix \newcount\FT@latinxi \newcount\FT@farsixi \newcount\FT@latinxii \newcount\FT@farsixii \newcount\FT@farsixiii \newcount\FT@temp \newcount\FT@temptwo \newcount\FT@tempthree \newcount\FT@yModHundred \newcount\FT@thirtytwo \newcount\FT@dn \newcount\FT@sn \newcount\FT@mminusone \def\ftoday{% \FT@y=\year \FT@m=\month \FT@d=\day % \FT@temp=\FT@y \divide\FT@temp by 100\relax \multiply\FT@temp by 100\relax \FT@yModHundred=\FT@y \advance\FT@yModHundred by -\FT@temp\relax % \ifodd\FT@yModHundred \FT@leapfalse \else \FT@temp=\FT@yModHundred \divide\FT@temp by 2\relax \ifodd\FT@temp\FT@leapfalse \else \ifnum\FT@yModHundred=0% \FT@temp=\FT@y \divide\FT@temp by 400\relax \multiply\FT@temp by 400\relax \ifnum\FT@y=\FT@temp\FT@leaptrue\else\FT@leapfalse\fi \else\FT@leaptrue \fi \fi \fi % \FT@latini=31\relax \ifFT@leap \FT@latinii = 29\relax \else \FT@latinii = 28\relax \fi \FT@latiniii = 31\relax \FT@latiniv = 30\relax \FT@latinv = 31\relax \FT@latinvi = 30\relax \FT@latinvii = 31\relax \FT@latinviii = 31\relax \FT@latinix = 30\relax \FT@latinx = 31\relax \FT@latinxi = 30\relax \FT@latinxii = 31\relax % \FT@thirtytwo=32\relax % \FT@temp=\FT@y \advance\FT@temp by -17\relax \FT@temptwo=\FT@temp \divide\FT@temptwo by 33\relax \multiply\FT@temptwo by 33\relax \advance\FT@temp by -\FT@temptwo \ifnum\FT@temp=\FT@thirtytwo\FT@kabisehfalse \else \FT@temptwo=\FT@temp \divide\FT@temptwo by 4\relax \multiply\FT@temptwo by 4\relax \advance\FT@temp by -\FT@temptwo \ifnum\FT@temp=\z@\FT@kabisehtrue\else\FT@kabisehfalse\fi \fi % % --BE % In fact farsii is equal to the Leap years from a fixed year to the last % year minus the Kabise years from a fixed year to the last year plus a const. % \FT@tempthree=\FT@y % Number of Leap years \advance\FT@tempthree by -1 \FT@temp=\FT@tempthree % T := (MY-1) div 4 \divide\FT@temp by 4\relax \FT@temptwo=\FT@tempthree % T := T - ((MY-1) div 100) \divide\FT@temptwo by 100\relax \advance\FT@temp by -\FT@temptwo \FT@temptwo=\FT@tempthree % T := T + ((MY-1) div 400) \divide\FT@temptwo by 400\relax \advance\FT@temp by \FT@temptwo \advance\FT@tempthree by -611 % Number of Kabise years \FT@temptwo=\FT@tempthree % T := T - ((SY+10) div 33) * 8 \divide\FT@temptwo by 33\relax \multiply\FT@temptwo by 8\relax \advance\FT@temp by -\FT@temptwo \FT@temptwo=\FT@tempthree % \divide\FT@temptwo by 33\relax \multiply\FT@temptwo by 33\relax \advance\FT@tempthree by -\FT@temptwo \ifnum\FT@tempthree=32\advance\FT@temp by 1\fi % if (SY+10) mod 33=32 then Inc(T); \divide\FT@tempthree by 4\relax % T := T - ((SY+10) mod 33) div 4 \advance\FT@temp by -\FT@tempthree \advance\FT@temp by -137 % T := T - 137 Adjust the value \FT@farsii=31 \advance\FT@farsii by -\FT@temp % now 31 - T is the farsii % \FT@farsiii = 30\relax \ifFT@kabiseh \FT@farsiiii = 30\relax \else \FT@farsiiii = 29\relax \fi \FT@farsiiv = 31\relax \FT@farsiv = 31\relax \FT@farsivi = 31\relax \FT@farsivii = 31\relax \FT@farsiviii= 31\relax \FT@farsiix = 31\relax \FT@farsix = 30\relax \FT@farsixi = 30\relax \FT@farsixii = 30\relax \FT@farsixiii= 30\relax % \FT@dn= 0\relax \FT@sn= 0\relax \FT@mminusone=\FT@m \advance\FT@mminusone by -1\relax % \FT@i=0\relax \ifnum\FT@i < \FT@mminusone \loop \advance \FT@i by 1\relax \advance\FT@dn by \csname FT@latin\romannumeral\the\FT@i\endcsname \ifnum\FT@i<\FT@mminusone \repeat \fi \advance \FT@dn by \FT@d % \FT@i=1\relax \FT@sn = \FT@farsii \ifnum \FT@sn<\FT@dn \loop \advance \FT@i by 1\relax \advance\FT@sn by \csname FT@farsi\romannumeral\the\FT@i\endcsname \ifnum \FT@sn<\FT@dn \repeat \fi \ifnum \FT@i < 4 \FT@m = 9 \advance\FT@m by \FT@i \advance \FT@y by -622\relax \else \FT@m = \FT@i \advance \FT@m by -3\relax \advance \FT@y by -621\relax \fi \advance\FT@sn by -\csname FT@farsi\romannumeral\the\FT@i% \endcsname \ifnum\FT@i = 1 \FT@d = \FT@dn \advance \FT@d by 30 \advance\FT@d by -\FT@farsii \else \FT@d = \FT@dn \advance \FT@d by -\FT@sn \fi \beginL\number\FT@d\endL\space% %Changedc from here YJ \farsimonth{\FT@m}\space\beginL\number\FT@y\endL% } % added \farsimonth YJ \def\farsimonth#1{\ifcase#1\or فروردین\or اردیبهشت\or خرداد\or تیر\or مرداد\or شهریور\or مهر\or آبان\or آذر\or دی\or بهمن\or اسفند\fi} \def\normalfont{\farsifont} \def\today{\ftoday} \let\@footnote=\footnote \def\footnote#1{\@footnote{\farsifont#1}} \let\@uthanks=\thanks \def\thanks#1{\@uthanks{\farsifont#1}} \let\@uframetitle=\frametitle \def\frametitle#1{\@uframetitle{\centerline{\farsifont#1}}} \let\@uframesubtitle=\framesubtitle \def\framesubtitle#1{\@uframesubtitle{\centerline{\farsifont#1}}} \let\@usubtitle=\subtitle \def\subtitle#1{\@usubtitle{\farsifont#1}} \let\@uinstitute=\institute \def\institute#1{\@uinstitute{\farsifont#1}} \let\@ucaption=\caption \def\caption#1{\@ucaption{\farsifont#1}} \let\@uleftmark=\leftmark \def\leftmark{\beginR\farsifont\@uleftmark\endR} \let\@urightmark=\rightmark \def\rightmark{\beginR\farsifont\@urightmark\endR} \renewcommand{\thefootnote}{\arabic{footnote}} \renewcommand{\thefigure}{\arabic{figure}} \renewcommand{\thetable}{\arabic{table}} \renewcommand{\theequation}{\arabic{equation}} \renewcommand{\figurename}{\farsifont شکل} \renewcommand{\tablename}{\farsifont جدول} \renewcommand{\contentsname}{فهرست مطالب} \renewcommand{\listfigurename}{لیست تصاویر} \renewcommand{\listtablename}{لیست جداول} \renewcommand{\appendixname}{پیوست} \renewcommand{\indexname}{نمایه} \@ifclassloaded{article}{% \def\ps@plain{\ps@empty \def\@oddfoot{\hfil\rl\thepage\hfil}% \let\@evenfoot\@oddfoot } \renewenvironment{thebibliography}[1] {\section*{\refname}% \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}% \list{\@biblabel{\@arabic\c@enumiv}}% {\settowidth\labelwidth{\@biblabel{#1}}% \rightmargin\labelwidth \advance\rightmargin\labelsep \@openbib@code \usecounter{enumiv}% \let\p@enumiv\@empty \renewcommand\theenumiv{\@arabic\c@enumiv}}% \sloppy \clubpenalty4000 \@clubpenalty \clubpenalty \widowpenalty4000% \sfcode`\.\@m} {\def\@noitemerr {\@latex@warning{Empty `thebibliography' environment}}% \endlist} \if@twoside \def\ps@headings{% \let\@oddfoot\@empty\let\@evenfoot\@empty \def\@evenhead{\rl\leftmark\hfil\rl\thepage}% \def\@oddhead{\rl\thepage\hfil\rl\rightmark}% \let\@mkboth\markboth \def\sectionmark##1{% \markboth {\MakeUppercase{% \ifnum \c@secnumdepth >\z@ \thesection\quad \fi \rl{##1}}}{}}% \def\subsectionmark##1{% \markright {% \ifnum \c@secnumdepth >\@ne \rl{\thesubsection\quad} \fi \rl{##1}}}} \else \def\ps@headings{% \let\@oddfoot\@empty \def\@oddhead{\rl\thepage\hfil\rl\rightmark}% \let\@mkboth\markboth \def\sectionmark##1{% \markright {\MakeUppercase{% \ifnum \c@secnumdepth >\m@ne \rl{\thesection\quad} \fi \rl{##1}}}}} \fi \def\ps@myheadings{% \let\@oddfoot\@empty\let\@evenfoot\@empty \def\@evenhead{\rl\thepage\hfil\rl\leftmark}% \def\@oddhead{\rl\rightmark\hfil\rl\thepage}% \let\@mkboth\@gobbletwo \let\sectionmark\@gobble \let\subsectionmark\@gobble } \pagestyle{plain} \renewcommand{\refname}{مراجع} \renewcommand{\abstractname}{چکیده} \renewcommand\appendix{\par \setcounter{section}{0}% \setcounter{subsection}{0}% \gdef\thesection{\@harfi\c@section}} }{} \@ifclassloaded{amsart}{% \let\oldleftskip=\leftskip \let\leftskip=\rightskip \let\rightskip=\oldleftskip \renewenvironment{thebibliography}[1]{% \@bibtitlestyle \normalfont\bibliofont\labelsep .5em\relax \renewcommand\theenumiv{\arabic{enumiv}}\let\p@enumiv\@empty \list{\@biblabel{\theenumiv}}{\settowidth\labelwidth{\@biblabel{#1}}% \leftmargin\labelwidth \advance\leftmargin\labelsep \rightmargin\labelwidth \advance\rightmargin\labelsep \usecounter{enumiv}}% \sloppy \clubpenalty\@M \widowpenalty\clubpenalty \sfcode`\.=\@m }{% \def\@noitemerr{\@latex@warning{Empty `thebibliography' environment}}% \endlist } \renewcommand{\datename}{\rl{تاریخ:}} \renewcommand{\refname}{مراجع} \renewcommand{\abstractname}{چکیده} \renewcommand\appendix{\par \setcounter{section}{0}% \setcounter{subsection}{0}% \gdef\thesection{\@harfi\c@section}} }{} \@ifclassloaded{report}{% \renewenvironment{thebibliography}[1] {\chapter*{\bibname}% \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}% \list{\@biblabel{\@arabic\c@enumiv}}% {\settowidth\labelwidth{\@biblabel{#1}}% \rightmargin\labelwidth \advance\rightmargin\labelsep \@openbib@code \usecounter{enumiv}% \let\p@enumiv\@empty \renewcommand\theenumiv{\@arabic\c@enumiv}}% \sloppy \clubpenalty4000 \@clubpenalty \clubpenalty \widowpenalty4000% \sfcode`\.\@m} {\def\@noitemerr {\@latex@warning{Empty `thebibliography' environment}}% \endlist} \if@twoside \def\ps@headings{% \let\@oddfoot\@empty\let\@evenfoot\@empty \def\@evenhead{\rl\thepage\hfil\rl\leftmark}% \def\@oddhead{\rl\rightmark\hfil\rl\thepage}% \let\@mkboth\markboth \def\chaptermark##1{% \markboth {\MakeUppercase{% \ifnum \c@secnumdepth >\m@ne \rl{\@chapapp\ \thechapter. \ }% \fi \rl{##1}}}{}}% \def\sectionmark##1{% \markright {\MakeUppercase{% \ifnum \c@secnumdepth >\z@ \rl{\thesection. \ }% \fi \rl{##1}}}}} \else \def\ps@headings{% \let\@oddfoot\@empty \def\@oddhead{\rl\rightmark\hfil\rl\thepage}% \let\@mkboth\markboth \def\chaptermark##1{% \markright {\MakeUppercase{% \ifnum \c@secnumdepth >\m@ne \rl{\@chapapp\ \thechapter. \ }% \fi \rl{##1}}}}} \fi \def\ps@myheadings{% \let\@oddfoot\@empty\let\@evenfoot\@empty \def\@evenhead{\rl\thepage\hfil\rl\leftmark}% \def\@oddhead{rl\rightmark\hfil\rl\thepage}% \let\@mkboth\@gobbletwo \let\chaptermark\@gobble \let\sectionmark\@gobble } \pagestyle{plain} \renewcommand{\bibname}{مراجع} \renewcommand{\abstractname}{چکیده} \renewcommand{\chaptername}{فصل} \renewcommand{\partname}{بخش} %to make appendix numbering farsi \renewcommand\appendix{\par \setcounter{chapter}{0}% \setcounter{section}{0}% \gdef\@chapapp{\appendixname}% \gdef\thechapter{\@harfi\c@chapter} }%end appendix }{} \@ifclassloaded{amsbook}{% \renewenvironment{thebibliography}[1]{% \@bibtitlestyle \normalfont\bibliofont\labelsep .5em\relax \renewcommand\theenumiv{\arabic{enumiv}}\let\p@enumiv\@empty \list{\@biblabel{\theenumiv}}{\settowidth\labelwidth{\@biblabel{#1}}% \rightmargin\labelwidth \advance\rightmargin\labelsep \leftmargin\labelwidth \advance\leftmargin\labelsep \usecounter{enumiv}}% \sloppy \clubpenalty\@M \widowpenalty\clubpenalty \sfcode`\.=\@m }{% \def\@noitemerr{\@latex@warning{Empty `thebibliography' environment}}% \endlist } \let\oldleftskip=\leftskip \let\leftskip=\rightskip \let\rightskip=\oldleftskip \def\frontmatter{\cleardoublepage\pagenumbering{harfi}} \renewcommand{\bibname}{کتاب‌نامه } \renewcommand{\chaptername}{فصل} \renewcommand{\partname}{بخش} %to make appendix numbering farsi \renewcommand\appendix{\par \setcounter{chapter}{0}% \setcounter{section}{0}% \gdef\@chapapp{\appendixname}% \gdef\thechapter{\@harfi\c@chapter} }%end appendix }{} \@ifclassloaded{bookest}{% \NoHyper \renewcommand{\bibname}{کتاب‌نامه } \renewcommand{\chaptername}{فصل} \renewcommand{\partname}{بخش} %to make appendix numbering farsi \renewcommand\appendix{\par \setcounter{chapter}{0}% \setcounter{section}{0}% \gdef\@chapapp{\appendixname}% \gdef\thechapter{\@harfi\c@chapter} }%end appendix }{} \@ifclassloaded{book}{% \renewenvironment{thebibliography}[1] {\chapter*{\bibname}% \@mkboth{\MakeUppercase\bibname}{\MakeUppercase\bibname}% \list{\@biblabel{\@arabic\c@enumiv}}% {\settowidth\labelwidth{\@biblabel{#1}}% \rightmargin\labelwidth \advance\rightmargin\labelsep \@openbib@code \usecounter{enumiv}% \let\p@enumiv\@empty \renewcommand\theenumiv{\@arabic\c@enumiv}}% \sloppy \clubpenalty4000 \@clubpenalty \clubpenalty \widowpenalty4000% \sfcode`\.\@m} {\def\@noitemerr {\@latex@warning{Empty `thebibliography' environment}}% \endlist} \renewcommand\frontmatter{% \cleardoublepage \@mainmatterfalse \pagenumbering{harfi}} \renewcommand\mainmatter{% \cleardoublepage \@mainmattertrue \pagenumbering{farsi}} \renewcommand\backmatter{% \if@openright \cleardoublepage \else \clearpage \fi \@mainmatterfalse} \if@twoside \def\ps@headings{% \let\@oddfoot\@empty\let\@evenfoot\@empty \def\@evenhead{\rl\rightmark\hfil\rl\thepage}% \def\@oddhead{\rl\thepage\hfil\rl\leftmark}% \let\@mkboth\markboth \def\chaptermark##1{% \markboth {\MakeUppercase{% \rl{\@chapapp\ \thechapter.\,\,}% \ifnum \c@secnumdepth >\m@ne \if@mainmatter \rl{##1} \fi \fi }}{}}% \def\ps@plain{\ps@empty \def\@oddfoot{\hfil\rl\thepage\hfil}% \let\@evenfoot\@oddfoot } \def\sectionmark##1{% \markright {\MakeUppercase{% \rl{\thesection}\, \ifnum \c@secnumdepth >\z@ \rl{##1} \ % \fi }}}} \else \def\ps@headings{% \let\@oddfoot\@empty \def\@oddhead{\rl\thepage\hfil\rl\rightmark}% \let\@mkboth\markboth \def\chaptermark##1{% \markright {\MakeUppercase{% \rl{\@chapapp\ \thechapter. } % \ifnum \c@secnumdepth >\m@ne \if@mainmatter \rl{##1} \fi \fi }}}} \fi \pagestyle{headings} \renewcommand{\bibname}{کتاب‌نامه } \renewcommand{\chaptername}{فصل} \renewcommand{\partname}{بخش} %to make appendix numbering farsi \renewcommand\appendix{\par \setcounter{chapter}{0}% \setcounter{section}{0}% \gdef\@chapapp{\appendixname}% \gdef\thechapter{\@harfi\c@chapter} }%end appendix }{} \@ifclassloaded{refrep}{% \renewcommand{\bibname}{کتاب‌نامه } \renewcommand{\chaptername}{فصل} \renewcommand{\partname}{بخش} %to make appendix numbering farsi \renewcommand\appendix{\par \setcounter{chapter}{0}% \setcounter{section}{0}% \gdef\@chapapp{\appendixname}% \gdef\thechapter{\@harfi\c@chapter} }%end appendix }{} %We redefine arabic counter style \def\@@number#1{\ifmmode\else\beginL\fi{\farsifont #1}\ifmmode\else\endL\fi} \def\@@latin#1{\@@number{{\@fromrl#1}}} \def\@number{\protect\@@number} \def\@latin{\protect\@@latin} \let\@farsi=\@arabic \let\@@arabic=\@arabic \let\@@roman=\@roman \let\@@Roman=\@Roman \let\@@alph=\@alph \let\@@Alph=\@Alph \def\@arabic#1{\ifmmode\else\@number{\@@arabic#1}\fi} \def\@Roman#1{\@latin{\@@Roman#1}} \def\arabicnorl#1{\expandafter\@@arabic\csname c@#1\endcsname} \def\make@lr#1{\begingroup \toks@=\expandafter{#1}% \edef\x{\endgroup \def\noexpand#1{\noexpand\@number{\the\toks@}}}% \x} \def\@character#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 ی\fi} \def\@harfi#1{\farsifont\@character{\@@arabic#1}} \def\@numeric#1{\ifcase#1 \or یک\or دو\or سه\or چهار\or پنج\or شش\or هفت\or هشت\or نه\or ده\or یازده\or دوازده\or سیزده\or چهارده\or پانزده\or شانزده\or هفده\or هجده\or نوزده\or بیست\fi} \def\@adadi#1{\farsifont\@numeric{\@@arabic#1}} %The figure or table caption \newsavebox\@Arabitempboxa \long\def\@makecaption#1#2{% \vskip\abovecaptionskip \sbox\@Arabitempboxa{\beginR #1: #2\endR}% \ifdim \wd\@Arabitempboxa >\hsize \beginR #1: #2\endR\par \else \global \@minipagefalse \hb@xt@\hsize{\hfil\box\@Arabitempboxa\hfil}% \fi \vskip\belowcaptionskip} %The correct the right footnorerule so it does not overlap the texts \def\r@fn{% \hbox to \columnwidth {\beginR \vbox{\kern -3\p@ \hrule width .4\columnwidth \kern2.6\p@}\hfil\endR}} \def\footnoterule{\r@fn} %a command to put a footnote from left to right %while in a right to left context \providerobustcmd{\Footnote}[1]{% \bgroup% To make the scope of the change local \footnotemark% \renewcommand{\thefootnote}{\arabic{footnote}}% \unsetRL% \footnotetext{#1}% \egroup } %For Right-to-Left two column command, I guess taken from rlbabel \makeatletter \let\@old@outputdblcol\@outputdblcol \newcommand{\rl@outputdblcolumn}{% \if@firstcolumn \global \@firstcolumnfalse \global \setbox\@leftcolumn \box\@outputbox \else \global \@firstcolumntrue \setbox\@outputbox \vbox {\hb@xt@\textwidth {% \hskip\columnwidth% \hfil\vrule\@width\columnseprule\hfil \hb@xt@\columnwidth {% \box\@leftcolumn \hss}% \hb@xt@\columnwidth {% \hskip-\textwidth% \box\@outputbox \hss}% \hskip\columnsep% \hskip\columnwidth}}% \@combinedblfloats \@outputpage \begingroup \@dblfloatplacement \@startdblcolumn \@whilesw\if@fcolmade \fi {\@outputpage \@startdblcolumn}% \endgroup \fi} \newcommand{\rldblcolumn}{\renewcommand{\@outputdblcol}{\rl@outputdblcolumn}} \newcommand{\lrdblcolumn}{\renewcommand{\@outputdblcol}{\@old@outputdblcol}} %set the default direction of the twocolumn texts to Right-to-Left \rldblcolumn % define the XePersian logo \def\reflect#1{{\setbox0=\hbox{#1}\rlap{\kern0.5\wd0 \special{x:gsave}\special{x:scale -1 1}}\box0 \special{x:grestore}}} \def\XePersian{\leavevmode$\smash{\hbox{X\lower.5ex \hbox{\kern-.125em\reflect{E}}Persian}}$} \newenvironment{english}{\par\vspace{.5cm}\setLR\begin{rmfamily}}{\end{rmfamily}\par\vspace{.5cm}} \def\lr#1{\LR{\rmfamily{#1}}} \def\rl#1{\RL{\farsifont#1}} %To fix tabular problem in bidi. Taken from farsitex \newif\if@tabsw \global\@tabswfalse \def\@tabular{\if@rl\global\@tabswtrue\fi \leavevmode \hbox \bgroup \if@tabsw\beginR\normalfont \fi $\let\@acol\@tabacol \let\@classz\@tabclassz \let\@classiv\@tabclassiv \let\\\@tabularcr\@tabarray} \def\endtabular{\crcr\egroup\if@tabsw\egroup\endR\egroup\fi \egroup $\if@tabsw\endR\fi \egroup \global\@tabswfalse} \expandafter \let \csname endtabular*\endcsname = \endtabular \def\@array[#1]#2{\setbox\@arstrutbox=\hbox{\vrule height\arraystretch \ht\strutbox depth\arraystretch \dp\strutbox width\z@}\@mkpream{#2}\edef\@preamble{% \halign \noexpand\@halignto \bgroup \tabskip\z@ \@arstrut \@preamble \tabskip\z@ \cr}% \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox \if #1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi \bgroup \let\par\relax \let\@sharp##\let\protect\relax \lineskip\z@\baselineskip\z@ \if@tabsw\hbox\bgroup\beginR\vbox\bgroup\fi \@preamble} %taken from rlbabel.ldf \newif\if@rl \AtBeginDocument{% Here we set the main document direction \newif\if@rlmain% \if@rl% e.g: if the options to babel were [english,hebrew] \@rlmaintrue% \else% e.g: if the options to babel were [hebrew,english] \@rlmainfalse% \fi% } %To fix eqref problem taken from amsmath \let\@@text=\text \def\text#1{\@@text{\RL{#1}}} \def\tagform@#1{\maketag@@@{)\ignorespaces\text{#1}\unskip\@@italiccorr(}} \renewcommand{\eqref}[1]{(\ref{#1})} %To fix equation numbers. taken from amsmath \renewenvironment{equation}{% \par\unsetRL \incr@eqnum \mathdisplay@push \st@rredfalse \global\@eqnswtrue \mathdisplay{equation}% }{% \endmathdisplay{equation}% \mathdisplay@pop \ignorespacesafterend \par\setRL\noindent } %almost taken verbatim from polyglossia for making abjad numbering in enumerate environment \providecommand*{\xpg@warning}[1]{% \PackageWarning{XePersian}% {#1}} \ifcsdef{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@zero{} \def\abj@num@i#1{% \ifcase#1\or ا\or ب\or ج\char"200D\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} } \def\farsi@numbers{% \let\@latinalph\@alph% \let\@latinAlph\@Alph% \let\@alph\abjad% \let\@Alph\abjad% } \AtBeginDocument{\farsi@numbers} \newcommand\twocolumnstableofcontents{% \begin{multicols}{2}[\section*{\contentsname}]% \small \@starttoc{toc}% \end{multicols}} \def\rcases#1{\left.\vcenter{\normalbaselines\m@th \ialign{$##\hfil$&\quad{##}\hfil\crcr#1\crcr}}\,\right\}} \endinput