Sublime Forum

How to configure custom fonts, requirements for font_face name and directory structure [Solved]

#1

Hi,

System: Linux, some Linux, Sublime Text 3, no root access

How do I configure custom fonts?

In Preferences.sublime-settings I have a working example:

"font_face": "Monaco",
"font_size": 12,
"font_options": ["dlig","ss04","no_italic"],

On Linux, user-space fonts are usually stored in $HOME/.fonts.

Here I have e.g.:

/home/$USER/.fonts/JetBrainsMono/
|-- ttf
|   |-- No ligatures
|   `-- Variable
`-- web
    |-- eot
    |-- woff
    `-- woff2

The font files in ttf folder look like this:

JetBrainsMono-Bold-Italic.ttf
JetBrainsMono-Bold.ttf
JetBrainsMono-ExtraBold-Italic.ttf
JetBrainsMono-ExtraBold.ttf
JetBrainsMono-ExtraLight-Italic.ttf
JetBrainsMono-ExtraLight.ttf
JetBrainsMono-Italic.ttf
JetBrainsMono-Light-Italic.ttf
JetBrainsMono-Light.ttf
JetBrainsMono-Medium-Italic.ttf
JetBrainsMono-Medium.ttf
JetBrainsMono-Regular.ttf
JetBrainsMono-SemiLight-Italic.ttf
JetBrainsMono-SemiLight.ttf

Nothing I tested so far worked in ā€œfont_faceā€, ā€œJetBrainsMono Regularā€, ā€œJetBrainsMono-Regularā€ ā€¦ whatever. So there must be some ā€œsystemā€ how to provide font names/files.

  • where is Sublime Text 3 looking for font files?
  • if ā€˜.fontsā€™ is an option, how should the directory structure look like? Any need for any structure or is ST searching recursively for font files?
  • what type of font files are supported? TTF only?
  • how can I deduce from TTF file what to put in into ā€œfont_faceā€?

I love ST but font management drives me frenzy ā€¦

best,
b

0 Likes

#2

You donā€™t need to provide font path, just add font name from installed fonts on your system.

0 Likes

#3

Well, these fonts are ā€œinstalledā€ in .fonts. All I have is a directory path and a bunch of TTFs.
As I wrote I tried to add the ā€œnameā€, without success. See my description ā€¦

0 Likes

#4

Sublime uses system-specific methods for working with fonts; for Linux is uses fontconfig, which is the standard way for Linux programs to work with and catalog fonts.

This is entirely a fontconfig thing and Sublime doesnā€™t care. In particular, itā€™s fontconfig's job to find, catalog and match fonts and all Sublime does is ask it for the appropriate font.

This is why for example different distributions of Linux may seem to use a different interface font in Sublime; it just asks fontconfig for a font named Sans by default, and whatever font the distribution (or you) has decided to map that to is the one that gets used.

fontconfig searches recursively through the font folders itā€™s configured with, so you can use whatever layout you like in your fonts directory (i.e. the above in your question is fine).

fontconfig can handle many types of fonts; ttf, ttc, otf, pfa, pfb and woff to name just the ones I happen to have currently installed. Sublime works with all of those font types. Presumably it would also work with bitmapped fonts as well, though Iā€™ve never tried that myself.

The bit where you are potentially going wrong here is that the name of the file that stores the font and the name of the font itself can be radically different; you could install My Cool Font from a file named zzz.ttf and it would still work as expected. The name of the font comes from metadata inside of the font file itself.

The easiest way to look something like this up is to use the fontconfig tool fc-list. See the documentation on that if youā€™re interested in the gory details, but simplistically you want to do something like this in your terminal:

tmartin:dart:~> fc-list : family
Standard Symbols PS
Samyak Oriya
Lohit Kannada
Iosevka Term SS09,Iosevka Term SS09 Medium Oblique
Samyak Devanagari
Iosevka Term SS09,Iosevka Term SS09 Extralight Oblique
Iosevka Term SS09,Iosevka Term SS09 Semibold
Century Schoolbook L
DejaVu Math TeX Gyre
URW Gothic
Serto Jerusalem Outline
Estrangelo Edessa
...
...
...

This will list every font that your system knows by name. This is probably overwhelming, so you may want to send it through less to page it or, if you know something about the name of the font you want you can grep it out; this doesnā€™t require a full name, just something you think is probably in there:

tmartin:dart:~> fc-list : family | grep -i jetbrains
JetBrains Mono,JetBrains Mono Semi Light
JetBrains Mono,JetBrains Mono Medium
JetBrains Mono,JetBrains Mono Extra Bold
JetBrains Mono,JetBrains Mono ExtraLight
JetBrains Mono,JetBrains Mono Light
JetBrains Mono

All of the items are font names; some will have a comma in them if there are multiple styles. You can include any one you like. So for example any of the following are valid:

"font_face": "JetBrains Mono",
"font_face": "JetBrains Mono Light",
"font_face": "JetBrains Mono Extra Bold"

If youā€™re not a terminal guy, your Linux disto/window manager likely has some sort of font viewer or configuration tool that would give you the names of fonts that you could use to discover the name as well. There is also other software such as font-manager that can provide this information, though Iā€™ve personally never used any.

3 Likes

#5

@OdatNurd ā€¦ thanks for your helpful and very complete answer.

I did not think about fontconfig. That solves the issues I had!

1 Like