Fonts: Difference between revisions
mNo edit summary |
Artoria2e5 (talk | contribs) →Installing fonts on NixOS: Migrate my diffs from https://nixos.wiki/index.php?title=Fonts&action=history. The edit summaries were: "Use a manpage website that actually updates. die.net should, well, die."; "I'm starting to think the Persian example is untested! Ubuntu should absolutely not be a monospace font. Or a serif font, for that matter."; "add: link to archwiki metric-compat list; explanation of why you don't want sans-serif and serif to mix; how defaultFonts works under the hood" |
||
| Line 45: | Line 45: | ||
fc-list -v | grep -i source | fc-list -v | grep -i source | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Set multiple fonts for different languages === | === Set multiple fonts for different languages === | ||
If you want to use other languages alongside English, you may want to set appropriate fonts for each language in your whole OS. For example, a Persian speaker might want to use the [https://rastikerdar.github.io/vazirmatn/ Vazirmatn] font for Persian texts | If you want to use other languages alongside English, you may want to set appropriate fonts for each language in your whole OS. For example, a Persian speaker might want to use the [https://rastikerdar.github.io/vazirmatn/ Vazirmatn] font for Persian texts, the [https://design.ubuntu.com/font/ Ubuntu] font for sans-serif English texts. Just put these lines into your <code>configuration.nix</code>: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
#----=[ Fonts ]=----# | |||
fonts = { | fonts = { | ||
enableDefaultPackages = true; | enableDefaultPackages = true; | ||
packages = with pkgs; [ | packages = with pkgs; [ | ||
ubuntu_font_family | ubuntu_font_family | ||
liberation_ttf | |||
# Persian Font | # Persian Font | ||
vazir-fonts | vazir-fonts | ||
| Line 62: | Line 62: | ||
fontconfig = { | fontconfig = { | ||
defaultFonts = { | defaultFonts = { | ||
serif = [ " | serif = [ "Liberation Serif" "Vazirmatn" ]; | ||
sansSerif = [ " | sansSerif = [ "Ubuntu" "Vazirmatn" ]; | ||
monospace = [ "Ubuntu" ]; | monospace = [ "Ubuntu Mono" ]; | ||
}; | }; | ||
}; | }; | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
NB: | |||
* This actually just sets the font fallback order so that fontconfig tries using the English font first, then falls back to another font if the character set is not covered. You ''usually'' want to write the English font ''before'' the other-language font, because the other-language font might cover Latin characters too, preventing the English font from showing up. | |||
* <code>defaultFonts</code> translates to <code><prefer></code> in the actual fontconfig file. See https://github.com/NixOS/nixpkgs/blob/nixos-23.11/nixos/modules/config/fonts/fontconfig.nix for how NixOS does it, and the links below for how fontconfig interpret it. | |||
* Vazirmatn is actually a "sans-serif" font; using it for <code>serif</code> is not a good visual match. You might need not one, but two (or if you count monospace, three!) font packages for a language. | |||
=== Use custom font substitutions === | === Use custom font substitutions === | ||
| Line 94: | Line 99: | ||
For more information and examples on the xml configuration language: | For more information and examples on the xml configuration language: | ||
* https:// | * https://www.mankier.com/5/fonts-conf | ||
* https://wiki.archlinux.org/index.php/Font_configuration | * https://wiki.archlinux.org/index.php/Font_configuration | ||
* https://wiki.archlinux.org/index.php/Font_configuration/Examples | * https://wiki.archlinux.org/index.php/Font_configuration/Examples | ||
For a list of suitable replacement fonts: | |||
* https://wiki.archlinux.org/title/Metric-compatible_fonts | |||
== Troubleshooting == | == Troubleshooting == | ||