Archive for August, 2007
ConTeXt + LuaTeX + Chinese
最近這幾天玩了一下 ConTeXt,搭配最近開始 beta 的 LuaTeX,想辦法設定中文,有了小小的成果……
因為急著要跟大家分享,所以可能寫的不是很清楚或有所遺漏,還請不吝指教
持續測試、改版中。
PS. 文中不能複製貼上的部份放在下面
$ export TEXMFCNF=/usr/share/texmf/web2c
$ export TEXMF='{/usr/share/texmf,/usr/share/texmf-texlive,/home/kanru/texmf}'
$ export TEXMFCACHE=/tmp
$ export OSFONTDIR='{/usr/share/fonts/truetype,/home/kanru/.fonts}'
\enableregime[utf]
\usemodule[chi-00]
\directlua0{
function wrap(str)
rt = ''
for u in string.utfvalues(str) do
up = math.ceil(u / 0x100)
low = u - math.ceil(u / 0x100) * 0x100
if u < 127 then % need to be replace by cjk range
rt = rt .. unicode.utf8.char(u)
else
rt = rt .. '\\lookaheaduchar{' .. up ..'}{' .. low ..'}'
end
end
return rt
end
callback.register('process_input_buffer', wrap)
}
\beginLUATEX\insertunicodeglyph
\unexpanded\def\insertunicodeglyph
{\doinsertunicodeglyph\unicodeone\unicodetwo}
\unexpanded\def\doinsertunicodeglyph#1#2%
{\char\numexpr(#2+(#1*256))\relax}
\endLUATEX
\def\en#1{%
\hskip\chinesesurroundskip
\hskip\chineseinterglyphskip\relax
#1%
\hskip\chineseinterglyphskip\relax
\hskip\chinesesurroundskip
\hskip\chinesesurroundskip
\hskip\chinesesurroundskip
\hskip\chinesesurroundskip
\hskip\chinesesurroundskip
\hskip\chinesesurroundskip
\hskip\chinesesurroundskip
\ignorespaces
}
\starttypescript [sans] [cwheib] [name]
\definefontsynonym [Sans] [cwheib]
\definefontsynonym [SansItalic] [cwheib]
\definefontsynonym [SansSlanted] [cwheib]
\definefontsynonym [SansBold] [cwheib]
\definefontsynonym [SansBoldSlanted] [cwheib]
\definefontsynonym [SansBoldItalic] [cwheib]
\stoptypescript
\starttypescript [my] [cwheib]
\definetypeface [cwheib][ss][sans][cwheib][default]
\stoptypescript
\usetypescript[my][cwheib]
\setupbodyfont[cwheib,ss,10pt]
有圖的水銀
根據 yungyuc 的有圖的水銀這篇,裝了 ActiveTCL 之後,終於把 hgk 在 Windows 上給跑了起來,不過我一直很好奇的是,Windows 版的 Python installer 預設會安裝 tcl/tk 的 module Tkinter 跟相關的 dll,難道不能用這個來跑 hgk 嗎?
原本是想把 hgk 一行一行搬到 python,不過這樣太慢了,後來發現有 Tkinter.Tk.eval 可以用
剛剛做了一下實驗,證明以下 code 可以執行:
# run-hgk.py
import sys
import Tkinter
# read hgk file
hgk = ''.join(open('hgk', 'r').readlines())
tk = Tkinter.Tk()
tk.eval('set argv [list ' + ' '.join(sys.argv[1:]) + ']')
tk.eval('set env(HG) "hg"')
try:
tk.eval(hgk)
tk.mainloop()
except Tkinter.TclError, e:
print e
不過要真的可以用,還要改一下路徑的處理跟環境變數的取得
接下來,想要真的把 hgk port 到 python,現在的 hgk 幾乎是 copynpaste gitk,連 help menu 裡面都沒改過,程式裡面還參考到 GIT_DIR 環境變數… Orz