2

In mydir/subdir, I have

\usepackage{../../latex/lecture/mylecture}

invoking the below mylecture.sty:

\usepackage{fontspec}
\usefonttheme{professionalfonts} % using non standard fonts for beamer
\usefonttheme{serif}
\definecolor{paleyellow}{RGB}{255,255,221}
\definecolor{myblue}{RGB}{0,0,144}
\setbeamercolor{frametitle}{fg=myblue}
\setbeamercolor{itemize item}{fg=myblue}
\setbeamercolor{title}{fg=myblue}
\setmainfont[
  Path           = ./ ,
  Extension      = .ttf ,
  UprightFont    = *-Regular ,
  BoldFont       = *-Bold ,
  ItalicFont     = *-Italic ,
  BoldItalicFont = *-BoldItalic
]{Alegreya}

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?

TeXnician
  • 33,589
Gergely
  • 1,065
  • 1
  • 8
  • 17
  • 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 07: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 07: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 08: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 08:19
  • @TeXnician because I want this to be installation-independent. – Gergely Sep 19 '18 at 08:24
  • But as you require packages like fontspec either way, why not simply add this to the "required" packages? Otherwise, I would suggest to follow Joseph's instructions. – TeXnician Sep 19 '18 at 08:39
  • @TeXnician as far as I understand, TEXINPUTS is an environment variable and I want to control this from the .tex file, and a symlink fits uneasy with a git repository – Gergely Sep 19 '18 at 08:43
  • I wrote my solution in an answer but moderators deleted it. – Gergely Sep 19 '18 at 08:44
  • @Gergely Just my view on what works with Git (I do use it that way): Use a build file (whatever system you prefer, Bash/Batch/…) and simply adjust the environment variables or add a local texmf tree before running. – TeXnician Sep 19 '18 at 08:52

1 Answers1

3

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:

\usepackage{../../latex/mylecture/mylecture}
\setmainfont[
  Path           = ../../latex/mylecture/ ,
  Extension      = .ttf ,
  UprightFont    = *-Regular ,
  BoldFont       = *-Bold ,
  ItalicFont     = *-Italic ,
  BoldItalicFont = *-BoldItalic
]{Alegreya}

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

Gergely
  • 1,065
  • 1
  • 8
  • 17
  • 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 08:55