این پرسش در اینجا پاسخ داده شده است اما خیلی قدیمی است و با نسخه فعلی بستهها کار نمیکند. هدف از این پاسخ بروزرسانی پاسخ است.
بروزرسانی کد نخست
\documentclass{article}
\usepackage{color}
\usepackage{lipsum}
\usepackage{ptext}
\usepackage{xepersian}
\settextfont{Yas}
\makeatletter
\newcount\WordCount
\newXeTeXintercharclass\MyComma
\XeTeXcharclass`\،\MyComma
\XeTeXcharclass`\,\MyComma
\XeTeXinterchartoks \z@ 4095 = {\PrintWordCount}
\XeTeXinterchartoks \z@ \MyComma = {\PrintWordCount}
\XeTeXinterchartoks \z@ \bidi@sepmark@charclass = {\PrintWordCount}
\newcommand*{\PrintWordCount}{\raise.8\baselineskip\llap{\tiny\global\advance\WordCount\@ne\textcolor{red}{\the\WordCount}}}
\makeatother
\begin{document}
\ptext
\begin{latin}
\lipsum
\end{latin}
\end{document}
بروزرسانی کد دوم
\documentclass{article}
\usepackage{lipsum}
\usepackage{ptext}
\usepackage{xepersian}
\settextfont{Yas}
\makeatletter
\newcount\WordCount
\newXeTeXintercharclass\MyPunctuations
\XeTeXcharclass`\{\MyPunctuations
\XeTeXcharclass`\}\MyPunctuations
\XeTeXcharclass`\[\MyPunctuations
\XeTeXcharclass`\]\MyPunctuations
\XeTeXcharclass`\(\MyPunctuations
\XeTeXcharclass`\)\MyPunctuations
\XeTeXcharclass`\`\MyPunctuations
\XeTeXcharclass`\'\MyPunctuations
\XeTeXcharclass`\!\MyPunctuations
\XeTeXcharclass`\:\MyPunctuations
\XeTeXcharclass`\;\MyPunctuations
\XeTeXcharclass`\?\MyPunctuations
\XeTeXcharclass`\؟\MyPunctuations
\XeTeXcharclass`\«\MyPunctuations
\XeTeXcharclass`\»\MyPunctuations
\XeTeXcharclass`\،\MyPunctuations
\XeTeXcharclass`\,\MyPunctuations
\XeTeXinterchartoks \z@ 4095 = {\AddTo@WordCount}
\XeTeXinterchartoks \z@ \MyPunctuations = {\AddTo@WordCount}
\XeTeXinterchartoks \z@ \bidi@sepmark@charclass = {\AddTo@WordCount}
\newcommand*{\AddTo@WordCount}{\global\advance\WordCount\@ne}
\newcommand*{\PrintWordCount}{\textbf{??}}
\newcommand*{\@PrintWordCount}[1]{\gdef\PrintWordCount{#1}}
\AtEndDocument{%
\protected@write\@auxout{}{\string\@PrintWordCount{\the\WordCount}}}
\makeatother
\begin{document}
\fbox{%
این نوشتار دارای
\PrintWordCount{}
کلمه
میباشد.%
}
\ptext
\begin{latin}
\lipsum
\end{latin}
\end{document}