0

I'm trying to understand how to get emacs to properly combine unicode combining characters when doing font substitution. Here is a concrete example. On my mac, I start emacs -Q, and try to display the sequence of characters x̂ x⃗ χ̂ χ⃗. This is an x followed by (#x302) COMBINING CIRCUMFLEX ACCENT, then an x followed by (#x20d7) COMBINING RIGHT ARROW ABOVE; and then χ (GREEK SMALL LETTER CHI) followed by the circumflex, and then χ followed by the combining right arrow above. The default font is Menlo, which obviously includes the ASCII x, and the circumflex and chi, but apparently not the combining right arrow. This is what I see:

Before changing the default for unicode characters

As you can see, the combining arrow gets pulled from some other font --- emacs falls back to Arial Unicode MS (I can't find where this default is determined). But the combining arrow doesn't get combined with the character before it, and I'm guessing this is because they're coming from different fonts.

Now, I can change the fallback font for unicode characters to be a different font --- in my case, the Symbola font --- by evaluating (set-fontset-font t 'unicode "Symbola" nil 'prepend). After evaluating it, this is what I see:

After changing the default for unicode characters

Now I get a combined chi with arrow, coming from Symbola. The x and combining arrow have not been combined.

I don't understand why this is, especially given that the default (Arial Unicode MS) also has the Greek small chi character and the combining arrow.

What are the rules for how font substitution works for combining characters? Why is x not being combined with the arrow?

If I set my default font to be one of those featureful fonts, I can get combining characters, but I want a monospaced font with obvious differences between the commonly-confused characters like O0Il1|, and most "programmer's" fonts seem to lack those combining symbols that I want.

1

1 Answer 1

0

You can check whether this is a problem caused by inputting characters or by displaying characters by writing these characters to a file and then loading it.

Assuming you did this or something equivalent, this would be caused by the way characters are displayed, as you are assuming.

I can recommend the font JuliaMono https://juliamono.netlify.app, which is designed for programming. This font is working for me, in the sense that it shows what you would expect.

I have these lines in my .emacs:

(custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(default ((t (:inherit nil :stipple nil :background "White" :foreground "Black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 100 :width normal :foundry "nil" :family "JuliaMono"))))) 
1
  • Thanks for the font recommendation, Erik! I can confirm that JuliaMono correctly displays all the combined unicode characters (which I input correctly, which you can verify by copy/pasting the unicode character sequence I included in my question). So while this avoids the problem I had, I still don't understand what emacs is doing under the hood regarding font substitution when there are combining characters. Commented Sep 19 at 19:51

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.