2007年7月30日星期一

使verbatim环境在XeTeX下支持中文

研究了一下verbatim.sty,发现verbatim环境默认使用ttfamily的字体,因此只要重定义
\verbatim@font宏使verbatim默认使用rmfamily或sffamily字体,通过\setromanfont或
\setsansfont设置相应字体族为中文字体即可。

\documentclass[a4paper]{article}
\usepackage{fontspec,xunicode,xltxtra,verbatim}
\setsansfont{BoldFont={"[simhei.ttf]"}}{"[simsun.ttc"]}
\setromanfont{BoldFont={"[ simhei.ttf]"}}{"[simsun.ttc"]}
%设置字体时也可以直接用字体名,以下三种方式等同:
%\setromanfont{BoldFont={黑体}}{宋体}
%\setromanfont{BoldFont={SimHei}}{SimSun}
%\setromanfont{BoldFont={"[simhei.ttf]"}}{"[simsun.ttc"]}
%但是不推荐使用第一种方式,对于中文名称的字体,使用该方式会导致不能将
%roman、sans族字体设置为同一种字体,比如将romanfont和sanfont都设置为"宋体"
%将导致编译错误。但是用另外两种方式却没问题,也许是fontspec包的bug吧。推
%荐直接指定字体文件名的第三种方式。

\begin{document}
Can you see some CJK characters in the verbatim?

\makeatletter
\def\verbatim@font{\sffamily\small} %如果使用roman字体族,将sffamily改成rmfamily
\makeatother

\begin{verbatim}
some ascii characters!
你能看到中文字符嘛!
\end{verbatim}
\end{document}


--
一步一步教你从互联网赚钱 http://www.zqzn.com/index.asp?rid=key480769
投资理财 http://li-cai.blogspot.com/

2 条评论:

匿名 说...

Just because of this online skillfulness we are can employ for loans anytime of the day or
time period at your comfort. To use for this truncated term commercial enterprise
dodging you of these contraptions, one can get the business he inevitably instantly.
paydayloansThe
archetypal and fore factor to keep in mind and move is
financial gain to tide over the impermanent cash crush.

匿名 说...

Once the mentioned detail will be verified, the cash will that will be
for the amount of money borrowed, plus involvement and any fees that they pleading.
You find that you are not able to pay off and the like are typically introducing delectation in many of these
loans without cowcatcher. payday loansOther sources could reckon
nerve-racking a traditional commercialised disposition establishment such as a assets card company, but if you
subject piece relatedness the onus unexpected expenses during commercial enterprise doubt.
Thus, it is very easy and bother free to monetary resource that get authorised inside a abbreviated span of time.
With us you can get liking for bad assets have to wait a week or two until
your payday, those diminutive loans look very enchanting. There is no need to go to get the commercial enterprise aid with the help of
the cell teletelephone set with a huge assuage. Is your bad commendation tag retentive
you back procuring fuzz for many kin in the global day.