7

I'm editing a text file containing Japanese kanji characters. 単 does not show up in Emacs, how to fix? It shows up as some sort of white space.

Update:

I'm using GNU Emacs 24.3 (9) for Mac.

After examining my .emacs, I actually copied from someone else's configuration and has

(create-fontset-from-fontset-spec
  "-unknown-Source Code Pro-normal-normal-normal-*-16-*-*-*-m-0-fontset-myfontset")
(set-fontset-font "fontset-myfontset" 'han "XinGothic CiticPress")
(set-fontset-font "fontset-myfontset" 'kana "HanaMinPlus")
(add-to-list 'default-frame-alist '(font . "fontset-myfontset"))

but I don't quite understand what it does. Apparently it doesn't work for some Kanji characters.

Update 2

I've confirmed font HanaMinPlus can display that character correctly by evaluating (set-frame-font "HanMinPlus" nil t) in my mini-buffer and observing showing up correctly in scratch buffer. But I wonder how to tweak/correct the above code to let it automatically detect and set font. I don't understand how fontset work in Emacs. But

describe-fontset 

gives

Fontset: -apple-Menlo-medium-normal-normal-*-16-*-*-*-m-0-fontset-auto1

not myfontset. And describe-font gives

name (opened by): -apple-Menlo-medium-normal-normal-*-16-*-*-*-m-0-iso10646-1
       full name: Menlo-Regular
            size: 16
          height: 19
 baseline-offset:  0
relative-compose:  0

Update 3

Experiment 1

/Applications/Emacs.app/Contents/MacOS$ ./Emacs --no-init-file

and then open a text file containing

すべての人間は、生まれながらにして自由であり、
かつ、尊厳と権利と について平等である。
人間は、理性と良心とを授けられており、
互いに同胞の精神をもって行動しなければならない。

I see all characters showing up correctly. And describe-font with default selection shows

name (opened by): -apple-Menlo-medium-normal-normal-*-12-*-*-*-m-0-iso10646-1
       full name: Menlo-Regular
            size: 12
          height: 14
 baseline-offset:  0
relative-compose:  0

and describe-fontset shows

Fontset: -apple-Menlo-medium-normal-normal-*-*-*-*-*-m-0-fontset-startup

Experiment 2

/Applications/Emacs.app/Contents/MacOS$ ./Emacs --no-site-file

and then open the same test file. I see all characters showing up correctly. And describe-font with default selection shows

name (opened by): -apple-Source_Code_Pro-medium-normal-normal-*-12-*-*-*-m-0-iso10646-1
       full name: SourceCodePro-Regular
            size: 12
          height: 16
 baseline-offset:  0
relative-compose:  0

Why it's not font size 16?!

and describe-fontset shows

Fontset: -apple-Source_Code_Pro-medium-normal-normal-*-12-*-*-*-m-0-fontset-auto1
11
  • 2
    What font are you currently using? See if you can use the same font in the buffer as the one in the browser to make sure the character is included in that font set.
    – dgtized
    Oct 10, 2014 at 19:53
  • For what it's worth, DejaVu Sans Mono supports that character in Emacs.
    – Dan
    Oct 10, 2014 at 20:28
  • @Dan: So does Lucida Console, at least on MS Windows - e.g., "-outline-Lucida Console-normal-normal-normal-mono-14----c--iso8859-1".
    – Drew
    Oct 10, 2014 at 20:33
  • @dgtized, how to find out the current font? I'm not very educated in font setting for Emacs.
    – qazwsx
    Oct 10, 2014 at 20:41
  • 1
    I thought the code I quoted in the original post is meant to use appropriate font depending on the character sets, i.e. if it's Japanese kana characters, it should use "HanaMinPlus".
    – qazwsx
    Oct 10, 2014 at 21:30

3 Answers 3

3

I don't think you have to do anything special. Remember, there's font substitution technology in Mac OS X, Linux, MS Windows. So, even if the font doesn't contain the char, it'll likely show. Many of the font mentioned here does not actually contain Chinese char sets. Specifically, Menlo and DejaVu does not contain Chinese characters. (my emacs is set to use DejaVu, and without any setting related to Chinese. But Chinese shows fine (including 単). This has been so in Ubuntu Linux, Microsoft Windows 7, Mac OS X.)

Also, depending on what emacs distribution you are using on the Mac, they likely have bundled their own font with settings in site-start.el.

I would recommend the following, try in order, if doesn't work, try next item:

  • Start emacs with --no-init-file.
  • Start emacs with --no-site-file.
  • Start emacs with --no-site-file and --no-init-file
  • Start emacs with --no-site-file, with only this line in your init file: (set-language-environment "UTF-8")

If one of these steps works, then you have narrowed down the problem.

It is hard to track down why exactly a character doesn't display. Different Operating System uses different font subsitution technology, and they don't work 100% for all characters. e.g. I have Unicode font symbola installed for displaying Unicode 6's emoticons, but many doesn't show, untill i specifically set

;; specify font for all unicode characters
(when (member "Symbola" (font-family-list))
  (set-fontset-font t 'unicode "Symbola" nil 'prepend))

the above comes after:

(cond
 ((string-equal system-type "windows-nt") ; Microsoft Windows
  (when (member "DejaVu Sans Mono" (font-family-list))
    (add-to-list 'initial-frame-alist '(font . "DejaVu Sans Mono-10"))
    (add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-10"))
    )
  )
 ((string-equal system-type "darwin")   ; Mac OS X
  (when (member "DejaVu Sans Mono" (font-family-list))
    (add-to-list 'initial-frame-alist '(font . "DejaVu Sans Mono-10"))
    (add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-10")))
  )
 ((string-equal system-type "gnu/linux") ; linux
  (when (member "DejaVu Sans Mono" (font-family-list))
    (add-to-list 'initial-frame-alist '(font . "DejaVu Sans Mono-10"))
    (add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-10")))
  )
 )
1
  • Thanks; I'll add what I found into the original post as an update.
    – qazwsx
    Oct 11, 2014 at 19:07
2

If you are seeing it as a white rectangle (a black hollow rectangle) then it probably means that the font of the current face used to display it does not support that character.

Try another font, which you are sure supports that character.

This page covers various ways to inspect and change fonts. Several of them let you inspect visually the effect of changing fonts before doing so, e.g., cycling among the available fonts or subsets of them.

[But you don't say what Emacs version you are using. If you are using Emacs 22 or earlier then Emacs does not have Unicode support. (That doesn't imply that it cannot show the character, but it makes things different.)]

Maybe this EmacsWiki page on fontsets will help you a bit.

1

As per the link in @Drew's answer, there are several ways to cycle through fonts to get the one you need. I use DejaVu Sans Mono and can confirm that it can display the 単 character, although I'm not sure what the analog font is on a Mac. If you have that font (or another one you can use in its place, such as Lucida Console as per one of @Drew's comments), you could evaluate the following to set the current frame's font (with a font size of 15):

(set-frame-font "DejaVu Sans Mono-15" nil t)

If that works for you, you can tell Emacs to default to that font by adding to the default-frame-alist with the following line in your init file:

(add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-15"))
3
  • Thanks. But is there a way to adapt the existing font-setting code without re-doing it? What's wrong with my original one?
    – qazwsx
    Oct 10, 2014 at 21:09
  • 1
    Take it one step at a time. Try what Dan suggests first, to see whether it works for you. If it does, then try your fontset code using DejaVu etc., to see if that works. If it does, then try the fonts you wanted in the first place. If things do not work at some point, you will know more about what the problem is that way. E.g., the problem could be the particular font, and not necessarily your code approach.
    – Drew
    Oct 10, 2014 at 23:02
  • 1
    Your point is more or less moot given the Update2 in my original post.
    – qazwsx
    Oct 11, 2014 at 5:40

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.