红联Linux门户
Linux帮助

Mac,Linux中统一配置Latex中文字体

发布时间:2017-06-27 11:43:24来源:linux网站作者:DocNan
对于中文的latex文档,在Linux下一般可以使用系统自带的开源字体:文泉驿(WenQuanYi)来实现,即如下的最小例子,通过xelatex命令来编译即可生成中文文档。
 
\documentclass[UTF8,nofonts]{ctexart}
\usepackage{xeCJK}
\title{中文测试}
\author{测试}
\date{\today}
% use buildin Chinese font in linux
\setCJKmainfont[BoldFont={WenQuanYi Micro Hei/Bold}]{WenQuanYi Micro Hei}
\begin{document}\large
\section{中文}
中文测试,中文测试,中文测试。
\end{document}
 
而在Mac下并没有文泉驿字体,但是却有其它的中文字体,有没有同时兼容Linux和Mac,而且不用安装额外字体的解决方案呢?
 
从网上搜到了解决方法,更换为通用的字体即可[1](可叹的是,给出解决方案的竟然是老外,国内的没搜到有用的解决方案):
 
\documentclass[UTF8,nofonts]{ctexart}
\usepackage{xeCJK}
\title{中文测试}
\author{测试}
\date{\today}
% use buildin Chinese font in linux and Mac
\setCJKmainfont[BoldFont=FandolSong-Bold.otf,ItalicFont=FandolKai-Regular.otf]{FandolSong-Regular.otf}
\setCJKsansfont[BoldFont=FandolHei-Bold.otf]{FandolHei-Regular.otf}
\setCJKmonofont{FandolFang-Regular.otf}
\begin{document}\large
\section{中文}
中文测试,中文测试,中文测试。
\end{document}
 
经过测试,这种设置在Linux Fedora25的英文环境也可以通过编译,成功生成中文的pdf文档。
 
参考[1]:
Mac,Linux中统一配置Latex中文字体
 
本文永久更新地址:http://www.linuxdiyf.com/linux/31750.html