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.

  • 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 '18 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 '18 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. – Herb Schulz Aug 20 '18 at 0:38
  • In terms of the syntax I wouldn't have expected that to cause a problem. Hmm... – Will Robertson Aug 20 '18 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 '18 at 13:36
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.