zoukankan      html  css  js  c++  java
  • 两种可行的Latex中文生成方式(GBK/UTF8)

          本来想总结一下Latex里各种中文排版支持,但是发现太乱了,CCT,CJK,CTEX神马的,还有GBK和UTF8下的不同编码方式,再加上XeLatex这样来搅局的……所以最后决定只给出一种可行的排版方式,测试环境是Windows+CTex2.8。

         ps:每天忍辱负重的在Windows下用Vim和Latex……

         第一种是gbk编码下的编译方式

    REM taskkill /im AcroRd32.exe 
    pdflatex %1 
    bibtex %1 
    pdflatex %1 
    gbk2uni %1.out 
    pdflatex %1 
    start %1.pdf

          其中第一句的目的是结束掉当前的PDF文档,但是它会随机选择一个Acrobat Reader进程结束,所以给注掉了。从代码里可以看出,需要执行多遍pdflatex,同时穿插bibtex生成参考文件,gbk2uni的作用是将gbk转成unicode,这个命令是cct里的,请确保你的环境变量中有cct的bin目录。

          测试article代码如下:

    \documentclass{article} 
    \usepackage{CJK} 
    \usepackage{cite} 
    \newcommand{\upcite}[1]{\textsuperscript{\textsuperscript{\cite{#1}}}} 
    \usepackage[colorlinks,linkcolor=blue,anchorcolor=blue,citecolor=blue,CJKbookmarks]{hyperref} 
    \begin{document} 
    \begin{CJK*}{GBK}{song} 
    \title{title} 
    \author{author} 
    \maketitle 
    \tableofcontents 
    \newpage 
    中文测试\upcite{test} 
    \renewcommand\refname{参考文献} 
    \bibliographystyle{plain} 
    \bibliography{test} 
    \clearpage 
    \end{CJK*} 
    \end{document}

          测试beamer代码如下:      

    \documentclass[compress,mathserif,CJK]{beamer} 
    \usepackage{CJK} 
    \usetheme{Warsaw} 
    \newcommand{\upcite}[1]{\textsuperscript{\textsuperscript{\cite{#1}}}} 
    \usepackage{hyperref} 
    \hypersetup{colorlinks,linkcolor=blue,anchorcolor=blue,citecolor=blue,CJKbookmarks}
    \begin{document} 
    \begin{CJK*}{GBK}{kai} 
    \title{title} 
    \author{author} 
    \frame{\titlepage} 
    \frame{\tableofcontents} 
    \frame{ 
    \frametitle{测试} 
    \begin{block}{测试} 
    测试\upcite{test} 
    \end{block} 

    \section{参考文献} 
    \begin{frame} 
    \frametitle{参考文献} 
    \bibliographystyle{plain} 
    \bibliography{test} 
    \end{frame} 
    \clearpage 
    \end{CJK*} 
    \end{document}

          第二种方式是UTF8下的编译方式

    REM taskkill /im AcroRd32.exe 
    pdflatex %1 
    bibtex %1 
    pdflatex %1 
    pdflatex %1 
    start %1.pdf

           可以看出,省了gbk2uni命令。所以推荐用这种,至少心理上觉得快一点……

           测试article代码如下:

    \documentclass{article} 
    \usepackage{CJKutf8
    \usepackage{cite} 
    \newcommand{\upcite}[1]{\textsuperscript{\textsuperscript{\cite{#1}}}} 
    \usepackage[colorlinks,linkcolor=blue,anchorcolor=blue,citecolor=blue,unicode]{hyperref} 
    \begin{document} 
    \begin{CJK*}{UTF8}{song} 
    \title{title} 
    \author{author} 
    \maketitle 
    \tableofcontents 
    \newpage 
    中文测试\upcite{test} 
    \renewcommand\refname{参考文献} 
    \bibliographystyle{plain} 
    \bibliography{test} 
    \clearpage 
    \end{CJK*} 
    \end{document}

            与GBK下不同的地方用红色标出了,\clearpage的作用见参考文献[4],另外bib文件也请转换成utf8格式。

            测试beamer代码如下:

    \documentclass[compress,mathserif,CJKutf8]{beamer} 
    \usepackage{CJKutf8
    \usetheme{Warsaw} 
    \newcommand{\upcite}[1]{\textsuperscript{\textsuperscript{\cite{#1}}}} 
    \usepackage{hyperref} 
    \hypersetup{colorlinks,linkcolor=blue,anchorcolor=blue,citecolor=blue,unicode}
    \begin{document} 
    \begin{CJK*}{UTF8}{kai} 
    \title{title} 
    \author{author} 
    \frame{\titlepage} 
    \frame{\tableofcontents} 
    \frame{ 
    \frametitle{测试} 
    \begin{block}{测试} 
    测试\upcite{test} 
    \end{block} 

    \section{参考文献} 
    \begin{frame} 
    \frametitle{参考文献} 
    \bibliographystyle{plain} 
    \bibliography{test} 
    \end{frame} 
    \clearpage 
    \end{CJK*} 
    \end{document}

            同样与GBK的不同已经标出,需要特别注意的是,直接编译是会报错的,需要修改一下beamer.cls,具体修改方法见参考文献[1]。

            如有错误请留言。

    参考文献:

    [1] 在beamer中使用utf8的中文标签,

    http://hi.baidu.com/wtx358/blog/item/8e94698969f771b40e244463.html

    [2] CJK中文PDF书签乱码解决[hyperref],

    http://hi.baidu.com/asnahu/blog/item/8d2d8a3194e3a7a65edf0efe.html

    [3] ubuntu下texlive使用CJKutf8生成中文目录,

    http://bbs.sciencenet.cn/home.php?mod=space&uid=436869&do=blog&id=493277

    [4] CJKutf8 results in error in TOC,

    http://www.digipedia.pl/usenet/thread/16691/248/

    [5]关于Beamer的几个问题请教,

    http://bbs.ctex.org/redirect.php?tid=39095&goto=lastpost&styleid=7

     
  • 相关阅读:
    一、数据库概念和操作数据库的命令
    [LeetCode] 208. Implement Trie (Prefix Tree) ☆☆☆
    [LeetCode] 329. Longest Increasing Path in a Matrix ☆☆☆
    [LeetCode] 382. Linked List Random Node ☆☆☆
    Java异常之try,catch,finally,throw,throws
    C#畅谈“网络电视”
    JavaWeb项目导入MyEclipse后变为JAVA项目项目【解决方法】
    springmvc学习笔记(理论)
    Struts2之类型转换器
    Oracle笔记
  • 原文地址:https://www.cnblogs.com/sdqxcxh/p/2399519.html
Copyright © 2011-2022 走看看