教程:在Linux(Ubuntu/Debian)中编译中文TeX文件
Texlive on Linux with Chinese support
目录
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:
1 2 |
apt-get install texlive apt-get install texlive-xetex |
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
1 2 3 4 5 6 7 8 |
\documentclass{article} \usepackage{xeCJK} \setCJKmainfont{Adobe Song Std} \begin{document} hi, this is xelatex! 这是中文测试! \end{document} |
The results is, after compile as xelatex test_zh.tex
, test_zh.pdf
2.1.1. File used
- The test_zh.tex source file
- Need to download Adobe.7z Adobe Fonts and
7zr e Adobe.7z -w /usr/share/fonts/winfonts/
(create ‘winfonts’ directory first) - Refreash your font cache as here.
- 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
2.2. cjk method
1 2 3 4 5 6 |
\documentclass[UTF8]{ctexart} \begin{document} Hi, Ctex! 你好, Ctex! \end{document} |
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
- The test_ctex.tex source file
- Need to download Win7Fonts.7z and extract to the same dir as before
- Need to modify the file
/usr/share/texlive/texmf-dist/tex/generic/zhmetrics/zhwinfonts.tex
as zhwinfonts.tex - Need to add
export OSFONTDIR=/usr/share/fonts/winfonts/
in~/.bash_profile
pdflatex test_ctex.tex
test_ctex.pdf3. Reference 4. Techological Remark
- If there are some missing sty files, try to use
apt-cache search the-missing-sty | grep tex
wherethe-missing-sty
are replaced by the sty file name
and then usesudo 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 trytlmgr 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
- Firstly, just go http://www.ctan.org/ to search bbm at the top bar
- 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
- 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. - Refreash the database of texlive by the command
mktexlsr
, which will tell texlive where the package is located. - Similarly to install the macro package bbm-macros.
And how about have a look at the final result: preview of ustcthesis.
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’