35

I have problems trying to get new fonts to work when compiling with LuaLaTeX. I'm working on Mac and use TexShop (with the MacTeX package).

It goes like this:

I downloaded for example the Cardo font; I installed the Cardo font (it now appears in the Font Book); I tried to compile a simple text that goes like this:

\documentclass[11pt]{book}
\usepackage[no-math]{fontspec}    
\usepackage[frenchb]{babel}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmainfont{Cardo}

\begin{document}
Hello world!
\end{document}

After compiling I obtained the following error message:

luaotfload | Font names database loaded: /Users/juan/Library/texlive/2012/texmf
-var/luatex-cache/generic/names/otfl-names.lua
luaotfload | Updating the font names database:
luaotfload | Scanning TEXMF fonts...
luaotfload | Scanning OS fonts...
luaotfload | Font names database saved: %s 
: /Users/juan/Library/texlive/2012/texmf-var/luatex-cache/generic/names/otfl-names.lua

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
./testBembo.tex:6: fontspec error: "font-not-found"
! 
! The font "Cardo" cannot be found.
! 
! See the fontspec documentation for further information.
! 
! For immediate help type H <return>.
!...............................................  

l.6 \setmainfont{Cardo}

? 
Process aborted
  • then I checked the otfl-names.lua and Cardo was missing;
  • I then added the Cardo folder font to this folder:

    /usr/local/texlive/2012/texmf-dist/fonts/
    
  • I executed the mkluatexfontdb -vvv command in a terminal;

  • I re-checked the otfl-names.lua and Cardo was finally there;

So I naturally tried to compile the text again after resetting the computer and (as you might guess by now) I obtained (again!) the following error message:

luaotfload | Font names database loaded: /Users/juan/Library/texlive/2012/texmf
-var/luatex-cache/generic/names/otfl-names.lua
luaotfload | Updating the font names database:
luaotfload | Scanning TEXMF fonts...
luaotfload | Scanning OS fonts...
luaotfload | Font names database saved: %s 
: /Users/juan/Library/texlive/2012/texmf-var/luatex-cache/generic/names/otfl-na
mes.lua

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
./testBembo.tex:6: fontspec error: "font-not-found"
! 
! The font "Cardo" cannot be found.
! 
! See the fontspec documentation for further information.
! 
! For immediate help type H <return>.
!...............................................  

l.6 \setmainfont{Cardo}

? 
Process aborted

The thing is driving me crazy! I migrated to LuaLaTeX only because I was promised to be able to use almost any font with it. What am I doing wrong?

9
  • Are you sure the authentic name the font is "cardo". Into font book you can probe the authentic name with Cmd i. Commented Mar 21, 2013 at 22:16
  • When dealing with newly downloaded fonts on a Mac system, I find it easiest to open the font file using the Font Book App (located i the Applications folder) and clicking on the "Install Font" button that's in the lower part of the window that FontBook opens. This method may become tedious if you're downloading dozens and dozens of fonts, but I find it to be completely failsafe.
    – Mico
    Commented Mar 21, 2013 at 22:16
  • @jpayansomet Well, the Font Book says Cardo, but most of all, the "otfl-names.lua" says "Cardo"...
    – Meclassic
    Commented Mar 21, 2013 at 22:18
  • 1
    Oh, one more thing: Don't install the fonts to a directory below /texmf-dist/2012, because those fonts won't migrate automatically when MacTeX2013 comes along. Much better to copy them to ~/Library/Fonts and let FontBook handle the "installation" business.
    – Mico
    Commented Mar 21, 2013 at 22:21
  • 1
    Don't install your own files in texmf-dist: use texmf-local. Commented Mar 22, 2013 at 13:06

4 Answers 4

33
+50

I came across the same problem as you when I first tried to use XeTeX. If you want fontspec to automatically find the path to the font and load it for you, then you need to have the font installed as a system font. On OS X, you can do this by navigating to Font Book -> Preferences and changing the "Default Installation Location" from "User" to "Computer". This should allow you to use the \setmainfont{<font name>} command without any prior configuration. For Linux distributions, you should consult the documentation for your desktop environment.

If you do not want to modify the set of system fonts, or you are working on a project in which you would like all of your resources to exist in one directory structure, you can specify the path to the font explicitly. For example, if you install Cardo as a user font (which is the default behavior on OS X), the font files should be copied to ~/Library/Fonts. Assuming that regular version of the font is supplied in a file called Cardo.ttf, you can load the font as follows. (Be sure to change <username> to your username).

\setmainfont[
    Path           = /Users/<username>/Library/Fonts/,
    Extension      = .ttf,
    Ligatures      = TeX
]{Cardo}

If you have bold, italic, and bold-italic variants of your font, you can use them by adding a few extra lines. In this example, I'm using a font called Crimson, which is supplied in the OTF format. The regular version of the font is called Crimson-Roman.otf; the bold, italic, and bold-italic variants are called Crimson-Bold.otf, Crimson-Italic.otf, and Crimson-BoldItalic.otf, respectively.

\setmainfont[
    Path           = /Users/<username>/Library/Fonts/,
    Extension      = .otf,
    Ligatures      = TeX,
    BoldFont       = Crimson-Bold,
    ItalicFont     = Crimson-Italic,
    BoldItalicFont = Crimson-BoldItalic
]{Crimson-Roman}

All of this information is available in the fontspec manual.

Edit

Since you still seem to be experiencing problems using other fonts with LuaTeX, I thought that posting my procedure step-by-step might help in identifying the problem. My texlive distribution is obtained from MacPorts; running lualatex -v returns the following: This is LuaTeX, Version beta-0.70.2-2013011221 (TeX Live 2012/MacPorts 2012_5).

  • I downloaded the Baskerville font from this link. The font files are called LibreBaskerville-Regular.otf, LibreBaskerville-Bold.otf, and LibreBaskerville-Italic.otf.
  • I installed the fonts as user fonts by double clicking the font files in Finder.
  • I created a file called baskerville.tex with the following contents. (I replaced my username by <username>).
\documentclass[11pt,a4paper]{article}
\usepackage{fontspec}
\setmainfont[
    Path           = /Users/<username>/Library/Fonts/,
    Extension      = .otf,
    Ligatures      = TeX,
    BoldFont       = LibreBaskerville-Bold,
    ItalicFont     = LibreBaskerville-Italic
]{LibreBaskerville-Regular}
\begin{document}
This is a test.
\end{document}
  • I compiled the file with the command lualatex baskerville.tex.
9
  • Thanks a lot! Well, it finally compiles! Though I first re-installed the font to "Computer" but it still didn't work. What worked for me was to set the path to /Library/Fonts/. Why is this so tricky?! Changing font for LaTeX is nothing less than dark art! Thanks again!
    – Meclassic
    Commented Mar 22, 2013 at 8:13
  • Well, it seems that the solution works for "Cardo" but not at all for "Baskerville" or "Garamond MT"... Knowing that 1)They all appear correctly in the otfl-names.lua file; 2)The path is absolute and the filenames are correct; 3)I erased, recreated and updated the otfl-names.lua` file; 4)I restarted the computer many times over; 5)Every single font I use is .ttf or .otf; 6)All the fonts are in the /Library/Fonts folder. I don't even know where to look from here...
    – Meclassic
    Commented Mar 22, 2013 at 12:11
  • @jrojasqu Hm, I'm using the texlive distribution downloaded from Macports --- maybe something is different about the configuration? I'm going to try downloading the Libre Baskerville font from here, and I'll post my setup step-by-step. Perhaps we can compare and see where the failure occurs. Commented Mar 22, 2013 at 21:25
  • @jrojasqu I posted a step-by-step procedure that I used for installing the Libre Baskerville font. Perhaps if you try the same steps and post the error messages, we can see where things go wrong. One thing I might suspect is that you are having some kind of file permissions problem. Commented Mar 22, 2013 at 21:50
  • 1
    There is a problem with ttf fonts which was documented here. Basically, LuaLaTex used to not be able to run ttf fonts so they were all blacklisted. But if you follow the instructions on that post you can edit the blacklist file.
    – jjewell
    Commented May 20, 2013 at 17:37
5

If your new fonts are in ~/.fonts and not being recognized by mkluatexfontdb, try this:

OSFONTDIR=${HOME}/.fonts:/usr/share/fonts//:/usr/share/texmf/fonts//   
mkluatexfontdb --force --verbose=-1 -vvv
0
4

On OSX, I was able to get things working in the following way:

  1. Install to default user location (/Users/john/Library/Fonts)
  2. mkluatexfontdb --force --verbose=-1 -vvv

That's all it took!

2
  • Does this answer differ materially from the one provided by @nuttyaboutnatty?
    – Mico
    Commented Aug 29, 2014 at 7:54
  • Well the first part of the command which explicitly specifies OSFONTDIR was not required, so I thought I would a new simplified answer. Commented Aug 29, 2014 at 8:17
0

Using the solution from void-pointer, I tried to use Cardo with LuaLaTex, but ran into some issues with the font not being found.

Here are the edits that I had to make to his answer so that it would work for me. Basically, ignore the name that FontBook gives the font, and use the filename, minus the extension (which can be found with ⌘ + i in FontBook and looking for Location.

\usepackage{fontspec}
\setmainfont[
    Path       = /Library/Fonts/, 
    Extension  = .ttf, 
    Ligatures  = TeX, 
    BoldFont   = Cardob101, 
    ItalicFont = Cardoi99,
]{Cardo104s}

N.B. Even the regular font name (i.e.\setmainfont[...]{regular-font-name}) needs to be the filename in Finder minus the extension.

You must log in to answer this question.

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