LaTeX使用--使用XeLaTeX支持中文(可以放弃Office了)

时间:2022-12-06 06:05:41

主机平台:Gentoo 11.2

内核版本:Linux Kernel 3.2.1

原创作品,转载请标明http://blog.csdn.net/yming0221/article/details/7410027


即将面临毕业,要写毕业论文,由于自己一直使用Linux,而Linux下的Office软件兼容性实在是达不到论文的要求,以前也听说过Linux下的强大的排版工具--LaTeX。这样就不会出现换台电脑格式就会发生改变,然后忙着修改论文格式的窘境。

下面安装环境,看网络上好多都是使用texlive镜像安装,我看了一下,那镜像2个多G,好大。而且通过CJK解决中文问题(现在还不是很了解)。

下面是安装XeLaTeX的步骤

在Gentoo下直接emerge即可

Gentoo下Xetex和默认安装的texlive-core是互相block的,最终方式是选择安装texlive-xetex模块

emerge texlive-xetex -av

自动解决依赖问题。

XeLaTeX可以直接解决字体的问题,直接使用系统的字体,不用像LaTeX手动生成字体。


下面是sheriden2006的中文宏包的一个配置文件(字体得自己安装,可以从网上下载,也可以直接在win下copy)

% xetex/xelatex 字体设定宏包
\ProvidesPackage{zhfontcfg}
\usepackage[cm-default]{fontspec} %[cm-default]选项主要用来解决使用数学环境时数学符号不能正常显示的问题

\usepackage{xunicode,xltxtra}
\defaultfontfeatures{Mapping=tex-text} %如果没有它,会有一些 tex 特殊字符无法正常使用,比如连字符。
% 中文断行
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
%将系统字体名映射为逻辑字体名称,主要是为了维护的方便
\newcommand\fontnamehei{Microsoft YaHei}
\newcommand\fontnamesong{SimSun}
\newcommand\fontnamekai{AR PL KaitiM GB}
\newcommand\fontnamemono{DejaVu Sans Mono}
\newcommand\fontnameroman{Times New Roman}
%%设置常用中文字号,方便调用
\newcommand{\erhao}{\fontsize{22pt}{\baselineskip}\selectfont}
\newcommand{\xiaoerhao}{\fontsize{18pt}{\baselineskip}\selectfont}
\newcommand{\sanhao}{\fontsize{16pt}{\baselineskip}\selectfont}
\newcommand{\xiaosanhao}{\fontsize{15pt}{\baselineskip}\selectfont}
\newcommand{\sihao}{\fontsize{14pt}{\baselineskip}\selectfont}
\newcommand{\xiaosihao}{\fontsize{12pt}{\baselineskip}\selectfont}
\newcommand{\wuhao}{\fontsize{10.5pt}{\baselineskip}\selectfont}
\newcommand{\xiaowuhao}{\fontsize{9pt}{\baselineskip}\selectfont}
\newcommand{\liuhao}{\fontsize{7.5pt}{\baselineskip}\selectfont}
%设置文档正文字体为宋体
\setmainfont[BoldFont=\fontnamehei]{\fontnamesong}
\setsansfont[BoldFont=\fontnamehei]{\fontnamekai}
\setmonofont{\fontnamemono}
%楷体
\newfontinstance\KAI {\fontnamekai}
\newcommand{\kai}[1]{{\KAI#1}}
%黑体
\newfontinstance\HEI{\fontnamehei}
\newcommand{\hei}[1]{{\HEI#1}}
%英文
\newfontinstance\ENF{\fontnameroman}
\newcommand{\en}[1]{\,{\ENF#1}\,}

下面是一个tex测试文件input.tex

\documentclass{article}\usepackage{zhfontcfg}\usepackage[colorlinks,linkcolor=black]{hyperref}%opening\title{latex多字体简易示例}\author{颜开}\begin{document}\maketitle\section{楷体}\kai{楷体}\section{黑体}\hei{黑体}\end{document}

使用命令xelatex input.tex

这样就生成了input.pdf文件

LaTeX使用--使用XeLaTeX支持中文(可以放弃Office了)