0

This is similar to, but not, to me, the same as, several other questions here. My MWE:

\documentclass{article}
\usepackage{fontspec}
\defaultfontfeatures[DejaVu]
  {
    UprightFont = DejaVuSerif.ttf,
    ItalicFont = DejaVuSerif-Italic.ttf,
    BoldFont = DejaVuSerif-Bold.ttf,
    BoldItalicFont = DejaVuSerif-BoldItalic.ttf
  }
\setmainfont{DejaVu}
\begin{document}
This is a test.
\end{document}

Running this with xelatex produces

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
! 
! The font "DejaVuSerif.ttf" cannot be found.
!
...

If I replace \setmainfont{DejaVu} with \setmainfont{DejaVuSerif.ttf}, everything works correctly, which tells me that my setup is okay, and the font can be found by fontspec.

7
  • 1
    Is there a reason why you’re trying to run \setmainfont{DejaVu} instead of \setmainfont{DejaVuSerif}? (DejaVu comes in both serif and sans-serif varieties — DejaVu is simply not sufficiently descriptive.)
    – Mico
    Aug 19, 2018 at 22:48
  • @Mico In my document, I don't need sans serif fonts, so I use the simpler form. In any case, using DejaVuSerifdoesn't change the behavior.
    – Derek
    Aug 19, 2018 at 23:06
  • On MacOS using a font name rather than the file name requires that the OS “sees” the font; I.e., it appears in FontBook. Aug 20, 2018 at 0:38
  • In terms of the syntax I wouldn't have expected that to cause a problem. Hmm... Aug 20, 2018 at 2:29
  • @HerbSchulz You can use defaultfontfeatures or a .fontspec file to provide a nicer name, avoiding the need to use the file name or install the font.
    – Derek
    Aug 20, 2018 at 13:36

1 Answer 1

4

This is a bug in fontspec, thanks for spotting it. I haven't tried to analyse this yet but the following workaround fixes it:

\documentclass{article}
\usepackage{fontspec}
\defaultfontfeatures[DejaVu]
  {
    Extension = .ttf,
    UprightFont = DejaVuSerif,
    ItalicFont = DejaVuSerif-Italic,
    BoldFont = DejaVuSerif-Bold,
    BoldItalicFont = DejaVuSerif-BoldItalic
  }
\setmainfont{DejaVu}
\begin{document}
This is a test.
\end{document}

(I suspect my code thinks that because .ttf wasn't part of the [DejaVu] name it shouldn't try to add an extension, but then there's probably an incorrect normalisation and the .ttf is stripped off when it shouldn't be.)

2

You must log in to answer this question.

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