tetex in utf8搞定
大部分内容都是参照这里
app-text/tetex-3.0_p1-r3
dev-tex/cjk-latex-4.5.2
media-libs/freetype-1.3.1-r5
然后保存以下内容成为一个脚本mktfm.sh,或者从这里下载:
#!/bin/sh
#
# Edward G.J. Lee <edt1023@info.sayya.org> 2005.01.13
# You need freetype1/contrib current version.
# This script is Public Domain
# $Id: mktfm.sh,v 1.4 2005/03/19 06:01:51 edt1023 Exp $
#
if [ $# -ne 3 ]
then
echo
echo "Usage: `basename $0` your.ttf cjk_name font_encoding"
echo "For example:"
echo "`basename $0` cwming.ttf cwming Big5"
echo "`basename $0` cwming.ttf cwmu Unicode"
echo
exit
fi
DATE=`date`
TTFONT=$1
BTTFONT=`basename $1`
eval `echo $TTFONT | awk -F. '{printf "FHEAD=%s;FTAIL=%s",\$1,\$2}'`
CJKNAME=$2
TTMAP=$3
#TOTFM=/usr/local/FT1/bin/ttf2tfm
`which ttf2tfm > /dev/null 2>&1`;ISTFM=$?
if [ $ISTFM -eq 0 ]
then
if [ `ttf2tfm --version|awk '/version/ {print $3*10}'` -lt 15 ]
then
echo
echo "This script need ttf2tfm version 1.5 or later."
echo "Please install FreeType1/contrib current version."
echo
exit
else
TOTFM=ttf2tfm
fi
else
echo
echo "This script need ttf2tfm!"
echo
exit
fi
case $TTMAP in
Big5)
PSENC=ETen-B5
CJKENC=00
NUMLIST=`awk 'BEGIN{n=1; while(n<56){printf "%02d\n",n; n++}}'`
;;
Unicode)
PSENC=Identity
CJKENC=70
NUMLIST=`awk 'BEGIN{n=0; while(n<256){printf "%02x\n",n; n++}}'`
;;
UGB)
PSENC=UniGB-UCS2
CJKENC=10
NUMLIST=`awk 'BEGIN{n=1; while(n<36){printf "%02d\n",n; n++}}'`
;;
UJIS)
PSENC=UniJIS-UCS2
CJKENC=40
NUMLIST=`awk 'BEGIN{n=1; while(n<36){printf "%02d\n",n; n++}}'`
;;
UKS)
PSENC=UniKS-UCS2
CJKENC=60
NUMLIST=`awk 'BEGIN{n=1; while(n<36){printf "%02d\n",n; n++}}'`
;;
*)
echo
echo "Not support yet!"
echo
;;
esac
create_cidmap()
{
cat >> cid-x.map.append << EoF
% created by Edward G.J. Lee <edt1023@info.sayya.org>
% $DATE
% Please append to cid-x.map.
%
$CJKNAME@$TTMAP@ ${PSENC}-H :0:$BTTFONT
${CJKNAME}s@$TTMAP@ ${PSENC}-H :0:$BTTFONT -s .167
$CJKNAME@$TTMAP@ ${PSENC}-H :0:$BTTFONT,Bold
${CJKNAME}s@$TTMAP@ ${PSENC}-H :0:$BTTFONT,Bold -s .167
EoF
}
create_newmap()
{
cat >> cid-x.map.append << EoF
% created by Edward G.J. Lee <edt1023@info.sayya.org>
% $DATE
% Please append to cid-x.map.
%
$CJKNAME@$TTMAP@ ${PSENC}-H $BTTFONT
${CJKNAME}s@$TTMAP@ ${PSENC}-H $BTTFONT -s .167
EoF
}
create_cjkfd()
{
cat > c${CJKENC}${CJKNAME}.fd << EoF
% This is c${CJKENC}${CJKNAME}.fd for CJK package.
% created by Edward G.J. Lee <edt1023@info.sayya.org>
% $DATE
%
\ProvidesFile{c${CJKENC}${CJKNAME}.fd}[\filedate\space\fileversion]
\DeclareFontFamily{C${CJKENC}}{$CJKNAME}{\hyphenchar \font\m@ne}
\DeclareFontShape{C${CJKENC}}{$CJKNAME}{m}{n}{<-> CJK * $CJKNAME}{}
\DeclareFontShape{C${CJKENC}}{$CJKNAME}{m}{sl}{<-> CJK * ${CJKNAME}s}{}
\DeclareFontShape{C${CJKENC}}{$CJKNAME}{m}{it}{<-> CJKssub * $CJKNAME/m/sl}{}
\DeclareFontShape{C${CJKENC}}{$CJKNAME}{bx}{n}{<-> CJKb * $CJKNAME}{\CJKbold}
\DeclareFontShape{C${CJKENC}}{$CJKNAME}{bx}{sl}{<-> CJKb * ${CJKNAME}s}{\CJKbold}
\DeclareFontShape{C${CJKENC}}{$CJKNAME}{bx}{it}{<-> CJKssub * $CJKNAME/bx/sl}{\CJKbold}
\endinput
EoF
}
create_pdftexmap()
{
# determinate NUMLIST here.
ENCMAP=${CJKNAME}-enc.map
cat > $ENCMAP << EoF
% This is map file for PDFLaTeX and LaTeX CJK package to embed TTF.
% Created by Edward G.J. Lee <edt1023@info.sayya.org>
% $DATE
EoF
for i in $NUMLIST
do
cat >> $ENCMAP << EoF
${FHEAD}$i <${FHEAD}$i.enc <${BTTFONT}
EoF
done
}
# for normal font
echo
echo "Please wait..."
echo "Create tfm/fd files for LaTeX-CJK."
echo "And cid-x.map for dvipdfmx."
echo
$TOTFM $TTFONT -q -w ${CJKNAME}@${TTMAP}@ >> ttfonts.map #/dev/null 2>&1
# for other TTF to fit cwttf.
#$TOTFM $TTFONT -e 0.92 -w ${CJKNAME}@${TTMAP}@ > /dev/null 2>&1
# for slant font
$TOTFM $TTFONT -q -s 0.167 -w ${CJKNAME}s@${TTMAP}@ >>ttfonts.map # /dev/null 2>&1
#$TOTFM $TTFONT -e 0.92 -s 0.167 -w ${CJKNAME}s@${TTMAP}@ > /dev/null 2>&1
create_cjkfd
`which dvipdfmx > /dev/null 2>&1`;ISPDFMX=$?
if [ $ISPDFMX -eq 0 ]
then
DVERSION=`dvipdfmx --version 2>&1 |awk '/dvipdfmx-/ {print substr($3,10)}'`
if [ $DVERSION -le 20031116 ]
then
create_cidmap
else
create_newmap
fi
else
echo
echo "You didn't install dvipdfmx, script abort!"
echo
exit
fi
脚本不是我写的,我只是修改一下让它能生成ttfonts.map文件,如此,准备工作完成
如果脚本抱怨ttf2tfm版本太低的话就下载这个ttf2tfm放到/usr/bin下
先在$TEXMFLOCAL/fonts下建立truetype目录,把需要用到的字体复制过来或者符号链接过来,并且把mktfm.sh也放在这个目录下面,再下载Unicode.sfd,同样放在这个目录,然后用脚本生成一大堆文件,比如我在用uming和ukai,我就执行./mktfm.sh ukai.ttf ukai Unicode和./mktfm.sh uming.ttf uming Unicode,然后建立放tfm文件的目录:
mkdir -p $TEXMFLOCAL/fonts/tfm/CJK/ukai
mkdir $TEXMFLOCAL/fonts/tfm/CJK/uming
然后把当前目录下所有ukai的tfm文件移到对应的目录下,uming也一样:
mv ukai*.tfm $TEXMFLOCAL/fonts/tfm/CJK/ukai/
mv uming*.tfm $TEXMFLOCAL/fonts/tfm/CJK/uming/
再建立放enc文件的目录:
mkdir -p $TEXMFLOCAL/fonts/enc/CJK/ukai
mkdir $TEXMFLOCAL/fonts/enc/CJK/uming
把当前目录下所有ukai的enc文件移动对应目录下,uming也一样:
mv ukai*.enc $TEXMFLOCAL/fonts/enc/CJK/ukai/
mv uming*.enc $TEXMFLOCAL/fonts/enc/CJK/uming/
把*.fd文件放到它们应该在的地方:
mkdir -p $TEXMFLOCAL/tex/latex/cjk-latex/UTF8
mv *.fd $TEXMFLOCAL/tex/latex/cjk-latex/UTF8/
让生成的cid-x.map.append也完成它的使命:
mkdir -p $TEXMFLOCAL/fonts/map/dvipdfm
cat cid-x.map.append >> $TEXMFLOCAL/fonts/map/dvipdfm/cid-x.map
把Unicode.sfd放到$TEXMFLOCAL/fonts/sfd下
把生成的ttfonts.map放到/usr/local/share/texmf/ttf2pk/
最后执行texhash,
以及updmap --enable Map ttfonts.map
这样utf8的latex就建立好了,随便建一个中文的tex文件试试就知道了
我刚开始没有emerge freetype,中文的tex文件可以编译,但是生成的dvi文件无法预览,要是用dvipdfmx生成pdf的话是正常的,问题是出现在mktexpk无法从ttf生成pk字体,而原因是我的ttf2pk是直接下载的二进制文件,它竟然无法找到ttf2pk.cfg或者ttfonts.map,我试图下载ttf2pk的源代码修改之,却发现原来ttf2pk是包含在freetype里的,然后emerge之,再用xdvi看dvi文件,一切正常,大功告成!
第一次完全搞定中文latex,顺便庆祝我的第一篇用latex完成的论文。
5 comments:
gongxigongxi,bgbg
惊喜,感谢,正愁如何为latex装方正超大字集
很高兴我的经验能帮到你
Post a Comment