Xepersian package prints persian text but does not recognize formulas and gives error

I have used MiKTeX for many works in last year. I didn't have a problem installing it. But now I am trying to install it on my new laptop. It's killing me with an ocean of errors. it has been two weeks, after tackling hundreds of errors finally I have been able to make it recognize Persian text. For example:

\documentclass{book}
\usepackage{xepersian}
\begin{document}
سلام
\end{document}


and it successfully prints the pdf file when typeset by XeLaTeX. But when I add a simple formula like the following:

\documentclass{book}
\usepackage{xepersian}
\begin{document}
سلام
$e^{i\pi}+1=0$
\end{document}


it will not give any output, instead the following error shows up:

! Undefined control sequence.
\SetMathCode #1#2#3#4->\Umathcode
#1="\mathchar@type #2 \csname sym#3\endcsn...
l.5 $e^{i\pi}+1=0$
?


What should I do? I am tired of examining various unhelpful solutions. I already installed and uninstalled MiKTeX many times. I downloaded Persian modern installed and put them in my windows. and many many many many other things I have done that I dont want to bore you with..... Many forums suggested to use TeX Live instead but I don't want to use that. It seems like another kind of problem that cant be solved by just changing the software. I want to know what is the problem with this software?

• I suspect you have old versions of some packages. Can you add the output you get in the log by adding \listfiles as the first command in the test document? Add what goes from **File List** to the end of the list. – egreg May 1 '13 at 9:20
• Dear egreg, I got the solution from Persian TeX Group. I also thank you for your kind attention to my problem – Sina May 1 '13 at 9:47

Sina, I find the tone of your language slightly (and uselessly) aggressive. The solutions you tried perhaps was your own solutions; well you may never talked about the problem with an expert; at least you did not contact us (maintainer of xepersian).

So what is the problem? In new version of XeTeX, \XeTeXmathcode and \XeTeXmathchardef are depreciated and so we changed them in new version of xepersian to \Umathcode and \Umathchardef. MikTeX still ships the old xetex binary and so you get the error. If you want to use MiKTeX, then as a workaround, add the following lines to the preamble of your tex document:

\makeatletter
\@ifundefined{Umathcode}{\let\Umathcode\XeTeXmathcode}{}
\@ifundefined{Umathchardef}{\let\Umathchardef\XeTeXmathchardef}{}
\makeatother


Or better install TeXLive 2013 (when it will be officially released).

• Dear Persian TeX Group. I am really really sorry for my tone. I didn't mean to be aggressive. Its because of my bad English. I hope you forgive me. When I said I searched many many forums and tried out many many solutions I meant from some other forums in this field. Now I understand that I should have come to this website and asked my question from the beginning. Your solution was very useful and finally worked for me. I really appreciate your help. I am really grateful for your groups effort in developing the software for Persian language. – Sina May 1 '13 at 9:44
• Sina, that is the pleasure. If you feel more confident asking your questions in Persian, you may try parsilatex forum: parsilatex.com/forum/SMF/index.php – Persian TeX Group May 1 '13 at 9:53

Try this.

\documentclass{book}
\usepackage{xepersian}
\settextfont[Scale=1]{XB Zar}
\begin{document}
سلام
\begin{latin}
$e ^ { i \ pi } + 1 = 0$
\end{latin}
\end{document}


Or this.

\documentclass{book}
\usepackage{xepersian}
\settextfont[Scale=1]{XB Zar}
\begin{document}
سلام
\lr{$e ^ { i \ pi } + 1 = 0$}
\end{document}


Better to use \dfrac{•}{•} in amsmath package for division.