TexLive+VScode+SumatraPDF配置LaTex编辑环境

本文最后更新于:2024年3月29日 上午

安装Texlive

  1. 下载镜像文件,可以使用【清华镜像】或者【中科大镜像】,下载texlive.iso文件,这是最新的texlive版本。

1a08d2a5020a48d3a68978323d002492

  1. 打开镜像文件,运行install-tl-windows.bat文件。

30ca33fcda014924bf36a8830ae378dd

  1. 修改安装位置,开始安装。

83d3ca7b72e8496aac2ddf8d60980f90

  1. 大约三十分钟后,安装完成。

80f741df248542f5a20145493d6065f4

VScode安装和配置

  1. 打开VScode官网,下载,安装。

e9dc2bbd643f45d4beff01f6bccdb0eb

  1. 打开VScode,安装LaTex WorkShop扩展。

e1906c038f7f43afb5d0296e146fcb70

  1. 按快捷键Ctrl+Shift+P,输入settings.json,打开setting.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
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
{
"latex-workshop.latex.autoBuild.run": "onFileChange", //自动编译:onFileChange、onSave 、never
"latex-workshop.showContextMenu": false, //此命令设置是否将编译文档的选项出现在鼠标右键的菜单中
"latex-workshop.intellisense.package.enabled": true, //从使用的宏包中自动提取命令和环境,从而补全正在编写的代码
"latex-workshop.message.error.show": false,
"latex-workshop.message.warning.show": false, //设置当文档编译错误时是否弹出显示出错和警告的弹窗
//定义在下文 recipes 编译链中被使用的编译命令,此处为默认配置,不需要进行更改
"latex-workshop.latex.tools": [
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"-outdir=%OUTDIR%",
"%DOCFILE%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
//此串代码是对编译链进行定义,其中name是标签,也就是出现在工具栏中的链名称;tool是name标签所对应的编译顺序,其内部编译命令来自上文latex-workshop.latex.recipes中内容。
"latex-workshop.latex.recipes": [
{
"name": "XeLaTeX",
"tools": [
"xelatex"
]
},
{
"name": "PDFLaTeX",
"tools": [
"pdflatex"
]
},
{
"name": "BibTeX",
"tools": [
"bibtex"
]
},
{
"name": "LaTeXmk",
"tools": [
"latexmk"
]
},
{
"name": "xelatex -> bibtex -> xelatex*2",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
},
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
},
],
//设置编译完成后要清除掉的辅助文件类型,若无特殊需求,无需进行更改。
"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.autoClean.run": "onFailed", //设置什么时候对上文设置的辅助文件进行清除:onBuilt、onFailed、never
"latex-workshop.latex.recipe.default": "lastUsed", //设置 vscode 编译 tex 文档时的默认编译链:first、lastUsed
"latex-workshop.view.pdf.internal.synctex.keybinding": "double-click" //反向同步:ctrl-click、double-click
}

到这里VScode就配置完LaTex环境了,下面是配置一个好用的外部PDF阅读器。

外部PDF阅读器SumatraPDF(可选)

安装与配置

  1. 下载SumatraPDF,官网
  2. 在上述setting.json中添加如下代码,注意将路径替换为自己的SumatraPDF路径和VScode路径。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"latex-workshop.view.pdf.viewer": "external", //设置默认的pdf查看器,tab、browser、external
"latex-workshop.view.pdf.ref.viewer": "auto", //设置PDF查看器用于在 \ref 命令上的[View on PDF]链接,此命令作用于 \ref 引用查看
"latex-workshop.view.pdf.external.viewer.command": "D:/Program Files/SumatraPDF/SumatraPDF.exe", //使用外部查看器时要执行的命令,设置外部查看器启动文件SumatraPDF.exe文件所在位置
"latex-workshop.view.pdf.external.viewer.args": [ //此代码是设置使用外部查看器时,latex-workshop.view.pdf.external.view .command的参数。%PDF%是用于生成PDF文件的绝对路径的占位符。
"%PDF%"
],
"latex-workshop.view.pdf.external.synctex.command": "D:/Program Files/SumatraPDF/SumatraPDF.exe", //将生成的辅助文件.synctex.gz转发到外部查看器时要执行的命令,设置其位置参数
//当 .synctex.gz 文件同步到外部查看器时latex-workshop.view.pdf.external.synctex的参数设置。%LINE%是行号,%PDF%是生成PDF文件的绝对路径的占位符,%TEX%是当触发syncTeX被触发时,扩展名为 .tex 的 LaTeX 文件路径。
"latex-workshop.view.pdf.external.synctex.args": [
"-forward-search",
"%TEX%",
"%LINE%",
"-reuse-instance",
"-inverse-search",
"\"D:/Program Files/Microsoft VS Code/Code.exe\" \"D:/Program Files/Microsoft VS Code/resources/app/out/cli.js\" -r -g \"%f:%l\"", // 注意修改路径
"%PDF%"
]

配置正向搜索与反向搜索

正向搜索

即从tex源码界面定位到pdf界面,使用快捷键Ctrl+Alt+J。

反向搜索

从pdf界面定位相应的tex源码界面。

  1. 打开SumatraPDF,点击选项。

33f8c9c89223469ab4b22174c101e5d3

  1. 在图示位置输入以下代码(注意VScode路径):

f2a006dd192f4fef8027aec187892ed3

1
"D:/Program Files/Microsoft VS Code/Code.exe" "D:/Program Files/Microsoft VS Code/resources/app/out/cli.js" --ms-enable-electron-run-as-node -r -g "%f:%l"
  1. 反向搜索配置成功,在pdf界面双击即可跳转。

TexLive+VScode+SumatraPDF配置LaTex编辑环境
https://summersong.top/post/1f879cd9.html
作者
SummerSong
发布于
2022年7月21日
更新于
2024年3月29日
许可协议