When inserting uncommon mathematical unicode symbols (normally through font-lock-add-keywords), I experience this issue that when my default font does not have a particular character, another font that includes that character is used instead.

Somehow, the height of the symbol in the second font is sometimes different from the height of all the regular characters in the first font, off by maybe one pixel. This changes the current line's height, and "moves" much screen text up/down by a pixel when I type a symbol, which is quite irritating. (The default substitute font that causes this problem is Arial.)

I currently solve this by using something like this, when "Source Code Pro" is the default font:

(set-default-fontset "fontset-default" '(#x???? . #x????) "DejaVu Serif")

The range is something like 2100..23ff, 27c0..27ff, 2900..2bff. Sometimes this doesn't work when I find out that DejaVu Serif also doesn't have the character, and I need to find yet another font with the same height that does. This is in emacs 24.3, on OS X 10.9.3.

A related issue is that for some characters a different font (different height) gets used depending on whether the character is highlighted inside selected region.

Why does this happen, and what can I do about it? I don't especially care which font gets used, so long as line heights don't jump. Any suggestions? Is there any way I can adjust the height of the second alternative font to be exactly the same?

  • I know about this question, but it's not what I'm looking for because I already know I can set fonts, but only some fonts work, some of the time.
    – Kirill
    Jul 1 '14 at 1:02
  • 1
    My recommendation would be to slowly create a list of offending characters, and modify the font height (etc.) as to those whenever they are used. You can do this with font-lock. For example, whenever you use the ±, you can make it bigger or smaller. Each time you come across a new offending character, decide what size you want it to be and add it to your ever-growing list.
    – lawlist
    Jul 1 '14 at 6:09
  • 1
    For example, whenever I use a checkmark, I shrink it a bit -- my face definition for lawlist-checkmark is smaller than my default font. Here is something I enable when turning on a particular minor-mode -- it has a special symbol, so I cannot make this comment a fancy shaded grey: (dolist (my-keyword '(("✓" (0 lawlist-checkmark)) )) (unless (memq my-keyword font-lock-keywords) (font-lock-add-keywords nil `(,my-keyword))))
    – lawlist
    Jul 1 '14 at 6:16
  • 1
    And, here is my face: (defvar lawlist-checkmark (make-face 'lawlist-checkmark)) (set-face-attribute 'lawlist-checkmark nil :background "black" :foreground "yellow" :bold t :height 150)
    – lawlist
    Jul 1 '14 at 6:19
  • @lawlist That makes sense. I suppose I am looking for a way to not have to do that by hand.
    – Kirill
    Jul 3 '14 at 4:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.