# How To Fix Rendering of Persian Font With XeLaTeX?

I am trying to typeset a poem with XeLaTeX using the IranNastaliq font, and I am running into problems with the glyphs rendered for many words. I have a PDF file I rendered from the same source tex file several years ago that is free of these problems.

A minimal example is shown below:

%!TEX TS-program-xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{fontspec}
\newfontfamily\farsifont[Script=Arabic,Scale=10]{IranNastaliq}

\begin{document}
\farsifont
{\huge نگار}
\end{document}


This produces the image on the left on my current setup (MacTeX BasicTeX 2014). The image on the right, on the other hand, is what gets rendered in other programs, such as TextEdit, and what I had rendered in the past using XeLaTeX on an older computer (also OS X).

What could be causing this problem? How would I debug this?

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Symbol 1 Apr 12 '15 at 2:02
• I can reproduce the correct rendering on XeTeX 3.1415926-2.4-0.9998 (TeX Live 2012) and the incorrect rendering on XeTeX 3.14159265-2.6-0.99991 (TeX Live 2014). – syakhmi Apr 12 '15 at 2:18
• I can confirm: the output with TL 2013 is like in the picture on the right. The change seems due to the switch to the HarfBuzz library. – egreg Apr 12 '15 at 9:42

I filed a bug with HarfBuzz, and the lead developer explained that this font makes use of contextual swashes cswh, which are not enabled by default in OpenType. More can be read about this and other OpenType features as they apply to Arabic fonts here: https://www.microsoft.com/typography/OpenTypeDev/arabic/intro.htm.
\newfontfamily\farsifont[Script=Arabic,Scale=10,Contextuals=Swash]{IranNastaliq}