چرا \autoref داخل دستور \text در محیط ریاضی کار نمیکند؟
بسته amstext دستور شرطی \iffirstchoice@ را تعریف میکند که به صورت پیشفرض مقدارش درست است هرچند اگر تعریف دستور \text@ (که در تعریف دستور \textبه کار رفته است) را در این بسته نگاه کنید
\def\text@#1{{\mathchoice
{\textdef@\displaystyle\f@size{#1}}%
{\textdef@\textstyle\f@size{\firstchoice@false #1}}%
{\textdef@\textstyle\sf@size{\firstchoice@false #1}}%
{\textdef@\textstyle \ssf@size{\firstchoice@false #1}}%
\check@mathfonts
}%
}
میبینید که در همه حالات غیر از حالت \displaystyle مقدار دستور شرطی نادرست است. از طرفی دیگر همین بسته دستور \addtocounter را تنها زمانی تعریف (بازتعریف) میکند که مقدار دستور شرطی درست باشد
\def\addtocounter#1#2{%
\iffirstchoice@
\@ifundefined {c@#1}{\@nocounterr {#1}}%
{\global \advance \csname c@#1\endcsname #2\relax}%
\fi}
بنابراین در نمونه شما دستور \addtocounter هیچ کاری انجام نمیدهد حال آنکه بسته hyperref از این دستور برای ارجاعات استفاده میکند.
راهحل کوتاه
در این نمونه از دستور \text استفاده شده است.
\documentclass{book}
\usepackage{amsmath,amssymb,amsthm,amsfonts}
\usepackage[colorlinks=true]{hyperref}
\usepackage{xepersian}
\settextfont[Scale=1]{Yas}
\setlatintextfont[Scale=.95]{Times New Roman}
\setdigitfont[Scale=1]{Yas}
\defpersianfont\chapfont[Scale=3.3]{Yas}
\def\theoremautorefname{قضیۀ}
\newtheoremstyle{Plain}% vahid
{\topsep}% measure of space to leave above the theorem. E.g.: 3pt
{\topsep}% measure of space to leave below the theorem. E.g.: 3pt
{\itshape}% name of font to use in the body of the theorem
{\parindent}% measure of space to indent
{\bf}%name of head font
{.}% punctuation between head and body
{0.5em}% space after theorem head; " " = normal interword space
{}%Manually specify head
\theoremstyle{Plain}
%\theoremstyle{definition}
\newtheorem{definition}{تعریف}[chapter]
\newtheorem{theorem}{قضیه}[chapter]
\newtheorem{Lemma}[theorem]{لم}
\begin{document}
\chapter{فضاهای متریک}
\begin{theorem}\label{theorem}
\end{theorem}
\begin{equation}
A\in G_{n}\stackrel{\text{\SetBoolean{firstchoice@}{true}
\autoref{theorem}}}{\Longleftrightarrow}B\in G_{n}
\end{equation}
\end{document}
راهحل بلند
در این نمونه دستوری به نام \mytext تعریف شده که مشابه دستور \text کار میکنه اما مشکل اون رو نداره و فقط برای محیط ریاضی طراحی شده.
\documentclass{book}
\usepackage{amsmath,amssymb,amsthm,amsfonts}
\usepackage[colorlinks=true]{hyperref}
\usepackage{xepersian}
\settextfont[Scale=1]{Yas}
\setlatintextfont[Scale=.95]{Times New Roman}
\setdigitfont[Scale=1]{Yas}
\defpersianfont\chapfont[Scale=3.3]{Yas}
\makeatletter
\def\theoremautorefname{قضیۀ}
\newcommand*{\mytext}[1]{%
{\mathchoice{{\hbox{%
\everymath{\displaystyle}%
\let\f@size\f@size\selectfont%
#1}}}{{\hbox{%
\everymath{\textstyle}%
\let\f@size\f@size\selectfont%
#1}}}{{\hbox{%
\everymath{\textstyle}%
\let\f@size\sf@size\selectfont%
#1}}}{{\hbox{%
\everymath{\textstyle}%
\let\f@size\ssf@size\selectfont%
#1}}}%
\check@mathfonts
}%
}
\makeatother
\newtheoremstyle{Plain}% vahid
{\topsep}% measure of space to leave above the theorem. E.g.: 3pt
{\topsep}% measure of space to leave below the theorem. E.g.: 3pt
{\itshape}% name of font to use in the body of the theorem
{\parindent}% measure of space to indent
{\bf}%name of head font
{.}% punctuation between head and body
{0.5em}% space after theorem head; " " = normal interword space
{}%Manually specify head
\theoremstyle{Plain}
%\theoremstyle{definition}
\newtheorem{definition}{تعریف}[chapter]
\newtheorem{theorem}{قضیه}[chapter]
\newtheorem{Lemma}[theorem]{لم}
\begin{document}
\chapter{فضاهای متریک}
\begin{theorem}\label{theorem}
\end{theorem}
\begin{equation}
A\in G_{n}\stackrel{\mytext{\autoref{theorem}}}{\Longleftrightarrow}B\in G_{n}
\end{equation}
\end{document}
ویرایش
در نسخه پیشین بسته hyperref در فایل hxetex.def که تعریفات درایور زیتک برای لینکهاست دستور \Hy@EndAnnot بصورت
\def\Hy@EndAnnot{%
\ifnum\value{Hy@AnnotLevel}=\@ne
\Hy@endcolorlink
\@pdfm@mark{eann}%
\fi
\addtocounter{Hy@AnnotLevel}\m@ne
}
تعریف شده بود در صورتی که در حال حاضر تعریف این دستور به صورت
\def\Hy@EndAnnot{%
\ifnum\value{Hy@AnnotLevel}=\@ne
\Hy@endcolorlink
\@pdfm@mark{eann}%
\fi
\global\advance\c@Hy@AnnotLevel\m@ne
}
تغییر کرده. همونوطوری که از مقایسه تعریف دو دستور مشاهده میکنید
\global\advance\c@Hy@AnnotLevel\m@ne
جایگزین
\addtocounter{Hy@AnnotLevel}\m@ne
شده. هر دوی اینها معادل هم هستند اما با توجه به توضیحی که در بالا دادم این تغییر در بسته hyperref پیش اومده تا مشکلی که بهش اشاره کردم پیش نیاد. شما وقتی از بسته bidi استفاده میکنید تعریف قدیمی وجود داره و به همین خاطر به مشکل برمیخورید. بنابراین برای حل مشکل از پایه بهتره تعریف این دستور در بسته bidi بروز بشود.