写在前面:用红色字体标出的是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.
更新完成。