惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
Vercel News
Vercel News
U
Unit 42
L
LangChain Blog
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
F
Fortinet All Blogs
小众软件
小众软件
I
InfoQ
P
Proofpoint News Feed
D
DataBreaches.Net
Martin Fowler
Martin Fowler
H
Help Net Security
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
How to Use Chinese with LaTeX
2018-03-29 · via jdhao's digital space

The original LaTeX do not have good support for Chinese. With the development of LaTeX, we can now easily use Chinese in LaTeX document. In this post, I would like to introduce several ways to work with Chinese in LaTeX.

Use CTeX#

Use ctexart documentclass#

The CTeX group has developed multiple document classes and packages to deal with the particular need of Chinese typesetting.

If you have a long article mainly written in Chinese, you should choose ctexart document class. An MWE is shown below:

\documentclass[UTF8]{ctexart}

\begin{document}
你好,这是一个测试文档。
\end{document}

When using the ctexart documentclass, you should also add \usepackage[T1]{fontenc}. Otherwise, some of the characters will be shown incorrectly.

Use ctex package#

Or you can use the ctex package instead:

\documentclass{article}
\usepackage[UTF8]{ctex}
\begin{document}
你好,这是一个测试文档。
\end{document}

You can compile it with latex, pdflatex, xelatex or lualatex. xelatex is recommed from the author of this class.

Use xeCJK with xelatex#

If you only need to type a few Chinese character, you can go with xeCJK package and compile the document with xelatex. A MWE is shown below:

Click to check the code.
% this file can be compiled with xelatex command
\documentclass[12pt, a4paper]{article}
\usepackage{fontspec}
\usepackage[slantfont, boldfont]{xeCJK}

% set up English font
\setmainfont{Microsoft YaHei}
\setsansfont{Comic Sans MS}
\setmonofont{Courier New}

% set up Chinese font, the font must be valid on your system
\setCJKmainfont{Microsoft YaHei}
\setCJKmonofont{Source Code Pro}
\setCJKsansfont{YouYuan}

% correct line break for chinese
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt

\title{测试}
\author{}
\date{2016年6月6日}
\begin{document}
\maketitle
\begin{center}
满纸荒唐言\\
一把辛酸泪\\
都云作者痴\\
谁解其中味\\
\end{center}
\begin{verse}
\texttt{Stray birds of summer come to my window to sing and fly away}. \\
\textsf{And yellow leaves of autumn, which have no songs}, \\
\textrm{flutter and fall there with a sign}.\\
\hfill \emph{RabindranathTagore}
\end{verse}
\begin{verse}
\texttt{夏天的飞鸟}\textsf{飞到我的窗前唱歌}\textrm{又飞去了}\\
秋天的黄叶,它们没有什么可唱,只叹息一声,飞落在那里。\\
\hfill \emph{罗宾德拉纳特·泰戈尔}
\end{verse}
\end{document}

For Chinese, the command \setCJKmainfont{} are used to set up the font used by main text, which is also used by \textrm{} command. \setCJKmonofont{} is used to set up the font used by \texttt{}. \setCJKsansfont{} is used to set up the font used by \textsf{}.

So how to find a valid Chinese font to use in these command? If you have installed TeX Live, it is easy to do. Just use the following command in your console:

It will list all the fonts on your system which support Chinese. A sample output is as follows:

You can pick the font you like or experiment with different fonts to choose the one you want.

The above example is based on a number of posts, but I have removed several package since they are now redundant.

References#