# Relative Path to Font in Luatex

I have the very same problem as described by someone once here, but not in a Lyx-Context, because of which the solution shown there seems not to work. Consider the following setup:

And in texfile I use some fonts from local font files:

\setmainfont[
Path          = fonts/,
Ligatures     = TeX,
UprightFont   = Calibri.ttf,
BoldItalicFont= Calibri_Bold_Italic.ttf,
BoldFont      = Calibri_Bold.ttf,
ItalicFont    = Calibri_Italic.ttf
]{Calibri}
\newfontfamily[
Path          = fonts/,
Ligatures     = TeX,
UprightFont   = Calibri_Light.ttf,
ItalicFont    = Calibri_Light_Italic.ttf
]{Calibri_Light}


File structure is

/texfolder
|
--texfile.tex
--/fonts
|
--Calibri.ttf
--...etc


I render it with the following command (bash):

 lualatex "\input{/texfolder/texfile.tex}"


That works if the command above is called from the folder from the texfolder. But if I call it from somewhere else, it fails on finding the fonts files, since the lualatex compiler searches for it in the folder from where it is called, not where the tex files lies. I can not write the absolute path in the tex-file because this is part of a program package and where it lies in the file system depends to the user.

What can I do?

• is there any chance to use \input@path in this context or an equivalent?
• or: is there a way to tell the lualatex command which working directory it has to use?
• or: Can I use somehow a variable for the path (instead of a relative path like fonts/) and provide this in the command?

Edit 1:

Following some suggestions of @Ulrike Fischer i tried the following:

\usepackage[abspath]{currfile}
\message{path is \currfileabsdir}
\setmainfont[
Path          = \currfileabsdir,
Ligatures     = TeX,
UprightFont   = calibri/Calibri.ttf,
BoldItalicFont= calibri/Calibri_Bold_Italic.ttf,
BoldFont      = calibri/Calibri_Bold.ttf,
ItalicFont    = calibri/Calibri_Italic.ttf
]{Calibri}
\newfontfamily[
Path          = \currfileabsdir,
Ligatures     = TeX,
UprightFont   = calibri/Calibri_Light.ttf,
ItalicFont    = calibri/Calibri_Light_Italic.ttf
]{Calibri_Light}


And run the command with -recorder. That seems to be the right trace, but still does not work. I get the following error, of which I have no idea what it could mean:

luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: "Font P not found.".

• About a month ago, I searched all over the Internet (and, of course, here) for that precise siuation. However, I did not find any solution. As I recall, there is a way to do it by calling a shell script from within TeX, but not everyone can do that. – user103221 Mar 8 '17 at 15:17
• If you call lualatex this way it should be too difficult to change the call to lualatex \def\pathprefix{..}\input{..} and then use \pathprefix in your settings. It is also possible to get the current path see e.g. tex.stackexchange.com/a/232413/2388 or tex.stackexchange.com/a/228928/2388. – Ulrike Fischer Mar 8 '17 at 15:56
• Hi @Ulrike Fischer I followed some of the suggestions you linked me, thank you for that. Still I did not manage it. Please have a look on my actualized question. – Paflow Mar 8 '17 at 16:39

Thanks to the hints of @Ulrike Fischer, I could solve this:

\usepackage{fontspec}
\usepackage[abspath]{currfile}
\usepackage[english]{babel}
\setmainfont[
Path          = \currfileabsdir,
Ligatures     = TeX,
UprightFont   = calibri/Calibri.ttf,
BoldItalicFont= calibri/Calibri_Bold_Italic.ttf,
BoldFont      = calibri/Calibri_Bold.ttf,
ItalicFont    = calibri/Calibri_Italic.ttf
]{Calibri}
\newfontfamily\CalibriLight[
Path          = \currfileabsdir,
Ligatures     = TeX,
UprightFont   = calibri/Calibri_Light.ttf,
ItalicFont    = calibri/Calibri_Light_Italic.ttf
]{Calibri_Light}


And run the command with -recorder. At first I made the mistake not providing a proper name for newfontfamily.

• Ah, yes that works... but the current file absolute directory is that of the master TeX document. The more general case, where an included file measures relative to itself, does not seem to work. – user103221 Mar 8 '17 at 18:28
• Fortunately I only have one tex-file. In other case, I would expect that you can store the currfileabsdir in a variable in the main file and then use that variable in the descendant files. – Paflow Mar 9 '17 at 9:19
• Yes, you can do that, but... If there are some files drawn from the TeX installation, and some drawn from a user directory (texmf-home) which is portable, then there can be confusion. However, this situation is very exotic. It is more of a "what-if" situation. – user103221 Mar 9 '17 at 15:41