CentOS6.5 下安裝 texlive2015 並設置 ctex 中文套裝


寫在前面:用紅色字體標出的是CentOS7 下安裝 TexLive2017 的記錄,參考自《Linux 下安裝 TeXLive 2017》。

-1 參考資料

[1] http://www.tug.org/texlive/doc/texlive-zh-cn/texlive-zh-cn.pdf  《TEX Live 指南—2015

[2] http://www.cnblogs.com/lienhua34/p/3675027.html        《ubuntu 下安裝 texlive 並設置 ctex 中文套裝

[3] http://seisman.info/install-texlive-under-linux.html       《Linux下安裝TeXLive 2015

[4] http://seisman.info/install-texlive-under-linux.html             《Linux 下安裝 TeXLive 2017

 

0 卸載舊版本的 texlive

0.1 卸載 texlive2007

如果系統沒有安裝過texlive,則跳過第0步。

可以在終端中使用如下命令查詢本機已經安裝的tex和latex版本:

[She@She LaTex_test]$ tex --version
TeX 3.141592 (Web2C 7.5.6)
kpathsea version 3.5.6
Copyright 2007 D.E. Knuth.
Kpathsea is copyright 2007 Karl Berry and Olaf Weber. ... [She@She LaTex_test]$ latex --version pdfTeX using libpoppler 3.141592-1.40.3-2.2 (Web2C 7.5.6)
kpathsea version 3.5.6
Copyright 2007 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Kpathsea is copyright 2007 Karl Berry and Olaf Weber. ...

通常,采用系統命令 1 sudo yum install texlive-latex ,自動安裝的texlive的版本都比較舊。

如果查到的版本太舊,則手動卸載和刪除它們,在終端中依次執行如下命令:

 1 sudo yum remove texlive-latex  2 sudo rm -rf /usr/local/texlive/2015  3 sudo rm -rf ~/.texlive2015  4 sudo rm -rf /usr/local/share/texmf  5 sudo rm -rf /var/lib/texmf  6 sudo rm -rf /etc/texmf  7 sudo rm -rf /usr/share/texmf  8 sudo rm -rf /usr/share/texmf-errata  9 sudo yum remove tex-common 10 sudo rm -rf ~/.texlive

至此,系統上的texlive清除完畢,重啟電腦之后,就可以開始新版本的安裝工作。

 

1 安裝 texlive2015

1.1 下載 texlive2015

下載地址: http://mirror.hust.edu.cn/CTAN/systems/texlive/Images/texlive2015-20150523.iso,這是來自華中科技大學的鏡像。

CentOS7 下安裝 TexLive2017:華中科技大學的鏡像下載速度太慢,改為下載官方鏡像

1.2 掛載 iso並安裝texlive2015

將下載的 texlive2015-20150523.iso 掛載到/mnt 目錄下並運行 install-tl 進行安裝

 sudo mount -o loop texlive2015-20150523.iso /mnt/tmp
 cd /mnt/tmp
 sudo ./install-tl

出現選項之后,輸入   I   直接安裝即可,幾分鍾即可安裝完畢。

[She@She tmp]$ sudo ./install-tl
Loading ./tlpkg/texlive.tlpdb
Installing TeX Live 2015 from: .
Platform: x86_64-linux => 'GNU/Linux on x86_64'
Distribution: inst (compressed)
Directory for temporary files: /tmp

======================> TeX Live installation procedure <=====================

======>   Letters/digits in <angle brackets> indicate   <=======
======>   menu items for commands or options            <=======

 Detected platform: GNU/Linux on x86_64
 
 <B> binary platforms: 1 out of 14

 <S> set installation scheme (scheme-full)

 <C> customizing installation collections
     47 collections out of 48, disk space required: 4044 MB

 <D> directories:
   TEXDIR (the main TeX directory):
     /usr/local/texlive/2015
   TEXMFLOCAL (directory for site-wide local files):
     /usr/local/texlive/texmf-local
   TEXMFSYSVAR (directory for variable and automatically generated data):
     /usr/local/texlive/2015/texmf-var
   TEXMFSYSCONFIG (directory for local config):
     /usr/local/texlive/2015/texmf-config
   TEXMFVAR (personal directory for variable and automatically generated data):
     ~/.texlive2015/texmf-var
   TEXMFCONFIG (personal directory for local config):
     ~/.texlive2015/texmf-config
   TEXMFHOME (directory for user-specific files):
     ~/texmf

 <O> options:
   [ ] use letter size instead of A4 by default
   [X] allow execution of restricted list of programs via \write18
   [X] create all format files
   [X] install macro/font doc tree
   [X] install macro/font source tree
   [ ] create symlinks to standard directories
   [X] after install, use tlnet on CTAN for package updates

 <V> set up for portable installation

Actions:
 <I> start installation to hard disk
 <H> help
 <Q> quit

Enter command: I

 

安裝完成之后, 提示如下:

...
Installing [3051/3056, time/total: 06:07/06:07]: zlmtt [56k]
Installing [3052/3056, time/total: 06:07/06:07]: zwgetfdate [242k]
Installing [3053/3056, time/total: 06:07/06:07]: zwpagelayout [587k]
Installing [3054/3056, time/total: 06:07/06:07]: zxjafbfont [3k]
Installing [3055/3056, time/total: 06:07/06:07]: zxjafont [136k]
Installing [3056/3056, time/total: 06:07/06:07]: zxjatype [142k]
Time used for installing the packages: 06:07
running mktexlsr /usr/local/texlive/2015/texmf-dist ...
mktexlsr: Updating /usr/local/texlive/2015/texmf-dist/ls-R... 
mktexlsr: Done.
writing fmtutil.cnf to /usr/local/texlive/2015/texmf-dist/web2c/fmtutil.cnf
writing updmap.cfg to /usr/local/texlive/2015/texmf-dist/web2c/updmap.cfg
writing language.dat to /usr/local/texlive/2015/texmf-var/tex/generic/config/language.dat
writing language.def to /usr/local/texlive/2015/texmf-var/tex/generic/config/language.def
writing language.dat.lua to /usr/local/texlive/2015/texmf-var/tex/generic/config/language.dat.lua
running mktexlsr /usr/local/texlive/2015/texmf-var /usr/local/texlive/2015/texmf-config /usr/local/texlive/2015/texmf-dist ...
mktexlsr: Updating /usr/local/texlive/2015/texmf-config/ls-R... 
mktexlsr: Updating /usr/local/texlive/2015/texmf-dist/ls-R... 
mktexlsr: Updating /usr/local/texlive/2015/texmf-var/ls-R... 
mktexlsr: Done.
running updmap-sys --nohash ...done
re-running mktexlsr /usr/local/texlive/2015/texmf-var /usr/local/texlive/2015/texmf-config ...
mktexlsr: Updating /usr/local/texlive/2015/texmf-config/ls-R... 
mktexlsr: Updating /usr/local/texlive/2015/texmf-var/ls-R... 
mktexlsr: Done.
setting up ConTeXt cache: running mtxrun --generate ...done
pre-generating all format files, be patient...
running fmtutil-sys --no-error-if-no-engine=luajittex --all ...done
running package-specific postactions
finished with package-specific postactions

 See
   /usr/local/texlive/2015/index.html
 for links to documentation.  The TeX Live web site
 contains updates and corrections: http://tug.org/texlive.

 TeX Live is a joint project of the TeX user groups around the world;
 please consider supporting it by joining the group best for you. The
 list of user groups is on the web at http://tug.org/usergroups.html.

 Add /usr/local/texlive/2015/texmf-dist/doc/info to INFOPATH.
 Add /usr/local/texlive/2015/texmf-dist/doc/man to MANPATH
   (if not dynamically found).

 Most importantly, add /usr/local/texlive/2015/bin/x86_64-linux
 to your PATH for current and future sessions.

 Welcome to TeX Live!
Logfile: /usr/local/texlive/2015/install-tl.log
[She@She tmp]$ 

至此,texlive2015已經成功安裝。

將 texlive2015-20150523.iso 卸載.

cd ..
sudo umount /mnt/tmp

1.3 修改環境變量

texlive 默認的安裝目錄是/usr/local/texlive/2015/bin/x86_64-linux/ (64位系統)或.../i386-linux/ (32位系統),為了讓 shell 能夠自動找到 tex 的 bin 文件,我們需要修改環境變量 PATH。

如果我們希望系統也能夠自動找到 texlive 的 man 或 info 文檔,我們一並修改環境變量 MANPATH 和 INFOPATH。

在終端輸入如下,編輯 $HOME/.bashrc 文檔 或 $HOME/.bash_profile 或 /etc/profile.d/texlive2017.sh (三個文檔只需修改其中一個) :

vim ~/.bashrc

或 在 ~/.bashrc 中添加下面的內容:

PATH=/usr/local/texlive/2015/bin/x86_64-linux:$PATH; export PATH
MANPATH=/usr/local/texlive/2015/texmf-dist/doc/man:$MANPATH; export MANPATH
INFOPATH=/usr/local/texlive/2015/texmf-dist/doc/man:$INFOPATH; export INFOPATH

又或 在 /etc/profile.d/texlive2017.sh 中添加以下內容:

#!/bin/bash
# setting for TexLive 2017 environment variables, edit by She
export PATH="/usr/local/texlive/2017/bin/x86_64-linux":$PATH
export MANPATH="/usr/local/texlive/2017/texmf-dist/doc/man":$MANPATH
export INFOPATH="/usr/local/texlive/2017/texmf-dist/doc/info":$INFOPATH
export TEXINPUTS="/usr/local/texlive/2017/texmf-dist/tex/latex/latexconfig"
export TEXMF="/usr/local/texlive/2017/texmf-dist"

 

 

 

接着,修改/etc/man.config (CentOS7對應的是這個文件: sudo gedit /etc/man_db.conf )

 sudo vi /etc/man.config

在# set up PATH to MANPATH mapping下輸入 (注意:中間的空白部分不是空格,而是Tab分隔符)

MANPATH_MAP  /usr/local/texlive/2015/bin/x86_64-linux  /usr/local/texlive/2015/texmf-dist/doc/man

重啟。

1.4 測試安裝是否成功

(1)首先確認我們安裝的 tex 和latex 版本

[She@She tmp]$ tex --version
TeX 3.14159265 (TeX Live 2015) kpathsea version 6.2.1 Copyright 2015 D.E. Knuth.
[She@She tmp]$ latex --version
pdfTeX 3.14159265-2.6-1.40.16 (TeX Live 2015) kpathsea version 6.2.1 Copyright 2015 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).

(2)編寫一個簡單的 tex 文件,然后編譯它

新建一個 test.tex 文件,然后輸入下面內容

 \documentclass{article}  \begin{document}  Hello \LaTeX!  \end{document}

然后運行下面命令即可生成 test.pdf。

 [She@She LaTex_test]$ xelatex test.tex

雙擊打開 test.pdf,看到如下內容

  

現在,texlive可以正常工作。

2 配置中文環境和中文字體安裝

2.1 拷貝Windows字體

 (1) 創建Windows字體目錄WinFonts和Adobe字體目錄AdobeFonts。

 sudo mkdir /usr/share/fonts/WinFonts
 sudo mkdir /usr/share/fonts/AdobeFonts

WinFonts位於C:\Windows\fonts\文件夾下,只要ttf、TTF、ttc 和 TTC 格式的中文字體(SimSun字體對應的文件是 simsun.ttc);Adobe的字體則位於它的安裝目錄下,一個名叫font的文件夾內。

 (2) 復制上述准備的字體到各自目錄。

 sudo cp /media/Ushe/WindowsFonts/* /usr/share/fonts/WinFonts
 sudo cp /media/Ushe/AdobeFonts/* /usr/share/fonts/AdobeFonts

 這里需要注意:修改上面拷貝字體的權限 

              sudo chmod 644 /usr/share/fonts/WinFonts/*

              sudo chmod 644 /usr/share/fonts/AdobeFonts/*

如果沒有這一步,會在編譯tex文件時出現下面類似的錯誤:

              SimSun at 17.28pt not loadable

 (3) 刷新字體緩存

sudo  mkfontscale
sudo  mkfontdir
sudo  fc-cache -fsv

2.2 安裝中文字體后的配置

(1) 查看系統中安裝的中文字體的名字。

fc-list :lang=zh | sort

(2) 查看並根據生成的 fonts 編輯 ctex-xecjk-winfonts.def(如果不存在,則新建該文件)[CentOS7 中安裝 TexLive2017 時,可略過這一步]

sudo  vi /usr/local/texlive/2015/texmf-dist/tex/latex/ctex/fontset/ctex-xecjk-winfonts.def

 編輯前ctex-xecjk-winfonts.def如下:

% ctex-xecjk-winfonts.def: Windows 的 xeCJK 字體設置,默認為六種中易字體
%vim:ft=tex/setCJKmainfont[BoldFont={SimHei},ItalicFont={[simkai.ttf]}]  
{SimSun}
/setCJKsansfont{SimHei}
/setCJKmonofont{[simfang.ttf]}
/setCJKfamilyfont{zhsong}{SimSun}
/setCJKfamilyfont{zhhei}{SimHei}
/setCJKfamilyfont{zhkai}{[simkai.ttf]}
/setCJKfamilyfont{zhfs}{[simfang.ttf]}
/newcommand*{/songti}{/CJKfamily{zhsong}} % 宋體
/newcommand*{/heiti}{/CJKfamily{zhhei}}   % 黑體
/newcommand*{/kaishu}{/CJKfamily{zhkai}}  % 楷書
/newcommand*{/fangsong}{/CJKfamily{zhfs}} % 仿宋
/newcommand*{/lishu}{/CJKfamily{zhli}}    % 隸書
/newcommand*{/youyuan}{/CJKfamily{zhyou}} % 幼圓
/endinput

編輯后 ctex-xecjk-winfonts.def 的內容:

% ctex-xecjk-winfonts.def: Windows 的 xeCJK 字體設置,默認為六種中易字體
% vim:ft=tex
/setCJKmainfont[BoldFont={SimHei},ItalicFont={KaiTi}]  {SimSun}
/setCJKsansfont{SimHei}
/setCJKmonofont{FangSong}
/setCJKfamilyfont{zhsong}{SimSun}
/setCJKfamilyfont{zhhei}{SimHei}
/setCJKfamilyfont{zhkai}{KaiTi}
/setCJKfamilyfont{zhfs}{FangSong}
/setCJKfamilyfont{zhli}{LiSu}
/setCJKfamilyfont{zhyou}{YouYuan}
/newcommand*{/songti}{/CJKfamily{zhsong}} % 宋體
/newcommand*{/heiti}{/CJKfamily{zhhei}}   % 黑體
/newcommand*{/kaishu}{/CJKfamily{zhkai}}  % 楷書
/newcommand*{/fangsong}{/CJKfamily{zhfs}} % 仿宋
/newcommand*{/lishu}{/CJKfamily{zhli}}    % 隸書
/newcommand*{/youyuan}{/CJKfamily{zhyou}} % 幼圓
/endinput

(3)  同上.查看並根據生成的fonts文件修改ctex-xecjk-adobefonts.def。

3 測試ctex中文套裝

要使我們的texlive支持中文,我們使用ctex套裝。

關於ctex的介紹見 http://www.ctex.org/HomePage。

texlive 安 裝 包 默 認 攜帶 了 ctex 宏 包,ctex 宏 包 的 目 錄 為/usr/local/texlive/2015/texmf-dist/tex/latex/ctex。

3.1  測試1

輸入一個典型的中文支持例子測試,新建一個名為test.tex的文件,其內容如下:

\documentclass[UTF8]{ctexart}
\begin{document}
這是我的第一個\TeX{}文件
\end{document}

用xelatex命令編譯: [She@She LaTex_test]$ xelatex test.tex 

結果如下,

3.2  測試2

我們新建一個 ctex.tex 文件,輸入下面的內容

\documentclass{ctexart}
\begin{document}
您好,\LaTeX!
\end{document}

保存,然后運行下面命令,可以得到結果。

[She@She LaTex_test]$ xelatex ctex.tex

 

4 更新源配置

配置合適的CTAN源可以加快宏包更新的網速,以中科大的源為例:

$ su
密碼:
[root@localhost She]#
tlmgr option repository http://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet
tlmgr: setting default package repository to http://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet

之后,可以利用  tlmgr  進行網絡更新。CTAN 上的包更新很頻繁,所以即便是最新版的 texlive2017,其中也有大量的宏包需要更新(可能包括 tlmgr 程序本身)

[root@localhost She]# tlmgr update --self # 更新 TeXLive 包管理器 tlmgr
tlmgr: package repository http://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet (verified)
tlmgr: saving backups to /usr/local/texlive/2017/tlpkg/backups
[1/1, ??:??/??:??] update: texlive.infra [339k] (44424 -> 44836) ... done
running mktexlsr ...
done running mktexlsr.
running mtxrun --generate ...
done running mtxrun --generate.
tlmgr: package log updated: /usr/local/texlive/2017/texmf-var/web2c/tlmgr.log [root@localhost She]#
tlmgr update --all # 更新 TeXLive 的全部包
tlmgr: package repository http://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet (verified)
tlmgr: saving backups to /usr/local/texlive/2017/tlpkg/backups
[  1/192] auto-remove: rputover ... done
[  2/192, ??:??/??:??] update: GS1 [1125k] (27540 -> 44822) ... done
[  3/192, 00:05/15:54] update: acmart [6410k] (44367 -> 44745) ... done
[  4/192, 00:10/04:44] update: acro [595k] (43186 -> 44667) ... done
[  5/192, 00:13/05:43] update: actuarialsymbol [293k] (43768 -> 44607) ... done
[  6/192, 00:25/10:36] update: adobemapping [1944k] (44085 -> 44861) ... done
[  7/192, 00:28/09:39] update: algorithm2e [579k] (38805 -> 44846) ... done
[  8/192, 00:29/09:28] update: apa6 [602k] (42516 -> 44652) ... done
[  9/192, 00:31/09:36] update: apxproof [452k] (43527 -> 44478) ... done
...
[189/192, 07:52/07:52] update: collection-luatex [1k] (42670 -> 44500) ... done
[190/192, 07:53/07:53] update: collection-pictures [2k] (44395 -> 44823) ... done
[191/192, 07:54/07:54] update: collection-pstricks [1k] (44305 -> 44742) ... done
[192/192, 07:55/07:55] update: collection-publishers [2k] (44026 -> 44485) ... done
running mktexlsr ...
done running mktexlsr.
running mtxrun --generate ...
done running mtxrun --generate.
running updmap-sys ...
done running updmap-sys.
regenerating fmtutil.cnf in /usr/local/texlive/2017/texmf-dist
running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine xetex ...
done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine xetex.
running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --no-error-if-no-format --byengine euptex ...
...
running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --byfmt latex ...
done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --byfmt latex.
running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --byfmt platex ...
done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --byfmt platex.
...
running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --byfmt pdfxmltex ...
done running fmtutil-sys --no-error-if-no-engine=luajittex,mfluajit --byfmt pdfxmltex.
...
tlmgr: package log updated: /usr/local/texlive/2017/texmf-var/web2c/tlmgr.log

最后,利用  texhash  命令進行位置的更新:

[root@localhost She]# texhash
texhash: Updating /usr/local/texlive/2017/texmf-config/ls-R... 
texhash: Updating /usr/local/texlive/2017/texmf-dist/ls-R...
texhash: Updating /usr/local/texlive/2017/texmf-var/ls-R...
texhash: Updating /usr/local/texlive/texmf-local/ls-R...
texhash: Done.

更新完成。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM