Enable verbatim environment to support Chinese Characters in xetex

Source: Internet
Author: User

After studying verbatim. sty, we found that the verbatim environment uses ttfamily fonts by default, so we only need to redefine
\ Verbatim @ font macro enables verbatim to use rmfamily or sffamily fonts by default through \ setromanfont or
\ Setsansfont: Set the font family to Chinese.

\ Documentclass [a4paper] {Article}
\ Usepackage {fontspec, xunicode, xltxtra, verbatim}
\ Setsansfont [boldfont = {"[simhei. TTF]"}] {"[simsun. TTC]"}
\ Setromanfon [boldfont = {"[simhei. TTF]"}] {"[simsun. TTC]"}
% You can also use the font name directly when setting the font. The following three methods are equivalent:
% \ Setromanfont [boldfont = {}] {}
% \ Setromanfont [boldfont = {simhei}] {simsun}
% \ Setromanfont [boldfont = {"[simhei. TTF]"}] {"[simsun. TTC]"}
%, But the first method is not recommended. If you use the font of a Chinese name
% Roman and sans fonts are set to the same font. For example, you can set both romanfont and sanfont to ""
% Will cause compilation errors. But there are no problems with the other two methods. Maybe it is a bug in the fontspec package. Push
% Recommend the third method to directly specify the font file name.

\ Begin {document}
Can you see some CJK characters in the Verbatim?

\ Makeatletter
\ Def \ verbatim @ font {\ sffamily \ small} % if Roman fonfamily is used, change sffamily to rmfamily
\ Makeatother

\ Begin {verbatim}
Some ASCII characters!
You can see Chinese characters!
\ End {verbatim}
\ End {document}

PS: This article was first published by myself in the water and wood Tsinghua Tex edition.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.