安装

安装 texlive

打开清华镜像网站,下载texlive.iso, 加载到虚拟光驱并以管理员方式运行install-tl-windows.bat,除安装路径自定义外,其余选项皆默认。(安装约30min)

安装插件:LaTeX Workshop

latex_workshop

配置

Ctrl+,进入配置界面并按右上角切换到settings.json文件,添加以下内容:

配置编译引擎程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"latex-workshop.latex.tools": [
// 编译工具和命令
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOCFILE%"
]
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOCFILE%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],

将 tools 中的 %DOC% 替换成%DOCFILE%可以支持中文路径下的文件。

配置编译链

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"latex-workshop.latex.recipes": [
{
"name": "XeLaTeX",
"tools": [
"xelatex"
]
},
{
"name": "PDFLaTeX",
"tools": [
"pdflatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},
{
"name": "BibTeX",
"tools": [
"bibtex"
]
},
{
"name": "pdf -> bib -> pdf*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
{
"name": "xe -> bib -> xe*2",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
}
],

配置临时文件清理方式

1
"latex-workshop.latex.autoClean.run": "onBuilt",

设置需清理文件的后缀(注意不要清理.gz文件,正反向搜索依赖该文件)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk",
],

配置自动编译

1
"latex-workshop.latex.autoBuild.run": "never",

编译完成后,自动打开PDF并跳转至光标所在行:

1
"latex-workshop.synctex.afterBuild.enabled": true,

配置PDF浏览方式

1
2
3
4
5
6
7
8
// external-外部浏览,tab-内部分栏,browser-浏览器
"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.ref.viewer":"external",
// 当选择外部PDF浏览器时,安装SumatraPDF并设置以下两项
"latex-workshop.view.pdf.external.viewer.command": "C:/Program Files/SumatraPDF/SumatraPDF.exe", //SumatraPDF.exe的实际路径
"latex-workshop.view.pdf.external.viewer.args": [
"%PDF%",
],

设置正向、反向跳转:

1
2
3
4
5
6
7
8
9
"latex-workshop.view.pdf.external.synctex.command": "C:/Program Files/SumatraPDF/SumatraPDF.exe",  //SumatraPDF.exe的实际路径
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"%PDF%",
"-inverse-search",
"\"C:/Program Files/Microsoft VS Code/bin/code.cmd\" -g \"%f\":\"%l\"", //修改为你的具体文件路径
],

配置文件内容汇总

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* Latex Config */
"latex-workshop.latex.tools": [
// 编译工具和命令
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOCFILE%"
]
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOCFILE%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],

"latex-workshop.latex.recipes": [
{
"name": "XeLaTeX",
"tools": [
"xelatex"
]
},
{
"name": "PDFLaTeX",
"tools": [
"pdflatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},
{
"name": "BibTeX",
"tools": [
"bibtex"
]
},
{
"name": "pdf -> bib -> pdf*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
{
"name": "xe -> bib -> xe*2",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
}
],

"latex-workshop.latex.autoClean.run": "onBuilt",
"latex-workshop.latex.clean.fileTypes": [
"*.aux",
"*.bbl",
"*.blg",
"*.idx",
"*.ind",
"*.lof",
"*.lot",
"*.out",
"*.toc",
"*.acn",
"*.acr",
"*.alg",
"*.glg",
"*.glo",
"*.gls",
"*.ist",
"*.fls",
"*.log",
"*.fdb_latexmk",
],

"latex-workshop.latex.autoBuild.run": "never",
"latex-workshop.synctex.afterBuild.enabled": true,

"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.ref.viewer":"external",
"latex-workshop.view.pdf.external.viewer.command": "C:/Program Files/SumatraPDF/SumatraPDF.exe", //SumatraPDF.exe的实际路径
"latex-workshop.view.pdf.external.viewer.args": [
"%PDF%",
],
"latex-workshop.view.pdf.external.synctex.command": "C:/Program Files/SumatraPDF/SumatraPDF.exe", //SumatraPDF.exe的实际路径
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"%PDF%",
"-inverse-search",
"\"C:/Program Files/Microsoft VS Code/bin/code.cmd\" -g \"%f\":\"%l\"", //修改为你的具体文件路径
],

更多

更多VS Code相关配置见环境搭建 - VS Code

参考资料

Win10 安装 TeXLive 2018 - 简书

使用VSCode编写LaTeX - 知乎

Synctex inverse search doesn't work half the time (and How I got forward search to work for SumatraPDF) · Issue #637 · James-Yu/LaTeX-Workshop · GitHub