3

How to get Emacs to use a font that is not installed?

Background

My USB flash drive has the font that I want to use, but the school's computer room doesn't give students admin permission, so I can't install the font.

Useful Information

An IDE called Portacle, which is (I guess) essentially a configured/encapsulated Emacs and doesn't require root/admin privilege to install and run, can display fonts that are NOT installed on my computers for either GNU/Linux or MS-Windows (macOS is untested yet). I can find the corresponding font's TTF file in its directory.

shynur
  • 5,253
  • 1
  • 4
  • 25
  • Probably it is still as stated here: https://stackoverflow.com/questions/496188/how-do-i-have-emacs-load-a-font-from-a-file#497737 : you can't load fonts from custom locations. In other words you probably need to hack the source code if you want to have all what Emacs need on a USB-stick. – Claudio May 03 '23 at 10:55
  • @Claudio: That is a 14-year-ago answer. Things may be different now. – shynur May 03 '23 at 11:31
  • Yes ... things may be different now ... the problem with stating that something is not possible is that it is hard to prove it by evidence especially because nothing is impossible if you hack the source of the application and/or of the system. It seems that there is no environment variable you can set to add an additional path to search for fonts. No idea if this is generally still true ... and it will sure depend on the specific OS you use. – Claudio May 03 '23 at 11:51
  • A known work around is to use (font-family-list) and pick a font from it which best fits own requirements during the initialization. By the way: if I run this function in the scratch buffer with C-j (with wrapping on) the buffer becomes so slow that it only helps to delete the line to make it responsive again and make the output with each list item on an own line. – Claudio May 03 '23 at 12:10
  • 2
    Portacle's fonts are in portacle/all/fonts/ – nega May 03 '23 at 18:55
  • Portacle's font config is in portacle/config/fontconfig/fonts.conf – nega May 03 '23 at 19:09
  • 1
    To grossly summarize Emacs's font handling, it doesn't care where the font is, it just asks the toolkit it was compiled against for a font. If you want to change font locations, change the toolkit's configuration. – nega May 03 '23 at 19:23

1 Answers1

2

The proper answer to this question is highly dependent on your OS and what toolkits your Emacs is compiled against. If you're looking to have an "Emacs on a thumbdrive" for your personal use, you can

  1. compile Emacs with fontconfig
  2. collect the fonts you want
  3. use fontconfigs tools to create a proper fonts.conf
  4. use environment variables to configure the location of that fonts.conf
  5. put all that goodness on your thumb drive

Or just use Portacle and disable the bits you don't want.

nega
  • 3,221
  • 15
  • 21