Here I will show you how to configure XTerm so that it uses nice TTF fonts, uses UTF8 encoding, and shows Chinese characters (or any Unicode characters, for that matter).

After unsuccessful search on the internet, I have decided to explore the solution myself. However, you cannot find anything useful on this topic in official XTerm documentation.

The solution

Put the following code into your .Xresources file:

XTerm*utf8: true
XTerm*faceName: DejaVu Sans Mono Book
XTerm*faceNameDoublesize: WenQuanYi Zen Hei Mono
XTerm*faceSize: 14
! workaround of disappearing underscore ('_') character
XTerm*scaleHeight: 1.01

Apply the changes:

xrdb -merge ~/.Xresources

Now run XTerm and see the changes.

The explanation:

First line

XTerm*utf8: true

instructs XTerm to use UTF8 initially.

Now we need to setup TTF fonts. It can be any TTF font, but I suggest you to use monospaced one.

XTerm*faceName: DejaVu Sans Mono Book

Now important part: how to show chinese characters: You need no set the following property:

XTerm*faceNameDoublesize: WenQuanYi Zen Hei Mono

The value is Chinese TTF font. But how to know the correct name? Just open up your LibreOffice and choose some Chinese monospaced font, and in font chooser there will be name. Just copy it from there.

You can also choose the font size:

XTerm*faceSize: 14

Well, 14 is the default size, so in this case this is unnecessary.

Next you may notice that underscore character is not showing anymore. Add this:

! workaround of disappearing underscore ('_') character
XTerm*scaleHeight: 1.01

As explained by XTerm developers, this is bug in Xft or some other font lib where it calculates the character bounding box wrongly. Then XTerm developers added this option to modify the value of bounding box somehow.

Note about colors

For a long time I liked the tango color scheme, it’s really nice and smooth. But recently, I started to use LED matrix and one day accidentally switched to standard Linux color scheme, and was quite surprised how nice the colors are! They are vivid and brilliant; since then I use standard colors on LED displays and tango on others. If you have LED matrix, you may try the standard color scheme and see if you like it.

Bonus: setup GNU Screen and Vim

If you use GNU Screen you need to tell it to use UTF8 encoding also. Add this to your .screenrc:

defutf8 on

And If you use Vim you also need to tell it to use UTF8. Add this to your .vimrc:

set enc=utf-8

All done and set. Hope this helps.

Leave a Reply

Close Menu