I need to resolve absolute path to fonts:

    Path          = \currfileabsdir,
    UprightFont   = fonts/HGS_Mincho/HGRMB.ttc,
    BoldFont      = fonts/HGS_Mincho/HGRME.ttc
]{HGS Mincho}

The solution \usepackage[abspath]{currfile} requires -recorder option, but I don't use console, and setup -recorder option is potentially unnecessary routine.

Other solution based on lfs library, but if we just use it as shown below, error will occur (at least, in Windows):

! Undefined control sequence.
l.1 C:\Users
l.6 ...sdir{\directlua{tex.sprint(lfs.currentdir())}

It was recommended to use catcodes as shown below:

\edef\currfileabsdir{\directlua{tex.sprint(-2, lfs.currentdir())}/}

What really will be is backslashes will be removed from absolute path, so


becomes to


How I get correct absolute path to font?

Update: MWE with first suggested solution

\documentclass[a4paper, twoside]{ltjsarticle}


\edef\currfileabsdir{\directlua{tex.sprint(\the\catcodetable@string, lfs.currentdir())}/}

    Path          = \currfileabsdir,
    UprightFont   = fonts/HGS_Mincho/HGRMB.ttc,
    BoldFont      = fonts/HGS_Mincho/HGRME.ttc
]{HGS Mincho}

    Path          = \currfileabsdir,
    UprightFont   = fonts/HGS_Gothic/HGRGM.ttc,
    BoldFont      = fonts/HGS_Gothic/HGRGE.ttc,
]{HGS Gothic}

  日本語文字  Latin letters Кириллица


luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: "File not found: C:UsersiDocumentsTeXLuaLaTeX_Development/fonts/HGS_Mincho/HGRMB.ttc.".

! fontspec error: "font-not-found"
! The font "fonts/HGS_Mincho/HGRMB.ttc" cannot be found.
! See the fontspec documentation for further information.
! For immediate help type H <return>.

l.13 ]{HGS Mincho}

enter image description here


Your code fails as the backslash used on windows in the path is in lua also the escape char. As the path is passed on to the lua backend one need to escape the backslash with another backslash. You can use \luaescapestring for this.


Or if you want to use \currfileabsdir also in other places, add the \luaescapestring to the Path:

   Path          = \luaescapestring{\currfileabsdir},
| improve this answer | |
  • There must be something else wrong with OP's code, which they haven't told us. Catcode table -2 is hardcoded: github.com/TeX-Live/luatex/blob/… – Henri Menke Apr 1 '19 at 9:01
  • @HenriMenke yes I guess too. That's why I showed a complete example ... – Ulrike Fischer Apr 1 '19 at 9:43
  • @UlrikeFischer, Thank you for the answer. Unfortunately, nothing changed. I added MWE with your solution in question filed. Please, take a look. – Gurebu Bokofu Apr 1 '19 at 10:48
  • Add \show\currfileabsdir directly after the \makeatother, compile, (hit enter when it stops at the \show) and then show the log-file. – Ulrike Fischer Apr 1 '19 at 10:54
  • I edited the answer. – Ulrike Fischer Apr 1 '19 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.