How to create a Japanese language text file using emacs

Mark Alford. Last updated: 2011-Oct-17.

Simplest method

  1. To go to Japanese input mode in emacs, type CTRL-\ , then when it asks for a coding system type "japanese". After that, typing CTRL-\ will toggle back and forth between English and Japanese input methods.
  2. How to enter Japanese text.
    Once you have set the input method to Japanese, you can type in romaji, and it will come out as hiragana, underlined. The underlined bit is the "conversion region", which is still malleable, i.e. not yet fixed. To fix it, and start a new conversion region, press return. To convert it to katakana, type "K" (uppercase). To toggle among a range of kanji for the conversion region, keep pressing space. (To go back and forth in the kanji list use CTRL-P and CTRL-N.) When you get the correct kanji, press Return to fix it. To get a Japanese "n" type "n" then some non-vowel like "q" (after that you can type "K" for Katakana) then Return to fix it. (For Hiragana "n", the non-vowel can be "n" itself.)
  3. To save the file just do the usual CTRL-X CTRL-C. By default emacs uses Unicode encoding for the Japanese characters.
  4. Selecting an appropriate font. You may find that the default font used by emacs is not satisfactory. Many of the font families used by my emacs installation contain simplified Chinese rather than Japanese characters, so they displayed some characters incorrectly, such as 5 Japanese kanji. To fix this, force emacs to use an appropriate font for Japanese characters, such as VL_Gothic. To do this, in your .emacs file, add the following:
    (set-fontset-font (frame-parameter nil 'font)
      'japanese-jisx0208
      '("VL Gothic" . "unicode-bmp"))
    
    (To see what font emacs is using for Japanese characters, position the cursor over one of them and run the describe-char command, by typing CTRL-u CTRL-X = or alternately by ESC x describe-char.)

Alternate method

You can tell emacs what encoding system to use and what input method to use by specifying them in a special line at the top of the file, e.g:

%-*- coding: utf-8; current-input-method: japanese -*-
This is in English.
これは 日本語 です。

Possible codings include utf-8 (Unicode), japanese-euc, japanese-shift-jis, emacs-mule, etc. With this first line, emacs will automatically detect the coding and display the characters correctly. Without it, emacs will probably auto-detect Unicode anyway.

When you open your file (something like the example above) using emacs, it may warn you that some of the local variable values may not be safe, just type "y" to accept them. You can then switch to Japanese input method by typing CTRL-\ twice, ignoring the "value is nil" message. After than things work as described under "Simplest method" above.


For more general information on Japanese and computing, see Jim Breen's Japanese page.

Please sent comments, corrections, improvements to alford(at)physics.wustl.edu. Thanks to those who have done so, including Paul Wyatt of Toshiba and Andrew A. Adams of Reading University.

Mark Alford's IBM Thinkpad GNU/Linux page,

Valid XHTML 1.0!