TexLive的配置和使用

以前使用miktex编译Letex,很久没更新,没法自动安装缺失的包。Google之后,考虑使用TexLive,并使用清华大学镜像。以下内容简要说明其步骤。

1、安装TexLive

1) 下载与安装

网上很多都是直接下载安装包进行安装,一般要超过4G大小的一个镜像。个人对这种方法无爱,以下安装使用的是在线安装模式。 首先下载install-tl.zip。 解压之后,进入install-tl-日期目录,编辑install-tl-advanced.bat文件,添加清华的镜像源:

1
-repository https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet
完整的命令行如下:
1
call "%~dp0install-tl-windows.bat" -repository https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet -gui perltk %*

双击修改后的install-tl-advanced.bat文件,进入GUI安装模式,根据自己的情况配置。这里安装路径设置为D:\Dev\TexLive,安装模式为portable

为了省事,可以选择全部安装,也可以选择自定义安装包。下图给出自定义的安装包:

配置完成之后,点击安装TexLive,可以开始喝茶慢慢等。安装完成之后,在环境变量PATH中添加TexLive的路径:D:\Dev\TexLive\win32\bin。至此TexLive已经基本可以使用了。

2) 安装TexLiveonfly

进入命令行模式,使用tlmgr进行包的管理。

1
2
3
4
5
6
7
$ tlmgr search texliveonfly
texliveonfly - On-the-fly download of missing TeX live packages

$ tlmgr install texliveonfly
tlmgr.pl: package repository https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/tlnet (not verified: gpg unavailable)
tlmgr.pl install: package already present: texliveonfly

texliveonfly安装完成后,修改其默认的配置参数:进入目录D:\Dev\TexLive\texmf-dist\scripts\texliveonfly,编辑texliveonfly.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
### 第一处修改 ###
#defaultCompiler = "pdflatex"
defaultCompiler = "xelatex" # pdflatex 改为 xelatex

### 第二处修改 ###
if __name__ == '__main__':

texlive_bin_path = "D:\\Dev\\TexLive\\bin\\win32" # 增加这一行
tlmgr_cmd = 'tlmgr.bat' # 增加这一行

# Parse command line

### 第三处修改 ###
parser.add_option('--texlive_bin', dest='texlive_bin', metavar='LOCATION',
help='Custom location for the TeX Live bin folder', default=texlive_bin_path) # default='' 改为 texlive_bin_path

### 第四处修改 ###
#initializes tlmgr, responds if the program not found
try:
tlmgr_path = os.path.join(options.texlive_bin, tlmgr_cmd) # tlmgr 改为 tlmgr_cmd

以上修改的目的是将告诉texliveonfly.py具体的编译路径和命令。经过上述修改,可以在命令行里直接使用texliveonfly xx.tex命令编译tex文件。