Emacs: Font setup for displaying unicode characters in OSX

余生颓废 提交于 2019-12-10 03:56:30

问题


I'm trying to display special unicode characters, in particular the mathematical operator 𝓮 in emacs. Specifically:

             position: 283 of 317 (89%), column: 0
            character: 𝓮 (displayed as 𝓮) (codepoint 120046, #o352356, #x1d4ee)
    preferred charset: unicode (Unicode (ISO10646))
code point in charset: 0x1D4EE
               syntax: w    which means: word
             category: .:Base, L:Left-to-right (strong)
          buffer code: #xF0 #x9D #x93 #xAE
            file code: #xF0 #x9D #x93 #xAE
               (encoded by coding system utf-8-unix)
              display: no font available
         Unicode data:
                 Name: MATHEMATICAL BOLD SCRIPT SMALL E
             Category: Letter, Lowercase
      Combining class: Ll
        Bidi category: Ll
        Decomposition: font e

Character code properties: customize what to show
  name: MATHEMATICAL BOLD SCRIPT SMALL E
  general-category: Ll (Letter, Lowercase)
  decomposition: (font 101) (font 'e')

There are text properties here:
  fontified            t

I'm using GNU Emacs 24 a recent nightly binary. The text above displays fine on my browser and in TextEdit however, the special characters come up empty when viewed in emacs.

I read this from an old Emacs 22 manual: "A fontset does not necessarily specify a font for all character codes. If a fontset specifies no font for a certain character, or if it specifies a font that does not exist on your system, then it cannot display that character. It will display an empty box instead." - This is the exact behavior I am observing

It seems I may need to build a fontset to be able to display such arbitrary characters (starting with the Xdefaults or Xresources files).

How can I identify which font families I will need to include in the fontset to display Math operators (most online examples refer to languages like Latin, Chinese, etc.)? I couldn't even find any examples of .Xdefault or .Xresource files.

Am I on the right track? Is there an easier/more obvious way to do this?


回答1:


I believe there is a known bug with MacOS emacs and displaying characters beyond the BMP. See for example my (unanswered) bug report at Emacs bugs.

After reporting this bug, I had an e-mail suggesting use of the “Mac port” version of emacs. This apparently displays non-BMP characters.

Of course, it’d be nice if the bug was fixed in the main line of emacs development. It’d also be nice if the bug was officially acknowledged...




回答2:


The function set-fontset-font may be used to specify which font to use for any range of characters; e.g.,

(set-fontset-font t '(#x1d4ee . #x1d4ee) (font-spec :family "FreeSerif"))



回答3:


I have the same problem, and I don't have a general solution either. Here's my approach to fixing a single character (or potentially a range), assuming that you have the character in a buffer and it's not displaying.

Some experimentation showed that Menlo is a useful source of characters, like FreeSerif.

  1. Put the cursor before the non-displayed character.

  2. m-x describe-char. This gives you a lot of information about the character, including a line of the form "code point in charset: 0x2055".

    1. Somewhere in your .emacs or related files, use this function. It can potentially fix a whole range of characters by snagging them from the FreeSerif family or something else, but I don't have good choices for anything but a few characters.
    (defun bbextra-fix-fontset-font (from &optional to family)
      "Make characters FROM to TO come from FAMILY.  
    Default value of TO is FROM, and of FAMILY is FreeSerif (which 
    seems to have some of the characters)" 
     (set-fontset-font t (cons from (or to from))
                       (font-spec :family (or family "FreeSerif"))))

    ;; Here are the characters I have fixed.  
    (bbextra-fix-fontset-font #x2042)
    (bbextra-fix-fontset-font #x2023) 
    (bbextra-fix-fontset-font #x203D) 
    (bbextra-fix-fontset-font #x2055) 


     ;These come from Menlo
     (bbextra-fix-fontset-font #x2620 #x2620 "Menlo") ; skull and crossbones
     (bbextra-fix-fontset-font #x266C #x266C "Menlo") ; 16th notes
     (bbextra-fix-fontset-font #x2695 #x2695 "Menlo") ; asclepion
     (bbextra-fix-fontset-font #x2624 #x2624 "Menlo") ; caduceus


来源:https://stackoverflow.com/questions/10906621/emacs-font-setup-for-displaying-unicode-characters-in-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!