This is a XeLaTeX question. It seems really silly to ask after many years of using fontspec
and XeLaTeX. I suppose I have always found a workaround. This time, I'd like a definitive answer.
Situation
A server (compiler/build system) is running in the background, generating documents (among other operations) from version control repositories around the clock. Documents are edited on several clients by humans. It cannot be assumed that the system fonts are the same on any of machines. There are two things that are the the same on all machines (or at least should be):
1. the TeX Live version/MikTeX. 2. The repository files. This implies that any fonts I load should either be in:
- TeX Live build-in Fonts (assuming same as MikTeX)
- Fonts files in the repository
NOT system fonts as listed by fc-list -f "%{family}\n" | sort -u
on unix-based machines.
Loading Fonts with fontspec
In fontspec, fonts are loaded several ways:
- File name with extension
e.g.
\setmainfont{texgyrepagella-regular.otf}
\let\texgyrepagellaregular\normalfont % create semantically relevant macro (name+font) to be consistent with other \newfontfamily macros
- Filename without extension but with path construction expressions given as parameters:
e.g.
\setmainfont{texgyrepagella}[
Path = /Users/will/Fonts/ ,
UprightFont = *-regular ,
BoldFont = *-bold ,]
I'd like to avoid loading fonts by typing /usr/local/texlive/<YEAR>/
[…] because they may not be located in the same location.
Attempt
\documentclass{article}
\usepackage{fontspec}
\setmonofont{Inconsolata}
\newcommand\escapedlog[1]{\par\ttfamily #1\par}
\begin{document}
Keep it simple.
\escapedlog{Hello}
\end{document}
Log Output (error)
I think I know what is happening here. fontspec
is checking the list of system fonts only fc-list -f "%{family}\n" | sort -u
.
kpathsea: Running mktextfm inconsolata
mktextfm: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input inconsolata
This is METAFONT, Version 2.7182818 (TeX Live 2015) (preloaded base=mf)
kpathsea: Running mktexmf inconsolata
! I can't find file `inconsolata'.
<*> ...our; mag:=1; nonstopmode; input inconsolata
Please type another input file name
! Emergency stop.
<*> ...our; mag:=1; nonstopmode; input inconsolata
Transcript written on mfput.log.
grep: inconsolata.log: No such file or directory
mktextfm: `mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input inconsolata' failed to make inconsolata.tfm.
kpathsea: Appending font creation commands to missfont.log.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
!
! The font "inconsolata" cannot be found.
!
! See the fontspec documentation for further information.
!
! For immediate help type H <return>.
!...............................................
l.3 \setmonofont{inconsolata}
?
Traditional Packages
According to this list, I should have that font installed.
Best Answer
You don't need to give an explicit path, so long as the font is in a directory searched by XeTeX. The relevant (pseudo)environment variables are
A user can set in the environment the variable
OSFONTDIR
, but settingOPENTYPEFONTS
andTTFFONTS
is a task performed by thekpse
library, whichxetex
is linked to, so the user does not need to set them: they're automatically set as soon asxetex
is started.Depending on the operating system, you can make the system aware of the fonts in the current TeX distribution. As described in the installation guide of TeX Live, on most GNU/Linux systems you can run
with superuser privileges (
sudo
or similar) and the TeX Live OpenType and TrueType fonts will be available to the OS.The first command should be loaded after the yearly TeX Live release, the second one should be run when updates or new fonts are installed with
tlmgr
. I do it on my GNU/Linux boxes.Here's an example, where the
\testpath
family is only defined for crosschecking that the\testkpse
suffices.Running this example with
will show the following information on the terminal
that shows the correct font is picked up in each case.