0%

安装配置LaTeX环境, TeX Live + VSCode

安装TeX Live

macOS/Linux

1
$ brew install texlive

Linux下更推荐用自带包管理安装.

Windows

1
PS > choco install texlive

配置TeX Live

查看TeX Live包管理版本

1
$ tlmgr --version

测试安装包

1
$ tlmgr install latexindent

如果报错

1
tlmgr: action not allowed in system mode: install

则需要在命令上加上--usermode参数:

1
$ tlmgr install latexindent --usermode

如果报错

1
2
TLPDB: not a directory, not loading: /Users/xxx/texmf
cannot setup TLPDB in /Users/xxx/texmf at /usr/local/bin/tlmgr line 6887.

则先执行

1
$ tlmgr init-usertree

再执行安装命令.

随后可以安装一些常用包, 例如beamer:

1
$ tlmgr install beamer

配置VSCode

安装LaTeX Workshop扩展:
https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop

打开扩展设置, 搜索 @ext:James-Yu.latex-workshop recipes

定位到 Latex-workshop › Latex: Recipes

点击 Edit in settings.json

将xelatex移动至第一位

1
2
3
4
5
6
7
8
9
"latex-workshop.latex.recipes": [
{
"name": "latexmk (xelatex)",
"tools": [
"xelatexmk"
]
},
...
]

每次保存tex文件时会自动编译, 此行为可以通过配置

1
"latex-workshop.latex.autoBuild.run": "onFileChange"

来更改, 可选值为

  • onFileChange 监测到文件改动时
  • onSave 文件保存时
  • never 永不

遇到编译错误时, 如果原因为缺少包, 可以通过包管理tlmgr安装.