2005-06-18

∶∶读书生活::
中国万维网联盟(W3CHINA)

2005-06-06

胡适先生的《希望》:

我从山中来,带着兰花草。
种在小园中,希望花开早。
一日看三回,看得花时过。
兰花却依然,苞也无一个。

眼见秋天到,移兰入暖房。
朝朝频顾惜,夜夜不能忘。
但愿花开早,能将宿愿偿。
满庭花簇簇,开得许多香。
From: Image:Debian-package-cycle.png - Wikipedia, the free encyclopedia

2005-06-03

My Latex Template:

% -*- TeX-PDF-mode:t -*-
\documentclass[english,a4paper]{article}
\usepackage{a4wide}
\usepackage[T1]{fontenc}
\usepackage{ucs}
\usepackage[utf8]{inputenc}
\usepackage{autofe}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{indentfirst}
\usepackage{times}
\usepackage{mathptm}
\usepackage{color}
\definecolor{webred}{rgb}{0.3,0,0}
\definecolor{webblue}{rgb}{0,0,0.7}
\definecolor{webgreen}{rgb}{0,0.4,0}
\usepackage[bookmarksnumbered=true,
colorlinks=true,
linkcolor=webred,
citecolor=webblue,
anchorcolor=webgreen,
urlcolor=webblue
]{hyperref}
\usepackage{thumbpdf}
\usepackage{amsmath}
\begin{document}
\title{Title}
\author{Li Daobing}
\maketitle
\begin{verbatim}
Source version: $Id$
\end{verbatim}
\tableofcontents
\end{document}

2005-06-01

From: Li-Cheng Tai Home Page

My things in UTF8

My things in UTF8

我准备把我的Linux平台的编码从zh_CN.GB2312改为zh_CN.UTF-8,希望能够一切 顺利。

我的系统是Debian/Linux, sid, 2.6。

基本配置

bash的设置没有改,.xsession是.xinitrc的软链接。 .xinitrc内容如下:
# .xinitrc
source $HOME/.bash_profile

LANG=zh_CN.UTF-8
LC_MESSAGES=en_US
LC_TIME=en_US
export LANG LC_MESSAGES LC_TIME

export GDK_USE_XFT=1
export GTK_IM_MODULE='scim'
export XMODIFIERS="@im=SCIM"
scim -d

xscreensaver -no-splash &
esd &

icewmbg &
icewmtray &
exec icewm

文件名

可以用convmv来转换
convmv -f gb2312 -t utf8 -r --notest *

-r表示包含所有子目录 不加--notest就表示只看看有什么需要转换的,不做实际转换

文件内容

  • 可以用iconv,不过我更喜欢用emacs.用emacs打开文件
    C-x <return> f utf-8 <return> C-x C-s
    搞定。
  • 或者用vim(Thanks to fishy9@SMTH)
    :set fenc=utf8
    :w

xterm

理论上uxterm, rxvt-unicode-ml, mlterm, gnome-terminal都应该支持的,但 似乎uxterm, rxvt总有莫名奇妙的问题,所以我用mlterm(gnome-terminal的粘 贴风格我不喜欢)

输入法

Emacs

只需加如下两句

(setq current-language-environment "Chinese-GB")
(prefer-coding-system 'utf-8)

这时你用

C-h v coding-category-list

可以看到coding-category-list等于

(coding-category-utf-8
coding-category-iso-8-2 coding-category-big5 coding-category-iso-7-else
coding-category-iso-8-1 coding-category-utf-16-be
coding-category-utf-16-le coding-category-iso-7-tight
coding-category-iso-7 coding-category-iso-8-else
coding-category-emacs-mule coding-category-raw-text
coding-category-sjis coding-category-ccl coding-category-binary)

其中coding-category-iso-8-2就是chinese-iso-8bit,也就是gb2312

LaTeX

CJK

cjk-latex支持UTF8,但需要cyberb(debian没有提供),只好拿ttf-arphic-gbsn00lp伪装一个。

首先安装tetex-bin, cjk-latex, ttf-arphic-gbsn00lp,然后运行脚本unisong

unisong含两个文件,Makefile和c70song.fd

Makefile:

all: build
build:
ln -s /usr/share/fonts/truetype/arphic/gbsn00lp.ttf unisong.ttf
ttf2tfm unisong.ttf -w unisong@Unicode@ > unisong.log
rm -f unisong.map
for i in *.tfm; do base=`basename $$i .tfm`; echo "$${base} <$${base}.enc > unisong.map; done

install:
install -d /usr/share/texmf/fonts/tfm/arphic/unisong/
cp *.tfm /usr/share/texmf/fonts/tfm/arphic/unisong/
install -d /usr/share/texmf/dvips/arphic/
cp *.enc /usr/share/texmf/dvips/arphic/
cp unisong.map /etc/texmf/dvips/
cp unisong.map /usr/share/texmf/dvips/omega/
cp unisong.ttf /usr/share/texmf/fonts/truetype/arphic/
grep '^unisong@Unicode@ unisong.ttf' /etc/ttf2pk/ttfonts.map || echo "unisong@Unicode@ unisong.tff" >> /etc/ttf2pk/ttfonts.map
cp -f c70song.fd /usr/share/texmf/tex/latex/CJK/UTF8/
grep "^map +unisong.map" /etc/texmf/pdftex/pdftex.cfg || echo "map +unisong.map" >> /etc/texmf/pdftex/pdftex.cfg
mktexlsr
clean:
rm -f unisong*.tfm
rm -f unisong*.enc
rm -f unisong.map
rm -f unisong.ttf
rm -f unisong.log
.PHONY: build

c70song.fd(cjk-latex自带的c70song.fd,再将cyberb改成unisong就可以了):

% This is the file c70song.fd of the CJK package
% for using Asian logographs (Chinese/Japanese/Korean) with LaTeX2e
%
% created by Werner Lemberg
%
% Version 4.5.1 (17-Jun-2002)

\def\fileversion{4.5.1}
\def\filedate{2002/06/17}
\ProvidesFile{c70song.fd}[\filedate\space\fileversion]


% character set: Unicode U+0080 - U+FFFD
% font encoding: Unicode

\DeclareFontFamily{C70}{song}{\hyphenchar \font\m@ne}

\DeclareFontShape{C70}{song}{m}{n}{<-> CJK * unisong}{}
\DeclareFontShape{C70}{song}{bx}{n}{<-> CJKb * unisong}{\CJKbold}

\endinput

OK, make; su; make install就可以了

然后把你的latex文章转成UTF8编码,把\begin{CJK*}{GB}{song}改成 \begin{CJK*}{UTF8}{song}就可以了。

non-CJK

如果在英文文档中,你想直接输入Å,而不是去输入\AA的话, 可以使用latex-ucs来帮你实现。

安装完latex-ucs后,在tex文件的头部加入

\usepackage{ucs}
\usepackage[utf8]{inputenc}
就可以在正文中输入任何unicode字符了。

如果在文件头加入

\usepackage[C10,T1]{fontenc}
\usepackage[cjkgb]{ucs}
\usepackage[utf8]{inputenc}
那么输入中文也没有问题,不过就不能享受CJK带来的其他好处了。

FTP

很多FTP的文件名是GB2312编码的。解决方法有:

  1. 用mozilla系列浏览器来访问FTP,可以自行设置编码。
  2. 用lftp,在$HOME/.lftp/rc或/etc/lftp.conf文件中加入(感谢:yabozj AT zju.edu.cn)
    set ftp:charset "gbk"
    set file:charset "UTF-8"

MP3 ID3 tag

xmms 里边一堆的乱码,看来是ID3的编码的问题,没办法,又写了一个脚本。注意,这个脚本依赖于pyid3lib, 你可以到 http://pyid3lib.sourceforge.net/ 下载,如果你用debian的话,可以直接用 apt-get install python-id3lib 安装
#!/usr/bin/python
# mp3iconv.py
import os
import pyid3lib

def texticonv(text, fcode, tcode):
try:
text.decode(tcode)
except UnicodeDecodeError:
try:
newtext = text.decode(fcode)
except UnicodeDecodeError:
return False, None
newtext = newtext.encode(tcode)
return True, newtext
os.rename(fname, newfname)
return False, None


def mp3iconv(fname, fcode='gb2312', tcode='utf8'):
tag = pyid3lib.tag(fname)
needupdate = False
for key in ['artist', 'title', 'album']:
try:
text = getattr(tag, key)
except AttributeError:
continue
r, newtext = texticonv(text, fcode, tcode)
if r:
setattr(tag, key, newtext)
needupdate = True
if needupdate:
tag.update()

def main():
import sys
assert len(sys.argv) > 1
for x in sys.argv[1:]:
mp3iconv(x)

if __name__ == '__main__':
main()

Debian 下 VPN Server 架设手记

以下步骤均假定你在root用户下运行

  1. 安装必要软件
    apt-get install pptpd kernel-tree-2.6.10 kernel-package
    apt-get install kernel-patch-mppe libc6-dev
  2. 解压Linux kernel
    cd /usr/src
    tar xjf kernel-source-2.6.10.tar.bz2
  3. 配置内核
    我图简单,直接拷贝了一份现有的config文件
    cd /usr/src/kernel-source-2.6.10
    cp /boot/config-2.6.10-1-686-smp .config
  4. 编译内核
    make-kpkg --added-patches debian,mppe --append-to-version -686-smp-mppe --initrd kernel_image
    然后去喝茶
  5. 安装新内核,重启
    cd /usr/src/
    dpkg -i kernel-image-2.6.10-686-smp-mppe_10.00.Custom_i386.deb
    update-grub
    reboot
  6. 配置pptpd
    vi /etc/pptpd.conf
    修改localip和remoteip, localip改成服务器的IP, remoteip是供登录上来的机器使用的IP,如
    localip 1.2.3.4
    remoteip 1.2.3.50-70
  7. 配置chap-secrets
    vi /etc/ppp/chap-secrets
    如果不限制ip,可以改成如下的样子
    username pptpd password *
    如果限制IP,可以改成
    username pptpd password 162.105.0.0/16 166.111.0.0/16
  8. 配置network
    /etc/network/options
    修改ip_forward选项
    ip_forward=yes
  9. 重启network和pptpd
    /etc/init.d/networking restart
    /etc/init.d/pptpd restart
  10. 测试
    运气好就应该可以了,测试时可以通过 tail -f /var/log/syslog 来监视
  11. 后记
    曾经在AMD64-K8-SMP的机器上进行这一套程序,结果一旦有人试图链接,就 Kernel Panic, 失败。
  12. THANKS
  • fjdc AT 163 DOT com
Some Comic URL:

now I am the official maintainer of QTerm debian package.


Qterm's bug track page: Here