# Fontspec not searching in TEXINPUTS

I'm writing an application in which I want to generate pdf file using xelatex. The process of generating the pdf file from tex file takes place in a tmp file however data files such as fonts and images are stored in a folder. To avoid writing the folder address in tex file I added this folder to my TEXINPUTS. Now tex can find the images in this folder but when I use a font which is inside this folder it's unable to find it. I'm using xepersian which uses fontspec. I tried using fontspec directly but it failed as well. Here is a document I tried to compile for test:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{XB Zar2}
\begin{document}\end{document}


There is a ttf file named XB Zar2 inside a folder named Zar in the current directory. So I used:

export TEXINPUTS=./Zar//:


May someone tell me how to handle this? Thank you.

• Fonts for fontspec are looked for in OPENTYPEFONTS and TTFONTS, not in TEXINPUTS – egreg Jan 25 '15 at 16:02
• Why not post it as an answer? May you tell me what each of them is for? I mean what is their difference? – Matrix Jan 25 '15 at 16:31
• It seems OPENTYPEFONTS is not working for me. However TTFONTS works and it seems it works for both opentype fonts and truetype fonts. Isn't there a more global variable? One that covers TEXINPUTS and TTFONTS both? – Matrix Jan 25 '15 at 16:40

Fonts for fontspec are looked for using the OPENTYPEFONTS and TTFONTS variables. The setting in texmf.cnf is

% TrueType outline fonts.
TTFONTS = .;$TEXMF/fonts/{truetype,opentype}//;$OSFONTDIR//

% OpenType outline fonts.
OPENTYPEFONTS = .;$TEXMF/fonts/{opentype,truetype}//;$OSFONTDIR//


The difference between the two variables is evident. The variable OSFONTDIR shouldn't need being set.

If you have your personal files in, say

~/personalfilesandfonts/


then you should set

export TEXINPUTS=~/personalfilesandfonts//:
export TTFONTS=~/personalfilesandfonts//:
export OPENTYPEFONTS=~/personalfilesandfonts//:


There's no way for setting a “catch all” variable, because the three are used for very different purposes.

If the files are in a subdirectory of the current directory, as in your example, use

export TEXINPUTS=./Zar//:
export TTFONTS=./Zar//:
export OPENTYPEFONTS=./Zar//: