Friday, October 8, 2010

tmux

In one of my articles, I wrote about GNU screen. I was looking for a terminal multiplexer and GNU screen provided me that. After using GNU screen for a while, I heard of tmux, another terminal multiplexer which is newer and easier to customize. GNU screen's language for customization is very hard to understand. Every time I wanted to customize something, I just couldn't find the way of doing it is screen. However, in tmux the language for customization is very easy to understand. It is well documented. So, I switched to tmux from screen. Also tmux has many advantages over screen. Some of them are as follows.
  1. Supports vertical splitting of window
  2. Any number of splitting of window is possible
  3. Better session management
  4. Easy to understand customization interface
  5. Lighter and faster
One problem with tmux is it is not installed by default on linux machines. So, when I need to work at any remote machine I have rely on GNU Screen. 

viper-mode in emacs

I love vi for its simplicity. Vi is a very powerful tool. I use vim (Improved vi) to edit program files. It saves a lot of my time. But, vim has a drawback. Vim does not support Japanese input very well. In vim one have to use ESC key frequently. When you use scim-anthy to input Japanese, after pressing ESC you cannot use the movement commands because of the Japanese character inputs. You have to stop Japanese IME and then move around the file.

For the above reason, I use Emacs to edit Japanese files mainly latex files. In my lab, I need to make materials for meetings in Japanese. In Emacs you can use plug-ins for latex file editing. It makes editing latex files very easy. I am quite happy with my latex plug-in (Yatex) in Emacs.

But, Emacs functions to move around a file is little bit complex. Vim style of movement suites me more that Emacs style. That is why I was desperately looking for a solution to edit Japanese files in Vim seamlessly (Without turning on/off the IME). While searching I found the following thing.

Emacs has a plug-in named "viper-mode" which emulates vi in Emacs. The first time I saw this, I knew that this is the solution what I wanted. Using this plug-in, now I can use all the Emacs functions and at the same time I can move around the file and edit file in vi style. Its just like a dream.

I have just started using this. I need to learn few things to customize it to my likings. But for now, I am happy to find this.

Monday, September 20, 2010

kpdfとxpdfで日本語の表示

日本語文章の編集するためのlatex環境を作りました。latexをコンパイルするためのパッケージなどはネットでいろいろなところにあるので、ここで省略します。ここで、コンパイル後の表示についてメモしておきます。

まず、dviファイルの表示についてですが、pxdviが標準だと思います。しかし、pxdviのグラフィックスあまりきれいではないということで、別のソフトを探しました。探した結果、kdviというのがありました。kdviはKDE desktopの1つのソフトで、見た目はpxdviに比べて非常にきれい。しかし、kdviは日本語に対応したいないのが残念なことです。私は研究室でのミーティング資料で日本語を使うため、どうしようと考えていました。そこで、じゃ、dvi viewerで見るのではなく、dviファイルをpdfファイルに変換してからpdfファイルを見ればいいんじゃないと思いました。pdfファイルだと、acrobat readerでも見れるし、evinceでも見れます。じゃ、使って見ると、あることが面倒くさくなりました。それは、texファイルをコンパイルする毎に、acroreaderあるいはevinceをreloadしないといけないことです。慣れてしまえば、大したことではないが、tex editorから離れたくないということで、pdfファイルの中身が変わると自動てきにファイルをreloadする機能はないかを調べました。

その結果、kpdfとxpdfはpdfファイルを自動的にreloadする機能がついていることがわかりました。acrobat readerはその機能はなく、evinceは自動的にファイルをreloadする機能を持っているとネットで書いてありますが、私の環境(CentOs 5.4)で動作しないです。私はKDEデスクトップを使っているため、kpdfは元々入っていました。kpdfは見た目がよく、非常に軽いpdf viewerです。しかし、kpdfでは日本語の文字が化けてしまいます。最後のオプションであるxpdfをインストールすることにしました。

xpdfのインストール
  1. EPELを入れる
  2. sudo yum install xpdf
以上の手順で非常に簡単にxpdfをインストールできました。EPELのインストールする方法について
次のサイトを参考にしました。


インストールしたxpdfでは日本語の表示ができませんでした。ネットで調べた結果、xpdfで日本語のフォントの表示用の設定ファイルがxpdfのホームページで提供されています。ここから日本語設定パッケージをダウンロードしました。手順としてはいくつかのファイルを/usr/local/share/xpdf/japaneseディレクトリに入れ、/usr/local/etc/xpdfrcあるいは~/.xpdfrcファイルを作成する。私のxpdfrcファイルの中身は次のようになりました。
#----- begin Japanese support package (2004-jul-27)
cidToUnicode    Adobe-Japan1    /usr/local/share/xpdf/japanese/Adobe-Japan1.cidToUnicode
cMapDir     Adobe-Japan1    /usr/local/share/xpdf/japanese/CMap
toUnicodeDir            /usr/local/share/xpdf/japanese/CMap

displayNamedCIDFontTT Ryumin-Light-Identity-H /usr/share/fonts/japanese/TrueType/sazanami-mincho.ttf
displayNamedCIDFontTT GothicBBB-Medium-Identity-H /usr/share/fonts/japanese/TrueType/sazanami-gothic.ttf

#displayCIDFontTT   Adobe-Japan1    /usr/..../kochi-mincho.ttf
#----- end Japanese support package
ここで、displayNamedCIDFontTTの設定のポイントです。displayNamedCIDFontTTは元々のパッケージに入っていなかったため、手動で入れる必要があります。この設定をしないと、dvipdfmxでpdfを作成した後、xpdfでファイルを開くと、次のようなエラーメッセージで出ます。


Error: Couldn't find a font for 'Ryumin-Light-Identity-H'
Error: Couldn't find a font for 'GothicBBB-Medium-Identity-H'

このエラーはフォントが見つからないというエラーなので、フォントの場所を教える必要があります。
上のdisplayNamedCIDFontTTでその場所を教えています。後、どのフォントファイルを使うかはlinux環境によって異なります。私はTrueTypeフォントは場所を探し、そこからminchoとgothicのフォントファイルをしています。これで、xpdfで日本語の文字がきれいに見えるようになりました。

で、最後に、以上の設定が完了した後、kdviで日本語の文字が含まれているpdfファイルを開くと日本語の文字が見えるようになりました。これはすごい。kdviはxpdfの設定ファイルを読んでいるようです。これでkdviで日本語の見えるようになったので、kdviを使うことにしました。

Thursday, August 19, 2010

My Typing Speed

Some days ago, I just wondered about my typing speed. So, I took a simple typing speed test on the web. I used the following website to take the test.

http://speedtest.10-fast-fingers.com/

Here is my result.

68 words
Typing Test

Not a bad one. But there are people who have typing speed near 100 wpm. The world record for the fastest typing speed is 216 by Stella Pajunas-Garnand on an IBM machine. I just wonder how fast that can be.

I have set my target for myself. Now, my typing speed varies from 60 to 70. I want a constant typing speed of near or more than 80. I make some mistakes also during typing. I have to be 100% accurate. It will need practice. May be I have some problems with my basics. So, I have started from the basics. I am having a lot of fun with it now. I hope that I can reach my target.

Friday, July 30, 2010

Unix File Redirection: How to Overwrite an Existing File

I have set my tc shell settings so that when ever I try to redirect command output to an existing file, it gives me an warning. The reason for why I am using this option is that while redirecting to a file, you loose all the contents of the file. If you make a mistake while typing the file name, this can lead to very dangerous outcome. Because that file may contain data whose backup you don't have.

But, this option has some drawbacks also. That is when you want to rewrite a file by redirect to it. The problem is every time you try to do this, you are given an warning. What you have to do is to remove the file first, then redirect to that file. Two steps become involved which eats many time. But, today I have found that there is a way to perform these steps by just one. It is adding the "!" sign at the end of ">" sign. Here is the example.

% echo hello world! > test.txt
% cat test.txt
hello world!
% echo again hello world > test.txt
test.txt: File exists.
% echo again hello world >! test.txt
% cat test.txt
again hello world!


In this example, I first redirect the output of the command "echo" to file "test.txt". As "test.txt" file does not exist, shell creates a new file and writes the output to this file. Next, I redirect the output of another "echo" command to this same file and this time, shell gives me an warning. Now, if I do this by adding the "!" sign after ">", shell overwrites the existing file and writes the new output result to that file. This trick will surely save a lot of my time.

Wednesday, July 28, 2010

Embedding formatted code into webpage

I wanted to write a post on ruby option parser. I wanted to add some code to the post but then I realized that Google Blogger does not provide any tool for formatting code and syntax highlighting. It would be so nice to have a tool for embedding program codes into the blog. At first, I became frustrated with Blogger, then began to search for some solutions.

After some searching, I found the solution which I liked very much. Its vim's "TOhtml" feature. I liked this feature because I use vim for code writing. So, I do not have to go to any other tool. Next, it converts the code into html format which I can embed in any webpage which is great.

But, the default html from vim's TOhtml did not look very clean. It seems that the color I see in my terminal and the color I see in browser are quite different. I found this article which gives an guideline on how can we change the html output by doing some simple vim scripting. I almost followed his way completely, except that he used a different color scheme plugin for vim where I decided to change the style sheet for changing the look. Here's one example of ruby code outputed using the vim's TOhtml feature.

$VERBOSE = nil
require 'gnuplot'

outfile = "test.obj"
plot = Plot.new
x = (0..50).to_a
y = x.collect { |v| v**2 }
data = DataSet.new([x,y])
plot.data << data
plot.term "tgif"
plot.output outfile
plot.plot

Isn't it clean enough? I like it. It's easy to do. Run command in vim, copy the code and then paste in the Blogger. I am hoping to post articles on programming languages from now on and this method will give me a good boost.

Tuesday, June 15, 2010

GNU Screen

It has been two years since I switched to linux from windows. And ever since the first day, I liked linux and liking linux more day by day. I use mainly vi to edit files (especially program files) on the terminal. Sometimes, I feel the need of several terminals. Present linux desktops provide tab based terminal interface which served my need for a while. But switching between the tabs takes times and not that convenient. I wasn't satisfied with it. I was hoping for some tools to give me an interface like vi where I can split to multiple windows, hide windows, switch between windows easily. And it would be very good to be able to make sessions and use them as I use buffers in vi. Guess what, I just found that tool of my dream. Its the "GNU screen". Its really amazing. It gave me everything that I wanted for. Here are some of the features of screen.
  1. Create multiple sessions, switch between the session
  2. Split the window into several windows, switch between the windows
  3. Copy/paste region of text on the screen without using mouse. I couldn't do it on conventional terminal.
  4. Detach session and attach the session again. In this way you can save your session and use it in later time. Its like the vncserver.
  5. And many more.....
One problem I had with the screen is its default escape keystroke which is Ctrl-A. I use Ctrl-A a lot to move to the beginning of a line in command line and emacs. I need this key stroke very much. But, screen is customizable and you can remap the keystrokes. So, I mapped the escape command to Ctrl-U. I did this by adding the following line in the .screenrc file.
escape ^Uu
Next, I wanted to use the j,k keys to move between the windows and did this by adding the following lines.
bind j focus down
bind k focus up
bind t focus top
bind b focus bottom
I wish to write a lot about the screen but because of my shortage of time, I would like to refer to the following site.
http://www.gnu.org/software/screen/