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


主机平台:Gentoo 11.2

内核版本:Linux Kernel 3.2.1

即将面临毕业,要写毕业论文,由于自己一直使用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)

  1. % xetex/xelatex 字体设定宏包  
  2.   
  3. \ProvidesPackage{zhfontcfg}  
  4. \usepackage[cm-default]{fontspec} %[cm-default]选项主要用来解决使用数学环境时数学符号不能正常显示的问题  
  5.   
  6. \usepackage{xunicode,xltxtra}  
  7. \defaultfontfeatures{Mapping=tex-text} %如果没有它,会有一些 tex 特殊字符无法正常使用,比如连字符。  
  8. % 中文断行  
  9. \XeTeXlinebreaklocale "zh"  
  10. \XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt  
  11. %将系统字体名映射为逻辑字体名称,主要是为了维护的方便  
  12. \newcommand\fontnamehei{Microsoft YaHei}  
  13. \newcommand\fontnamesong{SimSun}  
  14. \newcommand\fontnamekai{AR PL KaitiM GB}  
  15. \newcommand\fontnamemono{DejaVu Sans Mono}  
  16. \newcommand\fontnameroman{Times New Roman}  
  17. %%设置常用中文字号,方便调用  
  18. \newcommand{\erhao}{\fontsize{22pt}{\baselineskip}\selectfont}  
  19. \newcommand{\xiaoerhao}{\fontsize{18pt}{\baselineskip}\selectfont}  
  20. \newcommand{\sanhao}{\fontsize{16pt}{\baselineskip}\selectfont}  
  21. \newcommand{\xiaosanhao}{\fontsize{15pt}{\baselineskip}\selectfont}  
  22. \newcommand{\sihao}{\fontsize{14pt}{\baselineskip}\selectfont}  
  23. \newcommand{\xiaosihao}{\fontsize{12pt}{\baselineskip}\selectfont}  
  24. \newcommand{\wuhao}{\fontsize{10.5pt}{\baselineskip}\selectfont}  
  25. \newcommand{\xiaowuhao}{\fontsize{9pt}{\baselineskip}\selectfont}  
  26. \newcommand{\liuhao}{\fontsize{7.5pt}{\baselineskip}\selectfont}  
  27. %设置文档正文字体为宋体  
  28. \setmainfont[BoldFont=\fontnamehei]{\fontnamesong}  
  29. \setsansfont[BoldFont=\fontnamehei]{\fontnamekai}  
  30. \setmonofont{\fontnamemono}  
  31. %楷体  
  32. \newfontinstance\KAI {\fontnamekai}  
  33. \newcommand{\kai}[1]{{\KAI#1}}  
  34. %黑体  
  35. \newfontinstance\HEI{\fontnamehei}  
  36. \newcommand{\hei}[1]{{\HEI#1}}  
  37. %英文  
  38. \newfontinstance\ENF{\fontnameroman}  
  39. \newcommand{\en}[1]{\,{\ENF#1}\,}  
下面是一个tex测试文件input.tex
  1. \documentclass{article}  
  2.   
  3. \usepackage{zhfontcfg}  
  4. \usepackage[colorlinks,linkcolor=black]{hyperref}  
  5. %opening  
  6. \title{latex多字体简易示例}  
  7. \author{颜开}  
  8. \begin{document}  
  9. \maketitle  
  10. \section{楷体}  
  11. \kai{楷体}  
  12. \section{黑体}  
  13. \hei{黑体}  
  14. \end{document}  
使用命令xelatex input.tex

这样就生成了input.pdf文件


相关内容