2

I am trying to use custom OpenType fonts (using LuaLaTeX and the fontspec package) in a LyX document under version control. The document is potentially accessed by others on different machines, so I decided to ship the .otf files in a subdirectory of the document's folder rather than relying on them being installed on the system. In other words, I just wanted to have the document in a compilable state as soon as it is checked out from version control without the need of installing the otf files.

This is how I wanted to add the fonts in the document's LaTeX Preamble:

\setmainfont{foo}[
    Path = mypath,
    UprightFont = foo-regular.otf,
    BoldFont = foo-bold.otf,
    ItalicFont = foo-it.otf,
    BoldItalicFont = foo-boldit.otf,
]

As long as mypath is an absolute path, everything works fine. As soon as I want to use a relative path here (because absolute paths don't make sense for files under version control) the fonts are not found any more.

Is there any solution to either (a) make a relative path work here or (b) somehow determine the absolute path of the current folder (not LyX's temporary folder where the document is actually compiled) and plug it in at mypath? Or is there any other obvious solution that I have overlooked?

  • did you try ./mypath ? – Elad Den Aug 8 '16 at 10:40
  • I did. Doesn't work. I think the problem is that LyX copies its files to a temporary directory for compiling them. But it doesn't know that it has to copy the font files there. So both path and ./mypath refer to said temporary directory, which does not contain the otf files (as LyX did not copy them there). – simon Aug 8 '16 at 11:42
  • This theme pops up quite regularly. Imho only the lyx developers can do something about it. It should be possible to add "required resources" to a lyx document which is copied along with other resources (it should be possible, after all graphics and bib seems to work). – Ulrike Fischer Aug 8 '16 at 14:13
  • 1
    Suggestions: 1) try adding prepending your paths with \input@path (in some appropriate way), which is defined by LyX to refer to the original directory; 2) open a bug report at lyx.org/trac/wiki/BugTrackerHome and request the feature of taking arbitrary file dependencies into account – G.M. Aug 10 '16 at 16:20
  • 1
    @G.M. You are my hero! \input@path does the trick, thanks a lot! Here is what works (supposing the otf files are in a subdirectory called "fonts" under the original directory): Setting Path = \input@path , and then setting UprightFont = fonts/foo-regular.otf, etc., surrounding everything with \makeatletter and \makeatother – simon Aug 10 '16 at 16:56
2

Here is how I could solve it (thanks to the help of G.M.). Suppose the otf files are in a subdirectory called "fonts" that lies under the directory that contains the main LyX file:

\setmainfont{foo}[
    Path           = \input@path,
    UprightFont    = fonts/foo-regular.otf,
    BoldFont       = fonts/foo-bold.otf,
    ItalicFont     = fonts/foo-it.otf,
    BoldItalicFont = fonts/foo-boldit.otf,
]

As G.M. explained, \input@path refers to the original directory (i.e. not the temporary directory where everything will be compiled).

Update: In my original solution, I had everything surrounded with \makeatletter and \makeatother. However, as G.M. also mentioned, LyX's LaTeX Preamble already provides this. So this is not necessary here and might indeed even cause trouble.

  • 1
    Note that the LyX preamble is already between \makeatletter and \makeatother. Calling \makeatother early may cause unrelated problems. – G.M. Aug 11 '16 at 10:34
  • @G.M. Thank you for pointing this out. I will update my answer accordingly. – simon Aug 11 '16 at 12:19

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.