8

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:

  1. TeX Live build-in Fonts (assuming same as MikTeX)
  2. 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:

  1. 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
  1. 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.

What font packages are installed in TeX live?

5
  • Why do you always write such long questions? It is rather a pain to read them and to figure out what you want. On Linux system you need to add the texlive folders to fontconfig if you want to call fonts by name. See tug.org/texlive/doc/texlive-en/texlive-en.html#x1-340003.4.4 and tex.stackexchange.com/questions/257231/… Jun 9, 2016 at 9:28
  • 7
    @UlrikeFischer That's not very nice. Unlike many, I take time to explain my questions thoroughly and provide useful references, code examples, and related questions etc. It is more often the case that not enough information has been provided (often an afterthought). It also helps to weed out obvious answers. Jun 9, 2016 at 9:34
  • Which means that you are expecting that we take much time to read you question and follow all the references etc. The time I spent on your question is taken from the time I need for my work and from the time I can spent for the question of other peoples. To short questions are bad, but too long questions too. There is no need to write down all your research history. Jun 9, 2016 at 9:49
  • 6
    @UlrikeFischer See meta.stackexchange.com/help/how-to-ask which states "Sharing your research helps everyone. Tell us what you found and why it didn’t meet your needs.[...] If you ask a vague question, you’ll get a vague answer. But if you give us details and context, we can provide a useful answer." I am sorry to burden you, but I think you should observe the bigger picture. More people read this than you, which is why I group related information under headings so readers can easily seek headings. I did read the best practices policy on stackexchange awhile ago. Jun 9, 2016 at 10:05
  • 1
    You are not putting any burden on me. I can always ignore your question. But as it is it is completly unclear if your question is about a problem with the specific inconsolata (which can be solved by using the correct name Inconsolatazi4) or generally with calling fonts by name in texlive/linux (which can be solved by correcting the fontconfig configuration or by using file names instead of font names). Jun 9, 2016 at 11:06

2 Answers 2

6

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

% TrueType outline fonts.
TTFONTS = .;$TEXMF/fonts/{truetype,opentype}//;$OSFONTDIR//

% OpenType outline fonts.
OPENTYPEFONTS = .;$TEXMF/fonts/{opentype,truetype}//;$OSFONTDIR//

A user can set in the environment the variable OSFONTDIR, but setting OPENTYPEFONTS and TTFFONTS is a task performed by the kpse library, which xetex is linked to, so the user does not need to set them: they're automatically set as soon as xetex 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

cp $(kpsewhich -var-value TEXMFSYSVAR)/fonts/conf/texlive-fontconfig.conf /etc/fonts/conf.d/09-texlive.conf
fc-cache -fsv

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.

\documentclass{article}
\usepackage{fontspec}

\newfontfamily{\testkpse}{Inconsolatazi4}[
  Extension=.otf,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
]

\newfontfamily{\testpath}{Inconsolatazi4}[
  Extension=.otf,
  Path=/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
]

\newfontfamily{\testfc}{Inconsolatazi4}

\begin{document}
\pagestyle{empty}

{\testkpse Inconsolata \bfseries Bold}

{\testpath Inconsolata \bfseries Bold}

{\testfc Inconsolata \bfseries Bold}

\end{document}

Running this example with

xelatex -output-driver="xdvipdfmx -vv" test

will show the following information on the terminal

<FONTMAP:/usr/local/texlive/2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map><FONTMAP:/usr/local/texlive/2016/texmf-var/fonts/map/dvipdfmx/updmap/kanjix.map><FONTMAP:/usr/local/texlive/2016/texmf-dist/fonts/map/dvipdfmx/ckx.map>No dvi filename specified, reading standard input.
stdin -> incons.pdf
DVI Comment:  XeTeX output 2016.06.09:1437
<AGL:texglyphlist.txt><AGL:pdfglyphlist.txt><AGL:glyphlist.txt>[1</usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]<NATIVE-FONTMAP:/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf/0/H/65536/0/0>
pdf_font>> Input encoding "Identity-H" requires at least 2 bytes.
pdf_font>> The -m <00> option will be assumed for "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf".
(CID:Inconsolatazi4-Regular)
pdf_font>> Type0 font "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf" cmap_id=<Identity-H,0> opened at font_id=</usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf/0/H/65536/0/0,0>.
></usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4[email protected]<NATIVE-FONTMAP:/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf/0/H/65536/0/0>
pdf_font>> Input encoding "Identity-H" requires at least 2 bytes.
pdf_font>> The -m <00> option will be assumed for "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf".
(CID:Inconsolatazi4-Bold)
pdf_font>> Type0 font "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf" cmap_id=<Identity-H,0> opened at font_id=</usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf/0/H/65536/0/0,1>.
></usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]></usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]></usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]></usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]>]
otf_cmap>> Creating ToUnicode CMap for "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf"...

otf_cmap>> Creating ToUnicode CMap for "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf"...
(CID:/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf[CIDFontType0])(CID:/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf[CIDFontType0])

that shows the correct font is picked up in each case.

enter image description here

2
  • Most useful thing so far is: xetex + xelatex use kpsewhich, which is the reason why fontspec finds TeX Live fonts with the full name. Thanks for this helpful answer too, demonstrating the various path variables available. Side note: The most important thing for me is making compilation work across operating systems without modifying the original TeX Live install or global environment variables (as a general rule for maintenance costs). I need to keep all variables contained within their associated processes (as to not accidentally have overlaps with other build system functions). Jun 10, 2016 at 9:13
  • @macmadness86 Perhaps I was not clear: you don't need to set the variables OPENTYPEFONTS and TTFFONTS. They're automatically set when xetex is started.
    – egreg
    Jun 10, 2016 at 9:18
2

Use

 \setmonofont{Inconsolatazi4}

or

 \setmonofont[
   BoldFont=Inconsolatazi4-Bold.otf]{Inconsolatazi4-Regular.otf}

By default fontconfig, which is used by xetex/xelatex for searching font files do not scan the TeX font directories. But xetex/xelatex use kpsewhich, the reason why it will find fonts with the full name. One can put these files into the systems font directoty or extend the search path for fontconfig. Then one can use the symbolic name.

7
  • 1
    Yields same error. font-not-found. Jun 9, 2016 at 9:36
  • then load it with the complete filename Inconsolatazi4-Regular.otf
    – user2478
    Jun 9, 2016 at 9:53
  • On my TeXLive 2015 installation also, it seems that I have to give the whole file name: \setmonofont{Inconsolatazi4-Regular.otf} - otherwise fontspec goes into it's automatic "build the family" routines...
    – Thruston
    Jun 9, 2016 at 9:56
  • @Thruston Worked for me! I 'd like to confirm where this file is coming from. \listfiles does not show the source. Any ideas? Jun 9, 2016 at 10:38
  • By default fontconfig which is used by xetex/xelatexfor searching font files do not scan the TeX font directories. But xetex/xelatex use kpsewhich, the reason why it will find fonts with the full name. One can put these files into systems font directoty or extend the search path for fontconfig.
    – user2478
    Jun 9, 2016 at 12:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .