PdfLaTeX, XeLaTeX, LaTeX三种模式都兼容的模板(半中文版)

我们常用的编译模式有如下几种:PdfLaTeX, XeLaTeX, LaTeX, 各有各的优势.

今天, 就尝试了下如何把这三种模式整合到一起. (xelatex编译后的效果)

直接看代码吧:

\RequirePackage{ifxetex,ifpdf}
\ifxetex
%如果是xetex模式
\documentclass[12pt]{article}
%\XeTeXinputencoding "cp936"
\XeTeXinputencoding "utf8"
\usepackage{ctex}
\punctstyle{kaiming}
\else
\ifpdf
%如果是pdflatex模式
\documentclass[12pt, pdftex]{article}
\else
%如果是latex模式
\documentclass[12pt, dvipdfmx]{article}
\fi
\fi
%\listfiles
\usepackage[driverfallback=dvipdfmx]{hyperref}
\begin{document}
  \title{The pdf\LaTeX{}, Xe\LaTeX{}, \LaTeX{} Compatible Mode}
  \author{\href{mailto:[email protected]}{MATHWIZARD}}
  \date{}
  \maketitle
  如果你用的是Xe\LaTeX{}的编译模式, 那么也能够看到汉字了. 否则请用CJK包吧.
  
\end{document} 

技术很简单, 就是用ifxetex, ifpdf这两大宏包判断编译模式. 而为了统一编码, 使用了一句:\XeTeXinputencoding “cp936″.
同时为了测试中文, 我在xelatex下调用了中文处理宏包xecjk, 传说是现代流行的处理方式. 较旧的处理方式:cjk可以自己添加进去. 这也是为什么我的题目叫”半中文版”.

2 条关于 “PdfLaTeX, XeLaTeX, LaTeX三种模式都兼容的模板(半中文版)”的评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

*

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理