In mydir/subdir, I have


invoking the below mylecture.sty:

\usefonttheme{professionalfonts} % using non standard fonts for beamer
\setbeamercolor{itemize item}{fg=myblue}
  Path           = ./ ,
  Extension      = .ttf ,
  UprightFont    = *-Regular ,
  BoldFont       = *-Bold ,
  ItalicFont     = *-Italic ,
  BoldItalicFont = *-BoldItalic

XeLaTeX says

! fontspec error: "font-not-found"
! The font "Alegreya-Regular" cannot be found.   

In lecture/mylecture, there are the various Alegreya ttf files which work when I have mylecture.sty and the ttf files copied to the current directory.

Does XeLaTeX look for the ttf files in mydir/subdir, reading the ./ path specification in \setmainfont, instead of lecture/mylecture, what I expected?

I just do not want to copy mylecture.sty and the ttf files into each dir where I want to write a new lecture slide series.

How can I have mylecture.sty and the ttf files in one dir and refer to it from anywhere in my git repository?

  • It's much easier to use the path mechanisms provided by your TeX distribution. So on my MacTeX system, I would install the font as a standard system font and put my style file in the appropriate place in my ~/localtexmf/latex tree. Can you do something similar? – Thruston Sep 19 '18 at 7:46
  • As hinted in my last sentence, I would like to use this in a git repository which I synchronise to various machines. I want this to be independent of the local TeX installation, – Gergely Sep 19 '18 at 7:50
  • You can still use the standard mechanisms: include your local copy in texinputs or use a symlink in your local texmf tree – Joseph Wright Sep 19 '18 at 8:18
  • Another idea: Alegreya should be distributed with TeX Live and MikTeX, so why not simply use a distro package (and then include the font without Path)? For me a OTF version is at texmf-dist/fonts/opentype/huerta/alegreya/Alegreya-Regular.otf – TeXnician Sep 19 '18 at 8:19
  • @TeXnician because I want this to be installation-independent. – Gergely Sep 19 '18 at 8:24

I have found various descriptions of this topic, especially

Load font from package directory using fontspec

It writes:

It is seldom senseful to distribute a font automatically along with a class or packages.

I do understand LaTeX's original philosophy on installing fonts on the local machine but my setup, having a git repository and using it on various machines is another take on how things should work. I would like to write lecture slides in different directories without copying style and font files, just referring to a common latex dir in the repository tree.

I use a Google Web Font. It is considered off-topic here:

How do I include google fonts?

but people do use such fonts.

My solution is now that after invoking my style file through a \usepackage command I include my \setmainfont command into my LaTeX file:

  Path           = ../../latex/mylecture/ ,
  Extension      = .ttf ,
  UprightFont    = *-Regular ,
  BoldFont       = *-Bold ,
  ItalicFont     = *-Italic ,
  BoldItalicFont = *-BoldItalic

So I need to copy this \setmainfont command only to my LaTeX files to make it work.

  • Just to place my comment at the right spot: The question you link to (about Google web font) is about a completely different topic, i.e. using an opentype font with pdflatex, not with Xe-/LuaLaTeX). – TeXnician Sep 19 '18 at 8:55

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.