3

I am using Emacs 28.2 on Windows ("GNU Emacs 28.2 (build 2, x86_64-w64-mingw32)"). It has Unicode support for many characters, but some seem to be missing.

For example the Unicode character β€œπŸ”β€ (U+1F501) shows up as a little square placeholder (with the codepoint rendered inside) instead: enter image description here

Other Unicode characters, like for example β€œέβ€ (U+0750) render fine (and in this case, Emacs even automatically switches to left-to-right mode when entering that character). Other applications on this machine, for example the browser I am typing in right now, render the U+1F501 correctly.

What can I do to make this and other symbols appear in Emacs?

In other words, my system has at least one font to render those symbols (as witnessed by other applications doing it). As pointed out in the comments, the task is now to find which one that is, and tell Emacs to use it (or to figure out why Emacs does not do that on its own). Is there a way to do that?

5
  • 2
    The question is no doubt a duplicate - please look for one and close/delete this one. Thx. Your problem is that the font you're using doesn't support those particular Unicode chars. Just use a font that does support them.
    – Drew
    Commented Jan 2 at 14:47
  • It is available in -GOOG-Noto Color Emoji-regular - I use Liberation Mono Regular normally, so the Google Noto font is probably a fall-back for such glyphs. On Fedora, you can install it with dnf install google-noto-emoji-color-fonts. I don't think any Emacs configuration is required for using it.
    – NickD
    Commented Jan 2 at 16:32
  • @NickD, thank you! Fascinating: if I install the Noto Color Emoji .ttf and reopen Emacs, it does not show the code placeholder anymore, but instead nothing at all for those characters.
    – AnoE
    Commented Jan 3 at 9:25
  • @Drew: thanks for pointing out that I might not be the first with that problem - I did search for it, and tried again now. Either I don't know the correct search terms, or the answers are more specific for other circumstances (i.e., font issues in specific packages or on non-Windows systems). "Just using a font that does support them" is kind of obvious, and my system does have a font that supports them in other apps (and those other apps automatically use it). Is there a way in Emacs to systematically find which of the installed fonts can render a given glyph, maybe?
    – AnoE
    Commented Jan 3 at 9:28
  • FYI, you can accept your own answer.
    – Drew
    Commented Jan 4 at 2:22

1 Answer 1

2

Self-answer after some digging:

Here is some code to print out how Emacs renders one or more characters in all available fonts:

; to find fonts for a given character, interactively execute print-all-fonts in *scratch*:

(defun insert-character-with-font (char font)
  "Insert CHAR into the current buffer with FONT."
  (let ((start (point)))
    (insert char)
    (add-text-properties start (point)
                         `(face (:family ,font)))))

(defun print-all-fonts ()
  "Print details of all installed fonts."
  (interactive)
  (font-lock-mode -1)
  (set-fontset-font t 'symbol nil)
  (set-fontset-font t 'emoji nil)
  (let ((fonts (font-family-list)))
    (dolist (font fonts)
      (insert-character-with-font "πŸ”" font)  ; 01F501 - Segoe UI Symbol is best
      (insert " ")
      (insert-character-with-font "πŸ§—" font)  ; 01F9D7 - only in Segoe UI Emoji
      (insert (prin1-to-string font))
      (insert "\n"))))

(Mods: Full disclosure, these two defuns are adapted from code generated by ChatGPT 3.5; I am aware that ChatGPT content is not allowed here - if that policy also rules out code snippets, feel free to delete the answer.)

After defining those, switch to *scratch* or some other throwaway buffer and M-x print-all-fonts. It will override some settings (font-lock, some fontsets) and print all characters with their font name in a big list. Then you can scroll through that list and find the best-looking glyphs.

Obviously, your Emacs installation has to have basic Unicode support activated, which is outside of the scope here. You should be able to grab a character, say, from a web site, and paste it where I have my two example characters.

Also, if you are investigating other characters, not from the 'symbol or 'emoji blocks, you will have to figure out the appropriate names for them, and generally adjust the two defuns as necessary. They are only used for debugging/information-gathering, and not relevant otherwise.

N.B.: Note that Emacs has many ways to otherwise generate such characters, for example something like (insert-char (char-from-name "CIRCLED CROSS FORMEE WITH FOUR DOTS")) would be handy if you don't want to search that character on some website (or if you want to insert many).

To then configure Emacs to use a certain font for a certain range of codepoints, the set-fontset-font function is used. Its docstring explains how you can specify the ranges or even individual characters. In my particular example, I ended up with these snippets (slightly adapted from here and here):

; set up unicode symbols (order matters!)

(set-fontset-font
 t
 'emoji
 (cond
  ((member "Apple Color Emoji" (font-family-list)) "Apple Color Emoji")
  ((member "Noto Color Emoji" (font-family-list)) "Noto Color Emoji")
  ((member "Noto Emoji" (font-family-list)) "Noto Emoji")
  ((member "Segoe UI Emoji" (font-family-list)) "Segoe UI Emoji")  ; πŸ§—
  ((member "Symbola" (font-family-list)) "Symbola")))

(set-fontset-font
 t
 'symbol
 (cond
  ((member "Segoe UI Symbol" (font-family-list)) "Segoe UI Symbol")
  ((member "Apple Symbols" (font-family-list)) "Apple Symbols")
  ((member "Symbola" (font-family-list)) "Symbola")))

; nice on windows...

(cond
  ((eq system-type 'windows-nt)
   (set-fontset-font t '(#x1F300 . #x1F5FF) "Segoe UI Symbol")))  ; πŸ”, Miscellaneous Symbols and Pictographs

When you execute those, the display should update in all buffers immediately; no reloading is required.

As you see here, the critical third statement overrides a smaller block for a specific glyph I want from there because it is better-looking to me.

With these settings, the characters are displayed like this in my Emacs:

enter image description here

Unfortunately, this does not yet give us the beautiful colored symbols as we see it here in StackExchange's rendering:

enter image description here

But that is a topic for a different question.

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.