教程:在Linux(Ubuntu/Debian)中编译中文TeX文件


Texlive on Linux with Chinese support Van Abel

摘要. 本教程并非手把手的教你如何在Linux机器上编译中文文件. 而是我作为尝试编译ustcthesis的一个学习记录.

目录
Contents
 1.  Install of texlive
 2.  Chinese Support
   2.1.  xecjk method
     2.1.1.  File used
   2.2.  cjk method
 3.  Reference
 4.  Techological Remark
 5.  Test of ustcthesis

1. Install of texlive A lot of people will try to tell you install texlive by hand (download the texlive2014.iso), but I find it is about 2.5G, so why not just install texlive form the apt-get?

I follow here:

of course this will not make chinese support for texlive.
2. Chinese Support There are two method of texlive to support chinese. One is xecjk method, the other is cjk.
2.1. xecjk method


The results is, after compile as xelatex test_zh.tex, test_zh.pdf
2.1.1. File used

  1. The test_zh.tex source file
  2. Need to download Adobe.7z Adobe Fonts and 7zr e Adobe.7z -w /usr/share/fonts/winfonts/ (create ‘winfonts’ directory first)
  3. Refreash your font cache as here.
  4. Need to modify /usr/share/texlive/texmf-dist/tex/latex/ctex/fontset/ctex-xecjk-winfonts.def (please adapt it to your installation of texlive) as in the file ctex-xecjk-winfonts.def
If you have other problems, please take a look at the end of this post!
2.2. cjk method

firstly, let us compile is as latex test_ctex.tex, this will output test_ctex.dvi
Secondly, in order to make pdflatex work, we need the following:
2.1.1. File used

  1. The test_ctex.tex source file
  2. Need to download Win7Fonts.7z and extract to the same dir as before
  3. Need to modify the file /usr/share/texlive/texmf-dist/tex/generic/zhmetrics/zhwinfonts.tex as zhwinfonts.tex
  4. Need to add export OSFONTDIR=/usr/share/fonts/winfonts/ in ~/.bash_profile
And finally, we will get, after complie as pdflatex test_ctex.tex test_ctex.pdf
3. Reference
  1. Ubuntu下安装TeX Live并配置中文支持
  2. UnixFonts
  3. $OSFONTDIR on OSX
4. Techological Remark
  • If there are some missing sty files, try to use

    apt-cache search the-missing-sty | grep tex

    where the-missing-sty are replaced by the sty file name
    and then use sudo apt-get install the-find-package to install.

    I finally installed the following package

    sudo apt-get install latex-cjk-chinese texlive-bibtex-extra texlive-math-extra texlive-science texlive-science-doc texlive-latex-extra

  • you can also install the missing package by
    tlmgr install the-missing-package
  • If tlmgr report the error:
    cannot setup TLPDB in /root/texmf at /usr/bin/tlmgr line 5336.
    please try tlmgr init-usertree, I get the solution from here
  • If tlmgr report the error:
    /usr/bin/tlmgr: Please install xzdec and try again.
    Then try
    sudo apt-get install xzdec
  • If you find some package can’t be installed successfully by tlmgr, then try to install it by hand. This is not so hard at all, as an example, let me show you how to install bbm.sty
    1. Firstly, just go http://www.ctan.org/ to search bbm at the top bar
    2. It will show you that there are two packages, one is the font package bbm, and the other is the macros package bbm-macros, we need to install both of them
    3. click the link of font package bbm, we can see the sources is /fonts/cm/bbm, then download all the package by click the link at the bottom, to the directory ~/texmf/fonts/cm/bbm, maybe you have already noticed that we put the source in the local directory texmf.
    4. Refreash the database of texlive by the command mktexlsr, which will tell texlive where the package is located.
    5. Similarly to install the macro package bbm-macros.
5. Test of ustcthesis At last, you can compile ustcthesis easily, The uploading file has correct the error mentioned here. which is caused by the too old version of ctex, I think.

And how about have a look at the final result: preview of ustcthesis.

2 条关于 “教程:在Linux(Ubuntu/Debian)中编译中文TeX文件”的评论

  1. some error happened still:

    (/usr/local/texlive/2015/texmf-dist/tex/latex/url/url.sty)kpathsea:make_tex: Invalid fontname `Times New Roman’, contains ‘ ‘
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    !
    ! fontspec error: “font-not-found”
    !
    ! The font “Times New Roman” cannot be found.

    Have you ever seen his problem?
    How to solve it?
    Thank you.

    • I believe the problem is missing Times New Roman, since it is not inclued by texlive as distribution. See here for a solution suggestion: http://tex.stackexchange.com/a/273560/19832.

      By the way, I did not test the texlive with english complie (as my goal is to compile chinese USTCThesis), if you want to test texlive, try to begin with very simple tex file, such as only one line on wiki: tex ’empty Hello world!bye’

发表回复

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

*