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