2010年11月30日火曜日

クールな等幅フォント

最近Schemeを始めました.SchemeやLispといえば,括弧の嵐ですよね.
エディタで等幅じゃないフォントを使っていると,死ぬほど読みづらい.
そこで,クールな等幅フォントを入れて使ってみました.

[参考]
7 Of The Best Ubuntu Terminal (Fixed Width) Fonts

この中から,Inconsolataを選び,インストールしました.

sudo apt-get install ttf-inconsolata

で,~/.emacs に次の行を追加.

(add-to-list 'default-frame-alist
'(font . "-unknown-Inconsolata-normal-normal-normal-*-11-*-*-*-*-0-iso10646-1"))


些細なことだけど,かなりコーディング満足度が上がりました.

2010年11月21日日曜日

漢字を含むps,epsファイルをps2pdfで変換できない問題の解消

gnuplotで作成したEPSファイルを含んだtexファイルをPDFにしようとしたところ,ps2pdfコマンドでSegmentation fault が起こるために失敗しました.

ウェブで探すと,一回 ps2ps を介すると大丈夫なようですが,EPSファイル中のフォントがきもくなるので,何とか解決策を探りました.

「ps2pdf segmentation fault」とかでぐぐって分かりましたが,ファイルによってはps2pdf12 なら変換可能で、ps2pdf13 や ps2pdf14 (ps2pdf)、ps2pdfwr だとSEGVするらしいです.
http://vdr.jp/d/20100802.html

そこで,次のように対処しました.真似される方は自己責任でおねがいします.

  1. which ps2pdf コマンドで,/usr/bin/ 以下に ps2pdf* があることを確認
  2. sudo rm /usr/bin/ps2pdf
  3. sudo ln -s /usr/bin/ps2pdf12 /usr/bin/ps2pdf

これで,ps2pdf hoge.eps とかは成功するようになります.

しかし,これだけでは dvipdfmx が失敗することがあります.dvipdfmx が ps2pdf コマンドを呼び出すときに,-dCompatibilityLevel=1.4 とかいうオプションをつけているからなようです.
このオプションがつくと,実質的に ps2pdf14 コマンドを呼び出しているのと同じ動作をしている模様.(憶測)

そこで,このオプションを,-dCompatibilityLevel=1.2 に変更します.

  1. dvipdfmx.cfg という設定ファイルを探す.当環境では /usr/local/teTeX/share/texmf/dvipdfmx/dvipdfmx.cfg にありました
  2. エディタで開き,"Compatiblitity"とかで検索し,-dCompatibilityLevel=1.4 を -dCompatibilityLevel=1.2 に変更し保存

これで漢字を含むPS,EPSファイルを使ったtexファイルでも,問題なくPDF化できるようになるのではと思います.

2010年11月14日日曜日

awesome WM の導入と設定

ウィンドウマネージャ(WM)なんて,Gnomeで何も問題を感じていなかったのですが,「タイル型WM」なる全く異なるコンセプトのWMがあると聞き,導入してみました.

今回導入したのは,awesome WM です.

awesome WMの特徴(主観)
  • タイル型WMのジャンルで,Xmonad というWMと双璧をなす人気らしい
  • 設定がLuaという,比較的簡単なプログラミング言語で,柔軟に設定可能
  • タイル型なだけあり,ウィンドウが重ならない.
  • キーボードショートカットを覚えると,本格的にマウス不要になる.
  • Gnomeでいうワークスペース的な機能を「tag」という形で自然に取り込んでいて,画面を論理的に切り替えられる



こんな感じにできます(スクリーンショット)


導入


パッケージをダウンロード
-
sudo apt-get install awesome




/etc/X11/Xsession.d/40x11-common_xsessionrc を以下のように編集
(このあたりはだいぶ環境依存のはずです.)
-
# This file is sourced by Xsession(5), not executed.

#Source user defined xsessionrc (locales and other environment variables)
# if [ -r "$USERXSESSIONRC" ]; then
#   . "$USERXSESSIONRC"
# fi

source /home/sho/.xinitrc



~/.xinitrcを,以下のように作成・編集
-
#!/bin/sh

exec awesome




設定ファイルの作成
-
mkdir .config/awesome
cp /etc/xdg/awesome/rc.lua ~/.config/awesome/




この時点で一旦ログアウトして,「セッション」をawesomeに指定し,ログインする.
以下,自分好みの設定



CPUやメモリの状態を表示させる
- Visiousをダウンロード,解凍し,~/.config/awesome/visious という名前のディレクトリに移す
- rc.luaの変更箇所(変更箇所の周りの記述で検索かけてください):
--
-- Load Debian menu entries
require("debian.menu")
-- For dynamic widgets
require("vicious")
--
-- Create a systray
mysystray = widget({ type = "systray" })

refreshdelay = 1
-- memwidget
-- text
memtext = widget({ type = "textbox" })
memtext.text = ' mem '
-- bar
membar = awful.widget.graph()
membar:set_width(50)
membar:set_height(17)
membar:set_background_color("#494B4F")
membar:set_border_color(nil)
membar:set_color("#004080")
membar:set_gradient_colors({ "#004080", "#006699", "#CCCCFF" })
vicious.register(membar, vicious.widgets.mem, "$1", refreshdelay)
-- // memwidget

-- cpuwidget
-- text
cputext = widget({ type = "textbox" })
cputext.text = ' cpu '
-- graph
cpugraph = awful.widget.graph()
cpugraph:set_width(50)
cpugraph:set_height(17)
cpugraph:set_background_color("#494B4F")
cpugraph:set_color("#004080")
cpugraph:set_gradient_colors({ "#004080", "#006699", "#CCCCFF" })
vicious.register(cpugraph, vicious.widgets.cpu, "$1", refreshdelay)
-- // cpuwidget


-- Create a wibox for each screen and add it
--
      mylayoutbox[s],
      mytextclock,
      s == 1 and mysystray or nil,
      -- I added the followings.
      membar.widget,
      memtext,
      cpugraph.widget,
      cputext,

      mytasklist[s],

[参考] http://samemiso.blogspot.com/2009/12/awesome-34cpumem.html



テーマ(beautiful)の設定
- http://awesome.naquadah.org/wiki/Beautiful_themes から,zhuravlik を拝借
--
sudo mkdir /usr/share/awesome/themes/zhuravlik
-- /usr/share/awesome/themes/zhuravlik/theme.lua を以下のように作成・編集
---
---------------------------
-- Default awesome theme --
---------------------------

theme = {}

theme.font          = "sans 8"

theme.bg_normal     = "#f7f7f7ee"
theme.bg_focus      = "#535d6cee"
theme.bg_urgent     = "#ff0000ee"
theme.bg_minimize   = "#444444ee"

theme.fg_normal     = "#535d6c"
theme.fg_focus      = "#ffffff"
theme.fg_urgent     = "#ffffff"
theme.fg_minimize  = "#ffffff"

theme.border_width  = "1"
theme.border_normal = "#000000"
theme.border_focus  = "#535d6c"

-- There are other variable sets
-- overriding the default one when
-- defined, the sets are:
-- [taglist|tasklist]_[bg|fg]_[focus|urgent]
-- titlebar_[bg|fg]_[normal|focus]
-- tooltip_[font|opacity|fg_color|bg_color|border_width|border_color]
-- mouse_finder_[color|timeout|animate_timeout|radius|factor]
-- Example:
--theme.taglist_bg_focus = "#ff0000"

-- Display the taglist squares
theme.taglist_squares_sel   = "/usr/share/awesome/themes/default/taglist/squarefw.png"
theme.taglist_squares_unsel = "/usr/share/awesome/themes/default/taglist/squarew.png"

theme.tasklist_floating_icon = "/usr/share/awesome/themes/default/tasklist/floatingw.png"

-- Variables set for theming the menu:
-- menu_[bg|fg]_[normal|focus]
-- menu_[border_color|border_width]
theme.menu_submenu_icon = "/usr/share/awesome/themes/default/submenu.png"
theme.menu_height = "15"
theme.menu_width  = "100"

-- You can add as many variables as
-- you wish and access them by using
-- beautiful.variable in your rc.lua
--theme.bg_widget = "#cc0000"

-- Define the image to load
theme.titlebar_close_button_normal = "/usr/share/awesome/themes/default/titlebar/close_normal.png"
theme.titlebar_close_button_focus  = "/usr/share/awesome/themes/default/titlebar/close_focus.png"

theme.titlebar_ontop_button_normal_inactive = "/usr/share/awesome/themes/default/titlebar/ontop_normal_inactive.png"
theme.titlebar_ontop_button_focus_inactive  = "/usr/share/awesome/themes/default/titlebar/ontop_focus_inactive.png"
theme.titlebar_ontop_button_normal_active = "/usr/share/awesome/themes/default/titlebar/ontop_normal_active.png"
theme.titlebar_ontop_button_focus_active  = "/usr/share/awesome/themes/default/titlebar/ontop_focus_active.png"

theme.titlebar_sticky_button_normal_inactive = "/usr/share/awesome/themes/default/titlebar/sticky_normal_inactive.png"
theme.titlebar_sticky_button_focus_inactive  = "/usr/share/awesome/themes/default/titlebar/sticky_focus_inactive.png"
theme.titlebar_sticky_button_normal_active = "/usr/share/awesome/themes/default/titlebar/sticky_normal_active.png"
theme.titlebar_sticky_button_focus_active  = "/usr/share/awesome/themes/default/titlebar/sticky_focus_active.png"

theme.titlebar_floating_button_normal_inactive = "/usr/share/awesome/themes/default/titlebar/floating_normal_inactive.png"
theme.titlebar_floating_button_focus_inactive  = "/usr/share/awesome/themes/default/titlebar/floating_focus_inactive.png"
theme.titlebar_floating_button_normal_active = "/usr/share/awesome/themes/default/titlebar/floating_normal_active.png"
theme.titlebar_floating_button_focus_active  = "/usr/share/awesome/themes/default/titlebar/floating_focus_active.png"

theme.titlebar_maximized_button_normal_inactive = "/usr/share/awesome/themes/default/titlebar/maximized_normal_inactive.png"
theme.titlebar_maximized_button_focus_inactive  = "/usr/share/awesome/themes/default/titlebar/maximized_focus_inactive.png"
theme.titlebar_maximized_button_normal_active = "/usr/share/awesome/themes/default/titlebar/maximized_normal_active.png"
theme.titlebar_maximized_button_focus_active  = "/usr/share/awesome/themes/default/titlebar/maximized_focus_active.png"

-- You can use your own command to set your wallpaper
theme.wallpaper_cmd = { "feh --bg-scale /home/sho/document/wallpaper/Atmo.jpg" }

-- You can use your own layout icons like this:
theme.layout_fairh = "/usr/share/awesome/themes/default/layouts/fairhw.png"
theme.layout_fairv = "/usr/share/awesome/themes/default/layouts/fairvw.png"
theme.layout_floating  = "/usr/share/awesome/themes/default/layouts/floatingw.png"
theme.layout_magnifier = "/usr/share/awesome/themes/default/layouts/magnifierw.png"
theme.layout_max = "/usr/share/awesome/themes/default/layouts/maxw.png"
theme.layout_fullscreen = "/usr/share/awesome/themes/default/layouts/fullscreenw.png"
theme.layout_tilebottom = "/usr/share/awesome/themes/default/layouts/tilebottomw.png"
theme.layout_tileleft   = "/usr/share/awesome/themes/default/layouts/tileleftw.png"
theme.layout_tile = "/usr/share/awesome/themes/default/layouts/tilew.png"
theme.layout_tiletop = "/usr/share/awesome/themes/default/layouts/tiletopw.png"
theme.layout_spiral  = "/usr/share/awesome/themes/default/layouts/spiralw.png"
theme.layout_dwindle = "/usr/share/awesome/themes/default/layouts/dwindlew.png"

theme.awesome_icon = "/usr/share/awesome/icons/awesome16.png"

return theme
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
---- theme.wallpaper_cmd = { "feh --bg-scale /home/sho/document/wallpaper/Atmo.jpg" } の行は自分で設定する必要あり
---- 壁紙は,feh --bg-scale /path/to/wallpaper で設定.何個か試して,これだけうまくいった.

-- rc.luaの変更箇所(変更箇所の周りの記述で検索かけてください):
---
-- {{{ Variable definitions
-- Themes define colours, icons, and wallpapers
beautiful.init("/usr/share/awesome/themes/zhuravlik/theme.lua")



使わないレイアウトをコメントアウト
- rc.luaの変更箇所(変更箇所の周りの記述で検索かけてください):
--
-- Table of layouts to cover with awful.layout.inc, order matters.
layouts =
   {
   --    awful.layout.suit.floating,
   awful.layout.suit.tile,
   awful.layout.suit.tile.left,
   --    awful.layout.suit.tile.bottom,
   --    awful.layout.suit.tile.top,
   --    awful.layout.suit.fair,
   --    awful.layout.suit.fair.horizontal,
   --    awful.layout.suit.spiral,
   awful.layout.suit.spiral.dwindle,
   awful.layout.suit.max,
   --    awful.layout.suit.max.fullscreen,
   awful.layout.suit.magnifier
}
-- }}}



tagに名前をつける
- rc.luaの変更箇所(変更箇所の周りの記述で検索かけてください):
--
-- Define a tag table which hold all screen tags.
tags = {
   names = { "1.work", "2.dev", "3.web", "4.study", "5.skype", "6.twitter", 7, 8, 9 },
   layout = { layouts[2], layouts[2], layouts[2], layouts[2], layouts[2],
              layouts[2], layouts[2], layouts[2], layouts[2] }
}



メニューの編集
- rc.luaの変更箇所(変更箇所の周りの記述で検索かけてください):
--
mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
                                    { "Ubuntu", debian.menu.Debian_menu.Debian },
                                    { "Shutdown", function () awful.util.spawn_with_shell("gksu 'shutdown -h now'") end  },
                                    { "Reboot", function () awful.util.spawn_with_shell("gksu 'reboot'") end  },
                                    { "Suspend", function () awful.util.spawn_with_shell("gksu 'pm-suspend'") end  }
                                 }
                       })

mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
                                     menu = mymainmenu })
-- }}}



アプリごとに表示するタグを設定
- rc.luaの変更箇所(変更箇所の周りの記述で検索かけてください):
--
  -- Set skype to always map on tags number 5 of screen 1.
   { rule = { name = "Skype" },
     properties = { tag = tags[1][5] } },
   -- Set peraperaprv to always map on tags number 3 of screen 1.
   { rule = { name = "PeraPeraPrv" },
     properties = { tag = tags[1][6] } },
   -- Set Firefox to always map on tags number 2 of screen 1.
   -- { rule = { class = "Firefox" },
   --   properties = { tag = tags[1][2] } },

-- class = "hoge" に入れる文字列は,以下のようにして調べる.
--- xprop コマンドを起動
--- 調べたいアプリのウィンドウをクリック
--- WM_CLASSの2つめの文字列が目的の文字列



awesome WM起動時に,いくつかのアプリを起動
- rc.luaの変更箇所(ファイルの最後の方に追加):
--
-- Startup scripts
function run_once(prg,arg_string,screen) -- NOTE: screen and tag are different.
    if not prg then
        do return nil end
    end
    if not arg_string then 
        awful.util.spawn_with_shell("pgrep -f -u $USER -x " .. prg .. " || (" .. prg .. ")",screen)
    else
        awful.util.spawn_with_shell("pgrep -f -u $USER -x " .. prg .. " || (" .. prg .. " " .. arg_string .. ")",screen)
    end
end
run_once("xcompmgr", nil, 1)
run_once("wicd-gtk", nil, 1)
run_once("skype", nil, 1)
run_once("peraperaprv", nil, 1)



ウィンドウを半透明化する
-
sudo apt-get install xcompmgr
- rc.luaの変更箇所(ファイルの最後の方に追加):
--
-- Make some windows transparent
-- ref: http://nekolinux.blogspot.com/2009/05/awesomexcompmgr.html
-- Hook function to execute when focusing a client.                                                             
awful.hooks.focus.register(function (c)
    if not awful.client.ismarked(c) then
       c.border_color = beautiful.border_focus
       c.opacity = 0.9
    end
end)

-- Hook function to execute when unfocusing a client.                                                           
awful.hooks.unfocus.register(function (c)
    if not awful.client.ismarked(c) then
       c.border_color = beautiful.border_normal
       c.opacity = 0.5 
    end
end)
-- 上記「awesome WM起動時に,いくつかのアプリを起動」で,xcompmgr コマンドを起動していることが必要
[参考] http://nekolinux.blogspot.com/2009/05/awesomexcompmgr.html




以上です.この他にも,Emacsにlua-modeを入れたりflymake-luaを使えるようにしてます.

誰かのお役に立てれば幸いです.

[防備録] Ubuntu デスクトップ版 10.04 の再インストールと設定

ちょっとした事故でUbuntu デスクトップ版 10.04 が立ちあげられなくなったので,Ubuntu デスクトップ版 10.10 を入れてみました.

防備録がてら,作業ログを書き記します.
自分の環境に依存してる部分もかなりあると思うので,万一参考にする方はお気を付けください.

大まかにやったこと
  1. Ubuntu デスクトップ版 10.10 のインストール
  2. データの復旧
  3. 環境再構築
  4. awesome WM 導入



Ubuntu デスクトップ版 10.10 をCDに焼く



CDブートしインストール



インストール時の設定
- sda2,sda3のWindows用のパーティションを潰し,sda6にマウントポイント'/'を作成
- swap領域は既にあったのでそのまま使用



Ubuntu起動



rootのパスワード設定
-
sudo passwd



ファイルの復旧
-
sudo mkdir /mnt/sda5
sudo mount /dev/sda5 /mnt/sda5
cp -vr /mnt/sda5/home/sho/* .           (※軽く20分はかかった)
cd /mnt/sda5/usr/local/bin
sudo cp eps2png.sh convert.sh jabref peraperaprv latexmk /usr/local/bin/
sudo cp -r /mnt/sda5/usr/local/libexec/P3_4_36 /usr/local/lib  (PeraPeraPrvのコピー)



NetworkManager(UbuntuデフォルトのGnomeアプリ)でネットワーク接続



セキュリティ的にアップグレードをかける
-
sudo apt-get upgrade



日本語システムのための設定が不足してるらしいので,勝手に出てきたダイアログの指示に従ってインストール
- メニュー->システム->言語っぽい項目 からもいけるっぽい



この記事を書くためのエディタをゲット
-
sudo apt-get install emacs



CtrlとCapsを切り替え・MenuキーをWindowsキーに
(Windowsキーはawesome WM で右手用のMod4キーとして働く)

- ~/.Xmodmapを以下の内容で新規作成
--
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L

keysym Menu = Super_L

-以下のコマンドを,メニュー->システム->設定->自動起動するアプリ に追加
--
xmodmap ~/.Xmodmap

[参考] http://kaede.blog.abk.nu/xmodmapSwapCapsCtrl



gnome-terminalのプロファイルを設定
- 端末を右クリックして,適当に設定



欲しいアプリをインストール
- 自動的に依存関係を解消してもらえるときはそれに従う
- かなり検討したリストなので,自分がまた使うときはそのまま従う.例えば,flexもbisonも後でptetexをmakeするのに必要
-
sudo apt-get install \
g++ \
gnuplot \
gnuplot-doc \
gnuplot-x11 \
valgrind \
manpages-ja-dev \
openjdk-6-jdk \
openjdk-6-doc \
adobereader-jpn \
flashplugin-nonfree \
nkf \
netcat-openbsd \
ghostscript \
cmap-adobe-japan1 \
gs-cjk-resource \
xorg-dev \
iperf \
vim \
vim-tiny \
vim-gtk \
vim-nox \
patch \
flex \
bison \
gnome-alsamixer \
alsa-utils \
gv \
ipamonafont \
scim-mozc \
mozc-utils-gui \
git \
gitg \
wpagui \
libqt4-network \
gimp \
feh

[参考] http://g1g2g3.logos.ic.i.u-tokyo.ac.jp/index.php?tag=vdxjkzvv



mozcの設定
- メニュー->システム->設定->入力メソッド切替器
- Use SCIM via xim (scim)
- ログアウト
- 日本語入力を開始すると,右下にscimのメニューが出るので,そこから色々設定



ptetexのインストール
(apt-getで入手したパッケージではは日本語がまともに使えなかった)
-
wget http://tutimura.ath.cx/~nob/tex/ptetex/ptetex3/ptetex3-20090610.tar.gz
wget http://www.ring.gr.jp/pub/text/CTAN/obsolete/systems/unix/teTeX/3.0/distrib/tetex-src-3.0.tar.gz
wget http://www.ring.gr.jp/pub/text/CTAN/obsolete/systems/unix/teTeX/3.0/distrib/tetex-texmf-3.0po.tar.gz
tar xvf ptetex3-20090610.tar.gz
cd ptetex3-20090610
cp my_option.sample my_option

- my_optionを編集し,「KANJI_CODE=UTF8」の行のコメントアウトを外す.
- このままmakeすると途中で失敗するので,一時的に/usr/include/stdio.hを書き換える.具体的には,/usr/include/stdio.hの651行目から653行目にかけての, getline()関数の定義をコメントアウトする.
--
/*
extern _IO_ssize_t getline (char **__restrict __lineptr,
       size_t *__restrict __n,
      FILE *__restrict __stream) __wur;
*/

-
rm -rf /home/denjo/.texmf_var    (あれば)
make all

- dviのテスト出力が終わってからエラーがあるが,無視

-
sudo make install
-- ここでもエラーがあるが無視

- /usr/include/stdio.hを元に戻す

- /etc/profile.d/tetex.shというファイルを作り,以下を記述する:

--
export PATH=/usr/local/teTeX/bin:$PATH

- さらに実行権限を付けておく:
--
sudo chmod 0755 /etc/profile.d/tetex.sh

- 再起動でPATHを反映



TeXのスタイルファイルをコピー
-
sudo cp -r /mnt/sda5/usr/local/teTeX/share/texmf/ptex/platex/* /usr/local/teTeX/share/texmf/ptex/platex/
sudo /usr/local/teTeX/bin/mktexlsr




マウスの真ん中ボタンでスクロールできるように
- /usr/share/X11/xorg.conf.d/20-thinkpad.conf を以下のように作成・編集
--
Section "InputClass"
 Identifier "Trackpoint Wheel Emulation"
 MatchProduct "TPPS/2 IBM TrackPoint|DualPoint Stick|Synaptics Inc. Composite TouchPad / TrackPoint|ThinkPad USB Keyboard with TrackPoint|USB Trackpoint pointing device|Composite TouchPad / TrackPoint"
 MatchDevicePath "/dev/input/event*"
 Option  "EmulateWheel"  "true"
 Option  "EmulateWheelButton" "2"
 Option  "Emulate3Buttons" "false"
 Option  "XAxisMapping"  "6 7"
 Option  "YAxisMapping"  "4 5"
EndSection

- 再起動
[参考] http://www.thinkwiki.org/wiki/How_to_configure_the_TrackPoint#Scrolling



Firefoxの設定
- 設定ダイアログ
-- ダウンロード先とか
-- 言語設定で日本語を削除
-- フォントをIPA モナー Pゴシックに

- アドオン
-- All-in-One Gestures
-- Tab Mix Plus
-- Text Link
-- Xmarks Sync
-- AutoPager
-- Adblock Plus
-- FaviconizeTab
-- Force AutoComplete Extension 0.4
-- Firebug

- 起動を軽く
-- about:config で *history_expire* を適当に減らす



skypeのインストール
- 公式サイトからUbuntu用のdebパッケージをダウンロード
-
dpkg -i skype-ubuntu-intrepid_2.1.0.81-1_i386.deb



wicdのインストール
Gnome以外でのNetworkManagerの代わり
-
sudo apt-get install wicd-gtk wicd
sudo apt-get remove network-manager
- sudo wicd-gtk で設定



awesomeのインストール・設定
- 長くなるので,次のポスト参照