برای تعریف محیط مثال، از کد زیر استفاده کردم. حال مشکل اینجاست که موقع ارجاع به مثال، شماره آخرین بخش را به جای شماره مثال درج میکند.
\newcounter{mycounter}
\numberwithin{mycounter}{chapter}
\makeatletter
\newenvironment{example}
{\par\noindent\examplehang\par\nobreak\noindent
{\setRTL\hboxR{\refstepcounter{mycounter}\postdisplaypenalty=10000 %
{\bfseries\upshape{\color{magenta}{\themycounter~~\bfseries{مثال}}}}\ \ignorespaces}}} %\examplename
{\par\nobreak\noindent\examplehung\par\addvspace{\topsep}}
