home > hackerspace > fontconfig

Changing your conputer's default fonts with fontconfig

On a system with fontconfig installed (most Linuxes have it installed by default), you can either:

So if you wanted to set your default fonts to Besley for serif, Inria Sans for sans-serif, and Fantasque Sans Mono for monospace, your config might look as follows:

(raw text)

<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match target="pattern">
      <test qual="any" name="family">
          <string>serif</string>
        </test>
        <edit name="family" mode="prepend" binding="same">
          <string>Besley</string>
        </edit>
        <edit name="family" mode="append" binding="same">
          <string>Linux Libertine</string>
        </edit>
        <edit name="family" mode="append" binding="same">
          <string>DejaVu Serif</string>
        </edit>
    </match>
  <match target="pattern">
      <test qual="any" name="family">
          <string>sans-serif</string>
        </test>
        <edit name="family" mode="prepend" binding="same">
          <string>Inria Sans</string>
        </edit>
        <edit name="family" mode="append" binding="same">
          <string>Linux Biolinum</string>
        </edit>
        <edit name="family" mode="append" binding="same">
          <string>DejaVu Sans</string>
        </edit>
    </match>
  <match target="pattern">
      <test qual="any" name="family">
          <string>monospace</string>
        </test>
        <edit name="family" mode="prepend" binding="same">
          <string>Fantasque Sans Mono</string>
        </edit>
        <edit name="family" mode="append" binding="same">
          <string>Linux Libertine Mono</string>
        </edit>
        <edit name="family" mode="append" binding="same">
          <string>DejaVu Sans Mono</string>
        </edit>
    </match>
</fontconfig>

Your preferred fonts should be marked with mode="prepend". Families with mode="append" will be used as fallbacks in case a certain character isn't available in your preferred font. This is optional--if there are any fonts on your system that contain the needed character, most software will be able to find a font to display that character in. This just lets you choose which fonts you want to be checked first (e.g. so you can pick ones that look similar to your preferred font, or otherwise that you find aesthetically pleasant.)

Here are some more fontconfig examples for more advanced customization.