Warning: I’ve worked almost exclusively with Slackware. Also, I’m working on a new edition, based on Slackware 10 and more Unicode. The begin is here.
I wrote this after I upgraded to Slackware 9.1. Since there seems to be no active support for Japanese from Slackware itself, I was very glad to find the Slackware Add-on package Project. On this site, amongst other things, you can get Japanese packages made for Slackware 9.1 from this ftp directory.
So far I've only installed Canna-3.6p4-i386-3.tgz (kanjiserver), kinput2-v3.1-canna-i386-1.tgz (XIM capable inputsystem), the fonts in XFree86-jpfonts-2.1-noarch-1.tgz, and the terminals rxvt-2.7.8-i386-1.tgz and kterm-6.2.0-i386-1.tgz. For some reason kterm is broken on my system, but the rest works just fine (and rxvt seems even better than kterm).
I suppose there are lots of options, but this is what works for me.
Canna en kinput2 should be in place. Canna runs default after startup - assuming the initscript is in place in /etc/rc.d/, otherwise fix that, or start it manually with cannaserver. (Canna should come with this script, make it executable with chmod 755 [scriptname] and put it in /etc/rc.d/ if you run Slackware and don't want to start it by hand.)
Since kinput2 works in the X Window System only, it has to be started after that. If you use KDE and KDM, you can use the ~/.kde/Autostart folder to start it automatically with a small bash script (which should also be executable) like:
#!/usr/bin/bash
kinput2 -canna -xim &
If you do not use KDE (but for example Fluxbox, which is much lighter) but still use KDM to log in, it seems the new xinitscript .xprofile should be used (.xsession is by default disabled in Slackware 9.1, see - if you use Slackware - /etc/X11/xdm/Xsession). Simply put kinput2 -canna -xim & in .xprofile. (You can start it by hand with the same line as well of course.) Finding an initialisation script that actually works for you depends probably on your distribution, and on the way you start X. When using startx in Slackware .xsession or .xinitrc might work.
With these Canna and kinput2 running in the background, any XIM capable program can be used to write Japanese in. However, most of those programs need a hint that they are going to do Japanese tricks, which is done by setting the locale. It might not hurt to tell them we are using kinput2 for inputting as well. To be able to input Japanese in Mozilla, I start it with a small script (give it any name, and do chmod 755):
#!/usr/bin/bash
XMODIFIERS="@im=kinput2" LANG="ja_JP.eucJP" ~/bin/mozilla15/mozilla &
Inputting Japanese (into Google for example) is started with shift+space by default. (In my previous Mozilla the inputscreen lost focus, and I had to mouseclick the screen again, but otherwise it worked fine. With Mozilla 1.5 I’ve got no problem at all.) Conversion is with space, confirmation with enter, exit is shift+space a second time.
I've noticed that on other systems (Debian for example) the default key combintion shift+space does not always work. In that case you should define another "kanji key", which should work via xmodmap. But first you have got to select a key to use. Choose one with xev, select the keycode it displays. Then execute xmodmap -e 'keycode [some-keycode] = Kanji'. If your system allows it (few do nowadays it seems), the initfile .Xmodmap can automate that with the line keycode "[some-keycode]=Kanji". When things do not seem to work, check first a well known key, like the < sign, which is called "less". xmodmap -e 'keycode [some-keycode] = less'.
For me, first using Slackware 7 and now 9.1, shift+space always worked out of the box. (I recently learned that in a terminal or gvim ctrl+o might work as well. Not in Mozilla though.)
Mozilla contains a composer, but for writing I prefer gvim. This editor is started much like Mozilla, but it is not always able to find a suitable font on itself. When you start gvim and type :help japanese, gvim will display a text that explains it all, below I will only write what worked for me.
Note: For some reason I have had trouble with inputting Japanese in version 6.2 of gvim. Both a 6.2 version I compiled in Slackware 7 and the current GTK 6.2 version that came with Slackware 9.1 stop connecting to kinput2 almost immediately. Therefore I've compiled the 6.1 version with the Athena gui, and that one works great. To include Japanese support you've got to compile with feature "big". My configure line: ./configure --with-features=big --enable-gui=athena.
Gvim needs a "guifontset" that covers both Western and Japanese (or other multi-byte) fonts. This is possible by using lots of asteriskes. Choose a fontset, and put it in your .gvimrc like this:
if $LANG == "ja_JP.eucJP"
set guifontset=-*-mincho-medium-r-*-*-*-160-*-*-*-*-*-*
set linespace=4
endif
Making the font conditinal (whith the "if ... endif" statement) has the advantage that your default Western font won't disappear, and that you can add fonts for other languages as well. Sometimes really broad searchpatterns will work (it really depends on the fonts that are on your system I guess). Compare my lines for Chinese:
if $LANG == "zh_TW.big5"
set guifontset=-*-*-*-*-*-*-16-*-*-*-*-*-*-*
set linespace=4
endif
Font names for the X Window System contain a lot of information. The link www.pconline.com/~erc/xfonts.htm explains it adequately. While browsing your fonts, the programs xlsfonts (usage: xlsfonts -fn [some fontname] (the more asteriskes you put in the name, the more hits) or xlsfonts | grep [keyword, e.g. jis])and xfontsel (use the pull-down menu's) are nice.
After having addded a guifontset to .gvimrc for Japanese (or rather the locale you need), gvim can be started in Japanese mode just like Mozilla. For example, in a menu, the following exec line should work:
XMODIFIERS="@im=kinput2" LANG="ja_JP.eucJP" gvim -geometry 84x28 &
cat or head).
While in a terminal, you can change the locale on the fly. Just type export LANG="fr_FR". If you then type cat foo, assuming foo does not exist, the error should be "Aucun fichier ou répertoire de ce type". (This should confirm that your locale is properly set up at the same time.)
However, for Japanese I want to make sure kinput2 is identified as well, and even without that it is bothersome to type something like export LANG="ja_JP.eucJP" anyway. Calling a script would normally be the solution, but normal scripts open a new shell, and I want to modify the current shell. Using the command source does the latter. Create in your PATH a script that does not call bash, with an easy name, like "japan", and put something like the following in it:
XMODIFIERS="@im=kinput2" export XMODIFIERS; LANG="ja_JP.eucJP" export LANG; LC_ALL="ja_JP.eucJP" export LC_ALL; echo "(LANG is $LANG)"
Then type in your current terminal source japan, and it should tell you (LANG is ja_JP.eucJP). If you then start gvim, it will be in Japanese mode.
However, when I know I am going to use Japanese, I simply start rxvt directly in Japanese mode from my menu, like Mozilla as cited above. To achieve this, I start rxvt with a lot of options hidden in a short shell script, which I call from my menu (but it works from the command line as well). For example:
#!/usr/bin/bash
XMODIFIERS="@im=kinput2" LANG="ja_JP.eucJP" LC_ALL="ja_JP.eucJP" /usr/local/bin/rxvt -fm "-*-mincho-medium-r-*-*-*-160-*-*-*-*-jisx0208.1983-*"
-fn "-*-mincho-medium-r-*-*-*-160-*-*-*-*-iso8859-1"
-lsp 3
-fg "black" -bg "wheat"
-T " 日本語のrxvt"
All the options are documented in man rxvt, but to sum it up: -fn is the option for the Western font rxvt needs. -fm the Japanese font.
-lsp set vertical linespace. This is importent, because it seems that Japanese or Chinese characters don't fit well within normal linespace, which makes text diffecult to read. You may have noticed that my earlier example for gvim also contained an option for linespace in .gvimrc: set linespace=4. Finally, the option -T allows you to give the titelbar a different name. If your windowmanager allows it, you can use Japanese.
Most of the resources of rxvt can also be set in .Xdefaults, so that you don't have to fill in all the options. I am not sure if this script is still actively sourced in all distributions, but it is in Slackware. For my default rxvt I added lines like:
rxvt*background: wheat
rxvt*foreground: black
rxvt*font: -*-mincho-medium-r-*-*-*-160-*-*-*-*-iso8859-1
But if you start rxvt with the option -name you can call alternate configurations al well. For example, rxvt -name "rxvt2" sources the corresponding lines in .Xdefaults:
rxvt2*background: wheat
rxvt2*foreground: black
rxvt2*font: -*-mincho-medium-r-*-*-*-160-*-*-*-*-iso8859-1
rxvt2*mfont: -*-mincho-medium-r-*-*-*-160-*-*-*-*-jisx0208.1983-*
Illustrations: 1. rxvt as configured above.
One of the reasons for me to start using Linux in the mid 1990s was that for some reason high resolution printing in Japanese with Linux works very well. Not all distro's (an certainly not Slackware) provide it by default, but it is quite easy to install. Just download the Ghostscript package gs6.0.kanji.tar.gz (from www.enel.ucalgary.ca/People/far/howto/gs/gs6.00/, or do a search with http://www.filewatcher.com/).
The package contains the files of the font and the file Fontmap.kanji. The font needs to go to the fontdir of Ghostscript (in Slackware 9.1 /usr/share/ghostscript/fonts/). The contents of the file Fontmap.kanji could replace that of Fontmap.GS (in Slackware 9.1 located in /usr/share/ghostscript/7.05/lib/), but since the versions of Ghostscript differ I prefer to add only the lines relating to the Kanjifont to the end of Fontmap.GS (that part begins with "/min-21ku (min-21ku.gsf) " and ends with "/Ryumin-Light-90ms-RKSJ-H /min-RKSJ" - I think). Save the modified Fontmap.GS and you're done!
Well, if you have printing set up that is. The failsave method for Slackware is still using the SETUP script of apsfilter (currently located at /usr/share/apsfilter/SETUP) but other methods might work as well. Make sure that lpd is running and re_started after aspfilter setup. Remember the name you give to your printer (default lp in apsfilter) for the print command (lpr -Plp filename). Take note that for printing in Japanese you use a Ghostscript font. I don't know how to choose the font from the command line, but programs like Mozilla know how to use the Japanese Ghostscript font. Mozilla can not only be used to print HTML, but plain text as well.
Printing Japanese with LaTeX: In Slackware 9.1 not yet enabled by default, but using the instructions of Pai H. Chou’s How to make LaTeX (teTeX) handle unicode and CJK in MacOSX, I succeeded in adding utf-8 capability to LaTeX in Linux Slackware 9.1. I keep a local copy of that rather helpfull little howto here, just in case.
Last updated: Wed Oct 27 2004