0

I'm trying to add a font with Xelatex, yet, somehow while fontspec does find the font, it immediately claims that it doesn't exist.

Here is the font definition output:

Package fontspec Info: Font family 'SourceSansPro(0)' created for font
(fontspec)             'SourceSansPro' with options
(fontspec)             [Ligatures=TeX,Path=./static/fonts/sourcesans/,Extension
(fontspec)             =
(fontspec)             .ttf,UprightFont=*-Regular,BoldFont=*-Bold,ItalicFont=*-Italic,BoldItalicFont=*-BoldItalic].
(fontspec)              
(fontspec)              This font family consists of the following NFSS
(fontspec)             series/shapes:
(fontspec)              
(fontspec)             - 'normal' (m/n) with NFSS spec.:
(fontspec)             <->"[./static/fonts/sourcesans/SourceSansPro-Regular.ttf]/OT:script=latn;language=dflt;mapping=tex-text;"
(fontspec)             - 'small caps'  (m/sc) with NFSS spec.:
(fontspec)             <->"[./static/fonts/sourcesans/SourceSansPro-Regular.ttf]/OT:script=latn;language=dflt;+smcp;mapping=tex-text;"
(fontspec)             - 'bold' (b/n) with NFSS spec.:
(fontspec)             <->"[./static/fonts/sourcesans/SourceSansPro-Bold.ttf]/OT:script=latn;language=dflt;mapping=tex-text;"
(fontspec)             - 'bold small caps'  (b/sc) with NFSS spec.:
(fontspec)             <->"[./static/fonts/sourcesans/SourceSansPro-Bold.ttf]/OT:script=latn;language=dflt;+smcp;mapping=tex-text;"
(fontspec)             - 'italic' (m/it) with NFSS spec.:
(fontspec)             <->"[./static/fonts/sourcesans/SourceSansPro-Italic.ttf]/OT:script=latn;language=dflt;mapping=tex-text;"
(fontspec)             - 'italic small caps'  (m/scit) with NFSS spec.: 
(fontspec)             - 'bold italic' (b/it) with NFSS spec.:
(fontspec)             <->"[./static/fonts/sourcesans/SourceSansPro-BoldItalic.ttf]/OT:script=latn;language=dflt;mapping=tex-text;"
(fontspec)             - 'bold italic small caps'  (b/scit) with NFSS spec.: 

However when I use \setmainfont I get this:

! Package fontspec Error: The font "SourceSansPro" cannot be found.

For immediate help type H <return>.
 ...                                              
                                                  
l.47 
     

A font might not be found for many reasons.
 Check the spelling, where the font is installed etc. etc.

 When in doubt, ask someone for help!



Package fontspec Info: Could not resolve font "SourceSansPro/BI" (it probably
(fontspec)             doesn't exist).


Package fontspec Info: Could not resolve font "SourceSansPro/B" (it probably
(fontspec)             doesn't exist).


Package fontspec Info: Could not resolve font "SourceSansPro/I" (it probably
(fontspec)             doesn't exist).


! Package fontspec Error: The font "SourceSansPro" cannot be found.

For immediate help type H <return>.

What is really confusing me is that this works just fine with other fonts.

Here is the .tex that leads to this problem (fonts are downloaded from Google fonts):

\usepackage{fontspec}

\setsansfont{SourceSansPro}[
    Path=./static/fonts/sourcesans/,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    ]

\setromanfont{Brygada1918}[
    Path=./static/fonts/brygada/,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    ]

\setmonofont{JetBrainsMono}[
    Path=./static/fonts/jetbrains/,
    Scale=0.85,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    ]
    
\setmainfont{SourceSansPro}

Both Brygada and JetBrains work fine.

6
  • Your first log shows unusual pathes. Probably xelatex can't find fonts by name there as they are not in your fontconfig. Jun 4 at 12:10
  • 1
    Could you provide a minimal working example that generates this error? As Ulrike hints, fontspec allows you to choose fonts either by font name or by filename, but the former requires the font be installed system-wide, and the latter usually requires the extension be given. My guess is that you're doing something in between: using the file basename but without the path and/or extension. (The font name would be "Source Sans Pro" with spaces if installed systemwide.)
    – frabjous
    Jun 4 at 13:03
  • @frabjous Edited. Jun 5 at 8:27
  • 1
    You gave it all the information it needed when you set it as the sans font, but not when you set it as the main font. Either (1) put all that information in the [..] after that command as well, or just remove that line and (2) use something like \renewcommand*{\familydefault}{\sfdefault} to make the sans font default, or (3) use \sffamily at the beginning of your document.
    – frabjous
    Jun 5 at 14:31
  • Not essential to your question, but the name of the current release is Source Sans 3.
    – Thérèse
    Jun 5 at 14:40

1 Answer 1

2

As I mentioned in the comments, the problem is that you provided the information to find the fonts when you set SourceSansPro as your Sans font, but not when you set it as your main font.

I mentioned three options in the comments: (1) Put all the extra information with the \setmainfont as well:

\setmainfont{SourceSansPro}[
    Path=./static/fonts/sourcesans/,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    ]

Or (2) else you can leave the \setmainfont{SourceSansPro} line out, and instruct LaTeX to use the sans font by default with \renewcommand*{\familydefault}{\sfdefault}.

Or (3) you can leave that line out and just to switch to sans manually with \sffamily at the start of your document.

There are actually other options I didn't mention, such as (4) setting the default features for that font name, and then set that font more simply like so

\defaultfontfeatures[SourceSansPro]{
    Path=./static/fonts/sourcesans/,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    }
\setsansfont{SourceSansPro}
\setmainfont{SourceSansPro}

Finally you could put that information in a SourceSansPro.fontspec file as discussed in the fontspec documentation page 11.

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.