Chinese System Setup in Linux

There are quite a number of different ways you can set up your Linux to read and write Chinese. Most mordern Linux distributions come with Chinese font by default (at least some GB2312 fonts), and browsing Chinese web sites is no long an issue.

Chinese Input

Here is one example of setting a Chinese system for input under Slackware 9.0.

  • download, compile and install Fcitx. I used to use minichinput, but it has some wierd bug and doesn’t seem to be maintained actively.
  • download, compile and install mlterm. There are a few other terminal emulators that work well with X Input, but after testing Xterm, Rxvt and iTerm, I finally settled upon mlterm, which almost works out-of-box without any tweaking.
  • edit ~/.bashrc to have
export XMODIFIERS=@im=fcitx
unset LC_ALL
  • start fcitx before everything else. In my case, I insert the below line in my GDM startscript for Ion. Likewise, you can have it in ~/.Xclients before your favorite window manager’s starts.
LC_ALL=zh_CN.GB2312 fcitx
  • mlterm can be started with
LC_ALL=zh_CN.GB2312 mlterm
  • both opera and mozilla supports input if you run them properly
LC_ALL=zh_CN.GB2312 opera
LANG=zh_CN.GB2312 mozilla

Please note that all the LC_ALL and LANG stuff in the above is a bit hackish. On Redhat Linux 9, you simply need LANG=zh_CN.GB2312 mlterm to enable Chinese input via fcitx in mlterm. But somehow, it doesn’t work in Slackware 9.0, so I’m forced to use LC_ALL=zh_CN.GB2312 mlterm to start mlterm and reset LC_ALL in my .bashrc so that the usual date and locale settings are still English. It is also wierd that opera must be started with LC_ALL to receive Chinese input, while mozilla can do with only LANG setting. I also notice some wierdness of readline in bash under Redhat Linux 9.0, it no longer allows 8-bit clean inputs under its default locale setting.

In short, you may always try the LANG setting first, as it is the most non-intrusive. If that fails, then try LC_ALL setting. If you still prefer English environment and just want Chinese input only, you may reset LC_ALL in ~/.bashrc.

To input Chinese on normal command line under bash, the simple way is just

export LC_ALL=zh_CN.GB2312

This will change how ls sorts its output too. If that doesn’t work for you, try this too:

cat > ~/.inputrc << END
set meta-flag On
set convert-meta Off
set output-meta On

This is a setup for readline to accept 8-bit characters. On Slackware 9.0, the ~/.inputrc file alone works fine for me, but seems that on Redhat 9.0, the only way to do it is to set the LC_ALL.

I used to have Cxterm as a Chinese environment, but no longer.

Chinese Typesetting

There is a CJK Package for Latex, and you’ll need to set up Chinese fonts for Latex separately. Most guides I found on the web are overly complex, but it’s rather simple to setup once you understand what it needs. The following is done under tetex-3.0, but may also apply to other Latex environments.

For font installation, I use a tool called gbkfonts (not sure about its origin, but I got one from He Bo Liang’s homepage). I use the statically compiled version without going through the compilation.

Then you’ll need a set of Chinese Truetype fonts. I use the Microsoft YaHei font from Vista. Here is an example of what I do.

Install CJK Package

Download the latest CJK package. For example, I use cjk-4.7.0.tgz. Become root and do:

TEXDIR=/usr/share/texmf-local   # or you can use /usr/share/texmf
mkdir -p $TEXDIR/tex/latex
tar zxf cjk-4.7.0.tar.gz
mv cjk-4.7.0/texinput $TEXDIR/tex/latex/CJK

Install Chinese Type1 Font to Tetex

Copy gbkfonts binary and your Truetype fonts to a temporary directory, become root and do the following

./gbkfonts msyh.ttf yahei       # repeat it if you have more fonts
mkdir -p $TEXDIR/fonts/afm $TEXDIR/fonts/tfm $TEXDIR/fonts/type1 $TEXDIR/fonts/map/chinese
mv ./tex/latex/CJK/GB/* $TEXDIR/tex/latex/CJK/GB/
mv ./fonts/afm/chinese $TEXDIR/fonts/afm/
mv ./fonts/tfm/chinese $TEXDIR/fonts/tfm/
mv ./fonts/type1/chinese $TEXDIR/fonts/type1/
mv $TEXDIR/fonts/map/chinese/
echo "Map" >> /usr/share/texmf/web2c/updmap.cfg

The above installs the font metrics and the Type1 fonts with tetex and CJK, and then updates the map file setting to let it find them. You don’t even need the TTF file to be installed with tetex if you are not going to use dvipdfmx.

Use CJK Package in Latex

After the above setup, you may refresh tetex by:

updmap-sys                # do this as root, or updmap as an user

For a test, you may write a Tex document like this:

Comments powered by Disqus