歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> LaTeX使用--使用XeLaTeX支持中文(可以放棄Office了)

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

日期:2017/2/28 15:53:46   编辑:Linux教程

主機平台: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. \ProvidesPackage{zhfontcfg}
  3. \usepackage[cm-default]{fontspec} %[cm-default]選項主要用來解決使用數學環境時數學符號不能正常顯示的問題
  4. \usepackage{xunicode,xltxtra}
  5. \defaultfontfeatures{Mapping=tex-text} %如果沒有它,會有一些 tex 特殊字符無法正常使用,比如連字符。
  6. % 中文斷行
  7. \XeTeXlinebreaklocale "zh"
  8. \XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
  9. %將系統字體名映射為邏輯字體名稱,主要是為了維護的方便
  10. \newcommand\fontnamehei{Microsoft YaHei}
  11. \newcommand\fontnamesong{SimSun}
  12. \newcommand\fontnamekai{AR PL KaitiM GB}
  13. \newcommand\fontnamemono{DejaVu Sans Mono}
  14. \newcommand\fontnameroman{Times New Roman}
  15. %%設置常用中文字號,方便調用
  16. \newcommand{\erhao}{\fontsize{22pt}{\baselineskip}\selectfont}
  17. \newcommand{\xiaoerhao}{\fontsize{18pt}{\baselineskip}\selectfont}
  18. \newcommand{\sanhao}{\fontsize{16pt}{\baselineskip}\selectfont}
  19. \newcommand{\xiaosanhao}{\fontsize{15pt}{\baselineskip}\selectfont}
  20. \newcommand{\sihao}{\fontsize{14pt}{\baselineskip}\selectfont}
  21. \newcommand{\xiaosihao}{\fontsize{12pt}{\baselineskip}\selectfont}
  22. \newcommand{\wuhao}{\fontsize{10.5pt}{\baselineskip}\selectfont}
  23. \newcommand{\xiaowuhao}{\fontsize{9pt}{\baselineskip}\selectfont}
  24. \newcommand{\liuhao}{\fontsize{7.5pt}{\baselineskip}\selectfont}
  25. %設置文檔正文字體為宋體
  26. \setmainfont[BoldFont=\fontnamehei]{\fontnamesong}
  27. \setsansfont[BoldFont=\fontnamehei]{\fontnamekai}
  28. \setmonofont{\fontnamemono}
  29. %楷體
  30. \newfontinstance\KAI {\fontnamekai}
  31. \newcommand{\kai}[1]{{\KAI#1}}
  32. %黑體
  33. \newfontinstance\HEI{\fontnamehei}
  34. \newcommand{\hei}[1]{{\HEI#1}}
  35. %英文
  36. \newfontinstance\ENF{\fontnameroman}
  37. \newcommand{\en}[1]{\,{\ENF#1}\,}
下面是一個tex測試文件input.tex
  1. \documentclass{article}
  2. \usepackage{zhfontcfg}
  3. \usepackage[colorlinks,linkcolor=black]{hyperref}
  4. %opening
  5. \title{latex多字體簡易示例}
  6. \author{顏開}
  7. \begin{document}
  8. \maketitle
  9. \section{楷體}
  10. \kai{楷體}
  11. \section{黑體}
  12. \hei{黑體}
  13. \end{document}
使用命令xelatex input.tex

這樣就生成了input.pdf文件


Copyright © Linux教程網 All Rights Reserved