Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: Font setup for displaying unicode characters in OSX

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?

like image 333
GeneralBecos Avatar asked Jun 06 '12 00:06

GeneralBecos


3 Answers

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
like image 60
Bard Bloom Avatar answered Oct 24 '22 22:10

Bard Bloom


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"))
like image 21
huaiyuan Avatar answered Oct 24 '22 21:10

huaiyuan


There was a known bug with MacOS emacs and displaying characters beyond the BMP. See for example my 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.

The bug was fixed subsequently, in 24.4 and beyond.

like image 43
Michael Norrish Avatar answered Oct 24 '22 22:10

Michael Norrish