9

There is a monospace font family I like called IBM Plex Mono. It comes with several font weights beyond just normal and bold, namely:

Thin
ExtraLight
Light
Regular
Medium
SemiBold
Bold

Now, I have two workstations that I use regularly. One of them runs Kubuntu 22.04, where I have installed this font family using apt (it is in the repos). The other one runs Fedora Kinoite, and I have installed the font by downloading the .woff2 files and copying them to my ~/.local/share/fonts directory.

On both machines, I have set the default monospace font (using the Fonts settings in KDE settings) to IBM Plex Medium, which is the weight I like to use in my terminal (Konsole). After doing this, Konsole uses the correct medium weight in the terminal.

However, the two machines render bold text in the terminal differently, which you can test by running echo -e "\033[1mBold\033[0m normal" to print some bold text using ANSI escape codes.

  • On the Kubuntu machine, a bolder font weight (I think it's the Bold weight) is used.
  • On the Fedora machine, the font weight is exactly the same, as though the font resolution has decided that Medium is “already” bold enough.

My immediate problem, of course, is that I would like to figure out how to get Fedora (or at least Konsole) to use a variant of the font that actually has heavier weight so that I can tell bold and normal text apart.

But my question is broader than that—given a pile of .woff2 (or .ttf or whatever) files in ~/.local/share/fonts, and that I have specified one of these as my default monospace font, how does Linux decide which variant to use when Konsole asks for "default monospace with bold weight"? Is there a way I can control this myself, e.g. in /etc/fonts/conf.d/?


This question is similar to mine, but it's fairly old and doesn't really cover the "best practices" for how to set up these kinds of mapping (e.g. where I should stick that XML): How do I alias the bold weight of a font family to the bold weight of another font family?

1 Answer 1

10

Fontconfig is the library responsible for font discovery, matching, and configuration on many Linux systems. When an app requests a specific font weight, fontconfig determines the best match based on available fonts and configuration files.

To control font weight selection:

Make sure that all variants of IBM Plex Mono are correctly installed in ~/.local/share/fonts on your machine. This directory should contain all font files, including different weights.

Then update the font cache to ensure that the system recognizes the new fonts:

fc-cache -fv

Then create a font configuration file to specify how fontconfig should handle different font weights. You can create a new file in ~/.config/fontconfig/conf.d/ (create the directory if it doesn't exist) or in /etc/fonts/conf.d/ for system-wide settings. Example (this one is from my Fedora Linux, it's the same in most distros as far as I know), create a file named 10-ibm-plex-mono-bold.conf:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <!-- Match IBM Plex Mono Medium and use Bold for bold weight -->
    <match target="pattern">
        <test name="family"><string>IBM Plex Mono</string></test>
        <test name="weight"><const>medium</const></test>
        <edit name="weight" mode="assign" binding="strong">
            <const>bold</const>
        </edit>
    </match>

    <!-- Make sure bold weight maps to Bold variant -->
    <match target="pattern">
        <test name="family"><string>IBM Plex Mono</string></test>
        <test name="weight"><const>bold</const></test>
        <edit name="family" mode="assign" binding="strong">
            <string>IBM Plex Mono</string>
        </edit>
        <edit name="weight" mode="assign" binding="strong">
            <const>bold</const>
        </edit>
    </match>
</fontconfig>

Then, update the cache again:

fc-cache -fv

Now, you can use the fc-match command to verify that fontconfig is correctly matching the requested font weights:

fc-match -v 'IBM Plex Mono:weight=bold'

Specific mapping example

If you want to make sure that IBM Plex Mono Medium maps to IBM Plex Mono Bold when bold weight is requested, you can use the following specific configuration:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <match target="pattern">
        <test name="family"><string>IBM Plex Mono</string></test>
        <test name="weight"><const>medium</const></test>
        <edit name="family" mode="assign" binding="strong">
            <string>IBM Plex Mono</string>
        </edit>
        <edit name="weight" mode="assign" binding="strong">
            <const>bold</const>
        </edit>
    </match>
</fontconfig>

Thank you!

2
  • Thank you for this detailed explanation! I added your second XML block in my ~/.config/fontconfig/conf.d. I also added similar rules for the family names IBM Plex Mono Medm and IBM Plex Mono Medium (instead of IBM Plex Mono plus weight medium), since the KDE font chooser requires me to choose the full family name. After running fc-cache -fv, fc-match -v 'IBM Plex Mono:weight=bold' indicates the file ~/.local/share/fonts/IBM-Plex-Mono/fonts/complete/otf/IBMPlexMono-Bold.otf, which is correct. But the bold text in my terminal still renders with the medium weight. Any ideas?
    – Max
    Commented Jul 13 at 13:27
  • 1
    Ah, OK, I identified the problem: In the KDE font chooser, I had chosen IBM Plex Mono Medm as my monospace font. Choosing the "medium" variant of the IBM Plex Mono font instead causes the bold resolution to work as expected, no extra XML needed. I believe the relevant fc-match with this new, improved setup is fc-match -v 'IBM Plex Mono:weight=bold:weight=medium', which points to the ...-Bold.otf file as desired.
    – Max
    Commented Jul 13 at 13:30

This site is temporarily in read-only mode and not accepting new answers.

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