hew 2007-8-30 10:11
LaTeX with UTF-8
#1)安装teTeX-3.0或TeXLive-2005
#1.1)先用标准的方法安装teTeX或TeXLive,一定要安 装[url=http://cjk.ffii.org/][color=#0000ff]CJK[/color][/url]。
#1.2)下 载[url=http://delloye.free.fr/Unicode.sfd][color=#0000ff]Unicode.sfd[/color][/url]到 TEXMF/fonts/sfd目录,并运行mktexlsr。
#2)安装ttf2tfm(TeXLive已经包含了ttf2tfm,这一步只针对teTeX用户)
我们需要ttf2tfm这个工具来转换TrueType字体的尺寸信息。
#2.1)到[url=http://ctan.org/tex-archive/systems/texlive/Source/][color=#0000ff]这 里[/color][/url]下载TeXLive的源代码包:source.tar.bz2;
#2.2)运行如下命令
[i] $ mkdir /tmp/texlive_build[/i]
[i] $ cd /tmp/texlive_build[/i]
[i] $ tar jxvf source.tar.bz2[/i]
[i] $ ./configure [/i]
[i] $ gmake -C texk/ttf2pk ttf2tfm[/i]
[i] # cp texk/ttf2pk/ttf2tfm /usr/local/bin[/i]
#3)下面开始配置teTeX或TeXLive
#3.1)准备好TrueType字体,并编辑一个简单的文件fontdesc.txt,内容如下:
yahei [color=red]CHANGE_THIS[/color]/fonts/truetype/yahei.ttf
cyberbit [color=red]CHANGE_THIS[/color]/fonts/truetype/cyberbit.ttf
fangsong [color=red]CHANGE_THIS[/color]/fonts/truetype/simfang.ttf
heiti [color=red]CHANGE_THIS[/color]/fonts/truetype/simhei.ttf
kaiti [color=red]CHANGE_THIS[/color]/fonts/truetype/simkai.ttf
lishu [color=red]CHANGE_THIS[/color]/fonts/truetype/simli.ttf
songti [color=red]CHANGE_THIS[/color]/fonts/truetype/simsun.ttf
youyuan [color=red]CHANGE_THIS[/color]/fonts/truetype/simkai.ttf
shuti [color=red]CHANGE_THIS[/color]/fonts/truetype/fzstk.ttf
yaoti [color=red]CHANGE_THIS[/color]/fonts/truetype/fzytk.ttf
caiyun [color=red]CHANGE_THIS[/color]/fonts/truetype/stcaiyun.ttf
xihei [color=red]CHANGE_THIS[/color]/fonts/truetype/stxihei.ttf
xingkai [color=red]CHANGE_THIS[/color]/fonts/truetype/stxingka.ttf
xinwei [color=red]CHANGE_THIS[/color]/fonts/truetype/stxinwei.ttf
zhongsong [color=red]CHANGE_THIS[/color]/fonts/truetype/stzhongs.ttf
其中第一列是字体的名称,第二列给出字体文件的路径。
#3.2)复制下面的SHELL脚本,另存为latex-utf8.sh。
[i]#!/bin/sh[/i]
[i]
#
# Copyright (C) 2006, 2007 Hong MingJian
# All rights reserved.
#
# This piece of code is distributed with GPLv2 license.
#
[/i]
[i]
TEXMF=/home/hmj/.texmf-var # [color=red]CHANGE_THIS[/color]
TTF2TFM=/usr/local/bin/ttf2tfm # [color=red]CHANGE_THIS[/color]
if [ $# -ge 1 ]; then
if [ ! -r $1 ]; then
echo "No such file: $1"
exit 1
fi
infile=$1
fi
[/i]
[i]
SFD=$(kpsewhich Unicode.sfd)
if [ -z "${SFD}" ] ; then
echo "`Unicode.sfd' not found"
exit 1
fi
[/i]
[i]
if [ ! -d ${TEXMF}/web2c ]; then
mkdir -p ${TEXMF}/web2c
fi
[/i]
[i]
UPDMAPCFG=${TEXMF}/web2c/updmap.cfg
if [ ! -f ${UPDMAPCFG} ]
then
cp -v $(kpsewhich -format 'web2c files' updmap.cfg) ${UPDMAPCFG}
fi
[/i]
[i]
templ=`basename $0`
WORK=`mktemp -d /tmp/${templ}.XX`
cd ${WORK}
[/i]
[i]
while read font file
do
if [ -z "${font}" -o -z "${file}" ]; then
continue
fi
[/i]
[i]
if [ ! -f ${file} ]; then
continue
fi
[/i]
[i]
# ${font} - Font Name
# ${file} - Font File Name
[/i]
[i]
if [ ! -d ${TEXMF}/fonts/truetype ]; then
mkdir -p ${TEXMF}/fonts/truetype
fi
[/i]
[i]
if [ ! -f ${TEXMF}/fonts/truetype/$(basename ${file}) ]; then
cp -v ${file} ${TEXMF}/fonts/truetype
fi
${TTF2TFM} ${TEXMF}/fonts/truetype/$(basename ${file}) -q -w ${font}@${SFD}@
[/i]
[i]
for i in `ls *.tfm | cut -d. -f1`; do
echo "${i} <$(basename ${file}) <${i}.enc";
done > ${font}.map
if [ ! -d ${TEXMF}/fonts/map/pdftex/local ]; then
mkdir -p ${TEXMF}/fonts/map/pdftex/local
fi
mv ${font}.map ${TEXMF}/fonts/map/pdftex/local
echo "Map ${font}.map" >> ${UPDMAPCFG}
[/i]
[i]
if [ ! -d ${TEXMF}/fonts/tfm/local/${font} ]; then
mkdir -p ${TEXMF}/fonts/tfm/local/${font}
fi
mv ${font}*.tfm ${TEXMF}/fonts/tfm/local/${font}
[/i]
[i]
if [ ! -d ${TEXMF}/fonts/enc/pdftex/local/${font} ]; then
mkdir -p ${TEXMF}/fonts/enc/pdftex/local/${font}
fi
mv ${font}*.enc ${TEXMF}/fonts/enc/pdftex/local/${font}
[/i]
[i]
if [ ! -d ${TEXMF}/tex/latex/CJK/UTF8 ]; then
mkdir -p ${TEXMF}/tex/latex/CJK/UTF8
fi
cat >${TEXMF}/tex/latex/CJK/UTF8/c70${font}.fd <<EOF
% character set: Unicode U+0080 - U+FFFD
% font encoding: Unicode
ProvidesFile{c70${font}.fd}
DeclareFontFamily{C70}{${font}}{hyphenchar fontm@ne}
DeclareFontShape{C70}{${font}}{m}{n}{<-> CJK * ${font}}{}
DeclareFontShape{C70}{${font}}{bx}{n}{<-> CJKb * ${font}}{CJKbold}
endinput
EOF
[/i]
[i]
done < $(realpath ${infile})
[/i]
[i]
rmdir ${WORK}
[/i]
[i]
updmap
#updmap-sys
[/i]
[i]
mktexlsr
[/i]
[i]# end of file[/i]
#3.3)运行如下命令:
[i]$ /path/to/latex-utf8.sh /path/to/fontdesc.txt[/i]
#4)测试
写一个用UTF-8编码的tex文件,如sample.tex
[i] $ pdflatex sample[/i]
#5)说明
#5.1)TeX源文件必须采用UTF-8编码;
#5.2)生成的PDF文件可以复制和粘贴中文;
#5.3)这样配置的系统只能用pdflatex生成中文PDF,不支持dvipdfm/dvipdfmx。应该可以进一步配置支持它们。