6

I use XeLaTeX and XePersian to write Persian documents. Unfortunately, some frequently used fonts in Persian does support important characters like ی so I should replace them with Arabic counterparts like ي to get the expected result. Some others support it, so I should revert the changes.

I can not replace every single character of ی with ي, because in this way, my Persian macros and localised XePersian commands will fail, and if I do this manually, with a change of font I will have to do this again. For sure this can be fixed in the font-level, but I can not edit the font. :-/

My question is that is it possible to replace ی by ي in macro level?

I tried this, but it didn't work:

\documentclass[14pt,a4paper]{article}
\usepackage[localised]{xepersian}
\settextfont{Arial}

\defی{ي}

\begin{document}
می‌شود.

% added to show the problem with the localised commands
% even without it, it won't compile when placing replace commands
%before including xepersian
\سطرجدید %it means new line
\newline

\end{document}

2 Answers 2

5

Not essentially different from Tobi's answer, but the substitution is more robust.

\documentclass[a4paper]{article}
\usepackage{xepersian}
\usepackage{newunicodechar}
\settextfont{Arial}

\newunicodechar{ی}{ي}

\begin{document}
می‌شود.
\end{document}

(The thing appears to be reversed, I can't understand what the editor does when Arabic is involved.)

enter image description here

4
  • Thanks for the answer. But, both answers does not compile for my file (with extra contents), because we have localised commands like \آماده‌سازی in XePersian and several others involved. I'm changing my MWE to include this fact. Maybe this is essentailly impossible, because of Macro nature of TeX?
    – Ho1
    Commented Sep 30, 2015 at 18:20
  • @Hol: You could define a suitable mapping file. Search for teckit. Commented Sep 30, 2015 at 18:29
  • @UlrikeFischer Maybe I should forget localised commands. :-/
    – Ho1
    Commented Sep 30, 2015 at 18:31
  • @egreg Thanks for the answer, but it didn't work for me because of the localised macros. I edited the font and fixed it, and it was not as hard as I thought. :-)
    – Ho1
    Commented Oct 7, 2015 at 13:06
4

You can make the character that is written an active character by use of \catcode and then define it to be the other character:

\documentclass[14pt,a4paper]{article}
\usepackage{xepersian}
\settextfont{Arial Unicode MS}

\catcode`\ی=\active
\def ی{ي}

\begin{document}
می‌شود.
\end{document}

(I had to change the font on my system)

2
  • This seems to work, but I’m not sure if this has any drawbacks regarding ligature and such …
    – Tobi
    Commented Sep 30, 2015 at 17:57
  • 1
    \newunicodechar (of the newunicodechar package) does this in a more robust way.
    – egreg
    Commented Sep 30, 2015 at 18:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .