5

I'm trying to add Persian text to my document, however, my favorite fonts (which already have been installed on Windows 10 and I use them on Microsoft Word) can not be identified.

! fontspec error: "font-not-found"!! The font "XB Niloofar" cannot be found.!!
! fontspec error: "font-not-found"!! The font "Yas" cannot be found.!!
! fontspec error: "font-not-found"!! The font "IranNastaliq" cannot be found.!!

Here is the document I'm trying to compile:

‎\documentclass[11pt]{exam}‎
‎\usepackage{xepersian}‎

‎\settextfont[Scale=1]‎{XB Niloofar}‎
‎\setdigitfont[Scale=1]{Yas}‎
‎\setlatintextfont[Scale=0.9]{Times New Roman}‎
\defpersianfont\nastaliq[Scale=1]{IranNastaliq}‎

‎\begin{document}‎ 
\textbf{سلام}‎
‎\end{document}‎
Vahid
  • 109
  • If you have any local font caches in your %HOMEDRIVE%%HOMEPATH%\.texlive2019\texmf-var\, delete them. They might be hiding system fonts. – Davislor May 29 '19 at 06:12
  • 1
    I did it but it still gives the same error – Vahid May 29 '19 at 06:22
  • 1
    You might also check the family names of the fonts with otfinfo -i, or try loading them by filename, which should always work. – Davislor May 29 '19 at 06:22
  • 1
    Would you please let me know how I can check it? – Vahid May 29 '19 at 06:31
  • Try if the fonts are found if you don't use xepersian but only fontspec. (Only as a test, it doesn't need to give senseful output). – Ulrike Fischer May 29 '19 at 06:31
  • 4
    If you open up a command (Win-R, CMD), you can DIR "C:\Windows\Fonts\XB*" and you should see the filename, e.g. C:\Windows\Fonts\CB Niloofar.ttf. If it's not there, it might have been installed for you only.. – Davislor May 29 '19 at 06:34
  • When you have the filename, otfinfo -i "C:\Windows\Fonts\XB Niloofar.ttf". – Davislor May 29 '19 at 06:34
  • @UlrikeFischer: I got this error: !Undefined control sequence. \settextfont – Vahid May 29 '19 at 06:47
  • Use \setmainfont instead. – Ulrike Fischer May 29 '19 at 06:47
  • @Davislor: I tried DIR "C:\Windows\Fonts\XB*" and I got Volume in drive C is OS - Volume Serial Number is 04D2-B7D3- Directory of C:\Windows\Fonts - File Not Found. How can I fix it? – Vahid May 29 '19 at 07:07
  • 2
    It sounds like what probably happened is that you installed the fonts for yourself, instead of for all users. Extract the font files you downloaded into a temporary folder, select them, right-click, and select "Install for all users." – Davislor May 29 '19 at 07:10
  • @Davislor: Thank you so much, I can fix it. However, my problem has been solved only by your below answer: \settextfont[Scale = 1.0 , BoldFont = *Bd , ItalicFont = *It , BoldItalicFont = *BdIt , Extension = .ttf ]{XB Niloofar}. Would you please let me know how I can fix it with \settextfont[Scale=1]‎{XB Niloofar}‎? – Vahid May 29 '19 at 07:19
  • That form of the command is deprecated. It’s always been inconsistent what works and what doesn’t between XeTeX and LuaTeX and between Windows and Linux. However, if you use the family name returned by otfinfo -i, it theoretically should work. – Davislor May 29 '19 at 07:21
  • \settextfont[Scale=1]{XB Niloofar} in a current texlive 2019 works fine for me on windows. But you should really check if it works with fontspec alone. Your error message looks unusual and xepersian changes some fontspec internals. – Ulrike Fischer May 29 '19 at 07:33
  • The heavy-duty approach to make that syntax work is to create a file named XB Niloofar.fontspec with the correct options for your installation. That should let you work around just about any problem without changing your source. – Davislor May 29 '19 at 07:43

1 Answers1

1

The recommended way to load fonts in fontspec is by filename. You can try:

\settextfont[Scale = 1.0 ,
             BoldFont = *Bd ,
             ItalicFont = *It ,
             BoldItalicFont = *BdIt ,
             Extension = .ttf
            ]{XB Niloofar} 

If your fonts are named XB Niloofar.ttf, XB NiloofarBd.ttf, etc.

If that still doesn’t work, see if \setmainfont with the same options does. This is probably not what you want, but it can confirm that the issue is or is not with fontspec.

You can run fc-match "XB Niloofar" to see if XeTeX can find the font and luaotfload-tool --find "XB Niloofar" to see if LuaTeX can.

Also make sure the fonts are installed for all users, in the %WINDIR%\Fonts\ directory. Separately, if you have any local font caches in %HOMEDRIVE%%HOMEPATH%\.texlive2019\texmf-var\, delete them.

Davislor
  • 44,045
  • Unfortunately, it does not work. – Vahid May 29 '19 at 06:44
  • Okay, can either fc-match or luaotfload-tool --find find it? – Davislor May 29 '19 at 06:45
  • Well done! Thanks. – Vahid May 29 '19 at 07:20
  • @Davislor: I have same problem after installing TeXlive 2021 but that was fine in my previous TeXlive 2019. I opened %WINDIR%\Fonts folder but I couldn't find all fonts that I installed recently there but that fonts are listed in the control panel font folder. What's the wrong? – C.F.G May 09 '21 at 19:16
  • 1
    @C.F.G TeX Live can’t find fonts that you installed to your user account. Those go into a hidden directory in your user folder. You must install them either for all users, as an administrator, or to a folder in the local TeX tree (normally C:\texlive\texmf-local, but kpsewhich --var-value=TEXMFLOCAL is the way to look it up), or to a subfolder of your user TeX tree (normally %USERPROFILE%\texmf, but kpsewhich --var-value=TEXMFHOME is the way to look it up.) – Davislor May 09 '21 at 21:55
  • 1
    @C.F.G Normally, you would install .otf, .ttf and .otc files for all users.. Delete the copies you have in your Fonts Control Panel, select the files you downloaded, right-click, and Install for All Users. – Davislor May 09 '21 at 21:59
  • @C.F.G Install to a subdirectory of TEXMFLOCAL (such as C:\texlive\texmf-local\fonts\opentype) if you only use a font for TeX and don’t want it cluttering up your font menus. All legacy Type-1 or METAFONT fonts must also go in this tree. – Davislor May 09 '21 at 22:03
  • @C.F.G Put them in TEXMFHOME if you are on a shared computer and want to install files for your own account only, or you are not an administrator. – Davislor May 09 '21 at 22:04
  • @C.F.G Finally, put the fonts in your project directory, or in a subfolder that you call with Path=./fonts/, if you are going to archive a copy of that specific version of that specific font with that specific project, so you will never have to try to figure out which old version of the font your document needs, twenty years from now. – Davislor May 09 '21 at 22:07