Search code examples
latexpdflatexfarsixelatex

How to make babel correctly use special Persian Unicode characters?


I try to create a bilingual document in English with parts in Persian and want to use babel (please do not suggest using polyglossia instead, since I want to use a more complex document class and polyglossia seems to break it).

It works fine with pdflatex if I just use common Persian characters (this snippet compiles fine with pdflatex and displays correctly):

\documentclass{article}

\usepackage[LAE,LFE,T1]{fontenc}
\usepackage[farsi,english]{babel}

\begin{document}

\begin{otherlanguage}{farsi}
سلام
% خانوادهٔ من
\end{otherlanguage}

\end{document}

When I uncomment the second Persian line I get problems with pdflatex because of the Arabic Hamza.

! LaTeX Error: Unicode character ٔ (U+0654) not set up for use with LaTeX.

I also tried compiling with xelatex but have other problems with that. Although it compiles neither of the Persian lines is displayed and I get a bunch of warnings regarding the fonts:

LaTeX Font Warning: Font shape 'LAE/lmr/m/n' undefined using 'LAE/cmr/m/n' instead on input line 133.

Missing character: There is no خ ("62E) in font nazli!

(one warning for each character)

LaTeX Font Warning: Some font shapes were not available, defaults substituted.

The Nazli font is the default font for Persian/Arabic and shouldn't have a problem with the characters that I used.

I tried setting up different fonts with the \babelfont command when using xelatex but that did not yield different results.

Am I missing something?


Solution

  • I can reproduce the error with pdftex, but I’m not sure why it happens. With xetex, the setup is quite different:

    \documentclass{article}
    
    \usepackage[bidi=bidi, english]{babel}
    \babelprovide[import=fa]{farsi}
    \babelfont[farsi]{rm}{Nazli.ttf}
    
    \begin{document}
    
    \begin{otherlanguage}{farsi}
    سلام خانوادهٔ من
    \end{otherlanguage}
    
    \end{document}