Skip to content

Instantly share code, notes, and snippets.

@Bersam
Last active December 26, 2015 16:12
Show Gist options
  • Save Bersam/23eeaea5637a67f3f09b to your computer and use it in GitHub Desktop.
Save Bersam/23eeaea5637a67f3f09b to your computer and use it in GitHub Desktop.
Sample Tex File With Full Bidi Support (Including Numbers)
\documentclass{article}
\usepackage{xepersian}
\makeatletter
% classes 1-3 are used in unicode-letters.tex, so we'll put the Latin letters in 4
\newcount\xp@n
\xp@n=`\A \loop \XeTeXcharclass \xp@n=4 \ifnum\xp@n<`\Z \advance\xp@n by 1 \repeat
\xp@n=`\a \loop \XeTeXcharclass \xp@n=4 \ifnum\xp@n<`\z \advance\xp@n by 1 \repeat
% this line would put Latin numbers in 4 class too.
\xp@n=`\0 \loop \XeTeXcharclass \xp@n=4 \ifnum\xp@n<`\9 \advance\xp@n by 1 \repeat
% when we encounter class 4, we'll do \startlatin
\XeTeXinterchartoks 0 4 {\startlatin}
\XeTeXinterchartoks 255 4 {\startlatin}
% and when we encounter class 0, we'll do \finishlatin
\XeTeXinterchartoks 255 0 {\finishlatin}
\XeTeXinterchartoks 4 0 {\finishlatin}
\newcommand{\startlatin}{\if@Latin\else\bgroup\beginL\latinfont\@Latintrue\fi}
\newcommand{\finishlatin}{\if@Latin\unskip\endL\egroup{ }\fi}
\makeatother
\XeTeXinterchartokenstate=1
\begin{document}
این یک آزمایش است
One Two Three
و ادامه آن
\end{document}
@Bersam
Copy link
Author

Bersam commented Dec 26, 2015

Original snippet are from this stackexchange answer:

http://tex.stackexchange.com/a/54325

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment